summaryrefslogtreecommitdiffstats
path: root/bpmn
diff options
context:
space:
mode:
authorYulian Han <elaine.hanyulian@huawei.com>2018-10-09 12:50:59 +0800
committerSeshu Kumar M <seshu.kumar.m@huawei.com>2018-10-09 08:50:27 +0000
commit9f8d92bde51a5c567a4d60011c4dec11661b338b (patch)
tree58d0f0ab88e63b45626b67f6fa2b6605591ded4c /bpmn
parent8db7966a2de1a1f5ed7238a4a5c948a624681505 (diff)
E2EService support model-driven resource sequence
Change-Id: Idaa55084f5ecb0dd3636c232cebc14fa5f064401 Issue-ID: SO-1114 Signed-off-by: Yulian Han <elaine.hanyulian@huawei.com>
Diffstat (limited to 'bpmn')
-rw-r--r--bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/resource/ResourceRequestBuilder.java81
-rw-r--r--bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateResources.groovy281
2 files changed, 220 insertions, 142 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 35bd25fabf..0cce8b3f94 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
@@ -38,6 +38,8 @@ 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;
@@ -63,15 +65,88 @@ public class ResourceRequestBuilder {
static JsonUtils jsonUtil = new JsonUtils();
- /**
- * build the resource Parameters detail.
+ 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;
+ }
+
+ 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;
+ }
+
+ /* build the resource Parameters detail.
* It's a json string for resource instantiant
* {
* "locationConstraints":[...]
* "requestInputs":{K,V}
* }
* <br>
- *
+ *
* @param execution Execution context
* @param serviceUuid The service template uuid
* @param resourceCustomizationUuid The resource customization uuid
diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateResources.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateResources.groovy
index 482da23b33..2167025e18 100644
--- a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateResources.groovy
+++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateResources.groovy
@@ -17,7 +17,7 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
+
package org.onap.so.bpmn.infrastructure.scripts
import org.onap.so.bpmn.infrastructure.properties.BPMNProperties
@@ -69,41 +69,37 @@ import org.onap.so.logger.MsoLogger
*
* Outputs:
* @param - WorkflowException
-
*/
public class DoCreateResources extends AbstractServiceTaskProcessor{
- private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, DoCreateResources.class);
+ private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, DoCreateResources.class);
+
+ ExceptionUtil exceptionUtil = new ExceptionUtil()
+ JsonUtils jsonUtil = new JsonUtils()
+ CatalogDbUtils cutils = new CatalogDbUtils()
- ExceptionUtil exceptionUtil = new ExceptionUtil()
- JsonUtils jsonUtil = new JsonUtils()
- CatalogDbUtils cutils = new CatalogDbUtils()
+ public void preProcessRequest(DelegateExecution execution) {
+ msoLogger.trace("preProcessRequest ")
+ String msg = ""
- public void preProcessRequest(DelegateExecution execution)
- {
- msoLogger.trace("preProcessRequest ")
- String msg = ""
-
List addResourceList = execution.getVariable("addResourceList")
- if (addResourceList == null)
- {
+ if (addResourceList == null) {
msg = "Input addResourceList is null"
msoLogger.info(msg)
- exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
}
- else if (addResourceList.size() == 0)
- {
+ else if (addResourceList.size() == 0) {
msg = "No resource in addResourceList"
msoLogger.info(msg)
}
msoLogger.trace("Exit preProcessRequest ")
}
-
- public void sequenceResoure(DelegateExecution execution)
- {
+
+ public void sequenceResoure(DelegateExecution execution) {
msoLogger.trace("Start sequenceResoure Process ")
- String serviceModelUUID = execution.getVariable("modelUuid")
-
+ String incomingRequest = execution.getVariable("uuiRequest")
+ String serviceModelUuid = jsonUtil.getJsonValue(incomingRequest,"service.serviceUuid")
+
List<Resource> addResourceList = execution.getVariable("addResourceList")
List<NetworkResource> networkResourceList = new ArrayList<NetworkResource>()
@@ -112,40 +108,47 @@ public class DoCreateResources extends AbstractServiceTaskProcessor{
String serviceDecompose = execution.getVariable("serviceDecomposition")
String serviceModelName = jsonUtil.getJsonValue(serviceDecompose, "serviceResources.modelInfo.modelName")
+
+ // get Sequence from properties
def resourceSequence = BPMNProperties.getResourceSequenceProp(serviceModelName)
+ // get Sequence from csar(model)
+ if(resourceSequence == null) {
+ resourceSequence = ResourceRequestBuilder.getResourceSequence(execution, serviceModelUuid)
+ msoLogger.info("Get Sequence from csar : " + resourceSequence)
+ }
+
if(resourceSequence != null) {
- // sequence is defined in config file
- for (resourceType in resourceSequence) {
- for (resource in addResourceList) {
- if (StringUtils.containsIgnoreCase(resource.getModelInfo().getModelName(), resourceType)) {
- sequencedResourceList.add(resource)
-
- if (resource instanceof NetworkResource) {
- networkResourceList.add(resource)
+ for (resourceType in resourceSequence) {
+ for (resource in addResourceList) {
+ if (StringUtils.containsIgnoreCase(resource.getModelInfo().getModelName(), resourceType)) {
+ sequencedResourceList.add(resource)
+
+ if (resource instanceof NetworkResource) {
+ networkResourceList.add(resource)
+ }
}
}
}
- }
} else {
-
- //define sequenced resource list, we deploy vf first and then network and then ar
- //this is defaule sequence
- List<VnfResource> vnfResourceList = new ArrayList<VnfResource>()
- List<AllottedResource> arResourceList = new ArrayList<AllottedResource>()
-
- for (Resource rc : addResourceList){
- if (rc instanceof VnfResource) {
- vnfResourceList.add(rc)
- } else if (rc instanceof NetworkResource) {
- networkResourceList.add(rc)
- } else if (rc instanceof AllottedResource) {
- arResourceList.add(rc)
+
+ //define sequenced resource list, we deploy vf first and then network and then ar
+ //this is defaule sequence
+ List<VnfResource> vnfResourceList = new ArrayList<VnfResource>()
+ List<AllottedResource> arResourceList = new ArrayList<AllottedResource>()
+
+ for (Resource rc : addResourceList){
+ if (rc instanceof VnfResource) {
+ vnfResourceList.add(rc)
+ } else if (rc instanceof NetworkResource) {
+ networkResourceList.add(rc)
+ } else if (rc instanceof AllottedResource) {
+ arResourceList.add(rc)
+ }
}
- }
- sequencedResourceList.addAll(vnfResourceList)
- sequencedResourceList.addAll(networkResourceList)
- sequencedResourceList.addAll(arResourceList)
+ sequencedResourceList.addAll(vnfResourceList)
+ sequencedResourceList.addAll(networkResourceList)
+ sequencedResourceList.addAll(arResourceList)
}
String isContainsWanResource = networkResourceList.isEmpty() ? "false" : "true"
@@ -154,11 +157,11 @@ public class DoCreateResources extends AbstractServiceTaskProcessor{
String serviceNeedSDNC = "mso.workflow.custom." + serviceModelName + ".sdnc.need";
isContainsWanResource = BPMNProperties.getProperty(serviceNeedSDNC, isContainsWanResource)
}
-
+
execution.setVariable("isContainsWanResource", isContainsWanResource)
execution.setVariable("currentResourceIndex", 0)
execution.setVariable("sequencedResourceList", sequencedResourceList)
- msoLogger.info("sequencedResourceList: " + sequencedResourceList)
+ msoLogger.info("sequencedResourceList: " + sequencedResourceList)
msoLogger.trace("COMPLETED sequenceResoure Process ")
}
@@ -181,105 +184,105 @@ public class DoCreateResources extends AbstractServiceTaskProcessor{
msoLogger.trace("======== End prepareServiceTopologyRequest Process ======== ")
}
-
+
public void getCurrentResoure(DelegateExecution execution){
- msoLogger.trace("Start getCurrentResoure Process ")
- def currentIndex = execution.getVariable("currentResourceIndex")
- List<Resource> sequencedResourceList = execution.getVariable("sequencedResourceList")
- Resource currentResource = sequencedResourceList.get(currentIndex)
- execution.setVariable("resourceType", currentResource.getModelInfo().getModelName())
- msoLogger.info("Now we deal with resouce:" + currentResource.getModelInfo().getModelName())
- msoLogger.trace("COMPLETED getCurrentResoure Process ")
+ msoLogger.trace("Start getCurrentResoure Process ")
+ def currentIndex = execution.getVariable("currentResourceIndex")
+ List<Resource> sequencedResourceList = execution.getVariable("sequencedResourceList")
+ Resource currentResource = sequencedResourceList.get(currentIndex)
+ execution.setVariable("resourceType", currentResource.getModelInfo().getModelName())
+ msoLogger.info("Now we deal with resouce:" + currentResource.getModelInfo().getModelName())
+ msoLogger.trace("COMPLETED getCurrentResoure Process ")
}
-
+
public void parseNextResource(DelegateExecution execution){
- msoLogger.trace("Start parseNextResource Process ")
+ msoLogger.trace("Start parseNextResource Process ")
def currentIndex = execution.getVariable("currentResourceIndex")
def nextIndex = currentIndex + 1
execution.setVariable("currentResourceIndex", nextIndex)
- List<String> sequencedResourceList = execution.getVariable("sequencedResourceList")
+ List<String> sequencedResourceList = execution.getVariable("sequencedResourceList")
if(nextIndex >= sequencedResourceList.size()){
execution.setVariable("allResourceFinished", "true")
}else{
execution.setVariable("allResourceFinished", "false")
}
- msoLogger.trace("COMPLETED parseNextResource Process ")
- }
-
- public void prepareResourceRecipeRequest(DelegateExecution execution){
- msoLogger.trace("Start prepareResourceRecipeRequest Process ")
- ResourceInput resourceInput = new ResourceInput()
- String serviceInstanceName = execution.getVariable("serviceInstanceName")
- String resourceType = execution.getVariable("resourceType")
- String resourceInstanceName = resourceType + "_" + serviceInstanceName
- resourceInput.setResourceInstanceName(resourceInstanceName)
- msoLogger.info("Prepare Resource Request resourceInstanceName:" + resourceInstanceName)
- String globalSubscriberId = execution.getVariable("globalSubscriberId")
- String serviceType = execution.getVariable("serviceType")
- String serviceInstanceId = execution.getVariable("serviceInstanceId")
- String operationId = execution.getVariable("operationId")
- String operationType = "createInstance"
- resourceInput.setGlobalSubscriberId(globalSubscriberId)
- resourceInput.setServiceType(serviceType)
- resourceInput.setServiceInstanceId(serviceInstanceId)
- resourceInput.setOperationId(operationId)
- resourceInput.setOperationType(operationType);
- def currentIndex = execution.getVariable("currentResourceIndex")
- List<Resource> sequencedResourceList = execution.getVariable("sequencedResourceList")
- Resource currentResource = sequencedResourceList.get(currentIndex)
- resourceInput.setResourceModelInfo(currentResource.getModelInfo());
- ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
- resourceInput.setServiceModelInfo(serviceDecomposition.getModelInfo());
- def String resourceCustomizationUuid = currentResource.getModelInfo().getModelCustomizationUuid();
-
- String incomingRequest = execution.getVariable("uuiRequest")
- //set the requestInputs from tempalte To Be Done
- String serviceModelUuid = jsonUtil.getJsonValue(incomingRequest,"service.serviceUuid")
- String serviceParameters = jsonUtil.getJsonValue(incomingRequest, "service.parameters")
- String resourceParameters = ResourceRequestBuilder.buildResourceRequestParameters(execution, serviceModelUuid, resourceCustomizationUuid, serviceParameters)
- resourceInput.setResourceParameters(resourceParameters)
- resourceInput.setRequestsInputs(incomingRequest)
- execution.setVariable("resourceInput", resourceInput)
- msoLogger.trace("COMPLETED prepareResourceRecipeRequest Process ")
- }
-
- public void executeResourceRecipe(DelegateExecution execution){
- msoLogger.trace("Start executeResourceRecipe Process ")
-
- try {
- String requestId = execution.getVariable("msoRequestId")
- String serviceInstanceId = execution.getVariable("serviceInstanceId")
- String serviceType = execution.getVariable("serviceType")
- ResourceInput resourceInput = execution.getVariable("resourceInput")
-
- // requestAction is action, not opertiontype
- //String requestAction = resourceInput.getOperationType()
- String requestAction = "createInstance"
- JSONObject resourceRecipe = cutils.getResourceRecipe(execution, resourceInput.getResourceModelInfo().getModelUuid(), requestAction)
-
- if (resourceRecipe != null) {
- String recipeURL = BPMNProperties.getProperty("bpelURL", "http://mso:8080") + resourceRecipe.getString("orchestrationUri")
- int recipeTimeOut = resourceRecipe.getInt("recipeTimeout")
- String recipeParamXsd = resourceRecipe.get("paramXSD")
- HttpResponse resp = BpmnRestClient.post(recipeURL, requestId, recipeTimeOut, requestAction, serviceInstanceId, serviceType, resourceInput.toString(), recipeParamXsd)
- } else {
- String exceptionMessage = "Resource receipe is not found for resource modeluuid: " +
- resourceInput.getResourceModelInfo().getModelUuid()
- msoLogger.trace(exceptionMessage)
- exceptionUtil.buildAndThrowWorkflowException(execution, 500, exceptionMessage)
- }
-
- msoLogger.trace("======== end executeResourceRecipe Process ======== ")
- }catch(BpmnError b){
- msoLogger.debug("Rethrowing MSOWorkflowException")
- throw b
- }catch(Exception e){
- msoLogger.debug("Error occured within DoCreateResources executeResourceRecipe method: " + e)
- exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured during DoCreateResources executeResourceRecipe Catalog")
- }
- }
-
- public void postConfigRequest(DelegateExecution execution){
- //now do noting
- }
+ msoLogger.trace("COMPLETED parseNextResource Process ")
+ }
+
+ public void prepareResourceRecipeRequest(DelegateExecution execution){
+ msoLogger.trace("Start prepareResourceRecipeRequest Process ")
+ ResourceInput resourceInput = new ResourceInput()
+ String serviceInstanceName = execution.getVariable("serviceInstanceName")
+ String resourceType = execution.getVariable("resourceType")
+ String resourceInstanceName = resourceType + "_" + serviceInstanceName
+ resourceInput.setResourceInstanceName(resourceInstanceName)
+ msoLogger.info("Prepare Resource Request resourceInstanceName:" + resourceInstanceName)
+ String globalSubscriberId = execution.getVariable("globalSubscriberId")
+ String serviceType = execution.getVariable("serviceType")
+ String serviceInstanceId = execution.getVariable("serviceInstanceId")
+ String operationId = execution.getVariable("operationId")
+ String operationType = "createInstance"
+ resourceInput.setGlobalSubscriberId(globalSubscriberId)
+ resourceInput.setServiceType(serviceType)
+ resourceInput.setServiceInstanceId(serviceInstanceId)
+ resourceInput.setOperationId(operationId)
+ resourceInput.setOperationType(operationType);
+ def currentIndex = execution.getVariable("currentResourceIndex")
+ List<Resource> sequencedResourceList = execution.getVariable("sequencedResourceList")
+ Resource currentResource = sequencedResourceList.get(currentIndex)
+ resourceInput.setResourceModelInfo(currentResource.getModelInfo());
+ ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
+ resourceInput.setServiceModelInfo(serviceDecomposition.getModelInfo());
+ def String resourceCustomizationUuid = currentResource.getModelInfo().getModelCustomizationUuid();
+
+ String incomingRequest = execution.getVariable("uuiRequest")
+ //set the requestInputs from tempalte To Be Done
+ String serviceModelUuid = jsonUtil.getJsonValue(incomingRequest,"service.serviceUuid")
+ String serviceParameters = jsonUtil.getJsonValue(incomingRequest, "service.parameters")
+ String resourceParameters = ResourceRequestBuilder.buildResourceRequestParameters(execution, serviceModelUuid, resourceCustomizationUuid, serviceParameters)
+ resourceInput.setResourceParameters(resourceParameters)
+ resourceInput.setRequestsInputs(incomingRequest)
+ execution.setVariable("resourceInput", resourceInput)
+ msoLogger.trace("COMPLETED prepareResourceRecipeRequest Process ")
+ }
+
+ public void executeResourceRecipe(DelegateExecution execution){
+ msoLogger.trace("Start executeResourceRecipe Process ")
+
+ try {
+ String requestId = execution.getVariable("msoRequestId")
+ String serviceInstanceId = execution.getVariable("serviceInstanceId")
+ String serviceType = execution.getVariable("serviceType")
+ ResourceInput resourceInput = execution.getVariable("resourceInput")
+
+ // requestAction is action, not opertiontype
+ //String requestAction = resourceInput.getOperationType()
+ String requestAction = "createInstance"
+ JSONObject resourceRecipe = cutils.getResourceRecipe(execution, resourceInput.getResourceModelInfo().getModelUuid(), requestAction)
+
+ if (resourceRecipe != null) {
+ String recipeURL = BPMNProperties.getProperty("bpelURL", "http://mso:8080") + resourceRecipe.getString("orchestrationUri")
+ int recipeTimeOut = resourceRecipe.getInt("recipeTimeout")
+ String recipeParamXsd = resourceRecipe.get("paramXSD")
+ HttpResponse resp = BpmnRestClient.post(recipeURL, requestId, recipeTimeOut, requestAction, serviceInstanceId, serviceType, resourceInput.toString(), recipeParamXsd)
+ } else {
+ String exceptionMessage = "Resource receipe is not found for resource modeluuid: " +
+ resourceInput.getResourceModelInfo().getModelUuid()
+ msoLogger.trace(exceptionMessage)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 500, exceptionMessage)
+ }
+
+ msoLogger.trace("======== end executeResourceRecipe Process ======== ")
+ }catch(BpmnError b){
+ msoLogger.debug("Rethrowing MSOWorkflowException")
+ throw b
+ }catch(Exception e){
+ msoLogger.debug("Error occured within DoCreateResources executeResourceRecipe method: " + e)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured during DoCreateResources executeResourceRecipe Catalog")
+ }
+ }
+
+ public void postConfigRequest(DelegateExecution execution){
+ //now do noting
+ }
}