Validate if job index already exists after job validation.
Closes elastic/elasticsearch#594 Original commit: elastic/x-pack-elasticsearch@b3b7b086a7
This commit is contained in:
parent
999a1eb234
commit
0b5b26284b
|
@ -194,10 +194,11 @@ public class JobManager extends AbstractComponent {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ClusterState execute(ClusterState currentState) throws Exception {
|
public ClusterState execute(ClusterState currentState) throws Exception {
|
||||||
|
ClusterState cs = updateClusterState(job, request.isOverwrite(), currentState);
|
||||||
if (currentState.metaData().index(AnomalyDetectorsIndex.getJobIndexName(job.getIndexName())) != null) {
|
if (currentState.metaData().index(AnomalyDetectorsIndex.getJobIndexName(job.getIndexName())) != null) {
|
||||||
throw new ResourceAlreadyExistsException(Messages.getMessage(Messages.JOB_INDEX_ALREADY_EXISTS, job.getIndexName()));
|
throw new ResourceAlreadyExistsException(Messages.getMessage(Messages.JOB_INDEX_ALREADY_EXISTS, job.getIndexName()));
|
||||||
}
|
}
|
||||||
return updateClusterState(job, request.isOverwrite(), currentState);
|
return cs;
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -29,8 +29,6 @@ import org.elasticsearch.xpack.prelert.job.persistence.JobProvider;
|
||||||
import org.elasticsearch.xpack.prelert.job.persistence.JobResultsPersister;
|
import org.elasticsearch.xpack.prelert.job.persistence.JobResultsPersister;
|
||||||
import org.elasticsearch.xpack.prelert.job.persistence.QueryPage;
|
import org.elasticsearch.xpack.prelert.job.persistence.QueryPage;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.mockito.invocation.InvocationOnMock;
|
|
||||||
import org.mockito.stubbing.Answer;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
@ -167,15 +165,12 @@ public class JobManagerTests extends ESTestCase {
|
||||||
.fPut(AnomalyDetectorsIndex.getJobIndexName("my-special-place"), indexMetaData).build();
|
.fPut(AnomalyDetectorsIndex.getJobIndexName("my-special-place"), indexMetaData).build();
|
||||||
|
|
||||||
ClusterState cs = ClusterState.builder(new ClusterName("_name"))
|
ClusterState cs = ClusterState.builder(new ClusterName("_name"))
|
||||||
.metaData(MetaData.builder().indices(indexMap)).build();
|
.metaData(MetaData.builder().putCustom(PrelertMetadata.TYPE, PrelertMetadata.PROTO).indices(indexMap)).build();
|
||||||
|
|
||||||
doAnswer(new Answer<Void>() {
|
doAnswer(invocationOnMock -> {
|
||||||
@Override
|
AckedClusterStateUpdateTask<Boolean> task = (AckedClusterStateUpdateTask<Boolean>) invocationOnMock.getArguments()[1];
|
||||||
public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
|
task.execute(cs);
|
||||||
AckedClusterStateUpdateTask<Boolean> task = (AckedClusterStateUpdateTask<Boolean>) invocationOnMock.getArguments()[1];
|
return null;
|
||||||
task.execute(cs);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}).when(clusterService).submitStateUpdateTask(eq("put-job-foo"), any(AckedClusterStateUpdateTask.class));
|
}).when(clusterService).submitStateUpdateTask(eq("put-job-foo"), any(AckedClusterStateUpdateTask.class));
|
||||||
|
|
||||||
ResourceAlreadyExistsException e = expectThrows(ResourceAlreadyExistsException.class, () -> jobManager.putJob(request,
|
ResourceAlreadyExistsException e = expectThrows(ResourceAlreadyExistsException.class, () -> jobManager.putJob(request,
|
||||||
|
|
|
@ -83,6 +83,40 @@
|
||||||
"time_format":"yyyy-MM-dd HH:mm:ssX"
|
"time_format":"yyyy-MM-dd HH:mm:ssX"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
- do:
|
||||||
|
catch: /The job cannot be created with the Id 'farequote'. The Id is already used./
|
||||||
|
xpack.prelert.put_job:
|
||||||
|
body: >
|
||||||
|
{
|
||||||
|
"job_id":"farequote",
|
||||||
|
"description":"Analysis of response time by airline",
|
||||||
|
"analysis_config" : {
|
||||||
|
"bucket_span":3600,
|
||||||
|
"detectors" :[{"function":"metric","field_name":"responsetime","by_field_name":"airline"}]
|
||||||
|
},
|
||||||
|
"data_description" : {
|
||||||
|
"field_delimiter":",",
|
||||||
|
"time_field":"time",
|
||||||
|
"time_format":"yyyy-MM-dd HH:mm:ssX"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
- do:
|
||||||
|
catch: param
|
||||||
|
xpack.prelert.put_job:
|
||||||
|
body: >
|
||||||
|
{
|
||||||
|
"job_id":"farequote",
|
||||||
|
"description":"Analysis of response time by airline",
|
||||||
|
"analysis_config" : {
|
||||||
|
"bucket_span":3600,
|
||||||
|
"detectors" :[{"function":"metric","field_name":"responsetime","by_field_name":"airline"}]
|
||||||
|
},
|
||||||
|
"data_description" : {
|
||||||
|
"field_delimiter":",",
|
||||||
|
"time_field":"time",
|
||||||
|
"time_format":"yyyy-MM-dd HH:mm:ssX"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
---
|
---
|
||||||
"Test delete job that is referred by a scheduler":
|
"Test delete job that is referred by a scheduler":
|
||||||
|
|
Loading…
Reference in New Issue