You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@submarine.apache.org by li...@apache.org on 2020/09/02 15:11:01 UTC

[submarine] branch master updated: SUBMARINE-614. Environment Id should be string in JSON response

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

liuxun 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 1136622  SUBMARINE-614. Environment Id should be string in JSON response
1136622 is described below

commit 113662272f92cb6d9d32876eead5f874a19d2a87
Author: Lisa <ae...@gmail.com>
AuthorDate: Wed Sep 2 20:04:46 2020 +0800

    SUBMARINE-614. Environment Id should be string in JSON response
    
    ### What is this PR for?
    EnvironmentId now be string in JSON response
    
    ### What type of PR is it?
    [Bug Fix]
    
    ### Todos
    * [ ] - Task
    
    ### What is the Jira issue?
    https://issues.apache.org/jira/projects/SUBMARINE/issues/SUBMARINE-614
    
    ### How should this be tested?
    https://travis-ci.org/github/aeioulisa/submarine/builds/723157127
    * First time? Setup Travis CI as described on https://submarine.apache.org/contribution/contributions.html#continuous-integration
    * Strongly recommended: add automated unit tests for any new or changed behavior
    * Outline any manual steps to test the PR here.
    
    ### Screenshots (if appropriate)
    
    ### Questions:
    * Does the licenses files need update? No
    * Is there breaking changes for older versions? No
    * Does this needs documentation? No
    
    Author: Lisa <ae...@gmail.com>
    
    Closes #389 from aeioulisa/SUBMARINE-614 and squashes the following commits:
    
    1d6f361 [Lisa] update
    dd3a7e6 [Lisa] update
    436e1ae [Lisa] update
    24bdce5 [Lisa] update
    7901f71 [Lisa] update
    9857750 [Lisa] update
    a02cb60 [Lisa] fix the test failure in submarine test-k8s
    1e37446 [Lisa] merge
    711887e [Lisa] add serializer and deserializer
    2990071 [Lisa] update
    daa3c5e [Lisa] EnvironmentId now be string in JSON response
---
 .../server/gson/EnvironmentIdDeserializer.java     | 37 +++++++++++++
 .../server/gson/EnvironmentIdSerializer.java       | 35 +++++++++++++
 .../submarine/server/response/JsonResponse.java    |  5 ++
 .../server/AbstractSubmarineServerTest.java        | 37 ++++++++-----
 .../server/rest/EnvironmentRestApiTest.java        | 31 ++++++-----
 .../rest/EnvironmentManagerRestApiIT.java          | 16 ++++--
 .../apache/submarine/rest/ExperimentRestApiIT.java | 61 +++++++++++++---------
 .../apache/submarine/rest/NotebookRestApiIT.java   | 48 ++++++++++-------
 8 files changed, 195 insertions(+), 75 deletions(-)

diff --git a/submarine-server/server-core/src/main/java/org/apache/submarine/server/gson/EnvironmentIdDeserializer.java b/submarine-server/server-core/src/main/java/org/apache/submarine/server/gson/EnvironmentIdDeserializer.java
new file mode 100644
index 0000000..7a4d1fe
--- /dev/null
+++ b/submarine-server/server-core/src/main/java/org/apache/submarine/server/gson/EnvironmentIdDeserializer.java
@@ -0,0 +1,37 @@
+/*
+ * 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.gson;
+
+import com.google.gson.JsonDeserializationContext;
+import com.google.gson.JsonDeserializer;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonParseException;
+import org.apache.submarine.server.api.environment.EnvironmentId;
+
+import java.lang.reflect.Type;
+
+public class EnvironmentIdDeserializer implements JsonDeserializer<EnvironmentId> {
+
+  @Override
+  public EnvironmentId deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
+      throws JsonParseException {
+    return EnvironmentId.fromString(json.getAsJsonPrimitive().getAsString());
+  }
+}
diff --git a/submarine-server/server-core/src/main/java/org/apache/submarine/server/gson/EnvironmentIdSerializer.java b/submarine-server/server-core/src/main/java/org/apache/submarine/server/gson/EnvironmentIdSerializer.java
new file mode 100644
index 0000000..92cccb3
--- /dev/null
+++ b/submarine-server/server-core/src/main/java/org/apache/submarine/server/gson/EnvironmentIdSerializer.java
@@ -0,0 +1,35 @@
+/*
+ * 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.gson;
+
+import com.google.gson.JsonElement;
+import com.google.gson.JsonPrimitive;
+import com.google.gson.JsonSerializationContext;
+import com.google.gson.JsonSerializer;
+import org.apache.submarine.server.api.environment.EnvironmentId;
+
+import java.lang.reflect.Type;
+
+public class EnvironmentIdSerializer implements JsonSerializer<EnvironmentId> {
+  @Override
+  public JsonElement serialize(EnvironmentId src, Type typeOfSrc, JsonSerializationContext context) {
+    return new JsonPrimitive(src.toString());
+  }
+}
diff --git a/submarine-server/server-core/src/main/java/org/apache/submarine/server/response/JsonResponse.java b/submarine-server/server-core/src/main/java/org/apache/submarine/server/response/JsonResponse.java
index 27d4cd1..11bd02a 100644
--- a/submarine-server/server-core/src/main/java/org/apache/submarine/server/response/JsonResponse.java
+++ b/submarine-server/server-core/src/main/java/org/apache/submarine/server/response/JsonResponse.java
@@ -23,7 +23,10 @@ import com.google.common.annotations.VisibleForTesting;
 import com.google.gson.Gson;
 import com.google.gson.GsonBuilder;
 import com.google.gson.TypeAdapter;
+import org.apache.submarine.server.api.environment.EnvironmentId;
 import org.apache.submarine.server.api.experiment.ExperimentId;
+import org.apache.submarine.server.gson.EnvironmentIdDeserializer;
+import org.apache.submarine.server.gson.EnvironmentIdSerializer;
 import org.apache.submarine.server.api.notebook.NotebookId;
 import org.apache.submarine.server.gson.ExperimentIdDeserializer;
 import org.apache.submarine.server.gson.ExperimentIdSerializer;
@@ -174,6 +177,8 @@ public class JsonResponse<T> {
           .registerTypeAdapter(Date.class, safeDateTypeAdapter)
           .registerTypeAdapter(ExperimentId.class, new ExperimentIdSerializer())
           .registerTypeAdapter(ExperimentId.class, new ExperimentIdDeserializer())
+          .registerTypeAdapter(EnvironmentId.class, new EnvironmentIdSerializer())
+          .registerTypeAdapter(EnvironmentId.class, new EnvironmentIdDeserializer())
           .registerTypeAdapter(NotebookId.class, new NotebookIdSerializer())
           .registerTypeAdapter(NotebookId.class, new NotebookIdDeserializer())
           .serializeNulls()
diff --git a/submarine-server/server-core/src/test/java/org/apache/submarine/server/AbstractSubmarineServerTest.java b/submarine-server/server-core/src/test/java/org/apache/submarine/server/AbstractSubmarineServerTest.java
index 4b1b26f..e7ecde4 100644
--- a/submarine-server/server-core/src/test/java/org/apache/submarine/server/AbstractSubmarineServerTest.java
+++ b/submarine-server/server-core/src/test/java/org/apache/submarine/server/AbstractSubmarineServerTest.java
@@ -53,6 +53,9 @@ import org.apache.http.impl.client.HttpClients;
 import org.apache.http.util.EntityUtils;
 import org.apache.submarine.commons.utils.SubmarineConfVars;
 import org.apache.submarine.server.api.environment.Environment;
+import org.apache.submarine.server.api.environment.EnvironmentId;
+import org.apache.submarine.server.gson.EnvironmentIdDeserializer;
+import org.apache.submarine.server.gson.EnvironmentIdSerializer;
 import org.apache.submarine.server.response.JsonResponse;
 import org.apache.submarine.server.rest.RestConstants;
 import org.apache.submarine.server.utils.TestUtils;
@@ -82,7 +85,7 @@ public abstract class AbstractSubmarineServerTest {
   protected static String ENV_PATH =
       "/api/" + RestConstants.V1 + "/" + RestConstants.ENVIRONMENT;
   protected static String ENV_NAME = "my-submarine-env";
-  
+
   public static String getWebsocketApiUrlToTest() {
     String websocketUrl = "ws://localhost:8080" + WEBSOCKET_API_URL;
     if (System.getProperty("websocketUrl") != null) {
@@ -211,8 +214,9 @@ public abstract class AbstractSubmarineServerTest {
       throws IOException {
     return httpPost(path, request, MediaType.APPLICATION_JSON, user, pwd);
   }
+
   protected static PostMethod httpPost(String path, String request, String mediaType, String user,
-      String pwd) throws IOException {
+                                       String pwd) throws IOException {
     LOG.info("Connecting to {}", URL + path);
 
     HttpClient httpClient = new HttpClient();
@@ -251,12 +255,12 @@ public abstract class AbstractSubmarineServerTest {
     LOG.info("{} - {}", putMethod.getStatusCode(), putMethod.getStatusText());
     return putMethod;
   }
-  
+
   protected static String httpPatch(String path, String body,
-      String contentType) throws IOException {
+                                    String contentType) throws IOException {
     LOG.info("Connecting to {}", URL + path);
     CloseableHttpClient httpclient = HttpClients.createDefault();
-    
+
     HttpPatch httpPatch = new HttpPatch(URL + path);
     StringEntity entity = new StringEntity(body, ContentType.APPLICATION_JSON);
     httpPatch.setEntity(entity);
@@ -433,9 +437,12 @@ public abstract class AbstractSubmarineServerTest {
       return StringUtils.EMPTY;
     }
   }
-  
+
   protected void run(String body, String contentType) throws Exception {
-    Gson gson = new GsonBuilder().create();
+    Gson gson = new GsonBuilder()
+        .registerTypeAdapter(EnvironmentId.class, new EnvironmentIdSerializer())
+        .registerTypeAdapter(EnvironmentId.class, new EnvironmentIdDeserializer())
+        .create();
 
     // create
     LOG.info("Create Environment using Environment REST API");
@@ -453,15 +460,18 @@ public abstract class AbstractSubmarineServerTest {
         gson.fromJson(gson.toJson(jsonResponse.getResult()), Environment.class);
     verifyCreateEnvironmentApiResult(env);
   }
-  
+
   protected void update(String body, String contentType) throws Exception {
-    Gson gson = new GsonBuilder().create();
+    Gson gson = new GsonBuilder()
+        .registerTypeAdapter(EnvironmentId.class, new EnvironmentIdSerializer())
+        .registerTypeAdapter(EnvironmentId.class, new EnvironmentIdDeserializer())
+        .create();
 
     // update
     LOG.info("Update Environment using Environment REST API");
 
     String json = httpPatch(ENV_PATH + "/" + ENV_NAME, body, contentType);
-    
+
     JsonResponse jsonResponse = gson.fromJson(json, JsonResponse.class);
     Assert.assertEquals(Response.Status.OK.getStatusCode(),
         jsonResponse.getCode());
@@ -485,9 +495,12 @@ public abstract class AbstractSubmarineServerTest {
         env.getEnvironmentSpec().getKernelSpec().getDependencies().size() == 1);
   }
 
-  
+
   protected void deleteEnvironment() throws IOException {
-    Gson gson = new GsonBuilder().create();
+    Gson gson = new GsonBuilder()
+        .registerTypeAdapter(EnvironmentId.class, new EnvironmentIdSerializer())
+        .registerTypeAdapter(EnvironmentId.class, new EnvironmentIdDeserializer())
+        .create();
     DeleteMethod deleteMethod = httpDelete(ENV_PATH + "/" + ENV_NAME);
     Assert.assertEquals(Response.Status.OK.getStatusCode(),
         deleteMethod.getStatusCode());
diff --git a/submarine-server/server-core/src/test/java/org/apache/submarine/server/rest/EnvironmentRestApiTest.java b/submarine-server/server-core/src/test/java/org/apache/submarine/server/rest/EnvironmentRestApiTest.java
index 4f7b861..f057fe8 100644
--- a/submarine-server/server-core/src/test/java/org/apache/submarine/server/rest/EnvironmentRestApiTest.java
+++ b/submarine-server/server-core/src/test/java/org/apache/submarine/server/rest/EnvironmentRestApiTest.java
@@ -24,8 +24,11 @@ import com.google.gson.GsonBuilder;
 import com.google.gson.reflect.TypeToken;
 import org.apache.submarine.commons.utils.SubmarineConfiguration;
 import org.apache.submarine.server.api.environment.Environment;
+import org.apache.submarine.server.api.environment.EnvironmentId;
 import org.apache.submarine.server.api.spec.EnvironmentSpec;
 import org.apache.submarine.server.api.spec.KernelSpec;
+import org.apache.submarine.server.gson.EnvironmentIdDeserializer;
+import org.apache.submarine.server.gson.EnvironmentIdSerializer;
 import org.apache.submarine.server.response.JsonResponse;
 import org.junit.After;
 import org.junit.Before;
@@ -45,25 +48,27 @@ public class EnvironmentRestApiTest {
   private static String dockerImage = "continuumio/anaconda3";
   private static List<String> kernelChannels = Arrays.asList("defaults", "anaconda");
   private static List<String> kernelDependencies = Arrays.asList(
-          "_ipyw_jlab_nb_ext_conf=0.1.0=py37_0",
-          "alabaster=0.7.12=py37_0",
-          "anaconda=2020.02=py37_0",
-          "anaconda-client=1.7.2=py37_0",
-          "anaconda-navigator=1.9.12=py37_0");
-
-  private static GsonBuilder gsonBuilder = new GsonBuilder();
+      "_ipyw_jlab_nb_ext_conf=0.1.0=py37_0",
+      "alabaster=0.7.12=py37_0",
+      "anaconda=2020.02=py37_0",
+      "anaconda-client=1.7.2=py37_0",
+      "anaconda-navigator=1.9.12=py37_0");
+
+  private static GsonBuilder gsonBuilder = new GsonBuilder()
+      .registerTypeAdapter(EnvironmentId.class, new EnvironmentIdSerializer())
+      .registerTypeAdapter(EnvironmentId.class, new EnvironmentIdDeserializer());
   private static Gson gson = gsonBuilder.setDateFormat("yyyy-MM-dd HH:mm:ss").create();
 
   @BeforeClass
   public static void init() {
     SubmarineConfiguration submarineConf = SubmarineConfiguration.getInstance();
     submarineConf.setMetastoreJdbcUrl("jdbc:mysql://127.0.0.1:3306/submarine_test?" +
-            "useUnicode=true&amp;" +
-            "characterEncoding=UTF-8&amp;" +
-            "autoReconnect=true&amp;" +
-            "failOverReadOnly=false&amp;" +
-            "zeroDateTimeBehavior=convertToNull&amp;" +
-            "useSSL=false");
+        "useUnicode=true&amp;" +
+        "characterEncoding=UTF-8&amp;" +
+        "autoReconnect=true&amp;" +
+        "failOverReadOnly=false&amp;" +
+        "zeroDateTimeBehavior=convertToNull&amp;" +
+        "useSSL=false");
     submarineConf.setMetastoreJdbcUserName("submarine_test");
     submarineConf.setMetastoreJdbcPassword("password_test");
     environmentStoreApi = new EnvironmentRestApi();
diff --git a/submarine-test/test-k8s/src/test/java/org/apache/submarine/rest/EnvironmentManagerRestApiIT.java b/submarine-test/test-k8s/src/test/java/org/apache/submarine/rest/EnvironmentManagerRestApiIT.java
index f230207..d394d98 100644
--- a/submarine-test/test-k8s/src/test/java/org/apache/submarine/rest/EnvironmentManagerRestApiIT.java
+++ b/submarine-test/test-k8s/src/test/java/org/apache/submarine/rest/EnvironmentManagerRestApiIT.java
@@ -26,6 +26,9 @@ import javax.ws.rs.core.Response;
 import org.apache.commons.httpclient.methods.GetMethod;
 import org.apache.submarine.server.AbstractSubmarineServerTest;
 import org.apache.submarine.server.api.environment.Environment;
+import org.apache.submarine.server.api.environment.EnvironmentId;
+import org.apache.submarine.server.gson.EnvironmentIdDeserializer;
+import org.apache.submarine.server.gson.EnvironmentIdSerializer;
 import org.apache.submarine.server.response.JsonResponse;
 import org.junit.Assert;
 import org.junit.BeforeClass;
@@ -48,14 +51,17 @@ public class EnvironmentManagerRestApiIT extends AbstractSubmarineServerTest {
     run(body, "application/json");
     deleteEnvironment();
   }
-  
+
   @Test
   public void testGetEnvironment() throws Exception {
 
     String body = loadContent("environment/test_env_1.json");
     run(body, "application/json");
 
-    Gson gson = new GsonBuilder().create();
+    Gson gson = new GsonBuilder()
+        .registerTypeAdapter(EnvironmentId.class, new EnvironmentIdSerializer())
+        .registerTypeAdapter(EnvironmentId.class, new EnvironmentIdDeserializer())
+        .create();
     GetMethod getMethod = httpGet(ENV_PATH + "/" + ENV_NAME);
     Assert.assertEquals(Response.Status.OK.getStatusCode(),
         getMethod.getStatusCode());
@@ -70,7 +76,7 @@ public class EnvironmentManagerRestApiIT extends AbstractSubmarineServerTest {
     Assert.assertEquals(ENV_NAME, getEnvironment.getEnvironmentSpec().getName());
     deleteEnvironment();
   }
-  
+
 
   @Test
   public void testUpdateEnvironment() throws IOException {
@@ -82,11 +88,11 @@ public class EnvironmentManagerRestApiIT extends AbstractSubmarineServerTest {
     String body = loadContent("environment/test_env_1.json");
     run(body, "application/json");
     deleteEnvironment();
-    
+
     GetMethod getMethod = httpGet(ENV_PATH + "/" + ENV_NAME);
     Assert.assertEquals(Response.Status.NOT_FOUND.getStatusCode(),
         getMethod.getStatusCode());
-    
+
   }
 
   @Test
diff --git a/submarine-test/test-k8s/src/test/java/org/apache/submarine/rest/ExperimentRestApiIT.java b/submarine-test/test-k8s/src/test/java/org/apache/submarine/rest/ExperimentRestApiIT.java
index ebc108e..e440d15 100644
--- a/submarine-test/test-k8s/src/test/java/org/apache/submarine/rest/ExperimentRestApiIT.java
+++ b/submarine-test/test-k8s/src/test/java/org/apache/submarine/rest/ExperimentRestApiIT.java
@@ -34,8 +34,11 @@ import org.apache.commons.httpclient.methods.PostMethod;
 import org.apache.submarine.commons.utils.SubmarineConfVars;
 import org.apache.submarine.commons.utils.SubmarineConfiguration;
 import org.apache.submarine.server.AbstractSubmarineServerTest;
+import org.apache.submarine.server.api.environment.EnvironmentId;
 import org.apache.submarine.server.api.experiment.Experiment;
 import org.apache.submarine.server.api.experiment.ExperimentId;
+import org.apache.submarine.server.gson.EnvironmentIdDeserializer;
+import org.apache.submarine.server.gson.EnvironmentIdSerializer;
 import org.apache.submarine.server.gson.ExperimentIdDeserializer;
 import org.apache.submarine.server.gson.ExperimentIdSerializer;
 import org.apache.submarine.server.api.environment.Environment;
@@ -66,7 +69,9 @@ public class ExperimentRestApiIT extends AbstractSubmarineServerTest {
   private static final Logger LOG = LoggerFactory.getLogger(ExperimentRestApiIT.class);
 
   private static CustomObjectsApi k8sApi;
-  /** Key is the ml framework name, the value is the operator */
+  /**
+   * Key is the ml framework name, the value is the operator
+   */
   private static Map<String, KfOperator> kfOperatorMap;
   private static final String BASE_API_PATH = "/api/" + RestConstants.V1 + "/" + RestConstants.EXPERIMENT;
   private static final String LOG_API_PATH = BASE_API_PATH + "/" + RestConstants.LOGS;
@@ -74,9 +79,11 @@ public class ExperimentRestApiIT extends AbstractSubmarineServerTest {
   private final Gson gson = new GsonBuilder()
       .registerTypeAdapter(ExperimentId.class, new ExperimentIdSerializer())
       .registerTypeAdapter(ExperimentId.class, new ExperimentIdDeserializer())
+      .registerTypeAdapter(EnvironmentId.class, new EnvironmentIdSerializer())
+      .registerTypeAdapter(EnvironmentId.class, new EnvironmentIdDeserializer())
       .create();
-  
-  private static SubmarineConfiguration conf = 
+
+  private static SubmarineConfiguration conf =
       SubmarineConfiguration.getInstance();
 
   @BeforeClass
@@ -119,15 +126,17 @@ public class ExperimentRestApiIT extends AbstractSubmarineServerTest {
     String patchBody = loadContent("tensorflow/tf-mnist-patch-req.yaml");
     run(body, patchBody, "application/yaml");
   }
-  
+
   @Test
   public void testTensorFlowUsingEnvWithJsonSpec() throws Exception {
-
+    Gson gson = new GsonBuilder()
+        .registerTypeAdapter(EnvironmentId.class, new EnvironmentIdSerializer())
+        .registerTypeAdapter(EnvironmentId.class, new EnvironmentIdDeserializer())
+        .create();
     // Create environment
     String envBody = loadContent("environment/test_env_1.json");
     run(envBody, "application/json");
 
-    Gson gson = new GsonBuilder().create();
     GetMethod getMethod = httpGet(ENV_PATH + "/" + ENV_NAME);
     Assert.assertEquals(Response.Status.OK.getStatusCode(),
         getMethod.getStatusCode());
@@ -163,7 +172,7 @@ public class ExperimentRestApiIT extends AbstractSubmarineServerTest {
     String patchBody = loadContent("pytorch/pt-mnist-patch-req.yaml");
     run(body, patchBody, "application/yaml");
   }
-  
+
   @Test
   public void testTensorFlowUsingCodeWithJsonSpec() throws Exception {
     String body = loadContent("tensorflow/tf-mnist-with-http-git-code-localizer-req.json");
@@ -213,9 +222,9 @@ public class ExperimentRestApiIT extends AbstractSubmarineServerTest {
     Experiment deletedExperiment = gson.fromJson(gson.toJson(jsonResponse.getResult()), Experiment.class);
     verifyDeleteJobApiResult(createdExperiment, deletedExperiment);
   }
-  
+
   private void run(Environment expectedEnv, String body, String patchBody,
-      String contentType) throws Exception {
+                   String contentType) throws Exception {
     // create
     LOG.info("Create training job using Environment by Job REST API");
     PostMethod postMethod = httpPost(BASE_API_PATH, body, contentType);
@@ -227,7 +236,7 @@ public class ExperimentRestApiIT extends AbstractSubmarineServerTest {
     Assert.assertEquals(Response.Status.OK.getStatusCode(),
         jsonResponse.getCode());
 
-    Experiment createdExperiment = 
+    Experiment createdExperiment =
         gson.fromJson(gson.toJson(jsonResponse.getResult()), Experiment.class);
     verifyCreateJobApiResult(expectedEnv, createdExperiment);
 
@@ -269,7 +278,7 @@ public class ExperimentRestApiIT extends AbstractSubmarineServerTest {
 
     assertK8sResultEquals(createdExperiment);
   }
-  
+
   private void verifyCreateJobApiResult(Environment env, Experiment createdJob)
       throws Exception {
     Assert.assertNotNull(createdJob.getUid());
@@ -303,27 +312,27 @@ public class ExperimentRestApiIT extends AbstractSubmarineServerTest {
     JsonArray expected = new JsonArray();
     expected.add("/bin/bash");
     expected.add("-c");
-    
+
     String minVersion = "minVersion=\""
         + conf.getString(
-            SubmarineConfVars.ConfVars.ENVIRONMENT_CONDA_MIN_VERSION)
+        SubmarineConfVars.ConfVars.ENVIRONMENT_CONDA_MIN_VERSION)
         + "\";";
     String maxVersion = "maxVersion=\""
         + conf.getString(
-            SubmarineConfVars.ConfVars.ENVIRONMENT_CONDA_MAX_VERSION)
+        SubmarineConfVars.ConfVars.ENVIRONMENT_CONDA_MAX_VERSION)
         + "\";";
     String currentVersion = "currentVersion=$(conda -V | cut -f2 -d' ');";
-    String versionCommand = 
-        minVersion + maxVersion + currentVersion 
+    String versionCommand =
+        minVersion + maxVersion + currentVersion
             + "if [ \"$(printf '%s\\n' \"$minVersion\" \"$maxVersion\" "
-               + "\"$currentVersion\" | sort -V | head -n2 | tail -1 )\" "
-                    + "!= \"$currentVersion\" ]; then echo \"Conda version " + 
-                    "should be between minVersion=\"4.0.1\"; " + 
-                    "and maxVersion=\"4.10.10\";\"; exit 1; else echo "
-                    + "\"Conda current version is " + currentVersion + ". "
-                        + "Moving forward with env creation and activation.\"; "
-                        + "fi && ";
-    
+            + "\"$currentVersion\" | sort -V | head -n2 | tail -1 )\" "
+            + "!= \"$currentVersion\" ]; then echo \"Conda version " +
+            "should be between minVersion=\"4.0.1\"; " +
+            "and maxVersion=\"4.10.10\";\"; exit 1; else echo "
+            + "\"Conda current version is " + currentVersion + ". "
+            + "Moving forward with env creation and activation.\"; "
+            + "fi && ";
+
     String initialCommand =
         "conda create -n " + env.getEnvironmentSpec().getKernelSpec().getName();
 
@@ -361,7 +370,7 @@ public class ExperimentRestApiIT extends AbstractSubmarineServerTest {
     LOG.info("CreationTimestamp from K8s REST is {}", actualDate);
     Assert.assertEquals(expectedDate, actualDate);
   }
-  
+
   private void assertK8sResultEquals(Experiment experiment) throws Exception {
     KfOperator operator = kfOperatorMap.get(experiment.getSpec().getMeta().getFramework().toLowerCase());
     JsonObject rootObject = getJobByK8sApi(operator.getGroup(), operator.getVersion(),
@@ -401,7 +410,7 @@ public class ExperimentRestApiIT extends AbstractSubmarineServerTest {
   }
 
   private JsonObject getJobByK8sApi(String group, String version, String namespace, String plural,
-      String name) throws ApiException {
+                                    String name) throws ApiException {
     Object obj = k8sApi.getNamespacedCustomObject(group, version, namespace, plural, name);
     Gson gson = new JSON().getGson();
     JsonObject rootObject = gson.toJsonTree(obj).getAsJsonObject();
diff --git a/submarine-test/test-k8s/src/test/java/org/apache/submarine/rest/NotebookRestApiIT.java b/submarine-test/test-k8s/src/test/java/org/apache/submarine/rest/NotebookRestApiIT.java
index 1359ed8..8fd2bb5 100644
--- a/submarine-test/test-k8s/src/test/java/org/apache/submarine/rest/NotebookRestApiIT.java
+++ b/submarine-test/test-k8s/src/test/java/org/apache/submarine/rest/NotebookRestApiIT.java
@@ -35,9 +35,12 @@ import org.apache.commons.httpclient.methods.GetMethod;
 import org.apache.commons.httpclient.methods.PostMethod;
 import org.apache.submarine.server.AbstractSubmarineServerTest;
 import org.apache.submarine.server.api.environment.Environment;
+import org.apache.submarine.server.api.environment.EnvironmentId;
 import org.apache.submarine.server.api.experiment.Experiment;
 import org.apache.submarine.server.api.notebook.Notebook;
 import org.apache.submarine.server.api.notebook.NotebookId;
+import org.apache.submarine.server.gson.EnvironmentIdDeserializer;
+import org.apache.submarine.server.gson.EnvironmentIdSerializer;
 import org.apache.submarine.server.gson.NotebookIdDeserializer;
 import org.apache.submarine.server.gson.NotebookIdSerializer;
 import org.apache.submarine.server.response.JsonResponse;
@@ -67,9 +70,11 @@ public class NotebookRestApiIT extends AbstractSubmarineServerTest {
   public static final String PLURAL = "notebooks";
 
   private final Gson gson = new GsonBuilder()
-          .registerTypeAdapter(NotebookId.class, new NotebookIdSerializer())
-          .registerTypeAdapter(NotebookId.class, new NotebookIdDeserializer())
-          .create();
+      .registerTypeAdapter(NotebookId.class, new NotebookIdSerializer())
+      .registerTypeAdapter(NotebookId.class, new NotebookIdDeserializer())
+      .registerTypeAdapter(EnvironmentId.class, new EnvironmentIdSerializer())
+      .registerTypeAdapter(EnvironmentId.class, new EnvironmentIdDeserializer())
+      .create();
 
   @BeforeClass
   public static void startUp() throws IOException {
@@ -99,18 +104,21 @@ public class NotebookRestApiIT extends AbstractSubmarineServerTest {
     String envBody = loadContent("environment/test_env_3.json");
     run(envBody, "application/json");
 
-    Gson gson = new GsonBuilder().create();
+    Gson gson = new GsonBuilder()
+        .registerTypeAdapter(EnvironmentId.class, new EnvironmentIdSerializer())
+        .registerTypeAdapter(EnvironmentId.class, new EnvironmentIdDeserializer())
+        .create();
     GetMethod getMethod = httpGet(ENV_PATH + "/" + ENV_NAME);
     Assert.assertEquals(Response.Status.OK.getStatusCode(),
-            getMethod.getStatusCode());
+        getMethod.getStatusCode());
 
     String json = getMethod.getResponseBodyAsString();
     JsonResponse jsonResponse = gson.fromJson(json, JsonResponse.class);
     Assert.assertEquals(Response.Status.OK.getStatusCode(),
-            jsonResponse.getCode());
+        jsonResponse.getCode());
 
     Environment getEnvironment =
-            gson.fromJson(gson.toJson(jsonResponse.getResult()), Environment.class);
+        gson.fromJson(gson.toJson(jsonResponse.getResult()), Environment.class);
     Assert.assertEquals(ENV_NAME, getEnvironment.getEnvironmentSpec().getName());
 
     String body = loadContent("notebook/notebook-req.json");
@@ -124,19 +132,21 @@ public class NotebookRestApiIT extends AbstractSubmarineServerTest {
     // create environment
     String envBody = loadContent("environment/test_env_3.json");
     run(envBody, "application/json");
-
-    Gson gson = new GsonBuilder().create();
+    Gson gson = new GsonBuilder()
+        .registerTypeAdapter(EnvironmentId.class, new EnvironmentIdSerializer())
+        .registerTypeAdapter(EnvironmentId.class, new EnvironmentIdDeserializer())
+        .create();
     GetMethod getMethod = httpGet(ENV_PATH + "/" + ENV_NAME);
     Assert.assertEquals(Response.Status.OK.getStatusCode(),
-            getMethod.getStatusCode());
+        getMethod.getStatusCode());
 
     String json = getMethod.getResponseBodyAsString();
     JsonResponse jsonResponse = gson.fromJson(json, JsonResponse.class);
     Assert.assertEquals(Response.Status.OK.getStatusCode(),
-            jsonResponse.getCode());
+        jsonResponse.getCode());
 
     Environment getEnvironment =
-            gson.fromJson(gson.toJson(jsonResponse.getResult()), Environment.class);
+        gson.fromJson(gson.toJson(jsonResponse.getResult()), Environment.class);
     Assert.assertEquals(ENV_NAME, getEnvironment.getEnvironmentSpec().getName());
 
     String body = loadContent("notebook/notebook-req.yaml");
@@ -181,7 +191,7 @@ public class NotebookRestApiIT extends AbstractSubmarineServerTest {
 
     // delete
     DeleteMethod deleteMethod =
-            httpDelete(BASE_API_PATH + "/" + createdNotebook.getNotebookId().toString());
+        httpDelete(BASE_API_PATH + "/" + createdNotebook.getNotebookId().toString());
     Assert.assertEquals(Response.Status.OK.getStatusCode(), deleteMethod.getStatusCode());
 
     json = deleteMethod.getResponseBodyAsString();
@@ -216,7 +226,7 @@ public class NotebookRestApiIT extends AbstractSubmarineServerTest {
 
   private void assertGetK8sResult(Notebook notebook) throws Exception {
     JsonObject rootObject = getNotebookByK8sApi(GROUP, VERSION, notebook.getSpec().getMeta().getNamespace(),
-            PLURAL, notebook.getName());
+        PLURAL, notebook.getName());
 
     JsonObject metadataObject = rootObject.getAsJsonObject("metadata");
     String uid = metadataObject.getAsJsonPrimitive("uid").getAsString();
@@ -225,12 +235,12 @@ public class NotebookRestApiIT extends AbstractSubmarineServerTest {
     Assert.assertEquals(notebook.getUid(), uid);
 
     JsonArray envVars = (JsonArray) rootObject.getAsJsonObject("spec")
-            .getAsJsonObject("template").getAsJsonObject("spec")
-            .getAsJsonArray("containers").get(0).getAsJsonObject().get("env");
+        .getAsJsonObject("template").getAsJsonObject("spec")
+        .getAsJsonArray("containers").get(0).getAsJsonObject().get("env");
     Assert.assertNotNull("The environment command not found.", envVars);
 
     String creationTimestamp =
-            metadataObject.getAsJsonPrimitive("creationTimestamp").getAsString();
+        metadataObject.getAsJsonPrimitive("creationTimestamp").getAsString();
     Date expectedDate = new DateTime(notebook.getCreatedTime()).toDate();
     Date actualDate = new DateTime(creationTimestamp).toDate();
     LOG.info("CreationTimestamp from Notebook REST is {}", expectedDate);
@@ -242,7 +252,7 @@ public class NotebookRestApiIT extends AbstractSubmarineServerTest {
     JsonObject rootObject = null;
     try {
       rootObject = getNotebookByK8sApi(GROUP, VERSION, notebook.getSpec().getMeta().getNamespace(),
-              PLURAL, notebook.getName());
+          PLURAL, notebook.getName());
     } catch (ApiException e) {
       Assert.assertEquals(Response.Status.NOT_FOUND.getStatusCode(), e.getCode());
     } finally {
@@ -251,7 +261,7 @@ public class NotebookRestApiIT extends AbstractSubmarineServerTest {
   }
 
   private JsonObject getNotebookByK8sApi(String group, String version, String namespace, String plural,
-                                   String name) throws ApiException {
+                                         String name) throws ApiException {
     Object obj = k8sApi.getNamespacedCustomObject(group, version, namespace, plural, name);
     Gson gson = new JSON().getGson();
     JsonObject rootObject = gson.toJsonTree(obj).getAsJsonObject();


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@submarine.apache.org
For additional commands, e-mail: dev-help@submarine.apache.org