ML allow aliased .ml-anomalies* index on PUT Job (#38821) (#38847)

This commit is contained in:
Benjamin Trent 2019-02-13 10:58:55 -06:00 committed by GitHub
parent 46bb663a09
commit d2ac05e249
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 20 additions and 1 deletions

View File

@ -38,6 +38,7 @@ import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.block.ClusterBlock; import org.elasticsearch.cluster.block.ClusterBlock;
import org.elasticsearch.cluster.block.ClusterBlockException; import org.elasticsearch.cluster.block.ClusterBlockException;
import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
import org.elasticsearch.cluster.metadata.MappingMetaData; import org.elasticsearch.cluster.metadata.MappingMetaData;
import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.Strings; import org.elasticsearch.common.Strings;
@ -252,7 +253,25 @@ public class JobResultsProvider {
String readAliasName = AnomalyDetectorsIndex.jobResultsAliasedName(job.getId()); String readAliasName = AnomalyDetectorsIndex.jobResultsAliasedName(job.getId());
String writeAliasName = AnomalyDetectorsIndex.resultsWriteAlias(job.getId()); String writeAliasName = AnomalyDetectorsIndex.resultsWriteAlias(job.getId());
String indexName = job.getInitialResultsIndexName(); String tempIndexName = job.getInitialResultsIndexName();
// Our read/write aliases should point to the concrete index
// If the initial index is NOT an alias, either it is already a concrete index, or it does not exist yet
if (state.getMetaData().hasAlias(tempIndexName)) {
IndexNameExpressionResolver resolver = new IndexNameExpressionResolver();
String[] concreteIndices = resolver.concreteIndexNames(state, IndicesOptions.lenientExpandOpen(), tempIndexName);
// SHOULD NOT be closed as in typical call flow checkForLeftOverDocuments already verified this
// if it is closed, we bailout and return an error
if (concreteIndices.length == 0) {
finalListener.onFailure(
ExceptionsHelper.badRequestException("Cannot create job [{}] as it requires closed index {}", job.getId(),
tempIndexName));
return;
}
tempIndexName = concreteIndices[0];
}
final String indexName = tempIndexName;
final ActionListener<Boolean> createAliasListener = ActionListener.wrap(success -> { final ActionListener<Boolean> createAliasListener = ActionListener.wrap(success -> {
final IndicesAliasesRequest request = client.admin().indices().prepareAliases() final IndicesAliasesRequest request = client.admin().indices().prepareAliases()