org.elasticsearch.common.collect.ImmutableOpenMap Java Examples
The following examples show how to use
org.elasticsearch.common.collect.ImmutableOpenMap.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GetIndexResponse.java From Elasticsearch with Apache License 2.0 | 6 votes |
GetIndexResponse(String[] indices, ImmutableOpenMap<String, List<IndexWarmersMetaData.Entry>> warmers, ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> mappings, ImmutableOpenMap<String, List<AliasMetaData>> aliases, ImmutableOpenMap<String, Settings> settings) { this.indices = indices; if (warmers != null) { this.warmers = warmers; } if (mappings != null) { this.mappings = mappings; } if (aliases != null) { this.aliases = aliases; } if (settings != null) { this.settings = settings; } }
Example #2
Source File: GatewayMetaState.java From crate with Apache License 2.0 | 6 votes |
private static <Data> boolean applyPluginUpgraders(ImmutableOpenMap<String, Data> existingData, UnaryOperator<Map<String, Data>> upgrader, Consumer<String> removeData, BiConsumer<String, Data> putData) { // collect current data Map<String, Data> existingMap = new HashMap<>(); for (ObjectObjectCursor<String, Data> customCursor : existingData) { existingMap.put(customCursor.key, customCursor.value); } // upgrade global custom meta data Map<String, Data> upgradedCustoms = upgrader.apply(existingMap); if (upgradedCustoms.equals(existingMap) == false) { // remove all data first so a plugin can remove custom metadata or templates if needed existingMap.keySet().forEach(removeData); for (Map.Entry<String, Data> upgradedCustomEntry : upgradedCustoms.entrySet()) { putData.accept(upgradedCustomEntry.getKey(), upgradedCustomEntry.getValue()); } return true; } return false; }
Example #3
Source File: JoinClusterAction.java From Elasticsearch with Apache License 2.0 | 6 votes |
@Override public ClusterState execute(ClusterState currentState) { DiscoveryNodes.Builder nodesBuilder; nodesBuilder = DiscoveryNodes.builder(currentState.nodes()); if (currentState.nodes().nodeExists(node.id())) { logger.debug("received a join request for an existing node [{}]", node); return currentState; } // If this node is not in dead node list, then ignore this request ImmutableOpenMap<String, DiscoveryNode> deadNodes = clusterService.state().nodes().deadNodes(); if (deadNodes.get(node.getIpPortAddress()) == null) { logger.warn("failed to find node [{}] in node list, ignore the join request", node); throw new IllegalStateException("could not find this node " + node + " from active node list and dead node list"); } nodesBuilder.put(node); nodesBuilder.removeDeadNodeByIpPort(node); final ClusterState.Builder newStateBuilder = ClusterState.builder(currentState); newStateBuilder.nodes(nodesBuilder); ClusterState newState = newStateBuilder.build(); return newState; }
Example #4
Source File: RoutingProvider.java From crate with Apache License 2.0 | 6 votes |
public Routing forRandomMasterOrDataNode(RelationName relationName, DiscoveryNodes nodes) { DiscoveryNode localNode = nodes.getLocalNode(); if (localNode.isMasterNode() || localNode.isDataNode()) { return forTableOnSingleNode(relationName, localNode.getId()); } ImmutableOpenMap<String, DiscoveryNode> masterAndDataNodes = nodes.getMasterAndDataNodes(); int randomIdx = seed % masterAndDataNodes.size(); Iterator<DiscoveryNode> it = masterAndDataNodes.valuesIt(); int currIdx = 0; while (it.hasNext()) { if (currIdx == randomIdx) { return forTableOnSingleNode(relationName, it.next().getId()); } currIdx++; } throw new AssertionError("Cannot find a master or data node with given random index " + randomIdx); }
Example #5
Source File: MetaData.java From Elasticsearch with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") MetaData(String clusterUUID, long version, Settings transientSettings, Settings persistentSettings, ImmutableOpenMap<String, IndexMetaData> indices, ImmutableOpenMap<String, IndexTemplateMetaData> templates, UserMetadata userMetadata, TenantMetadata tenantMetadata, ImmutableOpenMap<String, Custom> customs, String[] allIndices, String[] allOpenIndices, String[] allClosedIndices, SortedMap<String, AliasOrIndex> aliasAndIndexLookup) { this.clusterUUID = clusterUUID; this.version = version; this.transientSettings = transientSettings; this.persistentSettings = persistentSettings; this.settings = Settings.settingsBuilder().put(persistentSettings).put(transientSettings).build(); this.indices = indices; this.customs = customs; this.templates = templates; this.userMetadata = userMetadata; this.tenantMetadata = tenantMetadata; int totalNumberOfShards = 0; int numberOfShards = 0; for (ObjectCursor<IndexMetaData> cursor : indices.values()) { totalNumberOfShards += cursor.value.getTotalNumberOfShards(); numberOfShards += cursor.value.getNumberOfShards(); } this.totalNumberOfShards = totalNumberOfShards; this.numberOfShards = numberOfShards; this.allIndices = allIndices; this.allOpenIndices = allOpenIndices; this.allClosedIndices = allClosedIndices; this.aliasAndIndexLookup = aliasAndIndexLookup; }
Example #6
Source File: RestoreInProgress.java From crate with Apache License 2.0 | 6 votes |
public RestoreInProgress(StreamInput in) throws IOException { Entry[] entries = new Entry[in.readVInt()]; for (int i = 0; i < entries.length; i++) { Snapshot snapshot = new Snapshot(in); State state = State.fromValue(in.readByte()); int indices = in.readVInt(); List<String> indexBuilder = new ArrayList<>(); for (int j = 0; j < indices; j++) { indexBuilder.add(in.readString()); } ImmutableOpenMap.Builder<ShardId, ShardRestoreStatus> builder = ImmutableOpenMap.builder(); int shards = in.readVInt(); for (int j = 0; j < shards; j++) { ShardId shardId = new ShardId(in); ShardRestoreStatus shardState = ShardRestoreStatus.readShardRestoreStatus(in); builder.put(shardId, shardState); } entries[i] = new Entry(snapshot, state, Collections.unmodifiableList(indexBuilder), builder.build()); } this.entries = Arrays.asList(entries); }
Example #7
Source File: RestoreService.java From crate with Apache License 2.0 | 6 votes |
public static RestoreInProgress.State overallState(RestoreInProgress.State nonCompletedState, ImmutableOpenMap<ShardId, RestoreInProgress.ShardRestoreStatus> shards) { boolean hasFailed = false; for (ObjectCursor<RestoreInProgress.ShardRestoreStatus> status : shards.values()) { if (!status.value.state().completed()) { return nonCompletedState; } if (status.value.state() == RestoreInProgress.State.FAILURE) { hasFailed = true; } } if (hasFailed) { return RestoreInProgress.State.FAILURE; } else { return RestoreInProgress.State.SUCCESS; } }
Example #8
Source File: MockInternalClusterInfoService.java From crate with Apache License 2.0 | 6 votes |
@Override protected CountDownLatch updateNodeStats(ActionListener<NodesStatsResponse> listener) { return super.updateNodeStats(new ActionListener<>() { @Override public void onResponse(NodesStatsResponse nodesStatsResponse) { ImmutableOpenMap.Builder<String, DiskUsage> leastAvailableUsagesBuilder = ImmutableOpenMap.builder(); ImmutableOpenMap.Builder<String, DiskUsage> mostAvailableUsagesBuilder = ImmutableOpenMap.builder(); fillDiskUsagePerNode( LOGGER, adjustNodesStats(nodesStatsResponse.getNodes()), leastAvailableUsagesBuilder, mostAvailableUsagesBuilder ); leastAvailableSpaceUsages = leastAvailableUsagesBuilder.build(); mostAvailableSpaceUsages = mostAvailableUsagesBuilder.build(); } @Override public void onFailure(Exception e) { } }); }
Example #9
Source File: DiffableUtils.java From crate with Apache License 2.0 | 6 votes |
public ImmutableOpenMapDiff(ImmutableOpenMap<K, T> before, ImmutableOpenMap<K, T> after, KeySerializer<K> keySerializer, ValueSerializer<K, T> valueSerializer) { super(keySerializer, valueSerializer); assert after != null && before != null; for (ObjectCursor<K> key : before.keys()) { if (!after.containsKey(key.value)) { deletes.add(key.value); } } for (ObjectObjectCursor<K, T> partIter : after) { T beforePart = before.get(partIter.key); if (beforePart == null) { upserts.put(partIter.key, partIter.value); } else if (partIter.value.equals(beforePart) == false) { if (valueSerializer.supportsDiffableValues()) { diffs.put(partIter.key, valueSerializer.diff(partIter.value, beforePart)); } else { upserts.put(partIter.key, partIter.value); } } } }
Example #10
Source File: GetMappingsResponse.java From Elasticsearch with Apache License 2.0 | 6 votes |
@Override public void readFrom(StreamInput in) throws IOException { super.readFrom(in); int size = in.readVInt(); ImmutableOpenMap.Builder<String, ImmutableOpenMap<String, MappingMetaData>> indexMapBuilder = ImmutableOpenMap.builder(); for (int i = 0; i < size; i++) { String key = in.readString(); int valueSize = in.readVInt(); ImmutableOpenMap.Builder<String, MappingMetaData> typeMapBuilder = ImmutableOpenMap.builder(); for (int j = 0; j < valueSize; j++) { typeMapBuilder.put(in.readString(), MappingMetaData.PROTO.readFrom(in)); } indexMapBuilder.put(key, typeMapBuilder.build()); } mappings = indexMapBuilder.build(); }
Example #11
Source File: IndexAdmin.java From search-spring-boot-starter with Apache License 2.0 | 6 votes |
/** * 装载索引数据结构 * * @param index * @param type * @return */ private String loadIndexStruct(String index, String type) { ClusterStateResponse response = client.admin().cluster().prepareState().execute().actionGet(); ImmutableOpenMap<String, IndexMetaData> immutableOpenMap = response.getState().getMetaData().getIndices(); if (immutableOpenMap != null) { IndexMetaData metaData = immutableOpenMap.get(index); if (metaData != null) { ImmutableOpenMap<String, MappingMetaData> mappings = metaData.getMappings(); if (mappings != null) { MappingMetaData mappingMetaData = mappings.get(type); if (mappingMetaData != null) { CompressedXContent content = mappingMetaData.source(); if (content != null) { return content.toString(); } } } } } LOGGER.error("获取ES数据结构失败 index:" + index + "|type:" + type); return null; }
Example #12
Source File: SnapshotsInProgress.java From crate with Apache License 2.0 | 5 votes |
public SnapshotsInProgress(StreamInput in) throws IOException { Entry[] entries = new Entry[in.readVInt()]; for (int i = 0; i < entries.length; i++) { final Snapshot snapshot = new Snapshot(in); final boolean includeGlobalState = in.readBoolean(); final boolean partial = in.readBoolean(); final State state = State.fromValue(in.readByte()); int indices = in.readVInt(); List<IndexId> indexBuilder = new ArrayList<>(); for (int j = 0; j < indices; j++) { indexBuilder.add(new IndexId(in.readString(), in.readString())); } final long startTime = in.readLong(); ImmutableOpenMap.Builder<ShardId, ShardSnapshotStatus> builder = ImmutableOpenMap.builder(); final int shards = in.readVInt(); for (int j = 0; j < shards; j++) { ShardId shardId = new ShardId(in); builder.put(shardId, new ShardSnapshotStatus(in)); } final long repositoryStateId = in.readLong(); final String failure = in.readOptionalString(); final boolean useShardGenerations; if (in.getVersion().onOrAfter(SnapshotsService.SHARD_GEN_IN_REPO_DATA_VERSION)) { useShardGenerations = in.readBoolean(); } else { useShardGenerations = false; } entries[i] = new Entry(snapshot, includeGlobalState, partial, state, Collections.unmodifiableList(indexBuilder), startTime, repositoryStateId, builder.build(), failure, useShardGenerations); } this.entries = Arrays.asList(entries); }
Example #13
Source File: DiskThresholdDecider.java From crate with Apache License 2.0 | 5 votes |
/** * Returns a {@link DiskUsage} for the {@link RoutingNode} using the * average usage of other nodes in the disk usage map. * @param node Node to return an averaged DiskUsage object for * @param usages Map of nodeId to DiskUsage for all known nodes * @return DiskUsage representing given node using the average disk usage */ DiskUsage averageUsage(RoutingNode node, ImmutableOpenMap<String, DiskUsage> usages) { if (usages.size() == 0) { return new DiskUsage(node.nodeId(), node.node().getName(), "_na_", 0, 0); } long totalBytes = 0; long freeBytes = 0; for (ObjectCursor<DiskUsage> du : usages.values()) { totalBytes += du.value.getTotalBytes(); freeBytes += du.value.getFreeBytes(); } return new DiskUsage(node.nodeId(), node.node().getName(), "_na_", totalBytes / usages.size(), freeBytes / usages.size()); }
Example #14
Source File: ElasticsearchTemplate.java From summerframework with Apache License 2.0 | 5 votes |
public List<Map<String, Object>> getAllMapping(String index) throws IOException { List<Map<String, Object>> result = new ArrayList<>(); ImmutableOpenMap<String, MappingMetaData> mappings = esClient.admin().cluster().prepareState().execute() .actionGet().getState().getMetaData().getIndices().get(index).getMappings(); for (ObjectObjectCursor<String, MappingMetaData> cursor : mappings) { log.info("type is:{}", cursor.key); result.add(cursor.value.getSourceAsMap()); } return result; }
Example #15
Source File: Elasticsearch2Client.java From presto-connectors with Apache License 2.0 | 5 votes |
@Override public ElasticsearchTable getTable(SchemaTableName tableName) { String indexWildcard = tableName.getTableName(); GetIndexRequest getIndexRequest = createGetIndexRequest(indexWildcard); //----es scher error -- Thread.currentThread().setName("getTable_001"); GetIndexResponse response = client.admin().indices() .getIndex(getIndexRequest).actionGet(); if (response.getIndices() == null || response.getIndices().length == 0) { return null; } //TODO: es中运行index名访问时可以使用*进行匹配,所以可能会返回多个index的mapping, 因此下面需要进行mapping merge test table = test1"*" ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> mappings = response.getMappings(); List<IndexResolution> resolutions; if (mappings.size() > 0) { resolutions = new ArrayList<>(mappings.size()); for (ObjectObjectCursor<String, ImmutableOpenMap<String, MappingMetaData>> indexMappings : mappings) { resolutions.add(buildGetIndexResult(indexMappings.key, indexMappings.value)); } } else { resolutions = emptyList(); } IndexResolution indexWithMerged = merge(resolutions, indexWildcard); return new ElasticsearchTable(typeManager, tableName.getSchemaName(), tableName.getTableName(), indexWithMerged.get()); }
Example #16
Source File: IndexTemplateMetaData.java From crate with Apache License 2.0 | 5 votes |
public Builder(IndexTemplateMetaData indexTemplateMetaData) { this.name = indexTemplateMetaData.name(); order(indexTemplateMetaData.order()); version(indexTemplateMetaData.version()); patterns(indexTemplateMetaData.patterns()); settings(indexTemplateMetaData.settings()); mappings = ImmutableOpenMap.builder(indexTemplateMetaData.mappings()); aliases = ImmutableOpenMap.builder(indexTemplateMetaData.aliases()); }
Example #17
Source File: DiskThresholdDeciderTests.java From crate with Apache License 2.0 | 5 votes |
@Test public void testAverageUsage() { RoutingNode rn = new RoutingNode("node1", newNode("node1")); DiskThresholdDecider decider = makeDecider(Settings.EMPTY); ImmutableOpenMap.Builder<String, DiskUsage> usages = ImmutableOpenMap.builder(); usages.put("node2", new DiskUsage("node2", "n2", "/dev/null", 100, 50)); // 50% used usages.put("node3", new DiskUsage("node3", "n3", "/dev/null", 100, 0)); // 100% used DiskUsage node1Usage = decider.averageUsage(rn, usages.build()); assertThat(node1Usage.getTotalBytes(), equalTo(100L)); assertThat(node1Usage.getFreeBytes(), equalTo(25L)); }
Example #18
Source File: ClusterCreation.java From anomaly-detection with Apache License 2.0 | 5 votes |
/** * Create data node map * @param numDataNodes the number of data nodes * @return data nodes map * * TODO: ModelManagerTests has the same method. Refactor. */ public static ImmutableOpenMap<String, DiscoveryNode> createDataNodes(int numDataNodes) { ImmutableOpenMap.Builder<String, DiscoveryNode> dataNodes = ImmutableOpenMap.builder(); for (int i = 0; i < numDataNodes; i++) { dataNodes.put("foo" + i, mock(DiscoveryNode.class)); } return dataNodes.build(); }
Example #19
Source File: TransportIndicesShardStoresAction.java From Elasticsearch with Apache License 2.0 | 5 votes |
void finish() { ImmutableOpenMap.Builder<String, ImmutableOpenIntMap<java.util.List<IndicesShardStoresResponse.StoreStatus>>> indicesStoreStatusesBuilder = ImmutableOpenMap.builder(); java.util.List<IndicesShardStoresResponse.Failure> failureBuilder = new ArrayList<>(); for (Response fetchResponse : fetchResponses) { ImmutableOpenIntMap<java.util.List<IndicesShardStoresResponse.StoreStatus>> indexStoreStatuses = indicesStoreStatusesBuilder.get(fetchResponse.shardId.getIndex()); final ImmutableOpenIntMap.Builder<java.util.List<IndicesShardStoresResponse.StoreStatus>> indexShardsBuilder; if (indexStoreStatuses == null) { indexShardsBuilder = ImmutableOpenIntMap.builder(); } else { indexShardsBuilder = ImmutableOpenIntMap.builder(indexStoreStatuses); } java.util.List<IndicesShardStoresResponse.StoreStatus> storeStatuses = indexShardsBuilder.get(fetchResponse.shardId.id()); if (storeStatuses == null) { storeStatuses = new ArrayList<>(); } for (NodeGatewayStartedShards response : fetchResponse.responses) { if (shardExistsInNode(response)) { IndicesShardStoresResponse.StoreStatus.Allocation allocation = getAllocation(fetchResponse.shardId.getIndex(), fetchResponse.shardId.id(), response.getNode()); storeStatuses.add(new IndicesShardStoresResponse.StoreStatus(response.getNode(), response.version(), allocation, response.storeException())); } } CollectionUtil.timSort(storeStatuses); indexShardsBuilder.put(fetchResponse.shardId.id(), storeStatuses); indicesStoreStatusesBuilder.put(fetchResponse.shardId.getIndex(), indexShardsBuilder.build()); for (FailedNodeException failure : fetchResponse.failures) { failureBuilder.add(new IndicesShardStoresResponse.Failure(failure.nodeId(), fetchResponse.shardId.getIndex(), fetchResponse.shardId.id(), failure.getCause())); } } listener.onResponse(new IndicesShardStoresResponse(indicesStoreStatusesBuilder.build(), Collections.unmodifiableList(failureBuilder))); }
Example #20
Source File: ClusterBlocks.java From crate with Apache License 2.0 | 5 votes |
public ClusterBlocks(StreamInput in) throws IOException { Set<ClusterBlock> global = readBlockSet(in); int size = in.readVInt(); ImmutableOpenMap.Builder<String, Set<ClusterBlock>> indicesBuilder = ImmutableOpenMap.builder(size); for (int j = 0; j < size; j++) { indicesBuilder.put(in.readString().intern(), readBlockSet(in)); } this.global = global; this.indicesBlocks = indicesBuilder.build(); levelHolders = generateLevelHolders(global, indicesBlocks); }
Example #21
Source File: MetaData.java From crate with Apache License 2.0 | 5 votes |
public Builder() { clusterUUID = UNKNOWN_CLUSTER_UUID; indices = ImmutableOpenMap.builder(); templates = ImmutableOpenMap.builder(); customs = ImmutableOpenMap.builder(); indexGraveyard(IndexGraveyard.builder().build()); // create new empty index graveyard to initialize }
Example #22
Source File: SnapshotsInProgressSerializationTests.java From crate with Apache License 2.0 | 5 votes |
private Entry randomSnapshot() { Snapshot snapshot = new Snapshot(randomAlphaOfLength(10), new SnapshotId(randomAlphaOfLength(10), randomAlphaOfLength(10))); boolean includeGlobalState = randomBoolean(); boolean partial = randomBoolean(); State state = randomFrom(State.values()); int numberOfIndices = randomIntBetween(0, 10); List<IndexId> indices = new ArrayList<>(); for (int i = 0; i < numberOfIndices; i++) { indices.add(new IndexId(randomAlphaOfLength(10), randomAlphaOfLength(10))); } long startTime = randomLong(); long repositoryStateId = randomLong(); ImmutableOpenMap.Builder<ShardId, SnapshotsInProgress.ShardSnapshotStatus> builder = ImmutableOpenMap.builder(); final List<Index> esIndices = indices.stream().map(i -> new Index(i.getName(), randomAlphaOfLength(10))).collect(Collectors.toList()); for (Index idx : esIndices) { int shardsCount = randomIntBetween(1, 10); for (int j = 0; j < shardsCount; j++) { ShardId shardId = new ShardId(idx, j); String nodeId = randomAlphaOfLength(10); ShardState shardState = randomFrom(ShardState.values()); builder.put(shardId, new SnapshotsInProgress.ShardSnapshotStatus(nodeId, shardState, shardState.failed() ? randomAlphaOfLength( 10) : null, randomAlphaOfLength(10))); } } ImmutableOpenMap<ShardId, SnapshotsInProgress.ShardSnapshotStatus> shards = builder.build(); return new Entry(snapshot, includeGlobalState, partial, state, indices, startTime, repositoryStateId, shards, randomBoolean()); }
Example #23
Source File: RestoreInProgress.java From crate with Apache License 2.0 | 5 votes |
/** * Creates new restore metadata * * @param snapshot snapshot * @param state current state of the restore process * @param indices list of indices being restored * @param shards map of shards being restored to their current restore status */ public Entry(Snapshot snapshot, State state, List<String> indices, ImmutableOpenMap<ShardId, ShardRestoreStatus> shards) { this.snapshot = Objects.requireNonNull(snapshot); this.state = Objects.requireNonNull(state); this.indices = Objects.requireNonNull(indices); if (shards == null) { this.shards = ImmutableOpenMap.of(); } else { this.shards = shards; } }
Example #24
Source File: ClusterState.java From Elasticsearch with Apache License 2.0 | 5 votes |
public ClusterState(ClusterName clusterName, long version, String stateUUID, MetaData metaData, RoutingTable routingTable, DiscoveryNodes nodes, ClusterBlocks blocks, ImmutableOpenMap<String, Custom> customs, boolean wasReadFromDiff) { this.version = version; this.stateUUID = stateUUID; this.clusterName = clusterName; this.metaData = metaData; this.routingTable = routingTable; this.nodes = nodes; this.blocks = blocks; this.customs = customs; this.status = ClusterStateStatus.UNKNOWN; this.wasReadFromDiff = wasReadFromDiff; }
Example #25
Source File: MetaData.java From Elasticsearch with Apache License 2.0 | 5 votes |
/** * Finds the specific index aliases that match with the specified aliases directly or partially via wildcards and * that point to the specified concrete indices or match partially with the indices via wildcards. * * @param aliases The names of the index aliases to find * @param concreteIndices The concrete indexes the index aliases must point to order to be returned. * @return the found index aliases grouped by index */ public ImmutableOpenMap<String, List<AliasMetaData>> findAliases(final String[] aliases, String[] concreteIndices) { assert aliases != null; assert concreteIndices != null; if (concreteIndices.length == 0) { return ImmutableOpenMap.of(); } boolean matchAllAliases = matchAllAliases(aliases); ImmutableOpenMap.Builder<String, List<AliasMetaData>> mapBuilder = ImmutableOpenMap.builder(); Iterable<String> intersection = HppcMaps.intersection(ObjectHashSet.from(concreteIndices), indices.keys()); for (String index : intersection) { IndexMetaData indexMetaData = indices.get(index); List<AliasMetaData> filteredValues = new ArrayList<>(); for (ObjectCursor<AliasMetaData> cursor : indexMetaData.getAliases().values()) { AliasMetaData value = cursor.value; if (matchAllAliases || Regex.simpleMatch(aliases, value.alias())) { filteredValues.add(value); } } if (!filteredValues.isEmpty()) { // Make the list order deterministic CollectionUtil.timSort(filteredValues, new Comparator<AliasMetaData>() { @Override public int compare(AliasMetaData o1, AliasMetaData o2) { return o1.alias().compareTo(o2.alias()); } }); mapBuilder.put(index, Collections.unmodifiableList(filteredValues)); } } return mapBuilder.build(); }
Example #26
Source File: ShowTest.java From elasticsearch-sql with Apache License 2.0 | 5 votes |
@Test public void showAll_atLeastOneIndexReturns() throws SqlParseException, SQLFeatureNotSupportedException, IOException { String query = "show *"; GetIndexResponse getIndexResponse = runShowQuery(query); ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetadata>> mappings = getIndexResponse.getMappings(); Assert.assertTrue(mappings.size() >= 1); }
Example #27
Source File: MetaData.java From crate with Apache License 2.0 | 5 votes |
/** * Finds the specific index aliases that match with the specified aliases directly or partially via wildcards and * that point to the specified concrete indices or match partially with the indices via wildcards. * * @param aliases The names of the index aliases to find * @param concreteIndices The concrete indexes the index aliases must point to order to be returned. * @return a map of index to a list of alias metadata, the list corresponding to a concrete index will be empty if no aliases are * present for that index */ public ImmutableOpenMap<String, List<AliasMetaData>> findAliases(final String[] aliases, String[] concreteIndices) { assert aliases != null; assert concreteIndices != null; if (concreteIndices.length == 0) { return ImmutableOpenMap.of(); } boolean matchAllAliases = matchAllAliases(aliases); ImmutableOpenMap.Builder<String, List<AliasMetaData>> mapBuilder = ImmutableOpenMap.builder(); for (String index : concreteIndices) { IndexMetaData indexMetaData = indices.get(index); List<AliasMetaData> filteredValues = new ArrayList<>(); for (ObjectCursor<AliasMetaData> cursor : indexMetaData.getAliases().values()) { AliasMetaData value = cursor.value; if (matchAllAliases || Regex.simpleMatch(aliases, value.alias())) { filteredValues.add(value); } } if (filteredValues.isEmpty() == false) { // Make the list order deterministic CollectionUtil.timSort(filteredValues, Comparator.comparing(AliasMetaData::alias)); mapBuilder.put(index, Collections.unmodifiableList(filteredValues)); } } return mapBuilder.build(); }
Example #28
Source File: IndexMetaData.java From Elasticsearch with Apache License 2.0 | 5 votes |
public IndexMetaData build() { ImmutableOpenMap.Builder<String, AliasMetaData> tmpAliases = aliases; Settings tmpSettings = settings; // update default mapping on the MappingMetaData if (mappings.containsKey(MapperService.DEFAULT_MAPPING)) { MappingMetaData defaultMapping = mappings.get(MapperService.DEFAULT_MAPPING); for (ObjectCursor<MappingMetaData> cursor : mappings.values()) { cursor.value.updateDefaultMapping(defaultMapping); } } return new IndexMetaData(index, version, state, tmpSettings, mappings.build(), tmpAliases.build(), customs.build(), indexOwnerTenantId); }
Example #29
Source File: IndexTemplateMetaData.java From Elasticsearch with Apache License 2.0 | 5 votes |
public IndexTemplateMetaData(String name, int order, String template, Settings settings, ImmutableOpenMap<String, CompressedXContent> mappings, ImmutableOpenMap<String, AliasMetaData> aliases, ImmutableOpenMap<String, IndexMetaData.Custom> customs, long templateOwnerTenantId) { this.name = name; this.order = order; this.template = template; this.settings = settings; this.mappings = mappings; this.aliases = aliases; this.customs = customs; this.templateOwnerTenantId = templateOwnerTenantId; }
Example #30
Source File: DefaultTemplateService.java From crate with Apache License 2.0 | 5 votes |
@VisibleForTesting static ClusterState addDefaultTemplate(ClusterState currentState) throws IOException { MetaData currentMetaData = currentState.getMetaData(); ImmutableOpenMap<String, IndexTemplateMetaData> currentTemplates = currentMetaData.getTemplates(); ImmutableOpenMap<String, IndexTemplateMetaData> newTemplates = createCopyWithDefaultTemplateAdded(currentTemplates); MetaData.Builder mdBuilder = MetaData.builder(currentMetaData).templates(newTemplates); return ClusterState.builder(currentState).metaData(mdBuilder).build(); }