diff options
4 files changed, 82 insertions, 39 deletions
diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloudify/utils/MsoCloudifyUtils.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloudify/utils/MsoCloudifyUtils.java index ad2543032f..d7bc22aa7c 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloudify/utils/MsoCloudifyUtils.java +++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloudify/utils/MsoCloudifyUtils.java @@ -755,16 +755,19 @@ public class MsoCloudifyUtils extends MsoCommonUtils implements VduPlugin { GetBlueprint getRequest = cloudify.blueprints().getMetadataById(blueprintId); try { Blueprint bp = getRequest.execute(); - logger.debug("Blueprint exists: {}", bp.getId()); - return true; + if (bp != null) { + logger.debug("Blueprint exists: {}", bp.getId()); + return true; + } else { + logger.debug("Null blueprint!"); + return false; + } } catch (CloudifyResponseException ce) { if (ce.getStatus() == 404) { return false; } else { throw ce; } - } catch (Exception e) { - throw e; } } @@ -803,8 +806,12 @@ public class MsoCloudifyUtils extends MsoCommonUtils implements VduPlugin { GetBlueprint getRequest = cloudify.blueprints().getMetadataById(blueprintId); try { Blueprint bp = getRequest.execute(); - logger.debug("Blueprint {} already exists.", bp.getId()); - return false; + if (bp != null) { + logger.debug("Blueprint {} already exists.", bp.getId()); + return false; + } else { + logger.debug("Null blueprint!"); + } } catch (CloudifyResponseException ce) { if (ce.getStatus() == 404) { // This is the expected result. @@ -812,8 +819,6 @@ public class MsoCloudifyUtils extends MsoCommonUtils implements VduPlugin { } else { throw ce; } - } catch (Exception e) { - throw e; } // Create a blueprint ZIP file in memory diff --git a/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/common/BPMNUtil.java b/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/common/BPMNUtil.java index a94713e9e0..7a50e5f9d3 100644 --- a/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/common/BPMNUtil.java +++ b/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/common/BPMNUtil.java @@ -155,24 +155,11 @@ public class BPMNUtil { } } - private static String getProcessInstanceId(HistoryService historyService, String processDefinitionID) { - List<HistoricProcessInstance> historyList = historyService.createHistoricProcessInstanceQuery().list(); - String pID = null; - for (HistoricProcessInstance hInstance : historyList) { - if (hInstance.getProcessDefinitionKey().equals(processDefinitionID)) { - pID = hInstance.getId(); - break; - } - } - return pID; - } - public static boolean isProcessInstanceFinished(ProcessEngineServices processEngineServices, String pid) { return processEngineServices.getHistoryService().createHistoricProcessInstanceQuery().processInstanceId(pid) .finished().count() == 1 ? true : false; } - private static void buildVariable(String key, String value, Map<String, Object> variableValueType) { Map<String, Object> host = new HashMap<>(); host.put("value", value); diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/ConfigAssignVnf.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/ConfigAssignVnf.java index 9413e8ef2e..e73a504291 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/ConfigAssignVnf.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/ConfigAssignVnf.java @@ -124,12 +124,14 @@ public class ConfigAssignVnf { private Service getServiceFromRequestUserParams(List<Map<String, Object>> userParams) throws Exception { Map<String, Object> serviceMap = userParams.stream().filter(key -> key.containsKey("service")).findFirst() .orElseThrow(() -> new Exception("Can not find service in userParams section in generalBuildingBlock")); - return convertServiceFromJsonToServiceObject((String) serviceMap.get("service")); + return getServiceObjectFromServiceMap(serviceMap); } - private Service convertServiceFromJsonToServiceObject(String serviceFromJson) throws Exception { + private Service getServiceObjectFromServiceMap(Map<String, Object> serviceMap) throws Exception { + ObjectMapper objectMapper = new ObjectMapper(); + String serviceFromJson = objectMapper.writeValueAsString(serviceMap.get("service")); try { - return new ObjectMapper().readValue(serviceFromJson, Service.class); + return objectMapper.readValue(serviceFromJson, Service.class); } catch (Exception e) { logger.error(String.format( "An exception occurred while converting json object to Service object. The json is: %s", @@ -150,5 +152,4 @@ public class ConfigAssignVnf { genericVnfModelCustomizationUuid)); } } - } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/ConfigAssignVnfTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/ConfigAssignVnfTest.java index 468bc7d8f6..bbc20706a6 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/ConfigAssignVnfTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/ConfigAssignVnfTest.java @@ -47,23 +47,32 @@ import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoServiceInstance; import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB; import org.onap.so.client.cds.beans.AbstractCDSPropertiesBean; import org.onap.so.client.exception.ExceptionBuilder; +import org.onap.so.serviceinstancebeans.ModelInfo; +import org.onap.so.serviceinstancebeans.Resources; +import org.onap.so.serviceinstancebeans.Service; +import org.onap.so.serviceinstancebeans.Vnfs; public class ConfigAssignVnfTest { private static final String GENERIC_VNF_ID = "vnfId_configVnfTest"; private static final String GENERIC_VNF_NAME = "vnfName_configVnfTest"; - private static final String VNF_MODEL_CUSTOMIZATION_UUID = "0c1ac643-377e-475b-be50-6be65f91a7ad"; + private static final String VNF_MODEL_CUSTOMIZATION_ID = "0c1ac643-377e-475b-be50-6be65f91a7ad"; private static final String SERVICE_INSTANCE_ID = "serviceInst_configTest"; private static final String SERVICE_MODEL_UUID = "5af91c26-8418-4d3f-944c-965842deda94"; private static final String TARGET_VNF_MODEL_CUSTOMIZATION_UUID = "0c1ac643-377e-475b-be50-6be65f91a7ad"; private static final String GENERAL_BLOCK_EXECUTION_MAP_KEY = "gBBInput"; private static final int THE_NUMBER_OF_EXPECTED_CONFIG_PROPERTIES = 8; - private static final String USER_PARAMS_FROM_REQUEST = "{\"resources\":{\"vnfs\":[" - + "{\"modelInfo\":{\"modelCustomizationId\":\"" + VNF_MODEL_CUSTOMIZATION_UUID + "\"}," - + "\"instanceParams\":[{\"paramName1\":\"paramValue1\",\"paramName2\":\"paramValue2\"},{\"paramName3\":\"paramValue3\"}]}," - + "{\"modelInfo\":{\"modelCustomizationId\":\"2d1ac656-377e-467b-be50-6ce65f66a7ca\"}," - + "\"instanceParams\":[{\"parName4\":\"parValue4\",\"parName5\":\"parValue5\"}]}]}}\n"; + private static final String INSTANCE_PARAM1_NAME = "paramName1"; + private static final String INSTANCE_PARAM1_VALUE = "paramValue1"; + private static final String INSTANCE_PARAM2_NAME = "paramName2"; + private static final String INSTANCE_PARAM2_VALUE = "paramValue2"; + private static final String INSTANCE_PARAM3_NAME = "paramName3"; + private static final String INSTANCE_PARAM3_VALUE = "paramValue3"; + private static final String INSTANCE_PARAM4_NAME = "paramName4"; + private static final String INSTANCE_PARAM4_VALUE = "paramValue4"; + private static final String INSTANCE_PARAM5_NAME = "paramName5"; + private static final String INSTANCE_PARAM5_VALUE = "paramValue5"; private ConfigAssignVnf testedObject; @@ -103,13 +112,13 @@ public class ConfigAssignVnfTest { assertThat(configAssignPropertiesNode.get("vnf-name").asText()).isEqualTo(GENERIC_VNF_NAME); assertThat(configAssignPropertiesNode.get("service-model-uuid").asText()).isEqualTo(SERVICE_MODEL_UUID); assertThat(configAssignPropertiesNode.get("vnf-customization-uuid").asText()) - .isEqualTo(VNF_MODEL_CUSTOMIZATION_UUID); - assertThat(configAssignPropertiesNode.has("paramName1")).isTrue(); - assertThat(configAssignPropertiesNode.get("paramName1").asText()).isEqualTo("paramValue1"); - assertThat(configAssignPropertiesNode.has("paramName2")).isTrue(); - assertThat(configAssignPropertiesNode.get("paramName2").asText()).isEqualTo("paramValue2"); - assertThat(configAssignPropertiesNode.has("paramName3")).isTrue(); - assertThat(configAssignPropertiesNode.get("paramName3").asText()).isEqualTo("paramValue3"); + .isEqualTo(VNF_MODEL_CUSTOMIZATION_ID); + assertThat(configAssignPropertiesNode.has(INSTANCE_PARAM1_NAME)).isTrue(); + assertThat(configAssignPropertiesNode.get(INSTANCE_PARAM1_NAME).asText()).isEqualTo(INSTANCE_PARAM1_VALUE); + assertThat(configAssignPropertiesNode.has(INSTANCE_PARAM2_NAME)).isTrue(); + assertThat(configAssignPropertiesNode.get(INSTANCE_PARAM2_NAME).asText()).isEqualTo(INSTANCE_PARAM2_VALUE); + assertThat(configAssignPropertiesNode.has(INSTANCE_PARAM3_NAME)).isTrue(); + assertThat(configAssignPropertiesNode.get(INSTANCE_PARAM3_NAME).asText()).isEqualTo(INSTANCE_PARAM3_VALUE); } private BuildingBlockExecution createBuildingBlockExecution() { @@ -152,8 +161,49 @@ public class ConfigAssignVnfTest { private List<Map<String, Object>> createRequestUserParams() { List<Map<String, Object>> userParams = new ArrayList<>(); Map<String, Object> userParamMap = new HashMap<>(); - userParamMap.put("service", USER_PARAMS_FROM_REQUEST); + userParamMap.put("service", createService()); userParams.add(userParamMap); return userParams; } + + private Service createService() { + Service service = new Service(); + Resources resources = new Resources(); + resources.setVnfs(createVnfList()); + service.setResources(resources); + return service; + } + + private List<Vnfs> createVnfList() { + List<Map<String, String>> instanceParamsListSearchedVnf = new ArrayList<>(); + Map<String, String> instanceParam = new HashMap<>(); + instanceParam.put(INSTANCE_PARAM1_NAME, INSTANCE_PARAM1_VALUE); + instanceParam.put(INSTANCE_PARAM2_NAME, INSTANCE_PARAM2_VALUE); + Map<String, String> instanceParam2 = new HashMap<>(); + instanceParam2.put(INSTANCE_PARAM3_NAME, INSTANCE_PARAM3_VALUE); + instanceParamsListSearchedVnf.add(instanceParam); + instanceParamsListSearchedVnf.add(instanceParam2); + Vnfs searchedVnf = createVnf(VNF_MODEL_CUSTOMIZATION_ID, instanceParamsListSearchedVnf); + + List<Map<String, String>> instanceParamsListForAnotherVnf = new ArrayList<>(); + Map<String, String> instanceParam3 = new HashMap<>(); + instanceParam3.put(INSTANCE_PARAM4_NAME, INSTANCE_PARAM4_VALUE); + instanceParam3.put(INSTANCE_PARAM5_NAME, INSTANCE_PARAM5_VALUE); + instanceParamsListForAnotherVnf.add(instanceParam3); + Vnfs anotherVnf = createVnf("2d1ac656-377e-467b-be50-6ce65f66a7ca", instanceParamsListForAnotherVnf); + + List<Vnfs> vnfList = new ArrayList<>(); + vnfList.add(searchedVnf); + vnfList.add(anotherVnf); + return vnfList; + } + + private Vnfs createVnf(String vnfModelCustomizationId, List<Map<String, String>> instanceParamsList) { + Vnfs vnf = new Vnfs(); + ModelInfo modelInfo = new ModelInfo(); + modelInfo.setModelCustomizationId(vnfModelCustomizationId); + vnf.setModelInfo(modelInfo); + vnf.setInstanceParams(instanceParamsList); + return vnf; + } } |