Skip to content

Commit

Permalink
Add native code info to ML info api (#43172)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rjernst committed Jun 13, 2019
1 parent d9dbf79 commit a3f2f40
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
6 changes: 6 additions & 0 deletions docs/reference/ml/apis/get-ml-info.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -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"/]
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
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;
Expand All @@ -20,26 +21,51 @@
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<MlInfoAction.Request, MlInfoAction.Response> {

private final ClusterService clusterService;
private final Map<String, Object> 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>) 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
protected void doExecute(Task task, MlInfoAction.Request request, ActionListener<MlInfoAction.Response> listener) {
Map<String, Object> 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));
}
Expand Down

0 comments on commit a3f2f40

Please sign in to comment.