[ML] Give test jobs meaningful names (elastic/x-pack-elasticsearch#1508)

Original commit: elastic/x-pack-elasticsearch@97bec3b1e9
This commit is contained in:
David Kyle 2017-05-22 12:22:39 +01:00 committed by GitHub
parent 5b2ef6e98e
commit 0425f58d80
1 changed files with 60 additions and 53 deletions

View File

@ -51,6 +51,7 @@ public class MachineLearningLicensingTests extends BaseMlIntegTestCase {
} }
public void testMachineLearningPutJobActionRestricted() throws Exception { public void testMachineLearningPutJobActionRestricted() throws Exception {
String jobId = "testmachinelearningputjobactionrestricted";
// Pick a license that does not allow machine learning // Pick a license that does not allow machine learning
License.OperationMode mode = randomInvalidLicenseType(); License.OperationMode mode = randomInvalidLicenseType();
enableLicensing(mode); enableLicensing(mode);
@ -59,7 +60,7 @@ public class MachineLearningLicensingTests extends BaseMlIntegTestCase {
try (TransportClient client = new TestXPackTransportClient(internalCluster().transportClient().settings())) { try (TransportClient client = new TestXPackTransportClient(internalCluster().transportClient().settings())) {
client.addTransportAddress(internalCluster().getDataNodeInstance(Transport.class).boundAddress().publishAddress()); client.addTransportAddress(internalCluster().getDataNodeInstance(Transport.class).boundAddress().publishAddress());
PlainActionFuture<PutJobAction.Response> listener = PlainActionFuture. newFuture(); PlainActionFuture<PutJobAction.Response> listener = PlainActionFuture. newFuture();
new MachineLearningClient(client).putJob(new PutJobAction.Request(createJob("foo")), listener); new MachineLearningClient(client).putJob(new PutJobAction.Request(createJob(jobId)), listener);
listener.actionGet(); listener.actionGet();
fail("put job action should not be enabled!"); fail("put job action should not be enabled!");
} catch (ElasticsearchSecurityException e) { } catch (ElasticsearchSecurityException e) {
@ -76,20 +77,20 @@ public class MachineLearningLicensingTests extends BaseMlIntegTestCase {
try (TransportClient client = new TestXPackTransportClient(internalCluster().transportClient().settings())) { try (TransportClient client = new TestXPackTransportClient(internalCluster().transportClient().settings())) {
client.addTransportAddress(internalCluster().getDataNodeInstance(Transport.class).boundAddress().publishAddress()); client.addTransportAddress(internalCluster().getDataNodeInstance(Transport.class).boundAddress().publishAddress());
PlainActionFuture<PutJobAction.Response> listener = PlainActionFuture.newFuture(); PlainActionFuture<PutJobAction.Response> listener = PlainActionFuture.newFuture();
new MachineLearningClient(client).putJob(new PutJobAction.Request(createJob("foo")), listener); new MachineLearningClient(client).putJob(new PutJobAction.Request(createJob(jobId)), listener);
PutJobAction.Response response = listener.actionGet(); PutJobAction.Response response = listener.actionGet();
assertNotNull(response); assertNotNull(response);
} }
} }
public void testMachineLearningOpenJobActionRestricted() throws Exception { public void testMachineLearningOpenJobActionRestricted() throws Exception {
String jobId = "testmachinelearningopenjobactionrestricted";
assertMLAllowed(true); assertMLAllowed(true);
// test that license restricted apis do now work // test that license restricted apis do now work
try (TransportClient client = new TestXPackTransportClient(internalCluster().transportClient().settings())) { try (TransportClient client = new TestXPackTransportClient(internalCluster().transportClient().settings())) {
client.addTransportAddress(internalCluster().getDataNodeInstance(Transport.class).boundAddress().publishAddress()); client.addTransportAddress(internalCluster().getDataNodeInstance(Transport.class).boundAddress().publishAddress());
PlainActionFuture<PutJobAction.Response> putJobListener = PlainActionFuture.newFuture(); PlainActionFuture<PutJobAction.Response> putJobListener = PlainActionFuture.newFuture();
new MachineLearningClient(client).putJob(new PutJobAction.Request(createJob("foo")), putJobListener); new MachineLearningClient(client).putJob(new PutJobAction.Request(createJob(jobId)), putJobListener);
PutJobAction.Response response = putJobListener.actionGet(); PutJobAction.Response response = putJobListener.actionGet();
assertNotNull(response); assertNotNull(response);
} }
@ -102,7 +103,7 @@ public class MachineLearningLicensingTests extends BaseMlIntegTestCase {
try (TransportClient client = new TestXPackTransportClient(internalCluster().transportClient().settings())) { try (TransportClient client = new TestXPackTransportClient(internalCluster().transportClient().settings())) {
client.addTransportAddress(internalCluster().getDataNodeInstance(Transport.class).boundAddress().publishAddress()); client.addTransportAddress(internalCluster().getDataNodeInstance(Transport.class).boundAddress().publishAddress());
PlainActionFuture<OpenJobAction.Response> listener = PlainActionFuture.newFuture(); PlainActionFuture<OpenJobAction.Response> listener = PlainActionFuture.newFuture();
new MachineLearningClient(client).openJob(new OpenJobAction.Request("foo"), listener); new MachineLearningClient(client).openJob(new OpenJobAction.Request(jobId), listener);
listener.actionGet(); listener.actionGet();
fail("open job action should not be enabled!"); fail("open job action should not be enabled!");
} catch (ElasticsearchSecurityException e) { } catch (ElasticsearchSecurityException e) {
@ -118,7 +119,7 @@ public class MachineLearningLicensingTests extends BaseMlIntegTestCase {
// now that the license is invalid, the job should get closed: // now that the license is invalid, the job should get closed:
assertBusy(() -> { assertBusy(() -> {
JobState jobState = getJobStats("foo").getState(); JobState jobState = getJobStats(jobId).getState();
assertEquals(JobState.CLOSED, jobState); assertEquals(JobState.CLOSED, jobState);
}); });
@ -126,20 +127,21 @@ public class MachineLearningLicensingTests extends BaseMlIntegTestCase {
try (TransportClient client = new TestXPackTransportClient(internalCluster().transportClient().settings())) { try (TransportClient client = new TestXPackTransportClient(internalCluster().transportClient().settings())) {
client.addTransportAddress(internalCluster().getDataNodeInstance(Transport.class).boundAddress().publishAddress()); client.addTransportAddress(internalCluster().getDataNodeInstance(Transport.class).boundAddress().publishAddress());
PlainActionFuture<OpenJobAction.Response> listener = PlainActionFuture.newFuture(); PlainActionFuture<OpenJobAction.Response> listener = PlainActionFuture.newFuture();
new MachineLearningClient(client).openJob(new OpenJobAction.Request("foo"), listener); new MachineLearningClient(client).openJob(new OpenJobAction.Request(jobId), listener);
OpenJobAction.Response response = listener.actionGet(); OpenJobAction.Response response = listener.actionGet();
assertNotNull(response); assertNotNull(response);
} }
} }
public void testMachineLearningPutDatafeedActionRestricted() throws Exception { public void testMachineLearningPutDatafeedActionRestricted() throws Exception {
String jobId = "testmachinelearningputdatafeedactionrestricted";
String datafeedId = jobId + "-datafeed";
assertMLAllowed(true); assertMLAllowed(true);
// test that license restricted apis do now work // test that license restricted apis do now work
try (TransportClient client = new TestXPackTransportClient(internalCluster().transportClient().settings())) { try (TransportClient client = new TestXPackTransportClient(internalCluster().transportClient().settings())) {
client.addTransportAddress(internalCluster().getDataNodeInstance(Transport.class).boundAddress().publishAddress()); client.addTransportAddress(internalCluster().getDataNodeInstance(Transport.class).boundAddress().publishAddress());
PlainActionFuture<PutJobAction.Response> putJobListener = PlainActionFuture.newFuture(); PlainActionFuture<PutJobAction.Response> putJobListener = PlainActionFuture.newFuture();
new MachineLearningClient(client).putJob(new PutJobAction.Request(createJob("foo")), putJobListener); new MachineLearningClient(client).putJob(new PutJobAction.Request(createJob(jobId)), putJobListener);
PutJobAction.Response putJobResponse = putJobListener.actionGet(); PutJobAction.Response putJobResponse = putJobListener.actionGet();
assertNotNull(putJobResponse); assertNotNull(putJobResponse);
} }
@ -153,7 +155,7 @@ public class MachineLearningLicensingTests extends BaseMlIntegTestCase {
client.addTransportAddress(internalCluster().getDataNodeInstance(Transport.class).boundAddress().publishAddress()); client.addTransportAddress(internalCluster().getDataNodeInstance(Transport.class).boundAddress().publishAddress());
PlainActionFuture<PutDatafeedAction.Response> listener = PlainActionFuture.newFuture(); PlainActionFuture<PutDatafeedAction.Response> listener = PlainActionFuture.newFuture();
new MachineLearningClient(client).putDatafeed( new MachineLearningClient(client).putDatafeed(
new PutDatafeedAction.Request(createDatafeed("foobar", "foo", Collections.singletonList("foo"))), listener); new PutDatafeedAction.Request(createDatafeed(datafeedId, jobId, Collections.singletonList(jobId))), listener);
listener.actionGet(); listener.actionGet();
fail("put datafeed action should not be enabled!"); fail("put datafeed action should not be enabled!");
} catch (ElasticsearchSecurityException e) { } catch (ElasticsearchSecurityException e) {
@ -171,36 +173,38 @@ public class MachineLearningLicensingTests extends BaseMlIntegTestCase {
client.addTransportAddress(internalCluster().getDataNodeInstance(Transport.class).boundAddress().publishAddress()); client.addTransportAddress(internalCluster().getDataNodeInstance(Transport.class).boundAddress().publishAddress());
PlainActionFuture<PutDatafeedAction.Response> listener = PlainActionFuture.newFuture(); PlainActionFuture<PutDatafeedAction.Response> listener = PlainActionFuture.newFuture();
new MachineLearningClient(client).putDatafeed( new MachineLearningClient(client).putDatafeed(
new PutDatafeedAction.Request(createDatafeed("foobar", "foo", Collections.singletonList("foo"))), listener); new PutDatafeedAction.Request(createDatafeed(datafeedId, jobId, Collections.singletonList(jobId))), listener);
PutDatafeedAction.Response response = listener.actionGet(); PutDatafeedAction.Response response = listener.actionGet();
assertNotNull(response); assertNotNull(response);
} }
} }
public void testAutoCloseJobWithDatafeed() throws Exception { public void testAutoCloseJobWithDatafeed() throws Exception {
String jobId = "testautoclosejobwithdatafeed";
String datafeedId = jobId + "-datafeed";
assertMLAllowed(true); assertMLAllowed(true);
createIndex("foo"); createIndex(jobId + "-data");
try (TransportClient client = new TestXPackTransportClient(internalCluster().transportClient().settings())) { try (TransportClient client = new TestXPackTransportClient(internalCluster().transportClient().settings())) {
client.addTransportAddress(internalCluster().getDataNodeInstance(Transport.class).boundAddress().publishAddress()); client.addTransportAddress(internalCluster().getDataNodeInstance(Transport.class).boundAddress().publishAddress());
// put job // put job
PlainActionFuture<PutJobAction.Response> putJobListener = PlainActionFuture.newFuture(); PlainActionFuture<PutJobAction.Response> putJobListener = PlainActionFuture.newFuture();
new MachineLearningClient(client).putJob(new PutJobAction.Request(createJob("foo")), putJobListener); new MachineLearningClient(client).putJob(new PutJobAction.Request(createJob(jobId)), putJobListener);
PutJobAction.Response putJobResponse = putJobListener.actionGet(); PutJobAction.Response putJobResponse = putJobListener.actionGet();
assertNotNull(putJobResponse); assertNotNull(putJobResponse);
// put datafeed // put datafeed
PlainActionFuture<PutDatafeedAction.Response> putDatafeedListener = PlainActionFuture.newFuture(); PlainActionFuture<PutDatafeedAction.Response> putDatafeedListener = PlainActionFuture.newFuture();
new MachineLearningClient(client).putDatafeed( new MachineLearningClient(client).putDatafeed(
new PutDatafeedAction.Request(createDatafeed("foobar", "foo", Collections.singletonList("foo"))), putDatafeedListener); new PutDatafeedAction.Request(createDatafeed(datafeedId, jobId, Collections.singletonList(jobId))), putDatafeedListener);
PutDatafeedAction.Response putDatafeedResponse = putDatafeedListener.actionGet(); PutDatafeedAction.Response putDatafeedResponse = putDatafeedListener.actionGet();
assertNotNull(putDatafeedResponse); assertNotNull(putDatafeedResponse);
// open job // open job
PlainActionFuture<OpenJobAction.Response> openJobListener = PlainActionFuture.newFuture(); PlainActionFuture<OpenJobAction.Response> openJobListener = PlainActionFuture.newFuture();
new MachineLearningClient(client).openJob(new OpenJobAction.Request("foo"), openJobListener); new MachineLearningClient(client).openJob(new OpenJobAction.Request(jobId), openJobListener);
OpenJobAction.Response openJobResponse = openJobListener.actionGet(); OpenJobAction.Response openJobResponse = openJobListener.actionGet();
assertNotNull(openJobResponse); assertNotNull(openJobResponse);
// start datafeed // start datafeed
PlainActionFuture<StartDatafeedAction.Response> listener = PlainActionFuture.newFuture(); PlainActionFuture<StartDatafeedAction.Response> listener = PlainActionFuture.newFuture();
new MachineLearningClient(client).startDatafeed(new StartDatafeedAction.Request("foobar", 0L), listener); new MachineLearningClient(client).startDatafeed(new StartDatafeedAction.Request(datafeedId, 0L), listener);
listener.actionGet(); listener.actionGet();
} }
@ -213,10 +217,10 @@ public class MachineLearningLicensingTests extends BaseMlIntegTestCase {
// now that the license is invalid, the job should be closed and datafeed stopped: // now that the license is invalid, the job should be closed and datafeed stopped:
assertBusy(() -> { assertBusy(() -> {
JobState jobState = getJobStats("foo").getState(); JobState jobState = getJobStats(jobId).getState();
assertEquals(JobState.CLOSED, jobState); assertEquals(JobState.CLOSED, jobState);
DatafeedState datafeedState = getDatafeedStats("foobar").getDatafeedState(); DatafeedState datafeedState = getDatafeedStats(datafeedId).getDatafeedState();
assertEquals(DatafeedState.STOPPED, datafeedState); assertEquals(DatafeedState.STOPPED, datafeedState);
ClusterState state = client().admin().cluster().prepareState().get().getState(); ClusterState state = client().admin().cluster().prepareState().get().getState();
@ -231,20 +235,20 @@ public class MachineLearningLicensingTests extends BaseMlIntegTestCase {
client.addTransportAddress(internalCluster().getDataNodeInstance(Transport.class).boundAddress().publishAddress()); client.addTransportAddress(internalCluster().getDataNodeInstance(Transport.class).boundAddress().publishAddress());
// open job // open job
PlainActionFuture<OpenJobAction.Response> openJobListener = PlainActionFuture.newFuture(); PlainActionFuture<OpenJobAction.Response> openJobListener = PlainActionFuture.newFuture();
new MachineLearningClient(client).openJob(new OpenJobAction.Request("foo"), openJobListener); new MachineLearningClient(client).openJob(new OpenJobAction.Request(jobId), openJobListener);
OpenJobAction.Response openJobResponse = openJobListener.actionGet(); OpenJobAction.Response openJobResponse = openJobListener.actionGet();
assertNotNull(openJobResponse); assertNotNull(openJobResponse);
// start datafeed // start datafeed
PlainActionFuture<StartDatafeedAction.Response> listener = PlainActionFuture.newFuture(); PlainActionFuture<StartDatafeedAction.Response> listener = PlainActionFuture.newFuture();
new MachineLearningClient(client).startDatafeed(new StartDatafeedAction.Request("foobar", 0L), listener); new MachineLearningClient(client).startDatafeed(new StartDatafeedAction.Request(datafeedId, 0L), listener);
listener.actionGet(); listener.actionGet();
} }
assertBusy(() -> { assertBusy(() -> {
JobState jobState = getJobStats("foo").getState(); JobState jobState = getJobStats(jobId).getState();
assertEquals(JobState.OPENED, jobState); assertEquals(JobState.OPENED, jobState);
DatafeedState datafeedState = getDatafeedStats("foobar").getDatafeedState(); DatafeedState datafeedState = getDatafeedStats(datafeedId).getDatafeedState();
assertEquals(DatafeedState.STARTED, datafeedState); assertEquals(DatafeedState.STARTED, datafeedState);
ClusterState state = client().admin().cluster().prepareState().get().getState(); ClusterState state = client().admin().cluster().prepareState().get().getState();
@ -261,10 +265,10 @@ public class MachineLearningLicensingTests extends BaseMlIntegTestCase {
// now that the license is invalid, the job should be closed and datafeed stopped: // now that the license is invalid, the job should be closed and datafeed stopped:
assertBusy(() -> { assertBusy(() -> {
JobState jobState = getJobStats("foo").getState(); JobState jobState = getJobStats(jobId).getState();
assertEquals(JobState.CLOSED, jobState); assertEquals(JobState.CLOSED, jobState);
DatafeedState datafeedState = getDatafeedStats("foobar").getDatafeedState(); DatafeedState datafeedState = getDatafeedStats(datafeedId).getDatafeedState();
assertEquals(DatafeedState.STOPPED, datafeedState); assertEquals(DatafeedState.STOPPED, datafeedState);
ClusterState state = client().admin().cluster().prepareState().get().getState(); ClusterState state = client().admin().cluster().prepareState().get().getState();
@ -274,23 +278,24 @@ public class MachineLearningLicensingTests extends BaseMlIntegTestCase {
} }
public void testMachineLearningStartDatafeedActionRestricted() throws Exception { public void testMachineLearningStartDatafeedActionRestricted() throws Exception {
String jobId = "testmachinelearningstartdatafeedactionrestricted";
String datafeedId = jobId + "-datafeed";
assertMLAllowed(true); assertMLAllowed(true);
createIndex("foo"); createIndex(jobId + "-data");
// test that license restricted apis do now work // test that license restricted apis do now work
try (TransportClient client = new TestXPackTransportClient(internalCluster().transportClient().settings())) { try (TransportClient client = new TestXPackTransportClient(internalCluster().transportClient().settings())) {
client.addTransportAddress(internalCluster().getDataNodeInstance(Transport.class).boundAddress().publishAddress()); client.addTransportAddress(internalCluster().getDataNodeInstance(Transport.class).boundAddress().publishAddress());
PlainActionFuture<PutJobAction.Response> putJobListener = PlainActionFuture.newFuture(); PlainActionFuture<PutJobAction.Response> putJobListener = PlainActionFuture.newFuture();
new MachineLearningClient(client).putJob(new PutJobAction.Request(createJob("foo")), putJobListener); new MachineLearningClient(client).putJob(new PutJobAction.Request(createJob(jobId)), putJobListener);
PutJobAction.Response putJobResponse = putJobListener.actionGet(); PutJobAction.Response putJobResponse = putJobListener.actionGet();
assertNotNull(putJobResponse); assertNotNull(putJobResponse);
PlainActionFuture<PutDatafeedAction.Response> putDatafeedListener = PlainActionFuture.newFuture(); PlainActionFuture<PutDatafeedAction.Response> putDatafeedListener = PlainActionFuture.newFuture();
new MachineLearningClient(client).putDatafeed( new MachineLearningClient(client).putDatafeed(
new PutDatafeedAction.Request(createDatafeed("foobar", "foo", Collections.singletonList("foo"))), putDatafeedListener); new PutDatafeedAction.Request(createDatafeed(datafeedId, jobId, Collections.singletonList(jobId))), putDatafeedListener);
PutDatafeedAction.Response putDatafeedResponse = putDatafeedListener.actionGet(); PutDatafeedAction.Response putDatafeedResponse = putDatafeedListener.actionGet();
assertNotNull(putDatafeedResponse); assertNotNull(putDatafeedResponse);
PlainActionFuture<OpenJobAction.Response> openJobListener = PlainActionFuture.newFuture(); PlainActionFuture<OpenJobAction.Response> openJobListener = PlainActionFuture.newFuture();
new MachineLearningClient(client).openJob(new OpenJobAction.Request("foo"), openJobListener); new MachineLearningClient(client).openJob(new OpenJobAction.Request(jobId), openJobListener);
OpenJobAction.Response openJobResponse = openJobListener.actionGet(); OpenJobAction.Response openJobResponse = openJobListener.actionGet();
assertNotNull(openJobResponse); assertNotNull(openJobResponse);
} }
@ -302,7 +307,7 @@ public class MachineLearningLicensingTests extends BaseMlIntegTestCase {
// now that the license is invalid, the job should get closed: // now that the license is invalid, the job should get closed:
assertBusy(() -> { assertBusy(() -> {
JobState jobState = getJobStats("foo").getState(); JobState jobState = getJobStats(jobId).getState();
assertEquals(JobState.CLOSED, jobState); assertEquals(JobState.CLOSED, jobState);
ClusterState state = client().admin().cluster().prepareState().get().getState(); ClusterState state = client().admin().cluster().prepareState().get().getState();
PersistentTasksCustomMetaData tasks = state.metaData().custom(PersistentTasksCustomMetaData.TYPE); PersistentTasksCustomMetaData tasks = state.metaData().custom(PersistentTasksCustomMetaData.TYPE);
@ -313,7 +318,7 @@ public class MachineLearningLicensingTests extends BaseMlIntegTestCase {
try (TransportClient client = new TestXPackTransportClient(internalCluster().transportClient().settings())) { try (TransportClient client = new TestXPackTransportClient(internalCluster().transportClient().settings())) {
client.addTransportAddress(internalCluster().getDataNodeInstance(Transport.class).boundAddress().publishAddress()); client.addTransportAddress(internalCluster().getDataNodeInstance(Transport.class).boundAddress().publishAddress());
PlainActionFuture<StartDatafeedAction.Response> listener = PlainActionFuture.newFuture(); PlainActionFuture<StartDatafeedAction.Response> listener = PlainActionFuture.newFuture();
new MachineLearningClient(client).startDatafeed(new StartDatafeedAction.Request("foobar", 0L), listener); new MachineLearningClient(client).startDatafeed(new StartDatafeedAction.Request(datafeedId, 0L), listener);
listener.actionGet(); listener.actionGet();
fail("start datafeed action should not be enabled!"); fail("start datafeed action should not be enabled!");
} catch (ElasticsearchSecurityException e) { } catch (ElasticsearchSecurityException e) {
@ -331,39 +336,40 @@ public class MachineLearningLicensingTests extends BaseMlIntegTestCase {
client.addTransportAddress(internalCluster().getDataNodeInstance(Transport.class).boundAddress().publishAddress()); client.addTransportAddress(internalCluster().getDataNodeInstance(Transport.class).boundAddress().publishAddress());
// re-open job now that the license is valid again // re-open job now that the license is valid again
PlainActionFuture<OpenJobAction.Response> openJobListener = PlainActionFuture.newFuture(); PlainActionFuture<OpenJobAction.Response> openJobListener = PlainActionFuture.newFuture();
new MachineLearningClient(client).openJob(new OpenJobAction.Request("foo"), openJobListener); new MachineLearningClient(client).openJob(new OpenJobAction.Request(jobId), openJobListener);
OpenJobAction.Response openJobResponse = openJobListener.actionGet(); OpenJobAction.Response openJobResponse = openJobListener.actionGet();
assertNotNull(openJobResponse); assertNotNull(openJobResponse);
PlainActionFuture<StartDatafeedAction.Response> listener = PlainActionFuture.newFuture(); PlainActionFuture<StartDatafeedAction.Response> listener = PlainActionFuture.newFuture();
new MachineLearningClient(client).startDatafeed(new StartDatafeedAction.Request("foobar", 0L), listener); new MachineLearningClient(client).startDatafeed(new StartDatafeedAction.Request(datafeedId, 0L), listener);
StartDatafeedAction.Response response = listener.actionGet(); StartDatafeedAction.Response response = listener.actionGet();
assertNotNull(response); assertNotNull(response);
} }
} }
public void testMachineLearningStopDatafeedActionNotRestricted() throws Exception { public void testMachineLearningStopDatafeedActionNotRestricted() throws Exception {
String jobId = "testmachinelearningstopdatafeedactionnotrestricted";
String datafeedId = jobId + "-datafeed";
assertMLAllowed(true); assertMLAllowed(true);
createIndex("foo"); createIndex(jobId + "-data");
// test that license restricted apis do now work // test that license restricted apis do now work
try (TransportClient client = new TestXPackTransportClient(internalCluster().transportClient().settings())) { try (TransportClient client = new TestXPackTransportClient(internalCluster().transportClient().settings())) {
client.addTransportAddress(internalCluster().getDataNodeInstance(Transport.class).boundAddress().publishAddress()); client.addTransportAddress(internalCluster().getDataNodeInstance(Transport.class).boundAddress().publishAddress());
PlainActionFuture<PutJobAction.Response> putJobListener = PlainActionFuture.newFuture(); PlainActionFuture<PutJobAction.Response> putJobListener = PlainActionFuture.newFuture();
new MachineLearningClient(client).putJob(new PutJobAction.Request(createJob("foo")), putJobListener); new MachineLearningClient(client).putJob(new PutJobAction.Request(createJob(jobId)), putJobListener);
PutJobAction.Response putJobResponse = putJobListener.actionGet(); PutJobAction.Response putJobResponse = putJobListener.actionGet();
assertNotNull(putJobResponse); assertNotNull(putJobResponse);
PlainActionFuture<PutDatafeedAction.Response> putDatafeedListener = PlainActionFuture.newFuture(); PlainActionFuture<PutDatafeedAction.Response> putDatafeedListener = PlainActionFuture.newFuture();
new MachineLearningClient(client).putDatafeed( new MachineLearningClient(client).putDatafeed(
new PutDatafeedAction.Request(createDatafeed("foobar", "foo", Collections.singletonList("foo"))), putDatafeedListener); new PutDatafeedAction.Request(createDatafeed(datafeedId, jobId, Collections.singletonList(jobId))), putDatafeedListener);
PutDatafeedAction.Response putDatafeedResponse = putDatafeedListener.actionGet(); PutDatafeedAction.Response putDatafeedResponse = putDatafeedListener.actionGet();
assertNotNull(putDatafeedResponse); assertNotNull(putDatafeedResponse);
PlainActionFuture<OpenJobAction.Response> openJobListener = PlainActionFuture.newFuture(); PlainActionFuture<OpenJobAction.Response> openJobListener = PlainActionFuture.newFuture();
new MachineLearningClient(client).openJob(new OpenJobAction.Request("foo"), openJobListener); new MachineLearningClient(client).openJob(new OpenJobAction.Request(jobId), openJobListener);
OpenJobAction.Response openJobResponse = openJobListener.actionGet(); OpenJobAction.Response openJobResponse = openJobListener.actionGet();
assertNotNull(openJobResponse); assertNotNull(openJobResponse);
PlainActionFuture<StartDatafeedAction.Response> startDatafeedListener = PlainActionFuture.newFuture(); PlainActionFuture<StartDatafeedAction.Response> startDatafeedListener = PlainActionFuture.newFuture();
new MachineLearningClient(client).startDatafeed(new StartDatafeedAction.Request("foobar", 0L), startDatafeedListener); new MachineLearningClient(client).startDatafeed(new StartDatafeedAction.Request(datafeedId, 0L), startDatafeedListener);
StartDatafeedAction.Response startDatafeedResponse = startDatafeedListener.actionGet(); StartDatafeedAction.Response startDatafeedResponse = startDatafeedListener.actionGet();
assertNotNull(startDatafeedResponse); assertNotNull(startDatafeedResponse);
} }
@ -378,12 +384,12 @@ public class MachineLearningLicensingTests extends BaseMlIntegTestCase {
try (TransportClient client = new TestXPackTransportClient(internalCluster().transportClient().settings())) { try (TransportClient client = new TestXPackTransportClient(internalCluster().transportClient().settings())) {
client.addTransportAddress(internalCluster().getDataNodeInstance(Transport.class).boundAddress().publishAddress()); client.addTransportAddress(internalCluster().getDataNodeInstance(Transport.class).boundAddress().publishAddress());
PlainActionFuture<StopDatafeedAction.Response> listener = PlainActionFuture.newFuture(); PlainActionFuture<StopDatafeedAction.Response> listener = PlainActionFuture.newFuture();
new MachineLearningClient(client).stopDatafeed(new StopDatafeedAction.Request("foobar"), listener); new MachineLearningClient(client).stopDatafeed(new StopDatafeedAction.Request(datafeedId), listener);
if (invalidLicense) { if (invalidLicense) {
// the stop datafeed due to invalid license happens async, so check if the datafeed turns into stopped state: // the stop datafeed due to invalid license happens async, so check if the datafeed turns into stopped state:
assertBusy(() -> { assertBusy(() -> {
GetDatafeedsStatsAction.Response response = GetDatafeedsStatsAction.Response response =
new MachineLearningClient(client).getDatafeedsStats(new GetDatafeedsStatsAction.Request("foobar")).actionGet(); new MachineLearningClient(client).getDatafeedsStats(new GetDatafeedsStatsAction.Request(datafeedId)).actionGet();
assertEquals(DatafeedState.STOPPED, response.getResponse().results().get(0).getDatafeedState()); assertEquals(DatafeedState.STOPPED, response.getResponse().results().get(0).getDatafeedState());
}); });
} else { } else {
@ -393,17 +399,17 @@ public class MachineLearningLicensingTests extends BaseMlIntegTestCase {
} }
public void testMachineLearningCloseJobActionNotRestricted() throws Exception { public void testMachineLearningCloseJobActionNotRestricted() throws Exception {
String jobId = "testmachinelearningclosejobactionnotrestricted";
assertMLAllowed(true); assertMLAllowed(true);
// test that license restricted apis do now work // test that license restricted apis do now work
try (TransportClient client = new TestXPackTransportClient(internalCluster().transportClient().settings())) { try (TransportClient client = new TestXPackTransportClient(internalCluster().transportClient().settings())) {
client.addTransportAddress(internalCluster().getDataNodeInstance(Transport.class).boundAddress().publishAddress()); client.addTransportAddress(internalCluster().getDataNodeInstance(Transport.class).boundAddress().publishAddress());
PlainActionFuture<PutJobAction.Response> putJobListener = PlainActionFuture.newFuture(); PlainActionFuture<PutJobAction.Response> putJobListener = PlainActionFuture.newFuture();
new MachineLearningClient(client).putJob(new PutJobAction.Request(createJob("foo")), putJobListener); new MachineLearningClient(client).putJob(new PutJobAction.Request(createJob(jobId)), putJobListener);
PutJobAction.Response putJobResponse = putJobListener.actionGet(); PutJobAction.Response putJobResponse = putJobListener.actionGet();
assertNotNull(putJobResponse); assertNotNull(putJobResponse);
PlainActionFuture<OpenJobAction.Response> openJobListener = PlainActionFuture.newFuture(); PlainActionFuture<OpenJobAction.Response> openJobListener = PlainActionFuture.newFuture();
new MachineLearningClient(client).openJob(new OpenJobAction.Request("foo"), openJobListener); new MachineLearningClient(client).openJob(new OpenJobAction.Request(jobId), openJobListener);
OpenJobAction.Response openJobResponse = openJobListener.actionGet(); OpenJobAction.Response openJobResponse = openJobListener.actionGet();
assertNotNull(openJobResponse); assertNotNull(openJobResponse);
} }
@ -418,13 +424,13 @@ public class MachineLearningLicensingTests extends BaseMlIntegTestCase {
try (TransportClient client = new TestXPackTransportClient(internalCluster().transportClient().settings())) { try (TransportClient client = new TestXPackTransportClient(internalCluster().transportClient().settings())) {
client.addTransportAddress(internalCluster().getDataNodeInstance(Transport.class).boundAddress().publishAddress()); client.addTransportAddress(internalCluster().getDataNodeInstance(Transport.class).boundAddress().publishAddress());
PlainActionFuture<CloseJobAction.Response> listener = PlainActionFuture.newFuture(); PlainActionFuture<CloseJobAction.Response> listener = PlainActionFuture.newFuture();
CloseJobAction.Request request = new CloseJobAction.Request("foo"); CloseJobAction.Request request = new CloseJobAction.Request(jobId);
request.setCloseTimeout(TimeValue.timeValueSeconds(20)); request.setCloseTimeout(TimeValue.timeValueSeconds(20));
if (invalidLicense) { if (invalidLicense) {
// the close due to invalid license happens async, so check if the job turns into closed state: // the close due to invalid license happens async, so check if the job turns into closed state:
assertBusy(() -> { assertBusy(() -> {
GetJobsStatsAction.Response response = GetJobsStatsAction.Response response =
new MachineLearningClient(client).getJobsStats(new GetJobsStatsAction.Request("foo")).actionGet(); new MachineLearningClient(client).getJobsStats(new GetJobsStatsAction.Request(jobId)).actionGet();
assertEquals(JobState.CLOSED, response.getResponse().results().get(0).getState()); assertEquals(JobState.CLOSED, response.getResponse().results().get(0).getState());
}); });
} else { } else {
@ -435,13 +441,13 @@ public class MachineLearningLicensingTests extends BaseMlIntegTestCase {
} }
public void testMachineLearningDeleteJobActionNotRestricted() throws Exception { public void testMachineLearningDeleteJobActionNotRestricted() throws Exception {
String jobId = "testmachinelearningclosejobactionnotrestricted";
assertMLAllowed(true); assertMLAllowed(true);
// test that license restricted apis do now work // test that license restricted apis do now work
try (TransportClient client = new TestXPackTransportClient(internalCluster().transportClient().settings())) { try (TransportClient client = new TestXPackTransportClient(internalCluster().transportClient().settings())) {
client.addTransportAddress(internalCluster().getDataNodeInstance(Transport.class).boundAddress().publishAddress()); client.addTransportAddress(internalCluster().getDataNodeInstance(Transport.class).boundAddress().publishAddress());
PlainActionFuture<PutJobAction.Response> putJobListener = PlainActionFuture.newFuture(); PlainActionFuture<PutJobAction.Response> putJobListener = PlainActionFuture.newFuture();
new MachineLearningClient(client).putJob(new PutJobAction.Request(createJob("foo")), putJobListener); new MachineLearningClient(client).putJob(new PutJobAction.Request(createJob(jobId)), putJobListener);
PutJobAction.Response putJobResponse = putJobListener.actionGet(); PutJobAction.Response putJobResponse = putJobListener.actionGet();
assertNotNull(putJobResponse); assertNotNull(putJobResponse);
} }
@ -453,24 +459,25 @@ public class MachineLearningLicensingTests extends BaseMlIntegTestCase {
try (TransportClient client = new TestXPackTransportClient(internalCluster().transportClient().settings())) { try (TransportClient client = new TestXPackTransportClient(internalCluster().transportClient().settings())) {
client.addTransportAddress(internalCluster().getDataNodeInstance(Transport.class).boundAddress().publishAddress()); client.addTransportAddress(internalCluster().getDataNodeInstance(Transport.class).boundAddress().publishAddress());
PlainActionFuture<DeleteJobAction.Response> listener = PlainActionFuture.newFuture(); PlainActionFuture<DeleteJobAction.Response> listener = PlainActionFuture.newFuture();
new MachineLearningClient(client).deleteJob(new DeleteJobAction.Request("foo"), listener); new MachineLearningClient(client).deleteJob(new DeleteJobAction.Request(jobId), listener);
listener.actionGet(); listener.actionGet();
} }
} }
public void testMachineLearningDeleteDatafeedActionNotRestricted() throws Exception { public void testMachineLearningDeleteDatafeedActionNotRestricted() throws Exception {
String jobId = "testmachinelearningdeletedatafeedactionnotrestricted";
String datafeedId = jobId + "-datafeed";
assertMLAllowed(true); assertMLAllowed(true);
// test that license restricted apis do now work // test that license restricted apis do now work
try (TransportClient client = new TestXPackTransportClient(internalCluster().transportClient().settings())) { try (TransportClient client = new TestXPackTransportClient(internalCluster().transportClient().settings())) {
client.addTransportAddress(internalCluster().getDataNodeInstance(Transport.class).boundAddress().publishAddress()); client.addTransportAddress(internalCluster().getDataNodeInstance(Transport.class).boundAddress().publishAddress());
PlainActionFuture<PutJobAction.Response> putJobListener = PlainActionFuture.newFuture(); PlainActionFuture<PutJobAction.Response> putJobListener = PlainActionFuture.newFuture();
new MachineLearningClient(client).putJob(new PutJobAction.Request(createJob("foo")), putJobListener); new MachineLearningClient(client).putJob(new PutJobAction.Request(createJob(jobId)), putJobListener);
PutJobAction.Response putJobResponse = putJobListener.actionGet(); PutJobAction.Response putJobResponse = putJobListener.actionGet();
assertNotNull(putJobResponse); assertNotNull(putJobResponse);
PlainActionFuture<PutDatafeedAction.Response> putDatafeedListener = PlainActionFuture.newFuture(); PlainActionFuture<PutDatafeedAction.Response> putDatafeedListener = PlainActionFuture.newFuture();
new MachineLearningClient(client).putDatafeed( new MachineLearningClient(client).putDatafeed(
new PutDatafeedAction.Request(createDatafeed("foobar", "foo", Collections.singletonList("foo"))), putDatafeedListener); new PutDatafeedAction.Request(createDatafeed(datafeedId, jobId, Collections.singletonList(jobId))), putDatafeedListener);
PutDatafeedAction.Response putDatafeedResponse = putDatafeedListener.actionGet(); PutDatafeedAction.Response putDatafeedResponse = putDatafeedListener.actionGet();
assertNotNull(putDatafeedResponse); assertNotNull(putDatafeedResponse);
} }
@ -482,7 +489,7 @@ public class MachineLearningLicensingTests extends BaseMlIntegTestCase {
try (TransportClient client = new TestXPackTransportClient(internalCluster().transportClient().settings())) { try (TransportClient client = new TestXPackTransportClient(internalCluster().transportClient().settings())) {
client.addTransportAddress(internalCluster().getDataNodeInstance(Transport.class).boundAddress().publishAddress()); client.addTransportAddress(internalCluster().getDataNodeInstance(Transport.class).boundAddress().publishAddress());
PlainActionFuture<DeleteDatafeedAction.Response> listener = PlainActionFuture.newFuture(); PlainActionFuture<DeleteDatafeedAction.Response> listener = PlainActionFuture.newFuture();
new MachineLearningClient(client).deleteDatafeed(new DeleteDatafeedAction.Request("foobar"), listener); new MachineLearningClient(client).deleteDatafeed(new DeleteDatafeedAction.Request(datafeedId), listener);
listener.actionGet(); listener.actionGet();
} }
} }