From 08e1502c1820a027f7412593023e9588cf4d37c8 Mon Sep 17 00:00:00 2001 From: sanket12345 Date: Wed, 25 Aug 2021 16:13:09 +0530 Subject: Implement Building Blocks for CNF AAI update Code changes to implement Building Blocks for CNF AAI update and delete Issue-ID: SO-3717 Signed-off-by: sanket12345 Change-Id: I93b555800a24048f6ecf4e7e786e4bdefa6952fc --- .../subprocess/BuildingBlock/CreateVfModuleBB.bpmn | 48 +++++++--- .../subprocess/BuildingBlock/DeleteVfModuleBB.bpmn | 102 ++++++++++++--------- .../subprocess/BuildingBlock/UpdateCnfAai.bpmn | 102 +++++++++++++++++++++ .../adapter/cnf/tasks/CnfAdapterCreateTasks.java | 81 ++++++++++++++++ .../adapter/cnf/entities/CnfAaiUpdateRequest.java | 72 +++++++++++++++ .../adapter/cnf/entities/CnfAaiUpdateResponse.java | 36 ++++++++ 6 files changed, 384 insertions(+), 57 deletions(-) create mode 100644 bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/UpdateCnfAai.bpmn create mode 100644 bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/CnfAaiUpdateRequest.java create mode 100644 bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/CnfAaiUpdateResponse.java (limited to 'bpmn') diff --git a/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/CreateVfModuleBB.bpmn b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/CreateVfModuleBB.bpmn index a32e9e8f62..49358c7c23 100644 --- a/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/CreateVfModuleBB.bpmn +++ b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/CreateVfModuleBB.bpmn @@ -1,5 +1,5 @@ - + SequenceFlow_1xr6chl @@ -47,7 +47,7 @@ Flow_10aq7a8 - Flow_1il4743 + Flow_1xlm2ij SequenceFlow_0xqhep5 @@ -107,11 +107,31 @@ - + + + + + + + + + + Flow_1il4743 + Flow_1xlm2ij + + + + + + + + + + @@ -212,15 +232,10 @@ - - - - - - - - - + + + + @@ -271,15 +286,18 @@ - - - + + + + + + diff --git a/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/DeleteVfModuleBB.bpmn b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/DeleteVfModuleBB.bpmn index 36d1708a45..128d2fff7f 100644 --- a/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/DeleteVfModuleBB.bpmn +++ b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/DeleteVfModuleBB.bpmn @@ -1,5 +1,5 @@ - + Flow_069drgn @@ -58,7 +58,7 @@ Flow_0plbl7p - Flow_1ktykz6 + Flow_1sj2wbe @@ -96,7 +96,7 @@ Flow_10r76pp Flow_1ktykz6 - + Flow_069drgn Flow_10r76pp @@ -108,12 +108,50 @@ + + + + + + + + Flow_1ktykz6 + Flow_1sj2wbe + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -172,40 +210,20 @@ - - + + - - - - - - - - - - - - - - - - - - - - - - - + + + @@ -215,6 +233,9 @@ + + + @@ -248,20 +269,8 @@ - - - - - - - - - - - - - - + + @@ -283,6 +292,15 @@ + + + + + + + + + diff --git a/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/UpdateCnfAai.bpmn b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/UpdateCnfAai.bpmn new file mode 100644 index 0000000000..01187b06b0 --- /dev/null +++ b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/UpdateCnfAai.bpmn @@ -0,0 +1,102 @@ + + + + + Flow_17d9zpo + + + Flow_17d9zpo + Flow_01esiz5 + + + + + + + + + + + + + Flow_01esiz5 + Flow_0tm9une + + + Flow_0tm9une + Flow_09shgs4 + + + + + Flow_09shgs4 + + + + + + Flow_1js1xt1 + + + + Flow_1js1xt1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnf/tasks/CnfAdapterCreateTasks.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnf/tasks/CnfAdapterCreateTasks.java index f49cf48ff5..2dda26718f 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnf/tasks/CnfAdapterCreateTasks.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnf/tasks/CnfAdapterCreateTasks.java @@ -35,6 +35,8 @@ import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext; import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB; import org.onap.so.client.adapter.cnf.CnfAdapterClient; +import org.onap.so.client.adapter.cnf.entities.CnfAaiUpdateRequest; +import org.onap.so.client.adapter.cnf.entities.CnfAaiUpdateResponse; import org.onap.so.client.adapter.cnf.entities.InstanceRequest; import org.onap.so.client.adapter.cnf.entities.InstanceResponse; import org.onap.so.client.adapter.vnf.mapper.AttributeNameValue; @@ -47,6 +49,7 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; @@ -54,6 +57,8 @@ import com.fasterxml.jackson.databind.ObjectMapper; public class CnfAdapterCreateTasks { private static final Logger logger = LoggerFactory.getLogger(CnfAdapterCreateTasks.class); public static final String SDNCQUERY_RESPONSE = "SDNCQueryResponse_"; + private static final String CNF_ADAPTER_MESSAGE_TYPE = "CNFCallback"; + private static final String CNF_ADAPTER_CALLBACK_TIMEOUT = "PT30M"; @Autowired private ExtractPojosForBB extractPojosForBB; @@ -122,4 +127,80 @@ public class CnfAdapterCreateTasks { return request; } + public void prepareForCnfUpdateOrDelete(BuildingBlockExecution execution) { + + GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock(); + + String heatStackId = execution.getVariable("heatStackId"); + + logger.debug("heatStackId: {}", heatStackId); + CloudRegion cloudRegion = gBBInput.getCloudRegion(); + String requestId = execution.getVariable("mso-request-id"); + + String callbackUrl = + "http://so-bpmn-infra.onap:8081/mso/WorkflowMessage/" + CNF_ADAPTER_MESSAGE_TYPE + "/" + requestId; + + CnfAaiUpdateRequest aaiRequest = createCnfAaiUpdateRequest(heatStackId, cloudRegion, callbackUrl); + logger.debug("aaiRequest: {}", aaiRequest); + + String cnfRequestPayload = ""; + try { + cnfRequestPayload = mapper.writeValueAsString(aaiRequest); + } catch (JsonProcessingException e) { + logger.error("Exception occurred", e); + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, e); + } + + // Prepare values to pass in execution variable for CNF Adapter async Handling + execution.setVariable("messageType", CNF_ADAPTER_MESSAGE_TYPE); + execution.setVariable("correlator", requestId); + execution.setVariable("timeout", CNF_ADAPTER_CALLBACK_TIMEOUT); + + String currentFlow = execution.getFlowToBeCalled(); + logger.debug("currentFlow: {}", currentFlow); + + String apiPath = "http://so-cnf-adapter:8090"; + if ("CreateVfModuleBB".equals(currentFlow)) { + apiPath = apiPath + "/api/cnf-adapter/v1/aai-update/"; + } else if ("DeleteVfModuleBB".equals(currentFlow)) { + apiPath = apiPath + "/api/cnf-adapter/v1/aai-delete/"; + } + + // Set variables in execution variable\ + execution.setVariable("apiPath", apiPath); + execution.setVariable("cnfRequestPayload", cnfRequestPayload); + } + + public void processCnfUpdateOrDeleteAsyncResponse(BuildingBlockExecution execution) { + + String asyncResponse = execution.getVariable("asyncCallbackResponse"); + + CnfAaiUpdateResponse response = new CnfAaiUpdateResponse(); + + logger.debug("asyncResponse: {}", asyncResponse); + + try { + response = mapper.readValue(asyncResponse, CnfAaiUpdateResponse.class); + } catch (JsonProcessingException e) { + logger.error("Error in parsing Cnf AAI update Response"); + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, e); + } + + if (!"COMPLETED".equalsIgnoreCase(response.getStatus())) { + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, new RuntimeException("Cannot update in AAI")); + } + } + + protected CnfAaiUpdateRequest createCnfAaiUpdateRequest(String heatStackId, CloudRegion cloudRegion, + String callbackUrl) { + CnfAaiUpdateRequest request = new CnfAaiUpdateRequest(); + request.setCallbackUrl(callbackUrl); + request.setCloudOwner(cloudRegion.getCloudOwner()); + request.setCloudRegion(cloudRegion.getLcpCloudRegionId()); + request.setTenantId(cloudRegion.getTenantId()); + request.setInstanceId(heatStackId); + + return request; + } + } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/CnfAaiUpdateRequest.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/CnfAaiUpdateRequest.java new file mode 100644 index 0000000000..4cc675f4e9 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/CnfAaiUpdateRequest.java @@ -0,0 +1,72 @@ +package org.onap.so.client.adapter.cnf.entities; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(value = "true") +public class CnfAaiUpdateRequest { + + @JsonProperty("instanceId") + private String instanceId; + + @JsonProperty("cloudRegion") + private String cloudRegion; + + @JsonProperty("cloudOwner") + private String cloudOwner; + + @JsonProperty("tenantId") + private String tenantId; + + @JsonProperty("callbackUrl") + private String callbackUrl; + + public String getInstanceId() { + return instanceId; + } + + public void setInstanceId(String instanceId) { + this.instanceId = instanceId; + } + + public String getCloudRegion() { + return cloudRegion; + } + + public void setCloudRegion(String cloudRegion) { + this.cloudRegion = cloudRegion; + } + + public String getCloudOwner() { + return cloudOwner; + } + + public void setCloudOwner(String cloudOwner) { + this.cloudOwner = cloudOwner; + } + + public String getTenantId() { + return tenantId; + } + + public void setTenantId(String tenantId) { + this.tenantId = tenantId; + } + + public String getCallbackUrl() { + return callbackUrl; + } + + public void setCallbackUrl(String callbackUrl) { + this.callbackUrl = callbackUrl; + } + + @Override + public String toString() { + return "CnfAaiUpdateRequest [instanceId=" + instanceId + ", cloudRegion=" + cloudRegion + ", cloudOwner=" + + cloudOwner + ", tenantId=" + tenantId + ", callbackUrl=" + callbackUrl + "]"; + } + +} diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/CnfAaiUpdateResponse.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/CnfAaiUpdateResponse.java new file mode 100644 index 0000000000..79d27abc35 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/CnfAaiUpdateResponse.java @@ -0,0 +1,36 @@ +package org.onap.so.client.adapter.cnf.entities; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +@JsonInclude(JsonInclude.Include.NON_NULL) +public class CnfAaiUpdateResponse { + + @JsonProperty("status") + private String status; + + @JsonProperty("statusMessage") + private String statusMessage; + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getStatusMessage() { + return statusMessage; + } + + public void setStatusMessage(String statusMessage) { + this.statusMessage = statusMessage; + } + + @Override + public String toString() { + return "CnfAaiUpdateResponse [status=" + status + ", statusMessage=" + statusMessage + "]"; + } + +} -- cgit 1.2.3-korg