summaryrefslogtreecommitdiffstats
path: root/bpmn/so-bpmn-tasks/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'bpmn/so-bpmn-tasks/src/main/java')
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/composition/ChildServiceRequestBuilder.java43
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/composition/DeleteChildServiceBB.java95
-rwxr-xr-xbpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java13
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/ServiceEBBLoader.java53
4 files changed, 189 insertions, 15 deletions
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/composition/ChildServiceRequestBuilder.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/composition/ChildServiceRequestBuilder.java
index 135b3d6ec4..2a008e3573 100644
--- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/composition/ChildServiceRequestBuilder.java
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/composition/ChildServiceRequestBuilder.java
@@ -13,15 +13,14 @@ import org.onap.so.serviceinstancebeans.RelatedInstance;
import org.onap.so.serviceinstancebeans.RelatedInstanceList;
import org.onap.so.serviceinstancebeans.RequestDetails;
import org.onap.so.serviceinstancebeans.RequestInfo;
+import org.onap.so.serviceinstancebeans.RequestParameters;
import org.onap.so.serviceinstancebeans.Service;
import org.onap.so.serviceinstancebeans.ServiceInstancesRequest;
-import org.onap.so.serviceinstancebeans.RequestParameters;
import org.onap.so.serviceinstancebeans.SubscriberInfo;
import java.io.IOException;
import java.util.Map;
public class ChildServiceRequestBuilder {
-
private final BuildingBlockExecution buildingBlockExecution;
private Service parent;
private Service child;
@@ -66,6 +65,17 @@ public class ChildServiceRequestBuilder {
return new ChildServiceRequestBuilder(buildingBlockExecution, parent, child);
}
+ public static ChildServiceRequestBuilder getInstance(final BuildingBlockExecution buildingBlockExecution,
+ Service parentInstance, Service childInstance) {
+ Service child = null;
+ Service parent = null;
+ if (childInstance != null) {
+ parent = parentInstance;
+ child = childInstance;
+ }
+ return new ChildServiceRequestBuilder(buildingBlockExecution, parent, child);
+ }
+
public ChildServiceRequestBuilder setParentRequestId(String parentRequestId) {
sir.getRequestDetails().getRequestInfo().setRequestorId(parentRequestId);
return this;
@@ -83,10 +93,28 @@ public class ChildServiceRequestBuilder {
public ServiceInstancesRequest build() {
RequestContext context = buildingBlockExecution.getGeneralBuildingBlock().getRequestContext();
- sir.setRequestDetails(createRequestDetails(context));
+
+ if (context.getAction().equals("deleteInstance")) {
+ sir.setRequestDetails(createRequestDetailsDeleteChild(context));
+ } else {
+ sir.setRequestDetails(createRequestDetails(context));
+ }
return sir;
}
+ private RequestDetails createRequestDetailsDeleteChild(RequestContext context) {
+ RequestDetails details = sir.getRequestDetails();
+
+ details.setRequestParameters(createRequestParameters(context, child));
+ details.setRequestInfo(createRequestInfo(context));
+ details.setCloudConfiguration(createCloudConfiguration());
+ details.setModelInfo(child.getModelInfo());
+ details.setSubscriberInfo(createSubscriberInfo());
+ details.setRelatedInstanceList(createRelatedInstanceList());
+
+ return details;
+ }
+
private RequestDetails createRequestDetails(RequestContext context) {
RequestDetails details = sir.getRequestDetails();
@@ -104,8 +132,13 @@ public class ChildServiceRequestBuilder {
private RequestParameters createRequestParameters(RequestContext context, Service childService) {
RequestParameters requestParameters = new RequestParameters();
- requestParameters.getUserParams().add(context.getRequestParameters().getUserParams().get(0));
- requestParameters.getUserParams().add(Map.of("service", childService));
+
+ if (!context.getRequestParameters().getUserParams().isEmpty()) {
+ requestParameters.getUserParams().add(context.getRequestParameters().getUserParams().get(0));
+ if (context.getAction().equals("createInstance")) {
+ requestParameters.getUserParams().add(Map.of("service", childService));
+ }
+ }
requestParameters.setSubscriptionServiceType(context.getRequestParameters().getSubscriptionServiceType());
requestParameters.setaLaCarte(context.getRequestParameters().getALaCarte());
requestParameters.setPayload(context.getRequestParameters().getPayload());
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/composition/DeleteChildServiceBB.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/composition/DeleteChildServiceBB.java
index a3f70c8f5b..52d1b68ccd 100644
--- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/composition/DeleteChildServiceBB.java
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/composition/DeleteChildServiceBB.java
@@ -16,27 +16,114 @@
package org.onap.so.bpmn.infrastructure.service.composition;
+import org.onap.aai.domain.yang.ServiceInstance;
+import org.onap.aaiclient.client.aai.AAIResourcesClient;
+import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory;
+import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder;
+import org.onap.aaiclient.client.graphinventory.entities.uri.Depth;
+import org.onap.logging.filter.base.ONAPComponents;
import org.onap.so.bpmn.common.BuildingBlockExecution;
+import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
+import org.onap.so.client.exception.ExceptionBuilder;
+import org.onap.so.client.orchestration.ApiHandlerClient;
+import org.onap.so.serviceinstancebeans.ModelInfo;
+import org.onap.so.serviceinstancebeans.ModelType;
+import org.onap.so.serviceinstancebeans.Service;
+import org.onap.so.serviceinstancebeans.ServiceInstancesRequest;
+import org.onap.so.serviceinstancebeans.ServiceInstancesResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
+import java.util.Map;
+import java.util.UUID;
+import static org.onap.so.bpmn.infrastructure.service.composition.ServiceCompositionConstants.CHILD_SVC_INSTANCE_ID;
+import static org.onap.so.bpmn.infrastructure.service.composition.ServiceCompositionConstants.CHILD_SVC_REQ_CORRELATION_ID;
+import static org.onap.so.bpmn.infrastructure.service.composition.ServiceCompositionConstants.CHILD_SVC_REQ_ERROR;
+import static org.onap.so.bpmn.infrastructure.service.composition.ServiceCompositionConstants.CHILD_SVC_REQ_ID;
+import static org.onap.so.bpmn.infrastructure.service.composition.ServiceCompositionConstants.CHILD_SVC_REQ_PAYLOAD;
+
@Component
public class DeleteChildServiceBB {
+ @Autowired
+ protected ExceptionBuilder exceptionBuilder;
+
+ @Autowired
+ private ApiHandlerClient apiHandlerClient;
+
+ private AAIResourcesClient aaiResourcesClient = new AAIResourcesClient();
+
private final Logger log = LoggerFactory.getLogger(this.getClass());
public void buildRequest(final BuildingBlockExecution buildingBlockExecution) {
log.info("Building Delete Service Request");
+ Map<ResourceKey, String> lookupMap = buildingBlockExecution.getLookupMap();
+ String childSvcInstanceId = lookupMap.get(ResourceKey.CHILD_SERVICE_INSTANCE_ID);
+ String childServiceInstanceId =
+ buildingBlockExecution.getLookupMap().get(ResourceKey.CHILD_SERVICE_INSTANCE_ID);
+ String parentServiceInstanceId = buildingBlockExecution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID);
+ ServiceInstance childInstanceAAI = aaiResourcesClient.get(ServiceInstance.class,
+ AAIUriFactory
+ .createResourceUri(
+ AAIFluentTypeBuilder.Types.SERVICE_INSTANCE.getFragment(childServiceInstanceId))
+ .depth(Depth.TWO))
+ .orElse(null);
+ ServiceInstance parentInstanceAAI =
+ aaiResourcesClient.get(ServiceInstance.class,
+ AAIUriFactory.createResourceUri(
+ AAIFluentTypeBuilder.Types.SERVICE_INSTANCE.getFragment(parentServiceInstanceId))
+ .depth(Depth.TWO))
+ .orElse(null);
+ if (childInstanceAAI == null || parentInstanceAAI == null) {
+ exceptionBuilder.buildAndThrowWorkflowException(buildingBlockExecution, 10004, "Service AAI request failed",
+ ONAPComponents.SO);
+ }
+ Service parentInstance = serviceInstanceToServiceBeanMapper(parentInstanceAAI);
+ Service childInstance = serviceInstanceToServiceBeanMapper(childInstanceAAI);
+ ServiceInstancesRequest sir = ChildServiceRequestBuilder
+ .getInstance(buildingBlockExecution, parentInstance, childInstance)
+ .setParentRequestId(
+ buildingBlockExecution.getGeneralBuildingBlock().getRequestContext().getMsoRequestId())
+ .setChildSvcInstanceId(childSvcInstanceId).setCorrelationId(UUID.randomUUID().toString()).build();
+ buildingBlockExecution.setVariable(CHILD_SVC_REQ_PAYLOAD, sir);
}
public void sendRequest(final BuildingBlockExecution buildingBlockExecution) {
- log.info("Sending Delete Service Request");
+ try {
+ ServiceInstancesRequest sir = buildingBlockExecution.getVariable(CHILD_SVC_REQ_PAYLOAD);
+ log.info("Sending Delete Service Request: \n{}", sir.toString());
+ buildingBlockExecution.setVariable(CHILD_SVC_REQ_CORRELATION_ID,
+ sir.getRequestDetails().getRequestInfo().getCorrelator());
+ ServiceInstancesResponse response = apiHandlerClient.deleteServiceInstance(sir);
+ buildingBlockExecution.setVariable(CHILD_SVC_REQ_ID, response.getRequestReferences().getRequestId());
+ buildingBlockExecution.setVariable(CHILD_SVC_INSTANCE_ID, response.getRequestReferences().getInstanceId());
+ } catch (Exception e) {
+ exceptionBuilder.buildAndThrowWorkflowException(buildingBlockExecution, 10003, e.getMessage(),
+ ONAPComponents.SO);
+ }
}
- public void handleFailure(final BuildingBlockExecution buildingBlockExecution, final String responsePayload) {
- // log error
- // build workflowException with proper message
+ public void handleFailure(final BuildingBlockExecution buildingBlockExecution) {
+ Map<ResourceKey, String> lookupMap = buildingBlockExecution.getLookupMap();
+ String childSvcInstanceName = lookupMap.get(ResourceKey.CHILD_SERVICE_INSTANCE_NAME);
+ String childErrorMessage = buildingBlockExecution.getVariable(CHILD_SVC_REQ_ERROR);
+ String errorMessage =
+ String.format("Failed deleting child service %:qqs %s", childSvcInstanceName, childErrorMessage);
+ exceptionBuilder.buildAndThrowWorkflowException(buildingBlockExecution, 10001, errorMessage, ONAPComponents.SO);
}
+ private static Service serviceInstanceToServiceBeanMapper(ServiceInstance serviceInstance) {
+ Service service = new Service();
+ service.setInstanceName(service.getInstanceName());
+ ModelInfo modelInfo = new ModelInfo();
+ modelInfo.setModelId(serviceInstance.getModelVersionId());
+ modelInfo.setModelType(ModelType.service);
+ modelInfo.setModelVersionId(serviceInstance.getModelVersionId());
+ modelInfo.setModelInstanceName(serviceInstance.getServiceInstanceName());
+ modelInfo.setModelInvariantId(serviceInstance.getModelInvariantId());
+ service.setModelInfo(modelInfo);
+ return service;
+ }
}
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 ef0fbc850e..31a7caacda 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
@@ -692,11 +692,11 @@ public class WorkflowAction {
logger.debug("{}, {}", pair.getValue0(), pair.getValue1());
}
Map<Resource, String> resourceInstanceIds = new HashMap<>();
- Arrays.stream(WorkflowType.values()).filter(type -> !type.equals(WorkflowType.SERVICE))
- .forEach(type -> resourceList.stream().filter(resource -> type.equals(resource.getResourceType()))
- .forEach(resource -> updateWorkflowResourceIds(flowsToExecute, type, resource,
- retrieveAAIResourceId(aaiResourceIds, type), null, serviceInstanceId,
- resourceInstanceIds)));
+ Arrays.stream(WorkflowType.values()).forEach(type -> resourceList.stream()
+ .filter(resource -> type.equals(resource.getResourceType())
+ && !(WorkflowType.SERVICE.equals(type) && !resource.hasParent()))
+ .forEach(resource -> updateWorkflowResourceIds(flowsToExecute, type, resource,
+ retrieveAAIResourceId(aaiResourceIds, type), null, serviceInstanceId, resourceInstanceIds)));
}
private String retrieveAAIResourceId(List<Pair<WorkflowType, String>> aaiResourceIds, WorkflowType resource) {
@@ -750,7 +750,8 @@ public class WorkflowAction {
}
if (resource.hasParent() && WorkflowType.SERVICE.equals(resourceType)
&& WorkflowType.SERVICE.equals(parent.getResourceType())) {
- workflowResourceIds.setChildServiceInstanceId(resourceId);
+ String childServiceInstanceId = resource.isGenerated() ? resourceId : resource.getResourceId();
+ workflowResourceIds.setChildServiceInstanceId(childServiceInstanceId);
workflowResourceIds.setChildServiceInstanceName(resource.getInstanceName());
} else {
WorkflowResourceIdsUtils.setInstanceNameByWorkflowType(workflowResourceIds, resourceType,
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/ServiceEBBLoader.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/ServiceEBBLoader.java
index 79e801b740..f16365b742 100644
--- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/ServiceEBBLoader.java
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/ServiceEBBLoader.java
@@ -25,8 +25,12 @@ package org.onap.so.bpmn.infrastructure.workflow.tasks.ebb.loader;
import com.fasterxml.jackson.core.JsonProcessingException;
import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.javatuples.Pair;
+import org.onap.aai.domain.yang.ComposedResource;
+import org.onap.aai.domain.yang.ComposedResources;
import org.onap.aai.domain.yang.GenericVnf;
import org.onap.aai.domain.yang.Relationship;
+import org.onap.aai.domain.yang.RelationshipData;
+import org.onap.aai.domain.yang.RelationshipList;
import org.onap.aai.domain.yang.ServiceInstance;
import org.onap.aai.domain.yang.VpnBinding;
import org.onap.aaiclient.client.aai.AAICommonObjectMapperProvider;
@@ -204,6 +208,7 @@ public class ServiceEBBLoader {
new Resource(WorkflowType.SERVICE, serviceInstanceMSO.getServiceInstanceId(), false, null);
serviceResource.setModelInvariantId(serviceInstanceAAI.getModelInvariantId());
resourceList.add(serviceResource);
+ traverseServiceInstanceChildService(resourceList, serviceResource, serviceInstanceAAI);
traverseServiceInstanceMSOVnfs(resourceList, serviceResource, aaiResourceIds, serviceInstanceMSO);
traverseServiceInstanceMSOPnfs(resourceList, serviceResource, aaiResourceIds, serviceInstanceMSO);
if (serviceInstanceMSO.getNetworks() != null) {
@@ -280,6 +285,54 @@ public class ServiceEBBLoader {
}
}
+ public void traverseServiceInstanceChildService(List<Resource> resourceList, Resource serviceResource,
+ ServiceInstance serviceInstanceAAI) {
+
+ ComposedResources composedResources = serviceInstanceAAI.getComposedResources();
+ if (composedResources == null) {
+ return;
+ }
+
+ List<ComposedResource> listOfComposedResource = composedResources.getComposedResource();
+
+ listOfComposedResource.forEach(composedResource -> {
+ // Get ServiceInstance from composedResource relationship List
+ RelationshipList relationshipList = composedResource.getRelationshipList();
+ if (relationshipList == null) {
+ return;
+ }
+ List<Relationship> composedResourceRelationshipList = relationshipList.getRelationship();
+ ServiceInstance childService = new ServiceInstance();
+ composedResourceRelationshipList.forEach(composedRelation -> {
+ if ("service-instance".equalsIgnoreCase(composedRelation.getRelatedTo())) {
+ List<RelationshipData> rData = composedRelation.getRelationshipData();
+ rData.forEach(data -> {
+ if ("service-instance.service-instance-id".equalsIgnoreCase(data.getRelationshipKey())) {
+ childService.setServiceInstanceId(data.getRelationshipValue());
+ }
+ });
+ composedRelation.getRelatedToProperty().forEach(relatedToProperty -> {
+ if ("service-instance.service-instance-name"
+ .equalsIgnoreCase(relatedToProperty.getPropertyKey())) {
+ childService.setServiceInstanceName(relatedToProperty.getPropertyValue());
+ }
+ });
+ }
+ });
+
+ if (childService.getServiceInstanceId() == null) {
+ return;
+ }
+
+ Resource childServiceResource =
+ new Resource(WorkflowType.SERVICE, childService.getServiceInstanceId(), false, serviceResource);
+
+ childServiceResource.setInstanceName(childService.getServiceInstanceName());
+ resourceList.add(childServiceResource);
+ });
+
+ }
+
protected void traverseVrfConfiguration(List<Pair<WorkflowType, String>> aaiResourceIds,
List<Resource> resourceList, Resource serviceResource, org.onap.so.db.catalog.beans.Service service,
RelatedInstance relatedVpnBinding, RelatedInstance relatedLocalNetwork)