本文整理匯總了Java中org.elasticsearch.cluster.metadata.MetaData.Custom方法的典型用法代碼示例。如果您正苦於以下問題:Java MetaData.Custom方法的具體用法?Java MetaData.Custom怎麽用?Java MetaData.Custom使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.elasticsearch.cluster.metadata.MetaData
的用法示例。
在下文中一共展示了MetaData.Custom方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: fromXContent
import org.elasticsearch.cluster.metadata.MetaData; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public static <T extends MetaData.Custom> T fromXContent(Function<String, MetaData.Custom> supplier, XContentParser parser)
throws IOException {
XContentParser.Token token;
String data = null;
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
if (token == XContentParser.Token.FIELD_NAME) {
String currentFieldName = parser.currentName();
if ("data".equals(currentFieldName)) {
if (parser.nextToken() != XContentParser.Token.VALUE_STRING) {
throw new ElasticsearchParseException("failed to parse snapshottable metadata, invalid data type");
}
data = parser.text();
} else {
throw new ElasticsearchParseException("failed to parse snapshottable metadata, unknown field [{}]", currentFieldName);
}
} else {
throw new ElasticsearchParseException("failed to parse snapshottable metadata");
}
}
if (data == null) {
throw new ElasticsearchParseException("failed to parse snapshottable metadata, data not found");
}
return (T) supplier.apply(data);
}
示例2: changedCustomMetaDataSet
import org.elasticsearch.cluster.metadata.MetaData; //導入方法依賴的package包/類
/**
* Returns a set of custom meta data types when any custom metadata for the cluster has changed
* between the previous cluster state and the new cluster state. custom meta data types are
* returned iff they have been added, updated or removed between the previous and the current state
*/
public Set<String> changedCustomMetaDataSet() {
Set<String> result = new HashSet<>();
ImmutableOpenMap<String, MetaData.Custom> currentCustoms = state.metaData().customs();
ImmutableOpenMap<String, MetaData.Custom> previousCustoms = previousState.metaData().customs();
if (currentCustoms.equals(previousCustoms) == false) {
for (ObjectObjectCursor<String, MetaData.Custom> currentCustomMetaData : currentCustoms) {
// new custom md added or existing custom md changed
if (previousCustoms.containsKey(currentCustomMetaData.key) == false
|| currentCustomMetaData.value.equals(previousCustoms.get(currentCustomMetaData.key)) == false) {
result.add(currentCustomMetaData.key);
}
}
// existing custom md deleted
for (ObjectObjectCursor<String, MetaData.Custom> previousCustomMetaData : previousCustoms) {
if (currentCustoms.containsKey(previousCustomMetaData.key) == false) {
result.add(previousCustomMetaData.key);
}
}
}
return result;
}
示例3: testMergeMultipleCustomMetaData
import org.elasticsearch.cluster.metadata.MetaData; //導入方法依賴的package包/類
public void testMergeMultipleCustomMetaData() {
Map<String, List<TribeService.MergableCustomMetaData>> inputMap = new HashMap<>();
inputMap.put(MergableCustomMetaData1.TYPE,
Arrays.asList(new MergableCustomMetaData1("data10"), new MergableCustomMetaData1("data11")));
inputMap.put(MergableCustomMetaData2.TYPE,
Arrays.asList(new MergableCustomMetaData2("data21"), new MergableCustomMetaData2("data20")));
Map<String, MetaData.Custom> mergedCustoms = TribeService.mergeChangedCustomMetaData(
Sets.newHashSet(MergableCustomMetaData1.TYPE, MergableCustomMetaData2.TYPE), inputMap::get);
TestCustomMetaData mergedCustom = (TestCustomMetaData) mergedCustoms.get(MergableCustomMetaData1.TYPE);
assertNotNull(mergedCustom);
assertThat(mergedCustom, instanceOf(MergableCustomMetaData1.class));
assertEquals(mergedCustom.getData(), "data11");
mergedCustom = (TestCustomMetaData) mergedCustoms.get(MergableCustomMetaData2.TYPE);
assertNotNull(mergedCustom);
assertThat(mergedCustom, instanceOf(MergableCustomMetaData2.class));
assertEquals(mergedCustom.getData(), "data21");
}
示例4: nextState
import org.elasticsearch.cluster.metadata.MetaData; //導入方法依賴的package包/類
private static ClusterState nextState(final ClusterState previousState, List<TestCustomMetaData> customMetaDataList) {
final ClusterState.Builder builder = ClusterState.builder(previousState);
builder.stateUUID(UUIDs.randomBase64UUID());
MetaData.Builder metaDataBuilder = new MetaData.Builder(previousState.metaData());
for (ObjectObjectCursor<String, MetaData.Custom> customMetaData : previousState.metaData().customs()) {
if (customMetaData.value instanceof TestCustomMetaData) {
metaDataBuilder.removeCustom(customMetaData.key);
}
}
for (TestCustomMetaData testCustomMetaData : customMetaDataList) {
metaDataBuilder.putCustom(testCustomMetaData.getWriteableName(), testCustomMetaData);
}
builder.metaData(metaDataBuilder);
return builder.build();
}
示例5: upgradeMetaData
import org.elasticsearch.cluster.metadata.MetaData; //導入方法依賴的package包/類
/**
* Elasticsearch 2.0 removed several deprecated features and as well as support for Lucene 3.x. This method calls
* {@link MetaDataIndexUpgradeService} to makes sure that indices are compatible with the current version. The
* MetaDataIndexUpgradeService might also update obsolete settings if needed.
* Allows upgrading global custom meta data via {@link MetaDataUpgrader#customMetaDataUpgraders}
*
* @return input <code>metaData</code> if no upgrade is needed or an upgraded metaData
*/
static MetaData upgradeMetaData(MetaData metaData,
MetaDataIndexUpgradeService metaDataIndexUpgradeService,
MetaDataUpgrader metaDataUpgrader) throws Exception {
// upgrade index meta data
boolean changed = false;
final MetaData.Builder upgradedMetaData = MetaData.builder(metaData);
for (IndexMetaData indexMetaData : metaData) {
IndexMetaData newMetaData = metaDataIndexUpgradeService.upgradeIndexMetaData(indexMetaData,
Version.CURRENT.minimumIndexCompatibilityVersion());
changed |= indexMetaData != newMetaData;
upgradedMetaData.put(newMetaData, false);
}
// collect current customs
Map<String, MetaData.Custom> existingCustoms = new HashMap<>();
for (ObjectObjectCursor<String, MetaData.Custom> customCursor : metaData.customs()) {
existingCustoms.put(customCursor.key, customCursor.value);
}
// upgrade global custom meta data
Map<String, MetaData.Custom> upgradedCustoms = metaDataUpgrader.customMetaDataUpgraders.apply(existingCustoms);
if (upgradedCustoms.equals(existingCustoms) == false) {
existingCustoms.keySet().forEach(upgradedMetaData::removeCustom);
for (Map.Entry<String, MetaData.Custom> upgradedCustomEntry : upgradedCustoms.entrySet()) {
upgradedMetaData.putCustom(upgradedCustomEntry.getKey(), upgradedCustomEntry.getValue());
}
changed = true;
}
return changed ? upgradedMetaData.build() : metaData;
}
示例6: updateCustoms
import org.elasticsearch.cluster.metadata.MetaData; //導入方法依賴的package包/類
private boolean updateCustoms(ClusterState currentState, List<ClusterChangedEvent> tasks, MetaData.Builder metaData) {
boolean clusterStateChanged = false;
Set<String> changedCustomMetaDataTypeSet = tasks.stream()
.map(ClusterChangedEvent::changedCustomMetaDataSet)
.flatMap(Collection::stream)
.collect(Collectors.toSet());
final List<Node> tribeClientNodes = TribeService.this.nodes;
Map<String, MetaData.Custom> mergedCustomMetaDataMap = mergeChangedCustomMetaData(changedCustomMetaDataTypeSet,
customMetaDataType -> tribeClientNodes.stream()
.map(TribeService::getClusterService).map(ClusterService::state)
.map(ClusterState::metaData)
.map(clusterMetaData -> ((MetaData.Custom) clusterMetaData.custom(customMetaDataType)))
.filter(custom1 -> custom1 != null && custom1 instanceof MergableCustomMetaData)
.map(custom2 -> (MergableCustomMetaData) marshal(custom2))
.collect(Collectors.toList())
);
for (String changedCustomMetaDataType : changedCustomMetaDataTypeSet) {
MetaData.Custom mergedCustomMetaData = mergedCustomMetaDataMap.get(changedCustomMetaDataType);
if (mergedCustomMetaData == null) {
// we ignore merging custom md which doesn't implement MergableCustomMetaData interface
if (currentState.metaData().custom(changedCustomMetaDataType) instanceof MergableCustomMetaData) {
// custom md has been removed
clusterStateChanged = true;
logger.info("[{}] removing custom meta data type [{}]", tribeName, changedCustomMetaDataType);
metaData.removeCustom(changedCustomMetaDataType);
}
} else {
// custom md has been changed
clusterStateChanged = true;
logger.info("[{}] updating custom meta data type [{}] data [{}]", tribeName, changedCustomMetaDataType, mergedCustomMetaData);
metaData.putCustom(changedCustomMetaDataType, mergedCustomMetaData);
}
}
return clusterStateChanged;
}
示例7: mergeChangedCustomMetaData
import org.elasticsearch.cluster.metadata.MetaData; //導入方法依賴的package包/類
static Map<String, MetaData.Custom> mergeChangedCustomMetaData(Set<String> changedCustomMetaDataTypeSet,
Function<String, List<MergableCustomMetaData>> customMetaDataByTribeNode) {
Map<String, MetaData.Custom> changedCustomMetaDataMap = new HashMap<>(changedCustomMetaDataTypeSet.size());
for (String customMetaDataType : changedCustomMetaDataTypeSet) {
customMetaDataByTribeNode.apply(customMetaDataType).stream()
.reduce((mergableCustomMD, mergableCustomMD2) ->
((MergableCustomMetaData) mergableCustomMD.merge((MetaData.Custom) mergableCustomMD2)))
.ifPresent(mergedCustomMetaData ->
changedCustomMetaDataMap.put(customMetaDataType, ((MetaData.Custom) mergedCustomMetaData)));
}
return changedCustomMetaDataMap;
}
示例8: marshal
import org.elasticsearch.cluster.metadata.MetaData; //導入方法依賴的package包/類
/**
* Since custom metadata can be loaded by a plugin class loader that resides in a sub-node, we need to
* marshal this object into something the tribe node can work with
*/
private MetaData.Custom marshal(MetaData.Custom custom) {
try (BytesStreamOutput bytesStreamOutput = new BytesStreamOutput()){
bytesStreamOutput.writeNamedWriteable(custom);
try(StreamInput input = bytesStreamOutput.bytes().streamInput()) {
StreamInput namedInput = new NamedWriteableAwareStreamInput(input, namedWriteableRegistry);
MetaData.Custom marshaled = namedInput.readNamedWriteable(MetaData.Custom.class);
return marshaled;
}
} catch (IOException ex) {
throw new IllegalStateException("cannot marshal object with type " + custom.getWriteableName() + " to tribe node");
}
}
示例9: registerMetaDataCustom
import org.elasticsearch.cluster.metadata.MetaData; //導入方法依賴的package包/類
private <T extends MetaData.Custom> void registerMetaDataCustom(String name, Writeable.Reader<T> reader,
Writeable.Reader<NamedDiff> diffReader,
CheckedFunction<XContentParser, T, IOException> parser) {
namedWritables.add(new NamedWriteableRegistry.Entry(MetaData.Custom.class, name, reader));
namedWritables.add(new NamedWriteableRegistry.Entry(NamedDiff.class, name, diffReader));
namedXContents.add(new NamedXContentRegistry.Entry(MetaData.Custom.class, new ParseField(name), parser));
}
示例10: testFromXContent
import org.elasticsearch.cluster.metadata.MetaData; //導入方法依賴的package包/類
public void testFromXContent() throws IOException {
PipelineConfiguration pipeline = new PipelineConfiguration(
"1", new BytesArray("{\"processors\": [{\"set\" : {\"field\": \"_field\", \"value\": \"_value\"}}]}"), XContentType.JSON
);
PipelineConfiguration pipeline2 = new PipelineConfiguration(
"2", new BytesArray("{\"processors\": [{\"set\" : {\"field\": \"_field1\", \"value\": \"_value1\"}}]}"), XContentType.JSON
);
Map<String, PipelineConfiguration> map = new HashMap<>();
map.put(pipeline.getId(), pipeline);
map.put(pipeline2.getId(), pipeline2);
IngestMetadata ingestMetadata = new IngestMetadata(map);
XContentBuilder builder = XContentFactory.contentBuilder(randomFrom(XContentType.values()));
builder.prettyPrint();
builder.startObject();
ingestMetadata.toXContent(builder, ToXContent.EMPTY_PARAMS);
builder.endObject();
XContentBuilder shuffled = shuffleXContent(builder);
final XContentParser parser = createParser(shuffled);
MetaData.Custom custom = IngestMetadata.fromXContent(parser);
assertTrue(custom instanceof IngestMetadata);
IngestMetadata m = (IngestMetadata) custom;
assertEquals(2, m.getPipelines().size());
assertEquals("1", m.getPipelines().get("1").getId());
assertEquals("2", m.getPipelines().get("2").getId());
assertEquals(pipeline.getConfigAsMap(), m.getPipelines().get("1").getConfigAsMap());
assertEquals(pipeline2.getConfigAsMap(), m.getPipelines().get("2").getConfigAsMap());
}
示例11: testMergeCustomMetaDataSimple
import org.elasticsearch.cluster.metadata.MetaData; //導入方法依賴的package包/類
public void testMergeCustomMetaDataSimple() {
Map<String, MetaData.Custom> mergedCustoms =
TribeService.mergeChangedCustomMetaData(Collections.singleton(MergableCustomMetaData1.TYPE),
s -> Collections.singletonList(new MergableCustomMetaData1("data1")));
TestCustomMetaData mergedCustom = (TestCustomMetaData) mergedCustoms.get(MergableCustomMetaData1.TYPE);
assertThat(mergedCustom, instanceOf(MergableCustomMetaData1.class));
assertNotNull(mergedCustom);
assertEquals(mergedCustom.getData(), "data1");
}
示例12: testMergeCustomMetaData
import org.elasticsearch.cluster.metadata.MetaData; //導入方法依賴的package包/類
public void testMergeCustomMetaData() {
Map<String, MetaData.Custom> mergedCustoms =
TribeService.mergeChangedCustomMetaData(Collections.singleton(MergableCustomMetaData1.TYPE),
s -> Arrays.asList(new MergableCustomMetaData1("data1"), new MergableCustomMetaData1("data2")));
TestCustomMetaData mergedCustom = (TestCustomMetaData) mergedCustoms.get(MergableCustomMetaData1.TYPE);
assertThat(mergedCustom, instanceOf(MergableCustomMetaData1.class));
assertNotNull(mergedCustom);
assertEquals(mergedCustom.getData(), "data2");
}
示例13: readDiffFrom
import org.elasticsearch.cluster.metadata.MetaData; //導入方法依賴的package包/類
public static NamedDiff<MetaData.Custom> readDiffFrom(StreamInput in) throws IOException {
return readDiffFrom(TYPE, in);
}
示例14: readDiffFrom
import org.elasticsearch.cluster.metadata.MetaData; //導入方法依賴的package包/類
public static NamedDiff<MetaData.Custom> readDiffFrom(StreamInput in) throws IOException {
return new ScriptMetadataDiff(in);
}
示例15: diff
import org.elasticsearch.cluster.metadata.MetaData; //導入方法依賴的package包/類
@Override
public Diff<MetaData.Custom> diff(MetaData.Custom before) {
return new ScriptMetadataDiff((ScriptMetaData)before, this);
}