use of org.elasticsearch.ResourceNotFoundException in project elasticsearch by elastic.
the class PipelineStoreTests method testDelete.
public void testDelete() {
PipelineConfiguration config = new PipelineConfiguration("_id", new BytesArray("{\"processors\": [{\"set\" : {\"field\": \"_field\", \"value\": \"_value\"}}]}"), XContentType.JSON);
IngestMetadata ingestMetadata = new IngestMetadata(Collections.singletonMap("_id", config));
ClusterState clusterState = ClusterState.builder(new ClusterName("_name")).build();
ClusterState previousClusterState = clusterState;
clusterState = ClusterState.builder(clusterState).metaData(MetaData.builder().putCustom(IngestMetadata.TYPE, ingestMetadata)).build();
store.innerUpdatePipelines(previousClusterState, clusterState);
assertThat(store.get("_id"), notNullValue());
// Delete pipeline:
DeletePipelineRequest deleteRequest = new DeletePipelineRequest("_id");
previousClusterState = clusterState;
clusterState = store.innerDelete(deleteRequest, clusterState);
store.innerUpdatePipelines(previousClusterState, clusterState);
assertThat(store.get("_id"), nullValue());
// Delete existing pipeline:
try {
store.innerDelete(deleteRequest, clusterState);
fail("exception expected");
} catch (ResourceNotFoundException e) {
assertThat(e.getMessage(), equalTo("pipeline [_id] is missing"));
}
}
use of org.elasticsearch.ResourceNotFoundException in project elasticsearch by elastic.
the class TransportGetTaskAction method runOnNodeWithTaskIfPossible.
/**
* Executed on the coordinating node to forward execution of the remaining work to the node that matches that requested
* {@link TaskId#getNodeId()}. If the node isn't in the cluster then this will just proceed to
* {@link #getFinishedTaskFromIndex(Task, GetTaskRequest, ActionListener)} on this node.
*/
private void runOnNodeWithTaskIfPossible(Task thisTask, GetTaskRequest request, ActionListener<GetTaskResponse> listener) {
TransportRequestOptions.Builder builder = TransportRequestOptions.builder();
if (request.getTimeout() != null) {
builder.withTimeout(request.getTimeout());
}
builder.withCompress(false);
DiscoveryNode node = clusterService.state().nodes().get(request.getTaskId().getNodeId());
if (node == null) {
// Node is no longer part of the cluster! Try and look the task up from the results index.
getFinishedTaskFromIndex(thisTask, request, ActionListener.wrap(listener::onResponse, e -> {
if (e instanceof ResourceNotFoundException) {
e = new ResourceNotFoundException("task [" + request.getTaskId() + "] belongs to the node [" + request.getTaskId().getNodeId() + "] which isn't part of the cluster and there is no record of the task", e);
}
listener.onFailure(e);
}));
return;
}
GetTaskRequest nodeRequest = request.nodeRequest(clusterService.localNode().getId(), thisTask.getId());
transportService.sendRequest(node, GetTaskAction.NAME, nodeRequest, builder.build(), new TransportResponseHandler<GetTaskResponse>() {
@Override
public GetTaskResponse newInstance() {
return new GetTaskResponse();
}
@Override
public void handleResponse(GetTaskResponse response) {
listener.onResponse(response);
}
@Override
public void handleException(TransportException exp) {
listener.onFailure(exp);
}
@Override
public String executor() {
return ThreadPool.Names.SAME;
}
});
}
use of org.elasticsearch.ResourceNotFoundException in project elasticsearch by elastic.
the class TransportGetTaskAction method getFinishedTaskFromIndex.
/**
* Send a {@link GetRequest} to the tasks index looking for a persisted copy of the task completed task. It'll only be found only if the
* task's result was stored. Called on the node that once had the task if that node is still part of the cluster or on the
* coordinating node if the node is no longer part of the cluster.
*/
void getFinishedTaskFromIndex(Task thisTask, GetTaskRequest request, ActionListener<GetTaskResponse> listener) {
GetRequest get = new GetRequest(TaskResultsService.TASK_INDEX, TaskResultsService.TASK_TYPE, request.getTaskId().toString());
get.setParentTask(clusterService.localNode().getId(), thisTask.getId());
client.get(get, new ActionListener<GetResponse>() {
@Override
public void onResponse(GetResponse getResponse) {
try {
onGetFinishedTaskFromIndex(getResponse, listener);
} catch (Exception e) {
listener.onFailure(e);
}
}
@Override
public void onFailure(Exception e) {
if (ExceptionsHelper.unwrap(e, IndexNotFoundException.class) != null) {
// We haven't yet created the index for the task results so it can't be found.
listener.onFailure(new ResourceNotFoundException("task [{}] isn't running and hasn't stored its results", e, request.getTaskId()));
} else {
listener.onFailure(e);
}
}
});
}
use of org.elasticsearch.ResourceNotFoundException in project elasticsearch by elastic.
the class TransportGetTaskAction method onGetFinishedTaskFromIndex.
/**
* Called with the {@linkplain GetResponse} from loading the task from the results index. Called on the node that once had the task if
* that node is part of the cluster or on the coordinating node if the node wasn't part of the cluster.
*/
void onGetFinishedTaskFromIndex(GetResponse response, ActionListener<GetTaskResponse> listener) throws IOException {
if (false == response.isExists()) {
listener.onFailure(new ResourceNotFoundException("task [{}] isn't running and hasn't stored its results", response.getId()));
return;
}
if (response.isSourceEmpty()) {
listener.onFailure(new ElasticsearchException("Stored task status for [{}] didn't contain any source!", response.getId()));
return;
}
try (XContentParser parser = XContentHelper.createParser(xContentRegistry, response.getSourceAsBytesRef())) {
TaskResult result = TaskResult.PARSER.apply(parser, null);
listener.onResponse(new GetTaskResponse(result));
}
}
use of org.elasticsearch.ResourceNotFoundException in project elasticsearch by elastic.
the class ScriptServiceTests method testDeleteScript.
public void testDeleteScript() throws Exception {
ScriptMetaData scriptMetaData = ScriptMetaData.putStoredScript(null, "_id", StoredScriptSource.parse("_lang", new BytesArray("{\"script\":\"abc\"}"), XContentType.JSON));
scriptMetaData = ScriptMetaData.deleteStoredScript(scriptMetaData, "_id", "_lang");
assertNotNull(scriptMetaData);
assertNull(scriptMetaData.getStoredScript("_id", "_lang"));
ScriptMetaData errorMetaData = scriptMetaData;
ResourceNotFoundException e = expectThrows(ResourceNotFoundException.class, () -> {
ScriptMetaData.deleteStoredScript(errorMetaData, "_id", "_lang");
});
assertEquals("stored script [_id] using lang [_lang] does not exist and cannot be deleted", e.getMessage());
}
Aggregations