|
12 | 12 | import org.elasticsearch.common.inject.Inject; |
13 | 13 | import org.elasticsearch.common.unit.ByteSizeUnit; |
14 | 14 | import org.elasticsearch.common.unit.ByteSizeValue; |
| 15 | +import org.elasticsearch.env.Environment; |
15 | 16 | import org.elasticsearch.tasks.Task; |
16 | 17 | import org.elasticsearch.transport.TransportService; |
17 | 18 | import org.elasticsearch.xpack.core.ml.MachineLearningField; |
|
20 | 21 | import org.elasticsearch.xpack.core.ml.datafeed.DatafeedConfig; |
21 | 22 | import org.elasticsearch.xpack.core.ml.job.config.AnalysisLimits; |
22 | 23 | import org.elasticsearch.xpack.core.ml.job.config.Job; |
| 24 | +import org.elasticsearch.xpack.ml.process.NativeController; |
| 25 | +import org.elasticsearch.xpack.ml.process.NativeControllerHolder; |
23 | 26 |
|
| 27 | +import java.io.IOException; |
| 28 | +import java.util.Collections; |
24 | 29 | import java.util.HashMap; |
25 | 30 | import java.util.Map; |
| 31 | +import java.util.concurrent.TimeoutException; |
26 | 32 | import java.util.function.Supplier; |
27 | 33 |
|
28 | 34 | public class TransportMlInfoAction extends HandledTransportAction<MlInfoAction.Request, MlInfoAction.Response> { |
29 | 35 |
|
30 | 36 | private final ClusterService clusterService; |
| 37 | + private final Map<String, Object> nativeCodeInfo; |
31 | 38 |
|
32 | 39 | @Inject |
33 | | - public TransportMlInfoAction(TransportService transportService, ActionFilters actionFilters, ClusterService clusterService) { |
| 40 | + public TransportMlInfoAction(TransportService transportService, ActionFilters actionFilters, |
| 41 | + ClusterService clusterService, Environment env) { |
34 | 42 | super(MlInfoAction.NAME, transportService, actionFilters, (Supplier<MlInfoAction.Request>) MlInfoAction.Request::new); |
35 | 43 | this.clusterService = clusterService; |
| 44 | + |
| 45 | + try { |
| 46 | + NativeController nativeController = NativeControllerHolder.getNativeController(clusterService.getNodeName(), env); |
| 47 | + // TODO: this leniency is only for tests. it can be removed when NativeController is created as a component and |
| 48 | + // becomes a ctor arg to this action |
| 49 | + if (nativeController != null) { |
| 50 | + nativeCodeInfo = nativeController.getNativeCodeInfo(); |
| 51 | + } else { |
| 52 | + nativeCodeInfo = Collections.emptyMap(); |
| 53 | + } |
| 54 | + } catch (IOException e) { |
| 55 | + // this should not be possible since this action is only registered when ML is enabled, |
| 56 | + // and the MachineLearning plugin would have failed to create components |
| 57 | + throw new IllegalStateException("native controller failed to load", e); |
| 58 | + } catch (TimeoutException e) { |
| 59 | + throw new RuntimeException("Could not get native code info from native controller", e); |
| 60 | + } |
36 | 61 | } |
37 | 62 |
|
38 | 63 | @Override |
39 | 64 | protected void doExecute(Task task, MlInfoAction.Request request, ActionListener<MlInfoAction.Response> listener) { |
40 | 65 | Map<String, Object> info = new HashMap<>(); |
41 | 66 | info.put("defaults", defaults()); |
42 | 67 | info.put("limits", limits()); |
| 68 | + info.put("native_code", nativeCodeInfo); |
43 | 69 | info.put(MlMetadata.UPGRADE_MODE.getPreferredName(), upgradeMode()); |
44 | 70 | listener.onResponse(new MlInfoAction.Response(info)); |
45 | 71 | } |
|
0 commit comments