Skip to content

Commit

Permalink
Merge pull request #383 from WeBankPartners/296_AppDeployment_query_fix
Browse files Browse the repository at this point in the history
#296 Fixed application deployment design query exceptions
  • Loading branch information
jordanzhangsz authored Nov 6, 2019
2 parents a70133e + 3626496 commit eaf0169
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class UIProperties {
private Integer ciTypeIdOfUnitDesign = 3;
private Integer ciTypeIdOfUnit = 8;
private Integer ciTypeIdOfSubsys = 7;
private String ciTypeCodeOfSubsys = "subsys";
private Integer ciTypeIdOfHost = 12;
private Integer ciTypeIdOfInstance = 15;
private Integer ciTypeIdOfIdc = 16;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.CaseFormat;
import com.google.common.collect.Lists;
import com.webank.cmdb.config.ApplicationProperties.UIProperties;
import com.webank.cmdb.constant.CmdbConstants;
Expand Down Expand Up @@ -95,7 +96,7 @@ public class UIWrapperService {
private FilterRuleService filterRuleService;
@Autowired
private BaseKeyInfoService baseKeyInfoService;

public void swapCiTypeLayerPosition(int layerId, int targetLayerId) {
CatCodeDto enumCode = getEnumCodeById(layerId);
CatCodeDto targetEnumCode = getEnumCodeById(targetLayerId);
Expand Down Expand Up @@ -218,13 +219,14 @@ private int getMaxLayerSeqNumber() {
}

public List<CatCodeDto> createEnumCodes(CatCodeDto catCode) {

if (catCode == null || catCode.getCatId().equals(0)) {
throw new CmdbException("Category Id is required");
}
if (catCode.getCatId().equals(getLayerCategoryId())) {
catCode.setSeqNo(getMaxLayerSeqNumber() + 1);
}

if (catCode.getGroupCodeId() != null && !(catCode.getGroupCodeId() instanceof Integer)) {
catCode.setGroupCodeId(null);
}
Expand Down Expand Up @@ -1087,6 +1089,7 @@ private List<Map<String, Object>> getAllCiDataOfRootCi(int rootCiTypeId, int env
QueryRequest queryRequest = new QueryRequest();
List<Filter> filters = new ArrayList<Filter>();
String enumPorpertyNameOfEnv = getEnumPropertyNameByCiTypeId(rootCiTypeId, envEnumCat);

if (envEnumCode != null && enumPorpertyNameOfEnv != null) {
Filter rootCifilter = new Filter("root$" + enumPorpertyNameOfEnv, "eq", getEnumCodeIdByCode(envEnumCat, envEnumCode));
filters.add(rootCifilter);
Expand Down Expand Up @@ -1116,8 +1119,8 @@ private List<Map<String, Object>> getAllCiDataOfRootCi(int rootCiTypeId, int env

rootDto.setCriteria(rootNode);
rootDto.setQueryRequest(queryRequest);

IntegrationQueryDto childQueryDto = travelRoutine(routineItems, filterCiTypeId, rootDto, 1);
IntegrationQueryDto childQueryDto = travelRoutine(routineItems, filterCiTypeId, rootDto, 1, "", envEnumCat, envEnumCode);
if (childQueryDto != null) {
rootDto.getCriteria().setChildren(Arrays.asList(childQueryDto));
}
Expand Down Expand Up @@ -1157,12 +1160,12 @@ private Integer getAttrIdByCiTypeId(int ciTypeId, String PropertyName) {
return null;
}

private IntegrationQueryDto travelRoutine(List<CiRoutineItem> routines, int filterCiTypeId, AdhocIntegrationQueryDto rootDto, int position) {
private IntegrationQueryDto travelRoutine(List<CiRoutineItem> routines, int filterCiTypeId, AdhocIntegrationQueryDto rootDto, int position, String key, int envEnumCat, String envEnumCode) {
if (position >= routines.size()) {
return null;
}

CiRoutineItem item = routines.get(position);

IntegrationQueryDto dto = new IntegrationQueryDto();
dto.setName("index-" + position);
dto.setCiTypeId(item.getCiTypeId());
Expand All @@ -1172,7 +1175,25 @@ private IntegrationQueryDto travelRoutine(List<CiRoutineItem> routines, int filt
parentRs.setIsReferedFromParent(item.getParentRs().getIsReferedFromParent() == 1);
dto.setParentRs(parentRs);

IntegrationQueryDto childDto = travelRoutine(routines, filterCiTypeId, rootDto, ++position);
AdmCiType ciType = staticEntityRepository.findEntityById(AdmCiType.class, item.getCiTypeId());
String tableName=CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, ciType.getTableName());
key = key+"-"+tableName;
String enumPorpertyNameOfEnv = getEnumPropertyNameByCiTypeId(item.getCiTypeId(), envEnumCat);
if (envEnumCode != null && enumPorpertyNameOfEnv != null) {
List<Integer> attrs = new ArrayList<Integer>();
List<String> attrKeyNames = new ArrayList<String>();
if (key.startsWith("-"))
key = key.substring(1);
Filter cifilter = new Filter(key + "." + enumPorpertyNameOfEnv, "eq",
getEnumCodeIdByCode(envEnumCat, envEnumCode));

rootDto.getQueryRequest().getFilters().add(cifilter);
attrs.add(getAttrIdByCiTypeId(item.getCiTypeId(), enumPorpertyNameOfEnv));
attrKeyNames.add(key + "." + enumPorpertyNameOfEnv);
dto.setAttrs(attrs);
dto.setAttrKeyNames(attrKeyNames);
}
IntegrationQueryDto childDto = travelRoutine(routines, filterCiTypeId, rootDto, ++position, "",envEnumCat,envEnumCode);
if (childDto == null) {
if (filterCiTypeId != item.getCiTypeId()) {
log.error("routine tail ciType not right!!!");
Expand Down Expand Up @@ -1297,7 +1318,13 @@ public List<ResourceTreeDto> getApplicationDeploymentDesignDataTreeBySystemDesig

private void getBottomChildrenDataByBottomCiTypeId(Integer ciTypeId, Integer bottomCiTypeId, List<ResourceTreeDto> bottomChildrenData, List<Integer> limitedCiTypeIds, Map<String, Object> inputFilters,
Map<String, Object> subsystemFilters) {
List<CiData> ciDatas = queryCiData(ciTypeId, buildQueryObjectWithEqualsFilter(inputFilters)).getContents();
QueryRequest buildQueryObjectWithEqualsFilter = buildQueryObjectWithEqualsFilter(inputFilters);
AdmCiType admCiType = staticEntityRepository.findEntityById(AdmCiType.class,
ciTypeId);
if (uiProperties.getCiTypeCodeOfSubsys().equals(admCiType.getTableName())) {
buildQueryObjectWithEqualsFilter = buildQueryObjectWithEqualsFilter.addEqualsFilters(subsystemFilters);
}
List<CiData> ciDatas = queryCiData(ciTypeId, buildQueryObjectWithEqualsFilter).getContents();
if (ciTypeId.equals(bottomCiTypeId)) {
for (CiData ciData : ciDatas) {
ResourceTreeDto ci = buildNewResourceTreeDto(ciData, ciTypeId);
Expand All @@ -1310,13 +1337,13 @@ private void getBottomChildrenDataByBottomCiTypeId(Integer ciTypeId, Integer bot
for (CiData ciData : ciDatas) {
Map<String, Object> ciDataMap = ciData.getData();
List<CiTypeAttrDto> childrenCiTypeRelativeAttributes = findChildrenCiTypeRelativeAttributes(ciTypeId, uiProperties.getReferenceCodeOfBelong());
if (childrenCiTypeRelativeAttributes.size() != 0) {
if (childrenCiTypeRelativeAttributes.size() != 0 && ciDataMap.get("guid") != null) {
findBelongCi = getBottomChildrenDataByRelativeAttributes(childrenCiTypeRelativeAttributes, limitedCiTypeIds, ciDataMap.get("guid").toString(), bottomChildrenData, bottomCiTypeId, subsystemFilters);
}

if (!findBelongCi) {
List<CiTypeAttrDto> realizeCiTypeRelativeAttributes = findRealizeCiAttributesByCiTypeId(ciTypeId);
if (realizeCiTypeRelativeAttributes.size() != 0) {
if (realizeCiTypeRelativeAttributes.size() != 0 && ciDataMap.get("guid") != null) {
getBottomChildrenDataByRealizeAttributes(realizeCiTypeRelativeAttributes, limitedCiTypeIds, ciDataMap.get("guid").toString(), bottomChildrenData, bottomCiTypeId, subsystemFilters);
}
}
Expand Down Expand Up @@ -1383,7 +1410,7 @@ private List<ResourceTreeDto> groupByAttr(List<ResourceTreeDto> toBeGroupData, C
boolean continueFlag = false;
Map ciMap = (Map) singleData.getData();
Object relateCiTypeDto = ciMap.get(relateCiAttrDto.getPropertyName());
if (relateCiTypeDto == null) {
if (relateCiTypeDto == null||"".equals(relateCiTypeDto)) {
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1623,7 +1623,7 @@ private Map<String, FieldInfo> buildIntQuery(From parentPath, AdmCiType parentCi
}else if(InputType.MultRef.getCode().equals(attr.getInputType())){
attrExpression = curFrom.get("guid");//need guid to fetch mult ref value
}else {
attrExpression = curFrom.get(attr.getPropertyName());
attrExpression = curFrom.get(attr.getPropertyName());
}
attrExpression.alias(keyName);
if (attrExprMap.containsKey(keyName)) {
Expand Down Expand Up @@ -1677,7 +1677,7 @@ private Map<String, FieldInfo> buildIntQuery(From parentPath, AdmCiType parentCi

attachAdditionalAttr(attrExprMap, path, curCiTypeId, curFrom, "guid");
attachAdditionalAttr(attrExprMap, path, curCiTypeId, curFrom, "r_guid");

if (enableBiz) {
attachAdditionalAttr(attrExprMap, path, curCiTypeId, curFrom, "biz_key");
attachAdditionalAttr(attrExprMap, path, curCiTypeId, curFrom, "state");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
package com.webank.cmdb.controller.ui;

import static com.webank.cmdb.domain.AdmMenu.MENU_DESIGNING_CI_DATA_MANAGEMENT;
import static com.webank.cmdb.domain.AdmMenu.MENU_APPLICATION_DEPLOYMENT_DESIGN;
import static com.webank.cmdb.domain.AdmMenu.ROLE_PREFIX;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.empty;

import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;

Expand All @@ -19,11 +25,12 @@
import com.webank.cmdb.controller.AbstractBaseControllerTest;
import com.webank.cmdb.util.JsonUtil;

@WithMockUser(username = "test", authorities = { ROLE_PREFIX + MENU_DESIGNING_CI_DATA_MANAGEMENT })
@WithMockUser(username = "test", authorities = { ROLE_PREFIX + MENU_DESIGNING_CI_DATA_MANAGEMENT ,ROLE_PREFIX + MENU_APPLICATION_DEPLOYMENT_DESIGN })
public class UICiDataManagementControllerTest extends AbstractBaseControllerTest {

private static final int SYSTEM_DESIGN = 1;
private static final int SUB_SYSTEM_DESIGN = 2;
private static final int ciTypeId = 3;

@Test
public void whenDeleteCiWithDependencyCiAtFinalStateShouldSuccess() throws Exception {
Expand Down Expand Up @@ -83,4 +90,38 @@ public void whenDeleteCiWithDependencyCiAtFinalStateShouldSuccess() throws Excep
.andExpect(jsonPath("$.statusCode", is("OK")));

}

@Test
public void deploymentDesignQuery() throws Exception {

mvc.perform(post("/ui/v2/deploy-designs/tabs/ci-data?code-id=102&env-code=STGk&system-design-guid=0001_0000000004")
.contentType(MediaType.APPLICATION_JSON)
.content("{}"))
.andExpect(jsonPath("$.statusCode", is("OK")));

mvc.perform(post("/ui/v2/deploy-designs/tabs/ci-data?code-id=102&env-code=PRD&system-design-guid=0001_0000000004")
.contentType(MediaType.APPLICATION_JSON)
.content("{}"))
.andExpect(jsonPath("$.statusCode", is("OK")));
}

@Test
public void physicalDeploymentDesignQuery() throws Exception {
Integer envCode_stgk=113;
Integer envCode_prd=111;
String systemDesignGuid="0001_0000000004";
mvc.perform(get("/ui/v2/data-tree/application-deployment-design?env-code={env-code}&system-design-guid={system-design-guid}"
, envCode_stgk,systemDesignGuid)
.contentType(MediaType.APPLICATION_JSON)
.content("{}"))
.andExpect(jsonPath("$.statusCode", is("OK")));

mvc.perform(get("/ui/v2/data-tree/application-deployment-design?env-code={env-code}&system-design-guid={system-design-guid}"
, envCode_prd,systemDesignGuid)
.contentType(MediaType.APPLICATION_JSON)
.content("{}"))
.andExpect(jsonPath("$.statusCode", is("OK")));
}


}

0 comments on commit eaf0169

Please sign in to comment.