Skip to content
This repository has been archived by the owner on Jul 10, 2024. It is now read-only.

SUBMARINE-598. Support get environment list from database #374

Closed
wants to merge 10 commits into from
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If direct return envs, Will this cause envs variable to never update?

}
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.");
pingsutw marked this conversation as resolved.
Show resolved Hide resolved
}
return envs;
}

private void checkSpec(EnvironmentSpec spec)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@

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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down