For consistency reasons (and reducing the overload of IllegalArgumentException) this changes the exception thrown when trying to create a data stream that already exists. (cherry picked from commit ac2184c4614bba0f3ee377da49aea0daed98bab4) Signed-off-by: Andrei Dan <andrei.dan@elastic.co>
This commit is contained in:
parent
fcc53d9e0e
commit
ac258f10d6
|
@ -20,6 +20,7 @@ package org.elasticsearch.cluster.metadata;
|
|||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.elasticsearch.ResourceAlreadyExistsException;
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.action.admin.indices.create.CreateIndexClusterStateUpdateRequest;
|
||||
|
@ -126,7 +127,7 @@ public class MetadataCreateDataStreamService {
|
|||
}
|
||||
|
||||
if (currentState.metadata().dataStreams().containsKey(request.name)) {
|
||||
throw new IllegalArgumentException("data_stream [" + request.name + "] already exists");
|
||||
throw new ResourceAlreadyExistsException("data_stream [" + request.name + "] already exists");
|
||||
}
|
||||
|
||||
MetadataCreateIndexService.validateIndexOrAliasName(request.name,
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
*/
|
||||
package org.elasticsearch.cluster.metadata;
|
||||
|
||||
import org.elasticsearch.ResourceAlreadyExistsException;
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.action.admin.indices.create.CreateIndexClusterStateUpdateRequest;
|
||||
import org.elasticsearch.cluster.ClusterName;
|
||||
|
@ -71,7 +72,7 @@ public class MetadataCreateDataStreamServiceTests extends ESTestCase {
|
|||
CreateDataStreamClusterStateUpdateRequest req =
|
||||
new CreateDataStreamClusterStateUpdateRequest(dataStreamName, TimeValue.ZERO, TimeValue.ZERO);
|
||||
|
||||
IllegalArgumentException e = expectThrows(IllegalArgumentException.class,
|
||||
ResourceAlreadyExistsException e = expectThrows(ResourceAlreadyExistsException.class,
|
||||
() -> MetadataCreateDataStreamService.createDataStream(metadataCreateIndexService, cs, req));
|
||||
assertThat(e.getMessage(), containsString("data_stream [" + dataStreamName + "] already exists"));
|
||||
}
|
||||
|
|
|
@ -116,6 +116,31 @@ setup:
|
|||
- match: { error.root_cause.0.type: "illegal_argument_exception" }
|
||||
- match: { error.root_cause.0.reason: "data_stream [invalid-data-stream#-name] must not contain '#'" }
|
||||
|
||||
---
|
||||
"Create existing data stream":
|
||||
- skip:
|
||||
version: " - 7.8.99"
|
||||
reason: "data streams only supported in 7.9+"
|
||||
|
||||
- do:
|
||||
indices.create_data_stream:
|
||||
name: simple-data-stream1
|
||||
- is_true: acknowledged
|
||||
|
||||
- do:
|
||||
catch: bad_request
|
||||
indices.create_data_stream:
|
||||
name: simple-data-stream1
|
||||
|
||||
- match: { status: 400 }
|
||||
- match: { error.root_cause.0.type: "resource_already_exists_exception" }
|
||||
- match: { error.root_cause.0.reason: "data_stream [simple-data-stream1] already exists" }
|
||||
|
||||
- do:
|
||||
indices.delete_data_stream:
|
||||
name: simple-data-stream1
|
||||
- is_true: acknowledged
|
||||
|
||||
---
|
||||
"Get data stream":
|
||||
- skip:
|
||||
|
|
Loading…
Reference in New Issue