diff options
Diffstat (limited to 'bpmn/so-bpmn-tasks/src/main/java')
4 files changed, 143 insertions, 2 deletions
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIDeleteTasks.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIDeleteTasks.java index d62fc6f50f..f3ee2a69b0 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIDeleteTasks.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIDeleteTasks.java @@ -36,6 +36,7 @@ import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration; import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; import org.onap.so.bpmn.servicedecomposition.bbobjects.InstanceGroup; import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network; +import org.onap.so.bpmn.servicedecomposition.bbobjects.Pnf; import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule; import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup; @@ -48,6 +49,7 @@ import org.onap.so.client.orchestration.AAINetworkResources; import org.onap.so.client.orchestration.AAIServiceInstanceResources; import org.onap.so.client.orchestration.AAIVfModuleResources; import org.onap.so.client.orchestration.AAIVnfResources; +import org.onap.so.client.orchestration.AAIPnfResources; import org.onap.so.client.orchestration.AAIVolumeGroupResources; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -70,6 +72,8 @@ public class AAIDeleteTasks { @Autowired private AAIVnfResources aaiVnfResources; @Autowired + private AAIPnfResources aaiPnfResources; + @Autowired private AAIVfModuleResources aaiVfModuleResources; @Autowired private AAINetworkResources aaiNetworkResources; @@ -127,6 +131,20 @@ public class AAIDeleteTasks { } } + + + public void deletePnf(BuildingBlockExecution execution) throws Exception { + Pnf pnf = extractPojosForBB.extractByKey(execution, ResourceKey.PNF); + execution.setVariable("aaiPnfRollback", false); + try { + aaiPnfResources.deletePnf(pnf); + execution.setVariable("aaiPnfRollback", true); + } catch (Exception ex) { + logger.error("Exception occurred in AAIDeleteTasks deletePnf process", ex); + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex); + } + } + /** * BPMN access method to delete the ServiceInstance from A&AI. * 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 35e11963a3..64e623ba98 100755 --- 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 @@ -71,6 +71,7 @@ import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory; import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder; import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types; import org.onap.so.bpmn.common.BBConstants; +import org.onap.so.bpmn.infrastructure.workflow.tasks.ebb.loader.PnfEBBLoader; import org.onap.so.bpmn.infrastructure.workflow.tasks.ebb.loader.ServiceEBBLoader; import org.onap.so.bpmn.infrastructure.workflow.tasks.ebb.loader.VnfEBBLoader; import org.onap.so.bpmn.infrastructure.workflow.tasks.excpetion.VnfcMultipleRelationshipException; @@ -111,7 +112,7 @@ public class WorkflowAction { private static final String VNF_TYPE = "vnfType"; private static final String CONFIGURATION = "Configuration"; private static final String SUPPORTEDTYPES = - "vnfs|vfModules|networks|networkCollections|volumeGroups|serviceInstances|instanceGroups"; + "vnfs|pnfs|vfModules|networks|networkCollections|volumeGroups|serviceInstances|instanceGroups"; private static final String HOMINGSOLUTION = "Homing_Solution"; private static final String SERVICE_TYPE_TRANSPORT = "TRANSPORT"; private static final String SERVICE_TYPE_BONDING = "BONDING"; @@ -140,6 +141,8 @@ public class WorkflowAction { @Autowired private VnfEBBLoader vnfEBBLoader; @Autowired + private PnfEBBLoader pnfEBBLoader; + @Autowired private ServiceEBBLoader serviceEBBLoader; public void setBbInputSetupUtils(BBInputSetupUtils bbInputSetupUtils) { @@ -293,9 +296,13 @@ public class WorkflowAction { List<Resource> resourceList = new ArrayList<>(); List<Pair<WorkflowType, String>> aaiResourceIds = new ArrayList<>(); - if (resourceType == WorkflowType.SERVICE || isVNFCreate(resourceType, requestAction)) { + if (resourceType == WorkflowType.SERVICE || isVNFCreate(resourceType, requestAction) + || isPNFCreate(resourceType, requestAction)) { resourceList = serviceEBBLoader.getResourceListForService(sIRequest, requestAction, execution, serviceInstanceId, resourceId, aaiResourceIds); + } else if (isPNFDelete(resourceType, requestAction)) { + pnfEBBLoader.traverseAAIPnf(execution, resourceList, workflowResourceIds.getServiceInstanceId(), resourceId, + aaiResourceIds); } else if (resourceType == WorkflowType.VNF && (DELETE_INSTANCE.equalsIgnoreCase(requestAction) || REPLACEINSTANCE.equalsIgnoreCase(requestAction) || (RECREATE_INSTANCE.equalsIgnoreCase(requestAction)))) { @@ -388,6 +395,16 @@ public class WorkflowAction { return resourceType == WorkflowType.VNF && CREATE_INSTANCE.equalsIgnoreCase(requestAction); } + + private boolean isPNFCreate(WorkflowType resourceType, String requestAction) { + return resourceType == WorkflowType.PNF && CREATE_INSTANCE.equalsIgnoreCase(requestAction); + } + + + private boolean isPNFDelete(WorkflowType resourceType, String requestAction) { + return resourceType == WorkflowType.PNF && DELETE_INSTANCE.equalsIgnoreCase(requestAction); + } + private void setExecutionVariables(DelegateExecution execution, List<ExecuteBuildingBlock> flowsToExecute, List<String> flowNames) { execution.setVariable("flowNames", flowNames); diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/PnfEBBLoader.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/PnfEBBLoader.java new file mode 100644 index 0000000000..761219c6be --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/PnfEBBLoader.java @@ -0,0 +1,100 @@ +package org.onap.so.bpmn.infrastructure.workflow.tasks.ebb.loader; + +import org.camunda.bpm.engine.delegate.DelegateExecution; +import org.javatuples.Pair; +import org.onap.aai.domain.yang.Relationship; +import org.onap.aai.domain.yang.RelationshipData; +import org.onap.so.bpmn.infrastructure.workflow.tasks.Resource; +import org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowType; +import org.onap.so.bpmn.servicedecomposition.bbobjects.Pnf; +import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; +import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetup; +import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetupUtils; +import org.onap.so.client.exception.ExceptionBuilder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; +import java.util.List; +import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.WORKFLOW_ACTION_ERROR_MESSAGE; + +@Component +public class PnfEBBLoader { + + private static final Logger logger = LoggerFactory.getLogger(PnfEBBLoader.class); + + private final BBInputSetupUtils bbInputSetupUtils; + private final BBInputSetup bbInputSetup; + private final WorkflowActionExtractResourcesAAI workflowActionUtils; + private final ExceptionBuilder exceptionBuilder; + + PnfEBBLoader(BBInputSetupUtils bbInputSetupUtils, BBInputSetup bbInputSetup, + WorkflowActionExtractResourcesAAI workflowActionUtils, ExceptionBuilder exceptionBuilder) { + this.bbInputSetupUtils = bbInputSetupUtils; + this.bbInputSetup = bbInputSetup; + this.workflowActionUtils = workflowActionUtils; + this.exceptionBuilder = exceptionBuilder; + } + + + public void traverseAAIPnf(DelegateExecution execution, List<Resource> resourceList, String serviceId, String pnfId, + List<Pair<WorkflowType, String>> aaiResourceIds) { + try { + String pN = null; + org.onap.aai.domain.yang.ServiceInstance serviceInstanceAAI = + bbInputSetupUtils.getAAIServiceInstanceById(serviceId); + List<Relationship> relationship = serviceInstanceAAI.getRelationshipList().getRelationship(); + List<RelationshipData> relationshipData; + org.onap.aai.domain.yang.Pnf pnf = null; + outerLoop: for (Relationship r : relationship) { + if (r.getRelatedTo().equalsIgnoreCase("pnf")) { + relationshipData = r.getRelationshipData(); + for (RelationshipData rd : relationshipData) { + if (rd.getRelationshipKey().equalsIgnoreCase("pnf.pnf-name")) { + pN = rd.getRelationshipValue(); + pnf = bbInputSetupUtils.getAAIPnf(pN); + if (pnf.getPnfId().equalsIgnoreCase(pnfId)) { + break outerLoop; + } + } + } + } + + } + ServiceInstance serviceInstanceMSO = bbInputSetup.getExistingServiceInstance(serviceInstanceAAI); + Resource serviceResource = + new Resource(WorkflowType.SERVICE, serviceInstanceAAI.getServiceInstanceId(), false, null); + resourceList.add(serviceResource); + if (serviceInstanceMSO.getPnfs() != null) { + findPnfWithGivenId(serviceInstanceMSO, pN, aaiResourceIds, resourceList, serviceResource); + } + } catch (Exception ex) { + logger.error("Exception in traverseAAIPnf", ex); + buildAndThrowException(execution, + "Could not find existing Pnf or related Instances to execute the request on."); + } + } + + + private void findPnfWithGivenId(ServiceInstance serviceInstanceMSO, String pName, + List<Pair<WorkflowType, String>> aaiResourceIds, List<Resource> resourceList, Resource serviceResource) { + for (Pnf pnf : serviceInstanceMSO.getPnfs()) { + if (pnf.getPnfName().equals(pName)) { + aaiResourceIds.add(new Pair<>(WorkflowType.PNF, pnf.getPnfId())); + Resource pnfResource = new Resource(WorkflowType.PNF, pnf.getPnfId(), false, serviceResource); + org.onap.aai.domain.yang.Pnf aaiPnf = bbInputSetupUtils.getAAIPnf(pnf.getPnfName()); + pnfResource.setModelCustomizationId(aaiPnf.getModelCustomizationId()); + pnfResource.setModelVersionId(aaiPnf.getModelVersionId()); + resourceList.add(pnfResource); + break; + } + } + } + + + private void buildAndThrowException(DelegateExecution execution, String msg) { + logger.error(msg); + execution.setVariable(WORKFLOW_ACTION_ERROR_MESSAGE, msg); + exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, msg); + } + +} diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIPnfResources.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIPnfResources.java index a426c39646..acfca5d55a 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIPnfResources.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIPnfResources.java @@ -87,6 +87,12 @@ public class AAIPnfResources { logger.debug("updatePnfInAAI: {}", pnfFromAai); } + + public void deletePnf(Pnf pnf) { + AAIResourceUri pnfURI = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().pnf(pnf.getPnfName())); + injectionHelper.getAaiClient().delete(pnfURI); + } + private void updatePnfFields(Pnf pnf, org.onap.aai.domain.yang.Pnf pnfFromAai) { if (pnf.getModelInfoPnf() != null && StringUtils.isNotBlank(pnf.getModelInfoPnf().getModelCustomizationUuid())) { |