Skip to content

Commit df6857c

Browse files
committed
MlAssignmentNotifier cannot read config from state
1 parent b75ebd1 commit df6857c

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/MlAssignmentNotifier.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,13 @@
1212
import org.elasticsearch.cluster.service.ClusterService;
1313
import org.elasticsearch.common.component.AbstractComponent;
1414
import org.elasticsearch.common.settings.Settings;
15+
import org.elasticsearch.persistent.PersistentTasksCustomMetaData;
16+
import org.elasticsearch.persistent.PersistentTasksCustomMetaData.Assignment;
17+
import org.elasticsearch.persistent.PersistentTasksCustomMetaData.PersistentTask;
1518
import org.elasticsearch.threadpool.ThreadPool;
16-
import org.elasticsearch.xpack.core.ml.MlMetadata;
1719
import org.elasticsearch.xpack.core.ml.MlTasks;
1820
import org.elasticsearch.xpack.core.ml.action.OpenJobAction;
1921
import org.elasticsearch.xpack.core.ml.action.StartDatafeedAction;
20-
import org.elasticsearch.xpack.core.ml.datafeed.DatafeedConfig;
21-
import org.elasticsearch.persistent.PersistentTasksCustomMetaData;
22-
import org.elasticsearch.persistent.PersistentTasksCustomMetaData.Assignment;
23-
import org.elasticsearch.persistent.PersistentTasksCustomMetaData.PersistentTask;
2422
import org.elasticsearch.xpack.ml.notifications.Auditor;
2523

2624
import java.util.Objects;
@@ -89,16 +87,20 @@ public void clusterChanged(ClusterChangedEvent event) {
8987
auditor.info(jobId, "Opening job on node [" + node.toString() + "]");
9088
}
9189
} else if (MlTasks.DATAFEED_TASK_NAME.equals(currentTask.getTaskName())) {
92-
String datafeedId = ((StartDatafeedAction.DatafeedParams) currentTask.getParams()).getDatafeedId();
93-
DatafeedConfig datafeedConfig = MlMetadata.getMlMetadata(event.state()).getDatafeed(datafeedId);
90+
StartDatafeedAction.DatafeedParams datafeedParams = (StartDatafeedAction.DatafeedParams) currentTask.getParams();
91+
String jobId = datafeedParams.getJob() != null ? datafeedParams.getJob().getId() : null;
9492
if (currentAssignment.getExecutorNode() == null) {
95-
String msg = "No node found to start datafeed [" + datafeedId +"]. Reasons [" +
93+
String msg = "No node found to start datafeed [" + datafeedParams.getDatafeedId() +"]. Reasons [" +
9694
currentAssignment.getExplanation() + "]";
97-
logger.warn("[{}] {}", datafeedConfig.getJobId(), msg);
98-
auditor.warning(datafeedConfig.getJobId(), msg);
95+
logger.warn("[{}] {}", jobId, msg);
96+
if (jobId != null) {
97+
auditor.warning(jobId, msg);
98+
}
9999
} else {
100100
DiscoveryNode node = event.state().nodes().get(currentAssignment.getExecutorNode());
101-
auditor.info(datafeedConfig.getJobId(), "Starting datafeed [" + datafeedId + "] on node [" + node + "]");
101+
if (jobId != null) {
102+
auditor.info(jobId, "Starting datafeed [" + datafeedParams.getDatafeedId() + "] on node [" + node + "]");
103+
}
102104
}
103105
}
104106
}

x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/MlAssignmentNotifierTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
public class MlAssignmentNotifierTests extends ESTestCase {
3434

35-
public void testClusterChanged_info() throws Exception {
35+
public void testClusterChanged_info() {
3636
Auditor auditor = mock(Auditor.class);
3737
ClusterService clusterService = mock(ClusterService.class);
3838
MlAssignmentNotifier notifier = new MlAssignmentNotifier(Settings.EMPTY, auditor, clusterService);
@@ -60,7 +60,7 @@ public void testClusterChanged_info() throws Exception {
6060
verifyNoMoreInteractions(auditor);
6161
}
6262

63-
public void testClusterChanged_warning() throws Exception {
63+
public void testClusterChanged_warning() {
6464
Auditor auditor = mock(Auditor.class);
6565
ClusterService clusterService = mock(ClusterService.class);
6666
MlAssignmentNotifier notifier = new MlAssignmentNotifier(Settings.EMPTY, auditor, clusterService);

0 commit comments

Comments
 (0)