From c3ce3f68919a75f03895a9a94b6ab00de11056a8 Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Thu, 13 Jun 2019 11:38:29 -0700 Subject: [PATCH] Add native code info to ML info api (#43172) The machine learning feature of xpack has native binaries with a different commit id than the rest of code. It is currently exposed in the xpack info api. This commit adds that commit information to the ML info api, so that it may be removed from the info api. --- docs/reference/ml/apis/get-ml-info.asciidoc | 6 ++++ .../ml/action/TransportMlInfoAction.java | 28 ++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/docs/reference/ml/apis/get-ml-info.asciidoc b/docs/reference/ml/apis/get-ml-info.asciidoc index 00c57c8cf7f..41b680e1327 100644 --- a/docs/reference/ml/apis/get-ml-info.asciidoc +++ b/docs/reference/ml/apis/get-ml-info.asciidoc @@ -57,7 +57,13 @@ This is a possible response: } }, "upgrade_mode": false, + "native_code" : { + "version": "7.0.0", + "build_hash": "99a07c016d5a73" + }, "limits" : { } } ---- // TESTRESPONSE[s/"upgrade_mode": false/"upgrade_mode": $body.upgrade_mode/] +// TESTRESPONSE[s/"version": "7.0.0",/"version": "$body.native_code.version",/] +// TESTRESPONSE[s/"build_hash": "99a07c016d5a73"/"build_hash": "$body.native_code.build_hash"/] diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportMlInfoAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportMlInfoAction.java index 48fbf9566fd..d423428b3b7 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportMlInfoAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportMlInfoAction.java @@ -12,6 +12,7 @@ import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.unit.ByteSizeUnit; import org.elasticsearch.common.unit.ByteSizeValue; +import org.elasticsearch.env.Environment; import org.elasticsearch.tasks.Task; import org.elasticsearch.transport.TransportService; import org.elasticsearch.xpack.core.ml.MachineLearningField; @@ -20,19 +21,43 @@ import org.elasticsearch.xpack.core.ml.action.MlInfoAction; import org.elasticsearch.xpack.core.ml.datafeed.DatafeedConfig; import org.elasticsearch.xpack.core.ml.job.config.AnalysisLimits; import org.elasticsearch.xpack.core.ml.job.config.Job; +import org.elasticsearch.xpack.ml.process.NativeController; +import org.elasticsearch.xpack.ml.process.NativeControllerHolder; +import java.io.IOException; +import java.util.Collections; import java.util.HashMap; import java.util.Map; +import java.util.concurrent.TimeoutException; import java.util.function.Supplier; public class TransportMlInfoAction extends HandledTransportAction { private final ClusterService clusterService; + private final Map nativeCodeInfo; @Inject - public TransportMlInfoAction(TransportService transportService, ActionFilters actionFilters, ClusterService clusterService) { + public TransportMlInfoAction(TransportService transportService, ActionFilters actionFilters, + ClusterService clusterService, Environment env) { super(MlInfoAction.NAME, transportService, actionFilters, (Supplier) MlInfoAction.Request::new); this.clusterService = clusterService; + + try { + NativeController nativeController = NativeControllerHolder.getNativeController(clusterService.getNodeName(), env); + // TODO: this leniency is only for tests. it can be removed when NativeController is created as a component and + // becomes a ctor arg to this action + if (nativeController != null) { + nativeCodeInfo = nativeController.getNativeCodeInfo(); + } else { + nativeCodeInfo = Collections.emptyMap(); + } + } catch (IOException e) { + // this should not be possible since this action is only registered when ML is enabled, + // and the MachineLearning plugin would have failed to create components + throw new IllegalStateException("native controller failed to load", e); + } catch (TimeoutException e) { + throw new RuntimeException("Could not get native code info from native controller", e); + } } @Override @@ -40,6 +65,7 @@ public class TransportMlInfoAction extends HandledTransportAction info = new HashMap<>(); info.put("defaults", defaults()); info.put("limits", limits()); + info.put("native_code", nativeCodeInfo); info.put(MlMetadata.UPGRADE_MODE.getPreferredName(), upgradeMode()); listener.onResponse(new MlInfoAction.Response(info)); }