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


Java MetaData类代码示例

本文整理汇总了Java中org.elasticsearch.cluster.metadata.MetaData的典型用法代码示例。如果您正苦于以下问题:Java MetaData类的具体用法?Java MetaData怎么用?Java MetaData使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


MetaData类属于org.elasticsearch.cluster.metadata包,在下文中一共展示了MetaData类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: buildShardLevelInfo

import org.elasticsearch.cluster.metadata.MetaData; //导入依赖的package包/类
static void buildShardLevelInfo(ESLogger logger, ShardStats[] stats, HashMap<String, Long> newShardSizes, HashMap<ShardRouting, String> newShardRoutingToDataPath, ClusterState state) {
    MetaData meta = state.getMetaData();
    for (ShardStats s : stats) {
        IndexMetaData indexMeta = meta.index(s.getShardRouting().index());
        Settings indexSettings = indexMeta == null ? null : indexMeta.getSettings();
        newShardRoutingToDataPath.put(s.getShardRouting(), s.getDataPath());
        long size = s.getStats().getStore().sizeInBytes();
        String sid = ClusterInfo.shardIdentifierFromRouting(s.getShardRouting());
        if (logger.isTraceEnabled()) {
            logger.trace("shard: {} size: {}", sid, size);
        }
        if (indexSettings != null && IndexMetaData.isIndexUsingShadowReplicas(indexSettings)) {
            // Shards on a shared filesystem should be considered of size 0
            if (logger.isTraceEnabled()) {
                logger.trace("shard: {} is using shadow replicas and will be treated as size 0", sid);
            }
            size = 0;
        }
        newShardSizes.put(sid, size);
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:22,代码来源:InternalClusterInfoService.java

示例2: shardOperationOnPrimary

import org.elasticsearch.cluster.metadata.MetaData; //导入依赖的package包/类
@Override
protected Tuple<IndexResponse, IndexRequest> shardOperationOnPrimary(MetaData metaData, IndexRequest request) throws Throwable {

    // validate, if routing is required, that we got routing
    IndexMetaData indexMetaData = metaData.index(request.shardId().getIndex());
    MappingMetaData mappingMd = indexMetaData.mappingOrDefault(request.type());
    if (mappingMd != null && mappingMd.routing().required()) {
        if (request.routing() == null) {
            throw new RoutingMissingException(request.shardId().getIndex(), request.type(), request.id());
        }
    }

    IndexService indexService = indicesService.indexServiceSafe(request.shardId().getIndex());
    IndexShard indexShard = indexService.shardSafe(request.shardId().id());
    indexShard.checkDiskSpace(fsService);
    final WriteResult<IndexResponse> result = executeIndexRequestOnPrimary(null, request, indexShard, mappingUpdatedAction);
    final IndexResponse response = result.response;
    final Translog.Location location = result.location;
    processAfterWrite(request.refresh(), indexShard, location);
    return new Tuple<>(response, request);
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:22,代码来源:TransportIndexAction.java

示例3: createInitialClusterState

import org.elasticsearch.cluster.metadata.MetaData; //导入依赖的package包/类
private ClusterState createInitialClusterState() {
    MetaData.Builder metaBuilder = MetaData.builder();
    metaBuilder.put(IndexMetaData.builder("idx").settings(settings(Version.CURRENT)).numberOfShards(1).numberOfReplicas(0));
    MetaData metaData = metaBuilder.build();
    RoutingTable.Builder routingTableBuilder = RoutingTable.builder();
    routingTableBuilder.addAsNew(metaData.index("idx"));

    RoutingTable routingTable = routingTableBuilder.build();
    ClusterState clusterState = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY))
        .metaData(metaData).routingTable(routingTable).build();
    clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1")).add(newNode("node2")))
        .build();
    RoutingTable prevRoutingTable = routingTable;
    routingTable = strategy.reroute(clusterState, "reroute", false).routingTable();
    clusterState = ClusterState.builder(clusterState).routingTable(routingTable).build();

    assertEquals(prevRoutingTable.index("idx").shards().size(), 1);
    assertEquals(prevRoutingTable.index("idx").shard(0).shards().get(0).state(), UNASSIGNED);

    assertEquals(routingTable.index("idx").shards().size(), 1);
    assertEquals(routingTable.index("idx").shard(0).shards().get(0).state(), INITIALIZING);
    return clusterState;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:24,代码来源:MaxRetryAllocationDeciderTests.java

示例4: testInvalidIndexFolder

import org.elasticsearch.cluster.metadata.MetaData; //导入依赖的package包/类
public void testInvalidIndexFolder() throws Exception {
    try (NodeEnvironment env = newNodeEnvironment()) {
        MetaStateService metaStateService = new MetaStateService(Settings.EMPTY, env, xContentRegistry());
        DanglingIndicesState danglingState = createDanglingIndicesState(env, metaStateService);

        MetaData metaData = MetaData.builder().build();
        final String uuid = "test1UUID";
        final Settings.Builder settings = Settings.builder().put(indexSettings).put(IndexMetaData.SETTING_INDEX_UUID, uuid);
        IndexMetaData dangledIndex = IndexMetaData.builder("test1").settings(settings).build();
        metaStateService.writeIndex("test_write", dangledIndex);
        for (Path path : env.resolveIndexFolder(uuid)) {
            if (Files.exists(path)) {
                Files.move(path, path.resolveSibling("invalidUUID"), StandardCopyOption.ATOMIC_MOVE);
            }
        }
        try {
            danglingState.findNewDanglingIndices(metaData);
            fail("no exception thrown for invalid folder name");
        } catch (IllegalStateException e) {
            assertThat(e.getMessage(), equalTo("[invalidUUID] invalid index folder name, rename to [test1UUID]"));
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:24,代码来源:DanglingIndicesStateTests.java

示例5: readFrom

import org.elasticsearch.cluster.metadata.MetaData; //导入依赖的package包/类
public ClusterState readFrom(StreamInput in, DiscoveryNode localNode) throws IOException {
    ClusterName clusterName = ClusterName.readClusterName(in);
    Builder builder = new Builder(clusterName);
    builder.version = in.readLong();
    builder.uuid = in.readString();
    builder.metaData = MetaData.Builder.readFrom(in);
    builder.routingTable = RoutingTable.Builder.readFrom(in);
    builder.nodes = DiscoveryNodes.Builder.readFrom(in, localNode);
    builder.blocks = ClusterBlocks.Builder.readClusterBlocks(in);
    int customSize = in.readVInt();
    for (int i = 0; i < customSize; i++) {
        String type = in.readString();
        Custom customIndexMetaData = lookupPrototypeSafe(type).readFrom(in);
        builder.putCustom(type, customIndexMetaData);
    }
    return builder.build();
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:18,代码来源:ClusterState.java

示例6: buildTable

import org.elasticsearch.cluster.metadata.MetaData; //导入依赖的package包/类
private Table buildTable(RestRequest request, ClusterStateResponse clusterStateResponse, String patternString) {
    Table table = getTableWithHeader(request);
    MetaData metadata = clusterStateResponse.getState().metaData();
    for (ObjectObjectCursor<String, IndexTemplateMetaData> entry : metadata.templates()) {
        IndexTemplateMetaData indexData = entry.value;
        if (patternString == null || Regex.simpleMatch(patternString, indexData.name())) {
            table.startRow();
            table.addCell(indexData.name());
            table.addCell("[" + String.join(", ", indexData.patterns()) + "]");
            table.addCell(indexData.getOrder());
            table.addCell(indexData.getVersion());
            table.endRow();
        }
    }
    return table;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:RestTemplatesAction.java

示例7: testReadClusterState

import org.elasticsearch.cluster.metadata.MetaData; //导入依赖的package包/类
/**
 * Ensure we can read a pre-generated cluster state.
 */
public void testReadClusterState() throws URISyntaxException, IOException {
    final MetaDataStateFormat<MetaData> format = new MetaDataStateFormat<MetaData>(randomFrom(XContentType.values()), "global-") {

        @Override
        public void toXContent(XContentBuilder builder, MetaData state) throws IOException {
            fail("this test doesn't write");
        }

        @Override
        public MetaData fromXContent(XContentParser parser) throws IOException {
            return MetaData.Builder.fromXContent(parser);
        }
    };
    Path tmp = createTempDir();
    final InputStream resource = this.getClass().getResourceAsStream("global-3.st");
    assertThat(resource, notNullValue());
    Path dst = tmp.resolve("global-3.st");
    Files.copy(resource, dst);
    MetaData read = format.read(xContentRegistry(), dst);
    assertThat(read, notNullValue());
    assertThat(read.clusterUUID(), equalTo("3O1tDF1IRB6fSJ-GrTMUtg"));
    // indices are empty since they are serialized separately
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:27,代码来源:MetaDataStateFormatTests.java

示例8: resolveStatesToBeWritten

import org.elasticsearch.cluster.metadata.MetaData; //导入依赖的package包/类
/**
 * Loads the current meta state for each index in the new cluster state and checks if it has to be persisted.
 * Each index state that should be written to disk will be returned. This is only run for data only nodes.
 * It will return only the states for indices that actually have a shard allocated on the current node.
 *
 * @param previouslyWrittenIndices    A list of indices for which the state was already written before
 * @param potentiallyUnwrittenIndices The list of indices for which state should potentially be written
 * @param previousMetaData            The last meta data we know of. meta data for all indices in previouslyWrittenIndices list is persisted now
 * @param newMetaData                 The new metadata
 * @return iterable over all indices states that should be written to disk
 */
public static Iterable<GatewayMetaState.IndexMetaWriteInfo> resolveStatesToBeWritten(ImmutableSet<String> previouslyWrittenIndices, Set<String> potentiallyUnwrittenIndices, MetaData previousMetaData, MetaData newMetaData) {
    List<GatewayMetaState.IndexMetaWriteInfo> indicesToWrite = new ArrayList<>();
    for (String index : potentiallyUnwrittenIndices) {
        IndexMetaData newIndexMetaData = newMetaData.index(index);
        IndexMetaData previousIndexMetaData = previousMetaData == null ? null : previousMetaData.index(index);
        String writeReason = null;
        if (previouslyWrittenIndices.contains(index) == false || previousIndexMetaData == null) {
            writeReason = "freshly created";
        } else if (previousIndexMetaData.getVersion() != newIndexMetaData.getVersion()) {
            writeReason = "version changed from [" + previousIndexMetaData.getVersion() + "] to [" + newIndexMetaData.getVersion() + "]";
        }
        if (writeReason != null) {
            indicesToWrite.add(new GatewayMetaState.IndexMetaWriteInfo(newIndexMetaData, previousIndexMetaData, writeReason));
        }
    }
    return indicesToWrite;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:29,代码来源:GatewayMetaState.java

示例9: initializeSnapshot

import org.elasticsearch.cluster.metadata.MetaData; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public void initializeSnapshot(SnapshotId snapshotId, List<String> indices, MetaData metaData) {
    if (readOnly()) {
        throw new RepositoryException(this.repositoryName, "cannot create snapshot in a readonly repository");
    }
    try {
        if (snapshotFormat.exists(snapshotsBlobContainer, snapshotId.getSnapshot()) ||
                snapshotLegacyFormat.exists(snapshotsBlobContainer, snapshotId.getSnapshot())) {
            throw new InvalidSnapshotNameException(snapshotId, "snapshot with such name already exists");
        }
        // Write Global MetaData
        globalMetaDataFormat.write(metaData, snapshotsBlobContainer, snapshotId.getSnapshot());
        for (String index : indices) {
            final IndexMetaData indexMetaData = metaData.index(index);
            final BlobPath indexPath = basePath().add("indices").add(index);
            final BlobContainer indexMetaDataBlobContainer = blobStore().blobContainer(indexPath);
            indexMetaDataFormat.write(indexMetaData, indexMetaDataBlobContainer, snapshotId.getSnapshot());
        }
    } catch (IOException ex) {
        throw new SnapshotCreationException(snapshotId, ex);
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:26,代码来源:BlobStoreRepository.java

示例10: testRoutingTableSerialization

import org.elasticsearch.cluster.metadata.MetaData; //导入依赖的package包/类
public void testRoutingTableSerialization() throws Exception {
    MetaData metaData = MetaData.builder()
            .put(IndexMetaData.builder("test").settings(settings(Version.CURRENT)).numberOfShards(10).numberOfReplicas(1))
            .build();

    RoutingTable routingTable = RoutingTable.builder()
            .addAsNew(metaData.index("test"))
            .build();

    DiscoveryNodes nodes = DiscoveryNodes.builder().add(newNode("node1")).add(newNode("node2")).add(newNode("node3")).build();

    ClusterState clusterState = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).nodes(nodes)
        .metaData(metaData).routingTable(routingTable).build();

    AllocationService strategy = createAllocationService();
    RoutingTable source = strategy.reroute(clusterState, "reroute").routingTable();

    BytesStreamOutput outStream = new BytesStreamOutput();
    source.writeTo(outStream);
    StreamInput inStream = outStream.bytes().streamInput();
    RoutingTable target = RoutingTable.readFrom(inStream);

    assertThat(target.toString(), equalTo(source.toString()));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:25,代码来源:ClusterSerializationTests.java

示例11: testClusterStateSerialization

import org.elasticsearch.cluster.metadata.MetaData; //导入依赖的package包/类
public void testClusterStateSerialization() throws Exception {
    MetaData metaData = MetaData.builder()
            .put(IndexMetaData.builder("test").settings(settings(Version.CURRENT)).numberOfShards(10).numberOfReplicas(1))
            .build();

    RoutingTable routingTable = RoutingTable.builder()
            .addAsNew(metaData.index("test"))
            .build();

    DiscoveryNodes nodes = DiscoveryNodes.builder().add(newNode("node1")).add(newNode("node2")).add(newNode("node3")).localNodeId("node1").masterNodeId("node2").build();

    ClusterState clusterState = ClusterState.builder(new ClusterName("clusterName1")).nodes(nodes).metaData(metaData).routingTable(routingTable).build();

    AllocationService strategy = createAllocationService();
    clusterState = ClusterState.builder(clusterState).routingTable(strategy.reroute(clusterState, "reroute").routingTable()).build();

    ClusterState serializedClusterState = ClusterState.Builder.fromBytes(ClusterState.Builder.toBytes(clusterState), newNode("node1"),
        new NamedWriteableRegistry(ClusterModule.getNamedWriteables()));

    assertThat(serializedClusterState.getClusterName().value(), equalTo(clusterState.getClusterName().value()));

    assertThat(serializedClusterState.routingTable().toString(), equalTo(clusterState.routingTable().toString()));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:24,代码来源:ClusterSerializationTests.java

示例12: testIterator1

import org.elasticsearch.cluster.metadata.MetaData; //导入依赖的package包/类
public void testIterator1() {
    MetaData metaData = MetaData.builder()
            .put(IndexMetaData.builder("test1").settings(settings(Version.CURRENT)).numberOfShards(1).numberOfReplicas(2))
            .build();
    RoutingTable routingTable = RoutingTable.builder()
            .addAsNew(metaData.index("test1"))
            .build();

    ShardIterator shardIterator = routingTable.index("test1").shard(0).shardsIt(0);
    assertThat(shardIterator.size(), equalTo(3));
    ShardRouting shardRouting1 = shardIterator.nextOrNull();
    assertThat(shardRouting1, notNullValue());
    assertThat(shardIterator.remaining(), equalTo(2));
    ShardRouting shardRouting2 = shardIterator.nextOrNull();
    assertThat(shardRouting2, notNullValue());
    assertThat(shardIterator.remaining(), equalTo(1));
    assertThat(shardRouting2, not(sameInstance(shardRouting1)));
    ShardRouting shardRouting3 = shardIterator.nextOrNull();
    assertThat(shardRouting3, notNullValue());
    assertThat(shardRouting3, not(sameInstance(shardRouting1)));
    assertThat(shardRouting3, not(sameInstance(shardRouting2)));
    assertThat(shardIterator.nextOrNull(), nullValue());
    assertThat(shardIterator.remaining(), equalTo(0));
    assertThat(shardIterator.nextOrNull(), nullValue());
    assertThat(shardIterator.remaining(), equalTo(0));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:27,代码来源:RoutingIteratorTests.java

示例13: concreteAliases

import org.elasticsearch.cluster.metadata.MetaData; //导入依赖的package包/类
public String[] concreteAliases(MetaData metaData, String concreteIndex) {
    if (expandAliasesWildcards()) {
        //for DELETE we expand the aliases
        String[] indexAsArray = {concreteIndex};
        ImmutableOpenMap<String, List<AliasMetaData>> aliasMetaData = metaData.findAliases(aliases, indexAsArray);
        List<String> finalAliases = new ArrayList<>();
        for (ObjectCursor<List<AliasMetaData>> curAliases : aliasMetaData.values()) {
            for (AliasMetaData aliasMeta: curAliases.value) {
                finalAliases.add(aliasMeta.alias());
            }
        }
        return finalAliases.toArray(new String[finalAliases.size()]);
    } else {
        //for add we just return the current aliases
        return aliases;
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:18,代码来源:IndicesAliasesRequest.java

示例14: testClusterStateSerialization

import org.elasticsearch.cluster.metadata.MetaData; //导入依赖的package包/类
public void testClusterStateSerialization() throws Exception {
    MetaData metaData = MetaData.builder()
            .put(IndexMetaData.builder("test_idx").settings(settings(Version.CURRENT)).numberOfShards(10).numberOfReplicas(1))
            .put(IndexTemplateMetaData.builder("test_template").build())
            .build();

    RoutingTable routingTable = RoutingTable.builder()
            .addAsNew(metaData.index("test_idx"))
            .build();

    DiscoveryNodes nodes = DiscoveryNodes.builder().add(new DiscoveryNode("node_foo", buildNewFakeTransportAddress(),
            emptyMap(), emptySet(), Version.CURRENT)).localNodeId("node_foo").masterNodeId("node_foo").build();

    ClusterState clusterState = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).nodes(nodes)
        .metaData(metaData).routingTable(routingTable).build();

    AllocationService strategy = createAllocationService();
    clusterState = ClusterState.builder(clusterState).routingTable(strategy.reroute(clusterState, "reroute").routingTable()).build();

    String clusterStateString = Strings.toString(clusterState);
    assertNotNull(clusterStateString);

    assertThat(clusterStateString, containsString("test_idx"));
    assertThat(clusterStateString, containsString("test_template"));
    assertThat(clusterStateString, containsString("node_foo"));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:27,代码来源:ClusterStateToStringTests.java

示例15: testIndexAndTombstoneWithSameNameOnStartup

import org.elasticsearch.cluster.metadata.MetaData; //导入依赖的package包/类
/**
 * This test checks an edge case where, if a node had an index (lets call it A with UUID 1), then
 * deleted it (so a tombstone entry for A will exist in the cluster state), then created
 * a new index A with UUID 2, then shutdown, when the node comes back online, it will look at the
 * tombstones for deletions, and it should proceed with trying to delete A with UUID 1 and not
 * throw any errors that the index still exists in the cluster state.  This is a case of ensuring
 * that tombstones that have the same name as current valid indices don't cause confusion by
 * trying to delete an index that exists.
 * See https://github.com/elastic/elasticsearch/issues/18054
 */
public void testIndexAndTombstoneWithSameNameOnStartup() throws Exception {
    final String indexName = "test";
    final Index index = new Index(indexName, UUIDs.randomBase64UUID());
    final IndicesService indicesService = getIndicesService();
    final Settings idxSettings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
                                     .put(IndexMetaData.SETTING_INDEX_UUID, index.getUUID())
                                     .build();
    final IndexMetaData indexMetaData = new IndexMetaData.Builder(index.getName())
                                            .settings(idxSettings)
                                            .numberOfShards(1)
                                            .numberOfReplicas(0)
                                            .build();
    final Index tombstonedIndex = new Index(indexName, UUIDs.randomBase64UUID());
    final IndexGraveyard graveyard = IndexGraveyard.builder().addTombstone(tombstonedIndex).build();
    final MetaData metaData = MetaData.builder().put(indexMetaData, true).indexGraveyard(graveyard).build();
    final ClusterState clusterState = new ClusterState.Builder(new ClusterName("testCluster")).metaData(metaData).build();
    // if all goes well, this won't throw an exception, otherwise, it will throw an IllegalStateException
    indicesService.verifyIndexIsDeleted(tombstonedIndex, clusterState);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:30,代码来源:IndicesServiceTests.java


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