|
@@ -21,6 +21,7 @@ package org.elasticsearch.action.admin.indices.mapping.put;
|
|
|
|
|
|
import org.apache.logging.log4j.message.ParameterizedMessage;
|
|
import org.apache.logging.log4j.message.ParameterizedMessage;
|
|
import org.elasticsearch.action.ActionListener;
|
|
import org.elasticsearch.action.ActionListener;
|
|
|
|
+import org.elasticsearch.action.RequestValidators;
|
|
import org.elasticsearch.action.support.ActionFilters;
|
|
import org.elasticsearch.action.support.ActionFilters;
|
|
import org.elasticsearch.action.support.master.AcknowledgedResponse;
|
|
import org.elasticsearch.action.support.master.AcknowledgedResponse;
|
|
import org.elasticsearch.action.support.master.TransportMasterNodeAction;
|
|
import org.elasticsearch.action.support.master.TransportMasterNodeAction;
|
|
@@ -37,7 +38,8 @@ import org.elasticsearch.index.IndexNotFoundException;
|
|
import org.elasticsearch.threadpool.ThreadPool;
|
|
import org.elasticsearch.threadpool.ThreadPool;
|
|
import org.elasticsearch.transport.TransportService;
|
|
import org.elasticsearch.transport.TransportService;
|
|
|
|
|
|
-import java.util.Collection;
|
|
|
|
|
|
+import java.util.Objects;
|
|
|
|
+import java.util.Optional;
|
|
|
|
|
|
/**
|
|
/**
|
|
* Put mapping action.
|
|
* Put mapping action.
|
|
@@ -45,17 +47,21 @@ import java.util.Collection;
|
|
public class TransportPutMappingAction extends TransportMasterNodeAction<PutMappingRequest, AcknowledgedResponse> {
|
|
public class TransportPutMappingAction extends TransportMasterNodeAction<PutMappingRequest, AcknowledgedResponse> {
|
|
|
|
|
|
private final MetaDataMappingService metaDataMappingService;
|
|
private final MetaDataMappingService metaDataMappingService;
|
|
- private final RequestValidators requestValidators;
|
|
|
|
|
|
+ private final RequestValidators<PutMappingRequest> requestValidators;
|
|
|
|
|
|
@Inject
|
|
@Inject
|
|
- public TransportPutMappingAction(TransportService transportService, ClusterService clusterService,
|
|
|
|
- ThreadPool threadPool, MetaDataMappingService metaDataMappingService,
|
|
|
|
- ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver,
|
|
|
|
- RequestValidators requestValidators) {
|
|
|
|
|
|
+ public TransportPutMappingAction(
|
|
|
|
+ final TransportService transportService,
|
|
|
|
+ final ClusterService clusterService,
|
|
|
|
+ final ThreadPool threadPool,
|
|
|
|
+ final MetaDataMappingService metaDataMappingService,
|
|
|
|
+ final ActionFilters actionFilters,
|
|
|
|
+ final IndexNameExpressionResolver indexNameExpressionResolver,
|
|
|
|
+ final RequestValidators<PutMappingRequest> requestValidators) {
|
|
super(PutMappingAction.NAME, transportService, clusterService, threadPool, actionFilters, indexNameExpressionResolver,
|
|
super(PutMappingAction.NAME, transportService, clusterService, threadPool, actionFilters, indexNameExpressionResolver,
|
|
PutMappingRequest::new);
|
|
PutMappingRequest::new);
|
|
this.metaDataMappingService = metaDataMappingService;
|
|
this.metaDataMappingService = metaDataMappingService;
|
|
- this.requestValidators = requestValidators;
|
|
|
|
|
|
+ this.requestValidators = Objects.requireNonNull(requestValidators);
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -87,9 +93,9 @@ public class TransportPutMappingAction extends TransportMasterNodeAction<PutMapp
|
|
final Index[] concreteIndices = request.getConcreteIndex() == null ?
|
|
final Index[] concreteIndices = request.getConcreteIndex() == null ?
|
|
indexNameExpressionResolver.concreteIndices(state, request)
|
|
indexNameExpressionResolver.concreteIndices(state, request)
|
|
: new Index[] {request.getConcreteIndex()};
|
|
: new Index[] {request.getConcreteIndex()};
|
|
- final Exception validationException = requestValidators.validateRequest(request, state, concreteIndices);
|
|
|
|
- if (validationException != null) {
|
|
|
|
- listener.onFailure(validationException);
|
|
|
|
|
|
+ final Optional<Exception> maybeValidationException = requestValidators.validateRequest(request, state, concreteIndices);
|
|
|
|
+ if (maybeValidationException.isPresent()) {
|
|
|
|
+ listener.onFailure(maybeValidationException.get());
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
PutMappingClusterStateUpdateRequest updateRequest = new PutMappingClusterStateUpdateRequest()
|
|
PutMappingClusterStateUpdateRequest updateRequest = new PutMappingClusterStateUpdateRequest()
|
|
@@ -118,26 +124,4 @@ public class TransportPutMappingAction extends TransportMasterNodeAction<PutMapp
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
- public static class RequestValidators {
|
|
|
|
- private final Collection<MappingRequestValidator> validators;
|
|
|
|
-
|
|
|
|
- public RequestValidators(Collection<MappingRequestValidator> validators) {
|
|
|
|
- this.validators = validators;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- Exception validateRequest(PutMappingRequest request, ClusterState state, Index[] indices) {
|
|
|
|
- Exception firstException = null;
|
|
|
|
- for (MappingRequestValidator validator : validators) {
|
|
|
|
- final Exception e = validator.validateRequest(request, state, indices);
|
|
|
|
- if (e == null) continue;
|
|
|
|
- if (firstException == null) {
|
|
|
|
- firstException = e;
|
|
|
|
- } else {
|
|
|
|
- firstException.addSuppressed(e);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- return firstException;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
}
|
|
}
|