private String[] getIndexesFromEs(final String aliasName){ final AdminClient adminClient = this.provider.getClient().admin(); //remove write alias, can only have one ImmutableOpenMap<String, List<AliasMetaData>> aliasMap = adminClient.indices().getAliases( new GetAliasesRequest( aliasName ) ).actionGet().getAliases(); return aliasMap.keys().toArray( String.class ); }
/** * All the shards (replicas) for all indices in this routing table. * * @return All the shards */ public List<ShardRouting> allShards() { List<ShardRouting> shards = new ArrayList<>(); String[] indices = indicesRouting.keys().toArray(String.class); for (String index : indices) { List<ShardRouting> allShardsIndex = allShards(index); shards.addAll(allShardsIndex); } return shards; }
/** * Get a {@link Map} of the coordinating only nodes (nodes which are neither master, nor data, nor ingest nodes) arranged by their ids * * @return {@link Map} of the coordinating only nodes arranged by their ids */ public ImmutableOpenMap<String, DiscoveryNode> getCoordinatingOnlyNodes() { ImmutableOpenMap.Builder<String, DiscoveryNode> nodes = ImmutableOpenMap.builder(this.nodes); nodes.removeAll(masterNodes.keys()); nodes.removeAll(dataNodes.keys()); nodes.removeAll(ingestNodes.keys()); return nodes.build(); }
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); } } } }
/** * Returns the indices created in this event */ public List<String> indicesCreated() { if (!metaDataChanged()) { return Collections.emptyList(); } List<String> created = null; for (ObjectCursor<String> cursor : state.metaData().indices().keys()) { String index = cursor.value; if (!previousState.metaData().hasIndex(index)) { if (created == null) { created = new ArrayList<>(); } created.add(index); } } return created == null ? Collections.<String>emptyList() : created; }
/** * If the newly created index matches with an index template whose aliases contains the rollover alias, * the rollover alias will point to multiple indices. This causes indexing requests to be rejected. * To avoid this, we make sure that there is no duplicated alias in index templates before creating a new index. */ static void checkNoDuplicatedAliasInIndexTemplate(MetaData metaData, String rolloverIndexName, String rolloverRequestAlias) { final List<IndexTemplateMetaData> matchedTemplates = MetaDataIndexTemplateService.findTemplates(metaData, rolloverIndexName); for (IndexTemplateMetaData template : matchedTemplates) { if (template.aliases().containsKey(rolloverRequestAlias)) { throw new IllegalArgumentException(String.format(Locale.ROOT, "Rollover alias [%s] can point to multiple indices, found duplicated alias [%s] in index template [%s]", rolloverRequestAlias, template.aliases().keys(), template.name())); } } } }
/** * Checks if at least one of the specified aliases exists in the specified concrete indices. Wildcards are supported in the * alias names for partial matches. * * @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 whether at least one of the specified aliases exists in one of the specified concrete indices. */ public boolean hasAliases(final String[] aliases, String[] concreteIndices) { assert aliases != null; assert concreteIndices != null; if (concreteIndices.length == 0) { return false; } 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 (Regex.simpleMatch(aliases, value.alias())) { filteredValues.add(value); } } if (!filteredValues.isEmpty()) { return true; } } return false; }
@Override public ClusterState execute(ClusterState currentState) { Set<String> templateNames = new HashSet<>(); for (ObjectCursor<String> cursor : currentState.metaData().templates().keys()) { String templateName = cursor.value; if (Regex.simpleMatch(request.name, templateName)) { templateNames.add(templateName); } } if (templateNames.isEmpty()) { // if its a match all pattern, and no templates are found (we have none), don't // fail with index missing... if (Regex.isMatchAllPattern(request.name)) { return currentState; } throw new IndexTemplateMissingException(request.name); } MetaData.Builder metaData = MetaData.builder(currentState.metaData()); for (String templateName : templateNames) { logger.info("removing template [{}]", templateName); metaData.removeTemplate(templateName); } return ClusterState.builder(currentState).metaData(metaData).build(); }
if (DiscoveryNode.Role.DATA.getRoleName().equals(matchAttrName)) { if (Booleans.parseBoolean(matchAttrValue, true)) { resolvedNodesIds.addAll(dataNodes.keys()); } else { resolvedNodesIds.removeAll(dataNodes.keys()); resolvedNodesIds.addAll(masterNodes.keys()); } else { resolvedNodesIds.removeAll(masterNodes.keys()); resolvedNodesIds.addAll(ingestNodes.keys()); } else { resolvedNodesIds.removeAll(ingestNodes.keys()); resolvedNodesIds.addAll(getCoordinatingOnlyNodes().keys()); } else { resolvedNodesIds.removeAll(getCoordinatingOnlyNodes().keys());
ObjectLookupContainer<String> nodes = usages.keys(); for (String node : nodeHasPassedWatermark) { if (nodes.contains(node) == false) {
for (ObjectCursor<String> cursor : indexMetaData.getAliases().keys()) { builder.value(cursor.value);
final String[] indices = allocation.routingTable().indicesRouting().keys().toArray(String.class); final float[] deltas = new float[indices.length]; for (int i = 0; i < deltas.length; i++) {
@Override public Set<String> types() { final Set<String> types = new HashSet<>(); for (ObjectCursor<String> cursor : typeToIds.keys()) { types.add(cursor.value); } return types; }
Iterable<String> intersection = HppcMaps.intersection(ObjectHashSet.from(concreteIndices), indices.keys()); for (String index : intersection) { IndexMetaData indexMetaData = indices.get(index);
@Override public void describeMismatchSafely(final ImmutableOpenMap map, final Description mismatchDescription) { if (map.size() == 0) { mismatchDescription.appendText("was empty"); } else { mismatchDescription.appendText("was ").appendValue(map.keys()); } }
public void performStateRecovery(final GatewayStateRecoveredListener listener) throws GatewayException { String[] nodesIds = clusterService.state().nodes().getMasterNodes().keys().toArray(String.class); logger.trace("performing state recovery from {}", Arrays.toString(nodesIds)); TransportNodesListGatewayMetaState.NodesGatewayMetaState nodesState = listGatewayMetaState.list(nodesIds, null).actionGet();
private boolean waitingShardsStartedOrUnassigned(ClusterChangedEvent event) { SnapshotsInProgress curr = event.state().custom(SnapshotsInProgress.TYPE); if (curr != null) { for (SnapshotsInProgress.Entry entry : curr.entries()) { if (entry.state() == State.STARTED && !entry.waitingIndices().isEmpty()) { for (ObjectCursor<String> index : entry.waitingIndices().keys()) { if (event.indexRoutingTableChanged(index.value)) { IndexRoutingTable indexShardRoutingTable = event.state().getRoutingTable().index(index.value); for (ShardId shardId : entry.waitingIndices().get(index.value)) { ShardRouting shardRouting = indexShardRoutingTable.shard(shardId.id()).primaryShard(); if (shardRouting != null && (shardRouting.started() || shardRouting.unassigned())) { return true; } } } } } } } return false; }
public void dropTables(final IndexMetaData indexMetaData) throws RequestExecutionException { String ksName = indexMetaData.keyspace(); for(ObjectCursor<String> cfName : indexMetaData.getMappings().keys()) { dropTable(ksName, cfName.value); } }
public static boolean mappingAlreadyExist(Client client, IndexName indexName, TypeName typeName) { return Iterators.toStream(client.admin() .indices() .prepareGetMappings(indexName.getValue()) .execute() .actionGet() .getMappings() .valuesIt()) .anyMatch(mapping -> mapping.keys().contains(typeName.getValue())); }