[ML] Adjust error to make sense for FAILED as well as CLOSED jobs (elastic/x-pack-elasticsearch#888)

Previously trying to perform an operation on a FAILED job would tell
you that it hadn't been opened.  This was very confusing if you knew
very well you'd just opened the job.

Relates elastic/x-pack-elasticsearch#879

Original commit: elastic/x-pack-elasticsearch@2dbe41caaa
This commit is contained in:
David Roberts 2017-03-30 10:33:56 +01:00 committed by GitHub
parent c335e79508
commit 72f5e92972
7 changed files with 8 additions and 8 deletions

View File

@ -472,7 +472,7 @@ public class StartDatafeedAction
JobState jobState = MlMetadata.getJobState(datafeed.getJobId(), tasks);
if (jobState != JobState.OPENED) {
throw ExceptionsHelper.conflictStatusException("cannot start datafeed [" + datafeedId + "] because job [" + job.getId() +
"] hasn't been opened");
"] is not open");
}
PersistentTask<?> datafeedTask = MlMetadata.getDatafeedTask(datafeedId, tasks);

View File

@ -63,7 +63,7 @@ public abstract class TransportJobTaskAction<OperationTask extends Task, Request
PersistentTasksCustomMetaData tasks = clusterService.state().getMetaData().custom(PersistentTasksCustomMetaData.TYPE);
PersistentTasksCustomMetaData.PersistentTask<?> jobTask = MlMetadata.getJobTask(jobId, tasks);
if (jobTask == null || jobTask.isAssigned() == false) {
String message = "Cannot perform requested action because job [" + jobId + "] hasn't been opened";
String message = "Cannot perform requested action because job [" + jobId + "] is not open";
listener.onFailure(ExceptionsHelper.conflictStatusException(message));
} else {
request.setNodes(jobTask.getExecutorNode());
@ -81,7 +81,7 @@ public abstract class TransportJobTaskAction<OperationTask extends Task, Request
} else {
logger.warn("Unexpected job state based on cluster state version [{}]", state.getVersion());
listener.onFailure(ExceptionsHelper.conflictStatusException("Cannot perform requested action because job [" +
request.getJobId() + "] hasn't been opened"));
request.getJobId() + "] is not open"));
}
}

View File

@ -421,7 +421,7 @@ public class MachineLearningLicensingTests extends BaseMlIntegTestCase {
if (invalidLicense) {
// so the license expired then job closes automatically, so an error is expected:
Exception e = expectThrows(ElasticsearchStatusException.class, listener::actionGet);
assertEquals("Cannot perform requested action because job [foo] hasn't been opened", e.getMessage());
assertEquals("Cannot perform requested action because job [foo] is not open", e.getMessage());
} else {
listener.actionGet();
}

View File

@ -134,7 +134,7 @@ public class StartDatafeedActionTests extends ESTestCase {
.build();
Exception e = expectThrows(ElasticsearchStatusException.class,
() -> StartDatafeedAction.validate("foo-datafeed", mlMetadata2, tasks));
assertThat(e.getMessage(), equalTo("cannot start datafeed [foo-datafeed] because job [job_id] hasn't been opened"));
assertThat(e.getMessage(), equalTo("cannot start datafeed [foo-datafeed] because job [job_id] is not open"));
}
public void testValidate_dataFeedAlreadyStarted() {

View File

@ -84,7 +84,7 @@ public class MlRestTestStateCleaner {
logger.error("Got status code " + statusCode + " when closing job " + jobId);
}
} catch (Exception e1) {
if (e1.getMessage().contains("because job [" + jobId + "] hasn't been opened")) {
if (e1.getMessage().contains("because job [" + jobId + "] is not open")) {
logger.debug("job [" + jobId + "] has already been closed", e1);
} else {
logger.warn("failed to close job [" + jobId + "]. Forcing closed", e1);

View File

@ -293,7 +293,7 @@ public abstract class BaseMlIntegTestCase extends ESIntegTestCase {
client.execute(CloseJobAction.INSTANCE, closeRequest).get();
assertTrue(response.isClosed());
} catch (Exception e1) {
if (e1.getMessage().contains("because job [" + jobId + "] hasn't been opened")) {
if (e1.getMessage().contains("because job [" + jobId + "] is not open")) {
logger.debug("job [" + jobId + "] has already been closed", e1);
} else {
try {

View File

@ -84,7 +84,7 @@ public class MlRestTestStateCleaner {
logger.error("Got status code " + statusCode + " when closing job " + jobId);
}
} catch (Exception e1) {
if (e1.getMessage().contains("because job [" + jobId + "] hasn't been opened")) {
if (e1.getMessage().contains("because job [" + jobId + "] is not open")) {
logger.debug("job [" + jobId + "] has already been closed", e1);
} else {
logger.warn("failed to close job [" + jobId + "]. Forcing closed", e1);