|
8 | 8 | import static org.opensearch.ml.common.settings.MLCommonsSettings.ML_COMMONS_SYNC_UP_JOB_INTERVAL_IN_SECONDS; |
9 | 9 | import static org.opensearch.ml.plugin.MachineLearningPlugin.GENERAL_THREAD_POOL; |
10 | 10 |
|
| 11 | +import java.io.IOException; |
| 12 | +import java.time.Instant; |
| 13 | +import java.time.temporal.ChronoUnit; |
11 | 14 | import java.util.List; |
12 | 15 |
|
| 16 | +import org.opensearch.action.index.IndexRequest; |
| 17 | +import org.opensearch.action.support.WriteRequest; |
13 | 18 | import org.opensearch.cluster.LocalNodeClusterManagerListener; |
14 | 19 | import org.opensearch.cluster.service.ClusterService; |
15 | 20 | import org.opensearch.common.lifecycle.LifecycleListener; |
16 | 21 | import org.opensearch.common.settings.Settings; |
17 | 22 | import org.opensearch.common.unit.TimeValue; |
| 23 | +import org.opensearch.common.xcontent.json.JsonXContent; |
18 | 24 | import org.opensearch.core.action.ActionListener; |
| 25 | +import org.opensearch.jobscheduler.spi.schedule.IntervalSchedule; |
19 | 26 | import org.opensearch.ml.autoredeploy.MLModelAutoReDeployer; |
20 | 27 | import org.opensearch.ml.common.settings.MLFeatureEnabledSetting; |
21 | 28 | import org.opensearch.ml.engine.encryptor.Encryptor; |
22 | 29 | import org.opensearch.ml.engine.indices.MLIndicesHandler; |
| 30 | +import org.opensearch.ml.common.CommonValue; |
| 31 | +import org.opensearch.ml.engine.encryptor.Encryptor; |
| 32 | +import org.opensearch.ml.engine.indices.MLIndicesHandler; |
| 33 | +import org.opensearch.ml.jobs.MLJobParameter; |
| 34 | +import org.opensearch.ml.jobs.MLJobType; |
| 35 | +import org.opensearch.ml.settings.MLFeatureEnabledSetting; |
23 | 36 | import org.opensearch.remote.metadata.client.SdkClient; |
24 | 37 | import org.opensearch.threadpool.Scheduler; |
25 | 38 | import org.opensearch.threadpool.ThreadPool; |
@@ -95,6 +108,40 @@ public void onClusterManager() { |
95 | 108 | TimeValue.timeValueSeconds(jobInterval), |
96 | 109 | GENERAL_THREAD_POOL |
97 | 110 | ); |
| 111 | +// startStatsCollectorJob(); |
| 112 | + } |
| 113 | + |
| 114 | + public void startStatsCollectorJob() { |
| 115 | + try { |
| 116 | + int intervalInMinutes = 5; |
| 117 | + Long lockDurationSeconds = 20L; |
| 118 | + |
| 119 | + MLJobParameter jobParameter = new MLJobParameter( |
| 120 | + MLJobType.STATS_COLLECTOR.name(), |
| 121 | + new IntervalSchedule(Instant.now(), intervalInMinutes, ChronoUnit.MINUTES), |
| 122 | + lockDurationSeconds, |
| 123 | + null, |
| 124 | + MLJobType.STATS_COLLECTOR |
| 125 | + ); |
| 126 | + |
| 127 | + IndexRequest indexRequest = new IndexRequest() |
| 128 | + .index(CommonValue.ML_JOBS_INDEX) |
| 129 | + .id(MLJobType.STATS_COLLECTOR.name()) |
| 130 | + .source(jobParameter.toXContent(JsonXContent.contentBuilder(), null)) |
| 131 | + .setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE); |
| 132 | + |
| 133 | + client |
| 134 | + .index( |
| 135 | + indexRequest, |
| 136 | + ActionListener |
| 137 | + .wrap( |
| 138 | + r -> log.info("Indexed ml stats collection job successfully"), |
| 139 | + e -> log.error("Failed to index stats collection job", e) |
| 140 | + ) |
| 141 | + ); |
| 142 | + } catch (IOException e) { |
| 143 | + log.error("Failed to index stats collection job", e); |
| 144 | + } |
98 | 145 | } |
99 | 146 |
|
100 | 147 | private void startSyncModelRoutingCron() { |
|
0 commit comments