|
@@ -6,17 +6,22 @@
|
|
|
|
|
|
package org.elasticsearch.xpack.deprecation;
|
|
|
|
|
|
+import org.elasticsearch.Version;
|
|
|
import org.elasticsearch.action.ActionListener;
|
|
|
import org.elasticsearch.common.settings.Settings;
|
|
|
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
|
|
|
import org.elasticsearch.xpack.core.XPackSettings;
|
|
|
+import org.elasticsearch.xpack.core.action.util.PageParams;
|
|
|
import org.elasticsearch.xpack.core.deprecation.DeprecationIssue;
|
|
|
import org.elasticsearch.xpack.core.ml.action.GetDatafeedsAction;
|
|
|
+import org.elasticsearch.xpack.core.ml.action.GetModelSnapshotsAction;
|
|
|
import org.elasticsearch.xpack.core.ml.datafeed.DatafeedConfig;
|
|
|
+import org.elasticsearch.xpack.core.ml.job.process.autodetect.state.ModelSnapshot;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Collections;
|
|
|
import java.util.List;
|
|
|
+import java.util.Locale;
|
|
|
import java.util.Optional;
|
|
|
|
|
|
public class MlDeprecationChecker implements DeprecationChecker {
|
|
@@ -45,6 +50,29 @@ public class MlDeprecationChecker implements DeprecationChecker {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ static Optional<DeprecationIssue> checkModelSnapshot(ModelSnapshot modelSnapshot) {
|
|
|
+ if (modelSnapshot.getMinVersion().before(Version.V_7_0_0)) {
|
|
|
+ return Optional.of(new DeprecationIssue(DeprecationIssue.Level.CRITICAL,
|
|
|
+ String.format(
|
|
|
+ Locale.ROOT,
|
|
|
+ "model snapshot [%s] for job [%s] needs to be deleted or upgraded",
|
|
|
+ modelSnapshot.getSnapshotId(),
|
|
|
+ modelSnapshot.getJobId()
|
|
|
+ ),
|
|
|
+ "https://www.elastic.co/guide/en/elasticsearch/reference/master/ml-upgrade-job-model-snapshot.html",
|
|
|
+ String.format(
|
|
|
+ Locale.ROOT,
|
|
|
+ "model snapshot [%s] for job [%s] supports minimum version [%s] and needs to be at least [%s]",
|
|
|
+ modelSnapshot.getSnapshotId(),
|
|
|
+ modelSnapshot.getJobId(),
|
|
|
+ modelSnapshot.getMinVersion(),
|
|
|
+ Version.V_7_0_0
|
|
|
+ )
|
|
|
+ ));
|
|
|
+ }
|
|
|
+ return Optional.empty();
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public boolean enabled(Settings settings) {
|
|
|
return XPackSettings.MACHINE_LEARNING_ENABLED.get(settings);
|
|
@@ -56,16 +84,36 @@ public class MlDeprecationChecker implements DeprecationChecker {
|
|
|
deprecationIssueListener.onResponse(new CheckResult(getName(), Collections.emptyList()));
|
|
|
return;
|
|
|
}
|
|
|
+ List<DeprecationIssue> issues = Collections.synchronizedList(new ArrayList<>());
|
|
|
+ final GetModelSnapshotsAction.Request getModelSnapshots = new GetModelSnapshotsAction.Request("*", null);
|
|
|
+ getModelSnapshots.setPageParams(new PageParams(0, 50));
|
|
|
+ getModelSnapshots.setSort(ModelSnapshot.MIN_VERSION.getPreferredName());
|
|
|
+
|
|
|
+ ActionListener<Void> getModelSnaphots = ActionListener.wrap(
|
|
|
+ _unused -> components.client().execute(
|
|
|
+ GetModelSnapshotsAction.INSTANCE,
|
|
|
+ getModelSnapshots,
|
|
|
+ ActionListener.wrap(
|
|
|
+ modelSnapshots -> {
|
|
|
+ modelSnapshots.getResources()
|
|
|
+ .results()
|
|
|
+ .forEach(modelSnapshot -> checkModelSnapshot(modelSnapshot)
|
|
|
+ .ifPresent(issues::add));
|
|
|
+ deprecationIssueListener.onResponse(new CheckResult(getName(), issues));
|
|
|
+ },
|
|
|
+ deprecationIssueListener::onFailure)
|
|
|
+ ),
|
|
|
+ deprecationIssueListener::onFailure);
|
|
|
+
|
|
|
components.client().execute(
|
|
|
GetDatafeedsAction.INSTANCE,
|
|
|
new GetDatafeedsAction.Request(GetDatafeedsAction.ALL), ActionListener.wrap(
|
|
|
datafeedsResponse -> {
|
|
|
- List<DeprecationIssue> issues = new ArrayList<>();
|
|
|
for (DatafeedConfig df : datafeedsResponse.getResponse().results()) {
|
|
|
checkDataFeedAggregations(df, components.xContentRegistry()).ifPresent(issues::add);
|
|
|
checkDataFeedQuery(df, components.xContentRegistry()).ifPresent(issues::add);
|
|
|
}
|
|
|
- deprecationIssueListener.onResponse(new CheckResult(getName(), issues));
|
|
|
+ getModelSnaphots.onResponse(null);
|
|
|
},
|
|
|
deprecationIssueListener::onFailure
|
|
|
)
|