[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;
}
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) {
MlMetadata mlMetadata = clusterState.metaData().custom(MlMetadata.TYPE);
Job job = mlMetadata.getJobs().get(jobId);
String jobResultIndex = AnomalyDetectorsIndex.jobResultsIndexName(job.getResultsIndexName());
String[] indices = new String[]{AnomalyDetectorsIndex.jobStateIndexName(), jobResultIndex, JobProvider.ML_META_INDEX};
String[] indices = indicesOfInterest(job);
for (String index : indices) {
// Indices are created on demand from templates.
// 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());
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()) {
routingTable.remove(indexToRemove);
} else {