summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortragait <rahul.tyagi@est.tech>2019-10-21 14:26:08 -0400
committertragait <rahul.tyagi@est.tech>2020-02-19 18:35:53 +0000
commit1ae4a5642022ff156021ae5b8e85473aa2b5a177 (patch)
tree2949d4c014cfe38800bc593e44fd906e99450ce1
parent493477ef59ce12d082683f188e0253fe2d34bdff (diff)
Generic cds payload for vnf/vf-module/service.
Things done- -Fixed review comments. -Added logic to create payload using scope and action. -Populate instance parameters from SO-request to CDS payload for VNF. -Implementation of setting orchestration status after CDS completes its operation based on SO scope. -Make use of ControllerRunnable interface. -Changed actionname to actionName to action.value as per Oscar's suggestion. -Setting orchestration status after CDS completes its operation for VF-Module. -Populate instance paraneters from SO to CDS for VF-Module. Issue-ID: SO-2312 Signed-off-by: prathamesh <prathamesh_morde@yahoo.ca> Change-Id: I026d9f7909e486c68f274b7e56c8bd7c8fdcd521 Signed-off-by: prathamesh <prathamesh_morde@yahoo.ca> Signed-off-by: tragait <rahul.tyagi@est.tech>
-rw-r--r--bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/AbstractCDSProcessingBBUtils.java169
-rw-r--r--bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/CDSRequestProvider.java76
-rw-r--r--bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/ConfigureInstanceParamsForVfModule.java79
-rw-r--r--bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/ConfigureInstanceParamsForVnf.java73
-rw-r--r--bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/ExtractServiceFromUserParameters.java53
-rw-r--r--bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/GeneratePayloadForCds.java105
-rw-r--r--bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/PayloadConstants.java34
-rw-r--r--bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/ServiceCDSRequestProvider.java89
-rw-r--r--bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/VfModuleCDSRequestProvider.java121
-rw-r--r--bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/VnfCDSRequestProvider.java106
-rw-r--r--bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/exception/PayloadGenerationException.java39
-rw-r--r--bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/AbstractCDSProcessingBBUtilsTest.java27
-rw-r--r--bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/AbstractVnfCDSRequestProviderTest.java205
-rw-r--r--bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/ConfigureInstanceParamsForVfModuleTest.java127
-rw-r--r--bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/GeneratePayloadForCdsTest.java287
-rw-r--r--bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/ServiceCDSRequestProviderTest.java62
-rw-r--r--bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/VfModuleCDSRequestProviderTest.java80
-rw-r--r--bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/VnfCDSRequestProviderTest.java104
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIUpdateTasks.java78
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/controller/cds/CdsControllerDE.java9
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericCDSProcessingBB.java92
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java9
-rw-r--r--bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/controller/cds/CdsControllerDETest.java7
-rw-r--r--bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericCDSProcessingBBTest.java197
-rw-r--r--pom.xml44
25 files changed, 2152 insertions, 120 deletions
diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/AbstractCDSProcessingBBUtils.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/AbstractCDSProcessingBBUtils.java
index 424a4f3ecc..ebced8e933 100644
--- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/AbstractCDSProcessingBBUtils.java
+++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/AbstractCDSProcessingBBUtils.java
@@ -22,14 +22,18 @@
package org.onap.so.client.cds;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
+import com.google.protobuf.InvalidProtocolBufferException;
+import com.google.protobuf.Struct;
+import com.google.protobuf.Struct.Builder;
+import com.google.protobuf.util.JsonFormat;
+import io.grpc.Status;
import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.onap.ccsdk.cds.controllerblueprints.common.api.ActionIdentifiers;
import org.onap.ccsdk.cds.controllerblueprints.common.api.CommonHeader;
import org.onap.ccsdk.cds.controllerblueprints.common.api.EventType;
import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceInput;
import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceOutput;
+import org.onap.so.bpmn.common.BuildingBlockExecution;
import org.onap.so.client.PreconditionFailedException;
import org.onap.so.client.RestPropertiesLoader;
import org.onap.so.client.cds.beans.AbstractCDSPropertiesBean;
@@ -39,15 +43,11 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
-import com.google.protobuf.InvalidProtocolBufferException;
-import com.google.protobuf.Struct;
-import com.google.protobuf.Struct.Builder;
-import com.google.protobuf.util.JsonFormat;
-import io.grpc.Status;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
/**
* Util class to support Call to CDS client
- *
*/
@Component
public class AbstractCDSProcessingBBUtils {
@@ -60,11 +60,7 @@ public class AbstractCDSProcessingBBUtils {
private static final String RESPONSE_PAYLOAD = "CDSResponsePayload";
private static final String CDS_STATUS = "CDSStatus";
private static final String EXEC_INPUT = "executionServiceInput";
-
-
- /**
- * indicate exception thrown.
- */
+ private static final String EXECUTION_OBJECT = "executionObject";
private static final String EXCEPTION = "Exception";
@Autowired
@@ -76,34 +72,33 @@ public class AbstractCDSProcessingBBUtils {
* @param execution DelegateExecution object
*/
public void constructExecutionServiceInputObject(DelegateExecution execution) {
- logger.trace("Start AbstractCDSProcessingBBUtils.preProcessRequest ");
+ logger.trace("Start AbstractCDSProcessingBBUtils.preProcessRequest for DelegateExecution object.");
try {
AbstractCDSPropertiesBean executionObject =
- (AbstractCDSPropertiesBean) execution.getVariable("executionObject");
-
- String payload = executionObject.getRequestObject();
-
- CommonHeader commonHeader = CommonHeader.newBuilder().setOriginatorId(executionObject.getOriginatorId())
- .setRequestId(executionObject.getRequestId()).setSubRequestId(executionObject.getSubRequestId())
- .build();
- ActionIdentifiers actionIdentifiers =
- ActionIdentifiers.newBuilder().setBlueprintName(executionObject.getBlueprintName())
- .setBlueprintVersion(executionObject.getBlueprintVersion())
- .setActionName(executionObject.getActionName()).setMode(executionObject.getMode()).build();
-
- Builder struct = Struct.newBuilder();
- try {
- JsonFormat.parser().merge(payload, struct);
- } catch (InvalidProtocolBufferException e) {
- logger.error("Failed to parse received message. blueprint({}:{}) for action({}). {}",
- executionObject.getBlueprintVersion(), executionObject.getBlueprintName(),
- executionObject.getActionName(), e);
- }
+ (AbstractCDSPropertiesBean) execution.getVariable(EXECUTION_OBJECT);
+
+ ExecutionServiceInput executionServiceInput = prepareExecutionServiceInput(executionObject);
+
+ execution.setVariable(EXEC_INPUT, executionServiceInput);
+
+ } catch (Exception ex) {
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
+ }
+ }
- ExecutionServiceInput executionServiceInput =
- ExecutionServiceInput.newBuilder().setCommonHeader(commonHeader)
- .setActionIdentifiers(actionIdentifiers).setPayload(struct.build()).build();
+ /**
+ * Extracting data from execution object and building the ExecutionServiceInput Object
+ *
+ * @param execution BuildingBlockExecution object
+ */
+ public void constructExecutionServiceInputObject(BuildingBlockExecution execution) {
+ logger.trace("Start AbstractCDSProcessingBBUtils.preProcessRequest for BuildingBlockExecution object.");
+
+ try {
+ AbstractCDSPropertiesBean executionObject = execution.getVariable(EXECUTION_OBJECT);
+
+ ExecutionServiceInput executionServiceInput = prepareExecutionServiceInput(executionObject);
execution.setVariable(EXEC_INPUT, executionServiceInput);
@@ -119,50 +114,98 @@ public class AbstractCDSProcessingBBUtils {
*/
public void sendRequestToCDSClient(DelegateExecution execution) {
- logger.trace("Start AbstractCDSProcessingBBUtils.sendRequestToCDSClient ");
+ logger.trace("Start AbstractCDSProcessingBBUtils.sendRequestToCDSClient for DelegateExecution object.");
try {
- CDSProperties props = RestPropertiesLoader.getInstance().getNewImpl(CDSProperties.class);
- if (props == null) {
- throw new PreconditionFailedException(
- "No RestProperty.CDSProperties implementation found on classpath, can't create client.");
- }
-
ExecutionServiceInput executionServiceInput = (ExecutionServiceInput) execution.getVariable(EXEC_INPUT);
+ CDSResponse cdsResponse = getCdsResponse(executionServiceInput);
+ execution.setVariable(CDS_STATUS, cdsResponse.status);
- CDSResponse cdsResponse = new CDSResponse();
-
- try (CDSProcessingClient cdsClient = new CDSProcessingClient(new ResponseHandler(cdsResponse))) {
- CountDownLatch countDownLatch = cdsClient.sendRequest(executionServiceInput);
- countDownLatch.await(props.getTimeout(), TimeUnit.SECONDS);
- } catch (InterruptedException ex) {
- logger.error("Caught exception in sendRequestToCDSClient in AbstractCDSProcessingBBUtils : ", ex);
- Thread.currentThread().interrupt();
+ if (cdsResponse.payload != null) {
+ String payload = JsonFormat.printer().print(cdsResponse.payload);
+ execution.setVariable(RESPONSE_PAYLOAD, payload);
}
- String cdsResponseStatus = cdsResponse.status;
+ } catch (Exception ex) {
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
+ }
+ }
- /**
- * throw CDS failed exception.
- */
- if (!cdsResponseStatus.equals(SUCCESS)) {
- throw new BadResponseException("CDS call failed with status: " + cdsResponse.status
- + " and errorMessage: " + cdsResponse.errorMessage);
- }
+ /**
+ * get the executionServiceInput object from execution and send a request to CDS Client and wait for TIMEOUT period
+ *
+ * @param execution BuildingBlockExecution object
+ */
+ public void sendRequestToCDSClient(BuildingBlockExecution execution) {
- execution.setVariable(CDS_STATUS, cdsResponseStatus);
+ logger.trace("Start AbstractCDSProcessingBBUtils.sendRequestToCDSClient for BuildingBlockExecution object.");
+ try {
+ ExecutionServiceInput executionServiceInput = execution.getVariable(EXEC_INPUT);
+ CDSResponse cdsResponse = getCdsResponse(executionServiceInput);
+ execution.setVariable(CDS_STATUS, cdsResponse.status);
if (cdsResponse.payload != null) {
String payload = JsonFormat.printer().print(cdsResponse.payload);
execution.setVariable(RESPONSE_PAYLOAD, payload);
}
-
-
} catch (Exception ex) {
exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
}
}
+ private CDSResponse getCdsResponse(ExecutionServiceInput executionServiceInput) throws BadResponseException {
+ CDSProperties props = RestPropertiesLoader.getInstance().getNewImpl(CDSProperties.class);
+ if (props == null) {
+ throw new PreconditionFailedException(
+ "No RestProperty.CDSProperties implementation found on classpath, can't create client.");
+ }
+
+ CDSResponse cdsResponse = new CDSResponse();
+
+ try (CDSProcessingClient cdsClient = new CDSProcessingClient(new ResponseHandler(cdsResponse))) {
+ CountDownLatch countDownLatch = cdsClient.sendRequest(executionServiceInput);
+ countDownLatch.await(props.getTimeout(), TimeUnit.SECONDS);
+ } catch (InterruptedException ex) {
+ logger.error("Caught exception in sendRequestToCDSClient in AbstractCDSProcessingBBUtils : ", ex);
+ Thread.currentThread().interrupt();
+ }
+
+ String cdsResponseStatus = cdsResponse.status;
+
+ /**
+ * throw CDS failed exception.
+ */
+ if (!cdsResponseStatus.equals(SUCCESS)) {
+ throw new BadResponseException("CDS call failed with status: " + cdsResponse.status + " and errorMessage: "
+ + cdsResponse.errorMessage);
+ }
+ return cdsResponse;
+ }
+
+ private ExecutionServiceInput prepareExecutionServiceInput(AbstractCDSPropertiesBean executionObject) {
+ String payload = executionObject.getRequestObject();
+
+ CommonHeader commonHeader = CommonHeader.newBuilder().setOriginatorId(executionObject.getOriginatorId())
+ .setRequestId(executionObject.getRequestId()).setSubRequestId(executionObject.getSubRequestId())
+ .build();
+ ActionIdentifiers actionIdentifiers =
+ ActionIdentifiers.newBuilder().setBlueprintName(executionObject.getBlueprintName())
+ .setBlueprintVersion(executionObject.getBlueprintVersion())
+ .setActionName(executionObject.getActionName()).setMode(executionObject.getMode()).build();
+
+ Builder struct = Struct.newBuilder();
+ try {
+ JsonFormat.parser().merge(payload, struct);
+ } catch (InvalidProtocolBufferException e) {
+ logger.error("Failed to parse received message. blueprint({}:{}) for action({}). {}",
+ executionObject.getBlueprintVersion(), executionObject.getBlueprintName(),
+ executionObject.getActionName(), e);
+ }
+
+ return ExecutionServiceInput.newBuilder().setCommonHeader(commonHeader).setActionIdentifiers(actionIdentifiers)
+ .setPayload(struct.build()).build();
+ }
+
private class ResponseHandler implements CDSProcessingListener {
private CDSResponse cdsResponse;
diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/CDSRequestProvider.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/CDSRequestProvider.java
new file mode 100644
index 0000000000..e01de69b74
--- /dev/null
+++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/CDSRequestProvider.java
@@ -0,0 +1,76 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2019 Bell Canada
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.client.cds;
+
+import com.google.gson.JsonObject;
+import org.onap.so.client.exception.PayloadGenerationException;
+import java.util.Optional;
+import static org.onap.so.client.cds.PayloadConstants.REQUEST;
+import static org.onap.so.client.cds.PayloadConstants.SEPARATOR;
+
+public interface CDSRequestProvider {
+
+ /**
+ * Build entire payload for CDS.
+ *
+ * @param action - action could be assign/deploy/undeploy etc.
+ * @return "payload":{ "config-<action>-<scope>":{ // information about resolution key, property configuration and
+ * template prefix based on the scope and action}
+ * @throws PayloadGenerationException If fail to build the payload.
+ */
+ Optional<String> buildRequestPayload(String action) throws PayloadGenerationException;
+
+ /**
+ * Get the blueprint name for CDS payload
+ *
+ * @return blueprint name
+ */
+ String getBlueprintName();
+
+ /**
+ * Get the blueprint version for CDS payload
+ *
+ * @return blueprint version
+ */
+ String getBlueprintVersion();
+
+ /**
+ * Set the executionObject(BuildingBlockExecution or DelegateExecution for PNF)
+ *
+ * @param executionObject object could be BuildingBlockExecution or DelegateExecution.
+ */
+ <T> void setExecutionObject(T executionObject);
+
+
+ /**
+ * Build Request payload for CDS
+ *
+ * @param cdsPropertyObject - Json Object
+ * @param action - action could be assign/deploy/undeploy etc.
+ * @return Request Payload
+ */
+ default String buildRequestJsonObject(JsonObject cdsPropertyObject, String action) {
+ String requestBasedOnAction = action.concat(SEPARATOR).concat(REQUEST);
+ JsonObject requestObject = new JsonObject();
+ requestObject.add(requestBasedOnAction, cdsPropertyObject);
+ return requestObject.toString();
+ }
+}
diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/ConfigureInstanceParamsForVfModule.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/ConfigureInstanceParamsForVfModule.java
new file mode 100644
index 0000000000..6f850fa898
--- /dev/null
+++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/ConfigureInstanceParamsForVfModule.java
@@ -0,0 +1,79 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2019 Bell Canada
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.client.cds;
+
+import com.google.gson.JsonObject;
+import org.onap.so.client.cds.ExtractServiceFromUserParameters;
+import org.onap.so.client.exception.PayloadGenerationException;
+import org.onap.so.serviceinstancebeans.Service;
+import org.onap.so.serviceinstancebeans.VfModules;
+import org.onap.so.serviceinstancebeans.Vnfs;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+import java.util.List;
+import java.util.Map;
+
+@Component
+public class ConfigureInstanceParamsForVfModule {
+
+ @Autowired
+ private ExtractServiceFromUserParameters extractServiceFromUserParameters;
+
+ /**
+ * Read instance parameters for VF-Module and put into JsonObject.
+ *
+ * @param jsonObject- JsonObject which will hold the payload to send to CDS.
+ * @param userParamsFromRequest - User parameters for a vf-module
+ * @param vnfCustomizationUuid - Unique ID for vnf.
+ * @param vfModuleCustomizationUuid - Unique ID for vf-module.
+ * @throws PayloadGenerationException- If it doesn't able to populate instance parameters from SO payload.
+ */
+ public void populateInstanceParams(JsonObject jsonObject, List<Map<String, Object>> userParamsFromRequest,
+ String vnfCustomizationUuid, String vfModuleCustomizationUuid) throws PayloadGenerationException {
+ try {
+ Service service = extractServiceFromUserParameters.getServiceFromRequestUserParams(userParamsFromRequest);
+
+ List<Map<String, String>> instanceParamsList =
+ getInstanceParams(service, vnfCustomizationUuid, vfModuleCustomizationUuid);
+
+ instanceParamsList.stream().flatMap(instanceParamsMap -> instanceParamsMap.entrySet().stream())
+ .forEachOrdered(entry -> jsonObject.addProperty(entry.getKey(), entry.getValue()));
+ } catch (Exception e) {
+ throw new PayloadGenerationException("Couldn't able to resolve instance parameters", e);
+ }
+ }
+
+ private List<Map<String, String>> getInstanceParams(Service service, String vnfCustomizationUuid,
+ String vfModuleCustomizationUuid) throws PayloadGenerationException {
+
+ Vnfs foundedVnf = service.getResources().getVnfs().stream()
+ .filter(vnfs -> vnfs.getModelInfo().getModelCustomizationId().equals(vnfCustomizationUuid)).findFirst()
+ .orElseThrow(() -> new PayloadGenerationException(String
+ .format("Can not find vnf for genericVnfModelCustomizationUuid: %s", vnfCustomizationUuid)));
+
+ VfModules vfModule = foundedVnf.getVfModules().stream().filter(
+ vfModules -> vfModules.getModelInfo().getModelCustomizationId().equals(vfModuleCustomizationUuid))
+ .findFirst().orElseThrow(() -> new PayloadGenerationException(String
+ .format("Can not find vnf for vfModuleCustomizationUuid: %s", vfModuleCustomizationUuid)));
+
+ return vfModule.getInstanceParams();
+ }
+}
diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/ConfigureInstanceParamsForVnf.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/ConfigureInstanceParamsForVnf.java
new file mode 100644
index 0000000000..22c9a7bee4
--- /dev/null
+++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/ConfigureInstanceParamsForVnf.java
@@ -0,0 +1,73 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2019 Bell Canada
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.client.cds;
+
+import com.google.gson.JsonObject;
+import org.onap.so.client.exception.PayloadGenerationException;
+import org.onap.so.serviceinstancebeans.Service;
+import org.onap.so.serviceinstancebeans.Vnfs;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+@Component
+public class ConfigureInstanceParamsForVnf {
+
+ @Autowired
+ private ExtractServiceFromUserParameters extractServiceFromUserParameters;
+
+ /**
+ * Read instance parameters for VNF and put into JsonObject.
+ *
+ * @param jsonObject - JsonObject which will hold the payload to send to CDS.
+ * @param userParamsFromRequest - User parameters.
+ * @param modelCustomizationUuid - Unique ID for Vnf.
+ * @throws PayloadGenerationException if it doesn't able to populate instance parameters from SO payload.
+ */
+ public void populateInstanceParams(JsonObject jsonObject, List<Map<String, Object>> userParamsFromRequest,
+ String modelCustomizationUuid) throws PayloadGenerationException {
+ try {
+ Service service = extractServiceFromUserParameters.getServiceFromRequestUserParams(userParamsFromRequest);
+ List<Map<String, String>> instanceParamsList = getInstanceParamForVnf(service, modelCustomizationUuid);
+
+ instanceParamsList.stream().flatMap(instanceParamsMap -> instanceParamsMap.entrySet().stream())
+ .forEachOrdered(entry -> jsonObject.addProperty(entry.getKey(), entry.getValue()));
+ } catch (Exception e) {
+ throw new PayloadGenerationException("Couldn't able to resolve instance parameters", e);
+ }
+ }
+
+ private List<Map<String, String>> getInstanceParamForVnf(Service service, String genericVnfModelCustomizationUuid)
+ throws PayloadGenerationException {
+ Optional<Vnfs> foundedVnf = service.getResources().getVnfs().stream()
+ .filter(vnfs -> vnfs.getModelInfo().getModelCustomizationId().equals(genericVnfModelCustomizationUuid))
+ .findFirst();
+
+ if (foundedVnf.isPresent()) {
+ return foundedVnf.get().getInstanceParams();
+ } else {
+ throw new PayloadGenerationException(String.format(
+ "Can not find vnf for genericVnfModelCustomizationUuid: %s", genericVnfModelCustomizationUuid));
+ }
+ }
+}
diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/ExtractServiceFromUserParameters.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/ExtractServiceFromUserParameters.java
new file mode 100644
index 0000000000..43fabd3253
--- /dev/null
+++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/ExtractServiceFromUserParameters.java
@@ -0,0 +1,53 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2019 Bell Canada
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.so.client.cds;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.onap.so.client.exception.PayloadGenerationException;
+import org.onap.so.serviceinstancebeans.Service;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+import java.util.List;
+import java.util.Map;
+
+@Component
+public class ExtractServiceFromUserParameters {
+
+ private static final String SERVICE_KEY = "service";
+
+ @Autowired
+ private ObjectMapper objectMapper;
+
+ public Service getServiceFromRequestUserParams(List<Map<String, Object>> userParams) throws Exception {
+ Map<String, Object> serviceMap = userParams.stream().filter(key -> key.containsKey(SERVICE_KEY)).findFirst()
+ .orElseThrow(() -> new Exception("Can not find service in userParams section in generalBuildingBlock"));
+ return getServiceObjectFromServiceMap(serviceMap);
+ }
+
+ private Service getServiceObjectFromServiceMap(Map<String, Object> serviceMap) throws PayloadGenerationException {
+ try {
+ String serviceFromJson = objectMapper.writeValueAsString(serviceMap.get(SERVICE_KEY));
+ return objectMapper.readValue(serviceFromJson, Service.class);
+ } catch (Exception e) {
+ throw new PayloadGenerationException("An exception occurred while converting json object to Service object",
+ e);
+ }
+ }
+}
diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/GeneratePayloadForCds.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/GeneratePayloadForCds.java
new file mode 100644
index 0000000000..0766dae8e1
--- /dev/null
+++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/GeneratePayloadForCds.java
@@ -0,0 +1,105 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2019 Bell Canada
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.client.cds;
+
+import org.onap.so.bpmn.common.BuildingBlockExecution;
+import org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock;
+import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock;
+import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
+import org.onap.so.client.cds.beans.AbstractCDSPropertiesBean;
+import org.onap.so.client.exception.PayloadGenerationException;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+import java.util.UUID;
+
+@Component
+public class GeneratePayloadForCds {
+
+ private static final String ORIGINATOR_ID = "SO";
+ private static final String MODE = "sync";
+ private static final String BUILDING_BLOCK = "buildingBlock";
+
+ @Autowired
+ private VnfCDSRequestProvider vnfCDSRequestProvider;
+
+ @Autowired
+ private VfModuleCDSRequestProvider vfModuleCDSRequestProvider;
+
+ @Autowired
+ private ServiceCDSRequestProvider serviceCDSRequestProvider;
+
+ @Autowired
+ private ExtractPojosForBB extractPojosForBB;
+
+ /**
+ * Build properties like (blueprint name, version, action etc..) along with the request payload.
+ *
+ * @param execution - A building block execution object.
+ * @return AbstractCDSPropertiesBean - A POJO which contains CDS related information.
+ * @throws PayloadGenerationException - Throw an exception if it fails to build payload for CDS.
+ */
+ public AbstractCDSPropertiesBean buildCdsPropertiesBean(BuildingBlockExecution execution)
+ throws PayloadGenerationException {
+
+ ExecuteBuildingBlock executeBuildingBlock = execution.getVariable(BUILDING_BLOCK);
+ BuildingBlock buildingBlock = executeBuildingBlock.getBuildingBlock();
+ String scope = buildingBlock.getBpmnScope();
+ String action = buildingBlock.getBpmnAction();
+
+
+ CDSRequestProvider requestProvider = getRequestProviderByScope(scope);
+ requestProvider.setExecutionObject(execution);
+
+ final String requestPayload = requestProvider.buildRequestPayload(action)
+ .orElseThrow(() -> new PayloadGenerationException("Failed to build payload for CDS"));
+
+ final String requestId = execution.getGeneralBuildingBlock().getRequestContext().getMsoRequestId();
+ final AbstractCDSPropertiesBean cdsPropertiesBean = new AbstractCDSPropertiesBean();
+ cdsPropertiesBean.setRequestObject(requestPayload);
+ cdsPropertiesBean.setBlueprintName(requestProvider.getBlueprintName());
+ cdsPropertiesBean.setBlueprintVersion(requestProvider.getBlueprintVersion());
+ cdsPropertiesBean.setRequestId(requestId);
+ cdsPropertiesBean.setOriginatorId(ORIGINATOR_ID);
+ cdsPropertiesBean.setSubRequestId(UUID.randomUUID().toString());
+ cdsPropertiesBean.setActionName(action);
+ cdsPropertiesBean.setMode(MODE);
+
+ return cdsPropertiesBean;
+ }
+
+ private CDSRequestProvider getRequestProviderByScope(String scope) throws PayloadGenerationException {
+ CDSRequestProvider requestProvider;
+ switch (scope) {
+ case "vnf":
+ requestProvider = vnfCDSRequestProvider;
+ break;
+ case "vfModule":
+ requestProvider = vfModuleCDSRequestProvider;
+ break;
+ case "service":
+ requestProvider = serviceCDSRequestProvider;
+ break;
+ default:
+ throw new PayloadGenerationException("No scope defined with " + scope);
+ }
+ return requestProvider;
+ }
+}
diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/PayloadConstants.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/PayloadConstants.java
new file mode 100644
index 0000000000..e758f548f7
--- /dev/null
+++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/PayloadConstants.java
@@ -0,0 +1,34 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2019 Bell Canada
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.client.cds;
+
+public final class PayloadConstants {
+
+ private PayloadConstants() {
+
+ }
+
+ public static final String REQUEST = "request";
+ public static final String PROPERTIES = "properties";
+ public static final String SCOPE = "scope";
+ public static final String ACTION = "action";
+ public static final String SEPARATOR = "-";
+}
diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/ServiceCDSRequestProvider.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/ServiceCDSRequestProvider.java
new file mode 100644
index 0000000000..12c841a2c6
--- /dev/null
+++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/ServiceCDSRequestProvider.java
@@ -0,0 +1,89 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2020 Bell Canada
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.client.cds;
+
+import com.google.gson.JsonObject;
+import org.onap.so.bpmn.common.BuildingBlockExecution;
+import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
+import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
+import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
+import org.onap.so.client.exception.PayloadGenerationException;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.config.ConfigurableBeanFactory;
+import org.springframework.context.annotation.Scope;
+import org.springframework.stereotype.Component;
+import java.util.Optional;
+import static org.onap.so.client.cds.PayloadConstants.PROPERTIES;
+import static org.onap.so.client.cds.PayloadConstants.SEPARATOR;
+
+@Component
+@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
+public class ServiceCDSRequestProvider implements CDSRequestProvider {
+
+ private static final String EMPTY_STRING = "";
+ private String resolutionKey;
+ private BuildingBlockExecution execution;
+
+ @Autowired
+ private ExtractPojosForBB extractPojosForBB;
+
+ @Override
+ public String getBlueprintName() {
+ return EMPTY_STRING;
+ }
+
+ @Override
+ public String getBlueprintVersion() {
+ return EMPTY_STRING;
+ }
+
+ @Override
+ public <T> void setExecutionObject(T executionObject) {
+ execution = (BuildingBlockExecution) executionObject;
+ }
+
+ @Override
+ public Optional<String> buildRequestPayload(String action) throws PayloadGenerationException {
+ JsonObject cdsPropertyObject = new JsonObject();
+ JsonObject serviceObject = new JsonObject();
+ try {
+ ServiceInstance serviceInstance =
+ extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
+
+ resolutionKey = serviceInstance.getServiceInstanceName();
+
+ // TODO Need to figure out how to populate blueprint name and version for service.
+
+ serviceObject.addProperty("service-instance-id", serviceInstance.getServiceInstanceId());
+ serviceObject.addProperty("service-model-uuid",
+ serviceInstance.getModelInfoServiceInstance().getModelUuid());
+
+ } catch (Exception e) {
+ throw new PayloadGenerationException("Failed to buildPropertyObjectForService", e);
+ }
+
+ cdsPropertyObject.addProperty("resolution-key", resolutionKey);
+ cdsPropertyObject.add(action + SEPARATOR + PROPERTIES, serviceObject);
+
+ return Optional.of(buildRequestJsonObject(cdsPropertyObject, action));
+ }
+
+}
diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/VfModuleCDSRequestProvider.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/VfModuleCDSRequestProvider.java
new file mode 100644
index 0000000000..bba8925f21
--- /dev/null
+++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/VfModuleCDSRequestProvider.java
@@ -0,0 +1,121 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2019 Bell Canada
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.client.cds;
+
+import com.google.gson.JsonObject;
+import org.onap.so.bpmn.common.BuildingBlockExecution;
+import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
+import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
+import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
+import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock;
+import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
+import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
+import org.onap.so.client.exception.PayloadGenerationException;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.config.ConfigurableBeanFactory;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Scope;
+import org.springframework.stereotype.Component;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import static org.onap.so.client.cds.PayloadConstants.PROPERTIES;
+import static org.onap.so.client.cds.PayloadConstants.SEPARATOR;
+
+@Component
+@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
+public class VfModuleCDSRequestProvider implements CDSRequestProvider {
+ private String blueprintName;
+ private String blueprintVersion;
+ private BuildingBlockExecution execution;
+
+ @Autowired
+ private ExtractPojosForBB extractPojosForBB;
+
+ @Autowired
+ private ConfigureInstanceParamsForVfModule configureInstanceParamsForVfModule;
+
+ @Override
+ public String getBlueprintName() {
+ return blueprintName;
+ }
+
+ @Override
+ public String getBlueprintVersion() {
+ return blueprintVersion;
+ }
+
+ @Override
+ public <T> void setExecutionObject(T executionObject) {
+ execution = (BuildingBlockExecution) executionObject;
+ }
+
+ @Override
+ public Optional<String> buildRequestPayload(String action) throws PayloadGenerationException {
+ JsonObject cdsPropertyObject = new JsonObject();
+ JsonObject vfModuleObject = new JsonObject();
+ String vfModuleName;
+
+ try {
+ ServiceInstance serviceInstance =
+ extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
+ GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
+
+ final String modelCustomizationUuidForVnf = genericVnf.getModelInfoGenericVnf().getModelCustomizationUuid();
+
+ blueprintName = genericVnf.getBlueprintName();
+ blueprintVersion = genericVnf.getBlueprintVersion();
+
+ VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID);
+ vfModuleName = vfModule.getVfModuleName();
+
+ final String modelCustomizationUuidForVfModule =
+ vfModule.getModelInfoVfModule().getModelCustomizationUUID();
+
+ vfModuleObject.addProperty("service-instance-id", serviceInstance.getServiceInstanceId());
+ vfModuleObject.addProperty("service-model-uuid",
+ serviceInstance.getModelInfoServiceInstance().getModelUuid());
+ vfModuleObject.addProperty("vnf-id", genericVnf.getVnfId());
+ vfModuleObject.addProperty("vnf-name", genericVnf.getVnfName());
+ vfModuleObject.addProperty("vf-module-id", vfModule.getVfModuleId());
+ vfModuleObject.addProperty("vf-module-name", vfModule.getVfModuleName());
+ vfModuleObject.addProperty("vf-module-customization-uuid",
+ vfModule.getModelInfoVfModule().getModelCustomizationUUID());
+
+ final GeneralBuildingBlock buildingBlock = execution.getGeneralBuildingBlock();
+ List<Map<String, Object>> userParamsFromRequest =
+ buildingBlock.getRequestContext().getRequestParameters().getUserParams();
+
+ configureInstanceParamsForVfModule.populateInstanceParams(vfModuleObject, userParamsFromRequest,
+ modelCustomizationUuidForVnf, modelCustomizationUuidForVfModule);
+ } catch (Exception e) {
+ throw new PayloadGenerationException("Failed to buildPropertyObject for VF-Module", e);
+ }
+
+ // Not sure for resolutionKey should be same as vfModule name.
+ cdsPropertyObject.addProperty("resolution-key", vfModuleName);
+ cdsPropertyObject.addProperty("template-prefix", vfModuleName + action);
+ cdsPropertyObject.add(action + SEPARATOR + PROPERTIES, vfModuleObject);
+
+ return Optional.of(buildRequestJsonObject(cdsPropertyObject, action));
+ }
+
+}
diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/VnfCDSRequestProvider.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/VnfCDSRequestProvider.java
new file mode 100644
index 0000000000..d33976d229
--- /dev/null
+++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/VnfCDSRequestProvider.java
@@ -0,0 +1,106 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2019 Bell Canada
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.client.cds;
+
+import com.google.gson.JsonObject;
+import org.onap.so.bpmn.common.BuildingBlockExecution;
+import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
+import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
+import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock;
+import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
+import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
+import org.onap.so.client.exception.PayloadGenerationException;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.config.ConfigurableBeanFactory;
+import org.springframework.context.annotation.Scope;
+import org.springframework.stereotype.Component;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import static org.onap.so.client.cds.PayloadConstants.PROPERTIES;
+import static org.onap.so.client.cds.PayloadConstants.SEPARATOR;
+
+@Component
+@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
+public class VnfCDSRequestProvider implements CDSRequestProvider {
+ private String blueprintName;
+ private String blueprintVersion;
+ private BuildingBlockExecution execution;
+
+ @Autowired
+ private ExtractPojosForBB extractPojosForBB;
+
+ @Autowired
+ private ConfigureInstanceParamsForVnf configureInstanceParamsForVnf;
+
+ @Override
+ public String getBlueprintName() {
+ return blueprintName;
+ }
+
+ @Override
+ public String getBlueprintVersion() {
+ return blueprintVersion;
+ }
+
+ @Override
+ public <T> void setExecutionObject(T executionObject) {
+ execution = (BuildingBlockExecution) executionObject;
+ }
+
+ @Override
+ public Optional<String> buildRequestPayload(String action) throws PayloadGenerationException {
+ JsonObject cdsPropertyObject = new JsonObject();
+ JsonObject vnfObject = new JsonObject();
+ String resolutionKey;
+ try {
+ ServiceInstance serviceInstance =
+ extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
+ GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
+
+ final String modelCustomizationUuid = genericVnf.getModelInfoGenericVnf().getModelCustomizationUuid();
+
+ resolutionKey = genericVnf.getVnfName();
+ blueprintName = genericVnf.getBlueprintName();
+ blueprintVersion = genericVnf.getBlueprintVersion();
+
+ vnfObject.addProperty("service-instance-id", serviceInstance.getServiceInstanceId());
+ vnfObject.addProperty("service-model-uuid", serviceInstance.getModelInfoServiceInstance().getModelUuid());
+ vnfObject.addProperty("vnf-id", genericVnf.getVnfId());
+ vnfObject.addProperty("vnf-name", genericVnf.getVnfName());
+ vnfObject.addProperty("vnf-customization-uuid", modelCustomizationUuid);
+
+ final GeneralBuildingBlock buildingBlock = execution.getGeneralBuildingBlock();
+ List<Map<String, Object>> userParamsFromRequest =
+ buildingBlock.getRequestContext().getRequestParameters().getUserParams();
+
+ configureInstanceParamsForVnf.populateInstanceParams(vnfObject, userParamsFromRequest,
+ modelCustomizationUuid);
+ } catch (Exception e) {
+ throw new PayloadGenerationException("Failed to buildPropertyObjectForVnf", e);
+ }
+
+ cdsPropertyObject.addProperty("resolution-key", resolutionKey);
+ cdsPropertyObject.add(action + SEPARATOR + PROPERTIES, vnfObject);
+
+ return Optional.of(buildRequestJsonObject(cdsPropertyObject, action));
+ }
+}
diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/exception/PayloadGenerationException.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/exception/PayloadGenerationException.java
new file mode 100644
index 0000000000..3c148a17a5
--- /dev/null
+++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/exception/PayloadGenerationException.java
@@ -0,0 +1,39 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2019 Bell Canada
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.client.exception;
+
+public class PayloadGenerationException extends Exception {
+
+ /**
+ * @param message The message to dump
+ */
+ public PayloadGenerationException(final String message) {
+ super(message);
+ }
+
+ /**
+ * @param message The message to dump.
+ * @param cause The throwable cause object.
+ */
+ public PayloadGenerationException(final String message, final Throwable cause) {
+ super(message, cause);
+ }
+}
diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/AbstractCDSProcessingBBUtilsTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/AbstractCDSProcessingBBUtilsTest.java
index f558932d33..10844ec652 100644
--- a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/AbstractCDSProcessingBBUtilsTest.java
+++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/AbstractCDSProcessingBBUtilsTest.java
@@ -34,6 +34,7 @@ import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.so.bpmn.common.BuildingBlockExecution;
import org.onap.so.client.cds.beans.AbstractCDSPropertiesBean;
import org.onap.so.client.exception.ExceptionBuilder;
@@ -69,7 +70,7 @@ public class AbstractCDSProcessingBBUtilsTest {
}
@Test
- public void preProcessRequestTest() throws Exception {
+ public void preProcessRequestDETest() throws Exception {
DelegateExecution execution = mock(DelegateExecution.class);
when(execution.getVariable("executionObject")).thenReturn(abstractCDSPropertiesBean);
@@ -80,7 +81,7 @@ public class AbstractCDSProcessingBBUtilsTest {
}
@Test
- public void sendRequestToCDSClientTest() {
+ public void sendRequestToCDSClientDETest() {
DelegateExecution execution = mock(DelegateExecution.class);
when(execution.getVariable("executionServiceInput")).thenReturn(abstractCDSPropertiesBean);
@@ -90,4 +91,26 @@ public class AbstractCDSProcessingBBUtilsTest {
}
+ @Test
+ public void preProcessRequestBBTest() throws Exception {
+
+ BuildingBlockExecution execution = mock(BuildingBlockExecution.class);
+ when(execution.getVariable("executionObject")).thenReturn(abstractCDSPropertiesBean);
+
+ abstractCDSProcessingBBUtils.constructExecutionServiceInputObject(execution);
+ verify(exceptionUtil, times(0)).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), anyInt(),
+ any(Exception.class));
+ }
+
+ @Test
+ public void sendRequestToCDSClientBBTest() {
+
+ BuildingBlockExecution execution = mock(BuildingBlockExecution.class);
+ when(execution.getVariable("executionServiceInput")).thenReturn(abstractCDSPropertiesBean);
+ abstractCDSProcessingBBUtils.sendRequestToCDSClient(execution);
+ verify(exceptionUtil, times(1)).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), anyInt(),
+ any(Exception.class));
+
+ }
+
}
diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/AbstractVnfCDSRequestProviderTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/AbstractVnfCDSRequestProviderTest.java
new file mode 100644
index 0000000000..9c3ce60400
--- /dev/null
+++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/AbstractVnfCDSRequestProviderTest.java
@@ -0,0 +1,205 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Nordix
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.client.cds;
+
+import com.google.gson.JsonParser;
+import org.camunda.bpm.engine.delegate.DelegateExecution;
+import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake;
+import org.junit.Before;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.so.bpmn.common.BuildingBlockExecution;
+import org.onap.so.bpmn.common.DelegateExecutionImpl;
+import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
+import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
+import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
+import org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock;
+import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock;
+import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock;
+import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
+import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestParameters;
+import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoGenericVnf;
+import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoServiceInstance;
+import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoVfModule;
+import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
+import org.onap.so.serviceinstancebeans.*;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+@RunWith(MockitoJUnitRunner.Silent.class)
+public abstract class AbstractVnfCDSRequestProviderTest {
+
+ protected static final String GENERIC_VNF_ID = "vnfId_configVnfTest1";
+ protected static final String VF_MODULE_ID = "vf-module-id-1";
+ protected static final String VF_MODULE_NAME = "vf-module-name-1";
+ protected static final String VF_MODULE_CUSTOMIZATION_UUID = "23ce9ac4-e5dd-11e9-81b4-2a2ae2dbcce1";
+ protected static final String GENERIC_VNF_NAME = "vnf-name-1";
+ protected static final String SERVICE_INSTANCE_ID = "serviceInst_configTest";
+ protected static final String SERVICE_MODEL_UUID = "b45b5780-e5dd-11e9-81b4-2a2ae2dbcce4";
+ protected static final String SERVICE_INSTANCE_NAME = "test-service-instance";
+ protected static final String VNF_MODEL_CUSTOMIZATION_UUID = "23ce9ac4-e5dd-11e9-81b4-2a2ae2dbcce4";
+ protected static final String GENERAL_BLOCK_EXECUTION_MAP_KEY = "gBBInput";
+ protected static final String VNF_SCOPE = "vnf";
+ protected static final String SERVICE_SCOPE = "service";
+ protected static final String SERVICE_ACTION = "create";
+ protected static final String VF_SCOPE = "vfModule";
+ protected static final String ASSIGN_ACTION = "configAssign";
+ protected static final String DEPLOY_ACTION = "configDeploy";
+ protected static final String MSO_REQUEST_ID = "1234";
+ protected static final String BUILDING_BLOCK = "buildingBlock";
+ protected static final String PUBLIC_NET_ID = "public-net-id";
+ protected static final String CLOUD_REGION = "acl-cloud-region";
+
+ @Mock
+ protected ExtractPojosForBB extractPojosForBB;
+
+ protected BuildingBlockExecution buildingBlockExecution;
+
+ protected ExecuteBuildingBlock executeBuildingBlock;
+
+
+ @Before
+ public void setUp() {
+ buildingBlockExecution = createBuildingBlockExecution();
+ executeBuildingBlock = new ExecuteBuildingBlock();
+ }
+
+ protected BuildingBlockExecution createBuildingBlockExecution() {
+ DelegateExecution execution = new DelegateExecutionFake();
+ execution.setVariable(GENERAL_BLOCK_EXECUTION_MAP_KEY, createGeneralBuildingBlock());
+ return new DelegateExecutionImpl(execution);
+ }
+
+ protected GeneralBuildingBlock createGeneralBuildingBlock() {
+ GeneralBuildingBlock generalBuildingBlock = new GeneralBuildingBlock();
+ RequestContext requestContext = new RequestContext();
+ RequestParameters requestParameters = new RequestParameters();
+ requestParameters.setUserParams(createRequestUserParams());
+ requestContext.setRequestParameters(requestParameters);
+ requestContext.setMsoRequestId(MSO_REQUEST_ID);
+ generalBuildingBlock.setRequestContext(requestContext);
+ return generalBuildingBlock;
+ }
+
+ protected ServiceInstance createServiceInstance() {
+ ServiceInstance serviceInstance = new ServiceInstance();
+ serviceInstance.setServiceInstanceName(SERVICE_INSTANCE_NAME);
+ serviceInstance.setServiceInstanceId(SERVICE_INSTANCE_ID);
+ ModelInfoServiceInstance modelInfoServiceInstance = new ModelInfoServiceInstance();
+ modelInfoServiceInstance.setModelUuid(SERVICE_MODEL_UUID);
+ serviceInstance.setModelInfoServiceInstance(modelInfoServiceInstance);
+ return serviceInstance;
+ }
+
+ protected GenericVnf createGenericVnf() {
+ GenericVnf genericVnf = new GenericVnf();
+ genericVnf.setVnfId(GENERIC_VNF_ID);
+ genericVnf.setVnfName(GENERIC_VNF_NAME);
+ genericVnf.setBlueprintName("test");
+ genericVnf.setBlueprintVersion("1.0.0");
+ ModelInfoGenericVnf modelInfoGenericVnf = new ModelInfoGenericVnf();
+ modelInfoGenericVnf.setModelCustomizationUuid(VNF_MODEL_CUSTOMIZATION_UUID);
+ genericVnf.setModelInfoGenericVnf(modelInfoGenericVnf);
+ return genericVnf;
+ }
+
+ protected VfModule createVfModule() {
+ VfModule vfModule = new VfModule();
+ vfModule.setVfModuleId(VF_MODULE_ID);
+ vfModule.setVfModuleName(VF_MODULE_NAME);
+ ModelInfoVfModule modelInfoVfModule = new ModelInfoVfModule();
+ modelInfoVfModule.setModelCustomizationUUID(VF_MODULE_CUSTOMIZATION_UUID);
+ vfModule.setModelInfoVfModule(modelInfoVfModule);
+ return vfModule;
+ }
+
+ protected List<Map<String, Object>> createRequestUserParams() {
+ List<Map<String, Object>> userParams = new ArrayList<>();
+ Map<String, Object> userParamMap = new HashMap<>();
+ userParamMap.put("service", getUserParams());
+ userParams.add(userParamMap);
+ return userParams;
+ }
+
+ protected Service getUserParams() {
+ Service service = new Service();
+ Resources resources = new Resources();
+ resources.setVnfs(createVnfList());
+ service.setResources(resources);
+ return service;
+ }
+
+ protected List<Vnfs> createVnfList() {
+ List<Map<String, String>> instanceParamsListSearchedVnf = new ArrayList<>();
+ Map<String, String> instanceParam = new HashMap<>();
+ instanceParam.put("public_net_id", PUBLIC_NET_ID);
+ instanceParam.put("acl-cloud-region", CLOUD_REGION);
+ instanceParamsListSearchedVnf.add(instanceParam);
+ Vnfs searchedVnf = createVnf(instanceParamsListSearchedVnf);
+ List<Vnfs> vnfList = new ArrayList<>();
+ vnfList.add(searchedVnf);
+ return vnfList;
+ }
+
+ protected Vnfs createVnf(List<Map<String, String>> instanceParamsList) {
+ Vnfs vnf = new Vnfs();
+ ModelInfo modelInfo = new ModelInfo();
+ modelInfo.setModelCustomizationId(VNF_MODEL_CUSTOMIZATION_UUID);
+ vnf.setModelInfo(modelInfo);
+ vnf.setInstanceParams(instanceParamsList);
+
+ // Set instance parameters and modelinfo for vf-module
+ VfModules vfModule = new VfModules();
+ ModelInfo modelInfoForVfModule = new ModelInfo();
+ modelInfoForVfModule.setModelCustomizationId(VF_MODULE_CUSTOMIZATION_UUID);
+ vfModule.setModelInfo(modelInfoForVfModule);
+
+ List<Map<String, String>> instanceParamsListSearchedVfModule = new ArrayList<>();
+ Map<String, String> instanceParams = new HashMap<>();
+ instanceParams.put("public-net-vf-module-id", PUBLIC_NET_ID);
+ instanceParams.put("aci-cloud-region-vf-module", CLOUD_REGION);
+
+ instanceParamsListSearchedVfModule.add(instanceParams);
+ vfModule.setInstanceParams(instanceParamsListSearchedVfModule);
+
+ List<VfModules> vfModules = new ArrayList<>();
+ vfModules.add(vfModule);
+
+ vnf.setVfModules(vfModules);
+
+ return vnf;
+ }
+
+ protected boolean verfiyJsonFromString(String payload) {
+ JsonParser parser = new JsonParser();
+ return parser.parse(payload).isJsonObject();
+ }
+
+ protected void setScopeAndAction(String scope, String action) {
+ BuildingBlock buildingBlock = new BuildingBlock();
+ buildingBlock.setBpmnScope(scope);
+ buildingBlock.setBpmnAction(action);
+ executeBuildingBlock.setBuildingBlock(buildingBlock);
+ buildingBlockExecution.setVariable(BUILDING_BLOCK, executeBuildingBlock);
+ }
+}
diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/ConfigureInstanceParamsForVfModuleTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/ConfigureInstanceParamsForVfModuleTest.java
new file mode 100644
index 0000000000..9baf5dc5bf
--- /dev/null
+++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/ConfigureInstanceParamsForVfModuleTest.java
@@ -0,0 +1,127 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2019 Bell Canada
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.client.cds;
+
+import com.google.gson.JsonObject;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
+import org.onap.so.serviceinstancebeans.ModelInfo;
+import org.onap.so.serviceinstancebeans.Resources;
+import org.onap.so.serviceinstancebeans.Service;
+import org.onap.so.serviceinstancebeans.VfModules;
+import org.onap.so.serviceinstancebeans.Vnfs;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import static org.junit.Assert.assertEquals;
+import static org.mockito.ArgumentMatchers.anyList;
+import static org.mockito.Mockito.doReturn;
+
+@RunWith(MockitoJUnitRunner.Silent.class)
+public class ConfigureInstanceParamsForVfModuleTest {
+
+ @InjectMocks
+ private ConfigureInstanceParamsForVfModule configureInstanceParamsForVfModule;
+
+ @Mock
+ private ExtractServiceFromUserParameters extractServiceFromUserParameters;
+
+ private static final String TEST_VNF_MODEL_CUSTOMIZATION_UUID = "23ce9ac4-e5dd-11e9-81b4-2a2ae2dbcce4";
+ private static final String TEST_VF_MODULE_CUSTOMIZATION_UUID = "23ce9ac4-e5dd-11e9-81b4-2a2ae2dbcce2";
+ private static final String TEST_INSTANCE_PARAM_VALUE_1 = "vf-module-1-value";
+ private static final String TEST_INSTANCE_PARAM_VALUE_2 = "vf-module-2-value";
+ private static final String TEST_INSTANCE_PARAM_KEY_1 = "instance-param-1";
+ private static final String TEST_INSTANCE_PARAM_KEY_2 = "instance-param-2";
+
+ @Test
+ public void testInstanceParamsForVfModule() throws Exception {
+ // given
+ List<Map<String, Object>> userParamsFromRequest = createRequestParameters();
+ JsonObject jsonObject = new JsonObject();
+ doReturn(getUserParams()).when(extractServiceFromUserParameters).getServiceFromRequestUserParams(anyList());
+
+ // when
+ configureInstanceParamsForVfModule.populateInstanceParams(jsonObject, userParamsFromRequest,
+ TEST_VNF_MODEL_CUSTOMIZATION_UUID, TEST_VF_MODULE_CUSTOMIZATION_UUID);
+
+ // verify
+ assertEquals(TEST_INSTANCE_PARAM_VALUE_1, jsonObject.get(TEST_INSTANCE_PARAM_KEY_1).getAsString());
+ assertEquals(TEST_INSTANCE_PARAM_VALUE_2, jsonObject.get(TEST_INSTANCE_PARAM_KEY_2).getAsString());
+ }
+
+ private List<Map<String, Object>> createRequestParameters() {
+ List<Map<String, Object>> userParams = new ArrayList<>();
+ Map<String, Object> userParamMap = new HashMap<>();
+ userParamMap.put("service", getUserParams());
+ userParams.add(userParamMap);
+ return userParams;
+ }
+
+ private Service getUserParams() {
+ Service service = new Service();
+ Resources resources = new Resources();
+ resources.setVnfs(createVnfs());
+ service.setResources(resources);
+ return service;
+ }
+
+ private List<Vnfs> createVnfs() {
+ Vnfs searchedVnf = createVnf();
+ List<Vnfs> vnfList = new ArrayList<>();
+ vnfList.add(searchedVnf);
+ return vnfList;
+ }
+
+ private Vnfs createVnf() {
+ Vnfs vnf = new Vnfs();
+ ModelInfo modelInfoForVnf = new ModelInfo();
+ modelInfoForVnf.setModelCustomizationId(TEST_VNF_MODEL_CUSTOMIZATION_UUID);
+ vnf.setModelInfo(modelInfoForVnf);
+
+ VfModules vfModule = new VfModules();
+
+ ModelInfo modelInfoForVfModule = new ModelInfo();
+ modelInfoForVfModule.setModelCustomizationId(TEST_VF_MODULE_CUSTOMIZATION_UUID);
+
+ vfModule.setModelInfo(modelInfoForVfModule);
+
+ // Set instance parameters.
+ List<Map<String, String>> instanceParamsListSearchedVfModule = new ArrayList<>();
+ Map<String, String> instanceParams = new HashMap<>();
+ instanceParams.put("instance-param-1", TEST_INSTANCE_PARAM_VALUE_1);
+ instanceParams.put("instance-param-2", TEST_INSTANCE_PARAM_VALUE_2);
+
+ instanceParamsListSearchedVfModule.add(instanceParams);
+ vfModule.setInstanceParams(instanceParamsListSearchedVfModule);
+
+ List<VfModules> vfModules = new ArrayList<>();
+ vfModules.add(vfModule);
+
+ vnf.setVfModules(vfModules);
+
+ return vnf;
+ }
+}
diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/GeneratePayloadForCdsTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/GeneratePayloadForCdsTest.java
new file mode 100644
index 0000000000..471bdb74fc
--- /dev/null
+++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/GeneratePayloadForCdsTest.java
@@ -0,0 +1,287 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2019 Bell Canada.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.so.client.cds;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.gson.JsonParser;
+import org.camunda.bpm.engine.delegate.DelegateExecution;
+import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.omg.Messaging.SYNC_WITH_TRANSPORT;
+import org.onap.so.bpmn.common.BuildingBlockExecution;
+import org.onap.so.bpmn.common.DelegateExecutionImpl;
+import org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock;
+import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock;
+import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock;
+import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
+import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestParameters;
+import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
+import org.onap.so.client.cds.beans.AbstractCDSPropertiesBean;
+import org.onap.so.client.exception.BBObjectNotFoundException;
+import org.onap.so.client.exception.PayloadGenerationException;
+import org.onap.so.serviceinstancebeans.*;
+import java.util.*;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.ThrowableAssert.catchThrowable;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.*;
+
+@RunWith(MockitoJUnitRunner.Silent.class)
+public class GeneratePayloadForCdsTest {
+ private static final String GENERIC_VNF_ID = "vnfId_configVnfTest1";
+ private static final String VF_MODULE_ID = "vf-module-id-1";
+ private static final String VF_MODULE_NAME = "vf-module-name-1";
+ private static final String VF_MODULE_CUSTOMIZATION_UUID = "23ce9ac4-e5dd-11e9-81b4-2a2ae2dbcce1";
+ private static final String GENERIC_VNF_NAME = "vnf-name-1";
+ private static final String SERVICE_INSTANCE_ID = "serviceInst_configTest";
+ private static final String SERVICE_MODEL_UUID = "b45b5780-e5dd-11e9-81b4-2a2ae2dbcce4";
+ private static final String SERVICE_INSTANCE_NAME = "test-service-instance";
+ private static final String VNF_MODEL_CUSTOMIZATION_UUID = "23ce9ac4-e5dd-11e9-81b4-2a2ae2dbcce4";
+ private static final String GENERAL_BLOCK_EXECUTION_MAP_KEY = "gBBInput";
+ private static final String VNF_SCOPE = "vnf";
+ private static final String SERVICE_SCOPE = "service";
+ private static final String SERVICE_ACTION = "create";
+ private static final String VF_SCOPE = "vfModule";
+ private static final String ASSIGN_ACTION = "configAssign";
+ private static final String DEPLOY_ACTION = "configDeploy";
+ private static final String MSO_REQUEST_ID = "1234";
+ private static final String BUILDING_BLOCK = "buildingBlock";
+ private static final String PUBLIC_NET_ID = "public-net-id";
+ private static final String CLOUD_REGION = "acl-cloud-region";
+
+ private BuildingBlockExecution buildingBlockExecution;
+ private ExecuteBuildingBlock executeBuildingBlock;
+
+ @InjectMocks
+ private GeneratePayloadForCds configurePayloadForCds;
+
+ @Mock
+ private VnfCDSRequestProvider vnfCDSRequestProvider;
+
+ @Mock
+ private VfModuleCDSRequestProvider vfModuleCDSRequestProvider;
+
+ @Mock
+ private ServiceCDSRequestProvider serviceCDSRequestProvider;
+
+
+ @Before
+ public void setup() {
+ buildingBlockExecution = createBuildingBlockExecution();
+ executeBuildingBlock = new ExecuteBuildingBlock();
+ }
+
+ @Test
+ public void testBuildCdsPropertiesBeanAssignVnf() throws Exception {
+ // given
+ final String assignPayload =
+ "{\"configAssign-request\":{\"resolution-key\":\"vnf-name-1\",\"configAssign-properties\":{\"service-instance-id\":\"serviceInst_configTest\",\"service-model-uuid\":\"b45b5780-e5dd-11e9-81b4-2a2ae2dbcce4\",\"vnf-id\":\"vnfId_configVnfTest1\",\"vnf-name\":\"vnf-name-1\",\"vnf-customization-uuid\":\"23ce9ac4-e5dd-11e9-81b4-2a2ae2dbcce4\",\"acl-cloud-region\":\"acl-cloud-region\",\"public_net_id\":\"public-net-id\"}}}";
+
+ setScopeAndAction(VNF_SCOPE, ASSIGN_ACTION);
+
+ doReturn(Optional.of(assignPayload)).when(vnfCDSRequestProvider).buildRequestPayload(ASSIGN_ACTION);
+
+ // when
+ AbstractCDSPropertiesBean propertyBean = configurePayloadForCds.buildCdsPropertiesBean(buildingBlockExecution);
+
+ // verify
+ assertNotNull(propertyBean);
+ String payload = propertyBean.getRequestObject();
+ assertThat(assignPayload.equals(payload));
+ assertThat(propertyBean.getRequestId().equals(MSO_REQUEST_ID));
+ assertThat(propertyBean.getOriginatorId().equals("SO"));
+ assertNotNull(propertyBean.getSubRequestId());
+ assertThat(propertyBean.getActionName().equals(ASSIGN_ACTION));
+ assertThat(propertyBean.getMode().equalsIgnoreCase("sync"));
+ }
+
+ @Test
+ public void testBuildCdsPropertiesBeanDeployVnf() throws Exception {
+ // given
+ final String deployPayload =
+ "{\"configDeploy-request\":{\"resolution-key\":\"vnf-name-1\",\"configDeploy-properties\":{\"service-instance-id\":\"serviceInst_configTest\",\"service-model-uuid\":\"b45b5780-e5dd-11e9-81b4-2a2ae2dbcce4\",\"vnf-id\":\"vnfId_configVnfTest1\",\"vnf-name\":\"vnf-name-1\",\"vnf-customization-uuid\":\"23ce9ac4-e5dd-11e9-81b4-2a2ae2dbcce4\",\"acl-cloud-region\":\"acl-cloud-region\",\"public_net_id\":\"public-net-id\"}}}";
+ setScopeAndAction(VNF_SCOPE, DEPLOY_ACTION);
+
+ doReturn(Optional.of(deployPayload)).when(vnfCDSRequestProvider).buildRequestPayload(DEPLOY_ACTION);
+
+ // when
+ AbstractCDSPropertiesBean propertyBean = configurePayloadForCds.buildCdsPropertiesBean(buildingBlockExecution);
+
+ // verify
+ assertNotNull(propertyBean);
+ String payload = propertyBean.getRequestObject();
+ assertThat(deployPayload.equals(payload));
+ assertThat(propertyBean.getRequestId().equals(MSO_REQUEST_ID));
+ assertThat(propertyBean.getOriginatorId().equals("SO"));
+ assertNotNull(propertyBean.getSubRequestId());
+ assertThat(propertyBean.getActionName().equals(DEPLOY_ACTION));
+ assertThat(propertyBean.getMode().equalsIgnoreCase("sync"));
+ }
+
+ @Test
+ public void testBuildCdsPropertiesBeanCreateService() throws Exception {
+ // given
+ final String servicePayload =
+ "{\"create-request\":{\"resolution-key\":\"test-service-instance\",\"create-properties\":{\"service-instance-id\":\"serviceInst_configTest\",\"service-model-uuid\":\"b45b5780-e5dd-11e9-81b4-2a2ae2dbcce4\"}}}";
+ setScopeAndAction(SERVICE_SCOPE, SERVICE_ACTION);
+ doReturn(Optional.of(servicePayload)).when(serviceCDSRequestProvider).buildRequestPayload(SERVICE_ACTION);
+
+ // when
+ AbstractCDSPropertiesBean propertyBean = configurePayloadForCds.buildCdsPropertiesBean(buildingBlockExecution);
+
+ // verify
+ assertNotNull(propertyBean);
+ String payload = propertyBean.getRequestObject();
+ assertThat(servicePayload.equals(payload));
+ assertThat(propertyBean.getRequestId().equals(MSO_REQUEST_ID));
+ assertThat(propertyBean.getOriginatorId().equals("SO"));
+ assertNotNull(propertyBean.getSubRequestId());
+ assertThat(propertyBean.getActionName().equals(SERVICE_ACTION));
+ assertThat(propertyBean.getMode().equalsIgnoreCase("sync"));
+ }
+
+ @Test
+ public void testBuildCdsPropertiesBeanConfigDeployVfModule() throws Exception {
+ // given
+ final String deployVfModulePayload =
+ "{\"configDeploy-request\":{\"resolution-key\":\"vf-module-name-1\",\"template-prefix\":\"vf-module-name-1configDeploy\",\"configDeploy-properties\":{\"service-instance-id\":\"serviceInst_configTest\",\"service-model-uuid\":\"b45b5780-e5dd-11e9-81b4-2a2ae2dbcce4\",\"vnf-id\":\"vnfId_configVnfTest1\",\"vnf-name\":\"vnf-name-1\",\"vf-module-id\":\"vf-module-id-1\",\"vf-module-name\":\"vf-module-name-1\",\"vf-module-customization-uuid\":\"23ce9ac4-e5dd-11e9-81b4-2a2ae2dbcce1\",\"aci-cloud-region-vf-module\":\"acl-cloud-region\",\"public-net-vf-module-id\":\"public-net-id\"}}}";
+ setScopeAndAction(VF_SCOPE, DEPLOY_ACTION);
+ doReturn(Optional.of(deployVfModulePayload)).when(vfModuleCDSRequestProvider)
+ .buildRequestPayload(DEPLOY_ACTION);
+
+ // when
+ AbstractCDSPropertiesBean propertyBean = configurePayloadForCds.buildCdsPropertiesBean(buildingBlockExecution);
+
+ // verify
+ assertNotNull(propertyBean);
+ String payload = propertyBean.getRequestObject();
+ assertThat(deployVfModulePayload.equals(payload));
+ assertThat(propertyBean.getRequestId().equals(MSO_REQUEST_ID));
+ assertThat(propertyBean.getOriginatorId().equals("SO"));
+ assertNotNull(propertyBean.getSubRequestId());
+ assertThat(propertyBean.getActionName().equals(DEPLOY_ACTION));
+ assertThat(propertyBean.getMode().equalsIgnoreCase("sync"));
+ }
+
+ @Test
+ public void testFailureWhenServiceInstanceIsNotPresent() throws Exception {
+ // given
+ setScopeAndAction(VNF_SCOPE, ASSIGN_ACTION);
+
+ doThrow(PayloadGenerationException.class).when(serviceCDSRequestProvider).buildRequestPayload(ASSIGN_ACTION);
+
+ // when
+ final Throwable throwable =
+ catchThrowable(() -> configurePayloadForCds.buildCdsPropertiesBean(buildingBlockExecution));
+
+ // verify
+ assertThat(throwable).isInstanceOf(PayloadGenerationException.class)
+ .hasMessage("Failed to build payload for CDS");
+ }
+
+ private BuildingBlockExecution createBuildingBlockExecution() {
+ DelegateExecution execution = new DelegateExecutionFake();
+ execution.setVariable(GENERAL_BLOCK_EXECUTION_MAP_KEY, createGeneralBuildingBlock());
+ return new DelegateExecutionImpl(execution);
+ }
+
+ private GeneralBuildingBlock createGeneralBuildingBlock() {
+ GeneralBuildingBlock generalBuildingBlock = new GeneralBuildingBlock();
+ RequestContext requestContext = new RequestContext();
+ RequestParameters requestParameters = new RequestParameters();
+ requestParameters.setUserParams(createRequestUserParams());
+ requestContext.setRequestParameters(requestParameters);
+ requestContext.setMsoRequestId(MSO_REQUEST_ID);
+ generalBuildingBlock.setRequestContext(requestContext);
+ return generalBuildingBlock;
+ }
+
+ private List<Map<String, Object>> createRequestUserParams() {
+ List<Map<String, Object>> userParams = new ArrayList<>();
+ Map<String, Object> userParamMap = new HashMap<>();
+ userParamMap.put("service", getUserParams());
+ userParams.add(userParamMap);
+ return userParams;
+ }
+
+ private Service getUserParams() {
+ Service service = new Service();
+ Resources resources = new Resources();
+ resources.setVnfs(createVnfList());
+ service.setResources(resources);
+ return service;
+ }
+
+ private List<Vnfs> createVnfList() {
+ List<Map<String, String>> instanceParamsListSearchedVnf = new ArrayList<>();
+ Map<String, String> instanceParam = new HashMap<>();
+ instanceParam.put("public_net_id", PUBLIC_NET_ID);
+ instanceParam.put("acl-cloud-region", CLOUD_REGION);
+ instanceParamsListSearchedVnf.add(instanceParam);
+ Vnfs searchedVnf = createVnf(instanceParamsListSearchedVnf);
+ List<Vnfs> vnfList = new ArrayList<>();
+ vnfList.add(searchedVnf);
+ return vnfList;
+ }
+
+ private Vnfs createVnf(List<Map<String, String>> instanceParamsList) {
+ Vnfs vnf = new Vnfs();
+ ModelInfo modelInfo = new ModelInfo();
+ modelInfo.setModelCustomizationId(VNF_MODEL_CUSTOMIZATION_UUID);
+ vnf.setModelInfo(modelInfo);
+ vnf.setInstanceParams(instanceParamsList);
+
+ // Set instance parameters and modelinfo for vf-module
+ VfModules vfModule = new VfModules();
+ ModelInfo modelInfoForVfModule = new ModelInfo();
+ modelInfoForVfModule.setModelCustomizationId(VF_MODULE_CUSTOMIZATION_UUID);
+ vfModule.setModelInfo(modelInfoForVfModule);
+
+ List<Map<String, String>> instanceParamsListSearchedVfModule = new ArrayList<>();
+ Map<String, String> instanceParams = new HashMap<>();
+ instanceParams.put("public-net-vf-module-id", PUBLIC_NET_ID);
+ instanceParams.put("aci-cloud-region-vf-module", CLOUD_REGION);
+
+ instanceParamsListSearchedVfModule.add(instanceParams);
+ vfModule.setInstanceParams(instanceParamsListSearchedVfModule);
+
+ List<VfModules> vfModules = new ArrayList<>();
+ vfModules.add(vfModule);
+
+ vnf.setVfModules(vfModules);
+
+ return vnf;
+ }
+
+ private void setScopeAndAction(String scope, String action) {
+ BuildingBlock buildingBlock = new BuildingBlock();
+ buildingBlock.setBpmnScope(scope);
+ buildingBlock.setBpmnAction(action);
+ executeBuildingBlock.setBuildingBlock(buildingBlock);
+ buildingBlockExecution.setVariable(BUILDING_BLOCK, executeBuildingBlock);
+ }
+}
diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/ServiceCDSRequestProviderTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/ServiceCDSRequestProviderTest.java
new file mode 100644
index 0000000000..70ce3a1eed
--- /dev/null
+++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/ServiceCDSRequestProviderTest.java
@@ -0,0 +1,62 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Nordix
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.client.cds;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.junit.Test;
+import org.mockito.InjectMocks;
+import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
+import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.*;
+
+public class ServiceCDSRequestProviderTest extends AbstractVnfCDSRequestProviderTest {
+
+ @InjectMocks
+ private ServiceCDSRequestProvider serviceCDSRequestProvider;
+
+ @Test
+ public void testRequestPayloadForCreateService() throws Exception {
+ // given
+ setScopeAndAction(SERVICE_SCOPE, SERVICE_ACTION);
+ ServiceInstance instance = createServiceInstance();
+ doReturn(instance).when(extractPojosForBB).extractByKey(buildingBlockExecution,
+ ResourceKey.SERVICE_INSTANCE_ID);
+
+ // when
+ serviceCDSRequestProvider.setExecutionObject(buildingBlockExecution);
+ String payload = serviceCDSRequestProvider.buildRequestPayload(SERVICE_ACTION).get();
+
+ // verify
+ ObjectMapper mapper = new ObjectMapper();
+ JsonNode payloadJson = mapper.readTree(payload);
+ JsonNode requestNode = payloadJson.findValue("create-request");
+ JsonNode propertiesNode = payloadJson.findValue("create-properties");
+
+ assertNotNull(payload);
+ assertTrue(verfiyJsonFromString(payload));
+ assertThat(requestNode.get("resolution-key").asText()).isEqualTo(SERVICE_INSTANCE_NAME);
+ assertThat(propertiesNode.get("service-instance-id").asText()).isEqualTo(SERVICE_INSTANCE_ID);
+ assertThat(propertiesNode.get("service-model-uuid").asText()).isEqualTo(SERVICE_MODEL_UUID);
+ }
+}
diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/VfModuleCDSRequestProviderTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/VfModuleCDSRequestProviderTest.java
new file mode 100644
index 0000000000..2ca09d9ab3
--- /dev/null
+++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/VfModuleCDSRequestProviderTest.java
@@ -0,0 +1,80 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Nordix
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.client.cds;
+
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.junit.Test;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
+import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.*;
+
+public class VfModuleCDSRequestProviderTest extends AbstractVnfCDSRequestProviderTest {
+
+ @InjectMocks
+ private VfModuleCDSRequestProvider vfModuleCDSRequestProvider;
+
+ @Mock
+ protected ConfigureInstanceParamsForVfModule configureInstanceParamsForVfModule;
+
+ @Test
+ public void testRequestPayloadForConfigDeployVfModule() throws Exception {
+ // given
+ setScopeAndAction(VF_SCOPE, DEPLOY_ACTION);
+ ServiceInstance serviceInstance = createServiceInstance();
+
+ doReturn(serviceInstance).when(extractPojosForBB).extractByKey(buildingBlockExecution,
+ ResourceKey.SERVICE_INSTANCE_ID);
+ doReturn(createGenericVnf()).when(extractPojosForBB).extractByKey(buildingBlockExecution,
+ ResourceKey.GENERIC_VNF_ID);
+ doReturn(createVfModule()).when(extractPojosForBB).extractByKey(buildingBlockExecution,
+ ResourceKey.VF_MODULE_ID);
+ doNothing().when(configureInstanceParamsForVfModule).populateInstanceParams(any(), any(), anyString(),
+ anyString());
+
+ // when
+ vfModuleCDSRequestProvider.setExecutionObject(buildingBlockExecution);
+ String payload = vfModuleCDSRequestProvider.buildRequestPayload(DEPLOY_ACTION).get();
+
+ // verify
+ ObjectMapper mapper = new ObjectMapper();
+ JsonNode payloadJson = mapper.readTree(payload);
+ JsonNode requestNode = payloadJson.findValue("configDeploy-request");
+ JsonNode propertiesNode = payloadJson.findValue("configDeploy-properties");
+
+ assertNotNull(payload);
+ assertTrue(verfiyJsonFromString(payload));
+ assertThat(requestNode.get("resolution-key").asText()).isEqualTo(VF_MODULE_NAME);
+ assertThat(propertiesNode.get("service-instance-id").asText()).isEqualTo(SERVICE_INSTANCE_ID);
+ assertThat(propertiesNode.get("vf-module-id").asText()).isEqualTo(VF_MODULE_ID);
+ assertThat(propertiesNode.get("vf-module-name").asText()).isEqualTo(VF_MODULE_NAME);
+ assertThat(propertiesNode.get("vf-module-customization-uuid").asText()).isEqualTo(VF_MODULE_CUSTOMIZATION_UUID);
+ assertThat(propertiesNode.get("service-model-uuid").asText()).isEqualTo(SERVICE_MODEL_UUID);
+ assertThat(propertiesNode.get("vnf-id").asText()).isEqualTo(GENERIC_VNF_ID);
+ }
+
+
+}
diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/VnfCDSRequestProviderTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/VnfCDSRequestProviderTest.java
new file mode 100644
index 0000000000..7aafd900d4
--- /dev/null
+++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/VnfCDSRequestProviderTest.java
@@ -0,0 +1,104 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Nordix
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.client.cds;
+
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.junit.Test;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
+import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.*;
+
+public class VnfCDSRequestProviderTest extends AbstractVnfCDSRequestProviderTest {
+
+ @InjectMocks
+ private VnfCDSRequestProvider vnfCDSRequestProvider;
+
+ @Mock
+ protected ConfigureInstanceParamsForVnf configureInstanceParamsForVnf;
+
+ @Test
+ public void testBuildRequestPayloadAssignActionVnf() throws Exception {
+ // given
+ setScopeAndAction(VNF_SCOPE, ASSIGN_ACTION);
+ ServiceInstance instance = createServiceInstance();
+
+ doReturn(instance).when(extractPojosForBB).extractByKey(buildingBlockExecution,
+ ResourceKey.SERVICE_INSTANCE_ID);
+ doReturn(createGenericVnf()).when(extractPojosForBB).extractByKey(buildingBlockExecution,
+ ResourceKey.GENERIC_VNF_ID);
+ doNothing().when(configureInstanceParamsForVnf).populateInstanceParams(any(), any(), anyString());
+
+ // when
+ vnfCDSRequestProvider.setExecutionObject(buildingBlockExecution);
+ String payload = vnfCDSRequestProvider.buildRequestPayload(ASSIGN_ACTION).get();
+
+ // verify
+ ObjectMapper mapper = new ObjectMapper();
+ JsonNode payloadJson = mapper.readTree(payload);
+ JsonNode requestNode = payloadJson.findValue("configAssign-request");
+ JsonNode propertiesNode = payloadJson.findValue("configAssign-properties");
+
+ assertNotNull(payload);
+ assertTrue(verfiyJsonFromString(payload));
+ assertThat(requestNode.get("resolution-key").asText()).isEqualTo(GENERIC_VNF_NAME);
+ assertThat(propertiesNode.get("service-instance-id").asText()).isEqualTo(SERVICE_INSTANCE_ID);
+ assertThat(propertiesNode.get("service-model-uuid").asText()).isEqualTo(SERVICE_MODEL_UUID);
+ assertThat(propertiesNode.get("vnf-id").asText()).isEqualTo(GENERIC_VNF_ID);
+ assertThat(propertiesNode.get("vnf-customization-uuid").asText()).isEqualTo(VNF_MODEL_CUSTOMIZATION_UUID);
+ }
+
+ @Test
+ public void testBuildRequestPayloadDeployActionVnf() throws Exception {
+ // given
+ setScopeAndAction(VNF_SCOPE, DEPLOY_ACTION);
+ ServiceInstance instance = createServiceInstance();
+
+ doReturn(instance).when(extractPojosForBB).extractByKey(buildingBlockExecution,
+ ResourceKey.SERVICE_INSTANCE_ID);
+ doReturn(createGenericVnf()).when(extractPojosForBB).extractByKey(buildingBlockExecution,
+ ResourceKey.GENERIC_VNF_ID);
+ doNothing().when(configureInstanceParamsForVnf).populateInstanceParams(any(), any(), any());
+
+ // when
+ vnfCDSRequestProvider.setExecutionObject(buildingBlockExecution);
+ String payload = vnfCDSRequestProvider.buildRequestPayload(DEPLOY_ACTION).get();
+
+ // verify
+ ObjectMapper mapper = new ObjectMapper();
+ JsonNode payloadJson = mapper.readTree(payload);
+ JsonNode requestNode = payloadJson.findValue("configDeploy-request");
+ JsonNode propertiesNode = payloadJson.findValue("configDeploy-properties");
+
+ assertNotNull(payload);
+ assertTrue(verfiyJsonFromString(payload));
+ assertThat(requestNode.get("resolution-key").asText()).isEqualTo(GENERIC_VNF_NAME);
+ assertThat(propertiesNode.get("service-instance-id").asText()).isEqualTo(SERVICE_INSTANCE_ID);
+ assertThat(propertiesNode.get("service-model-uuid").asText()).isEqualTo(SERVICE_MODEL_UUID);
+ assertThat(propertiesNode.get("vnf-id").asText()).isEqualTo(GENERIC_VNF_ID);
+ assertThat(propertiesNode.get("vnf-customization-uuid").asText()).isEqualTo(VNF_MODEL_CUSTOMIZATION_UUID);
+ }
+}
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIUpdateTasks.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIUpdateTasks.java
index 4d5494d18c..8a6c4c2796 100644
--- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIUpdateTasks.java
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIUpdateTasks.java
@@ -5,13 +5,14 @@
* Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Modifications Copyright (c) 2019 Samsung
+ * Modifications Copyright (c) 2019 Bell Canada.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -22,39 +23,23 @@
package org.onap.so.bpmn.infrastructure.aai.tasks;
-import java.util.List;
-import java.util.Map;
import org.onap.so.adapters.nwrest.CreateNetworkResponse;
import org.onap.so.adapters.nwrest.UpdateNetworkResponse;
import org.onap.so.bpmn.common.BuildingBlockExecution;
-import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
-import org.onap.so.bpmn.servicedecomposition.bbobjects.Collection;
-import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration;
-import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
-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.Subnet;
-import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
-import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup;
+import org.onap.so.bpmn.servicedecomposition.bbobjects.*;
import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock;
import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
import org.onap.so.client.exception.BBObjectNotFoundException;
import org.onap.so.client.exception.ExceptionBuilder;
-import org.onap.so.client.orchestration.AAICollectionResources;
-import org.onap.so.client.orchestration.AAIConfigurationResources;
-import org.onap.so.client.orchestration.AAINetworkResources;
-import org.onap.so.client.orchestration.AAIPnfResources;
-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.AAIVolumeGroupResources;
+import org.onap.so.client.orchestration.*;
import org.onap.so.db.catalog.beans.OrchestrationStatus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
+import java.util.List;
+import java.util.Map;
@Component
public class AAIUpdateTasks {
@@ -340,7 +325,6 @@ public class AAIUpdateTasks {
* BPMN access method to update status of VfModule to Created in AAI
*
* @param execution
- *
*/
public void updateOrchestrationStatusCreatedVfModule(BuildingBlockExecution execution) {
try {
@@ -357,7 +341,6 @@ public class AAIUpdateTasks {
* BPMN access method to update aaiDeactivateVfModuleRollback to true for deactivating the VfModule
*
* @param execution
- * @throws buildAndThrowWorkflowException
*/
public void updateOrchestrationStatusDeactivateVfModule(BuildingBlockExecution execution) {
execution.setVariable("aaiDeactivateVfModuleRollback", false);
@@ -794,7 +777,6 @@ public class AAIUpdateTasks {
logger.error("Exception occurred in AAIUpdateTasks updateOrchestrationStatusConfigDeployConfigureVnf", ex);
exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
}
-
}
/**
@@ -806,11 +788,55 @@ public class AAIUpdateTasks {
try {
GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
aaiVnfResources.updateOrchestrationStatusVnf(vnf, OrchestrationStatus.CONFIGURED);
-
} catch (Exception ex) {
logger.error("Exception occurred in AAIUpdateTasks updateOrchestrationStatusConfigDeployConfiguredVnf", ex);
exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
}
+ }
+ /**
+ * BPMN access method to update status of VNF/VF-Module based on SO scope and action.
+ *
+ * @param execution - BuildingBlockExecution
+ * @param scope - SO scope (vnf/vfModule)
+ * @param action - action (configAssign/configDeploy/configUndeploy etc..)
+ */
+ public void updateOrchestrationStatusForCds(BuildingBlockExecution execution, String scope, String action) {
+ try {
+ GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
+ OrchestrationStatus status = getOrchestrationStatus(action);
+ switch (scope) {
+ case "vnf":
+ aaiVnfResources.updateOrchestrationStatusVnf(vnf, status);
+ break;
+ case "vfModule":
+ VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID);
+ aaiVfModuleResources.updateOrchestrationStatusVfModule(vfModule, vnf, status);
+ break;
+ default:
+ throw new IllegalArgumentException(
+ "Invalid scope to update orchestration status for CDS : " + action);
+ }
+ } catch (Exception ex) {
+ logger.error("Exception occurred in AAIUpdateTasks updateOrchestrationStatusForCds", ex);
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
+ }
+ }
+
+ private OrchestrationStatus getOrchestrationStatus(String action) {
+ /**
+ * At this state, OrcherstationStatus enum associated with configAssign and configDeploy. I am not sure which is
+ * the correct approach. 1. Are we going to map each specific action to OrchestrationStauts ? 2. We will have
+ * only one generic status for all actions ?
+ */
+
+ switch (action) {
+ case "configAssign":
+ return OrchestrationStatus.ASSIGNED;
+ case "configDeploy":
+ return OrchestrationStatus.CONFIGURED;
+ default:
+ throw new IllegalArgumentException("Invalid action to set Orchestration status: " + action);
+ }
}
}
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/controller/cds/CdsControllerDE.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/controller/cds/CdsControllerDE.java
index 6b0cbc0396..0f65b4b3d4 100644
--- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/controller/cds/CdsControllerDE.java
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/controller/cds/CdsControllerDE.java
@@ -31,11 +31,14 @@ import org.springframework.stereotype.Component;
* This implementation of {@ref ControllerRunnable} is used for Self service, i.e, blueprint based Controller.
*/
@Component
-public class CdsControllerDE extends AbstractCDSProcessingBBUtils implements ControllerRunnable<DelegateExecution> {
+public class CdsControllerDE implements ControllerRunnable<DelegateExecution> {
@Autowired(required = false)
private List<ControllerPreparable<DelegateExecution>> prepareList;
+ @Autowired
+ private AbstractCDSProcessingBBUtils abstractCDSProcessingBBUtils;
+
@Override
public Boolean understand(ControllerContext<DelegateExecution> context) {
return context.getControllerActor().equalsIgnoreCase("cds");
@@ -55,7 +58,7 @@ public class CdsControllerDE extends AbstractCDSProcessingBBUtils implements Con
@Override
public void run(ControllerContext<DelegateExecution> context) {
DelegateExecution execution = context.getExecution();
- constructExecutionServiceInputObject(execution);
- sendRequestToCDSClient(execution);
+ abstractCDSProcessingBBUtils.constructExecutionServiceInputObject(execution);
+ abstractCDSProcessingBBUtils.sendRequestToCDSClient(execution);
}
}
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericCDSProcessingBB.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericCDSProcessingBB.java
new file mode 100644
index 0000000000..f568026aa5
--- /dev/null
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericCDSProcessingBB.java
@@ -0,0 +1,92 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2019 Bell Canada
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.bpmn.infrastructure.flowspecific.tasks;
+
+import org.onap.so.bpmn.common.BuildingBlockExecution;
+import org.onap.so.bpmn.infrastructure.decisionpoint.api.ControllerContext;
+import org.onap.so.bpmn.infrastructure.decisionpoint.api.ControllerRunnable;
+import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
+import org.onap.so.client.cds.AbstractCDSProcessingBBUtils;
+import org.onap.so.client.cds.GeneratePayloadForCds;
+import org.onap.so.client.cds.beans.AbstractCDSPropertiesBean;
+import org.onap.so.client.exception.ExceptionBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+/**
+ * For Vnf/Vf-Module/Service BuildingBlockExecution is being used.
+ *
+ * @param - BuildingBlockExecution
+ */
+@Component
+public class GenericCDSProcessingBB implements ControllerRunnable<BuildingBlockExecution> {
+ private static final Logger logger = LoggerFactory.getLogger(GenericCDSProcessingBB.class);
+ private static final String EXECUTION_OBJECT = "executionObject";
+ public static final String CDS_ACTOR = "cds";
+ public static final String VNF_SCOPE = "vnf";
+ public static final String VF_MODULE_SCOPE = "vf-module";
+
+ @Autowired
+ private ExceptionBuilder exceptionBuilder;
+
+ @Autowired
+ private ExtractPojosForBB extractPojosForBB;
+
+ @Autowired
+ private AbstractCDSProcessingBBUtils cdsDispather;
+
+ @Autowired
+ private GeneratePayloadForCds generatePayloadForCds;
+
+ @Override
+ public Boolean understand(ControllerContext<BuildingBlockExecution> context) {
+ String scope = context.getControllerScope();
+ return CDS_ACTOR.equalsIgnoreCase(context.getControllerActor())
+ && (VNF_SCOPE.equalsIgnoreCase(scope) || VF_MODULE_SCOPE.equalsIgnoreCase(scope));
+ }
+
+ @Override
+ public Boolean ready(ControllerContext<BuildingBlockExecution> context) {
+ return true;
+ }
+
+ @Override
+ public void prepare(ControllerContext<BuildingBlockExecution> context) {
+ BuildingBlockExecution buildingBlockExecution = context.getExecution();
+ try {
+ AbstractCDSPropertiesBean abstractCDSPropertiesBean =
+ generatePayloadForCds.buildCdsPropertiesBean(buildingBlockExecution);
+ buildingBlockExecution.setVariable(EXECUTION_OBJECT, abstractCDSPropertiesBean);
+ } catch (Exception ex) {
+ logger.error("An exception occurred when creating payload for CDS request", ex);
+ exceptionBuilder.buildAndThrowWorkflowException(buildingBlockExecution, 7000, ex);
+ }
+ }
+
+ @Override
+ public void run(ControllerContext<BuildingBlockExecution> context) {
+ BuildingBlockExecution obj = context.getExecution();
+ cdsDispather.constructExecutionServiceInputObject(obj);
+ cdsDispather.sendRequestToCDSClient(obj);
+ }
+}
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 2284c4af1a..9ee0104a5f 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
@@ -94,6 +94,7 @@ import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
+import org.springframework.util.CollectionUtils;
@Component
public class WorkflowAction {
@@ -410,15 +411,17 @@ public class WorkflowAction {
}
}
- if (flowsToExecute == null || flowsToExecute.isEmpty()) {
+ if (CollectionUtils.isEmpty(flowsToExecute)) {
throw new IllegalStateException("Macro did not come up with a valid execution path.");
}
+
List<String> flowNames = new ArrayList<>();
logger.info("List of BuildingBlocks to execute:");
- for (ExecuteBuildingBlock ebb : flowsToExecute) {
+
+ flowsToExecute.forEach(ebb -> {
logger.info(ebb.getBuildingBlock().getBpmnFlowName());
flowNames.add(ebb.getBuildingBlock().getBpmnFlowName());
- }
+ });
if (!isResume) {
bbInputSetupUtils.persistFlowExecutionPath(requestId, flowsToExecute);
diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/controller/cds/CdsControllerDETest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/controller/cds/CdsControllerDETest.java
index 79bce8a1f4..142cb53ed8 100644
--- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/controller/cds/CdsControllerDETest.java
+++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/controller/cds/CdsControllerDETest.java
@@ -26,8 +26,10 @@ import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.mockito.Mock;
import org.onap.so.bpmn.infrastructure.decisionpoint.api.ControllerContext;
import org.onap.so.bpmn.infrastructure.decisionpoint.api.controller.ControllerPreparable;
+import org.onap.so.client.cds.AbstractCDSProcessingBBUtils;
import org.onap.so.client.exception.ExceptionBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.mock.mockito.MockBean;
@@ -35,7 +37,7 @@ import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class)
-@ContextConfiguration(classes = {CdsControllerDE.class, ExceptionBuilder.class})
+@ContextConfiguration(classes = {CdsControllerDE.class, ExceptionBuilder.class, AbstractCDSProcessingBBUtils.class})
public class CdsControllerDETest {
@Autowired
@@ -47,6 +49,9 @@ public class CdsControllerDETest {
@MockBean
private ControllerPreparable<DelegateExecution> preparable;
+ @Mock
+ private AbstractCDSProcessingBBUtils abstractCDSProcessingBBUtils;
+
@Before
public void setUp() {
when(controllerContext.getControllerActor()).thenReturn("cds");
diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericCDSProcessingBBTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericCDSProcessingBBTest.java
new file mode 100644
index 0000000000..24bbc78afb
--- /dev/null
+++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericCDSProcessingBBTest.java
@@ -0,0 +1,197 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2019 Bell Canada.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.so.bpmn.infrastructure.flowspecific.tasks;
+
+import org.camunda.bpm.engine.delegate.DelegateExecution;
+import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.onap.so.bpmn.BaseTaskTest;
+import org.onap.so.bpmn.common.BuildingBlockExecution;
+import org.onap.so.bpmn.common.DelegateExecutionImpl;
+import org.onap.so.bpmn.infrastructure.decisionpoint.api.ControllerContext;
+import org.onap.so.bpmn.infrastructure.decisionpoint.api.ControllerRunnable;
+import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
+import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
+import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
+import org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock;
+import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock;
+import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock;
+import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
+import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
+import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestParameters;
+import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoGenericVnf;
+import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoServiceInstance;
+import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoVfModule;
+import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
+import org.onap.so.client.cds.*;
+import org.onap.so.client.cds.beans.AbstractCDSPropertiesBean;
+import org.onap.so.client.exception.ExceptionBuilder;
+import org.onap.so.serviceinstancebeans.ModelInfo;
+import org.onap.so.serviceinstancebeans.Resources;
+import org.onap.so.serviceinstancebeans.Service;
+import org.onap.so.serviceinstancebeans.Vnfs;
+import org.springframework.beans.factory.annotation.Autowired;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.mockito.Mockito.*;
+
+public class GenericCDSProcessingBBTest extends BaseTaskTest {
+
+ private static final String VNF_SCOPE = "vnf";
+ private static final String TEST_VNF_MODEL_CUSTOMIZATION_UUID = "23ce9ac4-e5dd-11e9-81b4-2a2ae2dbcce4";
+ private static final String DEPLOY_ACTION_FOR_CDS = "configDeploy";
+ private static final String GENERAL_BLOCK_EXECUTION_MAP_KEY = "gBBInput";
+ private static final String BUILDING_BLOCK = "buildingBlock";
+ private static final String TEST_MSO_REQUEST_ID = "ff874603-4222-11e7-9252-005056850d2e";
+ private static final String EXECUTION_OBJECT = "executionObject";
+ private static final String BLUEPRINT_NAME = "test";
+ private static final String BLUEPRINT_VERSION = "1.0.0";
+
+ @InjectMocks
+ private GenericCDSProcessingBB controllerRunnable;
+
+ @Mock
+ private AbstractCDSProcessingBBUtils cdsDispather;
+
+ @Mock
+ private GeneratePayloadForCds generatePayloadForCds;
+
+ private BuildingBlockExecution buildingBlockExecution;
+
+ private ExecuteBuildingBlock executeBuildingBlock;
+
+ @Before
+ public void setUp() {
+ buildingBlockExecution = createBuildingBlockExecution();
+ executeBuildingBlock = new ExecuteBuildingBlock();
+ }
+
+ @Test
+ public void testExecutionObjectCreationForVnf() throws Exception {
+ // given
+ ControllerContext<BuildingBlockExecution> controllerContext = new ControllerContext<>();
+ controllerContext.setExecution(buildingBlockExecution);
+ controllerContext.setControllerActor("CDS");
+ controllerContext.setControllerScope("vnf");
+ setScopeAndAction(VNF_SCOPE, DEPLOY_ACTION_FOR_CDS);
+ AbstractCDSPropertiesBean cdsBean = prepareCDSBean();
+
+ doReturn(cdsBean).when(generatePayloadForCds).buildCdsPropertiesBean(buildingBlockExecution);
+ doNothing().when(cdsDispather).constructExecutionServiceInputObject(buildingBlockExecution);
+ doNothing().when(cdsDispather).sendRequestToCDSClient(buildingBlockExecution);
+
+ // when
+ Boolean isUnderstandable = controllerRunnable.understand(controllerContext);
+ Boolean isReady = controllerRunnable.ready(controllerContext);
+ controllerRunnable.prepare(controllerContext);
+ controllerRunnable.run(controllerContext);
+
+ // verify
+ assertEquals(isUnderstandable, true);
+ assertEquals(isReady, true);
+ AbstractCDSPropertiesBean executionObject = buildingBlockExecution.getVariable(EXECUTION_OBJECT);
+ assertNotNull(executionObject);
+ assertThat(executionObject).isInstanceOf(AbstractCDSPropertiesBean.class);
+ assertEquals(BLUEPRINT_NAME, executionObject.getBlueprintName());
+ assertEquals(BLUEPRINT_VERSION, executionObject.getBlueprintVersion());
+ assertEquals(TEST_MSO_REQUEST_ID, executionObject.getRequestId());
+ assertNotNull(executionObject.getRequestObject());
+ }
+
+ private AbstractCDSPropertiesBean prepareCDSBean() {
+ AbstractCDSPropertiesBean cdsBean = new AbstractCDSPropertiesBean();
+ cdsBean.setBlueprintName(BLUEPRINT_NAME);
+ cdsBean.setBlueprintVersion(BLUEPRINT_VERSION);
+ cdsBean.setRequestId(TEST_MSO_REQUEST_ID);
+ cdsBean.setRequestObject("requestObject");
+
+ return cdsBean;
+ }
+
+ private GeneralBuildingBlock createGeneralBuildingBlock() {
+ GeneralBuildingBlock generalBuildingBlock = new GeneralBuildingBlock();
+ RequestContext requestContext = new RequestContext();
+ RequestParameters requestParameters = new RequestParameters();
+ requestParameters.setUserParams(createRequestParameters());
+ requestContext.setRequestParameters(requestParameters);
+ requestContext.setMsoRequestId(TEST_MSO_REQUEST_ID);
+ generalBuildingBlock.setRequestContext(requestContext);
+ return generalBuildingBlock;
+ }
+
+ private List<Map<String, Object>> createRequestParameters() {
+ List<Map<String, Object>> userParams = new ArrayList<>();
+ Map<String, Object> userParamMap = new HashMap<>();
+ userParamMap.put("service", getUserParams());
+ userParams.add(userParamMap);
+ return userParams;
+ }
+
+ private Service getUserParams() {
+ Service service = new Service();
+ Resources resources = new Resources();
+ resources.setVnfs(createVnfList());
+ service.setResources(resources);
+ return service;
+ }
+
+ private List<Vnfs> createVnfList() {
+ List<Map<String, String>> instanceParamsListSearchedVnf = new ArrayList<>();
+ Map<String, String> instanceParam = new HashMap<>();
+ instanceParam.put("sec_group", "sec_group");
+ instanceParam.put("net_id", "acl-cloud-region");
+ instanceParamsListSearchedVnf.add(instanceParam);
+ Vnfs searchedVnf = createVnf(instanceParamsListSearchedVnf);
+ List<Vnfs> vnfList = new ArrayList<>();
+ vnfList.add(searchedVnf);
+ return vnfList;
+ }
+
+ private Vnfs createVnf(List<Map<String, String>> instanceParamsList) {
+ Vnfs vnf = new Vnfs();
+ ModelInfo modelInfo = new ModelInfo();
+ modelInfo.setModelCustomizationId(TEST_VNF_MODEL_CUSTOMIZATION_UUID);
+ vnf.setModelInfo(modelInfo);
+ vnf.setInstanceParams(instanceParamsList);
+ return vnf;
+ }
+
+ private BuildingBlockExecution createBuildingBlockExecution() {
+ DelegateExecution execution = new DelegateExecutionFake();
+ execution.setVariable(GENERAL_BLOCK_EXECUTION_MAP_KEY, createGeneralBuildingBlock());
+ return new DelegateExecutionImpl(execution);
+ }
+
+ private void setScopeAndAction(String scope, String action) {
+ BuildingBlock buildingBlock = new BuildingBlock();
+ buildingBlock.setBpmnScope(scope);
+ buildingBlock.setBpmnAction(action);
+ executeBuildingBlock.setBuildingBlock(buildingBlock);
+ buildingBlockExecution.setVariable(BUILDING_BLOCK, executeBuildingBlock);
+ }
+}
diff --git a/pom.xml b/pom.xml
index 0955338a4e..0719b205df 100644
--- a/pom.xml
+++ b/pom.xml
@@ -337,28 +337,28 @@
</configuration>
</plugin>
<plugin>
- <groupId>org.jacoco</groupId>
- <artifactId>jacoco-maven-plugin</artifactId>
- <version>${jacoco.version}</version>
- <executions>
- <execution>
- <id>prepare-agent</id>
- <goals>
- <goal>prepare-agent</goal>
- </goals>
- </execution>
- <execution>
- <id>report</id>
- <goals>
- <goal>report</goal>
- </goals>
- <configuration>
- <dataFile>${project.build.directory}/code-coverage/jacoco.exec</dataFile>
- <outputDirectory>${project.reporting.outputDirectory}/jacoco-ut</outputDirectory>
- </configuration>
- </execution>
- </executions>
- </plugin>
+ <groupId>org.jacoco</groupId>
+ <artifactId>jacoco-maven-plugin</artifactId>
+ <version>${jacoco.version}</version>
+ <executions>
+ <execution>
+ <id>prepare-agent</id>
+ <goals>
+ <goal>prepare-agent</goal>
+ </goals>
+ </execution>
+ <execution>
+ <id>report</id>
+ <goals>
+ <goal>report</goal>
+ </goals>
+ <configuration>
+ <dataFile>${project.build.directory}/code-coverage/jacoco.exec</dataFile>
+ <outputDirectory>${project.reporting.outputDirectory}/jacoco-ut</outputDirectory>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>license-maven-plugin</artifactId>