&& sgIndex.getMappings() != null && sgIndex.getMappings().get(index) != null && sgIndex.getMappings().get(index).containsKey("config");
private boolean doesMappingExist(final String index, final String mappingName) { GetMappingsRequest request = new GetMappingsRequest() .indices(index); try { GetMappingsResponse response = elasticSearchClient.admin() .indices() .getMappings(request) .get(); return response.getMappings() .get(index) .containsKey(mappingName); } catch (InterruptedException | ExecutionException e) { throw new RuntimeException(e); } }
ImmutableOpenMap<String, MappingMetaData> mappings = client.admin().cluster().prepareState().get().getState().getMetaData() .index(index).mappings(); logger.trace("mappings contains type {}: {}", type, mappings.containsKey(type)); if (mappings.containsKey(type)) {
/** * Determine if a given node id exists * * @param nodeId id of the node which existence should be verified * @return <code>true</code> if the node exists. Otherwise <code>false</code> */ public boolean nodeExists(String nodeId) { return nodes.containsKey(nodeId); }
public boolean hasIndex(String index) { return indices.containsKey(index); }
public boolean hasIndex(String index) { return indicesRouting.containsKey(index); }
public boolean hasIndexBlock(String index, ClusterBlock block) { return indicesBlocks.containsKey(index) && indicesBlocks.get(index).contains(block); }
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 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; }
/** * 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())); } } } }
private boolean hasDeadNodes(RoutingAllocation allocation) { for (RoutingNode routingNode : allocation.routingNodes()) { if (allocation.nodes().getDataNodes().containsKey(routingNode.nodeId()) == false) { return true; } } return false; }
@Override boolean apply(NewAliasValidator aliasValidator, MetaData.Builder metadata, IndexMetaData index) { if (false == index.getAliases().containsKey(alias)) { return false; } metadata.put(IndexMetaData.builder(index).removeAlias(alias)); return true; } }
for (ObjectCursor<IndexMetaData> cursor : indices.values()) { for (String alias: duplicateAliasesIndices) { if (cursor.value.getAliases().containsKey(alias)) { duplicates.add(alias + " (alias of " + cursor.value.getIndex() + ")");
@Override protected void masterOperation(GetIndexTemplatesRequest request, ClusterState state, ActionListener<GetIndexTemplatesResponse> listener) { List<IndexTemplateMetaData> results; // If we did not ask for a specific name, then we return all templates if (request.names().length == 0) { results = Arrays.asList(state.metaData().templates().values().toArray(IndexTemplateMetaData.class)); } else { results = new ArrayList<>(); } for (String name : request.names()) { if (Regex.isSimpleMatchPattern(name)) { for (ObjectObjectCursor<String, IndexTemplateMetaData> entry : state.metaData().templates()) { if (Regex.simpleMatch(name, entry.key)) { results.add(entry.value); } } } else if (state.metaData().templates().containsKey(name)) { results.add(state.metaData().templates().get(name)); } } listener.onResponse(new GetIndexTemplatesResponse(results)); } }
private void deassociateDeadNodes(RoutingAllocation allocation) { for (Iterator<RoutingNode> it = allocation.routingNodes().mutableIterator(); it.hasNext(); ) { RoutingNode node = it.next(); if (allocation.nodes().getDataNodes().containsKey(node.nodeId())) { // its a live node, continue continue; } // now, go over all the shards routing on the node, and fail them for (ShardRouting shardRouting : node.copyShards()) { final IndexMetaData indexMetaData = allocation.metaData().getIndexSafe(shardRouting.index()); boolean delayed = INDEX_DELAYED_NODE_LEFT_TIMEOUT_SETTING.get(indexMetaData.getSettings()).nanos() > 0; UnassignedInfo unassignedInfo = new UnassignedInfo(UnassignedInfo.Reason.NODE_LEFT, "node_left[" + node.nodeId() + "]", null, 0, allocation.getCurrentNanoTime(), System.currentTimeMillis(), delayed, AllocationStatus.NO_ATTEMPT); allocation.routingNodes().failShard(logger, shardRouting, unassignedInfo, indexMetaData, allocation.changes()); } // its a dead node, remove it, note, its important to remove it *after* we apply failed shard // since it relies on the fact that the RoutingNode exists in the list of nodes it.remove(); } }
logger.trace("Removing node from cluster info: {}", removedNode.getId()); if (leastAvailableSpaceUsages.containsKey(removedNode.getId())) { ImmutableOpenMap.Builder<String, DiskUsage> newMaxUsages = ImmutableOpenMap.builder(leastAvailableSpaceUsages); newMaxUsages.remove(removedNode.getId()); leastAvailableSpaceUsages = newMaxUsages.build(); if (mostAvailableSpaceUsages.containsKey(removedNode.getId())) { ImmutableOpenMap.Builder<String, DiskUsage> newMinUsages = ImmutableOpenMap.builder(mostAvailableSpaceUsages); newMinUsages.remove(removedNode.getId());
@Override public ClusterState execute(ClusterState currentState) throws Exception { if (request.create && currentState.metaData().templates().containsKey(request.name)) { throw new IllegalArgumentException("index_template [" + request.name + "] already exists"); } validateAndAddTemplate(request, templateBuilder, indicesService, xContentRegistry); for (Alias alias : request.aliases) { AliasMetaData aliasMetaData = AliasMetaData.builder(alias.name()).filter(alias.filter()) .indexRouting(alias.indexRouting()).searchRouting(alias.searchRouting()).build(); templateBuilder.putAlias(aliasMetaData); } IndexTemplateMetaData template = templateBuilder.build(); MetaData.Builder builder = MetaData.builder(currentState.metaData()).put(template); logger.info("adding template [{}] for index patterns {}", request.name, request.indexPatterns); return ClusterState.builder(currentState).metaData(builder).build(); }
if (!mappings.containsKey(type)) { listener.onResponse(new TypesExistsResponse(false)); return;
String[] indices = indexNameExpressionResolver.concreteIndexNames(currentState, request); for (String filteredIndex : indices) { if (currentState.routingTable().getIndicesRouting().containsKey(filteredIndex)) { routingTableBuilder.add(currentState.routingTable().getIndicesRouting().get(filteredIndex));
@Override public boolean typeExists(String indexName, String type) { return getAdminClient().cluster().prepareState().execute().actionGet().getState().metaData().index(indexName) .getMappings().containsKey(type); }