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.
This commit is contained in:
Ryan Ernst 2019-06-13 11:38:29 -07:00
parent 8f7cd84422
commit c3ce3f6891
2 changed files with 33 additions and 1 deletions

View File

@ -57,7 +57,13 @@ This is a possible response:
} }
}, },
"upgrade_mode": false, "upgrade_mode": false,
"native_code" : {
"version": "7.0.0",
"build_hash": "99a07c016d5a73"
},
"limits" : { } "limits" : { }
} }
---- ----
// TESTRESPONSE[s/"upgrade_mode": false/"upgrade_mode": $body.upgrade_mode/] // 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"/]

View File

@ -12,6 +12,7 @@ import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.unit.ByteSizeUnit; import org.elasticsearch.common.unit.ByteSizeUnit;
import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.common.unit.ByteSizeValue;
import org.elasticsearch.env.Environment;
import org.elasticsearch.tasks.Task; import org.elasticsearch.tasks.Task;
import org.elasticsearch.transport.TransportService; import org.elasticsearch.transport.TransportService;
import org.elasticsearch.xpack.core.ml.MachineLearningField; 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.datafeed.DatafeedConfig;
import org.elasticsearch.xpack.core.ml.job.config.AnalysisLimits; import org.elasticsearch.xpack.core.ml.job.config.AnalysisLimits;
import org.elasticsearch.xpack.core.ml.job.config.Job; 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.HashMap;
import java.util.Map; import java.util.Map;
import java.util.concurrent.TimeoutException;
import java.util.function.Supplier; import java.util.function.Supplier;
public class TransportMlInfoAction extends HandledTransportAction<MlInfoAction.Request, MlInfoAction.Response> { public class TransportMlInfoAction extends HandledTransportAction<MlInfoAction.Request, MlInfoAction.Response> {
private final ClusterService clusterService; private final ClusterService clusterService;
private final Map<String, Object> nativeCodeInfo;
@Inject @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); super(MlInfoAction.NAME, transportService, actionFilters, (Supplier<MlInfoAction.Request>) MlInfoAction.Request::new);
this.clusterService = clusterService; 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 @Override
@ -40,6 +65,7 @@ public class TransportMlInfoAction extends HandledTransportAction<MlInfoAction.R
Map<String, Object> info = new HashMap<>(); Map<String, Object> info = new HashMap<>();
info.put("defaults", defaults()); info.put("defaults", defaults());
info.put("limits", limits()); info.put("limits", limits());
info.put("native_code", nativeCodeInfo);
info.put(MlMetadata.UPGRADE_MODE.getPreferredName(), upgradeMode()); info.put(MlMetadata.UPGRADE_MODE.getPreferredName(), upgradeMode());
listener.onResponse(new MlInfoAction.Response(info)); listener.onResponse(new MlInfoAction.Response(info));
} }