This is an automated email from the ASF dual-hosted git repository.

zhouquan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/submarine.git


The following commit(s) were added to refs/heads/master by this push:
     new 17e8ebc  SUBMARINE-214. [WIP] Add submitter-k8s module
17e8ebc is described below

commit 17e8ebc0f526f1c0e113d7a9311ce53bf333a832
Author: Wanqiang Ji <[email protected]>
AuthorDate: Sun Nov 3 22:58:06 2019 +0800

    SUBMARINE-214. [WIP] Add submitter-k8s module
    
    ### What is this PR for?
    Add the submitter-k8s module implements the CRUD for custom resource 
objects, includes the UTs. Before run the UTs, you should deploy the 
tf-operator in a K8s cluster and replace the config at the test resources.
    
    ### What type of PR is it?
    [ Feature ]
    
    ### Todos
    * [ ] - travics CI with UTs
    * [ ] - entry points
    * [ ] - doc
    
    ### What is the Jira issue?
    https://issues.apache.org/jira/browse/SUBMARINE-214
    
    ### How should this be tested?
    https://travis-ci.org/jiwq/submarine/builds/606910904
    
    ### Screenshots (if appropriate)
    
    ### Questions:
    * Does the licenses files need update? No
    * Is there breaking changes for older versions? No
    * Does this needs documentation? Yes
    
    Author: Wanqiang Ji <[email protected]>
    
    Closes #79 from jiwq/SUBMARINE-214 and squashes the following commits:
    
    8ed84ec [Wanqiang Ji] SUBMARINE-214. [WIP] Add submitter-k8s module
---
 .travis.yml                                        |   2 +-
 pom.xml                                            |  30 ++++-
 submarine-server/server-submitter/pom.xml          |   1 +
 .../server-submitter/{ => submitter-k8s}/pom.xml   |  24 ++--
 .../server/submitter/k8s/K8sJobRequest.java        |  90 ++++++++++++++
 .../server/submitter/k8s/K8sJobSubmitter.java      | 119 ++++++++++++++++++
 .../submitter/k8s/model/CustomResourceJob.java     |  66 ++++++++++
 .../submitter/k8s/model/CustomResourceJobList.java |  86 +++++++++++++
 .../server/submitter/k8s/model/ListMeta.java       |  34 ++++++
 .../server/submitter/k8s/model/ObjectMeta.java     | 135 +++++++++++++++++++++
 .../server/submitter/k8s/K8SJobSubmitterTest.java  |  95 +++++++++++++++
 .../submitter-k8s/src/test/resources/config        |  19 +++
 .../src/test/resources/tf_job_mnist.json           |  48 ++++++++
 .../src/test/resources/tf_job_mnist.yaml           |  29 +++++
 .../test/resources/tfevent-volume/tfevent-pv.yaml  |  15 +++
 .../test/resources/tfevent-volume/tfevent-pvc.yaml |  14 +++
 16 files changed, 793 insertions(+), 14 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 1b25f56..037c9cb 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -42,7 +42,7 @@ env:
   global:
     # submarine core does not required by workbench-server integration tests
     # If you need to compile Phadoop-3.1 or Phadoop-3.2, you need to add 
`!submarine-server/server-submitter/submitter-yarnservice` in EXCLUDE_SUBMARINE
-    - 
EXCLUDE_SUBMARINE="!submarine-all,!submarine-client,!submarine-commons,!submarine-commons/commons-runtime,!submarine-dist,!submarine-server/server-submitter/submitter-yarn"
+    - 
EXCLUDE_SUBMARINE="!submarine-all,!submarine-client,!submarine-commons,!submarine-commons/commons-runtime,!submarine-dist,!submarine-server/server-submitter/submitter-yarn,!submarine-server/server-submitter/submitter-k8s"
     - 
EXCLUDE_WORKBENCH="!submarine-workbench,!submarine-workbench/workbench-web,!submarine-workbench/workbench-server"
     - 
EXCLUDE_INTERPRETER="!submarine-workbench/interpreter,!submarine-workbench/interpreter/interpreter-engine,!submarine-workbench/interpreter/python-interpreter,!submarine-workbench/interpreter/spark-interpreter""
     - 
EXCLUDE_SUBMODULE_TONY="!submodules/tony,!submodules/tony/tony-mini,!submodules/tony/tony-core,!submodules/tony/tony-proxy,!submodules/tony/tony-portal,!submodules/tony/tony-azkaban,!submodules/tony/tony-cli"
diff --git a/pom.xml b/pom.xml
index 66e1dd1..df70ae0 100644
--- a/pom.xml
+++ b/pom.xml
@@ -122,6 +122,8 @@
     <spark.scala.version>2.11.8</spark.scala.version>
     <spark.scala.binary.version>2.11</spark.scala.binary.version>
     <hive.version>2.1.1</hive.version>
+    <!--  Submarine on Kubernetes  -->
+    <k8s.client-java.version>6.0.1</k8s.client-java.version>
   </properties>
 
   <modules>
@@ -138,15 +140,31 @@
   <dependencyManagement>
     <dependencies>
       <dependency>
+        <groupId>log4j</groupId>
+        <artifactId>log4j</artifactId>
+        <version>${log4j.version}</version>
+      </dependency>
+
+      <!--  Unit Tests  -->
+      <dependency>
+        <groupId>junit</groupId>
+        <artifactId>junit</artifactId>
+        <version>${junit.version}</version>
+      </dependency>
+      <dependency>
         <groupId>org.mockito</groupId>
         <artifactId>mockito-core</artifactId>
         <version>${mockito.version}</version>
       </dependency>
+
+      <!--  Submarine on Kubernetes  -->
       <dependency>
-        <groupId>log4j</groupId>
-        <artifactId>log4j</artifactId>
-        <version>${log4j.version}</version>
+        <groupId>io.kubernetes</groupId>
+        <artifactId>client-java</artifactId>
+        <version>${k8s.client-java.version}</version>
       </dependency>
+
+      <!--  Submarine on YARN  -->
       <dependency>
         <groupId>org.apache.hadoop</groupId>
         <artifactId>hadoop-yarn-services-api</artifactId>
@@ -415,6 +433,7 @@
             <exclude>.gitmodules</exclude>
             <exclude>LICENSE</exclude>
             <exclude>license_header</exclude>
+            <exclude>**/*.iml</exclude>
             <exclude>**/*.la</exclude>
             <exclude>**/*.svg</exclude>
             <exclude>**/*.png</exclude>
@@ -428,12 +447,13 @@
             <exclude>**/*.xsd</exclude>
             <exclude>**/*.json</exclude>
             <exclude>**/*.conf</exclude>
+            <exclude>**/*.yaml</exclude>
             <exclude>**/src/main/java/com/linkedin/tony/events/*</exclude>
             
<exclude>**/src/main/resources/META-INF/services/org.apache.hadoop.security.SecurityInfo</exclude>
             
<exclude>**/src/test/resources/typicalHistFolder/job1/application123-1-1-user1-SUCCEEDED.jhist</exclude>
             <exclude>**/conf/routes</exclude>
-            <exclude>submarine-runtime/yarnservice-runtime/target/**</exclude>
-            <exclude>submarine-runtime/target/**</exclude>
+            <exclude>**/submitter-yarnservice/target/**</exclude>
+            <exclude>**/src/test/resources/config</exclude>
             <exclude>licenses/**</exclude>
             <exclude>licenses-binary/**</exclude>
             <exclude>NOTICE-binary</exclude>
diff --git a/submarine-server/server-submitter/pom.xml 
b/submarine-server/server-submitter/pom.xml
index 7ab50c7..94ffede 100644
--- a/submarine-server/server-submitter/pom.xml
+++ b/submarine-server/server-submitter/pom.xml
@@ -35,6 +35,7 @@
 
   <modules>
     <module>submitter-yarn</module>
+    <module>submitter-k8s</module>
   </modules>
 
 </project>
diff --git a/submarine-server/server-submitter/pom.xml 
b/submarine-server/server-submitter/submitter-k8s/pom.xml
similarity index 72%
copy from submarine-server/server-submitter/pom.xml
copy to submarine-server/server-submitter/submitter-k8s/pom.xml
index 7ab50c7..e33b3b4 100644
--- a/submarine-server/server-submitter/pom.xml
+++ b/submarine-server/server-submitter/submitter-k8s/pom.xml
@@ -22,19 +22,27 @@
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
   <parent>
-    <artifactId>submarine-server</artifactId>
+    <artifactId>server-submitter</artifactId>
     <groupId>org.apache.submarine</groupId>
     <version>0.3.0-SNAPSHOT</version>
   </parent>
   <modelVersion>4.0.0</modelVersion>
 
-  <artifactId>server-submitter</artifactId>
+  <artifactId>submitter-k8s</artifactId>
   <version>0.3.0-SNAPSHOT</version>
-  <packaging>pom</packaging>
-  <name>Submarine: Server Submitter</name>
+  <name>Submarine: Kubernetes Submitter</name>
 
-  <modules>
-    <module>submitter-yarn</module>
-  </modules>
+  <dependencies>
+    <dependency>
+      <groupId>io.kubernetes</groupId>
+      <artifactId>client-java</artifactId>
+      <version>${k8s.client-java.version}</version>
+    </dependency>
 
-</project>
+    <!--  Unit Tests  -->
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+    </dependency>
+  </dependencies>
+</project>
\ No newline at end of file
diff --git 
a/submarine-server/server-submitter/submitter-k8s/src/main/java/org/apache/submarine/server/submitter/k8s/K8sJobRequest.java
 
b/submarine-server/server-submitter/submitter-k8s/src/main/java/org/apache/submarine/server/submitter/k8s/K8sJobRequest.java
new file mode 100644
index 0000000..827346d
--- /dev/null
+++ 
b/submarine-server/server-submitter/submitter-k8s/src/main/java/org/apache/submarine/server/submitter/k8s/K8sJobRequest.java
@@ -0,0 +1,90 @@
+/*
+ * 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.submarine.server.submitter.k8s;
+
+/**
+ * Job request for Kubernetes Submitter.
+ */
+// TODO: It should implement the JobRequest interface
+public class K8sJobRequest {
+  private Path path;
+  private Object body;
+  private String jobName;
+
+  public K8sJobRequest(Path path, Object body) {
+    this(path, body, null);
+  }
+
+  public K8sJobRequest(Path path, Object body, String jobName) {
+    this.path = path;
+    this.body = body;
+    this.jobName = jobName;
+  }
+
+  public void setPath(Path path) {
+    this.path = path;
+  }
+
+  public Path getPath() {
+    return path;
+  }
+
+  public void setBody(Object body) {
+    this.body = body;
+  }
+
+  public Object getBody() {
+    return body;
+  }
+
+  public String getJobName() {
+    return jobName;
+  }
+
+  static class Path {
+    private String group;
+    private String apiVersion;
+    private String namespace;
+    private String plural;
+
+    Path(String group, String apiVersion, String namespace, String plural) {
+      this.group = group;
+      this.apiVersion = apiVersion;
+      this.namespace = namespace;
+      this.plural = plural;
+    }
+
+    public String getGroup() {
+      return group;
+    }
+
+    public String getApiVersion() {
+      return apiVersion;
+    }
+
+    public String getNamespace() {
+      return namespace;
+    }
+
+    public String getPlural() {
+      return plural;
+    }
+  }
+}
diff --git 
a/submarine-server/server-submitter/submitter-k8s/src/main/java/org/apache/submarine/server/submitter/k8s/K8sJobSubmitter.java
 
b/submarine-server/server-submitter/submitter-k8s/src/main/java/org/apache/submarine/server/submitter/k8s/K8sJobSubmitter.java
new file mode 100644
index 0000000..18d59b6
--- /dev/null
+++ 
b/submarine-server/server-submitter/submitter-k8s/src/main/java/org/apache/submarine/server/submitter/k8s/K8sJobSubmitter.java
@@ -0,0 +1,119 @@
+/*
+ * 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.submarine.server.submitter.k8s;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.gson.Gson;
+import io.kubernetes.client.ApiClient;
+import io.kubernetes.client.ApiException;
+import io.kubernetes.client.Configuration;
+import io.kubernetes.client.apis.CustomObjectsApi;
+import io.kubernetes.client.models.V1DeleteOptions;
+import io.kubernetes.client.models.V1DeleteOptionsBuilder;
+import io.kubernetes.client.util.ClientBuilder;
+import io.kubernetes.client.util.KubeConfig;
+import org.apache.submarine.server.submitter.k8s.model.CustomResourceJob;
+import org.apache.submarine.server.submitter.k8s.model.CustomResourceJobList;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.FileReader;
+import java.io.IOException;
+
+/**
+ * JobSubmitter for Kubernetes Cluster.
+ */
+// TODO: It should implement the JobSubmitter interface
+public class K8sJobSubmitter {
+  private final Logger LOG = LoggerFactory.getLogger(K8sJobSubmitter.class);
+
+  public K8sJobSubmitter(String confPath) throws IOException {
+    ApiClient client =
+        ClientBuilder.kubeconfig(KubeConfig.loadKubeConfig(new 
FileReader(confPath))).build();
+    Configuration.setDefaultApiClient(client);
+  }
+
+  public String submitJob(K8sJobRequest request) {
+    return "job_id";
+  }
+
+  @VisibleForTesting
+  CustomResourceJob createCustomJob(K8sJobRequest request) {
+    try {
+      CustomObjectsApi api = new CustomObjectsApi();
+      K8sJobRequest.Path path = request.getPath();
+      Object o = api.createNamespacedCustomObject(path.getGroup(),
+          path.getApiVersion(), path.getNamespace(), path.getPlural(),
+          request.getBody(), "true");
+      Gson gson = new Gson();
+      return gson.fromJson(gson.toJson(o), CustomResourceJob.class);
+    } catch (ApiException ae) {
+      LOG.error("Create CRD job: " + ae.getMessage(), ae);
+    }
+    return null;
+  }
+
+  @VisibleForTesting
+  CustomResourceJob getCustomResourceJob(K8sJobRequest request) {
+    try {
+      CustomObjectsApi api = new CustomObjectsApi();
+      K8sJobRequest.Path path = request.getPath();
+      Object o = api.getNamespacedCustomObject(path.getGroup(), 
path.getApiVersion(),
+          path.getNamespace(), path.getPlural(), request.getJobName());
+      Gson gson = new Gson();
+      return gson.fromJson(gson.toJson(o), CustomResourceJob.class);
+    } catch (ApiException ae) {
+      LOG.error("Get CRD job: " + ae.getMessage(), ae);
+    }
+    return null;
+  }
+
+  CustomResourceJob deleteCustomResourceJob(K8sJobRequest request) {
+    try {
+      CustomObjectsApi api = new CustomObjectsApi();
+      K8sJobRequest.Path path = request.getPath();
+      V1DeleteOptions body =
+          new 
V1DeleteOptionsBuilder().withApiVersion(path.getApiVersion()).build();
+      Object o = api.deleteNamespacedCustomObject(path.getGroup(),
+          path.getApiVersion(), path.getNamespace(), path.getPlural(),
+          request.getJobName(), body, null, null, null);
+      Gson gson = new Gson();
+      return gson.fromJson(gson.toJson(o), CustomResourceJob.class);
+    } catch (ApiException ae) {
+      LOG.error("Delete CRD job: " + ae.getMessage(), ae);
+    }
+    return null;
+  }
+
+  @VisibleForTesting
+  CustomResourceJobList listCustomResourceJobs(K8sJobRequest request) {
+    try {
+      CustomObjectsApi api = new CustomObjectsApi();
+      K8sJobRequest.Path path = request.getPath();
+      Object o = api.listNamespacedCustomObject(path.getGroup(), 
path.getApiVersion(),
+          path.getNamespace(), path.getPlural(), "true", null, null, null, 
null, null);
+      Gson gson = new Gson();
+      return gson.fromJson(gson.toJson(o), CustomResourceJobList.class);
+    } catch (ApiException ae) {
+      LOG.error("List CRD jobs: " + ae.getMessage(), ae);
+    }
+    return null;
+  }
+}
diff --git 
a/submarine-server/server-submitter/submitter-k8s/src/main/java/org/apache/submarine/server/submitter/k8s/model/CustomResourceJob.java
 
b/submarine-server/server-submitter/submitter-k8s/src/main/java/org/apache/submarine/server/submitter/k8s/model/CustomResourceJob.java
new file mode 100644
index 0000000..610fc79
--- /dev/null
+++ 
b/submarine-server/server-submitter/submitter-k8s/src/main/java/org/apache/submarine/server/submitter/k8s/model/CustomResourceJob.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.submarine.server.submitter.k8s.model;
+
+import com.google.gson.GsonBuilder;
+import com.google.gson.annotations.SerializedName;
+
+import java.util.Map;
+
+/**
+ * The response job for CRD API.
+ *   POST:   /apis/{group}/{version}/namespaces/{namespace}/{plural}
+ *   GET:    /apis/{group}/{version}/namespaces/{namespace}/{plural}/{name}
+ *   DELETE: /apis/{group}/{version}/namespaces/{namespace}/{plural}/{name}
+ */
+public class CustomResourceJob {
+  @SerializedName("apiVersion")
+  private String apiVersion;
+
+  @SerializedName("kind")
+  protected String kind;
+
+  @SerializedName("metadata")
+  private ObjectMeta metadata;
+
+  @SerializedName("spec")
+  private Map<String, Object> spec;
+
+  public String getApiVersion() {
+    return apiVersion;
+  }
+
+  public String getKind() {
+    return kind;
+  }
+
+  public ObjectMeta getMetadata() {
+    return metadata;
+  }
+
+  public Map<String, Object> getSpec() {
+    return spec;
+  }
+
+  @Override
+  public String toString() {
+    return new GsonBuilder().setPrettyPrinting().create().toJson(this);
+  }
+}
diff --git 
a/submarine-server/server-submitter/submitter-k8s/src/main/java/org/apache/submarine/server/submitter/k8s/model/CustomResourceJobList.java
 
b/submarine-server/server-submitter/submitter-k8s/src/main/java/org/apache/submarine/server/submitter/k8s/model/CustomResourceJobList.java
new file mode 100644
index 0000000..3ad0114
--- /dev/null
+++ 
b/submarine-server/server-submitter/submitter-k8s/src/main/java/org/apache/submarine/server/submitter/k8s/model/CustomResourceJobList.java
@@ -0,0 +1,86 @@
+/*
+ * 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.submarine.server.submitter.k8s.model;
+
+import com.google.gson.GsonBuilder;
+import com.google.gson.annotations.SerializedName;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+
+/**
+ * The response for CRD API.
+ *   GET: /apis/{group}/{version}/namespaces/{namespace}/{plural}
+ */
+public class CustomResourceJobList {
+  @SerializedName("apiVersion")
+  private String apiVersion;
+
+  @SerializedName("items")
+  private List<Object> items = new ArrayList<>();
+
+  @SerializedName("kind")
+  protected String kind;
+
+  @SerializedName("metadata")
+  private ListMeta metadata;
+
+  public String getApiVersion() {
+    return apiVersion;
+  }
+
+  public List<Object> getItems() {
+    return items;
+  }
+
+  public String getKind() {
+    return kind;
+  }
+
+  public ListMeta getMetadata() {
+    return metadata;
+  }
+
+  @Override
+  public int hashCode() {
+    return Objects.hash(apiVersion, items, kind, metadata);
+  }
+
+  @Override
+  public boolean equals(java.lang.Object o) {
+    if (this == o) {
+      return true;
+    }
+    if (o == null || getClass() != o.getClass()) {
+      return false;
+    }
+    CustomResourceJobList jobList = (CustomResourceJobList) o;
+    return Objects.equals(this.apiVersion, jobList.apiVersion) &&
+        Objects.equals(this.items, jobList.items) &&
+        Objects.equals(this.kind, jobList.kind) &&
+        Objects.equals(this.metadata, jobList.metadata);
+  }
+
+  @Override
+  public String toString() {
+    return new GsonBuilder().setPrettyPrinting().create().toJson(this);
+  }
+}
diff --git 
a/submarine-server/server-submitter/submitter-k8s/src/main/java/org/apache/submarine/server/submitter/k8s/model/ListMeta.java
 
b/submarine-server/server-submitter/submitter-k8s/src/main/java/org/apache/submarine/server/submitter/k8s/model/ListMeta.java
new file mode 100644
index 0000000..7ed10f5
--- /dev/null
+++ 
b/submarine-server/server-submitter/submitter-k8s/src/main/java/org/apache/submarine/server/submitter/k8s/model/ListMeta.java
@@ -0,0 +1,34 @@
+/*
+ * 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.submarine.server.submitter.k8s.model;
+
+import com.google.gson.GsonBuilder;
+import io.kubernetes.client.models.V1ListMeta;
+
+/**
+ * ListMeta describes metadata that synthetic resources must have, including 
lists and various
+ * status objects.
+ */
+public class ListMeta extends V1ListMeta {
+  @Override
+  public String toString() {
+    return new GsonBuilder().setPrettyPrinting().create().toJson(this);
+  }
+}
diff --git 
a/submarine-server/server-submitter/submitter-k8s/src/main/java/org/apache/submarine/server/submitter/k8s/model/ObjectMeta.java
 
b/submarine-server/server-submitter/submitter-k8s/src/main/java/org/apache/submarine/server/submitter/k8s/model/ObjectMeta.java
new file mode 100644
index 0000000..95244fd
--- /dev/null
+++ 
b/submarine-server/server-submitter/submitter-k8s/src/main/java/org/apache/submarine/server/submitter/k8s/model/ObjectMeta.java
@@ -0,0 +1,135 @@
+/*
+ * 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.submarine.server.submitter.k8s.model;
+
+import com.google.gson.GsonBuilder;
+import com.google.gson.annotations.SerializedName;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * ObjectMeta is metadata that all persisted resources must have, which 
includes all objects users
+ * must create.
+ */
+public class ObjectMeta {
+  @SerializedName("annotations")
+  private Map<String, String> annotations;
+
+  @SerializedName("clusterName")
+  private String clusterName;
+
+  @SerializedName("creationTimestamp")
+  private String creationTimestamp;
+
+  @SerializedName("deletionGracePeriodSeconds")
+  private Long deletionGracePeriodSeconds;
+
+  @SerializedName("deletionTimestamp")
+  private String deletionTimestamp;
+
+  @SerializedName("finalizers")
+  private List<String> finalizers;
+
+  @SerializedName("generateName")
+  private String generateName;
+
+  @SerializedName("generation")
+  private Long generation;
+
+  @SerializedName("labels")
+  private Map<String, String> labels = null;
+
+  @SerializedName("name")
+  private String name = null;
+
+  @SerializedName("namespace")
+  private String namespace = null;
+
+  @SerializedName("resourceVersion")
+  private String resourceVersion = null;
+
+  @SerializedName("selfLink")
+  private String selfLink = null;
+
+  @SerializedName("uid")
+  private String uid = null;
+
+  public Map<String, String> getAnnotations() {
+    return annotations;
+  }
+
+  public String getClusterName() {
+    return clusterName;
+  }
+
+  public String getCreationTimestamp() {
+    return creationTimestamp;
+  }
+
+  public Long getDeletionGracePeriodSeconds() {
+    return deletionGracePeriodSeconds;
+  }
+
+  public String getDeletionTimestamp() {
+    return deletionTimestamp;
+  }
+
+  public List<String> getFinalizers() {
+    return finalizers;
+  }
+
+  public String getGenerateName() {
+    return generateName;
+  }
+
+  public Long getGeneration() {
+    return generation;
+  }
+
+  public Map<String, String> getLabels() {
+    return labels;
+  }
+
+  public String getName() {
+    return name;
+  }
+
+  public String getNamespace() {
+    return namespace;
+  }
+
+  public String getResourceVersion() {
+    return resourceVersion;
+  }
+
+  public String getSelfLink() {
+    return selfLink;
+  }
+
+  public String getUid() {
+    return uid;
+  }
+
+  @Override
+  public String toString() {
+    return new GsonBuilder().setPrettyPrinting().create().toJson(this);
+  }
+}
diff --git 
a/submarine-server/server-submitter/submitter-k8s/src/test/java/org/apache/submarine/server/submitter/k8s/K8SJobSubmitterTest.java
 
b/submarine-server/server-submitter/submitter-k8s/src/test/java/org/apache/submarine/server/submitter/k8s/K8SJobSubmitterTest.java
new file mode 100644
index 0000000..70b9c00
--- /dev/null
+++ 
b/submarine-server/server-submitter/submitter-k8s/src/test/java/org/apache/submarine/server/submitter/k8s/K8SJobSubmitterTest.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.submarine.server.submitter.k8s;
+
+import org.apache.submarine.server.submitter.k8s.model.CustomResourceJob;
+import org.apache.submarine.server.submitter.k8s.model.CustomResourceJobList;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.net.URL;
+
+public class K8SJobSubmitterTest {
+  private final String jobName = "mnist";
+  private K8sJobSubmitter submitter;
+  private K8sJobRequest.Path path;
+
+  @Before
+  public void before() throws IOException {
+    String confPath = this.getClass().getResource("/config").getFile();
+    submitter = new K8sJobSubmitter(confPath);
+    path = new K8sJobRequest.Path("kubeflow.org","v1","kubeflow", "tfjobs");
+  }
+
+  @Test
+  public void testCreateCustomJob() throws URISyntaxException {
+    if (getCustomJob() != null) {
+      K8sJobRequest request = new K8sJobRequest(path, null, jobName);
+      CustomResourceJob delJob = submitter.deleteCustomResourceJob(request);
+//      Assert.assertNotNull(delJob);
+    }
+
+    CustomResourceJob job = submitter.createCustomJob(new K8sJobRequest(path, 
getCutomJobSpecFile()));
+//    Assert.assertNotNull(job);
+    System.out.println("Create job: " + job);
+  }
+
+  @Test
+  public void testGetCustomJob() throws URISyntaxException {
+    testCreateCustomJob();
+
+    CustomResourceJob job = getCustomJob();
+//    Assert.assertNotNull(job);
+//    Assert.assertEquals(job.getMetadata().getName(), jobName);
+    System.out.println("Get Job: " + job);
+  }
+
+  @Test
+  public void testListCustomJobs() throws URISyntaxException {
+    CustomResourceJobList list = submitter.listCustomResourceJobs(new 
K8sJobRequest(path, getCutomJobSpecFile()));
+    System.out.println("Job List: " + list);
+  }
+
+  @Test
+  public void testDeleteCustomJob() throws URISyntaxException {
+    if (getCustomJob() == null) {
+      CustomResourceJob job = submitter.createCustomJob(new 
K8sJobRequest(path, getCutomJobSpecFile()));
+//      Assert.assertNotNull(job);
+    }
+
+    K8sJobRequest request = new K8sJobRequest(path, null, jobName);
+    CustomResourceJob delJob = submitter.deleteCustomResourceJob(request);
+//    Assert.assertNotNull(delJob);
+    System.out.println("Delete job: " + delJob);
+  }
+
+  private CustomResourceJob getCustomJob() {
+    K8sJobRequest request = new K8sJobRequest(path, null, jobName);
+    return submitter.getCustomResourceJob(request);
+  }
+
+  private File getCutomJobSpecFile() throws URISyntaxException {
+    URL fileUrl = this.getClass().getResource("/tf_job_mnist.json");
+    return new File(fileUrl.toURI());
+  }
+}
diff --git 
a/submarine-server/server-submitter/submitter-k8s/src/test/resources/config 
b/submarine-server/server-submitter/submitter-k8s/src/test/resources/config
new file mode 100644
index 0000000..bc57012
--- /dev/null
+++ b/submarine-server/server-submitter/submitter-k8s/src/test/resources/config
@@ -0,0 +1,19 @@
+apiVersion: v1
+clusters:
+- cluster:
+    certificate-authority-data: 
LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUM1ekNDQWMrZ0F3SUJBZ0lCQVRBTkJna3Foa2lHOXcwQkFRc0ZBREFWTVJNd0VRWURWUVFERXdwdGFXNXAKYTNWaVpVTkJNQjRYRFRFNU1Ea3hNREl6TVRjeE5sb1hEVEk1TURrd09ESXpNVGN4Tmxvd0ZURVRNQkVHQTFVRQpBeE1LYldsdWFXdDFZbVZEUVRDQ0FTSXdEUVlKS29aSWh2Y05BUUVCQlFBRGdnRVBBRENDQVFvQ2dnRUJBTm8zCmJGbnllQmlhOUlzeHorVWg3cExGMWNaTkNiR0lkWXJxejFFUlRodXcwN2t1QnlDNWp4K2wxOEZCcGkvSVJ0OWYKaXU4MVVGZEVKSStKaEo2bC95Y3RtRitxaXhiMkUyM1ltL29VTGIxOVh1V3RuZXZHZkNNZFZiUVRv
 [...]
+    server: https://localhost:8443
+  name: kind
+contexts:
+- context:
+    cluster: kind
+    user: kind-admin
+  name: kind
+current-context: kind
+kind: Config
+preferences: {}
+users:
+- name: kind-admin
+  user:
+    client-certificate-data: 
LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUM4akNDQWRxZ0F3SUJBZ0lJVzVPRkVhcmhlSU13RFFZSktvWklodmNOQVFFTEJRQXdGVEVUTUJFR0ExVUUKQXhNS2JXbHVhV3QxWW1WRFFUQWVGdzB4T1RBNU1UQXlNekUzTVRaYUZ3MHlNREE1TVRBeU16RTNORFJhTURReApGekFWQmdOVkJBb1REbk41YzNSbGJUcHRZWE4wWlhKek1Sa3dGd1lEVlFRREV4QnJkV0psY201bGRHVnpMV0ZrCmJXbHVNSUlCSWpBTkJna3Foa2lHOXcwQkFRRUZBQU9DQVE4QU1JSUJDZ0tDQVFFQXUyRWJyaVMraDZ4MzdaeXYKMnpvZWlUalI5Zm4rYSt3ZTJ4TXFHaDJVMG1vRGV6Y251TkdXWUZXUWpob0VrOEhnQTJGMmFZbEhJeEM
 [...]
+    client-key-data: 
LS0tLS1CRUdJTiBSU0EgUFJJVkFURSBLRVktLS0tLQpNSUlFcFFJQkFBS0NBUUVBdTJFYnJpUytoNngzN1p5djJ6b2VpVGpSOWZuK2Erd2UyeE1xR2gyVTBtb0RlemNuCnVOR1dZRldRamhvRWs4SGdBMkYyYVlsSEl4QzBvTTNpejlHQnFhcjRjUWNFV2p6dlI5WkczaXBnWDg1OTRYQkgKUko4b1ZSdDl1ZW5hT01PTjBlUVZaWFhycE1OZXY2MCtIeWJPbk5NQWFsUnRGN1pxeHhFblU3RGVwZTdmSXJ1ZApWZDFvNVU3ZndsUEt1WmJZREVoYzdCL2puMjVtV1BJNURPK1kxQTNTREVwQklxZVVaUVFjZUJvbnVNZTF0amo0CkxNeUhZZE5pNFZyb1NoZlFpMVluQS9WM1NwV2pNaitGQUYraDhaNWg3MzlUOXNUMWxCbjJ2MGtmQUpqS3R
 [...]
diff --git 
a/submarine-server/server-submitter/submitter-k8s/src/test/resources/tf_job_mnist.json
 
b/submarine-server/server-submitter/submitter-k8s/src/test/resources/tf_job_mnist.json
new file mode 100644
index 0000000..78be457
--- /dev/null
+++ 
b/submarine-server/server-submitter/submitter-k8s/src/test/resources/tf_job_mnist.json
@@ -0,0 +1,48 @@
+{
+  "apiVersion": "kubeflow.org/v1",
+  "kind": "TFJob",
+  "metadata": {
+    "name": "mnist",
+    "namespace": "kubeflow"
+  },
+  "spec": {
+    "cleanPodPolicy": "None",
+    "tfReplicaSpecs": {
+      "Worker": {
+        "replicas": 1,
+        "restartPolicy": "Never",
+        "template": {
+          "spec": {
+            "containers": [
+              {
+                "name": "tensorflow",
+                "image": "gcr.io/kubeflow-ci/tf-mnist-with-summaries:1.0",
+                "command": [
+                  "python",
+                  "/var/tf_mnist/mnist_with_summaries.py",
+                  "--log_dir=/train/logs",
+                  "--learning_rate=0.01",
+                  "--batch_size=150"
+                ],
+                "volumeMounts": [
+                  {
+                    "mountPath": "/train",
+                    "name": "training"
+                  }
+                ]
+              }
+            ],
+            "volumes": [
+              {
+                "name": "training",
+                "persistentVolumeClaim": {
+                  "claimName": "tfevent-volume"
+                }
+              }
+            ]
+          }
+        }
+      }
+    }
+  }
+}
diff --git 
a/submarine-server/server-submitter/submitter-k8s/src/test/resources/tf_job_mnist.yaml
 
b/submarine-server/server-submitter/submitter-k8s/src/test/resources/tf_job_mnist.yaml
new file mode 100644
index 0000000..370f4cc
--- /dev/null
+++ 
b/submarine-server/server-submitter/submitter-k8s/src/test/resources/tf_job_mnist.yaml
@@ -0,0 +1,29 @@
+apiVersion: "kubeflow.org/v1"
+kind: "TFJob"
+metadata:
+  name: "mnist"
+  namespace: kubeflow
+spec:
+  cleanPodPolicy: None
+  tfReplicaSpecs:
+    Worker:
+      replicas: 1
+      restartPolicy: Never
+      template:
+        spec:
+          containers:
+            - name: tensorflow
+              image: gcr.io/kubeflow-ci/tf-mnist-with-summaries:1.0
+              command:
+                - "python"
+                - "/var/tf_mnist/mnist_with_summaries.py"
+                - "--log_dir=/train/logs"
+                - "--learning_rate=0.01"
+                - "--batch_size=150"
+              volumeMounts:
+                - mountPath: "/train"
+                  name: "training"
+          volumes:
+            - name: "training"
+              persistentVolumeClaim:
+                claimName: "tfevent-volume"
diff --git 
a/submarine-server/server-submitter/submitter-k8s/src/test/resources/tfevent-volume/tfevent-pv.yaml
 
b/submarine-server/server-submitter/submitter-k8s/src/test/resources/tfevent-volume/tfevent-pv.yaml
new file mode 100644
index 0000000..a450c6a
--- /dev/null
+++ 
b/submarine-server/server-submitter/submitter-k8s/src/test/resources/tfevent-volume/tfevent-pv.yaml
@@ -0,0 +1,15 @@
+apiVersion: v1
+kind: PersistentVolume
+metadata:
+  name: tfevent-volume
+  labels:
+    type: local
+    app: tfjob
+spec:
+  capacity:
+    storage: 10Gi
+  storageClassName: standard  
+  accessModes:
+    - ReadWriteMany
+  hostPath:
+    path: /tmp/data
diff --git 
a/submarine-server/server-submitter/submitter-k8s/src/test/resources/tfevent-volume/tfevent-pvc.yaml
 
b/submarine-server/server-submitter/submitter-k8s/src/test/resources/tfevent-volume/tfevent-pvc.yaml
new file mode 100644
index 0000000..7d7f848
--- /dev/null
+++ 
b/submarine-server/server-submitter/submitter-k8s/src/test/resources/tfevent-volume/tfevent-pvc.yaml
@@ -0,0 +1,14 @@
+apiVersion: v1
+kind: PersistentVolumeClaim
+metadata:
+  name: tfevent-volume
+  namespace: kubeflow 
+  labels:
+    type: local
+    app: tfjob
+spec:
+  accessModes:
+    - ReadWriteMany
+  resources:
+    requests:
+      storage: 10Gi


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to