[ML] Fix intermittent test failure (occasionally deleted an index we don’t care about)

Original commit: elastic/x-pack-elasticsearch@56c7bdb5b9
This commit is contained in:
David Kyle 2017-02-24 12:19:05 +00:00
parent a09e8a260a
commit f67d8c3746
2 changed files with 10 additions and 3 deletions

View File

@ -454,11 +454,15 @@ public class OpenJobAction extends Action<OpenJobAction.Request, PersistentActio
return minLoadedNode; return minLoadedNode;
} }
static String[] indicesOfInterest(Job job) {
String jobResultIndex = AnomalyDetectorsIndex.jobResultsIndexName(job.getResultsIndexName());
return new String[]{AnomalyDetectorsIndex.jobStateIndexName(), jobResultIndex, JobProvider.ML_META_INDEX};
}
static boolean verifyIndicesPrimaryShardsAreActive(Logger logger, String jobId, ClusterState clusterState) { static boolean verifyIndicesPrimaryShardsAreActive(Logger logger, String jobId, ClusterState clusterState) {
MlMetadata mlMetadata = clusterState.metaData().custom(MlMetadata.TYPE); MlMetadata mlMetadata = clusterState.metaData().custom(MlMetadata.TYPE);
Job job = mlMetadata.getJobs().get(jobId); Job job = mlMetadata.getJobs().get(jobId);
String jobResultIndex = AnomalyDetectorsIndex.jobResultsIndexName(job.getResultsIndexName()); String[] indices = indicesOfInterest(job);
String[] indices = new String[]{AnomalyDetectorsIndex.jobStateIndexName(), jobResultIndex, JobProvider.ML_META_INDEX};
for (String index : indices) { for (String index : indices) {
// Indices are created on demand from templates. // Indices are created on demand from templates.
// It is not an error if the index doesn't exist yet // It is not an error if the index doesn't exist yet

View File

@ -276,7 +276,10 @@ public class OpenJobActionTests extends ESTestCase {
metaData = new MetaData.Builder(cs.metaData()); metaData = new MetaData.Builder(cs.metaData());
routingTable = new RoutingTable.Builder(cs.routingTable()); routingTable = new RoutingTable.Builder(cs.routingTable());
String indexToRemove = randomFrom(cs.metaData().getConcreteAllIndices());
MlMetadata mlMetadata = cs.metaData().custom(MlMetadata.TYPE);
Job job = mlMetadata.getJobs().get("job_id");
String indexToRemove = randomFrom(OpenJobAction.indicesOfInterest(job));
if (randomBoolean()) { if (randomBoolean()) {
routingTable.remove(indexToRemove); routingTable.remove(indexToRemove);
} else { } else {