summaryrefslogtreecommitdiffstats
path: root/bpmn/MSOCommonBPMN/src
diff options
context:
space:
mode:
Diffstat (limited to 'bpmn/MSOCommonBPMN/src')
-rw-r--r--bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/resource/ResourceRequestBuilder.java227
-rw-r--r--bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/common/resource/ResourceRequestBuilderTest.java406
2 files changed, 487 insertions, 146 deletions
diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/resource/ResourceRequestBuilder.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/resource/ResourceRequestBuilder.java
index 5e05637bca..7259c56b6c 100644
--- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/resource/ResourceRequestBuilder.java
+++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/resource/ResourceRequestBuilder.java
@@ -22,12 +22,16 @@ package org.onap.so.bpmn.common.resource;
import java.io.File;
import java.io.IOException;
+import java.lang.reflect.Type;
+import java.net.MalformedURLException;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
+import java.util.logging.Logger;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriBuilder;
@@ -60,86 +64,35 @@ import com.google.gson.reflect.TypeToken;
public class ResourceRequestBuilder {
- private static String CUSTOMIZATION_UUID = "customizationUUID";
+ private static String CUSTOMIZATION_UUID = "cuserviceResourcesstomizationUUID";
private static String SERVICE_URL_TOSCA_CSAR = "/v3/serviceToscaCsar";
+ private static String SERVICE_URL_SERVICE_INSTANCE = "/v3/serviceResources";
private static MsoLogger LOGGER = MsoLogger.getMsoLogger(MsoLogger.Catalog.RA, ResourceRequestBuilder.class);
static JsonUtils jsonUtil = new JsonUtils();
- public static List<String> getResourceSequence(Execution execution, String serviceUuid) {
- List<String> resouceSequence = new ArrayList<String>();
- List<NodeTemplate> resultList = new ArrayList<NodeTemplate>();
- String csarpath = null;
- try {
- csarpath = getCsarFromUuid(serviceUuid);
-
- SdcToscaParserFactory toscaParser = SdcToscaParserFactory.getInstance();
- ISdcCsarHelper iSdcCsarHelper = toscaParser.getSdcCsarHelper(csarpath, false);
- List<NodeTemplate> nodeTemplates = iSdcCsarHelper.getServiceNodeTemplates();
- List<NodeTemplate> nodes = new ArrayList<NodeTemplate>();
- nodes.addAll(nodeTemplates);
-
- for (NodeTemplate nodeTemplate : nodeTemplates) {
- RequirementAssignments requirement = iSdcCsarHelper.getRequirementsOf(nodeTemplate);
-
- if (requirement == null || requirement.getAll() == null || requirement.getAll().isEmpty()) {
- resultList.add(nodeTemplate);
- nodes.remove(nodeTemplate);
- }
- }
-
- resultList = getRequirementList(resultList, nodes, iSdcCsarHelper);
-
- for (NodeTemplate node : resultList) {
- String templateName = node.getMetaData().getValue("name");
- if (!resouceSequence.contains(templateName)) {
- resouceSequence.add(templateName);
- }
- }
-
- } catch (SdcToscaParserException toscarParserE) {
- LOGGER.debug("sdc tosca parser failed for csar: " + csarpath, toscarParserE);
- return resouceSequence;
- } catch (Exception e) {
- LOGGER.debug("csar file is not available for service uuid:" + serviceUuid, e);
- return resouceSequence;
- }
-
- return resouceSequence;
- }
+ public static List<String> getResourceSequence(String serviceUuid) {
+
+ List<String> resourceSequence = new ArrayList();
+ try {
+ Map<String, Object> serviceResponse = getServiceInstnace(serviceUuid);
+
+ if (serviceResponse.containsKey("serviceResources")) {
+ Map<String, Object> serviceResources = (Map<String, Object>) serviceResponse.get("serviceResources");
- private static List<NodeTemplate> getRequirementList(List<NodeTemplate> resultList, List<NodeTemplate> nodeTemplates,
- ISdcCsarHelper iSdcCsarHelper) {
-
- List<NodeTemplate> nodes = new ArrayList<NodeTemplate>();
- nodes.addAll(nodeTemplates);
-
- for (NodeTemplate nodeTemplate : nodeTemplates) {
- RequirementAssignments requirement = iSdcCsarHelper.getRequirementsOf(nodeTemplate);
- List<RequirementAssignment> reqAs = requirement.getAll();
- for (RequirementAssignment ra : reqAs) {
- String reqNode = ra.getNodeTemplateName();
- for (NodeTemplate rNode : resultList) {
- if (rNode.getName().equals(reqNode)) {
- if(!resultList.contains(nodeTemplate)) {
- resultList.add(nodeTemplate);
- }
- if(nodes.contains(nodeTemplate)) {
- nodes.remove(nodeTemplate);
- }
- break;
- }
- }
- }
- }
-
- if (!nodes.isEmpty()) {
- getRequirementList(resultList, nodes, iSdcCsarHelper);
- }
-
- return resultList;
+ if (serviceResources.containsKey("resourceOrder")) {
+ String resourceOrder = (String) serviceResources.get("resourceOrder");
+ if (resourceOrder!= null) {
+ resourceSequence.addAll(Arrays.asList(resourceOrder.split(",")));
+ }
+ }
+ }
+ } catch (Exception e) {
+ LOGGER.error("not able to retrieve service order.");
+ }
+ return resourceSequence;
}
/* build the resource Parameters detail.
@@ -186,12 +139,8 @@ public class ResourceRequestBuilder {
resourceInputsFromUuiMap = new HashMap();
}
- try {
- Map<String, Object> resourceInputsFromServiceDeclaredLevel = buildResouceRequest(serviceUuid, resourceCustomizationUuid, serviceInput);
- resourceInputsFromUuiMap.putAll(resourceInputsFromServiceDeclaredLevel);
- } catch(SdcToscaParserException e) {
- LOGGER.error("SdcToscaParserException", e);
- }
+ Map<String, Object> resourceInputsFromServiceDeclaredLevel = buildResouceRequest(serviceUuid, resourceCustomizationUuid, serviceInput);
+ resourceInputsFromUuiMap.putAll(resourceInputsFromServiceDeclaredLevel);
String resourceInputsStr = getJsonString(resourceInputsFromUuiMap);
String result = "{\n"
+ "\"locationConstraints\":" + locationConstraints +",\n"
@@ -200,74 +149,82 @@ public class ResourceRequestBuilder {
return result;
}
- public static Map<String, Object> buildResouceRequest(String serviceUuid, String resourceCustomizationUuid, Map<String, Object> serviceInputs)
- throws SdcToscaParserException {
+ @SuppressWarnings("unchecked")
+ public static Map<String, Object> buildResouceRequest(String serviceUuid, String resourceCustomizationUuid, Map<String, Object> serviceInputs) {
+ try {
+ Map<String, Object> serviceInstnace = getServiceInstnace(serviceUuid);
- Map<String, Object> resouceRequest = new HashMap<>();
+ // find match of customization uuid in vnf
+ Map<String, Map<String, Object>> serviceResources = (Map<String, Map<String, Object>>) serviceInstnace.get("serviceResources");
- String csarpath = null;
- try {
- csarpath = getCsarFromUuid(serviceUuid);
- } catch(Exception e) {
- LOGGER.debug("csar file is not available for service uuid:" + serviceUuid, e);
- return resouceRequest;
- }
+ List<Map<String, Object>> serviceVnfCust = (List<Map<String, Object>>) serviceResources.get("serviceVnfs");
+ String resourceInputStr = getResourceInputStr(serviceVnfCust, resourceCustomizationUuid);
- SdcToscaParserFactory toscaParser = SdcToscaParserFactory.getInstance();
- ISdcCsarHelper iSdcCsarHelper = toscaParser.getSdcCsarHelper(csarpath, false);
+ // find match in network resource
+ if (resourceInputStr == null) {
+ List<Map<String, Object>> serviceNetworkCust = (List<Map<String, Object>>) serviceResources.get("serviceNetworks");
+ resourceInputStr = getResourceInputStr(serviceNetworkCust, resourceCustomizationUuid);
- List<Input> serInput = iSdcCsarHelper.getServiceInputs();
- Optional<NodeTemplate> nodeTemplateOpt = iSdcCsarHelper.getServiceNodeTemplates().stream()
- .filter(e -> e.getMetaData().getValue(CUSTOMIZATION_UUID).equals(resourceCustomizationUuid)).findFirst();
+ // find match in AR resource
+ if (resourceInputStr == null) {
+ List<Map<String, Object>> serviceArCust = (List<Map<String, Object>>) serviceResources.get("serviceAllottedResources");
+ resourceInputStr = getResourceInputStr(serviceArCust, resourceCustomizationUuid);
+ }
+ }
- if(nodeTemplateOpt.isPresent()) {
- NodeTemplate nodeTemplate = nodeTemplateOpt.get();
- LinkedHashMap<String, Property> resourceProperties = nodeTemplate.getProperties();
+ if (resourceInputStr != null || !resourceInputStr.equals("")) {
+ return getResourceInput(resourceInputStr, serviceInputs);
+ }
- for(String key : resourceProperties.keySet()) {
- Property property = resourceProperties.get(key);
+ } catch (Exception e) {
+ LOGGER.error("not able to retrieve service instance");
+ }
+ return new HashMap();
+ }
- Object value = getValue(property.getValue(), serviceInputs, serInput);
- resouceRequest.put(key, value);
+ private static String getResourceInputStr(List<Map<String, Object>> resources, String resCustomizationUuid) {
+
+ for (Map<String, Object> resource : resources) {
+ Map<String, String> modelInfo = (Map<String, String>) resource.get("modelInfo");
+
+ if (modelInfo.get("modelCustomizationUuid").equalsIgnoreCase(resCustomizationUuid)) {
+ return (String) resource.get("resourceInput");
}
}
- return resouceRequest;
+ return null;
}
- private static Object getValue(Object value, Map<String, Object> serviceInputs, List<Input> servInputs) {
- if(value instanceof Map) {
- // currently this logic handles only one level of nesting.
-// Map<String, Object> valueMap = new HashMap<>();
-//
-// Map<String, Object> propertyMap = (Map<String, Object>)value;
-//
-// for(String key : propertyMap.keySet()) {
-// valueMap.put(key, getValue(propertyMap.get(key), serviceInputs, servInputs));
-// }
-// return valueMap; // return if the value is nested hashmap
- return ((LinkedHashMap) value).values().toArray()[0];
- } else if(value instanceof GetInput) {
- String inputName = ((GetInput)value).getInputName();
-
- if(serviceInputs.get(inputName) != null) {
- value = serviceInputs.get(inputName);
- } else {
- for(Input input : servInputs) {
- if(input.getName().equals(inputName)) {
- return input.getDefault(); // return default value
- }
+ // this method combines resource input with service input
+ private static Map<String, Object> getResourceInput(String resourceInputStr, Map<String, Object> serviceInputs) {
+ Gson gson = new Gson();
+ Type type = new TypeToken<Map<String, String>>(){}.getType();
+ Map<String, Object> resourceInput = gson.fromJson(resourceInputStr, type);
+
+ // replace value if key is available in service input
+ for (String key: resourceInput.keySet()) {
+ String value = (String) resourceInput.get(key);
+
+ if (value.contains("|")) {
+ // node it type of getinput
+ String[] split = value.split("\\|");
+ String tmpKey = split[0];
+ if (serviceInputs.containsKey(tmpKey)) {
+ value = (String) serviceInputs.get(tmpKey);
+ } else {
+ value = split[1];
}
}
+ resourceInput.put(key,value);
}
- return value; // return property value
+ return resourceInput;
}
- private static String getCsarFromUuid(String uuid) throws Exception {
- String catalogEndPoint = UrnPropertiesReader.getVariable("mso.catalog.db.endpoint");
+ public static Map<String, Object> getServiceInstnace(String uuid) throws Exception {
+ String catalogEndPoint = UrnPropertiesReader.getVariable("mso.catalog.db.endpoint");
RESTClient restClient = new RESTClient(new RESTConfig(
UriBuilder.fromUri(catalogEndPoint)
- .path(SERVICE_URL_TOSCA_CSAR)
+ .path(SERVICE_URL_SERVICE_INSTANCE)
.queryParam("serviceModelUuid", uuid)
.build().toURL().toString()
));
@@ -279,19 +236,11 @@ public class ResourceRequestBuilder {
String value = apiResponse.getResponseBodyAsString();
- HashMap<String, String> map = new Gson().fromJson(value, new TypeToken<HashMap<String, String>>() {}.getType());
-
- String filePath = System.getProperty("mso.config.path") + "/ASDC/" + map.get("version") + "/" + map.get("name");
-
- File csarFile = new File(filePath);
-
- if(!csarFile.exists()) {
- throw new Exception("csar file does not exist.");
- }
-
- return csarFile.getAbsolutePath();
+ ObjectMapper objectMapper = new ObjectMapper();
+ HashMap<String, Object> map = objectMapper.readValue(value, HashMap.class);
+ return map;
}
-
+
public static <T> T getJsonObject(String jsonstr, Class<T> type) {
ObjectMapper mapper = new ObjectMapper();
mapper.configure(SerializationFeature.WRAP_ROOT_VALUE, true);
diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/common/resource/ResourceRequestBuilderTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/common/resource/ResourceRequestBuilderTest.java
index 5598e3d2e4..731d890e15 100644
--- a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/common/resource/ResourceRequestBuilderTest.java
+++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/common/resource/ResourceRequestBuilderTest.java
@@ -19,24 +19,416 @@
*/
package org.onap.so.bpmn.common.resource;
+import com.github.tomakehurst.wiremock.client.WireMock;
+import com.github.tomakehurst.wiremock.junit.WireMockRule;
+import org.junit.Rule;
import org.junit.Test;
+import org.mockito.Mock;
+import org.onap.so.bpmn.core.UrnPropertiesReader;
+import org.springframework.core.env.Environment;
import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
public class ResourceRequestBuilderTest {
+ @Rule
+ public WireMockRule wireMockRule = new WireMockRule();
+
+ @Mock
+ UrnPropertiesReader urnPropertiesReader;
+
@Test
- public void buildResouceRequestTest() throws Exception {
+ public void getResourceInputTest() throws Exception {
+
+ UrnPropertiesReader reader = new UrnPropertiesReader();
+ Environment env = mock(Environment.class);
+
+ when(env.getProperty(eq("mso.catalog.db.endpoint"))).thenReturn("http://localhost:8080");
+ reader.setEnvironment(env);
+
+ WireMock.stubFor(WireMock.get(WireMock.urlEqualTo("/v3/serviceResources?serviceModelUuid=c3954379-4efe-431c-8258-f84905b158e5"))
+ .willReturn(WireMock.ok("{ \"serviceResources\" : {\n" +
+ "\t\"modelInfo\" : {\n" +
+ "\t\t\"modelName\" : \"demoVFWCL\",\n" +
+ "\t\t\"modelUuid\" : \"c3954379-4efe-431c-8258-f84905b158e5\",\n" +
+ "\t\t\"modelInvariantUuid\" : \"0cbff61e-3b0a-4eed-97ce-b1b4faa03493\",\n" +
+ "\t\t\"modelVersion\" : \"1.0\"\n" +
+ "\t},\n" +
+ "\t\"serviceType\" : \"\",\n" +
+ "\t\"serviceRole\" : \"\",\n" +
+ "\t\"environmentContext\" : null,\n" +
+ "\t\"resourceOrder\" : \"res1,res2\",\n" +
+ "\t\"workloadContext\" : \"Production\",\n" +
+ "\t\"serviceVnfs\": [\n" +
+ "\t\n" +
+ "\t\t{ \"modelInfo\" : {\n" +
+ "\t\t\t\"modelName\" : \"15968a6e-2fe5-41bf-a481\",\n" +
+ "\t\t\t\"modelUuid\" : \"808abda3-2023-4105-92d2-e62644b61d53\",\n" +
+ "\t\t\t\"modelInvariantUuid\" : \"6e4ffc7c-497e-4a77-970d-af966e642d31\",\n" +
+ "\t\t\t\"modelVersion\" : \"1.0\",\n" +
+ "\t\t\t\"modelCustomizationUuid\" : \"a00404d5-d7eb-4c46-b6b6-9cf2d087e545\",\n" +
+ "\t\t\t\"modelInstanceName\" : \"15968a6e-2fe5-41bf-a481 0\"\n" +
+ "\t\t\t},\n" +
+ "\t\t\"toscaNodeType\" : \"org.openecomp.resource.vf.15968a6e2fe541bfA481\",\n" +
+ "\t\t\"nfFunction\" \t: null,\n" +
+ "\"resourceInput\":\"{\\\"a\\\":\\\"b\\\"}\"," +
+ "\t\t\"nfType\" \t\t: null,\n" +
+ "\t\t\"nfRole\" \t\t: null,\n" +
+ "\t\t\"nfNamingCode\" \t: null,\n" +
+ "\t\t\"multiStageDesign\" : \"false\",\n" +
+ "\t\t\t\"vfModules\": [\n" +
+ "\t\t\t\t{\n" +
+ "\t\t\t\t\t\"modelInfo\" : { \n" +
+ "\t\t\t\t\t\t\"modelName\" : \"15968a6e2fe541bfA481..base_vfw..module-0\",\n" +
+ "\t\t\t\t\t\t\"modelUuid\" : \"ec7fadde-1e5a-42f7-8255-cb19e475ff45\",\n" +
+ "\t\t\t\t\t\t\"modelInvariantUuid\" : \"61ab8b64-a014-4cf3-8a5a-b5ef388f8819\",\n" +
+ "\t\t\t\t\t\t\"modelVersion\" : \"1\",\n" +
+ "\t\t\t\t\t\t\"modelCustomizationUuid\" : \"123aff6b-854f-4026-ae1e-cc74a3924576\"\n" +
+ "\t\t\t\t\t},\t\t\"isBase\" : true,\n" +
+ "\t\t\t\t\t\"vfModuleLabel\" : \"base_vfw\",\n" +
+ "\t\t\t\t\t\"initialCount\" : 1,\n" +
+ "\t\t\t\t\t\"hasVolumeGroup\" : true\n" +
+ "\t\t\t\t}\n" +
+ "\t\t\t]\n" +
+ "\t\t},\n" +
+ "\t\n" +
+ "\t\t{ \"modelInfo\" : {\n" +
+ "\t\t\t\"modelName\" : \"f971106a-248f-4202-9d1f\",\n" +
+ "\t\t\t\"modelUuid\" : \"4fbc08a4-35ed-4a59-9e47-79975e4add7e\",\n" +
+ "\t\t\t\"modelInvariantUuid\" : \"c669799e-adf1-46ae-8c70-48b326fe89f3\",\n" +
+ "\t\t\t\"modelVersion\" : \"1.0\",\n" +
+ "\t\t\t\"modelCustomizationUuid\" : \"e776449e-2b10-45c5-9217-2775c88ca1a0\",\n" +
+ "\t\t\t\"modelInstanceName\" : \"f971106a-248f-4202-9d1f 0\"\n" +
+ "\t\t\t},\n" +
+ "\t\t\"toscaNodeType\" : \"org.openecomp.resource.vf.F971106a248f42029d1f\",\n" +
+ "\t\t\"nfFunction\" \t: null,\n" +
+ "\t\t\"nfType\" \t\t: null,\n" +
+ "\t\t\"nfRole\" \t\t: null,\n" +
+ "\"resourceInput\":\"{\\\"a\\\":\\\"key|default_value\\\"}\"," +
+ "\t\t\"nfNamingCode\" \t: null,\n" +
+ "\t\t\"multiStageDesign\" : \"false\",\n" +
+ "\t\t\t\"vfModules\": [\n" +
+ "\t\t\t\t{\n" +
+ "\t\t\t\t\t\"modelInfo\" : { \n" +
+ "\t\t\t\t\t\t\"modelName\" : \"F971106a248f42029d1f..base_vpkg..module-0\",\n" +
+ "\t\t\t\t\t\t\"modelUuid\" : \"47d5273a-7456-4786-9035-b3911944cc35\",\n" +
+ "\t\t\t\t\t\t\"modelInvariantUuid\" : \"0ea3e57e-ac7a-425a-928b-b4aee8806c15\",\n" +
+ "\t\t\t\t\t\t\"modelVersion\" : \"1\",\n" +
+ "\t\t\t\t\t\t\"modelCustomizationUuid\" : \"9ed9fef6-d3f8-4433-9807-7e23393a16bc\"\n" +
+ "\t\t\t\t\t},\t\t\"isBase\" : true,\n" +
+ "\t\t\t\t\t\"vfModuleLabel\" : \"base_vpkg\",\n" +
+ "\t\t\t\t\t\"initialCount\" : 1,\n" +
+ "\t\t\t\t\t\"hasVolumeGroup\" : true\n" +
+ "\t\t\t\t}\n" +
+ "\t\t\t]\n" +
+ "\t\t}\n" +
+ "\t],\n" +
+ "\t\"serviceNetworks\": [],\n" +
+ "\t\"serviceAllottedResources\": []\n" +
+ "\t}}")));
- ResourceRequestBuilder.buildResouceRequest("xxxxxx",
- "a1074969-944f-4ddc-b687-9550b0c8cd57", new HashMap<>());
+// when(UrnPropertiesReader.getVariable(anyString())).thenReturn("http://localhost:8080");
+ HashMap serviceInput = new HashMap();
+ serviceInput.put("key", "value");
+ Map<String, Object> stringObjectMap = ResourceRequestBuilder.buildResouceRequest("c3954379-4efe-431c-8258-f84905b158e5",
+ "e776449e-2b10-45c5-9217-2775c88ca1a0", serviceInput);
+ assertEquals(stringObjectMap.get("a"), "value");
}
@Test
- public void buildResouceRequestParametersTest() throws Exception {
+ public void getResourceInputDefaultValueTest() throws Exception {
+
+ UrnPropertiesReader reader = new UrnPropertiesReader();
+ Environment env = mock(Environment.class);
+
+ when(env.getProperty(eq("mso.catalog.db.endpoint"))).thenReturn("http://localhost:8080");
+ reader.setEnvironment(env);
+
+ WireMock.stubFor(WireMock.get(WireMock.urlEqualTo("/v3/serviceResources?serviceModelUuid=c3954379-4efe-431c-8258-f84905b158e5"))
+ .willReturn(WireMock.ok("{ \"serviceResources\" : {\n" +
+ "\t\"modelInfo\" : {\n" +
+ "\t\t\"modelName\" : \"demoVFWCL\",\n" +
+ "\t\t\"modelUuid\" : \"c3954379-4efe-431c-8258-f84905b158e5\",\n" +
+ "\t\t\"modelInvariantUuid\" : \"0cbff61e-3b0a-4eed-97ce-b1b4faa03493\",\n" +
+ "\t\t\"modelVersion\" : \"1.0\"\n" +
+ "\t},\n" +
+ "\t\"serviceType\" : \"\",\n" +
+ "\t\"serviceRole\" : \"\",\n" +
+ "\t\"environmentContext\" : null,\n" +
+ "\t\"workloadContext\" : \"Production\",\n" +
+ "\t\"serviceVnfs\": [\n" +
+ "\t\n" +
+ "\t\t{ \"modelInfo\" : {\n" +
+ "\t\t\t\"modelName\" : \"15968a6e-2fe5-41bf-a481\",\n" +
+ "\t\t\t\"modelUuid\" : \"808abda3-2023-4105-92d2-e62644b61d53\",\n" +
+ "\t\t\t\"modelInvariantUuid\" : \"6e4ffc7c-497e-4a77-970d-af966e642d31\",\n" +
+ "\t\t\t\"modelVersion\" : \"1.0\",\n" +
+ "\t\t\t\"modelCustomizationUuid\" : \"a00404d5-d7eb-4c46-b6b6-9cf2d087e545\",\n" +
+ "\t\t\t\"modelInstanceName\" : \"15968a6e-2fe5-41bf-a481 0\"\n" +
+ "\t\t\t},\n" +
+ "\t\t\"toscaNodeType\" : \"org.openecomp.resource.vf.15968a6e2fe541bfA481\",\n" +
+ "\t\t\"nfFunction\" \t: null,\n" +
+ "\"resourceInput\":\"{\\\"a\\\":\\\"b\\\"}\"," +
+ "\t\t\"nfType\" \t\t: null,\n" +
+ "\t\t\"nfRole\" \t\t: null,\n" +
+ "\t\t\"nfNamingCode\" \t: null,\n" +
+ "\t\t\"multiStageDesign\" : \"false\",\n" +
+ "\t\t\t\"vfModules\": [\n" +
+ "\t\t\t\t{\n" +
+ "\t\t\t\t\t\"modelInfo\" : { \n" +
+ "\t\t\t\t\t\t\"modelName\" : \"15968a6e2fe541bfA481..base_vfw..module-0\",\n" +
+ "\t\t\t\t\t\t\"modelUuid\" : \"ec7fadde-1e5a-42f7-8255-cb19e475ff45\",\n" +
+ "\t\t\t\t\t\t\"modelInvariantUuid\" : \"61ab8b64-a014-4cf3-8a5a-b5ef388f8819\",\n" +
+ "\t\t\t\t\t\t\"modelVersion\" : \"1\",\n" +
+ "\t\t\t\t\t\t\"modelCustomizationUuid\" : \"123aff6b-854f-4026-ae1e-cc74a3924576\"\n" +
+ "\t\t\t\t\t},\t\t\"isBase\" : true,\n" +
+ "\t\t\t\t\t\"vfModuleLabel\" : \"base_vfw\",\n" +
+ "\t\t\t\t\t\"initialCount\" : 1,\n" +
+ "\t\t\t\t\t\"hasVolumeGroup\" : true\n" +
+ "\t\t\t\t}\n" +
+ "\t\t\t]\n" +
+ "\t\t},\n" +
+ "\t\n" +
+ "\t\t{ \"modelInfo\" : {\n" +
+ "\t\t\t\"modelName\" : \"f971106a-248f-4202-9d1f\",\n" +
+ "\t\t\t\"modelUuid\" : \"4fbc08a4-35ed-4a59-9e47-79975e4add7e\",\n" +
+ "\t\t\t\"modelInvariantUuid\" : \"c669799e-adf1-46ae-8c70-48b326fe89f3\",\n" +
+ "\t\t\t\"modelVersion\" : \"1.0\",\n" +
+ "\t\t\t\"modelCustomizationUuid\" : \"e776449e-2b10-45c5-9217-2775c88ca1a0\",\n" +
+ "\t\t\t\"modelInstanceName\" : \"f971106a-248f-4202-9d1f 0\"\n" +
+ "\t\t\t},\n" +
+ "\t\t\"toscaNodeType\" : \"org.openecomp.resource.vf.F971106a248f42029d1f\",\n" +
+ "\t\t\"nfFunction\" \t: null,\n" +
+ "\t\t\"nfType\" \t\t: null,\n" +
+ "\t\t\"nfRole\" \t\t: null,\n" +
+ "\"resourceInput\":\"{\\\"a\\\":\\\"key|default_value\\\"}\"," +
+ "\t\t\"nfNamingCode\" \t: null,\n" +
+ "\t\t\"multiStageDesign\" : \"false\",\n" +
+ "\t\t\t\"vfModules\": [\n" +
+ "\t\t\t\t{\n" +
+ "\t\t\t\t\t\"modelInfo\" : { \n" +
+ "\t\t\t\t\t\t\"modelName\" : \"F971106a248f42029d1f..base_vpkg..module-0\",\n" +
+ "\t\t\t\t\t\t\"modelUuid\" : \"47d5273a-7456-4786-9035-b3911944cc35\",\n" +
+ "\t\t\t\t\t\t\"modelInvariantUuid\" : \"0ea3e57e-ac7a-425a-928b-b4aee8806c15\",\n" +
+ "\t\t\t\t\t\t\"modelVersion\" : \"1\",\n" +
+ "\t\t\t\t\t\t\"modelCustomizationUuid\" : \"9ed9fef6-d3f8-4433-9807-7e23393a16bc\"\n" +
+ "\t\t\t\t\t},\t\t\"isBase\" : true,\n" +
+ "\t\t\t\t\t\"vfModuleLabel\" : \"base_vpkg\",\n" +
+ "\t\t\t\t\t\"initialCount\" : 1,\n" +
+ "\t\t\t\t\t\"hasVolumeGroup\" : true\n" +
+ "\t\t\t\t}\n" +
+ "\t\t\t]\n" +
+ "\t\t}\n" +
+ "\t],\n" +
+ "\t\"serviceNetworks\": [],\n" +
+ "\t\"serviceAllottedResources\": []\n" +
+ "\t}}")));
+
+// when(UrnPropertiesReader.getVariable(anyString())).thenReturn("http://localhost:8080");
+ HashMap serviceInput = new HashMap();
+ serviceInput.put("key1", "value");
+ Map<String, Object> stringObjectMap = ResourceRequestBuilder.buildResouceRequest("c3954379-4efe-431c-8258-f84905b158e5",
+ "e776449e-2b10-45c5-9217-2775c88ca1a0", serviceInput);
+ assertEquals(stringObjectMap.get("a"), "default_value");
+ }
+
+ @Test
+ public void getResourceInputValueNoDefaultTest() throws Exception {
+
+ UrnPropertiesReader reader = new UrnPropertiesReader();
+ Environment env = mock(Environment.class);
+
+ when(env.getProperty(eq("mso.catalog.db.endpoint"))).thenReturn("http://localhost:8080");
+ reader.setEnvironment(env);
+
+ WireMock.stubFor(WireMock.get(WireMock.urlEqualTo("/v3/serviceResources?serviceModelUuid=c3954379-4efe-431c-8258-f84905b158e5"))
+ .willReturn(WireMock.ok("{ \"serviceResources\" : {\n" +
+ "\t\"modelInfo\" : {\n" +
+ "\t\t\"modelName\" : \"demoVFWCL\",\n" +
+ "\t\t\"modelUuid\" : \"c3954379-4efe-431c-8258-f84905b158e5\",\n" +
+ "\t\t\"modelInvariantUuid\" : \"0cbff61e-3b0a-4eed-97ce-b1b4faa03493\",\n" +
+ "\t\t\"modelVersion\" : \"1.0\"\n" +
+ "\t},\n" +
+ "\t\"serviceType\" : \"\",\n" +
+ "\t\"serviceRole\" : \"\",\n" +
+ "\t\"environmentContext\" : null,\n" +
+ "\t\"workloadContext\" : \"Production\",\n" +
+ "\t\"serviceVnfs\": [\n" +
+ "\t\n" +
+ "\t\t{ \"modelInfo\" : {\n" +
+ "\t\t\t\"modelName\" : \"15968a6e-2fe5-41bf-a481\",\n" +
+ "\t\t\t\"modelUuid\" : \"808abda3-2023-4105-92d2-e62644b61d53\",\n" +
+ "\t\t\t\"modelInvariantUuid\" : \"6e4ffc7c-497e-4a77-970d-af966e642d31\",\n" +
+ "\t\t\t\"modelVersion\" : \"1.0\",\n" +
+ "\t\t\t\"modelCustomizationUuid\" : \"a00404d5-d7eb-4c46-b6b6-9cf2d087e545\",\n" +
+ "\t\t\t\"modelInstanceName\" : \"15968a6e-2fe5-41bf-a481 0\"\n" +
+ "\t\t\t},\n" +
+ "\t\t\"toscaNodeType\" : \"org.openecomp.resource.vf.15968a6e2fe541bfA481\",\n" +
+ "\t\t\"nfFunction\" \t: null,\n" +
+ "\"resourceInput\":\"{\\\"a\\\":\\\"b\\\"}\"," +
+ "\t\t\"nfType\" \t\t: null,\n" +
+ "\t\t\"nfRole\" \t\t: null,\n" +
+ "\t\t\"nfNamingCode\" \t: null,\n" +
+ "\t\t\"multiStageDesign\" : \"false\",\n" +
+ "\t\t\t\"vfModules\": [\n" +
+ "\t\t\t\t{\n" +
+ "\t\t\t\t\t\"modelInfo\" : { \n" +
+ "\t\t\t\t\t\t\"modelName\" : \"15968a6e2fe541bfA481..base_vfw..module-0\",\n" +
+ "\t\t\t\t\t\t\"modelUuid\" : \"ec7fadde-1e5a-42f7-8255-cb19e475ff45\",\n" +
+ "\t\t\t\t\t\t\"modelInvariantUuid\" : \"61ab8b64-a014-4cf3-8a5a-b5ef388f8819\",\n" +
+ "\t\t\t\t\t\t\"modelVersion\" : \"1\",\n" +
+ "\t\t\t\t\t\t\"modelCustomizationUuid\" : \"123aff6b-854f-4026-ae1e-cc74a3924576\"\n" +
+ "\t\t\t\t\t},\t\t\"isBase\" : true,\n" +
+ "\t\t\t\t\t\"vfModuleLabel\" : \"base_vfw\",\n" +
+ "\t\t\t\t\t\"initialCount\" : 1,\n" +
+ "\t\t\t\t\t\"hasVolumeGroup\" : true\n" +
+ "\t\t\t\t}\n" +
+ "\t\t\t]\n" +
+ "\t\t},\n" +
+ "\t\n" +
+ "\t\t{ \"modelInfo\" : {\n" +
+ "\t\t\t\"modelName\" : \"f971106a-248f-4202-9d1f\",\n" +
+ "\t\t\t\"modelUuid\" : \"4fbc08a4-35ed-4a59-9e47-79975e4add7e\",\n" +
+ "\t\t\t\"modelInvariantUuid\" : \"c669799e-adf1-46ae-8c70-48b326fe89f3\",\n" +
+ "\t\t\t\"modelVersion\" : \"1.0\",\n" +
+ "\t\t\t\"modelCustomizationUuid\" : \"e776449e-2b10-45c5-9217-2775c88ca1a0\",\n" +
+ "\t\t\t\"modelInstanceName\" : \"f971106a-248f-4202-9d1f 0\"\n" +
+ "\t\t\t},\n" +
+ "\t\t\"toscaNodeType\" : \"org.openecomp.resource.vf.F971106a248f42029d1f\",\n" +
+ "\t\t\"nfFunction\" \t: null,\n" +
+ "\t\t\"nfType\" \t\t: null,\n" +
+ "\t\t\"nfRole\" \t\t: null,\n" +
+ "\"resourceInput\":\"{\\\"a\\\":\\\"value\\\"}\"," +
+ "\t\t\"nfNamingCode\" \t: null,\n" +
+ "\t\t\"multiStageDesign\" : \"false\",\n" +
+ "\t\t\t\"vfModules\": [\n" +
+ "\t\t\t\t{\n" +
+ "\t\t\t\t\t\"modelInfo\" : { \n" +
+ "\t\t\t\t\t\t\"modelName\" : \"F971106a248f42029d1f..base_vpkg..module-0\",\n" +
+ "\t\t\t\t\t\t\"modelUuid\" : \"47d5273a-7456-4786-9035-b3911944cc35\",\n" +
+ "\t\t\t\t\t\t\"modelInvariantUuid\" : \"0ea3e57e-ac7a-425a-928b-b4aee8806c15\",\n" +
+ "\t\t\t\t\t\t\"modelVersion\" : \"1\",\n" +
+ "\t\t\t\t\t\t\"modelCustomizationUuid\" : \"9ed9fef6-d3f8-4433-9807-7e23393a16bc\"\n" +
+ "\t\t\t\t\t},\t\t\"isBase\" : true,\n" +
+ "\t\t\t\t\t\"vfModuleLabel\" : \"base_vpkg\",\n" +
+ "\t\t\t\t\t\"initialCount\" : 1,\n" +
+ "\t\t\t\t\t\"hasVolumeGroup\" : true\n" +
+ "\t\t\t\t}\n" +
+ "\t\t\t]\n" +
+ "\t\t}\n" +
+ "\t],\n" +
+ "\t\"serviceNetworks\": [],\n" +
+ "\t\"serviceAllottedResources\": []\n" +
+ "\t}}")));
+
+// when(UrnPropertiesReader.getVariable(anyString())).thenReturn("http://localhost:8080");
+ HashMap serviceInput = new HashMap();
+ serviceInput.put("key1", "value");
+ Map<String, Object> stringObjectMap = ResourceRequestBuilder.buildResouceRequest("c3954379-4efe-431c-8258-f84905b158e5",
+ "e776449e-2b10-45c5-9217-2775c88ca1a0", serviceInput);
+ assertEquals(stringObjectMap.get("a"), "value");
+ }
+
+ @Test
+ public void getResourceSequenceTest() throws Exception {
+
+ UrnPropertiesReader reader = new UrnPropertiesReader();
+ Environment env = mock(Environment.class);
+
+ when(env.getProperty(eq("mso.catalog.db.endpoint"))).thenReturn("http://localhost:8080");
+ reader.setEnvironment(env);
+
+ WireMock.stubFor(WireMock.get(WireMock.urlEqualTo("/v3/serviceResources?serviceModelUuid=c3954379-4efe-431c-8258-f84905b158e5"))
+ .willReturn(WireMock.ok("{ \"serviceResources\" : {\n" +
+ "\t\"modelInfo\" : {\n" +
+ "\t\t\"modelName\" : \"demoVFWCL\",\n" +
+ "\t\t\"modelUuid\" : \"c3954379-4efe-431c-8258-f84905b158e5\",\n" +
+ "\t\t\"modelInvariantUuid\" : \"0cbff61e-3b0a-4eed-97ce-b1b4faa03493\",\n" +
+ "\t\t\"modelVersion\" : \"1.0\"\n" +
+ "\t},\n" +
+ "\t\"serviceType\" : \"\",\n" +
+ "\t\"serviceRole\" : \"\",\n" +
+ "\t\"environmentContext\" : null,\n" +
+ "\t\"resourceOrder\" : \"res1,res2\",\n" +
+ "\t\"workloadContext\" : \"Production\",\n" +
+ "\t\"serviceVnfs\": [\n" +
+ "\t\n" +
+ "\t\t{ \"modelInfo\" : {\n" +
+ "\t\t\t\"modelName\" : \"15968a6e-2fe5-41bf-a481\",\n" +
+ "\t\t\t\"modelUuid\" : \"808abda3-2023-4105-92d2-e62644b61d53\",\n" +
+ "\t\t\t\"modelInvariantUuid\" : \"6e4ffc7c-497e-4a77-970d-af966e642d31\",\n" +
+ "\t\t\t\"modelVersion\" : \"1.0\",\n" +
+ "\t\t\t\"modelCustomizationUuid\" : \"a00404d5-d7eb-4c46-b6b6-9cf2d087e545\",\n" +
+ "\t\t\t\"modelInstanceName\" : \"15968a6e-2fe5-41bf-a481 0\"\n" +
+ "\t\t\t},\n" +
+ "\t\t\"toscaNodeType\" : \"org.openecomp.resource.vf.15968a6e2fe541bfA481\",\n" +
+ "\t\t\"nfFunction\" \t: null,\n" +
+ "\"resourceInput\":\"{\\\"a\\\":\\\"b\\\"}\"," +
+ "\t\t\"nfType\" \t\t: null,\n" +
+ "\t\t\"nfRole\" \t\t: null,\n" +
+ "\t\t\"nfNamingCode\" \t: null,\n" +
+ "\t\t\"multiStageDesign\" : \"false\",\n" +
+ "\t\t\t\"vfModules\": [\n" +
+ "\t\t\t\t{\n" +
+ "\t\t\t\t\t\"modelInfo\" : { \n" +
+ "\t\t\t\t\t\t\"modelName\" : \"15968a6e2fe541bfA481..base_vfw..module-0\",\n" +
+ "\t\t\t\t\t\t\"modelUuid\" : \"ec7fadde-1e5a-42f7-8255-cb19e475ff45\",\n" +
+ "\t\t\t\t\t\t\"modelInvariantUuid\" : \"61ab8b64-a014-4cf3-8a5a-b5ef388f8819\",\n" +
+ "\t\t\t\t\t\t\"modelVersion\" : \"1\",\n" +
+ "\t\t\t\t\t\t\"modelCustomizationUuid\" : \"123aff6b-854f-4026-ae1e-cc74a3924576\"\n" +
+ "\t\t\t\t\t},\t\t\"isBase\" : true,\n" +
+ "\t\t\t\t\t\"vfModuleLabel\" : \"base_vfw\",\n" +
+ "\t\t\t\t\t\"initialCount\" : 1,\n" +
+ "\t\t\t\t\t\"hasVolumeGroup\" : true\n" +
+ "\t\t\t\t}\n" +
+ "\t\t\t]\n" +
+ "\t\t},\n" +
+ "\t\n" +
+ "\t\t{ \"modelInfo\" : {\n" +
+ "\t\t\t\"modelName\" : \"f971106a-248f-4202-9d1f\",\n" +
+ "\t\t\t\"modelUuid\" : \"4fbc08a4-35ed-4a59-9e47-79975e4add7e\",\n" +
+ "\t\t\t\"modelInvariantUuid\" : \"c669799e-adf1-46ae-8c70-48b326fe89f3\",\n" +
+ "\t\t\t\"modelVersion\" : \"1.0\",\n" +
+ "\t\t\t\"modelCustomizationUuid\" : \"e776449e-2b10-45c5-9217-2775c88ca1a0\",\n" +
+ "\t\t\t\"modelInstanceName\" : \"f971106a-248f-4202-9d1f 0\"\n" +
+ "\t\t\t},\n" +
+ "\t\t\"toscaNodeType\" : \"org.openecomp.resource.vf.F971106a248f42029d1f\",\n" +
+ "\t\t\"nfFunction\" \t: null,\n" +
+ "\t\t\"nfType\" \t\t: null,\n" +
+ "\t\t\"nfRole\" \t\t: null,\n" +
+ "\"resourceInput\":\"{\\\"a\\\":\\\"key|default_value\\\"}\"," +
+ "\t\t\"nfNamingCode\" \t: null,\n" +
+ "\t\t\"multiStageDesign\" : \"false\",\n" +
+ "\t\t\t\"vfModules\": [\n" +
+ "\t\t\t\t{\n" +
+ "\t\t\t\t\t\"modelInfo\" : { \n" +
+ "\t\t\t\t\t\t\"modelName\" : \"F971106a248f42029d1f..base_vpkg..module-0\",\n" +
+ "\t\t\t\t\t\t\"modelUuid\" : \"47d5273a-7456-4786-9035-b3911944cc35\",\n" +
+ "\t\t\t\t\t\t\"modelInvariantUuid\" : \"0ea3e57e-ac7a-425a-928b-b4aee8806c15\",\n" +
+ "\t\t\t\t\t\t\"modelVersion\" : \"1\",\n" +
+ "\t\t\t\t\t\t\"modelCustomizationUuid\" : \"9ed9fef6-d3f8-4433-9807-7e23393a16bc\"\n" +
+ "\t\t\t\t\t},\t\t\"isBase\" : true,\n" +
+ "\t\t\t\t\t\"vfModuleLabel\" : \"base_vpkg\",\n" +
+ "\t\t\t\t\t\"initialCount\" : 1,\n" +
+ "\t\t\t\t\t\"hasVolumeGroup\" : true\n" +
+ "\t\t\t\t}\n" +
+ "\t\t\t]\n" +
+ "\t\t}\n" +
+ "\t],\n" +
+ "\t\"serviceNetworks\": [],\n" +
+ "\t\"serviceAllottedResources\": []\n" +
+ "\t}}")));
- String parameters =
- "{ \"locationConstraints\":[ ], \"resources\":[ { \"resourceName\":\"vEPC_ONAP01\", \"resourceInvariantUuid\":\"36ebe421-283a-4ee8-92f1-d09e7c44b911\", \"resourceUuid\":\"27a0e235-b67a-4ea4-a0cf-25761afed111\", \"resourceCustomizationUuid\":\"27a0e235-b67a-4ea4-a0cf-25761afed231\", \"parameters\":{ \"locationConstraints\":[ { \"vnfProfileId\":\"b244d433-8c9c-49ad-9c70-8e34b8dc8328\", \"locationConstraints\":{ \"vimId\":\"vmware_vio\" } }, { \"vnfProfileId\":\"8a9f7c48-21ce-41b7-95b8-a8ac61ccb1ff\", \"locationConstraints\":{ \"vimId\":\"core-dc_RegionOne\" } } ], \"resources\":[ ], \"requestInputs\":{ \"sdncontroller\":\"\" } } }, { \"resourceName\":\"VL OVERLAYTUNNEL\", \"resourceInvariantUuid\":\"184494cf-472f-436f-82e2-d83dddde21cb\", \"resourceUuid\":\"95bc3e59-c9c5-458f-ad6e-78874ab4b3cc\", \"resourceCustomizationUuid\":\"27a0e235-b67a-4ea4-a0cf-25761afed232\", \"parameters\":{ \"locationConstraints\":[ ], \"resources\":[ ], \"requestInputs\":{ } } } ], \"requestInputs\":{ \"vlunderlayvpn0_name\":\"l3connect\", \"vlunderlayvpn0_site1_id\":\"IP-WAN-Controller-1\", \"vlunderlayvpn0_site2_id\":\"SPTNController\", \"vlunderlayvpn0_site1_networkName\":\"network1,network2\", \"vlunderlayvpn0_site2_networkName\":\"network3,network4\", \"vlunderlayvpn0_site1_routerId\":\"a8098c1a-f86e-11da-bd1a-00112444be1a\", \"vlunderlayvpn0_site2_routerId\":\"a8098c1a-f86e-11da-bd1a-00112444be1e\", \"vlunderlayvpn0_site2_importRT1\":\"200:1,200:2\", \"vlunderlayvpn0_site1_exportRT1\":\"300:1,300:2\", \"vlunderlayvpn0_site2_exportRT1\":\"400:1,400:2\", \"vlunderlayvpn0_site1_vni\":\"2000\", \"vlunderlayvpn0_site2_vni\":\"3000\", \"vlunderlayvpn0_tunnelType\":\"L3-DCI\" } }";
- ResourceRequestBuilder.buildResourceRequestParameters(null, "1bd0eae6-2dcc-4461-9ae6-56d641f369d6", "27a0e235-b67a-4ea4-a0cf-25761afed231", parameters);
+ List<String> resourceSequence = ResourceRequestBuilder.getResourceSequence("c3954379-4efe-431c-8258-f84905b158e5");
+ assertEquals(resourceSequence.size(), 2);
+ assertEquals(resourceSequence.get(0), "res1");
+ assertEquals(resourceSequence.get(1), "res2");
}
} \ No newline at end of file