当前位置: 首页>>代码示例>>Java>>正文


Java MetaData.Custom方法代码示例

本文整理汇总了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);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:26,代码来源:TestCustomMetaData.java

示例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;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:27,代码来源:ClusterChangedEvent.java

示例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");
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:18,代码来源:TribeServiceTests.java

示例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();
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:16,代码来源:ClusterChangedEventTests.java

示例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;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:37,代码来源:GatewayMetaState.java

示例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;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:36,代码来源:TribeService.java

示例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;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:14,代码来源:TribeService.java

示例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");
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:TribeService.java

示例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));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:8,代码来源:DedicatedClusterSnapshotRestoreIT.java

示例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());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:28,代码来源:IngestMetadataTests.java

示例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");
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:10,代码来源:TribeServiceTests.java

示例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");
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:10,代码来源:TribeServiceTests.java

示例13: readDiffFrom

import org.elasticsearch.cluster.metadata.MetaData; //导入方法依赖的package包/类
public static NamedDiff<MetaData.Custom> readDiffFrom(StreamInput in) throws IOException {
    return readDiffFrom(TYPE, in);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:4,代码来源:TribeServiceTests.java

示例14: readDiffFrom

import org.elasticsearch.cluster.metadata.MetaData; //导入方法依赖的package包/类
public static NamedDiff<MetaData.Custom> readDiffFrom(StreamInput in) throws IOException {
    return new ScriptMetadataDiff(in);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:4,代码来源:ScriptMetaData.java

示例15: diff

import org.elasticsearch.cluster.metadata.MetaData; //导入方法依赖的package包/类
@Override
public Diff<MetaData.Custom> diff(MetaData.Custom before) {
    return new ScriptMetadataDiff((ScriptMetaData)before, this);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:5,代码来源:ScriptMetaData.java


注:本文中的org.elasticsearch.cluster.metadata.MetaData.Custom方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。