From 8c9f2c73f4366ae42ad7e2c1742885b5ad793360 Mon Sep 17 00:00:00 2001 From: eeginux Date: Wed, 20 Nov 2019 13:23:49 +0000 Subject: decision point API ControllerRunnable interface: implemented by controller ControllerContext: Controller Context for controller execution ControllerPreparable interface:used to setup execution context ControllerExecutionBB:controller execution for building block ControllerExecutionDE:controller execution for camunda Skeleton implementation for APPC controller Skeleton implementation for SDNC controller Use ControllerExecutionDE for existing PNF configuration. Add integration tests for controllerExecutionBB/DE Add GenericControllerExecution activity for BuildingBlockExecution based Add GenericControllerExecutionDE activity for DelegateExecution based. CDS controller to be implemented by SO-CDS generic buildingBlock Actor seletion based on ingested metadata Issue-ID: SO-2070 Change-Id: I4020c2ce21468939690e2cef78bbadbfff4bd3e4 Signed-off-by: eeginux --- .../client/cds/AbstractCDSProcessingBBUtils.java | 2 +- .../ActivitySpec/GenericControllerExecution.json | 15 ++ .../ActivitySpec/GenericControllerExecutionDE.json | 15 ++ .../Activity/GenericControllerExecution.bpmn | 44 +++++ .../Activity/GenericControllerExecutionDE.bpmn | 44 +++++ .../test/java/org/onap/so/bpmn/BaseBPMNTest.java | 8 + .../GenericControllerExecutionDETest.java | 54 ++++++ .../subprocess/GenericControllerExecutionTest.java | 54 ++++++ .../decisionpoint/api/ControllerContext.java | 95 ++++++++++ .../decisionpoint/api/ControllerRunnable.java | 56 ++++++ .../api/controller/ControllerPreparable.java | 48 +++++ .../pnf/delegate/ConfigCheckerDelegate.java | 27 +-- .../pnf/delegate/ExecutionVariableNames.java | 3 + .../resources/process/ConfigurePnfResource.bpmn | 104 +++++------ .../CreateVcpeResCustServiceSimplifiedTest.java | 1 - ...VcpeResCustServiceSimplifiedTest_catalogdb.json | 3 +- bpmn/so-bpmn-tasks/pom.xml | 7 + .../impl/AbstractControllerExecution.java | 174 ++++++++++++++++++ .../impl/buildingblock/ControllerExecutionBB.java | 152 ++++++++++++++++ .../buildingblock/controller/LcmControllerBB.java | 68 ++++++++ .../controller/appc/AppcControllerBB.java | 66 +++++++ .../controller/sdnc/SdncControllerBB.java | 73 ++++++++ .../controller/sdnc/prepare/PrepareSdncBB.java | 47 +++++ .../prepare/PrepareSdncUpgradePreCheckPnfBB.java | 60 +++++++ .../impl/camunda/ControllerExecutionDE.java | 148 ++++++++++++++++ .../impl/camunda/controller/LcmControllerDE.java | 69 ++++++++ .../camunda/controller/appc/AppcControllerDE.java | 62 +++++++ .../camunda/controller/cds/CdsControllerDE.java | 61 +++++++ .../cds/prepare/PreparePnfConfigAssignDE.java | 50 ++++++ .../cds/prepare/PreparePnfConfigDeployDE.java | 50 ++++++ .../camunda/controller/sdnc/SdncControllerDE.java | 62 +++++++ .../src/test/java/org/onap/so/GrpcNettyServer.java | 113 ++++++++++++ .../buildingblock/ControllerExecutionBBTest.java | 160 +++++++++++++++++ .../buildingblock/ControllerExecutionBBTestIT.java | 194 +++++++++++++++++++++ .../impl/buildingblock/MockControllerBB.java | 54 ++++++ .../controller/appc/AppcControllerBBTest.java | 65 +++++++ .../controller/sdnc/SdncControllerBBTest.java | 64 +++++++ .../impl/camunda/ControllerExecutionDETest.java | 160 +++++++++++++++++ .../impl/camunda/ControllerExecutionDETestIT.java | 144 +++++++++++++++ .../impl/camunda/MockControllerDE.java | 55 ++++++ .../controller/appc/AppcControllerDETest.java | 69 ++++++++ .../controller/cds/CdsControllerDETest.java | 66 +++++++ .../controller/sdnc/SdncControllerDETest.java | 69 ++++++++ .../src/test/resources/application-test.yaml | 6 + 44 files changed, 2865 insertions(+), 76 deletions(-) create mode 100644 bpmn/so-bpmn-building-blocks/src/main/resources/ActivitySpec/GenericControllerExecution.json create mode 100644 bpmn/so-bpmn-building-blocks/src/main/resources/ActivitySpec/GenericControllerExecutionDE.json create mode 100644 bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/Activity/GenericControllerExecution.bpmn create mode 100644 bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/Activity/GenericControllerExecutionDE.bpmn create mode 100644 bpmn/so-bpmn-building-blocks/src/test/java/org/onap/so/bpmn/infrastructure/bpmn/subprocess/GenericControllerExecutionDETest.java create mode 100644 bpmn/so-bpmn-building-blocks/src/test/java/org/onap/so/bpmn/infrastructure/bpmn/subprocess/GenericControllerExecutionTest.java create mode 100644 bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/api/ControllerContext.java create mode 100644 bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/api/ControllerRunnable.java create mode 100644 bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/api/controller/ControllerPreparable.java create mode 100644 bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/AbstractControllerExecution.java create mode 100644 bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/buildingblock/ControllerExecutionBB.java create mode 100644 bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/buildingblock/controller/LcmControllerBB.java create mode 100644 bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/buildingblock/controller/appc/AppcControllerBB.java create mode 100644 bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/buildingblock/controller/sdnc/SdncControllerBB.java create mode 100644 bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/buildingblock/controller/sdnc/prepare/PrepareSdncBB.java create mode 100644 bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/buildingblock/controller/sdnc/prepare/PrepareSdncUpgradePreCheckPnfBB.java create mode 100644 bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/ControllerExecutionDE.java create mode 100644 bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/controller/LcmControllerDE.java create mode 100644 bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/controller/appc/AppcControllerDE.java create mode 100644 bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/controller/cds/CdsControllerDE.java create mode 100644 bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/controller/cds/prepare/PreparePnfConfigAssignDE.java create mode 100644 bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/controller/cds/prepare/PreparePnfConfigDeployDE.java create mode 100644 bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/controller/sdnc/SdncControllerDE.java create mode 100644 bpmn/so-bpmn-tasks/src/test/java/org/onap/so/GrpcNettyServer.java create mode 100644 bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/buildingblock/ControllerExecutionBBTest.java create mode 100644 bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/buildingblock/ControllerExecutionBBTestIT.java create mode 100644 bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/buildingblock/MockControllerBB.java create mode 100644 bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/buildingblock/controller/appc/AppcControllerBBTest.java create mode 100644 bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/buildingblock/controller/sdnc/SdncControllerBBTest.java create mode 100644 bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/ControllerExecutionDETest.java create mode 100644 bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/ControllerExecutionDETestIT.java create mode 100644 bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/MockControllerDE.java create mode 100644 bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/controller/appc/AppcControllerDETest.java create mode 100644 bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/controller/cds/CdsControllerDETest.java create mode 100644 bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/controller/sdnc/SdncControllerDETest.java (limited to 'bpmn') 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 9741d4b6c2..424a4f3ecc 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 @@ -68,7 +68,7 @@ public class AbstractCDSProcessingBBUtils { private static final String EXCEPTION = "Exception"; @Autowired - private ExceptionBuilder exceptionUtil; + protected ExceptionBuilder exceptionUtil; /** * Extracting data from execution object and building the ExecutionServiceInput Object diff --git a/bpmn/so-bpmn-building-blocks/src/main/resources/ActivitySpec/GenericControllerExecution.json b/bpmn/so-bpmn-building-blocks/src/main/resources/ActivitySpec/GenericControllerExecution.json new file mode 100644 index 0000000000..d4a0e83546 --- /dev/null +++ b/bpmn/so-bpmn-building-blocks/src/main/resources/ActivitySpec/GenericControllerExecution.json @@ -0,0 +1,15 @@ +{ + "name": "GenericControllerExecution", + "description": "Generic controller execution with BuildingBlockExecution context against controller northbound interface", + "categoryList": [ + "VNF", + "PNF" + ], + "inputParameters": [], + "outputParameters": [ + { + "name": "WorkflowException", + "type": "WorkflowException" + } + ] +} diff --git a/bpmn/so-bpmn-building-blocks/src/main/resources/ActivitySpec/GenericControllerExecutionDE.json b/bpmn/so-bpmn-building-blocks/src/main/resources/ActivitySpec/GenericControllerExecutionDE.json new file mode 100644 index 0000000000..cd1fa865ee --- /dev/null +++ b/bpmn/so-bpmn-building-blocks/src/main/resources/ActivitySpec/GenericControllerExecutionDE.json @@ -0,0 +1,15 @@ +{ + "name": "GenericControllerExecutionDE", + "description": "Generic controller execution with DelegateExecution context against controller northbound interface", + "categoryList": [ + "VNF", + "PNF" + ], + "inputParameters": [], + "outputParameters": [ + { + "name": "WorkflowException", + "type": "WorkflowException" + } + ] +} diff --git a/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/Activity/GenericControllerExecution.bpmn b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/Activity/GenericControllerExecution.bpmn new file mode 100644 index 0000000000..bd606738e2 --- /dev/null +++ b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/Activity/GenericControllerExecution.bpmn @@ -0,0 +1,44 @@ + + + + + SequenceFlow_06ab7wm + + + + SequenceFlow_12srn62 + + + + SequenceFlow_06ab7wm + SequenceFlow_12srn62 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/Activity/GenericControllerExecutionDE.bpmn b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/Activity/GenericControllerExecutionDE.bpmn new file mode 100644 index 0000000000..b5dcec00cd --- /dev/null +++ b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/Activity/GenericControllerExecutionDE.bpmn @@ -0,0 +1,44 @@ + + + + + SequenceFlow_06ab7wm + + + + SequenceFlow_12srn62 + + + + SequenceFlow_06ab7wm + SequenceFlow_12srn62 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/bpmn/so-bpmn-building-blocks/src/test/java/org/onap/so/bpmn/BaseBPMNTest.java b/bpmn/so-bpmn-building-blocks/src/test/java/org/onap/so/bpmn/BaseBPMNTest.java index 5b7fe66f54..874e3415b2 100644 --- a/bpmn/so-bpmn-building-blocks/src/test/java/org/onap/so/bpmn/BaseBPMNTest.java +++ b/bpmn/so-bpmn-building-blocks/src/test/java/org/onap/so/bpmn/BaseBPMNTest.java @@ -55,6 +55,8 @@ import org.onap.so.bpmn.infrastructure.adapter.vnf.tasks.VnfAdapterImpl; import org.onap.so.bpmn.infrastructure.appc.tasks.AppcOrchestratorPreProcessor; import org.onap.so.bpmn.infrastructure.appc.tasks.AppcRunTasks; import org.onap.so.bpmn.infrastructure.audit.AuditTasks; +import org.onap.so.bpmn.infrastructure.decisionpoint.impl.buildingblock.ControllerExecutionBB; +import org.onap.so.bpmn.infrastructure.decisionpoint.impl.camunda.ControllerExecutionDE; import org.onap.so.bpmn.infrastructure.flowspecific.tasks.ActivateVfModule; import org.onap.so.bpmn.infrastructure.flowspecific.tasks.AssignNetwork; import org.onap.so.bpmn.infrastructure.flowspecific.tasks.AssignNetworkBBUtils; @@ -254,6 +256,12 @@ public abstract class BaseBPMNTest { @MockBean protected ManualHandlingTasks manualHandlingTasks; + @MockBean + protected ControllerExecutionBB controllerExecutionBB; + + @MockBean + protected ControllerExecutionDE controllerExecutionDE; + @LocalServerPort protected int port; diff --git a/bpmn/so-bpmn-building-blocks/src/test/java/org/onap/so/bpmn/infrastructure/bpmn/subprocess/GenericControllerExecutionDETest.java b/bpmn/so-bpmn-building-blocks/src/test/java/org/onap/so/bpmn/infrastructure/bpmn/subprocess/GenericControllerExecutionDETest.java new file mode 100644 index 0000000000..83cf98ec0c --- /dev/null +++ b/bpmn/so-bpmn-building-blocks/src/test/java/org/onap/so/bpmn/infrastructure/bpmn/subprocess/GenericControllerExecutionDETest.java @@ -0,0 +1,54 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 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.bpmn.infrastructure.bpmn.subprocess; + +import static org.camunda.bpm.engine.test.assertions.ProcessEngineTests.assertThat; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.doThrow; +import org.camunda.bpm.engine.delegate.BpmnError; +import org.camunda.bpm.engine.delegate.DelegateExecution; +import org.camunda.bpm.engine.runtime.ProcessInstance; +import org.junit.Test; +import org.onap.so.bpmn.BaseBPMNTest; + + +public class GenericControllerExecutionDETest extends BaseBPMNTest { + + @Test + public void testExecution_validInput_expectedExecution() { + + ProcessInstance pi = runtimeService.startProcessInstanceByKey("GenericControllerExecutionDE", variables); + assertThat(pi).isNotNull(); + assertThat(pi).isStarted().hasPassedInOrder("Start_ControllerExecutionDE", "Call_ControllerExecutionDE", + "End_ControllerExecutionDE"); + assertThat(pi).isEnded(); + } + + @Test + public void testExecution_failedExecution_exceptionThrown() { + doThrow(new BpmnError("7000", "TESTING ERRORS")).when(controllerExecutionDE) + .execute(any(DelegateExecution.class)); + ProcessInstance pi = runtimeService.startProcessInstanceByKey("GenericControllerExecutionDE", variables); + assertThat(pi).isNotNull(); + assertThat(pi).isStarted().hasPassedInOrder("Start_ControllerExecutionDE", "Call_ControllerExecutionDE") + .hasNotPassed("End_ControllerExecutionDE"); + assertThat(pi).isEnded(); + } +} diff --git a/bpmn/so-bpmn-building-blocks/src/test/java/org/onap/so/bpmn/infrastructure/bpmn/subprocess/GenericControllerExecutionTest.java b/bpmn/so-bpmn-building-blocks/src/test/java/org/onap/so/bpmn/infrastructure/bpmn/subprocess/GenericControllerExecutionTest.java new file mode 100644 index 0000000000..c2aa3af721 --- /dev/null +++ b/bpmn/so-bpmn-building-blocks/src/test/java/org/onap/so/bpmn/infrastructure/bpmn/subprocess/GenericControllerExecutionTest.java @@ -0,0 +1,54 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 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.bpmn.infrastructure.bpmn.subprocess; + +import static org.camunda.bpm.engine.test.assertions.ProcessEngineTests.assertThat; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.doThrow; +import org.camunda.bpm.engine.delegate.BpmnError; +import org.camunda.bpm.engine.runtime.ProcessInstance; +import org.junit.Test; +import org.onap.so.bpmn.BaseBPMNTest; +import org.onap.so.bpmn.common.BuildingBlockExecution; + + +public class GenericControllerExecutionTest extends BaseBPMNTest { + + @Test + public void testExecution_validInput_expectedExecution() { + + ProcessInstance pi = runtimeService.startProcessInstanceByKey("GenericControllerExecution", variables); + assertThat(pi).isNotNull(); + assertThat(pi).isStarted().hasPassedInOrder("Start_ControllerExecutionBB", "Call_ControllerExecutionBB", + "End_ControllerExecutionBB"); + assertThat(pi).isEnded(); + } + + @Test + public void testExecution_failedExecution_exceptionThrown() { + doThrow(new BpmnError("7000", "TESTING ERRORS")).when(controllerExecutionBB) + .execute(any(BuildingBlockExecution.class)); + ProcessInstance pi = runtimeService.startProcessInstanceByKey("GenericControllerExecution", variables); + assertThat(pi).isNotNull(); + assertThat(pi).isStarted().hasPassedInOrder("Start_ControllerExecutionBB", "Call_ControllerExecutionBB") + .hasNotPassed("End_ControllerExecutionBB"); + assertThat(pi).isEnded(); + } +} diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/api/ControllerContext.java b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/api/ControllerContext.java new file mode 100644 index 0000000000..0de211bd7d --- /dev/null +++ b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/api/ControllerContext.java @@ -0,0 +1,95 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 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.bpmn.infrastructure.decisionpoint.api; + +import java.util.Map; +import org.camunda.bpm.engine.delegate.DelegateExecution; + +/** + * This class is used to represent the Context used by {@ref ControllerRunnable}. + */ +public class ControllerContext { + + /** + * Action to be executed against controller. + * + * e.g, healthcheck, scaleout, config-assign + * + * Action is case insensitive. + */ + private String controllerAction; + + /** + * Controller actor. + * + * e.g., CDS, SDNC, APPC. + * + * actor name is case insensitive. + */ + private String controllerActor; + + /** + * scope: PNF, VNF, VF. + */ + private String controllerScope; + + /** + * Execution context, buildingblockExecution or DelegateExecution. + */ + private T execution; + + public ControllerContext() {} + + public void setExecution(T execution) { + this.execution = execution; + } + + public T getExecution() { + return execution; + } + + public String getControllerAction() { + return controllerAction; + } + + public void setControllerAction(String controllerAction) { + this.controllerAction = controllerAction; + } + + public String getControllerActor() { + return controllerActor; + } + + public void setControllerActor(String controllerActor) { + this.controllerActor = controllerActor; + } + + public String getControllerScope() { + return controllerScope; + } + + public void setControllerScope(String controllerScope) { + this.controllerScope = controllerScope; + } + + public String toString() { + return "Controller context for actor: " + controllerActor + ", action: " + controllerAction + ",scope: " + + controllerScope; + } +} diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/api/ControllerRunnable.java b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/api/ControllerRunnable.java new file mode 100644 index 0000000000..670f4d399e --- /dev/null +++ b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/api/ControllerRunnable.java @@ -0,0 +1,56 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 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.bpmn.infrastructure.decisionpoint.api; + +/** + * the ControllerRunnable interface should be implemented by any class intended to execute against controller northbound + * interface. + * + */ +public interface ControllerRunnable { + + /** + * This method is used to decide whether the implementation is to serve the controller northbound interface. + * + * @param context {@link ControllerContext} is used as the input to the execution. + * @return + */ + Boolean understand(final ControllerContext context); + + /** + * this method is used to check whether the controller Northbound interface is ready to use. + * + * @param context {@link ControllerContext} is used as the input to the execution. + * @return True if the controller is ready to use or return false. + */ + Boolean ready(final ControllerContext context); + + /** + * This method is used to set up the context so it can be used to run against the controller NB. + */ + void prepare(final ControllerContext context); + + /** + * This method is used to run against the controller northbound interface. + * + * @param context {@link ControllerContext} is used as the input to the execution. + */ + void run(final ControllerContext context); + +} diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/api/controller/ControllerPreparable.java b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/api/controller/ControllerPreparable.java new file mode 100644 index 0000000000..98bab2c1ed --- /dev/null +++ b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/api/controller/ControllerPreparable.java @@ -0,0 +1,48 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 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.bpmn.infrastructure.decisionpoint.api.controller; + +import org.onap.so.bpmn.infrastructure.decisionpoint.api.ControllerContext; +import org.onap.so.bpmn.infrastructure.decisionpoint.api.ControllerRunnable; + +/** + * This interface is used by {@link ControllerRunnable} to prepare the Context. + * + * The interface should be implementation by controller preparation instance to configure the context required for + * execution. + */ +public interface ControllerPreparable { + + /** + * This method is used to decide whether the implementation is used to configure the {@link ControllerContext}. + * + * @param controllerContext + * @return + */ + boolean understand(final ControllerContext controllerContext); + + /** + * This method is used to prepare the {@link ControllerContext}. + * + * @param controllerContext + */ + void prepare(final ControllerContext controllerContext); + +} diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/ConfigCheckerDelegate.java b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/ConfigCheckerDelegate.java index ee86ca4292..37b9376e14 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/ConfigCheckerDelegate.java +++ b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/ConfigCheckerDelegate.java @@ -1,15 +1,20 @@ -/* - * ============LICENSE_START======================================================= Copyright (C) 2019 Nordix - * Foundation. ================================================================================ 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 +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 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. + * 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========================================================= + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= */ package org.onap.so.bpmn.infrastructure.pnf.delegate; @@ -17,6 +22,7 @@ package org.onap.so.bpmn.infrastructure.pnf.delegate; import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.MODEL_UUID; import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PRC_BLUEPRINT_NAME; import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PRC_BLUEPRINT_VERSION; +import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PRC_CONTROLLER_ACTOR; import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PRC_CUSTOMIZATION_UUID; import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PRC_INSTANCE_NAME; import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.SERVICE_MODEL_INFO; @@ -75,6 +81,7 @@ public class ConfigCheckerDelegate implements JavaDelegate { delegateExecution.setVariable(PRC_CUSTOMIZATION_UUID, pnfResourceCustomization.getModelCustomizationUUID()); delegateExecution.setVariable(PRC_INSTANCE_NAME, pnfResourceCustomization.getModelInstanceName()); + delegateExecution.setVariable(PRC_CONTROLLER_ACTOR, pnfResourceCustomization.getControllerActor()); } else { logger.warn("Unable to find the PNF resource customizations of model service UUID: {}", serviceModelUuid); diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/ExecutionVariableNames.java b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/ExecutionVariableNames.java index c16175b8e2..fab3496559 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/ExecutionVariableNames.java +++ b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/ExecutionVariableNames.java @@ -5,6 +5,7 @@ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Modifications Copyright 2018 Nokia + * Modifications Copyright 2019 Nordix * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -51,6 +52,8 @@ public class ExecutionVariableNames { public static final String PRC_BLUEPRINT_VERSION = "PRC_blueprintVersion"; public static final String PRC_CUSTOMIZATION_UUID = "PRC_customizationUuid"; public static final String PRC_INSTANCE_NAME = "PRC_instanceName"; + public static final String PRC_CONTROLLER_ACTOR = "actor"; + /** * Variable used to contain skipPostInstantiationConfiguration flag. diff --git a/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/ConfigurePnfResource.bpmn b/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/ConfigurePnfResource.bpmn index 9a1a7ed628..6d5b2a2f28 100644 --- a/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/ConfigurePnfResource.bpmn +++ b/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/ConfigurePnfResource.bpmn @@ -16,45 +16,19 @@ #{SkipPostInstantiationConfiguration} - - SequenceFlow_0j3pm2g - SequenceFlow_17llfxw - - - - - - - - - SequenceFlow_17llfxw - SequenceFlow_0p0aqtx - - SequenceFlow_0p0aqtx + SequenceFlow_07bmtu7 SequenceFlow_1owbpsy SequenceFlow_1w4p9f7 - - + #{execution.getVariable("CDSStatus").equals("Success")} - - - - - - - - SequenceFlow_0jfgn7n - SequenceFlow_08voj55 - - SequenceFlow_08voj55 + SequenceFlow_02919fh SequenceFlow_1n080up SequenceFlow_0d24h26 - #{execution.getVariable("CDSStatus").equals("Success")} @@ -74,12 +48,30 @@ - + #{!SkipPostInstantiationConfiguration} - + + + + + config-assign + pnf + + + SequenceFlow_0j3pm2g + SequenceFlow_07bmtu7 + + + + + + config-deploy + pnf + + SequenceFlow_1owbpsy - SequenceFlow_0jfgn7n + SequenceFlow_02919fh @@ -105,44 +97,19 @@ - - - - - - - - - - - - - - - + - + - - - - - - - - - - - @@ -185,13 +152,24 @@ - + - + - - + + + + + + + + + + + + + diff --git a/bpmn/so-bpmn-infrastructure-flows/src/test/java/org/onap/so/bpmn/infrastructure/process/CreateVcpeResCustServiceSimplifiedTest.java b/bpmn/so-bpmn-infrastructure-flows/src/test/java/org/onap/so/bpmn/infrastructure/process/CreateVcpeResCustServiceSimplifiedTest.java index 1cd8295fa2..aea06b5fc9 100644 --- a/bpmn/so-bpmn-infrastructure-flows/src/test/java/org/onap/so/bpmn/infrastructure/process/CreateVcpeResCustServiceSimplifiedTest.java +++ b/bpmn/so-bpmn-infrastructure-flows/src/test/java/org/onap/so/bpmn/infrastructure/process/CreateVcpeResCustServiceSimplifiedTest.java @@ -105,7 +105,6 @@ public class CreateVcpeResCustServiceSimplifiedTest extends BaseBPMNTest { } - @Ignore @Test public void workflow_validInput_expectedOuput() throws InterruptedException { diff --git a/bpmn/so-bpmn-infrastructure-flows/src/test/resources/response/CreateVcpeResCustServiceSimplifiedTest_catalogdb.json b/bpmn/so-bpmn-infrastructure-flows/src/test/resources/response/CreateVcpeResCustServiceSimplifiedTest_catalogdb.json index 66d1a88ee8..422fb41de7 100644 --- a/bpmn/so-bpmn-infrastructure-flows/src/test/resources/response/CreateVcpeResCustServiceSimplifiedTest_catalogdb.json +++ b/bpmn/so-bpmn-infrastructure-flows/src/test/resources/response/CreateVcpeResCustServiceSimplifiedTest_catalogdb.json @@ -15,6 +15,7 @@ "blueprintVersion": "1.0.0", "skipPostInstConf": false, "creationTimestamp": "2019-03-08T12:00:29.000+0000", + "controllerActor": "cds", "_links": { "self": { "href": "http://localhost:41023/pnfResourceCustomization/68dc9a92-214c-11e7-93ae-92361f002680" @@ -34,4 +35,4 @@ "href": "http://localhost:41023/pnfResourceCustomization/search/findPnfResourceCustomizationByModelUuid?SERVICE_MODEL_UUID=5df8b6de-2083-11e7-93ae-92361f002676" } } -} \ No newline at end of file +} diff --git a/bpmn/so-bpmn-tasks/pom.xml b/bpmn/so-bpmn-tasks/pom.xml index bf129dfc56..d37120b452 100644 --- a/bpmn/so-bpmn-tasks/pom.xml +++ b/bpmn/so-bpmn-tasks/pom.xml @@ -13,6 +13,7 @@ UTF-8 1.8 1.8 + 1.17.1 @@ -165,5 +166,11 @@ 2.5.1 test + + io.grpc + grpc-testing + ${grpc.version} + test + diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/AbstractControllerExecution.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/AbstractControllerExecution.java new file mode 100644 index 0000000000..f3b767a8f1 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/AbstractControllerExecution.java @@ -0,0 +1,174 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 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.bpmn.infrastructure.decisionpoint.impl; + +import com.google.common.base.Strings; +import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; +import org.onap.so.bpmn.infrastructure.decisionpoint.api.ControllerContext; +import org.onap.so.bpmn.infrastructure.decisionpoint.api.ControllerRunnable; +import org.onap.so.client.exception.ExceptionBuilder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; + +/** + * Abstract class of the controller execution, it should be extended for the controller execution task. + * + * @param execution context type, e.g., BuildingBlockExecution or DelegateExecution + */ +public abstract class AbstractControllerExecution { + + /** + * parameters from the execution context. + */ + protected static final String CONTROLLER_ACTOR_PARAM = "actor"; + protected static final String CONTROLLER_ACTION_PARAM = "action"; + protected static final String CONTROLLER_SCOPE_PARAM = "scope"; + protected static final String RESOURCE_CUSTOMIZATION_UUID_PARAM = "resource_customization_uuid"; + protected static final String RESOURCE_TYPE_PARAM = "resource_type"; + + protected final Logger logger = LoggerFactory.getLogger(this.getClass()); + + @Autowired + protected List> availableControllerRunnables; + + @Autowired + protected ExceptionBuilder exceptionBuilder; + + /** + * Find the {@ref ControllerRunnable} instances understanding the {@ref ControllerContext}. + * + * Only one instance should be able to understand the context. if more than one or none instances found, return + * null. + * + * @param context controller context + * @return Optional of ControllerRunnable instance + */ + protected Optional getController(ControllerContext context) { + List> satisfiedControllers = availableControllerRunnables.stream() + .filter(controllerRunnable -> controllerRunnable.understand(context)).collect(Collectors.toList()); + + if (logger.isDebugEnabled()) { + for (ControllerRunnable satisfiedController : satisfiedControllers) { + logger.debug("{} controllerRunnable understands the context", satisfiedController.getClass().getName()); + } + } + + /** + * Make sure only one {@ref ControllerRunnable} instance understands the context or else return Null. + */ + if (satisfiedControllers.size() == 1) { + return Optional.of(satisfiedControllers.get(0)); + } else if (satisfiedControllers.isEmpty()) { + logger.warn("Can NOT find any ControllerRunnable for context: {}", context); + } else if (satisfiedControllers.size() > 1) { + logger.warn( + "Found {} instances understanding the context: {}, please make sure only 1 instance understands it", + satisfiedControllers.size(), context); + } + + return Optional.empty(); + } + + /** + * Build the {@ref ControllerContext} context based on execution context. + * + * @param t execution context instance, e.g., BuildingBlockExecution or DelegateExecution instance + * @return controller context instance of the execution context type + */ + protected ControllerContext buildControllerContext(final T t) { + String controllerAction = getParameterFromExecution(t, CONTROLLER_ACTION_PARAM); + String controllerScope = getParameterFromExecution(t, CONTROLLER_SCOPE_PARAM); + String resourceCustomizationUuid = getParameterFromExecution(t, RESOURCE_CUSTOMIZATION_UUID_PARAM); + String controllerActor = getControllerActor(t, controllerScope, resourceCustomizationUuid, controllerAction); + ControllerContext controllerContext = new ControllerContext<>(); + controllerContext.setExecution(t); + controllerContext.setControllerAction(controllerAction); + controllerContext.setControllerActor(controllerActor); + controllerContext.setControllerScope(controllerScope); + return controllerContext; + } + + /** + * Retrieve the controller actor. + * + * @param t execution context instance, e.g., BuildingBlockExecution or DelegateExecution instance + * @param controllerScope controller scope, e.g, pnf, vnf, vfModule + * @param resourceCustomizationUuid resource customization UUID, e.g, pnfCustomizationUuid, vnfCustomizationUuid + * @param controllerAction controller action, e.g, configAssign, configDeploy + * @return controller actor + */ + protected abstract String getControllerActor(T t, String controllerScope, String resourceCustomizationUuid, + String controllerAction); + + /** + * Controller execution based on the Controller Context. + * + * @param controllerContext ControllerContext object + */ + public abstract void controllerExecute(final ControllerContext controllerContext); + + /** + * Retrieve the parameter value as String from the execution context. + * + * @param t execution context instance, e.g., BuildingBlockExecution or DelegateExecution instance + * @param parameterName parameter name to be retrieved + * @return String value of the parameter + */ + protected abstract String getParameterFromExecution(final T t, String parameterName); + + /** + * Check whether the controller actor value is SO ref value, i.e, equals to SO-REF-DATA. + * + * @param controllerActor controller actor, e.g, SO-REF-DATA, SDNC, CDS + * @return true if the controller actor is SO-REF-DATA, else return false + */ + protected boolean isSoRefControllerActor(final String controllerActor) { + return !Strings.isNullOrEmpty(controllerActor) && controllerActor.equalsIgnoreCase("SO-REF-DATA"); + } + + /** + * Check whether the controller scope is PNF resource related. + * + * @param controllerScope controller scope, e.g, pnf, vnf, vfModule + * @return true if the controller scope is pnf, else return false + */ + protected boolean isPnfResourceScope(final String controllerScope) { + return ("pnf").equalsIgnoreCase(controllerScope); + } + + /** + * Check whether the controller scope is VNF resource related. + * + * @param controllerScope controller scope, e.g, pnf, vnf, vfModule + * @return true if the controller scope is vnf or vfModule, else return false + */ + protected boolean isVnfResourceScope(final String controllerScope) { + if (Strings.isNullOrEmpty(controllerScope)) { + return false; + } + if (controllerScope.toLowerCase().startsWith("vnf") || controllerScope.equalsIgnoreCase("vfmodule")) { + return true; + } + return false; + } +} diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/buildingblock/ControllerExecutionBB.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/buildingblock/ControllerExecutionBB.java new file mode 100644 index 0000000000..39a695b0b6 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/buildingblock/ControllerExecutionBB.java @@ -0,0 +1,152 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 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.bpmn.infrastructure.decisionpoint.impl.buildingblock; + +import com.google.common.base.Strings; +import java.util.Optional; +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.infrastructure.decisionpoint.impl.AbstractControllerExecution; +import org.onap.so.db.catalog.beans.ControllerSelectionReference; +import org.onap.so.db.catalog.beans.PnfResourceCustomization; +import org.onap.so.db.catalog.beans.VnfResourceCustomization; +import org.onap.so.db.catalog.client.CatalogDbClient; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +/** + * This class is used for {@ref BuildingBlockExecution} API based execution. + * + * it decides which controller implementation to use based on the parameters, like actor, scope, action. + * + * The following parameters are expected in the {@ref BuildingBlockExecution} context, + *
    + *
  • action: action to be executed
  • + *
  • scope: type of the resource, i.e, pnf, vnf, vf
  • + *
  • resource_customization_uuid: resource customization UUID
  • + *
  • resource_type: resource type, optional. It's used to find the controller from controller_selection_reference + * table. Same as VNF_TYPE in the table
  • + *
+ */ +@Component +public class ControllerExecutionBB extends AbstractControllerExecution { + + @Autowired + protected CatalogDbClient catalogDbClient; + + public void execute(final BuildingBlockExecution execution) { + ControllerContext controllerContext = buildControllerContext(execution); + controllerExecute(controllerContext); + } + + @Override + protected String getParameterFromExecution(BuildingBlockExecution execution, String parameterName) { + Object object = execution.getVariable(parameterName); + if (object != null) { + String paramValue = String.valueOf(object); + logger.debug("parameterName: {}, parameterValue: {}", parameterName, paramValue); + return paramValue; + } + return ""; + } + + /** + * this method is used to get the controller actor, there could be few places to get the actor(ordered by priority), + * + *
    + *
  1. Execution Context, i.e, BuildingBlockExecution
  2. + *
  3. Resource customization table, pnf_resource_customization for PNF or vnf_resource_customization for VNF
  4. + *
  5. controller_selection_reference, resource_type and action will be used to fetch from this table
  6. + *
+ * + * @param execution BuildingBlockExecution instance + * @param controllerScope controller scope, e.g, pnf, vnf, vfModule + * @param resourceCustomizationUuid resource customization UUID, e.g, pnfCustomizationUuid, vnfCustomizationUuid + * @param controllerAction controller action, e.g, configAssign, configDeploy + * @return controller actor name + */ + @Override + protected String getControllerActor(BuildingBlockExecution execution, String controllerScope, + String resourceCustomizationUuid, String controllerAction) { + + /** + * Firstly, check the execution context for actor parameter. + */ + String controllerActor = getParameterFromExecution(execution, CONTROLLER_ACTOR_PARAM); + + /** + * If no meaningful controller actor value found in the execution context and the value is not SO-REF-DATA. + */ + if (Strings.isNullOrEmpty(controllerActor) && !isSoRefControllerActor(controllerActor)) { + + /** + * For BuildingBlockExecution, we should try to get the resource information from Cached metadata. + * + * As the current cached metadata doesn't support controller actor, we use the + * {@link org.onap.so.db.catalog.client.CatalogDbClient} to fetch information. Once the change is done in + * cached metadata, this part should be refactored as well. + */ + if (isPnfResourceScope(controllerScope)) { + PnfResourceCustomization pnfResourceCustomization = + catalogDbClient.getPnfResourceCustomizationByModelCustomizationUUID(resourceCustomizationUuid); + controllerActor = pnfResourceCustomization.getControllerActor(); + } else if (isVnfResourceScope(controllerScope)) { + VnfResourceCustomization vnfResourceCustomization = + catalogDbClient.getVnfResourceCustomizationByModelCustomizationUUID(resourceCustomizationUuid); + controllerActor = vnfResourceCustomization.getControllerActor(); + } else { + logger.warn("Unrecognized scope: {}", controllerScope); + } + } + + /** + * Lastly, can NOT find the controller actor information from resource customization table or the return value + * is SO-REF-DATA. + */ + if (Strings.isNullOrEmpty(controllerActor) || isSoRefControllerActor(controllerActor)) { + String resourceType = getParameterFromExecution(execution, RESOURCE_TYPE_PARAM); + ControllerSelectionReference reference = catalogDbClient + .getControllerSelectionReferenceByVnfTypeAndActionCategory(resourceType, controllerAction); + + controllerActor = reference.getControllerName(); + } + return controllerActor; + } + + @Override + public void controllerExecute(ControllerContext controllerContext) { + Optional optional = getController(controllerContext); + if (optional.isPresent()) { + ControllerRunnable controller = optional.get(); + if (controller.ready(controllerContext)) { + controller.prepare(controllerContext); + controller.run(controllerContext); + } else { + exceptionBuilder.buildAndThrowWorkflowException(controllerContext.getExecution(), 9001, + "Controller is NOT Ready for the action", ONAPComponents.SO); + } + } else { + exceptionBuilder.buildAndThrowWorkflowException(controllerContext.getExecution(), 9000, + "Unable to find the controller implementation", ONAPComponents.SO); + } + } +} diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/buildingblock/controller/LcmControllerBB.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/buildingblock/controller/LcmControllerBB.java new file mode 100644 index 0000000000..d7f6808b75 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/buildingblock/controller/LcmControllerBB.java @@ -0,0 +1,68 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 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.bpmn.infrastructure.decisionpoint.impl.buildingblock.controller; + +import java.util.List; +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.infrastructure.decisionpoint.api.controller.ControllerPreparable; +import org.onap.so.client.appc.ApplicationControllerAction; +import org.onap.so.client.exception.ExceptionBuilder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; + +/** + * This class should be extended by LCM api based controllers. + */ +public abstract class LcmControllerBB implements ControllerRunnable { + + protected Logger logger = LoggerFactory.getLogger(this.getClass()); + + @Autowired + protected ExceptionBuilder exceptionUtil; + + @Autowired(required = false) + protected List> prepareList; + + @Autowired + protected ApplicationControllerAction client; + + @Override + public void prepare(ControllerContext context) { + prepareList.stream().filter(prepare -> prepare.understand(context)) + .forEach(prepare -> prepare.prepare(context)); + } + + @Override + public void run(ControllerContext context) { + callLcmClient(context); + } + + /** + * This method is used to execute the LCM action by calling LCM client, appc Client or SDNC client. + * + * @return error code + */ + protected abstract int callLcmClient(ControllerContext context); + + protected abstract int getErrorCode(); +} diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/buildingblock/controller/appc/AppcControllerBB.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/buildingblock/controller/appc/AppcControllerBB.java new file mode 100644 index 0000000000..8650994da6 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/buildingblock/controller/appc/AppcControllerBB.java @@ -0,0 +1,66 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 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.bpmn.infrastructure.decisionpoint.impl.buildingblock.controller.appc; + +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.infrastructure.decisionpoint.impl.buildingblock.controller.LcmControllerBB; +import org.onap.so.client.appc.ApplicationControllerAction; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +/** + * This implementation of {@link ControllerRunnable} is created to demonstrate how to support Appc based controller. + */ +@Component +public class AppcControllerBB extends LcmControllerBB { + + private static final int APPC_ERROR_CODE = 1002; + + @Autowired + private ApplicationControllerAction client; + + @Override + public Boolean understand(ControllerContext context) { + return context.getControllerActor().equalsIgnoreCase("appc"); + } + + @Override + public Boolean ready(ControllerContext context) { + return true; + } + + /** + * This method is left empty intentionally. If you are planning to use the Appc Controller, please implement here. + * + * You can use the {@ref ApplicationControllerAction}, {@ref ApplicationControllerOrchestrator}, + * {@ref ApplicationControllerClient} or create your own Appc Client proxy. + */ + @Override + protected int callLcmClient(ControllerContext context) { + return 0; + } + + @Override + protected int getErrorCode() { + return APPC_ERROR_CODE; + } +} diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/buildingblock/controller/sdnc/SdncControllerBB.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/buildingblock/controller/sdnc/SdncControllerBB.java new file mode 100644 index 0000000000..6baf881be8 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/buildingblock/controller/sdnc/SdncControllerBB.java @@ -0,0 +1,73 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 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.bpmn.infrastructure.decisionpoint.impl.buildingblock.controller.sdnc; + +import java.util.Arrays; +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.infrastructure.decisionpoint.impl.buildingblock.controller.LcmControllerBB; +import org.springframework.stereotype.Component; + +/** + * This implementation of {@link ControllerRunnable} is created to demonstrate how to support SDNC based controller. + * + * For demo purpose, the following actions are supported, UpgradePreCheck UpgradeSoftware UpgradePostCheck, all of these + * actions are appc based actions and they need to be refactored to proper SDNC LCM actions. + */ +@Component +public class SdncControllerBB extends LcmControllerBB { + + private static final String[] supportedActions = new String[] {}; + + private static final int SDNC_ERROR_CODE = 1002; + + @Override + public Boolean understand(ControllerContext context) { + return context.getControllerActor().equalsIgnoreCase("sdnc"); + } + + private boolean isActionSupported(ControllerContext context) { + return Arrays.stream(supportedActions).anyMatch(action -> action.equals(context.getControllerAction())); + } + + @Override + public Boolean ready(ControllerContext context) { + return true; + } + + /** + * This method is left empty intentionally. If you are planning to use the SDNC Controller, please implement here. + * + * You can use the Appc Client proxy, like, {@ref ApplicationControllerAction} + * {@ref ApplicationControllerOrchestrator} {@ref ApplicationControllerClient} + * + * Or create your own SDNC Client proxy. + */ + @Override + protected int callLcmClient(ControllerContext context) { + return 0; + } + + @Override + protected int getErrorCode() { + return SDNC_ERROR_CODE; + } +} diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/buildingblock/controller/sdnc/prepare/PrepareSdncBB.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/buildingblock/controller/sdnc/prepare/PrepareSdncBB.java new file mode 100644 index 0000000000..dd75107b73 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/buildingblock/controller/sdnc/prepare/PrepareSdncBB.java @@ -0,0 +1,47 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 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.bpmn.infrastructure.decisionpoint.impl.buildingblock.controller.sdnc.prepare; + +import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.so.bpmn.infrastructure.decisionpoint.api.ControllerContext; +import org.onap.so.bpmn.infrastructure.decisionpoint.api.controller.ControllerPreparable; +import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB; +import org.onap.so.client.exception.ExceptionBuilder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; + +/** + * This abstract class should be extended by all the SDNC based {@ControllerPreparable}. It defines some common + * behavior. + */ +public abstract class PrepareSdncBB implements ControllerPreparable { + + protected Logger logger = LoggerFactory.getLogger(this.getClass()); + + @Autowired + protected ExceptionBuilder exceptionUtil; + + @Autowired + protected ExtractPojosForBB extractPojosForBB; + + public boolean understand(final ControllerContext controllerContext) { + return controllerContext.getControllerActor().equalsIgnoreCase("sdnc"); + } +} diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/buildingblock/controller/sdnc/prepare/PrepareSdncUpgradePreCheckPnfBB.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/buildingblock/controller/sdnc/prepare/PrepareSdncUpgradePreCheckPnfBB.java new file mode 100644 index 0000000000..c659290f28 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/buildingblock/controller/sdnc/prepare/PrepareSdncUpgradePreCheckPnfBB.java @@ -0,0 +1,60 @@ +/* + * ============LICENSE_START======================================================= Copyright (C) 2019 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.bpmn.infrastructure.decisionpoint.impl.buildingblock.controller.sdnc.prepare; + +import org.json.JSONArray; +import org.json.JSONObject; +import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.so.bpmn.infrastructure.decisionpoint.api.ControllerContext; +import org.springframework.stereotype.Component; + +/** + * This class is used to prepare the {@ref ControllerContext} for SDNC UpgradePreCheck action. + */ +@Component +public class PrepareSdncUpgradePreCheckPnfBB extends PrepareSdncBB { + + @Override + public boolean understand(ControllerContext controllerContext) { + return super.understand(controllerContext) && controllerContext.getControllerAction().equals("UpgradePreCheck") + && controllerContext.getControllerScope().equalsIgnoreCase("pnf"); + } + + @Override + public void prepare(ControllerContext controllerContext) { + + String payload = controllerContext.getExecution().getVariable("payload"); + String actualPayLoad = constructPayload(payload, controllerContext.getControllerAction()); + + controllerContext.getExecution().setVariable("payload", actualPayLoad); + } + + private String constructPayload(String payload, String action) { + + JSONObject jsonObject = new JSONObject(payload); + if (jsonObject.has("action")) { + JSONArray jsonArray = jsonObject.getJSONArray("action"); + + for (int i = 0; i < jsonArray.length(); i++) { + JSONObject jsonObject1 = jsonArray.getJSONObject(i); + if (jsonObject1.has(action)) { + return jsonObject1.toString(); + } + } + } + return payload; + } +} + diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/ControllerExecutionDE.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/ControllerExecutionDE.java new file mode 100644 index 0000000000..0458d3c103 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/ControllerExecutionDE.java @@ -0,0 +1,148 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 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.bpmn.infrastructure.decisionpoint.impl.camunda; + +import com.google.common.base.Strings; +import java.util.Optional; +import org.camunda.bpm.engine.delegate.DelegateExecution; +import org.camunda.bpm.engine.delegate.JavaDelegate; +import org.onap.logging.filter.base.ONAPComponents; +import org.onap.so.bpmn.infrastructure.decisionpoint.api.ControllerContext; +import org.onap.so.bpmn.infrastructure.decisionpoint.api.ControllerRunnable; +import org.onap.so.bpmn.infrastructure.decisionpoint.impl.AbstractControllerExecution; +import org.onap.so.db.catalog.beans.ControllerSelectionReference; +import org.onap.so.db.catalog.beans.PnfResourceCustomization; +import org.onap.so.db.catalog.beans.VnfResourceCustomization; +import org.onap.so.db.catalog.client.CatalogDbClient; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +/** + * This class is used for camunda {@ref DelegateExecution} API based controller execution. + * + * The following parameters are expected in the {@ref DelegateExecution} context, + * + *
    + *
  • action: action to be executed
  • + *
  • scope: type of the resource, i.e, pnf, vnf, vf
  • + *
  • resource_customization_uuid: resource customization UUID
  • + *
  • resource_type: resource type, optional. It's used to find the controller from controller_selection_reference + * table. Same as VNF_TYPE in the table
  • + *
+ */ +@Component +public class ControllerExecutionDE extends AbstractControllerExecution implements JavaDelegate { + + @Autowired + protected CatalogDbClient catalogDbClient; + + @Override + public void execute(final DelegateExecution execution) { + ControllerContext controllerContext = buildControllerContext(execution); + controllerExecute(controllerContext); + } + + /** + * this method is used to get the controller actor, there could be few places to get the actor(ordered by priority), + * + *
    + *
  1. Execution Context, i.e, DelegateExecution
  2. + *
  3. Resource customization table, pnf_resource_customization for PNF or vnf_resource_customization for VNF
  4. + *
  5. controller_selection_reference, resource_type and action will be used to fetch from this table
  6. + *
+ * + * @param execution DelegateExecution instance + * @param controllerScope controller scope, e.g, pnf, vnf, vfModule + * @param resourceCustomizationUuid resource customization UUID, e.g, pnfCustomizationUuid, vnfCustomizationUuid + * @param controllerAction controller action, e.g, configAssign, configDeploy + * @return controller actor + */ + protected String getControllerActor(DelegateExecution execution, String controllerScope, + String resourceCustomizationUuid, String controllerAction) { + + /** + * Firstly, check the execution context for actor parameter. + */ + String controllerActor = getParameterFromExecution(execution, CONTROLLER_ACTOR_PARAM); + + /** + * If no meaningful controller actor value found in the execution context and the value is not SO-REF-DATA. + */ + if (Strings.isNullOrEmpty(controllerActor) && !isSoRefControllerActor(controllerActor)) { + + /** + * secondly, if no meaningful actor from execution context, getting from resource table in database. + */ + if (isPnfResourceScope(controllerScope)) { + PnfResourceCustomization pnfResourceCustomization = + catalogDbClient.getPnfResourceCustomizationByModelCustomizationUUID(resourceCustomizationUuid); + controllerActor = pnfResourceCustomization.getControllerActor(); + } else if (isVnfResourceScope(controllerScope)) { + VnfResourceCustomization vnfResourceCustomization = + catalogDbClient.getVnfResourceCustomizationByModelCustomizationUUID(resourceCustomizationUuid); + controllerActor = vnfResourceCustomization.getControllerActor(); + } else { + logger.warn("Unrecognized scope: {}", controllerScope); + } + } + + /** + * Lastly, can NOT find the controller actor information from resource customization table or value is + * SO-REF-DATA + */ + if (Strings.isNullOrEmpty(controllerActor) || isSoRefControllerActor(controllerActor)) { + String resourceType = getParameterFromExecution(execution, RESOURCE_TYPE_PARAM); + ControllerSelectionReference reference = catalogDbClient + .getControllerSelectionReferenceByVnfTypeAndActionCategory(resourceType, controllerAction); + controllerActor = reference.getControllerName(); + } + + return controllerActor; + } + + @Override + public void controllerExecute(ControllerContext controllerContext) { + Optional optional = getController(controllerContext); + + if (optional.isPresent()) { + ControllerRunnable controller = optional.get(); + if (controller.ready(controllerContext)) { + controller.prepare(controllerContext); + controller.run(controllerContext); + } else { + exceptionBuilder.buildAndThrowWorkflowException(controllerContext.getExecution(), 9001, + "Controller is NOT Ready for the action", ONAPComponents.SO); + } + } else { + exceptionBuilder.buildAndThrowWorkflowException(controllerContext.getExecution(), 9000, + "Unable to find the controller implementation", ONAPComponents.SO); + } + } + + @Override + protected String getParameterFromExecution(DelegateExecution execution, String parameterName) { + if (execution.hasVariable(parameterName)) { + String paramValue = String.valueOf(execution.getVariable(parameterName)); + logger.debug("parameterName: {}, parameterValue: {}", parameterName, paramValue); + return paramValue; + } else { + return ""; + } + } +} diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/controller/LcmControllerDE.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/controller/LcmControllerDE.java new file mode 100644 index 0000000000..95e270a071 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/controller/LcmControllerDE.java @@ -0,0 +1,69 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 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.bpmn.infrastructure.decisionpoint.impl.camunda.controller; + +import java.util.List; +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.infrastructure.decisionpoint.api.controller.ControllerPreparable; +import org.onap.so.client.appc.ApplicationControllerAction; +import org.onap.so.client.exception.ExceptionBuilder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; + +/** + * This abstract class implements {@link ControllerRunnable} used for {@link DelegateExecution} API based LCM + * controller. + */ +public abstract class LcmControllerDE implements ControllerRunnable { + + protected final Logger logger = LoggerFactory.getLogger(this.getClass()); + + @Autowired + protected ExceptionBuilder exceptionUtil; + + @Autowired + protected List> prepareList; + + @Autowired + protected ApplicationControllerAction client; + + @Override + public void prepare(ControllerContext context) { + prepareList.stream().filter(prepare -> prepare.understand(context)) + .forEach(prepare -> prepare.prepare(context)); + } + + @Override + public void run(ControllerContext context) { + callLcmClient(context); + } + + /** + * This method is used to execute the LCM action by calling LCM client, appc Client or SDNC client. + * + * @return error code + */ + protected abstract int callLcmClient(ControllerContext context); + + protected abstract int getErrorCode(); +} diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/controller/appc/AppcControllerDE.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/controller/appc/AppcControllerDE.java new file mode 100644 index 0000000000..7ebd16e561 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/controller/appc/AppcControllerDE.java @@ -0,0 +1,62 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 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.bpmn.infrastructure.decisionpoint.impl.camunda.controller.appc; + +import org.camunda.bpm.engine.delegate.DelegateExecution; +import org.onap.so.bpmn.infrastructure.decisionpoint.api.ControllerContext; +import org.onap.so.bpmn.infrastructure.decisionpoint.impl.camunda.controller.LcmControllerDE; +import org.springframework.stereotype.Component; + +/** + * This class is created to demonstrate how to support {@link DelegateExecution} API based APPC controller. + * + * Function wise, it's similar as {@ref AppcClient} groovy code. + */ +@Component +public class AppcControllerDE extends LcmControllerDE { + + private static final int APPC_DELEGATE_EXECUTION_ERROR_CODE = 1102; + + @Override + public Boolean understand(ControllerContext context) { + return context.getControllerActor().equalsIgnoreCase("appc"); + } + + @Override + public Boolean ready(ControllerContext context) { + return true; + } + + /** + * This method is left empty intentionally. If you are planning to use the Appc Controller, please implement here. + * + * You can use the {@ref ApplicationControllerAction}, {@ref ApplicationControllerOrchestrator}, + * {@ref ApplicationControllerClient} or create your own Appc Client proxy. + */ + @Override + protected int callLcmClient(ControllerContext context) { + return 0; + } + + @Override + protected int getErrorCode() { + return APPC_DELEGATE_EXECUTION_ERROR_CODE; + } +} 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 new file mode 100644 index 0000000000..6b0cbc0396 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/controller/cds/CdsControllerDE.java @@ -0,0 +1,61 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 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.bpmn.infrastructure.decisionpoint.impl.camunda.controller.cds; + +import java.util.List; +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.infrastructure.decisionpoint.api.controller.ControllerPreparable; +import org.onap.so.client.cds.AbstractCDSProcessingBBUtils; +import org.springframework.beans.factory.annotation.Autowired; +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 { + + @Autowired(required = false) + private List> prepareList; + + @Override + public Boolean understand(ControllerContext context) { + return context.getControllerActor().equalsIgnoreCase("cds"); + } + + @Override + public Boolean ready(ControllerContext context) { + return true; + } + + @Override + public void prepare(ControllerContext context) { + prepareList.stream().filter(prepare -> prepare.understand(context)) + .forEach(prepare -> prepare.prepare(context)); + } + + @Override + public void run(ControllerContext context) { + DelegateExecution execution = context.getExecution(); + constructExecutionServiceInputObject(execution); + sendRequestToCDSClient(execution); + } +} diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/controller/cds/prepare/PreparePnfConfigAssignDE.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/controller/cds/prepare/PreparePnfConfigAssignDE.java new file mode 100644 index 0000000000..b0da075e7e --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/controller/cds/prepare/PreparePnfConfigAssignDE.java @@ -0,0 +1,50 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 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.bpmn.infrastructure.decisionpoint.impl.camunda.controller.cds.prepare; + +import org.camunda.bpm.engine.delegate.DelegateExecution; +import org.onap.so.bpmn.infrastructure.decisionpoint.api.ControllerContext; +import org.onap.so.bpmn.infrastructure.decisionpoint.api.controller.ControllerPreparable; +import org.onap.so.bpmn.infrastructure.pnf.delegate.PrepareConfigAssignDelegate; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +/** + * This class implements {@link ControllerPreparable} interface and is used to set up the context for PNF config-assign + * action. + */ +@Component +public class PreparePnfConfigAssignDE implements ControllerPreparable { + + @Autowired + private PrepareConfigAssignDelegate prepareConfigAssignDelegate; + + @Override + public boolean understand(ControllerContext controllerContext) { + return controllerContext.getControllerActor().equalsIgnoreCase("cds") + && controllerContext.getControllerAction().equalsIgnoreCase("config-assign") + && controllerContext.getControllerScope().equalsIgnoreCase("pnf"); + } + + @Override + public void prepare(ControllerContext controllerContext) { + prepareConfigAssignDelegate.execute(controllerContext.getExecution()); + } +} diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/controller/cds/prepare/PreparePnfConfigDeployDE.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/controller/cds/prepare/PreparePnfConfigDeployDE.java new file mode 100644 index 0000000000..b88da2ed39 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/controller/cds/prepare/PreparePnfConfigDeployDE.java @@ -0,0 +1,50 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 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.bpmn.infrastructure.decisionpoint.impl.camunda.controller.cds.prepare; + +import org.camunda.bpm.engine.delegate.DelegateExecution; +import org.onap.so.bpmn.infrastructure.decisionpoint.api.ControllerContext; +import org.onap.so.bpmn.infrastructure.decisionpoint.api.controller.ControllerPreparable; +import org.onap.so.bpmn.infrastructure.pnf.delegate.PrepareConfigDeployDelegate; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +/** + * This class implements {@link ControllerPreparable} interface and is used to set up the context for PNF config-deploy + * action. + */ +@Component +public class PreparePnfConfigDeployDE implements ControllerPreparable { + + @Autowired + private PrepareConfigDeployDelegate prepareConfigDeployDelegate; + + @Override + public boolean understand(ControllerContext controllerContext) { + return controllerContext.getControllerActor().equalsIgnoreCase("cds") + && controllerContext.getControllerAction().equalsIgnoreCase("config-deploy") + && controllerContext.getControllerScope().equalsIgnoreCase("pnf"); + } + + @Override + public void prepare(ControllerContext controllerContext) { + prepareConfigDeployDelegate.execute(controllerContext.getExecution()); + } +} diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/controller/sdnc/SdncControllerDE.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/controller/sdnc/SdncControllerDE.java new file mode 100644 index 0000000000..db0d402f6e --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/controller/sdnc/SdncControllerDE.java @@ -0,0 +1,62 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 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.bpmn.infrastructure.decisionpoint.impl.camunda.controller.sdnc; + +import org.camunda.bpm.engine.delegate.DelegateExecution; +import org.onap.so.bpmn.infrastructure.decisionpoint.api.ControllerContext; +import org.onap.so.bpmn.infrastructure.decisionpoint.impl.camunda.controller.LcmControllerDE; +import org.springframework.stereotype.Component; + +/** + * This class is created to demonstrate how to support {@link DelegateExecution} API based SDNC controller. + * + * Function wise, it's similar to the Appc Controller, like in the AppcClient groovy code. + */ +@Component +public class SdncControllerDE extends LcmControllerDE { + + private static final int SDNC_DELEGATE_EXECUTION_ERROR_CODE = 1103; + + @Override + public Boolean understand(ControllerContext context) { + return context.getControllerActor().equalsIgnoreCase("sdnc"); + } + + @Override + public Boolean ready(ControllerContext context) { + return true; + } + + /** + * This method is left empty intentionally. If you are planning to use the SDNC Controller, please implement here. + * + * You can use the {@ref ApplicationControllerAction}, {@ref ApplicationControllerOrchestrator}, + * {@ref ApplicationControllerClient} or create your own SDNC Client proxy. + */ + @Override + protected int callLcmClient(ControllerContext context) { + return 0; + } + + @Override + protected int getErrorCode() { + return SDNC_DELEGATE_EXECUTION_ERROR_CODE; + } +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/GrpcNettyServer.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/GrpcNettyServer.java new file mode 100644 index 0000000000..e089da6ac7 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/GrpcNettyServer.java @@ -0,0 +1,113 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 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; + +import io.grpc.ServerBuilder; +import io.grpc.stub.StreamObserver; +import io.grpc.testing.GrpcCleanupRule; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.atomic.AtomicReference; +import javax.annotation.PostConstruct; +import org.junit.Rule; +import org.onap.ccsdk.cds.controllerblueprints.common.api.EventType; +import org.onap.ccsdk.cds.controllerblueprints.common.api.Status; +import org.onap.ccsdk.cds.controllerblueprints.processing.api.BluePrintProcessingServiceGrpc.BluePrintProcessingServiceImplBase; +import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceInput; +import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceOutput; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +@Component +public class GrpcNettyServer extends BluePrintProcessingServiceImplBase { + + private static final Logger logger = LoggerFactory.getLogger(GrpcNettyServer.class); + + @Value("${cds.endpoint}") + private String host; + + @Value("${cds.port}") + private String port; + + @Rule + public final GrpcCleanupRule grpcCleanup = new GrpcCleanupRule(); + + private final CountDownLatch allRequestsDelivered = new CountDownLatch(1); + private final AtomicReference> responseObserverRef = new AtomicReference<>(); + private final List detailedMessages = new ArrayList<>(); + + @PostConstruct + public void start() throws IOException { + + final BluePrintProcessingServiceImplBase blueprintPrcessorImpl = new BluePrintProcessingServiceImplBase() { + @Override + public StreamObserver process( + StreamObserver responseObserver) { + + responseObserverRef.set(responseObserver); + + StreamObserver requestObserver = new StreamObserver() { + @Override + public void onNext(ExecutionServiceInput message) { + detailedMessages.add(message); + logger.info("Message received: {}", message); + ExecutionServiceOutput executionServiceOutput = ExecutionServiceOutput.newBuilder() + .setActionIdentifiers(message.getActionIdentifiers()) + .setStatus(Status.newBuilder().setEventType(EventType.EVENT_COMPONENT_EXECUTED).build()) + .build(); + + responseObserverRef.get().onNext(executionServiceOutput); + logger.info("Message sent: {}", executionServiceOutput); + } + + @Override + public void onError(Throwable t) { + responseObserverRef.get().onError(t); + } + + @Override + public void onCompleted() { + allRequestsDelivered.countDown(); + responseObserverRef.get().onCompleted(); + } + }; + + return requestObserver; + } + }; + grpcCleanup.register(ServerBuilder.forPort(Integer.valueOf(port)).directExecutor() + .addService(blueprintPrcessorImpl).build().start()); + + } + + public List getDetailedMessages() { + return this.detailedMessages; + } + + public void cleanMessage() { + this.detailedMessages.clear(); + } + +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/buildingblock/ControllerExecutionBBTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/buildingblock/ControllerExecutionBBTest.java new file mode 100644 index 0000000000..0f9b4d9012 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/buildingblock/ControllerExecutionBBTest.java @@ -0,0 +1,160 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 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.bpmn.infrastructure.decisionpoint.impl.buildingblock; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import static org.onap.so.bpmn.infrastructure.decisionpoint.impl.buildingblock.MockControllerBB.TEST_ACTION; +import static org.onap.so.bpmn.infrastructure.decisionpoint.impl.buildingblock.MockControllerBB.TEST_ACTOR; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.so.client.exception.ExceptionBuilder; +import org.onap.so.db.catalog.beans.ControllerSelectionReference; +import org.onap.so.db.catalog.beans.PnfResourceCustomization; +import org.onap.so.db.catalog.beans.VnfResourceCustomization; +import org.onap.so.db.catalog.client.CatalogDbClient; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = {ControllerExecutionBB.class, MockControllerBB.class, ExceptionBuilder.class}) +public class ControllerExecutionBBTest { + + private static final String ACTOR_PARAM = "actor"; + private static final String ACTION_PARAM = "action"; + private static final String RESOURCE_TYPE_PARAM = "resource_type"; + + private static final String TEST_RESOURCE_CUSTOMIZATION_UUID = "68dc9a92-214c-11e7-93ae-92361f002680"; + private static final String TEST_CATALOGDB_CONTROLLER_ACTOR = "cds"; + private static final String TEST_RESOURCE_TYPE = "Firewall"; + private static final String TEST_CONTROLLER_REFERENCE_ACTOR = "sdnc"; + private static final String TEST_SCOPE = "pnf"; + + @Autowired + private ControllerExecutionBB controllerExecutionBB; + + @MockBean + private BuildingBlockExecution execution; + + @MockBean + private CatalogDbClient client; + + @MockBean + private PnfResourceCustomization pnfResourceCustomization; + + @MockBean + private VnfResourceCustomization vnfResourceCustomization; + + @MockBean + private ControllerSelectionReference controllerSelectionReference; + + @Before + public void setUp() { + when(execution.getVariable(ACTOR_PARAM)).thenReturn(TEST_ACTOR); + when(execution.getVariable(ACTION_PARAM)).thenReturn(MockControllerBB.TEST_ACTION); + + when(pnfResourceCustomization.getControllerActor()).thenReturn(TEST_CATALOGDB_CONTROLLER_ACTOR); + when(client.getPnfResourceCustomizationByModelCustomizationUUID(TEST_RESOURCE_CUSTOMIZATION_UUID)) + .thenReturn(pnfResourceCustomization); + + when(execution.getVariable(RESOURCE_TYPE_PARAM)).thenReturn(TEST_RESOURCE_TYPE); + when(controllerSelectionReference.getControllerName()).thenReturn(TEST_CONTROLLER_REFERENCE_ACTOR); + when(client.getControllerSelectionReferenceByVnfTypeAndActionCategory(TEST_RESOURCE_TYPE, TEST_ACTION)) + .thenReturn(controllerSelectionReference); + } + + @Test + public void testExecution_validInput_expectedOutput() { + controllerExecutionBB.execute(execution); + verify(execution).setVariable("stage", "ready"); + verify(execution).setVariable("stage", "prepare"); + verify(execution).setVariable("stage", "run"); + } + + @Test + public void testGetController_availableInExecutionContext_returnFromExecutionContext() { + String controllerActor = controllerExecutionBB.getControllerActor(execution, TEST_SCOPE, "", TEST_ACTION); + assertEquals(TEST_ACTOR, controllerActor); + } + + @Test + public void testGetController_soRefDataInExecutionContext_returnFromControllerReference() { + when(execution.getVariable(ACTOR_PARAM)).thenReturn("so-ref-data"); + String controllerActor = controllerExecutionBB.getControllerActor(execution, TEST_SCOPE, "", TEST_ACTION); + assertEquals(TEST_CONTROLLER_REFERENCE_ACTOR, controllerActor); + } + + @Test + public void testGetController_notAvailableInExecutionContext_returnFromCatalogdb() { + when(execution.getVariable(ACTOR_PARAM)).thenReturn(""); + String controllerActor = controllerExecutionBB.getControllerActor(execution, TEST_SCOPE, + TEST_RESOURCE_CUSTOMIZATION_UUID, TEST_ACTION); + assertEquals("The controller actor should be the same as in the catalogdb", TEST_CATALOGDB_CONTROLLER_ACTOR, + controllerActor); + } + + @Test + public void testGetController_notAvailableInExecutionContextAndSoRefDataInCatalogdb_returnFromControllerReference() { + when(execution.getVariable(ACTOR_PARAM)).thenReturn(""); + when(pnfResourceCustomization.getControllerActor()).thenReturn("SO-REF-DATA"); + String controllerActor = controllerExecutionBB.getControllerActor(execution, TEST_SCOPE, + TEST_RESOURCE_CUSTOMIZATION_UUID, TEST_ACTION); + assertEquals("The controller actor should be the same as in the catalogdb", TEST_CONTROLLER_REFERENCE_ACTOR, + controllerActor); + } + + @Test + public void testGetController_notAvailableInExecutionContextAndCatalogdb_returnFromControllerReference() { + when(execution.getVariable(ACTOR_PARAM)).thenReturn(""); + when(pnfResourceCustomization.getControllerActor()).thenReturn(""); + + String controllerActor = controllerExecutionBB.getControllerActor(execution, TEST_SCOPE, + TEST_RESOURCE_CUSTOMIZATION_UUID, TEST_ACTION); + assertEquals("The controller actor should be the same as in the controller reference table", + TEST_CONTROLLER_REFERENCE_ACTOR, controllerActor); + } + + @Test + public void testGetController_notAvailableInExecutionContextVnfType_returnFromCatalogdb() { + when(execution.getVariable(ACTOR_PARAM)).thenReturn(""); + + String expectedVnfControllerActor = "appc"; + + String[] controllerScopeArray = new String[] {"vnf", "vfModule"}; + + for (String controllerScope : controllerScopeArray) { + + when(vnfResourceCustomization.getControllerActor()).thenReturn(expectedVnfControllerActor); + when(client.getVnfResourceCustomizationByModelCustomizationUUID(TEST_RESOURCE_CUSTOMIZATION_UUID)) + .thenReturn(vnfResourceCustomization); + + String controllerActor = controllerExecutionBB.getControllerActor(execution, controllerScope, + TEST_RESOURCE_CUSTOMIZATION_UUID, TEST_ACTION); + + assertEquals("The controller actor should be the same as in the catalogdb for scope: " + controllerScope, + expectedVnfControllerActor, controllerActor); + } + } +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/buildingblock/ControllerExecutionBBTestIT.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/buildingblock/ControllerExecutionBBTestIT.java new file mode 100644 index 0000000000..5eef671106 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/buildingblock/ControllerExecutionBBTestIT.java @@ -0,0 +1,194 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 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.bpmn.infrastructure.decisionpoint.impl.buildingblock; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.AssertionsForClassTypes.fail; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.MODEL_UUID; +import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.MSO_REQUEST_ID; +import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PNF_CORRELATION_ID; +import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PNF_UUID; +import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PRC_BLUEPRINT_NAME; +import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PRC_BLUEPRINT_VERSION; +import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PRC_CUSTOMIZATION_UUID; +import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PRC_INSTANCE_NAME; +import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.SERVICE_INSTANCE_ID; +import com.google.protobuf.Struct; +import java.util.HashMap; +import java.util.List; +import java.util.Optional; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; +import org.onap.appc.client.lcm.model.Action; +import org.onap.ccsdk.cds.controllerblueprints.common.api.ActionIdentifiers; +import org.onap.ccsdk.cds.controllerblueprints.common.api.CommonHeader; +import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceInput; +import org.onap.so.BaseIntegrationTest; +import org.onap.so.GrpcNettyServer; +import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; +import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; + +public class ControllerExecutionBBTestIT extends BaseIntegrationTest { + + private Logger logger = LoggerFactory.getLogger(this.getClass()); + + @Autowired + private ControllerExecutionBB controllerExecutionBB; + + @Autowired + private GrpcNettyServer grpcNettyServer; + + private GenericVnf genericVnf; + + private static String TEST_MODEL_UUID = "6bc0b04d-1873-4721-b53d-6615225b2a28"; + private static String TEST_SERVICE_INSTANCE_ID = "test_service_id"; + private static String TEST_PROCESS_KEY = "processKey1"; + private static String TEST_MSO_REQUEST_ID = "ff874603-4222-11e7-9252-005056850d2e"; + + private static String TEST_CDS_ACTION = "config-assign"; + private static String TEST_APPC_ACTION = "HealthCheck"; + + private static String TEST_PNF_RESOURCE_INSTANCE_NAME = "PNF_demo_resource"; + private static String TEST_PNF_CORRELATION_ID = "PNFDemo"; + private static String TEST_PNF_RESOURCE_BLUEPRINT_NAME = "blueprintOnap"; + private static String TEST_PNF_RESOURCE_BLUEPRINT_VERSION = "1.0.1"; + private static String TEST_PNF_RESOURCE_CUSTOMIZATION_UUID = "9acb3a83-8a52-412c-9a45-901764938144"; + private static String TEST_PNF_UUID = "5df8b6de-2083-11e7-93ae-92361f002671"; + + @Before + public void setUp() { + execution.setVariable(MODEL_UUID, TEST_MODEL_UUID); + execution.setVariable(SERVICE_INSTANCE_ID, TEST_SERVICE_INSTANCE_ID); + execution.setVariable(MSO_REQUEST_ID, TEST_MSO_REQUEST_ID); + execution.setVariable("testProcessKey", TEST_PROCESS_KEY); + + grpcNettyServer.cleanMessage(); + } + + @Test + @Ignore + // TODO: re-activate this test case after the SO-CDS generic buildingblock implementation in place + public void testExecution_cdsConfigAssign_actionExecuted() { + + configureCdsConfigAssign(); + + controllerExecutionBB.execute(execution); + List detailedMessages = grpcNettyServer.getDetailedMessages(); + assertThat(detailedMessages).hasSize(1); + try { + checkConfigAssign(detailedMessages.get(0)); + } catch (Exception e) { + e.printStackTrace(); + fail("ConfigAssign request exception", e); + } + } + + @Test + @Ignore + // TODO: re-activate this test case after the SDNC controller is fully implemented. + public void testExecution_sdncUpgradeHealthCheck_actionExecuted() { + configureSdncUpgrade(); + controllerExecutionBB.execute(execution); + + verify(appCClient, times(1)).runAppCCommand(eq(Action.UpgradePreCheck), eq(TEST_MSO_REQUEST_ID), eq(null), + any(Optional.class), any(HashMap.class), eq("sdnc")); + } + + private void configureSdncUpgrade() { + execution.setVariable("actor", "sdnc"); + execution.setVariable("action", "UpgradePreCheck"); + execution.setVariable("payload", "{ \n" + " \"action\":[ \n" + " { \n" + + " \"UpgradePreCheck\":{ \n" + " \"payload\":{ \n" + + " \"pnf-flag\":\"true\",\n" + " \"pnf-name\":\"5gDU0001\",\n" + + " \"pnfId\":\"5gDU0001\",\n" + + " \"ipaddress-v4-oam\":\"192.168.35.83\",\n" + + " \"oldSwVersion\":\"v1\",\n" + " \"targetSwVersion\":\"v2\",\n" + + " \"ruleName\":\"r001\",\n" + " \"Id\":\"10\",\n" + + " \"additionalData\":\"{}\"\n" + " }\n" + " }\n" + " },\n" + + " { \n" + " \"UpgradeSoftware\":{ \n" + " \"payload\":{ \n" + + " \"pnf-flag\":\"true\",\n" + " \"pnfId\":\"5gDU0001\",\n" + + " \"ipaddress-v4-oam\":\"192.168.35.83\",\n" + + " \"swToBeDownloaded\":[ \n" + " { \n" + + " \"swLocation\":\"http://192.168.35.96:10080/ran_du_pkg1-v2.zip\",\n" + + " \"swFileSize\":353,\n" + " \"swFileCompression\":\"ZIP\",\n" + + " \"swFileFormat\":\"zip\"\n" + " }\n" + " ]\n" + + " }\n" + " }\n" + " }\n" + " ]\n" + "}"); + + setServiceInstance(); + genericVnf = setGenericVnf(); + + RequestContext requestContext = setRequestContext(); + requestContext.setMsoRequestId(TEST_MSO_REQUEST_ID); + gBBInput.setRequestContext(requestContext); + } + + private void configureCdsConfigAssign() { + execution.setVariable("actor", "cds"); + execution.setVariable("scope", "pnf"); + execution.setVariable("action", TEST_CDS_ACTION); + + execution.setVariable(PNF_CORRELATION_ID, TEST_PNF_CORRELATION_ID); + execution.setVariable(PNF_UUID, TEST_PNF_UUID); + execution.setVariable(PRC_INSTANCE_NAME, TEST_PNF_RESOURCE_INSTANCE_NAME); + execution.setVariable(PRC_CUSTOMIZATION_UUID, TEST_PNF_RESOURCE_CUSTOMIZATION_UUID); + execution.setVariable(PRC_BLUEPRINT_NAME, TEST_PNF_RESOURCE_BLUEPRINT_NAME); + execution.setVariable(PRC_BLUEPRINT_VERSION, TEST_PNF_RESOURCE_BLUEPRINT_VERSION); + } + + private void checkConfigAssign(ExecutionServiceInput executionServiceInput) { + + logger.info("Checking the configAssign request"); + ActionIdentifiers actionIdentifiers = executionServiceInput.getActionIdentifiers(); + + /** + * the fields of actionIdentifiers should match the one in the + * response/createVcpeResCustServiceSimplifiedTest_catalogdb.json. + */ + assertThat(actionIdentifiers.getBlueprintName()).isEqualTo(TEST_PNF_RESOURCE_BLUEPRINT_NAME); + assertThat(actionIdentifiers.getBlueprintVersion()).isEqualTo(TEST_PNF_RESOURCE_BLUEPRINT_VERSION); + assertThat(actionIdentifiers.getActionName()).isEqualTo(TEST_CDS_ACTION); + assertThat(actionIdentifiers.getMode()).isEqualTo("sync"); + + CommonHeader commonHeader = executionServiceInput.getCommonHeader(); + assertThat(commonHeader.getOriginatorId()).isEqualTo("SO"); + assertThat(commonHeader.getRequestId()).isEqualTo(TEST_MSO_REQUEST_ID); + + Struct payload = executionServiceInput.getPayload(); + Struct requeststruct = payload.getFieldsOrThrow("config-assign-request").getStructValue(); + + assertThat(requeststruct.getFieldsOrThrow("resolution-key").getStringValue()) + .isEqualTo(TEST_PNF_CORRELATION_ID); + Struct propertiesStruct = requeststruct.getFieldsOrThrow("config-assign-properties").getStructValue(); + + assertThat(propertiesStruct.getFieldsOrThrow("pnf-name").getStringValue()).isEqualTo(TEST_PNF_CORRELATION_ID); + assertThat(propertiesStruct.getFieldsOrThrow("service-model-uuid").getStringValue()).isEqualTo(TEST_MODEL_UUID); + assertThat(propertiesStruct.getFieldsOrThrow("pnf-customization-uuid").getStringValue()) + .isEqualTo(TEST_PNF_RESOURCE_CUSTOMIZATION_UUID); + } + +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/buildingblock/MockControllerBB.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/buildingblock/MockControllerBB.java new file mode 100644 index 0000000000..06fd01dce1 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/buildingblock/MockControllerBB.java @@ -0,0 +1,54 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 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.bpmn.infrastructure.decisionpoint.impl.buildingblock; + +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.springframework.stereotype.Component; + +@Component +public class MockControllerBB implements ControllerRunnable { + + public static final String TEST_ACTOR = "test-controller"; + public static final String TEST_ACTION = "configuration"; + + @Override + public Boolean understand(ControllerContext context) { + return context.getControllerAction().equalsIgnoreCase(TEST_ACTION) + && context.getControllerActor().equalsIgnoreCase(TEST_ACTOR); + } + + @Override + public Boolean ready(ControllerContext context) { + context.getExecution().setVariable("stage", "ready"); + return true; + } + + @Override + public void prepare(ControllerContext context) { + context.getExecution().setVariable("stage", "prepare"); + } + + @Override + public void run(ControllerContext context) { + context.getExecution().setVariable("stage", "run"); + } +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/buildingblock/controller/appc/AppcControllerBBTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/buildingblock/controller/appc/AppcControllerBBTest.java new file mode 100644 index 0000000000..46cb8189cc --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/buildingblock/controller/appc/AppcControllerBBTest.java @@ -0,0 +1,65 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 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.bpmn.infrastructure.decisionpoint.impl.buildingblock.controller.appc; + + +import static junit.framework.TestCase.assertTrue; +import static org.junit.Assert.assertFalse; +import static org.mockito.Mockito.when; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.so.bpmn.infrastructure.decisionpoint.api.ControllerContext; +import org.onap.so.client.appc.ApplicationControllerAction; +import org.onap.so.client.exception.ExceptionBuilder; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = {AppcControllerBB.class, ExceptionBuilder.class}) +public class AppcControllerBBTest { + + @Autowired + private AppcControllerBB appcControllerBB; + + @MockBean + private ControllerContext controllerContext; + + @MockBean + protected ApplicationControllerAction client; + + @Before + public void setUp() { + when(controllerContext.getControllerActor()).thenReturn("appc"); + } + + @Test + public void testUnderstand_validContext_TrueReturned() { + assertTrue(appcControllerBB.understand(controllerContext)); + } + + @Test + public void testUnderstand_invalidContext_FalseReturned() { + when(controllerContext.getControllerActor()).thenReturn("sdnc"); + assertFalse(appcControllerBB.understand(controllerContext)); + } +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/buildingblock/controller/sdnc/SdncControllerBBTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/buildingblock/controller/sdnc/SdncControllerBBTest.java new file mode 100644 index 0000000000..5c3b439819 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/buildingblock/controller/sdnc/SdncControllerBBTest.java @@ -0,0 +1,64 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 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.bpmn.infrastructure.decisionpoint.impl.buildingblock.controller.sdnc; + +import static junit.framework.TestCase.assertTrue; +import static org.junit.Assert.assertFalse; +import static org.mockito.Mockito.when; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.so.bpmn.infrastructure.decisionpoint.api.ControllerContext; +import org.onap.so.client.appc.ApplicationControllerAction; +import org.onap.so.client.exception.ExceptionBuilder; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = {SdncControllerBB.class, ExceptionBuilder.class}) +public class SdncControllerBBTest { + + @Autowired + private SdncControllerBB sSdncControllerBB; + + @MockBean + private ControllerContext controllerContext; + + @MockBean + protected ApplicationControllerAction client; + + @Before + public void setUp() { + when(controllerContext.getControllerActor()).thenReturn("sdnc"); + } + + @Test + public void testUnderstand_validContext_TrueReturned() { + assertTrue(sSdncControllerBB.understand(controllerContext)); + } + + @Test + public void testUnderstand_invalidContext_FalseReturned() { + when(controllerContext.getControllerActor()).thenReturn("cds"); + assertFalse(sSdncControllerBB.understand(controllerContext)); + } +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/ControllerExecutionDETest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/ControllerExecutionDETest.java new file mode 100644 index 0000000000..15a1a1e52d --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/ControllerExecutionDETest.java @@ -0,0 +1,160 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 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.bpmn.infrastructure.decisionpoint.impl.camunda; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.when; +import static org.onap.so.bpmn.infrastructure.decisionpoint.impl.camunda.MockControllerDE.TEST_ACTION; +import static org.onap.so.bpmn.infrastructure.decisionpoint.impl.camunda.MockControllerDE.TEST_ACTOR; +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.onap.so.client.exception.ExceptionBuilder; +import org.onap.so.db.catalog.beans.ControllerSelectionReference; +import org.onap.so.db.catalog.beans.PnfResourceCustomization; +import org.onap.so.db.catalog.beans.VnfResourceCustomization; +import org.onap.so.db.catalog.client.CatalogDbClient; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = {ControllerExecutionDE.class, MockControllerDE.class, ExceptionBuilder.class}) +public class ControllerExecutionDETest { + + private static final String ACTOR_PARAM = "actor"; + private static final String ACTION_PARAM = "action"; + private static final String RESOURCE_TYPE_PARAM = "resource_type"; + + private static final String TEST_RESOURCE_CUSTOMIZATION_UUID = "68dc9a92-214c-11e7-93ae-92361f002680"; + private static final String TEST_CATALOGDB_CONTROLLER_ACTOR = "cds"; + private static final String TEST_RESOURCE_TYPE = "Firewall"; + private static final String TEST_CONTROLLER_REFERENCE_ACTOR = "sdnc"; + private static final String TEST_SCOPE = "pnf"; + + @Autowired + private ControllerExecutionDE controllerExecutionDE; + + @MockBean + private CatalogDbClient client; + + @MockBean + private PnfResourceCustomization pnfResourceCustomization; + + @MockBean + private VnfResourceCustomization vnfResourceCustomization; + + @MockBean + private ControllerSelectionReference controllerSelectionReference; + + private DelegateExecution execution = new DelegateExecutionFake(); + + @Before + public void setUp() { + execution.setVariable(ACTION_PARAM, TEST_ACTION); + execution.setVariable(ACTOR_PARAM, TEST_ACTOR); + + when(pnfResourceCustomization.getControllerActor()).thenReturn(TEST_CATALOGDB_CONTROLLER_ACTOR); + when(client.getPnfResourceCustomizationByModelCustomizationUUID(TEST_RESOURCE_CUSTOMIZATION_UUID)) + .thenReturn(pnfResourceCustomization); + + execution.setVariable(RESOURCE_TYPE_PARAM, TEST_RESOURCE_TYPE); + when(controllerSelectionReference.getControllerName()).thenReturn(TEST_CONTROLLER_REFERENCE_ACTOR); + when(client.getControllerSelectionReferenceByVnfTypeAndActionCategory(TEST_RESOURCE_TYPE, TEST_ACTION)) + .thenReturn(controllerSelectionReference); + } + + @Test + public void testExecution_validInput_expectedOutput() { + controllerExecutionDE.execute(execution); + assertTrue((Boolean) execution.getVariable("ready")); + assertTrue((Boolean) execution.getVariable("prepare")); + assertTrue((Boolean) execution.getVariable("run")); + } + + @Test + public void testGetController_availableInExecutionContext_returnFromExecutionContext() { + String controllerActor = controllerExecutionDE.getControllerActor(execution, TEST_SCOPE, "", TEST_ACTION); + assertEquals(TEST_ACTOR, controllerActor); + } + + @Test + public void testGetController_soRefDataInExecutionContext_returnFromExecutionContext() { + execution.setVariable(ACTOR_PARAM, "so-ref-data"); + String controllerActor = controllerExecutionDE.getControllerActor(execution, TEST_SCOPE, "", TEST_ACTION); + assertEquals(TEST_CONTROLLER_REFERENCE_ACTOR, controllerActor); + } + + @Test + public void testGetController_notAvailableInExecutionContext_returnFromCatalogdb() { + execution.setVariable(ACTOR_PARAM, ""); + String controllerActor = controllerExecutionDE.getControllerActor(execution, TEST_SCOPE, + TEST_RESOURCE_CUSTOMIZATION_UUID, TEST_ACTION); + assertEquals("The controller actor should be the same as in the catalogdb", TEST_CATALOGDB_CONTROLLER_ACTOR, + controllerActor); + } + + @Test + public void testGetController_notAvailableInExecutionContextAndSoRefDataInCatalogdb_returnFromControllerReference() { + execution.setVariable(ACTOR_PARAM, ""); + when(pnfResourceCustomization.getControllerActor()).thenReturn("SO-REF-DATA"); + String controllerActor = controllerExecutionDE.getControllerActor(execution, TEST_SCOPE, + TEST_RESOURCE_CUSTOMIZATION_UUID, TEST_ACTION); + assertEquals("The controller actor should be the same as in the catalogdb", TEST_CONTROLLER_REFERENCE_ACTOR, + controllerActor); + } + + @Test + public void testGetController_notAvailableInExecutionContextAndCatalogdb_returnFromControllerReference() { + execution.setVariable(ACTOR_PARAM, ""); + when(pnfResourceCustomization.getControllerActor()).thenReturn(""); + + String controllerActor = controllerExecutionDE.getControllerActor(execution, TEST_SCOPE, + TEST_RESOURCE_CUSTOMIZATION_UUID, TEST_ACTION); + assertEquals("The controller actor should be the same as in the controller reference table", + TEST_CONTROLLER_REFERENCE_ACTOR, controllerActor); + } + + @Test + public void testGetController_notAvailableInExecutionContextVnfType_returnFromCatalogdb() { + execution.setVariable(ACTOR_PARAM, ""); + + String expectedVnfControllerActor = "appc"; + + String[] controllerScopeArray = new String[] {"vnf", "vfModule"}; + + for (String controllerScope : controllerScopeArray) { + + when(vnfResourceCustomization.getControllerActor()).thenReturn(expectedVnfControllerActor); + when(client.getVnfResourceCustomizationByModelCustomizationUUID(TEST_RESOURCE_CUSTOMIZATION_UUID)) + .thenReturn(vnfResourceCustomization); + + String controllerActor = controllerExecutionDE.getControllerActor(execution, controllerScope, + TEST_RESOURCE_CUSTOMIZATION_UUID, TEST_ACTION); + + assertEquals("The controller actor should be the same as in the catalogdb for scope: " + controllerScope, + expectedVnfControllerActor, controllerActor); + } + } +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/ControllerExecutionDETestIT.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/ControllerExecutionDETestIT.java new file mode 100644 index 0000000000..860780a2fc --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/ControllerExecutionDETestIT.java @@ -0,0 +1,144 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 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.bpmn.infrastructure.decisionpoint.impl.camunda; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.AssertionsForClassTypes.fail; +import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.MODEL_UUID; +import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.MSO_REQUEST_ID; +import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PNF_CORRELATION_ID; +import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PNF_UUID; +import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PRC_BLUEPRINT_NAME; +import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PRC_BLUEPRINT_VERSION; +import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PRC_CUSTOMIZATION_UUID; +import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PRC_INSTANCE_NAME; +import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.SERVICE_INSTANCE_ID; +import com.google.protobuf.Struct; +import java.util.List; +import org.junit.Before; +import org.junit.Test; +import org.onap.ccsdk.cds.controllerblueprints.common.api.ActionIdentifiers; +import org.onap.ccsdk.cds.controllerblueprints.common.api.CommonHeader; +import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceInput; +import org.onap.so.BaseIntegrationTest; +import org.onap.so.GrpcNettyServer; +import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; + +public class ControllerExecutionDETestIT extends BaseIntegrationTest { + + private Logger logger = LoggerFactory.getLogger(this.getClass()); + + @Autowired + private ControllerExecutionDE controllerExecutionDE; + + @Autowired + private GrpcNettyServer grpcNettyServer; + + private GenericVnf genericVnf; + + private static String TEST_MODEL_UUID = "6bc0b04d-1873-4721-b53d-6615225b2a28"; + private static String TEST_SERVICE_INSTANCE_ID = "test_service_id"; + private static String TEST_PROCESS_KEY = "processKey1"; + private static String TEST_MSO_REQUEST_ID = "ff874603-4222-11e7-9252-005056850d2e"; + + private static String TEST_CDS_ACTION = "config-assign"; + private static String TEST_APPC_ACTION = "HealthCheck"; + + private static String TEST_PNF_RESOURCE_INSTANCE_NAME = "PNF_demo_resource"; + private static String TEST_PNF_CORRELATION_ID = "PNFDemo"; + private static String TEST_PNF_RESOURCE_BLUEPRINT_NAME = "blueprintOnap"; + private static String TEST_PNF_RESOURCE_BLUEPRINT_VERSION = "1.0.1"; + private static String TEST_PNF_RESOURCE_CUSTOMIZATION_UUID = "9acb3a83-8a52-412c-9a45-901764938144"; + private static String TEST_PNF_UUID = "5df8b6de-2083-11e7-93ae-92361f002671"; + + @Before + public void setUp() { + delegateExecution.setVariable(MODEL_UUID, TEST_MODEL_UUID); + delegateExecution.setVariable(SERVICE_INSTANCE_ID, TEST_SERVICE_INSTANCE_ID); + delegateExecution.setVariable(MSO_REQUEST_ID, TEST_MSO_REQUEST_ID); + delegateExecution.setVariable("testProcessKey", TEST_PROCESS_KEY); + + grpcNettyServer.cleanMessage(); + } + + @Test + public void testExecution_cdsConfigAssign_actionExecuted() { + + configureCdsConfigAssign(); + + controllerExecutionDE.execute(delegateExecution); + List detailedMessages = grpcNettyServer.getDetailedMessages(); + assertThat(detailedMessages).hasSize(1); + try { + checkConfigAssign(detailedMessages.get(0)); + } catch (Exception e) { + e.printStackTrace(); + fail("ConfigAssign request exception", e); + } + } + + private void configureCdsConfigAssign() { + delegateExecution.setVariable("actor", "cds"); + delegateExecution.setVariable("action", TEST_CDS_ACTION); + delegateExecution.setVariable("scope", "pnf"); + + delegateExecution.setVariable(PNF_CORRELATION_ID, TEST_PNF_CORRELATION_ID); + delegateExecution.setVariable(PNF_UUID, TEST_PNF_UUID); + delegateExecution.setVariable(PRC_INSTANCE_NAME, TEST_PNF_RESOURCE_INSTANCE_NAME); + delegateExecution.setVariable(PRC_CUSTOMIZATION_UUID, TEST_PNF_RESOURCE_CUSTOMIZATION_UUID); + delegateExecution.setVariable(PRC_BLUEPRINT_NAME, TEST_PNF_RESOURCE_BLUEPRINT_NAME); + delegateExecution.setVariable(PRC_BLUEPRINT_VERSION, TEST_PNF_RESOURCE_BLUEPRINT_VERSION); + } + + private void checkConfigAssign(ExecutionServiceInput executionServiceInput) { + + logger.info("Checking the configAssign request"); + ActionIdentifiers actionIdentifiers = executionServiceInput.getActionIdentifiers(); + + /** + * the fields of actionIdentifiers should match the one in the + * response/createVcpeResCustServiceSimplifiedTest_catalogdb.json. + */ + assertThat(actionIdentifiers.getBlueprintName()).isEqualTo(TEST_PNF_RESOURCE_BLUEPRINT_NAME); + assertThat(actionIdentifiers.getBlueprintVersion()).isEqualTo(TEST_PNF_RESOURCE_BLUEPRINT_VERSION); + assertThat(actionIdentifiers.getActionName()).isEqualTo(TEST_CDS_ACTION); + assertThat(actionIdentifiers.getMode()).isEqualTo("sync"); + + CommonHeader commonHeader = executionServiceInput.getCommonHeader(); + assertThat(commonHeader.getOriginatorId()).isEqualTo("SO"); + assertThat(commonHeader.getRequestId()).isEqualTo(TEST_MSO_REQUEST_ID); + + Struct payload = executionServiceInput.getPayload(); + Struct requeststruct = payload.getFieldsOrThrow("config-assign-request").getStructValue(); + + assertThat(requeststruct.getFieldsOrThrow("resolution-key").getStringValue()) + .isEqualTo(TEST_PNF_CORRELATION_ID); + Struct propertiesStruct = requeststruct.getFieldsOrThrow("config-assign-properties").getStructValue(); + + assertThat(propertiesStruct.getFieldsOrThrow("pnf-name").getStringValue()).isEqualTo(TEST_PNF_CORRELATION_ID); + assertThat(propertiesStruct.getFieldsOrThrow("service-model-uuid").getStringValue()).isEqualTo(TEST_MODEL_UUID); + assertThat(propertiesStruct.getFieldsOrThrow("pnf-customization-uuid").getStringValue()) + .isEqualTo(TEST_PNF_RESOURCE_CUSTOMIZATION_UUID); + } + +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/MockControllerDE.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/MockControllerDE.java new file mode 100644 index 0000000000..c66fefdffe --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/MockControllerDE.java @@ -0,0 +1,55 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 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.bpmn.infrastructure.decisionpoint.impl.camunda; + +import org.camunda.bpm.engine.delegate.DelegateExecution; +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.springframework.stereotype.Component; + +@Component +public class MockControllerDE implements ControllerRunnable { + + public static final String TEST_ACTOR = "test-controller"; + public static final String TEST_ACTION = "configuration"; + + @Override + public Boolean understand(ControllerContext context) { + return context.getControllerAction().equalsIgnoreCase(TEST_ACTION) + && context.getControllerActor().equalsIgnoreCase(TEST_ACTOR); + } + + @Override + public Boolean ready(ControllerContext context) { + context.getExecution().setVariable("ready", true); + return true; + } + + @Override + public void prepare(ControllerContext context) { + context.getExecution().setVariable("prepare", true); + } + + @Override + public void run(ControllerContext context) { + context.getExecution().setVariable("run", true); + } +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/controller/appc/AppcControllerDETest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/controller/appc/AppcControllerDETest.java new file mode 100644 index 0000000000..3b7a863cd3 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/controller/appc/AppcControllerDETest.java @@ -0,0 +1,69 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 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.bpmn.infrastructure.decisionpoint.impl.camunda.controller.appc; + +import static junit.framework.TestCase.assertTrue; +import static org.junit.Assert.assertFalse; +import static org.mockito.Mockito.when; +import org.camunda.bpm.engine.delegate.DelegateExecution; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.so.bpmn.infrastructure.decisionpoint.api.ControllerContext; +import org.onap.so.bpmn.infrastructure.decisionpoint.api.controller.ControllerPreparable; +import org.onap.so.client.appc.ApplicationControllerAction; +import org.onap.so.client.exception.ExceptionBuilder; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = {AppcControllerDE.class, ExceptionBuilder.class}) +public class AppcControllerDETest { + + @Autowired + private AppcControllerDE appcControllerDE; + + @MockBean + private ControllerContext controllerContext; + + @MockBean + private ControllerPreparable preparable; + + @MockBean + protected ApplicationControllerAction client; + + @Before + public void setUp() { + when(controllerContext.getControllerActor()).thenReturn("appc"); + } + + @Test + public void testUnderstand_validContext_TrueReturned() { + assertTrue(appcControllerDE.understand(controllerContext)); + } + + @Test + public void testUnderstand_invalidContext_FalseReturned() { + when(controllerContext.getControllerActor()).thenReturn("sdnc"); + assertFalse(appcControllerDE.understand(controllerContext)); + } +} 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 new file mode 100644 index 0000000000..79bce8a1f4 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/controller/cds/CdsControllerDETest.java @@ -0,0 +1,66 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 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.bpmn.infrastructure.decisionpoint.impl.camunda.controller.cds; + +import static junit.framework.TestCase.assertTrue; +import static org.junit.Assert.assertFalse; +import static org.mockito.Mockito.when; +import org.camunda.bpm.engine.delegate.DelegateExecution; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.so.bpmn.infrastructure.decisionpoint.api.ControllerContext; +import org.onap.so.bpmn.infrastructure.decisionpoint.api.controller.ControllerPreparable; +import org.onap.so.client.exception.ExceptionBuilder; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = {CdsControllerDE.class, ExceptionBuilder.class}) +public class CdsControllerDETest { + + @Autowired + private CdsControllerDE cdsControllerDE; + + @MockBean + private ControllerContext controllerContext; + + @MockBean + private ControllerPreparable preparable; + + @Before + public void setUp() { + when(controllerContext.getControllerActor()).thenReturn("cds"); + } + + @Test + public void testUnderstand_validContext_TrueReturned() { + assertTrue(cdsControllerDE.understand(controllerContext)); + } + + @Test + public void testUnderstand_invalidContext_FalseReturned() { + when(controllerContext.getControllerActor()).thenReturn("appc"); + assertFalse(cdsControllerDE.understand(controllerContext)); + } + +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/controller/sdnc/SdncControllerDETest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/controller/sdnc/SdncControllerDETest.java new file mode 100644 index 0000000000..674167624e --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/controller/sdnc/SdncControllerDETest.java @@ -0,0 +1,69 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 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.bpmn.infrastructure.decisionpoint.impl.camunda.controller.sdnc; + +import static junit.framework.TestCase.assertTrue; +import static org.junit.Assert.assertFalse; +import static org.mockito.Mockito.when; +import org.camunda.bpm.engine.delegate.DelegateExecution; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.so.bpmn.infrastructure.decisionpoint.api.ControllerContext; +import org.onap.so.bpmn.infrastructure.decisionpoint.api.controller.ControllerPreparable; +import org.onap.so.client.appc.ApplicationControllerAction; +import org.onap.so.client.exception.ExceptionBuilder; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = {SdncControllerDE.class, ExceptionBuilder.class}) +public class SdncControllerDETest { + + @Autowired + private SdncControllerDE sdncControllerDE; + + @MockBean + private ControllerContext controllerContext; + + @MockBean + private ControllerPreparable preparable; + + @MockBean + protected ApplicationControllerAction client; + + @Before + public void setUp() { + when(controllerContext.getControllerActor()).thenReturn("sdnc"); + } + + @Test + public void testUnderstand_validContext_TrueReturned() { + assertTrue(sdncControllerDE.understand(controllerContext)); + } + + @Test + public void testUnderstand_invalidContext_FalseReturned() { + when(controllerContext.getControllerActor()).thenReturn("cds"); + assertFalse(sdncControllerDE.understand(controllerContext)); + } +} diff --git a/bpmn/so-bpmn-tasks/src/test/resources/application-test.yaml b/bpmn/so-bpmn-tasks/src/test/resources/application-test.yaml index fed2aa69c7..199274e94c 100644 --- a/bpmn/so-bpmn-tasks/src/test/resources/application-test.yaml +++ b/bpmn/so-bpmn-tasks/src/test/resources/application-test.yaml @@ -215,3 +215,9 @@ camunda: metrics: enabled: false db-reporter-activate: false +# CDSProcessingClient +cds: + endpoint: localhost + port: 11012 + auth: Basic Y2NzZGthcHBzOmNjc2RrYXBwcw== + timeout: 60 -- cgit 1.2.3-korg