You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@submarine.apache.org by GitBox <gi...@apache.org> on 2020/08/12 11:43:45 UTC

[GitHub] [submarine] liuxunorg commented on a change in pull request #374: SUBMARINE-598. Support get environment list from database

liuxunorg commented on a change in pull request #374:
URL: https://github.com/apache/submarine/pull/374#discussion_r469194472



##########
File path: submarine-server/server-core/src/main/java/org/apache/submarine/server/environment/EnvironmentManager.java
##########
@@ -204,9 +204,31 @@ public Environment getEnvironment(String name)
    */
   public List<Environment> listEnvironments(String status)
       throws SubmarineRuntimeException {
-    List<Environment> environmentList =
+    List<Environment> envs =
         new ArrayList<Environment>(cachedEnvironments.values());
-    return environmentList;
+
+    if (envs.size() != 0) {
+      return envs;
+    }
+    try (SqlSession sqlSession = MyBatisUtil.getSqlSession()) {
+      EnvironmentMapper environmentMapper =
+            sqlSession.getMapper(EnvironmentMapper.class);
+      List<EnvironmentEntity> environmentEntitys = environmentMapper.selectAll();
+      for (EnvironmentEntity environmentEntity : environmentEntitys) {
+        if (environmentEntity != null) {
+          Environment env = new Environment();
+          env.setEnvironmentSpec(new Gson().fromJson(
+                environmentEntity.getEnvironmentSpec(), EnvironmentSpec.class));
+          envs.add(env);
+          cachedEnvironments.put(env.getEnvironmentSpec().getName(), env);
+        }
+      }
+    } catch (Exception e) {
+      LOG.error(e.getMessage(), e);
+      throw new SubmarineRuntimeException(Status.BAD_REQUEST.getStatusCode(),
+            "Unable to get the environment details.");

Review comment:
       Maybe it would be better to change to `Unable to get the environment list.` ?

##########
File path: submarine-server/server-core/src/main/java/org/apache/submarine/server/environment/EnvironmentManager.java
##########
@@ -204,9 +204,31 @@ public Environment getEnvironment(String name)
    */
   public List<Environment> listEnvironments(String status)
       throws SubmarineRuntimeException {
-    List<Environment> environmentList =
+    List<Environment> envs =
         new ArrayList<Environment>(cachedEnvironments.values());
-    return environmentList;
+
+    if (envs.size() != 0) {
+      return envs;

Review comment:
       If direct return envs, Will this cause `envs ` variable to never update?




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org