aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericPnfCDSControllerRunnableBB.java166
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericPnfCDSProcessingDE.java1
-rw-r--r--bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericPnfCDSControllerRunnableBBTest.java156
-rw-r--r--bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericPnfCDSProcessingDETest.java4
4 files changed, 322 insertions, 5 deletions
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericPnfCDSControllerRunnableBB.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericPnfCDSControllerRunnableBB.java
new file mode 100644
index 0000000000..a1e513fd47
--- /dev/null
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericPnfCDSControllerRunnableBB.java
@@ -0,0 +1,166 @@
+/*
+ * ============LICENSE_START======================================================= Copyright (C) 2020 Nokia. All rights
+ * reserved. ================================================================================ 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 com.google.gson.JsonObject;
+import org.onap.logging.filter.base.ONAPComponents;
+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.bbobjects.Pnf;
+import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
+import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock;
+import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
+import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
+import org.onap.so.client.cds.AbstractCDSProcessingBBUtils;
+import org.onap.so.client.cds.beans.AbstractCDSPropertiesBean;
+import org.onap.so.client.cds.PayloadConstants;
+import org.onap.so.client.exception.BBObjectNotFoundException;
+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;
+import java.util.UUID;
+import static org.onap.so.client.cds.PayloadConstants.PRC_BLUEPRINT_NAME;
+import static org.onap.so.client.cds.PayloadConstants.PRC_BLUEPRINT_VERSION;
+import static org.onap.so.client.cds.PayloadConstants.RESOLUTION_KEY;
+import static org.onap.so.client.cds.PayloadConstants.REQUEST;
+import static org.onap.so.client.cds.PayloadConstants.SEPARATOR;
+import static org.onap.so.client.cds.PayloadConstants.PROPERTIES;
+
+@Component
+public class GenericPnfCDSControllerRunnableBB implements ControllerRunnable<BuildingBlockExecution> {
+
+ private static final Logger logger = LoggerFactory.getLogger(GenericPnfCDSControllerRunnableBB.class);
+ private static final String EXECUTION_OBJECT = "executionObject";
+ private static final String ORIGINATOR_ID = "SO";
+ private static final String BUILDING_BLOCK = "buildingBlock";
+ private static final String DEFAULT_SYNC_MODE = "sync";
+ private static final String MSO_REQUEST_ID = "msoRequestId";
+
+ private AbstractCDSProcessingBBUtils abstractCDSProcessingBBUtils;
+ private ExtractPojosForBB extractPojosForBB;
+ private ExceptionBuilder exceptionBuilder;
+
+ @Autowired
+ public GenericPnfCDSControllerRunnableBB(AbstractCDSProcessingBBUtils abstractCDSProcessingBBUtils,
+ ExtractPojosForBB extractPojosForBB, ExceptionBuilder exceptionBuilder) {
+ this.abstractCDSProcessingBBUtils = abstractCDSProcessingBBUtils;
+ this.extractPojosForBB = extractPojosForBB;
+ this.exceptionBuilder = exceptionBuilder;
+ }
+
+ @Override
+ public Boolean understand(ControllerContext<BuildingBlockExecution> controllerContext) {
+ return PayloadConstants.CDS_ACTOR.equalsIgnoreCase(controllerContext.getControllerActor())
+ && PayloadConstants.PNF_SCOPE.equalsIgnoreCase(controllerContext.getControllerScope());
+ }
+
+ @Override
+ public Boolean ready(ControllerContext<BuildingBlockExecution> controllerContext) {
+ return true;
+ }
+
+ @Override
+ public void prepare(ControllerContext<BuildingBlockExecution> controllerContext) {
+ BuildingBlockExecution buildingBlockExecution = controllerContext.getExecution();
+ final AbstractCDSPropertiesBean abstractCDSPropertiesBean =
+ prepareAndSetCdsPropertyBean(buildingBlockExecution);
+
+ buildingBlockExecution.setVariable(EXECUTION_OBJECT, abstractCDSPropertiesBean);
+ }
+
+ @Override
+ public void run(ControllerContext<BuildingBlockExecution> controllerContext) {
+ BuildingBlockExecution buildingBlockExecution = controllerContext.getExecution();
+ abstractCDSProcessingBBUtils.constructExecutionServiceInputObject(buildingBlockExecution);
+ abstractCDSProcessingBBUtils.sendRequestToCDSClient(buildingBlockExecution);
+ }
+
+ private AbstractCDSPropertiesBean prepareAndSetCdsPropertyBean(BuildingBlockExecution buildingBlockExecution) {
+ final AbstractCDSPropertiesBean abstractCDSPropertiesBean = new AbstractCDSPropertiesBean();
+ final String action = getAction(buildingBlockExecution);
+
+ if (action == null) {
+ exceptionBuilder.buildAndThrowWorkflowException(buildingBlockExecution, 7000, "Action is null!",
+ ONAPComponents.SO);
+ }
+
+ abstractCDSPropertiesBean.setRequestObject(this.buildRequestPayload(action, buildingBlockExecution));
+ abstractCDSPropertiesBean.setBlueprintName(buildingBlockExecution.getVariable(PRC_BLUEPRINT_NAME));
+ abstractCDSPropertiesBean.setBlueprintVersion(buildingBlockExecution.getVariable(PRC_BLUEPRINT_VERSION));
+ abstractCDSPropertiesBean.setRequestId(buildingBlockExecution.getVariable(MSO_REQUEST_ID));
+ abstractCDSPropertiesBean.setOriginatorId(ORIGINATOR_ID);
+ abstractCDSPropertiesBean.setSubRequestId(UUID.randomUUID().toString());
+ abstractCDSPropertiesBean.setActionName(action);
+ abstractCDSPropertiesBean.setMode(DEFAULT_SYNC_MODE);
+ return abstractCDSPropertiesBean;
+ }
+
+ private String buildRequestPayload(String action, BuildingBlockExecution execution) {
+ final JsonObject pnfObject = new JsonObject();
+ String resolutionKey = null;
+ try {
+ final Pnf pnf = getPnf(execution);
+ final ServiceInstance serviceInstance = getServiceInstance(execution);
+ resolutionKey = pnf.getPnfName();
+
+ setExecutionVariable("service-instance-id", serviceInstance.getServiceInstanceId(), pnfObject);
+ setExecutionVariable("service-model-uuid", serviceInstance.getModelInfoServiceInstance().getModelUuid(),
+ pnfObject);
+ setExecutionVariable("pnf-id", pnf.getPnfId(), pnfObject);
+ setExecutionVariable("pnf-name", resolutionKey, pnfObject);
+ setExecutionVariable("pnf-customization-uuid", pnf.getModelInfoPnf().getModelCustomizationUuid(),
+ pnfObject);
+
+ } catch (BBObjectNotFoundException exception) {
+ logger.error("An exception occurred when creating payload for CDS request", exception);
+ exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, exception);
+ }
+ final JsonObject cdsPropertyObject = new JsonObject();
+ cdsPropertyObject.addProperty(RESOLUTION_KEY, resolutionKey);
+ cdsPropertyObject.add(action + SEPARATOR + PROPERTIES, pnfObject);
+
+ return buildRequestJsonObject(cdsPropertyObject, action);
+ }
+
+ private String buildRequestJsonObject(JsonObject cdsPropertyObject, String action) {
+ String requestBasedOnAction = action.concat(SEPARATOR).concat(REQUEST);
+ JsonObject requestObject = new JsonObject();
+ requestObject.add(requestBasedOnAction, cdsPropertyObject);
+ return requestObject.toString();
+ }
+
+ private void setExecutionVariable(String jsonProperty, String executionProperty, JsonObject pnfObject) {
+ if (executionProperty != null) {
+ pnfObject.addProperty(jsonProperty, executionProperty);
+ }
+ }
+
+ private String getAction(BuildingBlockExecution buildingBlockExecution) {
+ ExecuteBuildingBlock executeBuildingBlock = buildingBlockExecution.getVariable(BUILDING_BLOCK);
+ return executeBuildingBlock.getBuildingBlock().getBpmnAction();
+ }
+
+ private Pnf getPnf(BuildingBlockExecution buildingBlockExecution) throws BBObjectNotFoundException {
+ return extractPojosForBB.extractByKey(buildingBlockExecution, ResourceKey.PNF);
+ }
+
+ private ServiceInstance getServiceInstance(BuildingBlockExecution buildingBlockExecution)
+ throws BBObjectNotFoundException {
+ return extractPojosForBB.extractByKey(buildingBlockExecution, ResourceKey.SERVICE_INSTANCE_ID);
+ }
+}
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericPnfCDSProcessingDE.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericPnfCDSProcessingDE.java
index d5423b2ff7..aa74074cf6 100644
--- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericPnfCDSProcessingDE.java
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericPnfCDSProcessingDE.java
@@ -22,7 +22,6 @@ package org.onap.so.bpmn.infrastructure.flowspecific.tasks;
import org.camunda.bpm.engine.delegate.DelegateExecution;
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.PayloadConstants;
diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericPnfCDSControllerRunnableBBTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericPnfCDSControllerRunnableBBTest.java
new file mode 100644
index 0000000000..d6a28cba25
--- /dev/null
+++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericPnfCDSControllerRunnableBBTest.java
@@ -0,0 +1,156 @@
+/*
+ * ============LICENSE_START======================================================= Copyright (C) 2020 Nokia. All rights
+ * reserved. ================================================================================ 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.impl.pvm.runtime.ExecutionImpl;
+import org.json.JSONObject;
+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.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.servicedecomposition.bbobjects.Pnf;
+import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
+import org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock;
+import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock;
+import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
+import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoPnf;
+import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoServiceInstance;
+import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
+import org.onap.so.client.cds.beans.AbstractCDSPropertiesBean;
+import org.onap.so.client.exception.BBObjectNotFoundException;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.when;
+import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.EXECUTION_OBJECT;
+import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.MSO_REQUEST_ID;
+import static org.onap.so.client.cds.PayloadConstants.PRC_BLUEPRINT_NAME;
+import static org.onap.so.client.cds.PayloadConstants.PRC_BLUEPRINT_VERSION;
+import static org.onap.so.client.cds.PayloadConstants.SCOPE;
+
+@RunWith(MockitoJUnitRunner.class)
+public class GenericPnfCDSControllerRunnableBBTest {
+
+ @Mock
+ private ExtractPojosForBB extractPojosForBB;
+
+ @InjectMocks
+ private GenericPnfCDSControllerRunnableBB genericPnfCDSControllerRunnableBB;
+
+ private ControllerContext<BuildingBlockExecution> controllerContext;
+ private BuildingBlockExecution execution;
+
+ private final static String blueprintName = "blueprint_name";
+ private final static String blueprintVersion = "blueprint_version";
+ private final static String msoRequestId = "mso_request_id";
+ private final static String pnfID = "5df8b6de-2083-11e7-93ae-92361f002671";
+ private final static String serviceInstanceID = "test_service_id";
+ private final static String pnfName = "PNFDemo";
+ private final static String serviceModelUUID = "6bc0b04d-1873-4721-b53d-6615225b2a28";
+ private final static String pnfCustomizationUUID = "9acb3a83-8a52-412c-9a45-901764938144";
+ private final static String action = "action";
+
+ @Before
+ public void setUp() {
+ ExecuteBuildingBlock executeBuildingBlock = new ExecuteBuildingBlock();
+ BuildingBlock buildingBlock = new BuildingBlock();
+
+ buildingBlock.setBpmnAction(action);
+ executeBuildingBlock.setBuildingBlock(buildingBlock);
+
+ execution = new DelegateExecutionImpl(new ExecutionImpl());
+ execution.setVariable("buildingBlock", executeBuildingBlock);
+ execution.setVariable(PRC_BLUEPRINT_NAME, blueprintName);
+ execution.setVariable(PRC_BLUEPRINT_VERSION, blueprintVersion);
+ execution.setVariable(MSO_REQUEST_ID, msoRequestId);
+ execution.setVariable(SCOPE, "scope");
+
+ controllerContext = new ControllerContext<>();
+ controllerContext.setExecution(execution);
+ }
+
+ @Test
+ public void understandTest() {
+ // given
+ controllerContext.setControllerScope("pnf");
+ controllerContext.setControllerActor("cds");
+
+ // when, then
+ assertTrue(genericPnfCDSControllerRunnableBB.understand(controllerContext));
+ }
+
+ @Test
+ public void readyTest() {
+ // when, then
+ assertTrue(genericPnfCDSControllerRunnableBB.ready(controllerContext));
+ }
+
+ @Test
+ public void prepareTest() throws BBObjectNotFoundException {
+ // given
+ prepareData();
+
+ // when
+ genericPnfCDSControllerRunnableBB.prepare(controllerContext);
+
+ // then
+ final AbstractCDSPropertiesBean abstractCDSPropertiesBean = execution.getVariable(EXECUTION_OBJECT);
+ final JSONObject actionProperties = new JSONObject(abstractCDSPropertiesBean.getRequestObject())
+ .getJSONObject("action-request").getJSONObject("action-properties");
+
+ assertThat(abstractCDSPropertiesBean).isNotNull();
+ assertThat(abstractCDSPropertiesBean.getRequestObject()).isNotNull();
+ assertThat(abstractCDSPropertiesBean.getRequestObject()).isInstanceOf(String.class);
+
+ assertEquals(blueprintName, abstractCDSPropertiesBean.getBlueprintName());
+ assertEquals(blueprintVersion, abstractCDSPropertiesBean.getBlueprintVersion());
+ assertEquals(msoRequestId, abstractCDSPropertiesBean.getRequestId());
+ assertEquals(action, abstractCDSPropertiesBean.getActionName());
+ assertEquals("sync", abstractCDSPropertiesBean.getMode());
+ assertEquals("SO", abstractCDSPropertiesBean.getOriginatorId());
+
+ assertEquals(pnfID, actionProperties.get("pnf-id"));
+ assertEquals(serviceInstanceID, actionProperties.get("service-instance-id"));
+ assertEquals(serviceModelUUID, actionProperties.get("service-model-uuid"));
+ assertEquals(pnfName, actionProperties.get("pnf-name"));
+ assertEquals(pnfCustomizationUUID, actionProperties.get("pnf-customization-uuid"));
+ }
+
+ private void prepareData() throws BBObjectNotFoundException {
+ Pnf pnf = new Pnf();
+ ServiceInstance serviceInstance = new ServiceInstance();
+
+ pnf.setPnfName(pnfName);
+ pnf.setPnfId(pnfID);
+ ModelInfoPnf modelInfoPnf = new ModelInfoPnf();
+ modelInfoPnf.setModelCustomizationUuid(pnfCustomizationUUID);
+ pnf.setModelInfoPnf(modelInfoPnf);
+
+ serviceInstance.setServiceInstanceId(serviceInstanceID);
+ ModelInfoServiceInstance modelInfoServiceInstance = new ModelInfoServiceInstance();
+ modelInfoServiceInstance.setModelUuid(serviceModelUUID);
+ serviceInstance.setModelInfoServiceInstance(modelInfoServiceInstance);
+
+ when(extractPojosForBB.extractByKey(eq(execution), eq(ResourceKey.PNF))).thenReturn(pnf);
+ when(extractPojosForBB.extractByKey(eq(execution), eq(ResourceKey.SERVICE_INSTANCE_ID)))
+ .thenReturn(serviceInstance);
+ }
+}
diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericPnfCDSProcessingDETest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericPnfCDSProcessingDETest.java
index 583e139edd..ae5f4370e6 100644
--- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericPnfCDSProcessingDETest.java
+++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericPnfCDSProcessingDETest.java
@@ -20,7 +20,6 @@ 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.ClassRule;
import org.junit.Rule;
import org.junit.Test;
@@ -33,9 +32,6 @@ import org.onap.so.bpmn.infrastructure.decisionpoint.api.ControllerContext;
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.skyscreamer.jsonassert.JSONAssert;
-import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.rules.SpringClassRule;
import org.springframework.test.context.junit4.rules.SpringMethodRule;
import java.util.Arrays;