Skip to content

Commit

Permalink
!1073 add appList to profile model
Browse files Browse the repository at this point in the history
Merge pull request !1073 from 刘慧玲/master
  • Loading branch information
ChuanyuChen authored and gitee-org committed Nov 23, 2021
2 parents d42af41 + 87cbed6 commit 1711968
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ public class ProfileInfo {
@Size(max = Consts.LENGTH_255, message = "profile app deploy seq can not more than 255.")
private List<String> seq;

/**
* app list the profile contains.
*/
@Size(max = Consts.LENGTH_255, message = "profile app list can not more than 255.")
private List<String> appList;

/**
* profile create time.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
Expand Down Expand Up @@ -376,20 +377,23 @@ private void analysizeProfile(String baseFilePath, ProfileInfo profileInfo) {
profileInfo.setType((String) profile.get("type"));
profileInfo.setIndustry((String) profile.get("industry"));
profileInfo.setConfigFilePath(baseFilePath.concat(File.separator).concat((String) profile.get("config")));
String seq = (String) profile.get("seq");
profileInfo.setSeq(Arrays.asList(seq.split(",")));
String seq = null == profile.get("seq") ? null : (String) profile.get("seq");
profileInfo.setSeq(null == seq ? null : Arrays.asList(seq.split(",")));

HashMap<String, Map<String, String>> appList = (HashMap<String, Map<String, String>>) profile
HashMap<String, Map<String, String>> appInfoList = (HashMap<String, Map<String, String>>) profile
.get(FIELD_APP);
checkParamNull(appList, "there is no app field in profile file.");
checkParamNull(appInfoList, "there is no app field in profile file.");
Map<String, String> deployFilePath = new HashMap<>();
appList.keySet().stream().forEach(key -> {
List<String> appList = new ArrayList<>();
appInfoList.keySet().stream().forEach(key -> {
checkAppNameUniformity(key, profileInfo.getSeq());
Map<String, String> appInfo = appList.get(key);
Map<String, String> appInfo = appInfoList.get(key);
String deploymentFile = appInfo.get("deploymentFile");
deployFilePath.put(key, baseFilePath.concat(File.separator).concat(deploymentFile));
appList.add(key);
});
profileInfo.setDeployFilePath(deployFilePath);
profileInfo.setAppList(appList);
} catch (DomainException e) {
LOGGER.error("Yaml deserialization failed {}", e.getMessage());
throw new DomainException("Yaml deserialization failed.");
Expand All @@ -406,7 +410,7 @@ private void analysizeProfile(String baseFilePath, ProfileInfo profileInfo) {
* @param seq app deploy seq
*/
private void checkAppNameUniformity(String appName, List<String> seq) {
if (!seq.contains(appName)) {
if (null != seq && !seq.contains(appName)) {
String msg = "app seq ".concat(seq.toString()).concat(" not contains app name: ").concat(appName);
LOGGER.error(msg);
throw new IllegalRequestException(msg, ResponseConsts.RET_REQUEST_PARAM_ERROR);
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/developerdb.sql
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,8 @@
"file_path" varchar(255) NOT NULL,
"deploy_file_path" TEXT NOT NULL,
"config_file_path" varchar(255) DEFAULT NULL,
"seq" varchar(255) NOT NULL,
"seq" varchar(255) DEFAULT NULL,
"app_list" varchar(255) NOT NULL,
"create_time" timestamptz(6) NOT NULL,
"type" varchar(255) NOT NULL,
"industry" varchar(255) NOT NULL,
Expand Down
8 changes: 6 additions & 2 deletions src/main/resources/mapper/ProfileMapper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
<result property="configFilePath" column="config_file_path"/>
<result property="seq" column="seq"
typeHandler="org.edgegallery.developer.model.handler.JsonCollectionTypeHandler"/>
<result property="appList" column="app_list"
typeHandler="org.edgegallery.developer.model.handler.JsonCollectionTypeHandler"/>
<result property="createTime" column="create_time"/>
<result property="type" column="type"/>
<result property="industry" column="industry"/>
Expand All @@ -36,17 +38,18 @@

<sql id="AllColumn">
id, name, description, description_en,
file_path, deploy_file_path, config_file_path, seq, create_time,type, industry, topo_file_path
file_path, deploy_file_path, config_file_path, seq, app_list, create_time,type, industry, topo_file_path
</sql>

<insert id="createProfile" parameterType="org.edgegallery.developer.model.profile.ProfileInfo">
insert into tbl_profile (id, name, description, description_en,
file_path, deploy_file_path, config_file_path, seq, create_time,type, industry, topo_file_path)
file_path, deploy_file_path, config_file_path, seq, app_list, create_time,type, industry, topo_file_path)
values
(#{id}, #{name}, #{description}, #{descriptionEn}, #{filePath},
#{deployFilePath, jdbcType=OTHER, typeHandler=org.edgegallery.developer.model.handler.JsonTypeHandler},
#{configFilePath},
#{seq, jdbcType=OTHER, typeHandler=org.edgegallery.developer.model.handler.JsonCollectionTypeHandler},
#{appList, jdbcType=OTHER, typeHandler=org.edgegallery.developer.model.handler.JsonCollectionTypeHandler},
#{createTime}, #{type}, #{industry}, #{topoFilePath})
</insert>

Expand All @@ -66,6 +69,7 @@
#{deployFilePath, jdbcType=OTHER, typeHandler=org.edgegallery.developer.model.handler.JsonTypeHandler},
config_file_path = #{configFilePath},
seq = #{seq, jdbcType=OTHER, typeHandler=org.edgegallery.developer.model.handler.JsonCollectionTypeHandler},
app_list = #{appList, jdbcType=OTHER, typeHandler=org.edgegallery.developer.model.handler.JsonCollectionTypeHandler},
type = #{type}, industry = #{industry}, topo_file_path = #{topoFilePath}
WHERE
id = #{id}
Expand Down
3 changes: 2 additions & 1 deletion src/test/resources/mec-test.sql
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,8 @@ CREATE TABLE IF NOT EXISTS tbl_vm_regulation (
file_path varchar(255) NOT NULL,
deploy_file_path TEXT NOT NULL,
config_file_path varchar(255) DEFAULT NULL,
seq varchar(255) NOT NULL,
seq varchar(255) DEFAULT NULL,
app_list varchar(255) NOT NULL,
create_time varchar(255) NOT NULL,
type varchar(255) NOT NULL,
industry varchar(255) NOT NULL,
Expand Down

0 comments on commit 1711968

Please sign in to comment.