aboutsummaryrefslogtreecommitdiffstats
path: root/bpmn/MSOCommonBPMN/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'bpmn/MSOCommonBPMN/src/main')
-rw-r--r--bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/MsoUtils.groovy3
-rw-r--r--bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/OofHoming.groovy83
-rw-r--r--bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/OofUtils.groovy16
-rw-r--r--bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/resource/ResourceRequestBuilder.java245
-rw-r--r--bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/util/OofInfraUtils.java112
5 files changed, 282 insertions, 177 deletions
diff --git a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/MsoUtils.groovy b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/MsoUtils.groovy
index 2f240fb70d..4f0b530a3b 100644
--- a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/MsoUtils.groovy
+++ b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/MsoUtils.groovy
@@ -931,7 +931,8 @@ class MsoUtils {
if (moduleIndexList == null || moduleIndexList.size() == 0) {
return "0"
}
- def sortedModuleIndexList = moduleIndexList.sort { a, b -> a.compareTo b }
+
+ def sortedModuleIndexList = moduleIndexList.sort{ a, b -> a as Integer <=> b as Integer}
for (i in 0..sortedModuleIndexList.size()-1) {
if (Integer.parseInt(sortedModuleIndexList[i]) != i) {
diff --git a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/OofHoming.groovy b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/OofHoming.groovy
index 5659c7affa..5e949fd8d2 100644
--- a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/OofHoming.groovy
+++ b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/OofHoming.groovy
@@ -35,7 +35,7 @@ import org.onap.so.client.HttpClientFactory
import org.onap.so.logger.MsoLogger
import org.onap.so.db.catalog.beans.CloudIdentity
import org.onap.so.db.catalog.beans.CloudSite
-
+import org.onap.so.db.catalog.beans.HomingInstance
import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
import org.onap.so.utils.TargetEntity
@@ -209,17 +209,12 @@ class OofHoming extends AbstractServiceTaskProcessor {
for (int j = 0; j < arrSol.length(); j++) {
JSONObject placement = arrSol.getJSONObject(j)
utils.log("DEBUG", "****** Placement Solution is: " + placement + " *****", "true")
- String jsonServiceResourceId = placement.getString("serviceResourceId")
- String jsonResourceModuleName = placement.getString("resourceModuleName")
+ String jsonServiceResourceId = jsonUtil.getJsonValue( placement.toString(), "serviceResourceId")
+ utils.log("DEBUG", "****** homing serviceResourceId is: " + jsonServiceResourceId + " *****", "true")
for (Resource resource : resourceList) {
String serviceResourceId = resource.getResourceId()
- String resourceModuleName = ""
- if (resource.getResourceType() == ResourceType.ALLOTTED_RESOURCE ||
- resource.getResourceType() == ResourceType.VNF) {
- resourceModuleName = resource.getNfFunction()
- }
- if (serviceResourceId.equalsIgnoreCase(jsonServiceResourceId) ||
- resourceModuleName.equalsIgnoreCase(jsonResourceModuleName)) {
+ utils.log("DEBUG", "****** decomp serviceResourceId is: " + serviceResourceId + " *****", "true")
+ if (serviceResourceId.equalsIgnoreCase(jsonServiceResourceId)) {
JSONObject solution = placement.getJSONObject("solution")
String solutionType = solution.getString("identifierType")
String inventoryType = ""
@@ -228,20 +223,26 @@ class OofHoming extends AbstractServiceTaskProcessor {
} else {
inventoryType = "cloud"
}
+ utils.log("DEBUG", "****** homing inventoryType is: " + inventoryType + " *****", "true")
resource.getHomingSolution().setInventoryType(InventoryType.valueOf(inventoryType))
JSONArray assignmentArr = placement.getJSONArray("assignmentInfo")
+ utils.log("DEBUG", "****** assignmentInfo is: " + assignmentArr.toString() + " *****", "true")
+
+ Map<String, String> assignmentMap = jsonUtil.entryArrayToMap(execution,
+ assignmentArr.toString(), "key", "value")
String oofDirectives = null
- assignmentArr.each { element ->
- JSONObject jsonObject = new JSONObject(element.toString())
- if (jsonUtil.getJsonRawValue(jsonObject.toString(), "key") == "oof_directives") {
- oofDirectives = jsonUtil.getJsonRawValue(jsonObject.toString(), "value")
+ assignmentMap.each { key, value ->
+ utils.log("DEBUG", "****** element: " + key + " *****", "true")
+ if (key == "oof_directives") {
+ oofDirectives = value
+ utils.log("DEBUG", "****** homing oofDirectives: " + oofDirectives + " *****", "true")
}
}
- Map<String, String> assignmentMap = jsonUtil.entryArrayToMap(execution,
- assignmentArr.toString(), "key", "value")
String cloudOwner = assignmentMap.get("cloudOwner")
+ utils.log("DEBUG", "****** homing cloudOwner: " + cloudOwner + " *****", "true")
String cloudRegionId = assignmentMap.get("locationId")
+ utils.log("DEBUG", "****** homing cloudRegionId: " + cloudRegionId + " *****", "true")
resource.getHomingSolution().setCloudOwner(cloudOwner)
resource.getHomingSolution().setCloudRegionId(cloudRegionId)
@@ -249,12 +250,26 @@ class OofHoming extends AbstractServiceTaskProcessor {
cloudSite.setId(cloudRegionId)
cloudSite.setRegionId(cloudRegionId)
String orchestrator = execution.getVariable("orchestrator")
- if ((orchestrator != null) || (orchestrator != "")) {
+ if ((orchestrator != null) && (orchestrator != "")) {
cloudSite.setOrchestrator(orchestrator)
+ utils.log("DEBUG", "****** orchestrator: " + orchestrator + " *****", "true")
+ } else {
+ cloudSite.setOrchestrator("multicloud")
}
CloudIdentity cloudIdentity = new CloudIdentity()
cloudIdentity.setId(cloudRegionId)
+ cloudIdentity.setIdentityServerType(ServerType."KEYSTONE")
+ cloudIdentity.setAdminTenant("service")
+ cloudIdentity.setIdentityAuthenticationType(AuthenticationType.USERNAME_PASSWORD)
+ String msoMulticloudUserName = UrnPropertiesReader
+ .getVariable("mso.multicloud.api.username", execution,
+ "apih")
+ String msoMulticloudPassword = UrnPropertiesReader
+ .getVariable("mso.multicloud.api.password", execution,
+ "abc123")
+ cloudIdentity.setMsoId(msoMulticloudUserName)
+ cloudIdentity.setMsoPass(msoMulticloudPassword)
// Get MSB Url
String msbHost = oofUtils.getMsbHost(execution)
String multicloudApiEndpoint = UrnPropertiesReader
@@ -263,19 +278,39 @@ class OofHoming extends AbstractServiceTaskProcessor {
cloudIdentity.setIdentityUrl(msbHost + multicloudApiEndpoint
+ "/" + cloudOwner + "/" +
cloudRegionId + "/infra_workload")
-
+ utils.log("DEBUG", "****** Cloud IdentityUrl: " + msbHost + multicloudApiEndpoint
+ + "/" + cloudOwner + "/" +
+ cloudRegionId + "/infra_workload"
+ + " *****", "true")
+ utils.log("DEBUG", "****** CloudIdentity: " + cloudIdentity.toString()
+ + " *****", "true")
cloudSite.setIdentityService(cloudIdentity)
+ utils.log("DEBUG", "****** CloudSite: " + cloudSite.toString()
+ + " *****", "true")
// Set cloudsite in catalog DB here
- oofUtils.createCloudSiteCatalogDb(cloudSite)
+ oofUtils.createCloudSite(cloudSite, execution)
if (oofDirectives != null && oofDirectives != "") {
resource.getHomingSolution().setOofDirectives(oofDirectives)
execution.setVariable("oofDirectives", oofDirectives)
- utils.log("DEBUG", "***** OofDirectives is: " + oofDirectives +
+ utils.log("DEBUG", "***** OofDirectives set to: " + oofDirectives +
" *****", "true")
}
+ // Set Homing Instance
+ String serviceInstanceId = decomposition.getServiceInstance().getInstanceId()
+ HomingInstance homingInstance = new HomingInstance()
+ homingInstance.setServiceInstanceId(serviceInstanceId)
+ homingInstance.setCloudOwner(cloudOwner)
+ homingInstance.setCloudRegionId(cloudRegionId)
+ if (oofDirectives != null && oofDirectives != "") {
+ homingInstance.setOofDirectives(oofDirectives)}
+ else {
+ homingInstance.setOofDirectives("{}")
+ }
+ oofUtils.createHomingInstance(homingInstance, execution)
+
if (inventoryType.equalsIgnoreCase("service")) {
resource.getHomingSolution().setRehome(assignmentMap.get("isRehome").toBoolean())
VnfResource vnf = new VnfResource()
@@ -283,6 +318,12 @@ class OofHoming extends AbstractServiceTaskProcessor {
resource.getHomingSolution().setVnf(vnf)
resource.getHomingSolution().setServiceInstanceId(solution.getJSONArray("identifiers")[0].toString())
}
+ } else {
+ utils.log("DEBUG", "ProcessHomingSolution Exception: no matching serviceResourceIds returned in " +
+ "homing solution", isDebugEnabled)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - " +
+ "Occurred in Homing ProcessHomingSolution: no matching serviceResourceIds returned")
+
}
}
}
@@ -312,8 +353,10 @@ class OofHoming extends AbstractServiceTaskProcessor {
utils.log("DEBUG", "*** Completed Homing Process Homing Solution ***", isDebugEnabled)
} catch (BpmnError b) {
+ utils.log("DEBUG", "ProcessHomingSolution Error: " + b, isDebugEnabled)
throw b
} catch (Exception e) {
+ utils.log("DEBUG", "ProcessHomingSolution Exception: " + e, isDebugEnabled)
msoLogger.error(e);
exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occurred in Homing ProcessHomingSolution")
}
diff --git a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/OofUtils.groovy b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/OofUtils.groovy
index c0da8881fb..af33f38a64 100644
--- a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/OofUtils.groovy
+++ b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/OofUtils.groovy
@@ -36,6 +36,7 @@ import org.onap.so.bpmn.core.json.JsonUtils
import org.onap.so.client.HttpClient
import org.onap.so.client.HttpClientFactory
import org.onap.so.db.catalog.beans.CloudSite
+import org.onap.so.db.catalog.beans.HomingInstance
import org.onap.so.utils.TargetEntity
import org.springframework.http.HttpEntity
import org.springframework.http.HttpHeaders
@@ -495,6 +496,7 @@ class OofUtils {
if (candidatesJson != "") {candidatesJson = candidatesJson.substring(0, candidatesJson.length() - 1)}
return candidatesJson
}
+
/**
* This method creates a cloudsite in catalog database.
*
@@ -524,9 +526,19 @@ class OofUtils {
exceptionUtil.buildAndThrowWorkflowException(execution, responseCode, "Received a Bad Sync Response from CatalogDB.")
}
}
-
+
+ /**
+ * This method creates a HomingInstance in catalog database.
+ *
+ * @param HomingInstance homingInstance
+ *
+ * @return void
+ */
+ Void createHomingInstance(HomingInstance homingInstance, DelegateExecution execution) {
+ oofInfraUtils.createHomingInstance(homingInstance, execution)
+ }
String getMsbHost(DelegateExecution execution) {
- msbHost = UrnPropertiesReader.getVariable("mso.msb.host", execution, "msb-iag.onap")
+ String msbHost = UrnPropertiesReader.getVariable("mso.msb.host", execution, "msb-iag.onap")
Integer msbPort = UrnPropertiesReader.getVariable("mso.msb.port", execution, "80").toInteger()
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 12a4b2a9c3..025b533dc0 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
@@ -20,29 +20,18 @@
package org.onap.so.bpmn.common.resource;
-import java.io.File;
import java.io.IOException;
-import java.nio.file.Paths;
+import java.lang.reflect.Type;
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 javax.ws.rs.core.Response;
import javax.ws.rs.core.UriBuilder;
import org.camunda.bpm.engine.runtime.Execution;
-import org.onap.sdc.tosca.parser.api.ISdcCsarHelper;
-import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException;
-import org.onap.sdc.tosca.parser.impl.SdcToscaParserFactory;
-import org.onap.sdc.toscaparser.api.NodeTemplate;
-import org.onap.sdc.toscaparser.api.Property;
-import org.onap.sdc.toscaparser.api.RequirementAssignment;
-import org.onap.sdc.toscaparser.api.RequirementAssignments;
-import org.onap.sdc.toscaparser.api.functions.GetInput;
-import org.onap.sdc.toscaparser.api.parameters.Input;
import org.onap.so.bpmn.core.UrnPropertiesReader;
import org.onap.so.bpmn.core.json.JsonUtils;
import org.onap.so.client.HttpClient;
@@ -58,86 +47,34 @@ 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 = "/v2/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.
@@ -184,12 +121,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"
@@ -198,91 +131,95 @@ public class ResourceRequestBuilder {
return result;
}
- public static Map<String, Object> buildResouceRequest(String serviceUuid, String resourceCustomizationUuid, Map<String, Object> serviceInputs)
- throws SdcToscaParserException {
-
- Map<String, Object> resouceRequest = new HashMap<>();
-
- String csarpath = null;
+ @SuppressWarnings("unchecked")
+ public static Map<String, Object> buildResouceRequest(String serviceUuid, String resourceCustomizationUuid, Map<String, Object> serviceInputs) {
try {
- csarpath = getCsarFromUuid(serviceUuid);
- } catch(Exception e) {
- LOGGER.debug("csar file is not available for service uuid:" + serviceUuid, e);
- return resouceRequest;
- }
+ Map<String, Object> serviceInstnace = getServiceInstnace(serviceUuid);
- SdcToscaParserFactory toscaParser = SdcToscaParserFactory.getInstance();
- ISdcCsarHelper iSdcCsarHelper = toscaParser.getSdcCsarHelper(csarpath, false);
+ // find match of customization uuid in vnf
+ Map<String, Map<String, Object>> serviceResources = (Map<String, Map<String, Object>>) serviceInstnace.get("serviceResources");
- List<Input> serInput = iSdcCsarHelper.getServiceInputs();
- Optional<NodeTemplate> nodeTemplateOpt = iSdcCsarHelper.getServiceNodeTemplates().stream()
- .filter(e -> e.getMetaData().getValue(CUSTOMIZATION_UUID).equals(resourceCustomizationUuid)).findFirst();
+ List<Map<String, Object>> serviceVnfCust = (List<Map<String, Object>>) serviceResources.get("serviceVnfs");
+ String resourceInputStr = getResourceInputStr(serviceVnfCust, resourceCustomizationUuid);
- if(nodeTemplateOpt.isPresent()) {
- NodeTemplate nodeTemplate = nodeTemplateOpt.get();
- LinkedHashMap<String, Property> resourceProperties = nodeTemplate.getProperties();
+ // find match in network resource
+ if (resourceInputStr == null) {
+ List<Map<String, Object>> serviceNetworkCust = (List<Map<String, Object>>) serviceResources.get("serviceNetworks");
+ resourceInputStr = getResourceInputStr(serviceNetworkCust, resourceCustomizationUuid);
- for(String key : resourceProperties.keySet()) {
- Property property = resourceProperties.get(key);
-
- Object value = getValue(property.getValue(), serviceInputs, serInput);
- resouceRequest.put(key, value);
+ // 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 (resourceInputStr != null || !resourceInputStr.equals("")) {
+ return getResourceInput(resourceInputStr, serviceInputs);
+ }
+
+ } catch (Exception e) {
+ LOGGER.error("not able to retrieve service instance");
}
- return resouceRequest;
+ return new HashMap();
}
- private static Object getValue(Object value, Map<String, Object> serviceInputs, List<Input> servInputs) {
- if(value instanceof Map) {
- Map<String, Object> valueMap = new HashMap<>();
+ private static String getResourceInputStr(List<Map<String, Object>> resources, String resCustomizationUuid) {
- Map<String, Object> propertyMap = (Map<String, Object>)value;
+ for (Map<String, Object> resource : resources) {
+ Map<String, String> modelInfo = (Map<String, String>) resource.get("modelInfo");
- for(String key : propertyMap.keySet()) {
- valueMap.put(key, getValue(propertyMap.get(key), serviceInputs, servInputs));
+ if (modelInfo.get("modelCustomizationUuid").equalsIgnoreCase(resCustomizationUuid)) {
+ return (String) resource.get("resourceInput");
}
- return valueMap; // return if the value is nested hashmap
- } 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
- }
+ }
+ return null;
+ }
+
+ // 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");
- HttpClient client = new HttpClientFactory().newJsonClient(
- UriBuilder.fromUri(catalogEndPoint).path(SERVICE_URL_TOSCA_CSAR).queryParam("serviceModelUuid", uuid).build().toURL(),
- TargetEntity.CATALOG_DB);
-
- client.addAdditionalHeader("Accept", "application/json");
-// client.addBasicAuthHeader (UrnPropertiesReader.getVariable("mso.adapters.db.auth"), UrnPropertiesReader.getVariable("mso.msoKey"));
- client.addAdditionalHeader("Authorization", UrnPropertiesReader.getVariable("mso.db.auth"));
- Response response = client.get();
- String value = response.readEntity(String.class);
+ public static Map<String, Object> getServiceInstnace(String uuid) throws Exception {
+ String catalogEndPoint = UrnPropertiesReader.getVariable("mso.catalog.db.endpoint");
- HashMap<String, String> map = new Gson().fromJson(value, new TypeToken<HashMap<String, String>>() {}.getType());
+ HttpClient client = new HttpClientFactory().newJsonClient(
+ UriBuilder.fromUri(catalogEndPoint).path(SERVICE_URL_SERVICE_INSTANCE).queryParam("serviceModelUuid", uuid).build().toURL(),
+ TargetEntity.CATALOG_DB);
- String filePath = Paths.get(System.getProperty("mso.config.path"), "ASDC", map.get("version"), map.get("name")).normalize().toString();
+ client.addAdditionalHeader("Accept", "application/json");
+ client.addAdditionalHeader("Authorization", UrnPropertiesReader.getVariable("mso.db.auth"));
- File csarFile = new File(filePath);
+ Response apiResponse = client.get();
- if(!csarFile.exists()) {
- throw new Exception("csar file does not exist in filePath:" + csarFile.getAbsolutePath());
- }
+ String value = apiResponse.readEntity(String.class);
- 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/main/java/org/onap/so/bpmn/common/util/OofInfraUtils.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/util/OofInfraUtils.java
new file mode 100644
index 0000000000..df7b57f3a3
--- /dev/null
+++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/util/OofInfraUtils.java
@@ -0,0 +1,112 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2018. Intel Corp. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.so.bpmn.common.util;
+
+import org.camunda.bpm.engine.delegate.DelegateExecution;
+import org.onap.so.bpmn.core.UrnPropertiesReader;
+import org.onap.so.db.catalog.beans.CloudSite;
+import org.onap.so.db.catalog.beans.HomingInstance;
+import org.onap.so.db.catalog.client.CatalogDbClient;
+import org.onap.so.logger.MsoLogger;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.util.Arrays;
+import java.util.Optional;
+
+public class OofInfraUtils {
+
+ private static final MsoLogger LOGGER = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, OofInfraUtils.class);
+
+ /**
+ * This method creates a cloudsite in catalog database.
+ *
+ * @param cloudSite
+ *
+ * @return void
+ */
+ public void createCloudSite(CloudSite cloudSite, DelegateExecution execution) {
+ String endpoint = UrnPropertiesReader.getVariable("mso.catalog.db.spring.endpoint", execution);
+ String auth = UrnPropertiesReader.getVariable("mso.db.auth", execution);
+ try {
+ CloudSite getCloudsite;
+
+ CatalogDbClient client = new CatalogDbClient(endpoint, auth);
+
+ getCloudsite = Optional.ofNullable(client.getCloudSite(cloudSite.getId(), endpoint + "/cloudSite/")).orElse(new CloudSite());
+ if (!cloudSite.getId().equals(getCloudsite.getId())) {
+ client.postCloudSite(cloudSite);
+ LOGGER.debug("Did not findd cloudsite : " + cloudSite.getId());
+ LOGGER.debug("Will create cloudSite: " + cloudSite.toString());
+ }
+ else {
+ LOGGER.debug("Found cloudsite : " + cloudSite.getId());
+ LOGGER.debug("Will not create cloudSite: " + cloudSite.toString());
+ }
+ } catch (Exception e) {
+ LOGGER.debug("Error looking up or creating cloudsite : " + cloudSite.getId());
+ LOGGER.debug("CloudSite Lookup/Creation Error: " + e);
+ }
+
+
+ }
+
+ /**
+ * This method creates a HomingInstance in catalog database.
+ *
+ * @param homingInstance
+ *
+ * @return void
+ */
+ public void createHomingInstance(HomingInstance homingInstance, DelegateExecution execution) {
+ String endpoint = UrnPropertiesReader.getVariable("mso.catalog.db.spring.endpoint", execution);
+ String auth = UrnPropertiesReader.getVariable("mso.db.auth", execution);
+
+ CatalogDbClient client = new CatalogDbClient(endpoint, auth);
+ try {
+ client.postHomingInstance(homingInstance);
+ } catch (Exception exception) {
+ LOGGER.debug("Could not create HomingInstance : " + homingInstance.getServiceInstanceId());
+ LOGGER.debug("HomingInstance Creation Error: " + exception);
+ }
+
+ }
+
+ /**
+ * This method gets a HomingInstance in catalog database.
+ *
+ * @param serviceInstanceId
+ *
+ * @return HomingInstance
+ */
+ public HomingInstance getHomingInstance(String serviceInstanceId, DelegateExecution execution) {
+ String endpoint = UrnPropertiesReader.getVariable("mso.catalog.db.spring.endpoint", execution);
+ String auth = UrnPropertiesReader.getVariable("mso.db.auth", execution);
+
+ CatalogDbClient client = new CatalogDbClient(endpoint, auth);
+ try {
+ return client.getHomingInstance(serviceInstanceId, endpoint + "/homingInstance/");
+ } catch (Exception exception) {
+ LOGGER.debug("Could not get HomingInstance for serviceInstanceId : " + serviceInstanceId);
+ LOGGER.debug("Get HomingInstance Error: " + exception);
+ }
+ return null;
+ }
+}