org.elasticsearch.cluster.ClusterState.getMetaData()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(10.8k)|赞(0)|评价(0)|浏览(140)

本文整理了Java中org.elasticsearch.cluster.ClusterState.getMetaData()方法的一些代码示例,展示了ClusterState.getMetaData()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ClusterState.getMetaData()方法的具体详情如下:
包路径:org.elasticsearch.cluster.ClusterState
类名称:ClusterState
方法名:getMetaData

ClusterState.getMetaData介绍

暂无

代码示例

代码示例来源:origin: floragunncom/search-guard

private String[] getResolvedIndexPattern(User user, IndexNameExpressionResolver resolver, ClusterService cs) {
  String unresolved = getUnresolvedIndexPattern(user);
  String[] resolved = null;
  if(WildcardMatcher.containsWildcard(unresolved)) {
    final String[] aliasesForPermittedPattern = cs.state().getMetaData().getAliasAndIndexLookup()        
        .entrySet().stream()
        .filter(e->e.getValue().isAlias())
        .filter(e->WildcardMatcher.match(unresolved, e.getKey()))
        .map(e->e.getKey()).toArray(String[]::new);
    
    if(aliasesForPermittedPattern != null && aliasesForPermittedPattern.length > 0) {
      resolved = resolver.concreteIndexNames(cs.state(), IndicesOptions.lenientExpandOpen(), aliasesForPermittedPattern);
    }
  }
  
  if(resolved == null && !unresolved.isEmpty()) {
    resolved = resolver.concreteIndexNames(cs.state(), IndicesOptions.lenientExpandOpen(), unresolved);
  }
  if(resolved == null || resolved.length == 0) {
    return new String[]{unresolved};
  } else {
    //append unresolved value for pattern matching
    String[] retval = Arrays.copyOf(resolved, resolved.length +1);
    retval[retval.length-1] = unresolved;
    return retval;
  }
}

代码示例来源:origin: alibaba/canal

.actionGet()
.getState()
.getMetaData()
.getIndices()
.get(mapping.get_index())

代码示例来源:origin: SonarSource/sonarqube

public void clearIndexes() {
 Loggers.get(getClass()).info("Truncate Elasticsearch indices");
 try {
  esClient.prepareClearCache().get();
  for (String index : esClient.prepareState().get().getState().getMetaData().getConcreteAllIndices()) {
   clearIndex(new IndexType(index, index));
  }
 } catch (Exception e) {
  throw new IllegalStateException("Unable to clear indexes", e);
 }
}

代码示例来源:origin: richardwilly98/elasticsearch-river-mongodb

logger.trace("dropRecreateMapping index[{}] - type[{}]", index, type);
client.admin().indices().prepareRefresh(index).get();
ImmutableOpenMap<String, MappingMetaData> mappings = client.admin().cluster().prepareState().get().getState().getMetaData()
    .index(index).mappings();
logger.trace("mappings contains type {}: {}", type, mappings.containsKey(type));

代码示例来源:origin: Netflix/conductor

private void deleteAllIndices() {
  ImmutableOpenMap<String, IndexMetaData> indices = elasticSearchClient.admin().cluster()
      .prepareState().get().getState()
      .getMetaData().getIndices();
  indices.forEach(cursor -> {
    try {
      elasticSearchClient.admin()
          .indices()
          .delete(new DeleteIndexRequest(cursor.value.getIndex().getName()))
          .get();
    } catch (InterruptedException | ExecutionException e) {
      throw new RuntimeException(e);
    }
  });
}

代码示例来源:origin: org.elasticsearch/elasticsearch

/**
 * @return pipeline configuration specified by id. If multiple ids or wildcards are specified multiple pipelines
 * may be returned
 */
// Returning PipelineConfiguration instead of Pipeline, because Pipeline and Processor interface don't
// know how to serialize themselves.
public static List<PipelineConfiguration> getPipelines(ClusterState clusterState, String... ids) {
  IngestMetadata ingestMetadata = clusterState.getMetaData().custom(IngestMetadata.TYPE);
  return innerGetPipelines(ingestMetadata, ids);
}

代码示例来源:origin: org.elasticsearch/elasticsearch

@Override
  public void clusterStateProcessed(String source, ClusterState oldState, ClusterState newState) {
    if (isAnyTaskUnassigned(newState.getMetaData().custom(PersistentTasksCustomMetaData.TYPE))) {
      periodicRechecker.rescheduleIfNecessary();
    }
  }
});

代码示例来源:origin: org.elasticsearch/elasticsearch

private static PersistentTasksCustomMetaData.Builder builder(ClusterState currentState) {
  return PersistentTasksCustomMetaData.builder(currentState.getMetaData().custom(PersistentTasksCustomMetaData.TYPE));
}

代码示例来源:origin: org.elasticsearch/elasticsearch

static Collection<BiConsumer<DiscoveryNode,ClusterState>> addBuiltInJoinValidators(
  Collection<BiConsumer<DiscoveryNode,ClusterState>> onJoinValidators) {
  Collection<BiConsumer<DiscoveryNode, ClusterState>> validators = new ArrayList<>();
  validators.add((node, state) -> {
    MembershipAction.ensureNodesCompatibility(node.getVersion(), state.getNodes());
    MembershipAction.ensureIndexCompatibility(node.getVersion(), state.getMetaData());
  });
  validators.addAll(onJoinValidators);
  return Collections.unmodifiableCollection(validators);
}

代码示例来源:origin: org.elasticsearch/elasticsearch

@Override
public void runInternal() {
  if (clusterService.localNode().isMasterNode()) {
    final ClusterState state = clusterService.state();
    logger.trace("periodic persistent task assignment check running for cluster state {}", state.getVersion());
    if (isAnyTaskUnassigned(state.getMetaData().custom(PersistentTasksCustomMetaData.TYPE))) {
      reassignPersistentTasks();
    }
  }
}

代码示例来源:origin: org.elasticsearch/elasticsearch

/**
 * Validates snapshot request
 *
 * @param request snapshot request
 * @param state   current cluster state
 */
private void validate(SnapshotRequest request, ClusterState state) {
  RepositoriesMetaData repositoriesMetaData = state.getMetaData().custom(RepositoriesMetaData.TYPE);
  final String repository = request.repositoryName;
  if (repositoriesMetaData == null || repositoriesMetaData.repository(repository) == null) {
    throw new RepositoryMissingException(repository);
  }
  validate(repository, request.snapshotName);
}

代码示例来源:origin: org.elasticsearch/elasticsearch

@Override
  public void onFailure(Exception e) {
    logger.trace("{}: got failure from {}", actionName, shardId);
    int totalNumCopies = clusterState.getMetaData().getIndexSafe(shardId.getIndex()).getNumberOfReplicas() + 1;
    ShardResponse shardResponse = newShardResponse();
    ReplicationResponse.ShardInfo.Failure[] failures;
    if (TransportActions.isShardNotAvailableException(e)) {
      failures = new ReplicationResponse.ShardInfo.Failure[0];
    } else {
      ReplicationResponse.ShardInfo.Failure failure = new ReplicationResponse.ShardInfo.Failure(shardId, null, e,
        ExceptionsHelper.status(e), true);
      failures = new ReplicationResponse.ShardInfo.Failure[totalNumCopies];
      Arrays.fill(failures, failure);
    }
    shardResponse.setShardInfo(new ReplicationResponse.ShardInfo(totalNumCopies, 0, failures));
    shardsResponses.add(shardResponse);
    if (responsesCountDown.countDown()) {
      finishAndNotifyListener(listener, shardsResponses);
    }
  }
};

代码示例来源:origin: org.elasticsearch/elasticsearch

static ClusterState innerPut(PutPipelineRequest request, ClusterState currentState) {
  IngestMetadata currentIngestMetadata = currentState.metaData().custom(IngestMetadata.TYPE);
  Map<String, PipelineConfiguration> pipelines;
  if (currentIngestMetadata != null) {
    pipelines = new HashMap<>(currentIngestMetadata.getPipelines());
  } else {
    pipelines = new HashMap<>();
  }
  pipelines.put(request.getId(), new PipelineConfiguration(request.getId(), request.getSource(), request.getXContentType()));
  ClusterState.Builder newState = ClusterState.builder(currentState);
  newState.metaData(MetaData.builder(currentState.getMetaData())
    .putCustom(IngestMetadata.TYPE, new IngestMetadata(pipelines))
    .build());
  return newState.build();
}

代码示例来源:origin: org.elasticsearch/elasticsearch

@SuppressWarnings("unchecked")
  @Override
  public void clusterStateProcessed(String source, ClusterState oldState, ClusterState newState) {
    PersistentTasksCustomMetaData tasks = newState.getMetaData().custom(PersistentTasksCustomMetaData.TYPE);
    if (tasks != null) {
      PersistentTask<?> task = tasks.getTask(taskId);
      listener.onResponse(task);
      if (task != null && task.isAssigned() == false && periodicRechecker.isScheduled() == false) {
        periodicRechecker.rescheduleIfNecessary();
      }
    } else {
      listener.onResponse(null);
    }
  }
});

代码示例来源:origin: org.elasticsearch/elasticsearch

@Override
  public ClusterState execute(ClusterState currentState) throws Exception {
    ScriptMetaData smd = currentState.metaData().custom(ScriptMetaData.TYPE);
    smd = ScriptMetaData.putStoredScript(smd, request.id(), source);
    MetaData.Builder mdb = MetaData.builder(currentState.getMetaData()).putCustom(ScriptMetaData.TYPE, smd);
    return ClusterState.builder(currentState).metaData(mdb).build();
  }
});

代码示例来源:origin: org.elasticsearch/elasticsearch

@Override
  public ClusterState execute(ClusterState currentState) throws Exception {
    ScriptMetaData smd = currentState.metaData().custom(ScriptMetaData.TYPE);
    smd = ScriptMetaData.deleteStoredScript(smd, request.id());
    MetaData.Builder mdb = MetaData.builder(currentState.getMetaData()).putCustom(ScriptMetaData.TYPE, smd);
    return ClusterState.builder(currentState).metaData(mdb).build();
  }
});

代码示例来源:origin: org.elasticsearch/elasticsearch

@Override
protected void resolveRequest(ClusterState state, InternalRequest request) {
  IndexMetaData indexMeta = state.getMetaData().index(request.concreteIndex());
  // update the routing (request#index here is possibly an alias)
  request.request().routing(state.metaData().resolveIndexRouting(request.request().parent(), request.request().routing(),
    request.request().index()));
  // Fail fast on the node that received the request.
  if (request.request().routing() == null && state.getMetaData().routingRequired(request.concreteIndex(), request.request().type())) {
    throw new RoutingMissingException(request.concreteIndex(), request.request().type(), request.request().id());
  }
}

代码示例来源:origin: org.elasticsearch/elasticsearch

final IndexShardRoutingTable getShardRoutingTable(ShardId shardId, ClusterState state) {
  final IndexRoutingTable indexRoutingTable = state.routingTable().index(shardId.getIndexName());
  if (indexRoutingTable == null) {
    IndexMetaData index = state.getMetaData().index(shardId.getIndex());
    if (index != null && index.getState() == IndexMetaData.State.CLOSE) {
      throw new IndexClosedException(shardId.getIndex());
    }
    throw new IndexNotFoundException(shardId.getIndexName());
  }
  final IndexShardRoutingTable shardRoutingTable = indexRoutingTable.shard(shardId.id());
  if (shardRoutingTable == null) {
    throw new ShardNotFoundException(shardId);
  }
  return shardRoutingTable;
}

代码示例来源:origin: org.elasticsearch/elasticsearch

@Override
protected void resolveRequest(ClusterState state, InternalRequest request) {
  final AliasFilter aliasFilter = searchService.buildAliasFilter(state, request.concreteIndex(),
    request.request().index());
  request.request().filteringAlias(aliasFilter);
  // Fail fast on the node that received the request.
  if (request.request().routing() == null && state.getMetaData().routingRequired(request.concreteIndex(), request.request().type())) {
    throw new RoutingMissingException(request.concreteIndex(), request.request().type(), request.request().id());
  }
}

代码示例来源:origin: org.elasticsearch/elasticsearch

@Override
protected void resolveRequest(ClusterState state, InternalRequest request) {
  // update the routing (request#index here is possibly an alias or a parent)
  request.request().routing(state.metaData()
    .resolveIndexRouting(request.request().parent(), request.request().routing(), request.request().index()));
  // Fail fast on the node that received the request.
  if (request.request().routing() == null && state.getMetaData().routingRequired(request.concreteIndex(), request.request().type())) {
    throw new RoutingMissingException(request.concreteIndex(), request.request().type(), request.request().id());
  }
}

相关文章