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 dc0f409  SUBMARINE-567. Fix travis test failure
dc0f409 is described below

commit dc0f409151202033eab925d2824cc04319e09c3d
Author: Kevin Su <[email protected]>
AuthorDate: Thu Jul 16 06:53:54 2020 +0800

    SUBMARINE-567. Fix travis test failure
    
    ### What is this PR for?
    Fix the test failure causes by SUBMARINE-504
    
    ### What type of PR is it?
    [Bug Fix]
    
    ### Todos
    * [ ] - Task
    
    ### What is the Jira issue?
    https://issues.apache.org/jira/browse/SUBMARINE-567
    
    ### How should this be tested?
    https://travis-ci.org/github/pingsutw/hadoop-submarine/builds/708518581
    
    ### 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: Kevin Su <[email protected]>
    Author: pingsutw <[email protected]>
    
    Closes #347 from pingsutw/SUBMARINE-507-2 and squashes the following 
commits:
    
    63a66d9 [pingsutw] Fix checkstyle
    ac9dd66 [pingsutw] test18
    51d0e46 [pingsutw] test17
    90f6861 [pingsutw] test16
    0ac802e [pingsutw] test15
    8fbd610 [Kevin Su] test12
    841fb76 [Kevin Su] test11
    cc2e920 [Kevin Su] test11
    e5a1dc5 [Kevin Su] test10
    4d49377 [Kevin Su] test10
    d962176 [Kevin Su] test9
    d60e4ff [Kevin Su] test8
    003313d [Kevin Su] test7
    80c1c63 [Kevin Su] test7
    8d860c0 [Kevin Su] test5
    64ebc06 [Kevin Su] test4
    db9eb38 [Kevin Su] test3
    ee96962 [Kevin Su] test2
    8ce998e [Kevin Su] test1
---
 docs/database/metastore.sql                        |  12 --
 docs/database/submarine.sql                        |  18 ++-
 .../server/database/utils/MyBatisUtil.java         |  59 ++++------
 .../server/environment/EnvironmentManager.java     |  38 +++----
 .../src/main/resources/mybatis-config.xml          |   1 +
 .../server/rest/EnvironmentManagerRestApiTest.java | 124 ---------------------
 .../server/rest/EnvironmentRestApiTest.java        | 119 ++++++++++++++++++++
 .../server-submitter/submitter-k8s/pom.xml         |   4 +
 .../submitter/k8s/parser/ExperimentSpecParser.java |   9 +-
 9 files changed, 186 insertions(+), 198 deletions(-)

diff --git a/docs/database/metastore.sql b/docs/database/metastore.sql
index 264d6c6..041c96d 100644
--- a/docs/database/metastore.sql
+++ b/docs/database/metastore.sql
@@ -963,18 +963,6 @@ CREATE TABLE WRITE_SET (
   WS_OPERATION_TYPE char(1) NOT NULL
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
 
-CREATE TABLE `environment` (
-  `id` varchar(64) NOT NULL COMMENT 'Id of the Environment',
-  `environment_name` varchar(255) NOT NULL COMMENT 'Name of the Environment',
-  `environment_spec` text NOT NULL COMMENT 'Spec of the Environment',
-  `create_by` varchar(32) DEFAULT NULL COMMENT 'create user',
-  `create_time` datetime DEFAULT NULL COMMENT 'create time',
-  `update_by` varchar(32) DEFAULT NULL COMMENT 'last update user',
-  `update_time` datetime DEFAULT NULL COMMENT 'last update time',
-   PRIMARY KEY `id` (`id`),
-   UNIQUE KEY `environment_name` (`environment_name`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-
 -- -----------------------------------------------------------------
 -- Record schema version. Should be the last step in the init script
 -- -----------------------------------------------------------------
diff --git a/docs/database/submarine.sql b/docs/database/submarine.sql
index 729aed5..dabfcfb 100644
--- a/docs/database/submarine.sql
+++ b/docs/database/submarine.sql
@@ -219,7 +219,23 @@ CREATE TABLE `job` (
   `update_time` datetime default NULL COMMENT 'last update time',
   PRIMARY KEY  (`id`)
   ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-  
+
+-- ----------------------------
+-- Table structure for environment
+-- ----------------------------
+DROP TABLE IF EXISTS `environment`;
+CREATE TABLE `environment` (
+  `id` varchar(64) NOT NULL COMMENT 'Id of the Environment',
+  `environment_name` varchar(255) NOT NULL COMMENT 'Name of the Environment',
+  `environment_spec` text NOT NULL COMMENT 'Spec of the Environment',
+  `create_by` varchar(32) DEFAULT NULL COMMENT 'create user',
+  `create_time` datetime DEFAULT NULL COMMENT 'create time',
+  `update_by` varchar(32) DEFAULT NULL COMMENT 'last update user',
+  `update_time` datetime DEFAULT NULL COMMENT 'last update time',
+   PRIMARY KEY `id` (`id`),
+   UNIQUE KEY `environment_name` (`environment_name`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+
 -- ----------------------------
 -- Table structure for metric
 -- ----------------------------
diff --git 
a/submarine-server/server-core/src/main/java/org/apache/submarine/server/database/utils/MyBatisUtil.java
 
b/submarine-server/server-core/src/main/java/org/apache/submarine/server/database/utils/MyBatisUtil.java
index 9c85765..51b4519 100755
--- 
a/submarine-server/server-core/src/main/java/org/apache/submarine/server/database/utils/MyBatisUtil.java
+++ 
b/submarine-server/server-core/src/main/java/org/apache/submarine/server/database/utils/MyBatisUtil.java
@@ -34,39 +34,33 @@ public class MyBatisUtil {
   private static final Logger LOG = LoggerFactory.getLogger(MyBatisUtil.class);
 
   private static SqlSessionFactory sqlSessionFactory;
-  private static SqlSessionFactory metastoreSqlSessionFactory;
 
   static {
-    SubmarineConfiguration conf = SubmarineConfiguration.getInstance();
-    sqlSessionFactory = buildSqlSessionFactory("mybatis-config.xml",
-        conf.getJdbcUrl(), conf.getJdbcUserName(), conf.getJdbcPassword());
-    metastoreSqlSessionFactory = buildSqlSessionFactory(
-        "mybatis-config-metastore.xml", conf.getMetastoreJdbcUrl(),
-        conf.getMetastoreJdbcUserName(), conf.getMetastoreJdbcPassword());
-  }
-
-  private static SqlSessionFactory buildSqlSessionFactory(String configFile,
-      String jdbcUrl, String jdbcUserName, String jdbcPassword) {
     Reader reader = null;
-    SqlSessionFactory sqlSessionFactory = null;
     try {
       try {
-        reader = Resources.getResourceAsReader(configFile);
+        reader = Resources.getResourceAsReader("mybatis-config.xml");
       } catch (IOException e) {
         LOG.error(e.getMessage(), e);
         throw new RuntimeException(e.getMessage());
       }
-      checkCalledByTestMethod(jdbcUrl, jdbcUserName, jdbcPassword);
-      String jdbcClassName =
-          SubmarineConfiguration.getInstance().getJdbcDriverClassName();
-      LOG.info(
-          "MyBatisUtil -> jdbcClassName: {}, jdbcUrl: {}, jdbcUserName: {}, 
jdbcPassword: {}",
-          jdbcClassName, jdbcUrl, jdbcUserName, jdbcPassword);
+
+      checkCalledByTestMethod();
+
+      SubmarineConfiguration conf = SubmarineConfiguration.getInstance();
+      String jdbcClassName = conf.getJdbcDriverClassName();
+      String jdbcUrl = conf.getJdbcUrl();
+      String jdbcUserName = conf.getJdbcUserName();
+      String jdbcPassword = conf.getJdbcPassword();
+      LOG.info("MyBatisUtil -> jdbcClassName: {}, jdbcUrl: {}, jdbcUserName: 
{}, jdbcPassword: {}",
+              jdbcClassName, jdbcUrl, jdbcUserName, jdbcPassword);
+
       Properties props = new Properties();
       props.setProperty("jdbc.driverClassName", jdbcClassName);
       props.setProperty("jdbc.url", jdbcUrl);
       props.setProperty("jdbc.username", jdbcUserName);
       props.setProperty("jdbc.password", jdbcPassword);
+
       sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader, props);
     } finally {
       try {
@@ -77,7 +71,6 @@ public class MyBatisUtil {
         LOG.error(e.getMessage(), e);
       }
     }
-    return sqlSessionFactory;
   }
 
   /**
@@ -88,31 +81,25 @@ public class MyBatisUtil {
   public static SqlSession getSqlSession() {
     return sqlSessionFactory.openSession();
   }
-  
-  public static SqlSession getMetastoreSqlSession() {
-    return metastoreSqlSessionFactory.openSession();
-  }
 
-  private static void checkCalledByTestMethod(String jdbcUrl,
-      String jdbcUserName, String jdbcPassword) {
-    StackTraceElement[] stackTraceElements =
-        Thread.currentThread().getStackTrace();
+  private static void checkCalledByTestMethod() {
+    StackTraceElement[] stackTraceElements = 
Thread.currentThread().getStackTrace();
     for (StackTraceElement element : stackTraceElements) {
       if (element.getClassName().endsWith("Test")) {
-        usingTestDatabase(jdbcUrl, jdbcUserName, jdbcPassword);
+        usingTestDatabase();
         return;
       }
     }
   }
 
-  private static void usingTestDatabase(String jdbcUrl, String jdbcUserName,
-      String jdbcPassword) {
+  private static void usingTestDatabase() {
     LOG.info("Run the test unit using the test database");
-    String jdbcPropertiesSuffix = "_test";
-    String finalJdbcUrl = jdbcUrl.replace("?", jdbcPropertiesSuffix + "?");
+    // Run the test unit using the test database
     SubmarineConfiguration conf = SubmarineConfiguration.getInstance();
-    conf.setJdbcUrl(finalJdbcUrl);
-    conf.setJdbcUserName(jdbcUserName + jdbcPropertiesSuffix);
-    conf.setJdbcPassword(jdbcPassword + jdbcPropertiesSuffix);
+    conf.setJdbcUrl("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");
+    conf.setJdbcUserName("submarine_test");
+    conf.setJdbcPassword("password_test");
   }
 }
diff --git 
a/submarine-server/server-core/src/main/java/org/apache/submarine/server/environment/EnvironmentManager.java
 
b/submarine-server/server-core/src/main/java/org/apache/submarine/server/environment/EnvironmentManager.java
index 8cfcf89..cbd6756 100644
--- 
a/submarine-server/server-core/src/main/java/org/apache/submarine/server/environment/EnvironmentManager.java
+++ 
b/submarine-server/server-core/src/main/java/org/apache/submarine/server/environment/EnvironmentManager.java
@@ -46,20 +46,20 @@ import com.google.gson.GsonBuilder;
  * Environment Management
  */
 public class EnvironmentManager {
-  
+
   private static final Logger LOG =
       LoggerFactory.getLogger(EnvironmentManager.class);
 
   private static volatile EnvironmentManager manager;
-  
+
   private final AtomicInteger environmentIdCounter = new AtomicInteger(0);
-  
+
   /**
    * Environment Cache
    */
   private final ConcurrentMap<String, Environment> cachedEnvironments =
       new ConcurrentHashMap<>();
-  
+
   /**
    * Get the singleton instance
    * @return object
@@ -76,7 +76,7 @@ public class EnvironmentManager {
   }
 
   private EnvironmentManager() {
-    
+
   }
 
   /**
@@ -84,7 +84,6 @@ public class EnvironmentManager {
    * @param spec environment spec
    * @return Environment environment
    * @throws SubmarineRuntimeException the service error
-   * @throws MetaException 
    */
   public Environment createEnvironment(EnvironmentSpec spec)
       throws SubmarineRuntimeException {
@@ -92,7 +91,7 @@ public class EnvironmentManager {
     LOG.info("Create Environment using spec: " + spec.toString());
     return createOrUpdateEnvironment(spec, "c");
   }
-  
+
   /**
    * Update environment
    * @param name Name of the environment
@@ -111,7 +110,7 @@ public class EnvironmentManager {
     LOG.info("Update Environment using spec: " + spec.toString());
     return createOrUpdateEnvironment(spec, "u");
   }
-  
+
   private Environment createOrUpdateEnvironment(EnvironmentSpec spec,
       String operation) {
     EnvironmentEntity entity = new EnvironmentEntity();
@@ -120,7 +119,7 @@ public class EnvironmentManager {
     entity.setEnvironmentName(spec.getName());
     entity.setEnvironmentSpec(
         new GsonBuilder().disableHtmlEscaping().create().toJson(spec));
-    try (SqlSession sqlSession = MyBatisUtil.getMetastoreSqlSession()) {
+    try (SqlSession sqlSession = MyBatisUtil.getSqlSession()) {
       EnvironmentMapper environmentMapper =
           sqlSession.getMapper(EnvironmentMapper.class);
       if (operation.equals("c")) {
@@ -144,12 +143,12 @@ public class EnvironmentManager {
           "Unable to process the environment spec.");
     }
   }
-  
+
   private EnvironmentId generateEnvironmentId() {
     return EnvironmentId.newInstance(SubmarineServer.getServerTimeStamp(),
         environmentIdCounter.incrementAndGet());
   }
-  
+
   /**
    * Delete environment
    * @param name Name of the environment
@@ -163,14 +162,14 @@ public class EnvironmentManager {
       throw new SubmarineRuntimeException(Status.NOT_FOUND.getStatusCode(),
           "Environment not found.");
     }
-    
+
     LOG.info("Delete Environment for " + name);
-    try (SqlSession sqlSession = MyBatisUtil.getMetastoreSqlSession()) {
+    try (SqlSession sqlSession = MyBatisUtil.getSqlSession()) {
       EnvironmentMapper environmentMapper =
           sqlSession.getMapper(EnvironmentMapper.class);
       environmentMapper.delete(name);
       sqlSession.commit();
-      
+
       // Invalidate cache
       cachedEnvironments.remove(name);
       return env;
@@ -180,7 +179,7 @@ public class EnvironmentManager {
           "Unable to delete the environment.");
     }
   }
-  
+
   /**
    * Get Environment
    * @param name Name of the environment
@@ -212,7 +211,7 @@ public class EnvironmentManager {
   private void checkSpec(EnvironmentSpec spec)
       throws SubmarineRuntimeException {
     if (spec == null) {
-      throw new SubmarineRuntimeException(Status.OK.getStatusCode(),
+      throw new SubmarineRuntimeException(Status.BAD_REQUEST.getStatusCode(),
           "Invalid environment spec.");
     }
   }
@@ -225,10 +224,9 @@ public class EnvironmentManager {
     if (env != null) {
       return env;
     }
-    
-    try (SqlSession sqlSession = MyBatisUtil.getMetastoreSqlSession()) {
-      EnvironmentMapper environmentMapper =
-          sqlSession.getMapper(EnvironmentMapper.class);
+
+    try (SqlSession sqlSession = MyBatisUtil.getSqlSession()) {
+      EnvironmentMapper environmentMapper = 
sqlSession.getMapper(EnvironmentMapper.class);
       EnvironmentEntity environmentEntity = environmentMapper.select(name);
 
       if (environmentEntity != null) {
diff --git a/submarine-server/server-core/src/main/resources/mybatis-config.xml 
b/submarine-server/server-core/src/main/resources/mybatis-config.xml
index 62a4201..fee836c 100755
--- a/submarine-server/server-core/src/main/resources/mybatis-config.xml
+++ b/submarine-server/server-core/src/main/resources/mybatis-config.xml
@@ -66,5 +66,6 @@
     <mapper resource='org/apache/submarine/database/mappers/JobMapper.xml'/>
     <mapper resource='org/apache/submarine/database/mappers/MetricMapper.xml'/>
     <mapper resource='org/apache/submarine/database/mappers/ParamMapper.xml'/>
+    <mapper 
resource='org/apache/submarine/database/mappers/EnvironmentMapper.xml'/>
   </mappers>
 </configuration>
diff --git 
a/submarine-server/server-core/src/test/java/org/apache/submarine/server/rest/EnvironmentManagerRestApiTest.java
 
b/submarine-server/server-core/src/test/java/org/apache/submarine/server/rest/EnvironmentManagerRestApiTest.java
deleted file mode 100644
index dd1dfd8..0000000
--- 
a/submarine-server/server-core/src/test/java/org/apache/submarine/server/rest/EnvironmentManagerRestApiTest.java
+++ /dev/null
@@ -1,124 +0,0 @@
-/*
- * 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.rest;
-
-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.response.JsonResponse;
-import org.junit.AfterClass;
-import org.junit.Assert;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
-
-@SuppressWarnings("rawtypes")
-public class EnvironmentManagerRestApiTest extends AbstractSubmarineServerTest 
{
-
-  private static String ENV_PATH =
-      "/api/" + RestConstants.V1 + "/" + RestConstants.ENVIRONMENTS;
-  private static String ENV_NAME = "my-submarine-env";
-
-  @BeforeClass
-  public static void startUp() throws Exception {
-    AbstractSubmarineServerTest
-        .startUp(EnvironmentManagerRestApiTest.class.getSimpleName());
-    Assert.assertTrue(checkIfServerIsRunning());
-  }
-
-  @AfterClass
-  public static void destroy() throws Exception {
-    AbstractSubmarineServerTest.shutDown();
-  }
-
-  @Test
-  public void testCreateEnvironment() throws Exception {
-    String body = loadContent("environment/test_env_1.json");
-    run(body, "application/json");
-    deleteEnvironment();
-  }
-
-  @Test
-  public void testUpdateEnvironment() throws Exception {
-    
-    // Create environment
-    String body = loadContent("environment/test_env_1.json");
-    run(body, "application/json");
-    
-    // Updated spec
-    String updatedBody = loadContent("environment/test_env_2.json");
-    
-    update(updatedBody, "application/json");
-    deleteEnvironment();
-  }
-
-  @Test
-  public void testDeleteEnvironment() throws Exception {
-    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
-  public void testGetEnvironment() throws Exception {
-
-    String body = loadContent("environment/test_env_1.json");
-    run(body, "application/json");
-
-    Gson gson = new GsonBuilder().create();
-    GetMethod getMethod = httpGet(ENV_PATH + "/" + ENV_NAME);
-    Assert.assertEquals(Response.Status.OK.getStatusCode(),
-        getMethod.getStatusCode());
-
-    String json = getMethod.getResponseBodyAsString();
-    JsonResponse jsonResponse = gson.fromJson(json, JsonResponse.class);
-    Assert.assertEquals(Response.Status.OK.getStatusCode(),
-        jsonResponse.getCode());
-
-    Environment getEnvironment =
-        gson.fromJson(gson.toJson(jsonResponse.getResult()), 
Environment.class);
-    Assert.assertEquals(ENV_NAME, 
getEnvironment.getEnvironmentSpec().getName());
-    
-    deleteEnvironment();
-  }
-
-  @Test
-  public void testNotFoundEnvironment() throws Exception {
-
-    Gson gson = new GsonBuilder().create();
-
-    GetMethod getMethod = httpGet(ENV_PATH + "/" + "no_such_env_exists");
-    Assert.assertEquals(Response.Status.NOT_FOUND.getStatusCode(),
-        getMethod.getStatusCode());
-
-    String json = getMethod.getResponseBodyAsString();
-    JsonResponse jsonResponse = gson.fromJson(json, JsonResponse.class);
-    Assert.assertEquals(Response.Status.NOT_FOUND.getStatusCode(),
-        jsonResponse.getCode());
-  }
-}
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
new file mode 100644
index 0000000..44ecd96
--- /dev/null
+++ 
b/submarine-server/server-core/src/test/java/org/apache/submarine/server/rest/EnvironmentRestApiTest.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.rest;
+
+import com.google.gson.Gson;
+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.spec.EnvironmentSpec;
+import org.apache.submarine.server.api.spec.KernelSpec;
+import org.apache.submarine.server.response.JsonResponse;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import javax.ws.rs.core.Response;
+import java.lang.reflect.Type;
+import java.util.Arrays;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+
+public class EnvironmentRestApiTest {
+  private static EnvironmentRestApi environmentStoreApi;
+  private static String environmentName = "my-submarine-env";
+  private static String kernelName = "team_default_python_3";
+  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();
+  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");
+    submarineConf.setMetastoreJdbcUserName("submarine_test");
+    submarineConf.setMetastoreJdbcPassword("password_test");
+    environmentStoreApi = new EnvironmentRestApi();
+  }
+
+  @Before
+  public void createAndUpdateEnvironment() {
+    KernelSpec kernelSpec = new KernelSpec();
+    kernelSpec.setName(kernelName);
+    kernelSpec.setChannels(kernelChannels);
+    kernelSpec.setDependencies(kernelDependencies);
+    EnvironmentSpec environmentSpec = new EnvironmentSpec();
+    environmentSpec.setDockerImage(dockerImage);
+    environmentSpec.setKernelSpec(kernelSpec);
+    environmentSpec.setName("foo");
+
+    // Create Environment
+    Response createEnvResponse = 
environmentStoreApi.createEnvironment(environmentSpec);
+    assertEquals(Response.Status.OK.getStatusCode(), 
createEnvResponse.getStatus());
+
+    // Update Environment
+    environmentSpec.setName(environmentName);
+    Response updateEnvResponse = environmentStoreApi.updateEnvironment(
+            "foo", environmentSpec);
+    assertEquals(Response.Status.OK.getStatusCode(), 
updateEnvResponse.getStatus());
+  }
+
+  @After
+  public void deleteEnvironment() {
+    Response deleteEnvResponse = environmentStoreApi
+            .deleteEnvironment(environmentName);
+    assertEquals(Response.Status.OK.getStatusCode(), 
deleteEnvResponse.getStatus());
+  }
+
+  @Test
+  public void getEnvironment() {
+    Response getEnvResponse = 
environmentStoreApi.getEnvironment(environmentName);
+    Environment environment = getEnvironmentFromResponse(getEnvResponse);
+    assertEquals(environmentName, environment.getEnvironmentSpec().getName());
+    assertEquals(kernelName, 
environment.getEnvironmentSpec().getKernelSpec().getName());
+    assertEquals(kernelChannels, 
environment.getEnvironmentSpec().getKernelSpec().getChannels());
+    assertEquals(kernelDependencies, 
environment.getEnvironmentSpec().getKernelSpec().getDependencies());
+    assertEquals(dockerImage, 
environment.getEnvironmentSpec().getDockerImage());
+  }
+
+  private Environment getEnvironmentFromResponse(Response response) {
+    String entity = (String) response.getEntity();
+    Type type = new TypeToken<JsonResponse<Environment>>() {}.getType();
+    JsonResponse<Environment> jsonResponse = gson.fromJson(entity, type);
+    return jsonResponse.getResult();
+  }
+}
diff --git a/submarine-server/server-submitter/submitter-k8s/pom.xml 
b/submarine-server/server-submitter/submitter-k8s/pom.xml
index d5d0d65..a2b4b24 100644
--- a/submarine-server/server-submitter/submitter-k8s/pom.xml
+++ b/submarine-server/server-submitter/submitter-k8s/pom.xml
@@ -78,6 +78,10 @@
           <groupId>joda-time</groupId>
           <artifactId>joda-time</artifactId>
         </exclusion>
+        <exclusion>
+          <groupId>mysql</groupId>
+          <artifactId>mysql-connector-java</artifactId>
+        </exclusion>
       </exclusions>
     </dependency>
 
diff --git 
a/submarine-server/server-submitter/submitter-k8s/src/main/java/org/apache/submarine/server/submitter/k8s/parser/ExperimentSpecParser.java
 
b/submarine-server/server-submitter/submitter-k8s/src/main/java/org/apache/submarine/server/submitter/k8s/parser/ExperimentSpecParser.java
index c29f1d6..ee745a9 100644
--- 
a/submarine-server/server-submitter/submitter-k8s/src/main/java/org/apache/submarine/server/submitter/k8s/parser/ExperimentSpecParser.java
+++ 
b/submarine-server/server-submitter/submitter-k8s/src/main/java/org/apache/submarine/server/submitter/k8s/parser/ExperimentSpecParser.java
@@ -56,7 +56,7 @@ public class ExperimentSpecParser {
 
   private static SubmarineConfiguration conf =
       SubmarineConfiguration.getInstance();
-  
+
   public static MLJob parseJob(ExperimentSpec experimentSpec) throws 
InvalidSpecException {
     String framework = experimentSpec.getMeta().getFramework();
     if (ExperimentMeta.SupportedMLFramework.TENSORFLOW.
@@ -224,7 +224,7 @@ public class ExperimentSpecParser {
           String activateCommand = "echo \"source activate "
               + condaEnvironmentName + "\" > ~/.bashrc";
           String pathCommand = "PATH=/opt/conda/envs/env/bin:$PATH";
-          String finalCommand = condaVersionValidationCommand.toString() + 
+          String finalCommand = condaVersionValidationCommand.toString() +
               " && " + createCommand.toString() + " && "
               + activateCommand + " && " + pathCommand;
           initContainer.addCommandItem("/bin/bash");
@@ -274,13 +274,12 @@ public class ExperimentSpecParser {
     }
     return resources;
   }
-  
+
   private static Environment getEnvironment(ExperimentSpec experimentSpec) {
     if (experimentSpec.getEnvironment().getName() != null) {
       EnvironmentManager environmentManager = EnvironmentManager.getInstance();
-      Environment environment = environmentManager
+      return environmentManager
           .getEnvironment(experimentSpec.getEnvironment().getName());
-      return environment;
     } else {
       return null;
     }


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

Reply via email to