Skip to content

World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.

[#7503] feat(core): Add job system API for Gravitino (#7531)

Jerry Shaob261600136f4
diff --git a/api/src/main/java/org/apache/gravitino/exceptions/JobTemplateAlreadyExistsException.java b/api/src/main/java/org/apache/gravitino/exceptions/JobTemplateAlreadyExistsException.java
new file mode 100644
index 0000000000..33f135df3b
--- /dev/null
+++ b/api/src/main/java/org/apache/gravitino/exceptions/JobTemplateAlreadyExistsException.java
@@ -0,0 +1,54 @@
+/*
+ * 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.exceptions;
+
+import com.google.errorprone.annotations.FormatMethod;
+import com.google.errorprone.annotations.FormatString;
+
+/**
+ * An exception thrown when a job template with the specified name already exists. This exception is
+ * typically used to indicate that a requested job template cannot be created because it already
+ * exists in the system.
+ */
+public class JobTemplateAlreadyExistsException extends AlreadyExistsException {
+
+ /**
+ * Constructs a new exception with the specified detail message.
+ *
+ * @param message the detail message.
+ * @param args the arguments to the message.
+ */
+ @FormatMethod
+ public JobTemplateAlreadyExistsException(@FormatString String message, Object... args) {
+ super(message, args);
+ }
+
+ /**
+ * Constructs a new exception with the specified detail message and cause.
+ *
+ * @param cause the cause of the exception.
+ * @param message the detail message.
+ * @param args the arguments to the message.
+ */
+ @FormatMethod
+ public JobTemplateAlreadyExistsException(
+ Throwable cause, @FormatString String message, Object... args) {
+ super(cause, message, args);
+ }
+}
diff --git a/api/src/main/java/org/apache/gravitino/exceptions/NoSuchJobException.java b/api/src/main/java/org/apache/gravitino/exceptions/NoSuchJobException.java
new file mode 100644
index 0000000000..2e43a21929
--- /dev/null
+++ b/api/src/main/java/org/apache/gravitino/exceptions/NoSuchJobException.java
@@ -0,0 +1,52 @@
+/*
+ * 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.exceptions;
+
+import com.google.errorprone.annotations.FormatMethod;
+import com.google.errorprone.annotations.FormatString;
+
+/**
+ * An exception thrown when a job is not found. This exception is typically used to indicate that a
+ * requested job does not exist in the system.
+ */
+public class NoSuchJobException extends NotFoundException {
+
+ /**
+ * Constructs a new NoSuchJobException with the specified detail message.
+ *
+ * @param message the detail message.
+ * @param args the arguments to the message.
+ */
+ @FormatMethod
+ public NoSuchJobException(@FormatString String message, Object... args) {
+ super(message, args);
+ }
+
+ /**
+ * Constructs a new NoSuchJobException with the specified detail message and cause.
+ *
+ * @param cause the cause of the exception.
+ * @param message the detail message.
+ * @param args the arguments to the message.
+ */
+ @FormatMethod
+ public NoSuchJobException(Throwable cause, @FormatString String message, Object... args) {
+ super(cause, message, args);
+ }
+}
diff --git a/api/src/main/java/org/apache/gravitino/exceptions/NoSuchJobTemplateException.java b/api/src/main/java/org/apache/gravitino/exceptions/NoSuchJobTemplateException.java
new file mode 100644
index 0000000000..f97a88ec08
--- /dev/null
+++ b/api/src/main/java/org/apache/gravitino/exceptions/NoSuchJobTemplateException.java
@@ -0,0 +1,52 @@
+/*
+ * 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.exceptions;
+
+import com.google.errorprone.annotations.FormatMethod;
+import com.google.errorprone.annotations.FormatString;
+
+/**
+ * An exception thrown when the job template is not existed. This exception is typically used to
+ * indicate that a requested job template does not exist in the system.
+ */
+public class NoSuchJobTemplateException extends NotFoundException {
+
+ /**
+ * Constructs a new NoSuchJobTemplateException with the specified detail message.
+ *
+ * @param message the detail message.
+ * @param args the arguments to the message.
+ */
+ @FormatMethod
+ public NoSuchJobTemplateException(@FormatString String message, Object... args) {
+ super(message, args);
+ }
+
+ /**
+ * Constructs a new NoSuchJobTemplateException with the specified detail message and cause.
+ *
+ * @param cause the cause of the exception.
+ * @param message the detail message.
+ * @param args the arguments to the message.
+ */
+ @FormatMethod
+ public NoSuchJobTemplateException(Throwable cause, @FormatString String message, Object... args) {
+ super(cause, message, args);
+ }
+}
diff --git a/api/src/main/java/org/apache/gravitino/job/JobHandle.java b/api/src/main/java/org/apache/gravitino/job/JobHandle.java
new file mode 100644
index 0000000000..815e72ea48
--- /dev/null
+++ b/api/src/main/java/org/apache/gravitino/job/JobHandle.java
@@ -0,0 +1,66 @@
+/*
+ * 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.job;
+
+/**
+ * JobHandle is an interface that is returned by the job submission, which provides methods to get
+ * the job name, job ID, job status, and to add listeners for jobs.
+ */
+public interface JobHandle {
+
+ /** The status of the job. */
+ enum Status {
+
+ /** The job is in the queue and waiting to be executed. */
+ QUEUED,
+
+ /** The job is currently being executed. */
+ STARTED,
+
+ /** The job has failed during execution. */
+ FAILED,
+
+ /** The job has completed successfully. */
+ SUCCEEDED,
+
+ /** The job has been cancelled. */
+ CANCELLED;
+ }
+
+ /**
+ * Get the name of the job template.
+ *
+ * @return the name of the job template
+ */
+ String jobTemplateName();
+
+ /**
+ * Get the unique identifier of the job.
+ *
+ * @return the job ID
+ */
+ String jobId();
+
+ /**
+ * Get the current status of the job.
+ *
+ * @return the status of the job
+ */
+ Status jobStatus();
+}
diff --git a/api/src/main/java/org/apache/gravitino/job/JobTemplate.java b/api/src/main/java/org/apache/gravitino/job/JobTemplate.java
new file mode 100644
index 0000000000..51714b6784
--- /dev/null
+++ b/api/src/main/java/org/apache/gravitino/job/JobTemplate.java
@@ -0,0 +1,335 @@
+/*
+ * 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.job;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import org.apache.commons.lang3.StringUtils;
+
+/**
+ * JobTemplate is a class to define all the configuration parameters for a job.
+ *
+ * <p>JobType is enum to define the type of the job, because Gravitino needs different runtime
+ * environments to execute different types of jobs, so the job type is required.
+ *
+ * <p>Some parameters can be templated, which means that they can be replaced with actual values
+ * when running the job, for example, arguments can be { "{{input_path}}", "{{output_path}}" },
+ * environment variables can be { "foo": "{{foo_value}}", "bar": "{{bar_value}}" }. the parameters
+ * support templating are:
+ *
+ * <ul>
+ * <li>arguments
+ * <li>environments
+ * </ul>
+ */
+public abstract class JobTemplate {
+
+ /**
+ * JobType is an enum to define the type of the job.
+ *
+ * <p>Gravitino supports different types of jobs, such as Spark and Shell. The job type is
+ * required to determine the runtime environment for executing the job.
+ */
+ public enum JobType {
+
+ /** Job type for executing a Spark application. */
+ SPARK,
+
+ /** Job type for executing a shell command. */
+ SHELL,
+ }
+
+ /** The name of the job template. */
+ protected final String name;
+
+ /** The comment or description of the job template. */
+ protected final String comment;
+
+ /** The executable path for the job template. */
+ protected final String executable;
+
+ /** The list of arguments for the job template. */
+ protected final List<String> arguments;
+
+ /** The map of environment variables for the job template. */
+ protected final Map<String, String> environments;
+
+ /** The map of custom fields for the job template. */
+ protected final Map<String, String> customFields;
+
+ /**
+ * Constructs a JobTemplate instance with the specified parameters.
+ *
+ * @param builder the builder containing the job template parameters
+ */
+ protected JobTemplate(BaseBuilder<?, ?> builder) {
+ this.name = builder.name;
+ this.comment = builder.comment;
+ this.executable = builder.executable;
+ this.arguments = builder.arguments;
+ this.environments = builder.environments;
+ this.customFields = builder.customFields;
+ }
+
+ /**
+ * Get the job type.
+ *
+ * @return the type of the job template
+ */
+ public abstract JobType jobType();
+
+ /**
+ * Get the name of the job template.
+ *
+ * @return the name of the job template
+ */
+ public String name() {
+ return name;
+ }
+
+ /**
+ * Get the comment for the job template.
+ *
+ * @return the comment
+ */
+ public String comment() {
+ return comment;
+ }
+
+ /**
+ * Get the executable for the job template.
+ *
+ * @return the executable path
+ */
+ public String executable() {
+ return executable;
+ }
+
+ /**
+ * Get the arguments for the job template.
+ *
+ * @return the list of arguments
+ */
+ public List<String> arguments() {
+ return arguments;
+ }
+
+ /**
+ * Get the environment variables for the job template.
+ *
+ * @return the map of environment variables
+ */
+ public Map<String, String> environments() {
+ return environments;
+ }
+
+ /**
+ * Get the custom fields for the job template.
+ *
+ * @return the map of custom fields
+ */
+ public Map<String, String> customFields() {
+ return customFields;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (!(o instanceof JobTemplate)) {
+ return false;
+ }
+
+ JobTemplate that = (JobTemplate) o;
+ return Objects.equals(jobType(), that.jobType())
+ && Objects.equals(name, that.name)
+ && Objects.equals(comment, that.comment)
+ && Objects.equals(executable, that.executable)
+ && Objects.equals(arguments, that.arguments)
+ && Objects.equals(environments, that.environments)
+ && Objects.equals(customFields, that.customFields);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(
+ jobType(), name, comment, executable, arguments, environments, customFields);
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb =
+ new StringBuilder(" jobType=")
+ .append(jobType())
+ .append(",\n")
+ .append(" name='")
+ .append(name)
+ .append("',\n");
+ if (StringUtils.isNotBlank(comment)) {
+ sb.append(" comment='").append(comment).append("',\n");
+ }
+
+ sb.append(" executable='").append(executable).append("',\n");
+
+ if (!arguments.isEmpty()) {
+ sb.append(" arguments=[\n");
+ arguments.forEach(arg -> sb.append(" ").append(arg).append(",\n"));
+ sb.append(" ],\n");
+ } else {
+ sb.append(" arguments=[],\n");
+ }
+
+ if (!environments.isEmpty()) {
+ sb.append(" environments={\n");
+ environments.forEach(
+ (k, v) -> sb.append(" ").append(k).append(": ").append(v).append(",\n"));
+ sb.append(" },\n");
+ } else {
+ sb.append(" environments={},\n");
+ }
+
+ if (!customFields.isEmpty()) {
+ sb.append(" customFields={\n");
+ customFields.forEach(
+ (k, v) -> sb.append(" ").append(k).append(": ").append(v).append(",\n"));
+ sb.append(" }\n");
+ } else {
+ sb.append(" customFields={}\n");
+ }
+
+ return sb.toString();
+ }
+
+ /** Builder class for constructing JobTemplate instances. */
+ public abstract static class BaseBuilder<B extends BaseBuilder<B, P>, P extends JobTemplate> {
+
+ private String name;
+ private String comment;
+ private String executable;
+ private List<String> arguments;
+ private Map<String, String> environments;
+ private Map<String, String> customFields;
+
+ /**
+ * Constructor for the BaseBuilder. This constructor is protected to ensure that only subclasses
+ * can instantiate it.
+ */
+ protected BaseBuilder() {}
+
+ /**
+ * Returns the current instance of the builder.
+ *
+ * @return the current builder instance
+ */
+ protected abstract B self();
+
+ /**
+ * Build the JobTemplate instance.
+ *
+ * @return the constructed JobTemplate instance
+ */
+ public abstract P build();
+
+ /**
+ * Set the name of the job template.
+ *
+ * @param name the name of the job template.
+ * @return this Builder instance
+ */
+ public B withName(String name) {
+ this.name = name;
+ return self();
+ }
+
+ /**
+ * Set the comment for the job template.
+ *
+ * @param comment the comment or description of the job template
+ * @return this Builder instance
+ */
+ public B withComment(String comment) {
+ this.comment = comment;
+ return self();
+ }
+
+ /**
+ * Set the executable for the job template.
+ *
+ * @param executable the path to the executable
+ * @return this Builder instance
+ */
+ public B withExecutable(String executable) {
+ this.executable = executable;
+ return self();
+ }
+
+ /**
+ * Set the arguments for the job template.
+ *
+ * @param arguments the list of arguments
+ * @return this Builder instance
+ */
+ public B withArguments(List<String> arguments) {
+ this.arguments = arguments;
+ return self();
+ }
+
+ /**
+ * Set the environment variables for the job template.
+ *
+ * @param environments the map of environment variables
+ * @return this Builder instance
+ */
+ public B withEnvironments(Map<String, String> environments) {
+ this.environments = environments;
+ return self();
+ }
+
+ /**
+ * Set the custom fields for the job template.
+ *
+ * @param customFields the map of custom fields
+ * @return this Builder instance
+ */
+ public B withCustomFields(Map<String, String> customFields) {
+ this.customFields = customFields;
+ return self();
+ }
+
+ /** Validates the parameters of the job template. */
+ protected void validate() {
+ Preconditions.checkArgument(
+ StringUtils.isNotBlank(name), "Job name must not be null or empty");
+
+ Preconditions.checkArgument(
+ StringUtils.isNotBlank(executable), "Executable must not be null or empty");
+
+ this.arguments = arguments != null ? ImmutableList.copyOf(arguments) : ImmutableList.of();
+ this.environments =
+ environments != null ? ImmutableMap.copyOf(environments) : ImmutableMap.of();
+ this.customFields =
+ customFields != null ? ImmutableMap.copyOf(customFields) : ImmutableMap.of();
+ }
+ }
+}
diff --git a/api/src/main/java/org/apache/gravitino/job/ShellJobTemplate.java b/api/src/main/java/org/apache/gravitino/job/ShellJobTemplate.java
new file mode 100644
index 0000000000..566d2b74eb
--- /dev/null
+++ b/api/src/main/java/org/apache/gravitino/job/ShellJobTemplate.java
@@ -0,0 +1,126 @@
+/*
+ * 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.job;
+
+import com.google.common.collect.ImmutableList;
+import java.util.List;
+import java.util.Objects;
+
+/**
+ * Represents a job template for executing shell scripts. This class extends the JobTemplate class
+ * and provides functionality specific to shell job templates, including a list of scripts to be
+ * executed.
+ */
+public class ShellJobTemplate extends JobTemplate {
+
+ private final List<String> scripts;
+
+ /**
+ * Constructs a ShellJobTemplate with the specified builder.
+ *
+ * @param builder the builder containing the configuration for the shell job template
+ */
+ protected ShellJobTemplate(Builder builder) {
+ super(builder);
+ this.scripts = builder.scripts;
+ }
+
+ /**
+ * Returns the list of scripts to be executed by the shell job template.
+ *
+ * @return the list of scripts
+ */
+ public List<String> scripts() {
+ return scripts;
+ }
+
+ @Override
+ public JobType jobType() {
+ return JobType.SHELL;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof ShellJobTemplate)) return false;
+ if (!super.equals(o)) return false;
+
+ ShellJobTemplate that = (ShellJobTemplate) o;
+ return Objects.equals(scripts, that.scripts);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(super.hashCode(), scripts);
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ if (!scripts.isEmpty()) {
+ sb.append(" scripts=[\n");
+ scripts.forEach(s -> sb.append(" ").append(s).append("\n"));
+ sb.append(" ]\n");
+ } else {
+ sb.append(" scripts=[]\n");
+ }
+
+ return "\nShellJobTemplate{\n" + super.toString() + sb + "}\n";
+ }
+
+ /** Builder for creating instances of {@link ShellJobTemplate}. */
+ public static class Builder extends BaseBuilder<Builder, ShellJobTemplate> {
+
+ private List<String> scripts;
+
+ /**
+ * Sets the scripts to be executed by the shell job template.
+ *
+ * @param scripts the list of scripts to be executed
+ * @return the builder instance for method chaining
+ */
+ public Builder withScripts(List<String> scripts) {
+ this.scripts = scripts;
+ return this;
+ }
+
+ /**
+ * Build the ShellJobTemplate instance.
+ *
+ * @return the constructed ShellJobTemplate
+ */
+ @Override
+ public ShellJobTemplate build() {
+ validate();
+ return new ShellJobTemplate(this);
+ }
+
+ @Override
+ protected Builder self() {
+ return this;
+ }
+
+ @Override
+ protected void validate() {
+ super.validate();
+
+ this.scripts = scripts != null ? ImmutableList.copyOf(scripts) : ImmutableList.of();
+ }
+ }
+}
diff --git a/api/src/main/java/org/apache/gravitino/job/SparkJobTemplate.java b/api/src/main/java/org/apache/gravitino/job/SparkJobTemplate.java
new file mode 100644
index 0000000000..f2a6da13a8
--- /dev/null
+++ b/api/src/main/java/org/apache/gravitino/job/SparkJobTemplate.java
@@ -0,0 +1,264 @@
+/*
+ * 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.job;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import org.apache.commons.lang3.StringUtils;
+
+/**
+ * Represents a job template for executing Spark applications. This class extends the JobTemplate
+ * class and provides functionality specific to Spark job templates, including the class name, jars,
+ * files, archives, and configurations required for the Spark job.
+ */
+public class SparkJobTemplate extends JobTemplate {
+
+ private final String className;
+
+ private final List<String> jars;
+
+ private final List<String> files;
+
+ private final List<String> archives;
+
+ private final Map<String, String> configs;
+
+ /**
+ * Constructs a SparkJobTemplate with the specified builder.
+ *
+ * @param builder the builder containing the configuration for the Spark job template
+ */
+ protected SparkJobTemplate(Builder builder) {
+ super(builder);
+ this.className = builder.className;
+ this.jars = builder.jars;
+ this.files = builder.files;
+ this.archives = builder.archives;
+ this.configs = builder.configs;
+ }
+
+ /**
+ * Returns the class name of the Spark application to be executed.
+ *
+ * @return the class name
+ */
+ public String className() {
+ return className;
+ }
+
+ /**
+ * Returns the list of JAR files required for the Spark job.
+ *
+ * @return the list of JAR files
+ */
+ public List<String> jars() {
+ return jars;
+ }
+
+ /**
+ * Returns the list of files required for the Spark job.
+ *
+ * @return the list of files
+ */
+ public List<String> files() {
+ return files;
+ }
+
+ /**
+ * Returns the list of archives required for the Spark job.
+ *
+ * @return the list of archives
+ */
+ public List<String> archives() {
+ return archives;
+ }
+
+ /**
+ * Returns the configuration map for the Spark job.
+ *
+ * @return the configuration map
+ */
+ public Map<String, String> configs() {
+ return configs;
+ }
+
+ @Override
+ public JobType jobType() {
+ return JobType.SPARK;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof SparkJobTemplate)) return false;
+ if (!super.equals(o)) return false;
+
+ SparkJobTemplate that = (SparkJobTemplate) o;
+ return Objects.equals(className, that.className)
+ && Objects.equals(jars, that.jars)
+ && Objects.equals(files, that.files)
+ && Objects.equals(archives, that.archives)
+ && Objects.equals(configs, that.configs);
+ }
+
+ public int hashCode() {
+ return Objects.hash(super.hashCode(), className, jars, files, archives, configs);
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder("\nSparkJobTemplate{\n");
+ sb.append(" className='").append(className).append("',\n");
+
+ if (!jars.isEmpty()) {
+ sb.append(" jars=[\n");
+ jars.forEach(j -> sb.append(" ").append(j).append("\n"));
+ sb.append(" ],\n");
+ } else {
+ sb.append(" jars=[],\n");
+ }
+
+ if (!files.isEmpty()) {
+ sb.append(" files=[\n");
+ files.forEach(f -> sb.append(" ").append(f).append("\n"));
+ sb.append(" ],\n");
+ } else {
+ sb.append(" files=[],\n");
+ }
+
+ if (!archives.isEmpty()) {
+ sb.append(" archives=[\n");
+ archives.forEach(a -> sb.append(" ").append(a).append("\n"));
+ sb.append(" ],\n");
+ } else {
+ sb.append(" archives=[],\n");
+ }
+
+ if (!configs.isEmpty()) {
+ sb.append(" configs={\n");
+ configs.forEach((k, v) -> sb.append(" ").append(k).append(": ").append(v).append(",\n"));
+ sb.append(" }\n");
+ } else {
+ sb.append(" configs={}\n");
+ }
+
+ return sb + super.toString() + "}\n";
+ }
+
+ /** Builder for creating instances of {@link SparkJobTemplate}. */
+ public static class Builder extends JobTemplate.BaseBuilder<Builder, SparkJobTemplate> {
+
+ private String className;
+
+ private List<String> jars;
+
+ private List<String> files;
+
+ private List<String> archives;
+
+ private Map<String, String> configs;
+
+ /**
+ * Sets the class name of the Spark application to be executed.
+ *
+ * @param className the class name
+ * @return the builder instance for method chaining
+ */
+ public Builder withClassName(String className) {
+ this.className = className;
+ return this;
+ }
+
+ /**
+ * Sets the list of JAR files required for the Spark job.
+ *
+ * @param jars the list of JAR files
+ * @return the builder instance for method chaining
+ */
+ public Builder withJars(List<String> jars) {
+ this.jars = jars;
+ return this;
+ }
+
+ /**
+ * Sets the list of files required for the Spark job.
+ *
+ * @param files the list of files
+ * @return the builder instance for method chaining
+ */
+ public Builder withFiles(List<String> files) {
+ this.files = files;
+ return this;
+ }
+
+ /**
+ * Sets the list of archives required for the Spark job.
+ *
+ * @param archives the list of archives
+ * @return the builder instance for method chaining
+ */
+ public Builder withArchives(List<String> archives) {
+ this.archives = archives;
+ return this;
+ }
+
+ /**
+ * Sets the configuration map for the Spark job.
+ *
+ * @param configs the configuration map
+ * @return the builder instance for method chaining
+ */
+ public Builder withConfigs(Map<String, String> configs) {
+ this.configs = configs;
+ return this;
+ }
+
+ /**
+ * Builds the SparkJobTemplate instance with the specified parameters.
+ *
+ * @return a new instance of SparkJobTemplate
+ */
+ @Override
+ public SparkJobTemplate build() {
+ return new SparkJobTemplate(this);
+ }
+
+ @Override
+ protected Builder self() {
+ return this;
+ }
+
+ @Override
+ protected void validate() {
+ super.validate();
+
+ Preconditions.checkArgument(
+ StringUtils.isNotBlank(className), "Class name must not be null or empty");
+
+ this.jars = jars != null ? ImmutableList.copyOf(jars) : ImmutableList.of();
+ this.files = files != null ? ImmutableList.copyOf(files) : ImmutableList.of();
+ this.archives = archives != null ? ImmutableList.copyOf(archives) : ImmutableList.of();
+ this.configs = configs != null ? ImmutableMap.copyOf(configs) : ImmutableMap.of();
+ }
+ }
+}
diff --git a/api/src/main/java/org/apache/gravitino/job/SupportsJobs.java b/api/src/main/java/org/apache/gravitino/job/SupportsJobs.java
new file mode 100644
index 0000000000..e199107806
--- /dev/null
+++ b/api/src/main/java/org/apache/gravitino/job/SupportsJobs.java
@@ -0,0 +1,124 @@
+/*
+ * 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.job;
+
+import java.util.List;
+import java.util.Map;
+import org.apache.gravitino.exceptions.InUseException;
+import org.apache.gravitino.exceptions.JobTemplateAlreadyExistsException;
+import org.apache.gravitino.exceptions.NoSuchJobException;
+import org.apache.gravitino.exceptions.NoSuchJobTemplateException;
+
+/**
+ * Interface for job management operations. This interface will be mixed with GravitinoClient to
+ * provide the ability to manage job templates and jobs within the Gravitino system.
+ */
+public interface SupportsJobs {
+
+ /**
+ * Lists all the registered job templates in Gravitino.
+ *
+ * @return a list of job templates
+ */
+ List<JobTemplate> listJobTemplates();
+
+ /**
+ * Register a job template with the specified job template to Gravitino. The registered job
+ * template will be maintained in Gravitino, allowing it to be executed later.
+ *
+ * @param jobTemplate the template for the job
+ * @throws JobTemplateAlreadyExistsException if a job template with the same name already exists
+ */
+ void registerJobTemplate(JobTemplate jobTemplate) throws JobTemplateAlreadyExistsException;
+
+ /**
+ * Retrieves a job template by its name.
+ *
+ * @param jobTemplateName the name of the job template to retrieve
+ * @return the job template associated with the specified name
+ * @throws NoSuchJobTemplateException if no job template with the specified name exists
+ */
+ JobTemplate getJobTemplate(String jobTemplateName) throws NoSuchJobTemplateException;
+
+ /**
+ * Deletes a job template by its name. This will remove the job template from Gravitino, and it
+ * will no longer be available for execution. Only when all the jobs associated with this job
+ * template are completed, failed, or cancelled, the job template can be deleted successfully,
+ * otherwise it will throw an exception.
+ *
+ * <p>The deletion of a job template will also delete all the jobs associated with this template.
+ *
+ * @param jobTemplateName the name of the job template to delete
+ * @return true if the job template was successfully deleted, false if the job template does not
+ * exist
+ * @throws InUseException if there are still queued or started jobs associated with the job
+ * template
+ */
+ boolean deleteJobTemplate(String jobTemplateName) throws InUseException;
+
+ /**
+ * Lists all the jobs by the specified job template name. This will return a list of job handles
+ * associated with the specified job template. Each job handle represents a specific job.
+ *
+ * @param jobTemplateName the name of the job template to list jobs for
+ * @return a list of job handles associated with the specified job template
+ * @throws NoSuchJobTemplateException if no job template with the specified name exists
+ */
+ List<JobHandle> listJobs(String jobTemplateName) throws NoSuchJobTemplateException;
+
+ /**
+ * Lists all the jobs in Gravitino. This will return a list of all job handles, regardless of the
+ * job template they are associated with.
+ *
+ * @return a list of all job handles in Gravitino
+ */
+ List<JobHandle> listJobs();
+
+ /**
+ * Run a job with the template name and configuration. The jobConf is a map of key-value contains
+ * the variables that will be used to replace the templated parameters in the job template.
+ *
+ * @param jobTemplateName the name of the job template to run
+ * @param jobConf the configuration for the job
+ * @return a handle to the run job
+ * @throws NoSuchJobTemplateException if no job template with the specified name exists
+ */
+ JobHandle runJob(String jobTemplateName, Map<String, String> jobConf)
+ throws NoSuchJobTemplateException;
+
+ /**
+ * Retrieves a job by its ID.
+ *
+ * @param jobId the ID of the job to retrieve
+ * @return a handle to the job
+ * @throws NoSuchJobException if the job with the specified ID does not exist
+ */
+ JobHandle getJob(String jobId) throws NoSuchJobException;
+
+ /**
+ * Cancel a job by its ID. This operation will attempt to cancel the job if it is still running.
+ * This method will return immediately, user could use the job handle to check the status of the
+ * job after invoking this method.
+ *
+ * @param jobId the ID of the job to cancel
+ * @return a handle to the cancelled job
+ * @throws NoSuchJobException if the job with the specified ID does not exist
+ */
+ JobHandle cancelJob(String jobId) throws NoSuchJobException;
+}
diff --git a/clients/client-python/gravitino/api/job/__init__.py b/clients/client-python/gravitino/api/job/__init__.py
new file mode 100644
index 0000000000..13a83393a9
--- /dev/null
+++ b/clients/client-python/gravitino/api/job/__init__.py
@@ -0,0 +1,16 @@
+# 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.
diff --git a/clients/client-python/gravitino/api/job/job_handle.py b/clients/client-python/gravitino/api/job/job_handle.py
new file mode 100644
index 0000000000..d1b0ba734a
--- /dev/null
+++ b/clients/client-python/gravitino/api/job/job_handle.py
@@ -0,0 +1,40 @@
+# 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.
+
+from abc import ABC, abstractmethod
+from enum import Enum
+
+
+class JobHandle(ABC):
+ class Status(Enum):
+ QUEUED = "QUEUED"
+ STARTED = "STARTED"
+ FAILED = "FAILED"
+ SUCCEEDED = "SUCCEEDED"
+ CANCELLED = "CANCELLED"
+
+ @abstractmethod
+ def job_template_name(self) -> str:
+ pass
+
+ @abstractmethod
+ def job_id(self) -> str:
+ pass
+
+ @abstractmethod
+ def job_status(self) -> Status:
+ pass
diff --git a/clients/client-python/gravitino/api/job/job_template.py b/clients/client-python/gravitino/api/job/job_template.py
new file mode 100644
index 0000000000..755905640c
--- /dev/null
+++ b/clients/client-python/gravitino/api/job/job_template.py
@@ -0,0 +1,301 @@
+# 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.
+from abc import abstractmethod, ABC
+from typing import List, Dict, Optional, TypeVar, Generic, Any
+from enum import Enum
+from copy import deepcopy
+
+
+class JobType(Enum):
+ """
+ JobType is an enum to define the type of the job.
+
+ Gravitino supports different types of jobs, such as Spark and Shell. The job type is
+ required to determine the runtime environment for executing the job.
+ """
+
+ SPARK = "SPARK"
+ """job type for executing Spark jobs"""
+ SHELL = "SHELL"
+ """job type for executing shell commands"""
+
+
+T = TypeVar("T", bound="JobTemplate")
+B = TypeVar("B", bound="BaseBuilder")
+
+
+class JobTemplate(ABC):
+ """
+ JobTemplate is a class to define all the configuration parameters for a job.
+
+ JobType is enum to define the type of the job, because Gravitino needs different runtime
+ environments to execute different types of jobs, so the job type is required.
+
+ Some parameters can be templated, which means that they can be replaced with actual values
+ when running the job, for example, arguments can be { "{input_path}}", "{{output_path}" },
+ environment variables can be { "foo": "{{foo_value}}", "bar": "{{bar_value}}" }. the parameters
+ support templating are: arguments, environments.
+ """
+
+ def __init__(self, builder: "BaseBuilder"):
+ self._name = builder.name
+ self._comment = builder.comment
+ self._executable = builder.executable
+ self._arguments = builder.arguments
+ self._environments = builder.environments
+ self._custom_fields = builder.custom_fields
+
+ @property
+ def name(self) -> str:
+ """
+ Returns:
+ The name of the job template.
+ """
+ return self._name
+
+ @property
+ def comment(self) -> Optional[str]:
+ """
+ Returns:
+ The comment of the job template, which can be used to describe the job.
+ This field is optional and can be None.
+ """
+ return self._comment
+
+ @property
+ def executable(self) -> str:
+ """
+ Returns:
+ The executable of the job template, which is the command or script that will be executed
+ when the job is run. This field is required and must not be empty.
+ """
+ return self._executable
+
+ @property
+ def arguments(self) -> List[str]:
+ """
+ Returns:
+ The arguments of the job template, which are the parameters that will be passed to the
+ executable when the job is run.
+ """
+ return self._arguments
+
+ @property
+ def environments(self) -> Dict[str, str]:
+ """
+ Returns:
+ The environment variables of the job template, which are key-value pairs that will be
+ set in the environment when the job is run. This can include variables that can be
+ templated with actual values when running the job.
+ """
+ return self._environments
+
+ @property
+ def custom_fields(self) -> Dict[str, str]:
+ """
+ Returns:
+ Custom fields of the job template, which are additional key-value pairs that can be
+ used to store any other information related to the job. This field is optional
+ and can be empty.
+ """
+ return self._custom_fields
+
+ @abstractmethod
+ def job_type(self) -> JobType:
+ """
+ Returns:
+ The type of the job template, which is an enum value indicating the type of job
+ (e.g., SPARK, SHELL). This is required to determine the runtime environment for executing
+ the job.
+ """
+ pass
+
+ def __eq__(self, other: Any) -> bool:
+ if self is other:
+ return True
+ if not isinstance(other, JobTemplate):
+ return False
+ return (
+ self.job_type() == other.job_type()
+ and self._name == other.name
+ and self._comment == other.comment
+ and self._executable == other.executable
+ and self._arguments == other.arguments
+ and self._environments == other.environments
+ and self._custom_fields == other.custom_fields
+ )
+
+ def __hash__(self) -> int:
+ return hash(
+ (
+ self.job_type(),
+ self._name,
+ self._comment,
+ self._executable,
+ tuple(self._arguments),
+ frozenset(self._environments.items()),
+ frozenset(self._custom_fields.items()),
+ )
+ )
+
+ def __str__(self) -> str:
+ res = f" jobType={self.job_type()},\n name='{self._name}',\n"
+ if self._comment:
+ res += f" comment='{self._comment}',\n"
+ res += f" executable='{self._executable}',\n"
+
+ if self._arguments:
+ res += (
+ " arguments=[\n"
+ + "".join(f" {arg},\n" for arg in self._arguments)
+ + " ],\n"
+ )
+ else:
+ res += " arguments=[],\n"
+
+ if self._environments:
+ res += (
+ " environments={\n"
+ + "".join(f" {k}: {v},\n" for k, v in self._environments.items())
+ + " },\n"
+ )
+ else:
+ res += " environments={},\n"
+
+ if self._custom_fields:
+ res += (
+ " customFields={\n"
+ + "".join(f" {k}: {v},\n" for k, v in self._custom_fields.items())
+ + " }\n"
+ )
+ else:
+ res += " customFields={}\n"
+
+ return res
+
+ class BaseBuilder(Generic[B, T]):
+ """
+ BaseBuilder is a generic class to build a JobTemplate.
+ """
+
+ def __init__(self: B):
+ self.name: Optional[str] = None
+ self.comment: Optional[str] = None
+ self.executable: Optional[str] = None
+ self.arguments: List[str] = []
+ self.environments: Dict[str, str] = {}
+ self.custom_fields: Dict[str, str] = {}
+
+ def with_name(self: B, name: str) -> B:
+ """
+ Sets the name of the job template.
+
+ Args:
+ name: The name of the job template. It must not be null or empty.
+
+ Returns:
+ The builder instance for method chaining.
+ """
+ self.name = name
+ return self
+
+ def with_comment(self: B, comment: str) -> B:
+ """
+ Sets the comment of the job template.
+
+ Args:
+ comment: The comment of the job template. It can be null or empty.
+
+ Returns:
+ The builder instance for method chaining.
+ """
+ self.comment = comment
+ return self
+
+ def with_executable(self: B, executable: str) -> B:
+ """
+ Sets the executable of the job template.
+
+ Args:
+ executable: The executable of the job template. It must not be null or empty.
+
+ Returns:
+ The builder instance for method chaining.
+ """
+ self.executable = executable
+ return self
+
+ def with_arguments(self: B, arguments: List[str]) -> B:
+ """
+ Sets the arguments of the job template.
+
+ Args:
+ arguments: The arguments of the job template.
+
+ Returns:
+ The builder instance for method chaining.
+ """
+ self.arguments = deepcopy(arguments)
+ return self
+
+ def with_environments(self: B, environments: Dict[str, str]) -> B:
+ """
+ Sets the environment variables of the job template.
+
+ Args:
+ environments: The environment variables of the job template.
+
+ Returns:
+ The builder instance for method chaining.
+ """
+ self.environments = deepcopy(environments)
+ return self
+
+ def with_custom_fields(self: B, custom_fields: Dict[str, str]) -> B:
+ """
+ Sets the custom fields of the job template.
+
+ Args:
+ custom_fields: The custom fields of the job template.
+
+ Returns:
+ The builder instance for method chaining.
+ """
+ self.custom_fields = deepcopy(custom_fields)
+ return self
+
+ def validate(self: B):
+ """
+ Validates the job template parameters.
+ """
+ if not self.name or not self.name.strip():
+ raise ValueError("Job name must not be null or empty")
+ if not self.executable or not self.executable.strip():
+ raise ValueError("Executable must not be null or empty")
+ self.arguments = self.arguments or []
+ self.environments = self.environments or {}
+ self.custom_fields = self.custom_fields or {}
+
+ @abstractmethod
+ def build(self) -> T:
+ """
+ Builds the JobTemplate instance.
+
+ Returns:
+ An instance of JobTemplate with the configured parameters.
+ """
+ pass
diff --git a/clients/client-python/gravitino/api/job/shell_job_template.py b/clients/client-python/gravitino/api/job/shell_job_template.py
new file mode 100644
index 0000000000..2c321bc91b
--- /dev/null
+++ b/clients/client-python/gravitino/api/job/shell_job_template.py
@@ -0,0 +1,117 @@
+# 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.
+
+from copy import deepcopy
+from typing import List, Any
+from .job_template import JobTemplate, JobType
+
+
+class ShellJobTemplate(JobTemplate):
+ """
+ Represents a job template for executing shell scripts.
+ """
+
+ def __init__(self, builder: "ShellJobTemplate.Builder"):
+ """
+ Initializes a ShellJobTemplate instance.
+ """
+ super().__init__(builder)
+ self._scripts = builder.scripts
+
+ @property
+ def scripts(self) -> List[str]:
+ """
+ Returns the list of shell scripts associated with this job template.
+
+ Returns:
+ List of shell scripts.
+ """
+ return self._scripts
+
+ def job_type(self) -> JobType:
+ """
+ Returns the type of the job, which is SHELL for this template.
+
+ Returns:
+ JobType.SHELL: Indicates that this is a shell job template.
+ """
+ return JobType.SHELL
+
+ def __eq__(self, other: Any) -> bool:
+ if not super().__eq__(other):
+ return False
+ return self._scripts == other.scripts
+
+ def __hash__(self) -> int:
+ return hash((super().__hash__(), tuple(self._scripts)))
+
+ def __str__(self) -> str:
+ res = "\nSellJobTemplate{\n"
+ if self._scripts:
+ res += (
+ " scripts=[\n"
+ + "".join(f" {s},\n" for s in self._scripts)
+ + " ],\n"
+ )
+ else:
+ res += " scripts=[],\n"
+
+ return res + super().__str__() + "}\n"
+
+ class Builder(
+ JobTemplate.BaseBuilder["ShellJobTemplate.Builder", "ShellJobTemplate"]
+ ):
+ """
+ Builder class for creating ShellJobTemplate instances.
+ """
+
+ def __init__(self):
+ """
+ Initializes the builder with default values.
+ """
+ super().__init__()
+ self.scripts: List[str] = []
+
+ def with_scripts(self, scripts: List[str]) -> "ShellJobTemplate.Builder":
+ """
+ Sets the shell scripts for this job template.
+
+ Args:
+ scripts: A list of shell scripts to be executed by this job template.
+
+ Returns:
+ ShellJobTemplate.Builder: The builder instance for method chaining.
+ """
+ self.scripts = deepcopy(scripts)
+ return self
+
+ def validate(self):
+ """
+ Validates the builder state before building the ShellJobTemplate.
+ """
+ super().validate()
+ self.scripts = self.scripts or []
+
+ def build(self) -> "ShellJobTemplate":
+ """
+ Builds and returns a ShellJobTemplate instance.
+
+ Returns:
+ ShellJobTemplate: The constructed shell job template.
+ """
+ self.validate()
+ return ShellJobTemplate(self)
diff --git a/clients/client-python/gravitino/api/job/spark_job_template.py b/clients/client-python/gravitino/api/job/spark_job_template.py
new file mode 100644
index 0000000000..d0ac6c1d5e
--- /dev/null
+++ b/clients/client-python/gravitino/api/job/spark_job_template.py
@@ -0,0 +1,259 @@
+# 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.
+
+from copy import deepcopy
+from typing import List, Dict, Optional, Any
+from .job_template import JobTemplate, JobType
+
+
+class SparkJobTemplate(JobTemplate):
+ """
+ Represents a job template for executing Spark jobs.
+ """
+
+ def __init__(self, builder: "SparkJobTemplate.Builder"):
+ """
+ Initializes a SparkJobTemplate instance.
+ """
+ super().__init__(builder)
+ self._class_name = builder.class_name
+ self._jars = builder.jars
+ self._files = builder.files
+ self._archives = builder.archives
+ self._configs = builder.configs
+
+ @property
+ def class_name(self) -> str:
+ """
+ Returns the class name of the Spark job.
+
+ Returns:
+ the class name as a string.
+ """
+ return self._class_name
+
+ @property
+ def jars(self) -> List[str]:
+ """
+ Returns the list of JAR files associated with this Spark job template.
+
+ Returns:
+ List of JAR file paths.
+ """
+ return self._jars
+
+ @property
+ def files(self) -> List[str]:
+ """
+ Returns the list of files associated with this Spark job template.
+
+ Returns:
+ List of file paths.
+ """
+ return self._files
+
+ @property
+ def archives(self) -> List[str]:
+ """
+ Returns the list of archives associated with this Spark job template.
+
+ Returns:
+ List of archive file paths.
+ """
+ return self._archives
+
+ @property
+ def configs(self) -> Dict[str, str]:
+ """
+ Returns the configuration settings for this Spark job template.
+
+ Returns:
+ A dictionary of configuration key-value pairs.
+ """
+ return self._configs
+
+ def job_type(self) -> JobType:
+ """
+ Returns the type of the job, which is SPARK for this template.
+
+ Returns:
+ JobType.SPARK: Indicates that this is a Spark job template.
+ """
+ return JobType.SPARK
+
+ def __eq__(self, other: Any) -> bool:
+ if not super().__eq__(other):
+ return False
+ return (
+ self._class_name == other.class_name
+ and self._jars == other.jars
+ and self._files == other.files
+ and self._archives == other.archives
+ and self._configs == other.configs
+ )
+
+ def __hash__(self) -> int:
+ return hash(
+ (
+ super().__hash__(),
+ self._class_name,
+ tuple(self._jars),
+ tuple(self._files),
+ tuple(self._archives),
+ frozenset(self._configs.items()),
+ )
+ )
+
+ def __str__(self) -> str:
+ result = "\nSparkJobTemplate{\n"
+ result += f" className='{self.class_name}',\n"
+
+ if self._jars:
+ result += (
+ " jars=[\n" + "".join(f" {j},\n" for j in self._jars) + " ],\n"
+ )
+ else:
+ result += " jars=[],\n"
+
+ if self._files:
+ result += (
+ " files=[\n" + "".join(f" {f},\n" for f in self._files) + " ],\n"
+ )
+ else:
+ result += " files=[],\n"
+
+ if self._archives:
+ result += (
+ " archives=[\n"
+ + "".join(f" {a},\n" for a in self._archives)
+ + " ],\n"
+ )
+ else:
+ result += " archives=[],\n"
+
+ if self._configs:
+ result += (
+ " configs={\n"
+ + "".join(f" {k}: {v},\n" for k, v in self.configs.items())
+ + " },\n"
+ )
+ else:
+ result += " configs={},\n"
+
+ return result + super().__str__() + "}\n"
+
+ class Builder(
+ JobTemplate.BaseBuilder["SparkJobTemplate.Builder", "SparkJobTemplate"]
+ ):
+ """
+ Builder class for creating SparkJobTemplate instances.
+ """
+
+ def __init__(self):
+ """
+ Initializes the builder with default values.
+ """
+ super().__init__()
+ self.class_name: Optional[str] = None
+ self.jars: List[str] = []
+ self.files: List[str] = []
+ self.archives: List[str] = []
+ self.configs: Dict[str, str] = {}
+
+ def with_class_name(self, class_name: str) -> "SparkJobTemplate.Builder":
+ """
+ Sets the class name for this Spark job template.
+
+ Args:
+ class_name: The fully qualified name of the Spark job class.
+
+ Returns:
+ The builder instance for method chaining.
+ """
+ self.class_name = class_name
+ return self
+
+ def with_jars(self, jars: List[str]) -> "SparkJobTemplate.Builder":
+ """
+ Sets the JAR files for this Spark job template.
+
+ Args:
+ jars: A list of JAR file paths to be included in the Spark job.
+
+ Returns:
+ The builder instance for method chaining.
+ """
+ self.jars = deepcopy(jars)
+ return self
+
+ def with_files(self, files: List[str]) -> "SparkJobTemplate.Builder":
+ """
+ Sets the files for this Spark job template.
+
+ Args:
+ files: A list of file paths to be included in the Spark job.
+
+ Returns:
+ The builder instance for method chaining.
+ """
+ self.files = deepcopy(files)
+ return self
+
+ def with_archives(self, archives: List[str]) -> "SparkJobTemplate.Builder":
+ """
+ Sets the archives for this Spark job template.
+
+ Args:
+ archives: A list of archive file paths to be included in the Spark job.
+
+ Returns:
+ The builder instance for method chaining.
+ """
+ self.archives = deepcopy(archives)
+ return self
+
+ def with_configs(self, configs: Dict[str, str]) -> "SparkJobTemplate.Builder":
+ """
+ Sets the configuration settings for this Spark job template.
+
+ Args:
+ configs: A dictionary of configuration key-value pairs to be applied to the Spark job.
+
+ Returns:
+ The builder instance for method chaining.
+ """
+ self.configs = deepcopy(configs)
+ return self
+
+ def validate(self):
+ """
+ Validates the SparkJobTemplate properties.
+ """
+ super().validate()
+ if not self.class_name or not self.class_name.strip():
+ raise ValueError("Class name must not be null or empty")
+ self.jars = self.jars or []
+ self.files = self.files or []
+ self.archives = self.archives or []
+ self.configs = self.configs or {}
+
+ def build(self) -> "SparkJobTemplate":
+ """
+ Builds and returns a SparkJobTemplate instance.
+ """
+ self.validate()
+ return SparkJobTemplate(self)
diff --git a/clients/client-python/gravitino/api/job/supports_jobs.py b/clients/client-python/gravitino/api/job/supports_jobs.py
new file mode 100644
index 0000000000..6c86a98bf9
--- /dev/null
+++ b/clients/client-python/gravitino/api/job/supports_jobs.py
@@ -0,0 +1,153 @@
+# 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.
+
+from abc import ABC, abstractmethod
+from typing import List, Dict
+from .job_handle import JobHandle
+from .job_template import JobTemplate
+
+
+class SupportsJobs(ABC):
+ """
+ Interface for job management operations. This interface will be mixed with GravitinoClient to
+ provide the ability to manage job templates and jobs within the Gravitino system.
+ """
+
+ @abstractmethod
+ def list_job_templates(self) -> List[JobTemplate]:
+ """
+ Lists all the registered job templates in Gravitino.
+
+ Returns:
+ List of job templates.
+ """
+ pass
+
+ @abstractmethod
+ def register_job_template(self, job_template) -> None:
+ """
+ Register a job template with the specified job template to Gravitino. The registered
+ job will be maintained in Gravitino, allowing it to be executed later.
+
+ Args:
+ job_template: The job template to register.
+
+ Raises:
+ JobTemplateAlreadyExists: If a job template with the same name already exists.
+ """
+ pass
+
+ @abstractmethod
+ def get_job_template(self, job_template_name: str) -> JobTemplate:
+ """
+ Retrieves a job template by its name.
+
+ Args:
+ job_template_name: The name of the job template to retrieve.
+
+ Returns:
+ The job template if found, otherwise raises an exception.
+
+ Raises:
+ NoSuchJobTemplateException: If no job template with the specified name exists.
+ """
+ pass
+
+ @abstractmethod
+ def delete_job_template(self, job_template_name: str) -> bool:
+ """
+ Deletes a job template by its name. This will remove the job template from Gravitino, and it
+ will no longer be available for execution. Only when all the jobs associated with this job
+ template are completed, failed or cancelled, the job template can be deleted successfully,
+ otherwise it will return false.
+
+ The deletion of a job template will also delete all the jobs associated with this template.
+
+ Args:
+ job_template_name: The name of the job template to delete.
+
+ Returns:
+ bool: True if the job template was deleted successfully, False if the job template
+ does not exist.
+
+ Raises:
+ InUseException: If there are still queued or started jobs associated with this job template.
+ """
+ pass
+
+ def list_jobs(self, job_template_name: str = None) -> List[JobHandle]:
+ """
+ Lists all the jobs in Gravitino. If a job template name is provided, it will filter the jobs
+ by that template.
+
+ Args:
+ job_template_name: Optional; if provided, only jobs associated with this template will be listed.
+
+ Returns:
+ List of JobHandle objects representing the jobs.
+ """
+ pass
+
+ @abstractmethod
+ def run_job(self, job_template_name: str, job_conf: Dict[str, str]) -> JobHandle:
+ """
+ Run a job with the template name and configuration. The jobConf is a map of key-value
+ contains the variables that will be used to replace the templated parameters in the job
+ template.
+
+ Args:
+ job_template_name: The name of the job template to run.
+ job_conf: A dictionary containing the job configuration parameters.
+
+ Returns:
+ JobHandle: A handle to the running job, which can be used to monitor or manage the job.
+
+ Raises:
+ NoSuchJobTemplateException: If no job template with the specified name exists.
+ """
+ pass
+
+ @abstractmethod
+ def get_job(self, job_id: str) -> JobHandle:
+ """
+ Retrieves a job by its ID.
+
+ Args:
+ job_id: The ID of the job to retrieve.
+
+ Returns:
+ JobHandle: The handle representing the job with the specified ID.
+
+ Raises:
+ NoSuchJobException: If no job with the specified ID exists.
+ """
+ pass
+
+ @abstractmethod
+ def cancel_job(self, job_id: str) -> JobHandle:
+ """
+ Cancels a running job by its ID. This operation will attempt to cancel the job if it is
+ still running. This method will return immediately, user could use the job handle to
+ check the status of the job after invoking this method.
+
+ Args:
+ job_id: The ID of the job to cancel.
+
+ Raises:
+ NoSuchJobException: If no job with the specified ID exists.
+ """
+ pass
diff --git a/clients/client-python/gravitino/exceptions/base.py b/clients/client-python/gravitino/exceptions/base.py
index 505655d869..ce2f0d536a 100644
--- a/clients/client-python/gravitino/exceptions/base.py
+++ b/clients/client-python/gravitino/exceptions/base.py
@@ -175,3 +175,15 @@ class NoSuchTagException(NotFoundException):
class TagAlreadyExistsException(AlreadyExistsException):
"""An exception thrown when a tag with specified name already associated to a metadata object."""
+
+
+class JobTemplateAlreadyExistsException(AlreadyExistsException):
+ """An exception thrown when a job template with specified name already exists."""
+
+
+class NoSuchJobTemplateException(NotFoundException):
+ """An exception thrown when a job template with specified name is not found."""
+
+
+class NoSuchJobException(NotFoundException):
+ """An exception thrown when a job with specified name is not found."""