Search in sources :

Example 31 with Supplier

use of org.apache.logging.log4j.util.Supplier in project elasticsearch by elastic.

the class TransportShardMultiGetAction method shardOperation.

@Override
protected MultiGetShardResponse shardOperation(MultiGetShardRequest request, ShardId shardId) {
    IndexService indexService = indicesService.indexServiceSafe(shardId.getIndex());
    IndexShard indexShard = indexService.getShard(shardId.id());
    if (request.refresh() && !request.realtime()) {
        indexShard.refresh("refresh_flag_mget");
    }
    MultiGetShardResponse response = new MultiGetShardResponse();
    for (int i = 0; i < request.locations.size(); i++) {
        MultiGetRequest.Item item = request.items.get(i);
        try {
            GetResult getResult = indexShard.getService().get(item.type(), item.id(), item.storedFields(), request.realtime(), item.version(), item.versionType(), item.fetchSourceContext());
            response.add(request.locations.get(i), new GetResponse(getResult));
        } catch (Exception e) {
            if (TransportActions.isShardNotAvailableException(e)) {
                throw (ElasticsearchException) e;
            } else {
                logger.debug((Supplier<?>) () -> new ParameterizedMessage("{} failed to execute multi_get for [{}]/[{}]", shardId, item.type(), item.id()), e);
                response.add(request.locations.get(i), new MultiGetResponse.Failure(request.index(), item.type(), item.id(), e));
            }
        }
    }
    return response;
}
Also used : GetResult(org.elasticsearch.index.get.GetResult) IndexService(org.elasticsearch.index.IndexService) IndexShard(org.elasticsearch.index.shard.IndexShard) Supplier(org.apache.logging.log4j.util.Supplier) ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage) ElasticsearchException(org.elasticsearch.ElasticsearchException)

Example 32 with Supplier

use of org.apache.logging.log4j.util.Supplier in project elasticsearch by elastic.

the class TransportPutIndexTemplateAction method masterOperation.

@Override
protected void masterOperation(final PutIndexTemplateRequest request, final ClusterState state, final ActionListener<PutIndexTemplateResponse> listener) {
    String cause = request.cause();
    if (cause.length() == 0) {
        cause = "api";
    }
    final Settings.Builder templateSettingsBuilder = Settings.builder();
    templateSettingsBuilder.put(request.settings()).normalizePrefix(IndexMetaData.INDEX_SETTING_PREFIX);
    indexScopedSettings.validate(templateSettingsBuilder);
    indexTemplateService.putTemplate(new MetaDataIndexTemplateService.PutRequest(cause, request.name()).patterns(request.patterns()).order(request.order()).settings(templateSettingsBuilder.build()).mappings(request.mappings()).aliases(request.aliases()).customs(request.customs()).create(request.create()).masterTimeout(request.masterNodeTimeout()).version(request.version()), new MetaDataIndexTemplateService.PutListener() {

        @Override
        public void onResponse(MetaDataIndexTemplateService.PutResponse response) {
            listener.onResponse(new PutIndexTemplateResponse(response.acknowledged()));
        }

        @Override
        public void onFailure(Exception e) {
            logger.debug((Supplier<?>) () -> new ParameterizedMessage("failed to put template [{}]", request.name()), e);
            listener.onFailure(e);
        }
    });
}
Also used : Supplier(org.apache.logging.log4j.util.Supplier) ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage) IndexScopedSettings(org.elasticsearch.common.settings.IndexScopedSettings) Settings(org.elasticsearch.common.settings.Settings) ClusterBlockException(org.elasticsearch.cluster.block.ClusterBlockException) MetaDataIndexTemplateService(org.elasticsearch.cluster.metadata.MetaDataIndexTemplateService)

Example 33 with Supplier

use of org.apache.logging.log4j.util.Supplier in project elasticsearch by elastic.

the class TransportUpgradeSettingsAction method masterOperation.

@Override
protected void masterOperation(final UpgradeSettingsRequest request, final ClusterState state, final ActionListener<UpgradeSettingsResponse> listener) {
    UpgradeSettingsClusterStateUpdateRequest clusterStateUpdateRequest = new UpgradeSettingsClusterStateUpdateRequest().ackTimeout(request.timeout()).versions(request.versions()).masterNodeTimeout(request.masterNodeTimeout());
    updateSettingsService.upgradeIndexSettings(clusterStateUpdateRequest, new ActionListener<ClusterStateUpdateResponse>() {

        @Override
        public void onResponse(ClusterStateUpdateResponse response) {
            listener.onResponse(new UpgradeSettingsResponse(response.isAcknowledged()));
        }

        @Override
        public void onFailure(Exception t) {
            logger.debug((Supplier<?>) () -> new ParameterizedMessage("failed to upgrade minimum compatibility version settings on indices [{}]", request.versions().keySet()), t);
            listener.onFailure(t);
        }
    });
}
Also used : Supplier(org.apache.logging.log4j.util.Supplier) ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage) ClusterStateUpdateResponse(org.elasticsearch.cluster.ack.ClusterStateUpdateResponse) ClusterBlockException(org.elasticsearch.cluster.block.ClusterBlockException)

Example 34 with Supplier

use of org.apache.logging.log4j.util.Supplier in project elasticsearch by elastic.

the class MetaDataMappingService method refreshMapping.

/**
     * Refreshes mappings if they are not the same between original and parsed version
     */
public void refreshMapping(final String index, final String indexUUID) {
    final RefreshTask refreshTask = new RefreshTask(index, indexUUID);
    clusterService.submitStateUpdateTask("refresh-mapping", refreshTask, ClusterStateTaskConfig.build(Priority.HIGH), refreshExecutor, (source, e) -> logger.warn((Supplier<?>) () -> new ParameterizedMessage("failure during [{}]", source), e));
}
Also used : Supplier(org.apache.logging.log4j.util.Supplier) ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage)

Example 35 with Supplier

use of org.apache.logging.log4j.util.Supplier in project elasticsearch by elastic.

the class NodeConnectionsService method validateAndConnectIfNeeded.

void validateAndConnectIfNeeded(DiscoveryNode node) {
    assert nodeLocks.isHeldByCurrentThread(node) : "validateAndConnectIfNeeded must be called under lock";
    if (lifecycle.stoppedOrClosed() || nodes.containsKey(node) == false) {
    // we double check existence of node since connectToNode might take time...
    // nothing to do
    } else {
        try {
            // connecting to an already connected node is a noop
            transportService.connectToNode(node);
            nodes.put(node, 0);
        } catch (Exception e) {
            Integer nodeFailureCount = nodes.get(node);
            assert nodeFailureCount != null : node + " didn't have a counter in nodes map";
            nodeFailureCount = nodeFailureCount + 1;
            // log every 6th failure
            if ((nodeFailureCount % 6) == 1) {
                final int finalNodeFailureCount = nodeFailureCount;
                logger.warn((Supplier<?>) () -> new ParameterizedMessage("failed to connect to node {} (tried [{}] times)", node, finalNodeFailureCount), e);
            }
            nodes.put(node, nodeFailureCount);
        }
    }
}
Also used : Supplier(org.apache.logging.log4j.util.Supplier) ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage)

Aggregations

Supplier (org.apache.logging.log4j.util.Supplier)94 ParameterizedMessage (org.apache.logging.log4j.message.ParameterizedMessage)91 IOException (java.io.IOException)55 ElasticsearchException (org.elasticsearch.ElasticsearchException)27 ArrayList (java.util.ArrayList)25 ClusterState (org.elasticsearch.cluster.ClusterState)21 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)21 TimeValue (org.elasticsearch.common.unit.TimeValue)14 HashMap (java.util.HashMap)12 Map (java.util.Map)11 Settings (org.elasticsearch.common.settings.Settings)11 TransportException (org.elasticsearch.transport.TransportException)11 List (java.util.List)10 ExecutionException (java.util.concurrent.ExecutionException)10 Index (org.elasticsearch.index.Index)10 CountDownLatch (java.util.concurrent.CountDownLatch)9 NotMasterException (org.elasticsearch.cluster.NotMasterException)8 ClusterStateUpdateResponse (org.elasticsearch.cluster.ack.ClusterStateUpdateResponse)8 ClusterBlockException (org.elasticsearch.cluster.block.ClusterBlockException)8 NoSuchFileException (java.nio.file.NoSuchFileException)7