-
Notifications
You must be signed in to change notification settings - Fork 25k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ML] Job in index: Restore ability to update cluster state jobs (#35539)
Job updates can apply to cluster state or index jobs this includes reverting a model snapshot and finalizing the job
- Loading branch information
Showing
6 changed files
with
418 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/ClusterStateJobUpdate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
package org.elasticsearch.xpack.ml.job; | ||
|
||
import org.elasticsearch.cluster.ClusterState; | ||
import org.elasticsearch.cluster.metadata.MetaData; | ||
import org.elasticsearch.xpack.core.XPackPlugin; | ||
import org.elasticsearch.xpack.core.ml.MlMetadata; | ||
import org.elasticsearch.xpack.core.ml.job.config.Job; | ||
|
||
/** | ||
* Helper functions for managing cluster state job configurations | ||
*/ | ||
public final class ClusterStateJobUpdate { | ||
|
||
private ClusterStateJobUpdate() { | ||
} | ||
|
||
public static boolean jobIsInClusterState(ClusterState clusterState, String jobId) { | ||
MlMetadata mlMetadata = MlMetadata.getMlMetadata(clusterState); | ||
return mlMetadata.getJobs().containsKey(jobId); | ||
} | ||
|
||
public static boolean jobIsInMlMetadata(MlMetadata mlMetadata, String jobId) { | ||
return mlMetadata.getJobs().containsKey(jobId); | ||
} | ||
|
||
public static ClusterState putJobInClusterState(Job job, boolean overwrite, ClusterState currentState) { | ||
MlMetadata.Builder builder = createMlMetadataBuilder(currentState); | ||
builder.putJob(job, overwrite); | ||
return buildNewClusterState(currentState, builder); | ||
} | ||
|
||
private static MlMetadata.Builder createMlMetadataBuilder(ClusterState currentState) { | ||
return new MlMetadata.Builder(MlMetadata.getMlMetadata(currentState)); | ||
} | ||
|
||
private static ClusterState buildNewClusterState(ClusterState currentState, MlMetadata.Builder builder) { | ||
XPackPlugin.checkReadyForXPackCustomMetadata(currentState); | ||
ClusterState.Builder newState = ClusterState.builder(currentState); | ||
newState.metaData(MetaData.builder(currentState.getMetaData()).putCustom(MlMetadata.TYPE, builder.build()).build()); | ||
return newState.build(); | ||
} | ||
} |
Oops, something went wrong.