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 @@ -197,15 +197,33 @@ public Environment getEnvironment(String name)
}

/**
* List environments
* @param status environment status, if null will return all status
* List all environments from database
* @return environment list
* @throws SubmarineRuntimeException the service error
*/
public List<Environment> listEnvironments(String status)
throws SubmarineRuntimeException {
List<Environment> environmentList =
new ArrayList<Environment>(cachedEnvironments.values());
new ArrayList<Environment>();

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));
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.");
}
return environmentList;
}

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 @@ -137,10 +137,11 @@ public Response deleteEnvironment(
}

/**
* List all environments.
* List all environments from database.
* @return environment list
*/
@GET
@Path("/list")
@Operation(summary = "List of Environments",
tags = {"environments"},
responses = {
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