From e383e96f58542ae14f51828755460995d8de0088 Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Wed, 20 Jan 2016 11:40:17 +0100 Subject: [PATCH] replaced custom PipelineMissingException with ResourceNotFoundException --- .../elasticsearch/ElasticsearchException.java | 3 +- .../ingest/PipelineMissingException.java | 42 ------------------- .../elasticsearch/ingest/PipelineStore.java | 3 +- .../ExceptionSerializationTests.java | 1 - .../ingest/PipelineStoreTests.java | 3 +- 5 files changed, 5 insertions(+), 47 deletions(-) delete mode 100644 core/src/main/java/org/elasticsearch/ingest/PipelineMissingException.java diff --git a/core/src/main/java/org/elasticsearch/ElasticsearchException.java b/core/src/main/java/org/elasticsearch/ElasticsearchException.java index 98c992cf2bc..4a35bcbcfb0 100644 --- a/core/src/main/java/org/elasticsearch/ElasticsearchException.java +++ b/core/src/main/java/org/elasticsearch/ElasticsearchException.java @@ -610,8 +610,7 @@ public class ElasticsearchException extends RuntimeException implements ToXConte RETRY_ON_REPLICA_EXCEPTION(org.elasticsearch.action.support.replication.TransportReplicationAction.RetryOnReplicaException.class, org.elasticsearch.action.support.replication.TransportReplicationAction.RetryOnReplicaException::new, 136), TYPE_MISSING_EXCEPTION(org.elasticsearch.indices.TypeMissingException.class, org.elasticsearch.indices.TypeMissingException::new, 137), FAILED_TO_COMMIT_CLUSTER_STATE_EXCEPTION(org.elasticsearch.discovery.Discovery.FailedToCommitClusterStateException.class, org.elasticsearch.discovery.Discovery.FailedToCommitClusterStateException::new, 140), - QUERY_SHARD_EXCEPTION(org.elasticsearch.index.query.QueryShardException.class, org.elasticsearch.index.query.QueryShardException::new, 141), - PIPELINE_MISSING_EXCEPTION(org.elasticsearch.ingest.PipelineMissingException.class, org.elasticsearch.ingest.PipelineMissingException::new, 142); + QUERY_SHARD_EXCEPTION(org.elasticsearch.index.query.QueryShardException.class, org.elasticsearch.index.query.QueryShardException::new, 141); final Class exceptionClass; final FunctionThatThrowsIOException constructor; diff --git a/core/src/main/java/org/elasticsearch/ingest/PipelineMissingException.java b/core/src/main/java/org/elasticsearch/ingest/PipelineMissingException.java deleted file mode 100644 index 82637ae2ded..00000000000 --- a/core/src/main/java/org/elasticsearch/ingest/PipelineMissingException.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.ingest; - -import org.elasticsearch.ElasticsearchException; -import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.rest.RestStatus; - -import java.io.IOException; - -public class PipelineMissingException extends ElasticsearchException { - - public PipelineMissingException(String id) { - super("pipeline [{}] is missing", id); - } - - public PipelineMissingException(StreamInput in) throws IOException { - super(in); - } - - @Override - public RestStatus status() { - return RestStatus.NOT_FOUND; - } -} diff --git a/core/src/main/java/org/elasticsearch/ingest/PipelineStore.java b/core/src/main/java/org/elasticsearch/ingest/PipelineStore.java index 6db1d6c0681..e7ab217e736 100644 --- a/core/src/main/java/org/elasticsearch/ingest/PipelineStore.java +++ b/core/src/main/java/org/elasticsearch/ingest/PipelineStore.java @@ -20,6 +20,7 @@ package org.elasticsearch.ingest; import org.apache.lucene.util.IOUtils; +import org.elasticsearch.ResourceNotFoundException; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ingest.DeletePipelineRequest; import org.elasticsearch.action.ingest.PutPipelineRequest; @@ -136,7 +137,7 @@ public class PipelineStore extends AbstractComponent implements Closeable, Clust } Map pipelines = currentIngestMetadata.getPipelines(); if (pipelines.containsKey(request.id()) == false) { - throw new PipelineMissingException(request.id()); + throw new ResourceNotFoundException("pipeline [{}] is missing", request.id()); } else { pipelines = new HashMap<>(pipelines); pipelines.remove(request.id()); diff --git a/core/src/test/java/org/elasticsearch/ExceptionSerializationTests.java b/core/src/test/java/org/elasticsearch/ExceptionSerializationTests.java index be229310043..db7b5df6662 100644 --- a/core/src/test/java/org/elasticsearch/ExceptionSerializationTests.java +++ b/core/src/test/java/org/elasticsearch/ExceptionSerializationTests.java @@ -776,7 +776,6 @@ public class ExceptionSerializationTests extends ESTestCase { ids.put(139, null); ids.put(140, org.elasticsearch.discovery.Discovery.FailedToCommitClusterStateException.class); ids.put(141, org.elasticsearch.index.query.QueryShardException.class); - ids.put(142, org.elasticsearch.ingest.PipelineMissingException.class); Map, Integer> reverse = new HashMap<>(); for (Map.Entry> entry : ids.entrySet()) { diff --git a/core/src/test/java/org/elasticsearch/ingest/PipelineStoreTests.java b/core/src/test/java/org/elasticsearch/ingest/PipelineStoreTests.java index c1f14b26eb8..a0e07169f8f 100644 --- a/core/src/test/java/org/elasticsearch/ingest/PipelineStoreTests.java +++ b/core/src/test/java/org/elasticsearch/ingest/PipelineStoreTests.java @@ -19,6 +19,7 @@ package org.elasticsearch.ingest; +import org.elasticsearch.ResourceNotFoundException; import org.elasticsearch.action.ingest.DeletePipelineRequest; import org.elasticsearch.action.ingest.PutPipelineRequest; import org.elasticsearch.cluster.ClusterName; @@ -129,7 +130,7 @@ public class PipelineStoreTests extends ESTestCase { try { store.innerDelete(deleteRequest, clusterState); fail("exception expected"); - } catch (PipelineMissingException e) { + } catch (ResourceNotFoundException e) { assertThat(e.getMessage(), equalTo("pipeline [_id] is missing")); } }