audit index creation after it the index has been created (#51479)
moves audit message for index creation after the index has been successfully created. This has been confusing for a user where index creation failed but audit reported index creation.
This commit is contained in:
parent
4f3548fbd7
commit
bebce4b190
|
@ -181,7 +181,7 @@ public class TransportStartTransformAction extends TransportMasterNodeAction<Sta
|
|||
}, listener::onFailure);
|
||||
|
||||
// <4> Create the task in cluster state so that it will start executing on the node
|
||||
ActionListener<Void> createOrGetIndexListener = ActionListener.wrap(unused -> {
|
||||
ActionListener<Boolean> createOrGetIndexListener = ActionListener.wrap(unused -> {
|
||||
TransformTaskParams transformTask = transformTaskHolder.get();
|
||||
assert transformTask != null;
|
||||
PersistentTasksCustomMetaData.PersistentTask<TransformTaskParams> existingTask = getExistingTask(transformTask.getId(), state);
|
||||
|
@ -222,8 +222,10 @@ public class TransportStartTransformAction extends TransportMasterNodeAction<Sta
|
|||
String[] dest = indexNameExpressionResolver.concreteIndexNames(state, IndicesOptions.lenientExpandOpen(), destinationIndex);
|
||||
|
||||
if (dest.length == 0) {
|
||||
auditor.info(request.getId(), "Creating destination index [" + destinationIndex + "] with deduced mappings.");
|
||||
createDestinationIndex(transformConfigHolder.get(), createOrGetIndexListener);
|
||||
createDestinationIndex(transformConfigHolder.get(), ActionListener.wrap(r -> {
|
||||
auditor.info(request.getId(), "Created destination index [" + destinationIndex + "] with deduced mappings.");
|
||||
createOrGetIndexListener.onResponse(r);
|
||||
}, createOrGetIndexListener::onFailure));
|
||||
} else {
|
||||
auditor.info(request.getId(), "Using existing destination index [" + destinationIndex + "].");
|
||||
ClientHelper.executeAsyncWithOrigin(
|
||||
|
@ -238,12 +240,12 @@ public class TransportStartTransformAction extends TransportMasterNodeAction<Sta
|
|||
"Non-empty destination index [" + destinationIndex + "]. " + "Contains [" + docTotal + "] total documents."
|
||||
);
|
||||
}
|
||||
createOrGetIndexListener.onResponse(null);
|
||||
createOrGetIndexListener.onResponse(true);
|
||||
}, e -> {
|
||||
String msg = "Unable to determine destination index stats, error: " + e.getMessage();
|
||||
logger.error(msg, e);
|
||||
logger.warn(msg, e);
|
||||
auditor.warning(request.getId(), msg);
|
||||
createOrGetIndexListener.onResponse(null);
|
||||
createOrGetIndexListener.onResponse(true);
|
||||
}),
|
||||
client.admin().indices()::stats
|
||||
);
|
||||
|
@ -265,9 +267,10 @@ public class TransportStartTransformAction extends TransportMasterNodeAction<Sta
|
|||
transformConfigHolder.set(config);
|
||||
if (config.getDestination().getPipeline() != null) {
|
||||
if (ingestService.getPipeline(config.getDestination().getPipeline()) == null) {
|
||||
listener.onFailure(new ElasticsearchStatusException(
|
||||
TransformMessages.getMessage(TransformMessages.PIPELINE_MISSING, config.getDestination().getPipeline()),
|
||||
RestStatus.BAD_REQUEST
|
||||
listener.onFailure(
|
||||
new ElasticsearchStatusException(
|
||||
TransformMessages.getMessage(TransformMessages.PIPELINE_MISSING, config.getDestination().getPipeline()),
|
||||
RestStatus.BAD_REQUEST
|
||||
)
|
||||
);
|
||||
return;
|
||||
|
@ -287,18 +290,12 @@ public class TransportStartTransformAction extends TransportMasterNodeAction<Sta
|
|||
transformConfigManager.getTransformConfiguration(request.getId(), getTransformListener);
|
||||
}
|
||||
|
||||
private void createDestinationIndex(final TransformConfig config, final ActionListener<Void> listener) {
|
||||
private void createDestinationIndex(final TransformConfig config, final ActionListener<Boolean> listener) {
|
||||
|
||||
final Pivot pivot = new Pivot(config.getPivotConfig());
|
||||
|
||||
ActionListener<Map<String, String>> deduceMappingsListener = ActionListener.wrap(
|
||||
mappings -> TransformIndex.createDestinationIndex(
|
||||
client,
|
||||
Clock.systemUTC(),
|
||||
config,
|
||||
mappings,
|
||||
ActionListener.wrap(r -> listener.onResponse(null), listener::onFailure)
|
||||
),
|
||||
mappings -> TransformIndex.createDestinationIndex(client, Clock.systemUTC(), config, mappings, listener),
|
||||
deduceTargetMappingsException -> listener.onFailure(
|
||||
new RuntimeException(TransformMessages.REST_PUT_TRANSFORM_FAILED_TO_DEDUCE_DEST_MAPPINGS, deduceTargetMappingsException)
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue