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 689ae3c SUBMARINE-598. Support get environment list from database
689ae3c is described below
commit 689ae3cd4f18c8b8941efb35896bed2f037b07e6
Author: kobe860219 <[email protected]>
AuthorDate: Tue Aug 18 19:33:47 2020 +0800
SUBMARINE-598. Support get environment list from database
### What is this PR for?
Improve environment swagger api.
When cache is null. Will get environment data from database.
### What type of PR is it?
[Improvement]
### Todos
### What is the Jira issue?
https://issues.apache.org/jira/browse/SUBMARINE-598
### How should this be tested?
https://travis-ci.org/github/kobe860219/submarine/builds/716904008?utm_source=github_status&utm_medium=notification
### Screenshots (if appropriate)
<img width="1358" alt="ζͺε 2020-08-16 δΈε12 11 07"
src="https://user-images.githubusercontent.com/48027290/90316540-71a3dd00-df55-11ea-9752-0eeead919962.png">
### Questions:
* Does the licenses files need update? No
* Is there breaking changes for older versions? No
* Does this needs documentation? No
Author: kobe860219 <[email protected]>
Closes #374 from kobe860219/SUBMARINE-598 and squashes the following
commits:
d4d4938 [kobe860219] SUBMARINE-598. Support get environment list from
database
8c07802 [kobe860219] SUBMARINE-598. Support get environment list from
database
e755201 [kobe860219] SUBMARINE-598. Support get environment list from
database
d535c66 [kobe860219] SUBMARINE-598. Support get environment list from
database
736c192 [kobe860219] SUBMARINE-598. Support get environment list from
database
065ef0d [kobe860219] SUBMARINE-598. Support get environment list from
database
730c0b8 [kobe860219] SUBMARINE-598. Support get environment list from
database
19920f2 [kobe860219] Edit .gitignore
9d5506c [kobe860219] Edit .gitignore
22b2bfe [kobe860219] SUBMARINE-598. Support get environment list from
database
---
.../server/environment/EnvironmentManager.java | 27 ++++++++++++++++++++++
.../database/mappers/EnvironmentMapper.java | 4 ++++
.../database/mappers/EnvironmentMapper.xml | 6 +++++
.../server/rest/EnvironmentRestApiTest.java | 4 +++-
4 files changed, 40 insertions(+), 1 deletion(-)
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 eb238a5..0721746 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
@@ -54,6 +54,8 @@ public class EnvironmentManager {
private final AtomicInteger environmentIdCounter = new AtomicInteger(0);
+ private static Boolean readedDB = true;
+
/**
* Environment Cache
*/
@@ -206,6 +208,31 @@ public class EnvironmentManager {
throws SubmarineRuntimeException {
List<Environment> environmentList =
new ArrayList<Environment>(cachedEnvironments.values());
+
+ // Is it available in cache?
+ if (this.readedDB == true) {
+ 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));
+ env.setEnvironmentId(
+ EnvironmentId.fromString(environmentEntity.getId()));
+ environmentList.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 list.");
+ }
+ }
+ this.readedDB = false;
return environmentList;
}
diff --git
a/submarine-server/server-core/src/main/java/org/apache/submarine/server/environment/database/mappers/EnvironmentMapper.java
b/submarine-server/server-core/src/main/java/org/apache/submarine/server/environment/database/mappers/EnvironmentMapper.java
index eddea32..43b1a3c 100644
---
a/submarine-server/server-core/src/main/java/org/apache/submarine/server/environment/database/mappers/EnvironmentMapper.java
+++
b/submarine-server/server-core/src/main/java/org/apache/submarine/server/environment/database/mappers/EnvironmentMapper.java
@@ -20,8 +20,12 @@ package
org.apache.submarine.server.environment.database.mappers;
import
org.apache.submarine.server.environment.database.entity.EnvironmentEntity;
+import java.util.List;
+
public interface EnvironmentMapper {
+ List<EnvironmentEntity> selectAll();
+
EnvironmentEntity select(String environmentName);
int insert(EnvironmentEntity environment);
diff --git
a/submarine-server/server-core/src/main/resources/org/apache/submarine/database/mappers/EnvironmentMapper.xml
b/submarine-server/server-core/src/main/resources/org/apache/submarine/database/mappers/EnvironmentMapper.xml
index 0efce7d..4d870b7 100644
---
a/submarine-server/server-core/src/main/resources/org/apache/submarine/database/mappers/EnvironmentMapper.xml
+++
b/submarine-server/server-core/src/main/resources/org/apache/submarine/database/mappers/EnvironmentMapper.xml
@@ -36,6 +36,12 @@
id, environment_name, environment_spec, create_by, create_time, update_by,
update_time
</sql>
+ <select id="selectAll" parameterType="java.lang.String"
resultMap="resultMap">
+ select
+ <include refid="Base_Column_List" />
+ from environment
+ </select>
+
<select id="select" parameterType="java.lang.String" resultMap="resultMap">
select
<include refid="Base_Column_List" />
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 67a3699..4f7b861 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
@@ -124,9 +124,11 @@ public class EnvironmentRestApiTest {
Response getEnvResponse = environmentStoreApi.listEnvironment("");
String entity = (String) getEnvResponse.getEntity();
JsonResponse jsonResponse = gson.fromJson(entity, JsonResponse.class);
+
+ // environments.length = 2; One is created in this test, one is get from
database
Environment[] environments = gson
.fromJson(gson.toJson(jsonResponse.getResult()), Environment[].class);
- assertEquals(1, environments.length);
+ assertEquals(2, environments.length);
Environment environment = environments[0];
assertEquals("foo", environment.getEnvironmentSpec().getName());
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]