Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
package org.elasticsearch.upgrades;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.client.internal.Client;
import org.elasticsearch.client.internal.OriginSettingClient;
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.cluster.metadata.Metadata;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.settings.IndexScopedSettings;
import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.indices.SystemIndexDescriptor;
import org.elasticsearch.indices.SystemIndices;
import org.elasticsearch.plugins.SystemIndexPlugin;
import java.util.Comparator;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Stream;
import static org.elasticsearch.cluster.metadata.IndexMetadata.State.CLOSE;
import static org.elasticsearch.core.Strings.format;
/**
* Holds the data required to migrate a single system index, including metadata from the current index. If necessary, computes the settings
* and mappings for the "next" index based off of the current one.
*/
class SystemIndexMigrationInfo implements Comparable {
private static final Logger logger = LogManager.getLogger(SystemIndexMigrationInfo.class);
private final IndexMetadata currentIndex;
private final String featureName;
private final Settings settings;
private final String mapping;
private final String origin;
private final SystemIndices.Feature owningFeature;
private final boolean allowsTemplates;
private static final Comparator SAME_CLASS_COMPARATOR = Comparator.comparing(
SystemIndexMigrationInfo::getFeatureName
).thenComparing(SystemIndexMigrationInfo::getCurrentIndexName);
private SystemIndexMigrationInfo(
IndexMetadata currentIndex,
String featureName,
Settings settings,
String mapping,
String origin,
SystemIndices.Feature owningFeature,
boolean allowsTemplates
) {
this.currentIndex = currentIndex;
this.featureName = featureName;
this.settings = settings;
this.mapping = mapping;
this.origin = origin;
this.owningFeature = owningFeature;
this.allowsTemplates = allowsTemplates;
}
/**
* Gets the name of the index to be migrated.
*/
String getCurrentIndexName() {
return currentIndex.getIndex().getName();
}
/**
* Indicates if the index to be migrated is closed.
*/
boolean isCurrentIndexClosed() {
return CLOSE.equals(currentIndex.getState());
}
/**
* Gets the name to be used for the post-migration index.
*/
String getNextIndexName() {
return currentIndex.getIndex().getName() + SystemIndices.UPGRADED_INDEX_SUFFIX;
}
/**
* Gets the name of the feature which owns the index to be migrated.
*/
String getFeatureName() {
return featureName;
}
/**
* Gets the mappings to be used for the post-migration index.
*/
String getMappings() {
return mapping;
}
/**
* Gets the settings to be used for the post-migration index.
*/
Settings getSettings() {
return settings;
}
/**
* Gets the origin that should be used when interacting with this index.
*/
String getOrigin() {
return origin;
}
/**
* By default, system indices should not be affected by user defined templates, so this
* method should return false in almost all cases. At the moment certain Kibana indices use
* templates, therefore we allow templates to be used on Kibana created system indices until
* Kibana removes the template use on system index creation.
*/
boolean allowsTemplates() {
return allowsTemplates;
}
/**
* Invokes the pre-migration hook for the feature that owns this index.
* See {@link SystemIndexPlugin#prepareForIndicesMigration(ClusterService, Client, ActionListener)}.
* @param clusterService For retrieving the state.
* @param client For performing any update operations necessary to prepare for the upgrade.
* @param listener Call {@link ActionListener#onResponse(Object)} when preparation for migration is complete.
*/
void prepareForIndicesMigration(ClusterService clusterService, Client client, ActionListener