tedyu commented on code in PR #9651:
URL: https://github.com/apache/gravitino/pull/9651#discussion_r2809381235


##########
maintenance/optimizer/src/main/java/org/apache/gravitino/maintenance/optimizer/recommender/job/GravitinoJobSubmitter.java:
##########
@@ -0,0 +1,95 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.gravitino.maintenance.optimizer.recommender.job;
+
+import com.google.common.annotations.VisibleForTesting;
+import java.util.Map;
+import org.apache.gravitino.client.GravitinoClient;
+import 
org.apache.gravitino.maintenance.optimizer.api.recommender.JobExecutionContext;
+import org.apache.gravitino.maintenance.optimizer.api.recommender.JobSubmitter;
+import org.apache.gravitino.maintenance.optimizer.common.OptimizerEnv;
+import 
org.apache.gravitino.maintenance.optimizer.common.util.GravitinoClientUtils;
+
+/** Submits optimizer jobs to Gravitino using job template adapters. */
+public class GravitinoJobSubmitter implements JobSubmitter {
+
+  public static final String NAME = "gravitino-job-submitter";
+
+  private GravitinoClient gravitinoClient;
+
+  private final Map<String, Class<? extends GravitinoJobAdapter>> jobAdapters 
= Map.of();
+
+  /**
+   * Returns the provider name for configuration lookup.
+   *
+   * @return provider name
+   */
+  @Override
+  public String name() {
+    return NAME;
+  }
+
+  /**
+   * Initializes the submitter with a Gravitino client derived from the 
optimizer configuration.
+   *
+   * @param optimizerEnv optimizer environment
+   */
+  @Override
+  public void initialize(OptimizerEnv optimizerEnv) {
+    this.gravitinoClient = GravitinoClientUtils.createClient(optimizerEnv);
+  }
+
+  /**
+   * Submits a job through Gravitino using the resolved job adapter.
+   *
+   * @param jobTemplateName template name used to select an adapter
+   * @param jobExecutionContext execution context for the job
+   * @return submitted job identifier
+   */
+  @Override
+  public String submitJob(String jobTemplateName, JobExecutionContext 
jobExecutionContext) {
+    GravitinoJobAdapter jobAdapter = loadJobAdapter(jobTemplateName);
+    return gravitinoClient
+        .runJob(jobTemplateName, jobAdapter.jobConfig(jobExecutionContext))
+        .jobId();
+  }
+
+  /** Closes the underlying Gravitino client. */
+  @Override
+  public void close() throws Exception {
+    if (gravitinoClient != null) {
+      gravitinoClient.close();

Review Comment:
   It seems `gravitinoClient` should be set to null after closing.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to