diff options
author | Smokowski, Steve (ss835w) <ss835w@us.att.com> | 2018-12-06 16:52:59 -0500 |
---|---|---|
committer | Smokowski, Steve (ss835w) <ss835w@us.att.com> | 2018-12-10 09:33:25 -0500 |
commit | 264e0c009955ed10a656ba4d4e7f7bbf00dadbb5 (patch) | |
tree | f653e73740b7cecfacbf43129ac118a6f4f2c8af /bpmn/so-bpmn-tasks/src/main/java/org/onap | |
parent | 3b56cf0c1763c45b7673a087107c5e1553dd4f40 (diff) |
VNF Recreate
renamed util class to workflowaction extractresourceaai
added junit test for grapi on a vnf level macro flow
added component to workflowactionutils helper class
added functionality for gr api to run vnf level flows
Change-Id: Ie2e53b10df99c5a15008a380f89c835ca49bb5d5
Issue-ID: SO-1293
Signed-off-by: Smokowski, Steve (ss835w) <ss835w@us.att.com>
Diffstat (limited to 'bpmn/so-bpmn-tasks/src/main/java/org/onap')
2 files changed, 109 insertions, 1 deletions
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java index 294fd56cfd..4eb4ffec2f 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java @@ -50,6 +50,10 @@ import org.onap.so.bpmn.servicedecomposition.entities.WorkflowResourceIds; import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetup; import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetupUtils; import org.onap.so.bpmn.infrastructure.workflow.tasks.Resource; +import org.onap.so.client.aai.AAICommonObjectMapperProvider; +import org.onap.so.client.aai.AAIObjectType; +import org.onap.so.client.aai.entities.AAIResultWrapper; +import org.onap.so.client.aai.entities.Relationships; import org.onap.so.client.exception.ExceptionBuilder; import org.onap.so.client.orchestration.AAIConfigurationResources; import org.onap.so.db.catalog.beans.CollectionNetworkResourceCustomization; @@ -121,7 +125,10 @@ public class WorkflowAction { @Autowired private AAIConfigurationResources aaiConfigurationResources; @Autowired - private Environment environment; + private WorkflowActionExtractResourcesAAI workflowActionUtils; + + @Autowired + private Environment environment; private String defaultCloudOwner = "org.onap.so.cloud-owner"; public void setBbInputSetupUtils(BBInputSetupUtils bbInputSetupUtils) { @@ -249,6 +256,8 @@ public class WorkflowAction { } else if (resourceType == WorkflowType.SERVICE && requestAction.equalsIgnoreCase("deactivateInstance")) { resourceCounter.add(new Resource(WorkflowType.SERVICE,"",false)); + } else if (resourceType == WorkflowType.VNF && (requestAction.equalsIgnoreCase("replaceInstance") || (requestAction.equalsIgnoreCase("recreateInstance")))) { + traverseAAIVnf(execution, resourceCounter, workflowResourceIds.getServiceInstanceId(), workflowResourceIds.getVnfId(), aaiResourceIds); } else { buildAndThrowException(execution, "Current Macro Request is not supported"); } @@ -550,6 +559,67 @@ public class WorkflowAction { } } + private void traverseAAIVnf(DelegateExecution execution, List<Resource> resourceCounter, String serviceId, String vnfId, + List<Pair<WorkflowType, String>> aaiResourceIds) { + try{ + ServiceInstance serviceInstanceAAI = bbInputSetupUtils.getAAIServiceInstanceById(serviceId); + org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance serviceInstanceMSO = bbInputSetup + .getExistingServiceInstance(serviceInstanceAAI); + resourceCounter.add(new Resource(WorkflowType.SERVICE,serviceInstanceMSO.getServiceInstanceId(),false)); + if (serviceInstanceMSO.getVnfs() != null) { + for (org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf vnf : serviceInstanceMSO + .getVnfs()) { + if(vnf.getVnfId().equals(vnfId)){ + aaiResourceIds.add(new Pair<WorkflowType, String>(WorkflowType.VNF, vnf.getVnfId())); + resourceCounter.add(new Resource(WorkflowType.VNF,vnf.getVnfId(),false)); + if (vnf.getVfModules() != null) { + for (VfModule vfModule : vnf.getVfModules()) { + aaiResourceIds.add(new Pair<WorkflowType, String>(WorkflowType.VFMODULE, vfModule.getVfModuleId())); + resourceCounter.add(new Resource(WorkflowType.VFMODULE,vfModule.getVfModuleId(),false)); + findConfigurationsInsideVfModule(execution, vnf.getVnfId(), vfModule.getVfModuleId(), resourceCounter, aaiResourceIds); + } + } + if (vnf.getVolumeGroups() != null) { + for (org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup volumeGroup : vnf + .getVolumeGroups()) { + aaiResourceIds.add(new Pair<WorkflowType, String>(WorkflowType.VOLUMEGROUP, volumeGroup.getVolumeGroupId())); + resourceCounter.add(new Resource(WorkflowType.VOLUMEGROUP,volumeGroup.getVolumeGroupId(),false)); + } + } + break; + } + } + } + } catch (Exception ex) { + buildAndThrowException(execution, + "Could not find existing Vnf or related Instances to execute the request on."); + } + } + + private void findConfigurationsInsideVfModule(DelegateExecution execution, String vnfId, String vfModuleId, List<Resource> resourceCounter, + List<Pair<WorkflowType, String>> aaiResourceIds) { + try{ + org.onap.aai.domain.yang.VfModule aaiVfModule = bbInputSetupUtils.getAAIVfModule(vnfId, vfModuleId); + AAIResultWrapper vfModuleWrapper = new AAIResultWrapper( + new AAICommonObjectMapperProvider().getMapper().writeValueAsString(aaiVfModule)); + Optional<Relationships> relationshipsOp; + relationshipsOp = vfModuleWrapper.getRelationships(); + if(relationshipsOp.isPresent()) { + relationshipsOp = workflowActionUtils.extractRelationshipsVnfc(relationshipsOp.get()); + if(relationshipsOp.isPresent()){ + Optional<Configuration> config = workflowActionUtils.extractRelationshipsConfiguration(relationshipsOp.get()); + if(config.isPresent()){ + aaiResourceIds.add(new Pair<WorkflowType, String>(WorkflowType.CONFIGURATION, config.get().getConfigurationId())); + resourceCounter.add(new Resource(WorkflowType.CONFIGURATION, config.get().getConfigurationId(), false)); + } + } + } + }catch (Exception ex){ + buildAndThrowException(execution, + "Failed to find Configuration object from the vfModule."); + } + } + protected boolean traverseUserParamsService(DelegateExecution execution, List<Resource> resourceCounter, ServiceInstancesRequest sIRequest, String requestAction) throws IOException { diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionExtractResourcesAAI.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionExtractResourcesAAI.java new file mode 100644 index 0000000000..81609d1ddd --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionExtractResourcesAAI.java @@ -0,0 +1,38 @@ +package org.onap.so.bpmn.infrastructure.workflow.tasks; + +import java.util.List; +import java.util.Optional; + +import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration; +import org.onap.so.client.aai.AAIObjectType; +import org.onap.so.client.aai.entities.AAIResultWrapper; +import org.onap.so.client.aai.entities.Relationships; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; + +@Component +public class WorkflowActionExtractResourcesAAI { + private static final Logger logger = LoggerFactory.getLogger(WorkflowActionExtractResourcesAAI.class); + + public Optional<Configuration> extractRelationshipsConfiguration(Relationships relationships) { + List<AAIResultWrapper> configurations = relationships.getByType(AAIObjectType.CONFIGURATION); + for(AAIResultWrapper configWrapper : configurations) { + Optional<Configuration> config = configWrapper.asBean(Configuration.class); + if(config.isPresent()){ + return config; + } + } + return Optional.empty(); + } + + public Optional<Relationships> extractRelationshipsVnfc(Relationships relationships) { + List<AAIResultWrapper> vnfcs = relationships.getByType(AAIObjectType.VNFC); + for(AAIResultWrapper vnfcWrapper : vnfcs){ + if(vnfcWrapper.getRelationships().isPresent()){ + return vnfcWrapper.getRelationships(); + } + } + return Optional.empty(); + } +} |