aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/AbstractServiceLevelPreparable.java81
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/impl/ServiceLevelPreparation.java77
-rw-r--r--bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/service/level/ServiceLevelPreparationTest.java130
3 files changed, 288 insertions, 0 deletions
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/AbstractServiceLevelPreparable.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/AbstractServiceLevelPreparable.java
new file mode 100644
index 0000000000..36db549486
--- /dev/null
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/AbstractServiceLevelPreparable.java
@@ -0,0 +1,81 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 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
+ *
+ * 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.service.level;
+
+import org.camunda.bpm.engine.delegate.DelegateExecution;
+import org.onap.so.client.exception.ExceptionBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Abstract class for Service level upgrade Execution, it should be extended for service level upgrade tasks.
+ */
+public abstract class AbstractServiceLevelPreparable {
+
+ protected static final String WORKFLOW_TO_INVOKE = "healthCheckWorkflow";
+ protected static final String GENERIC_PNF_HEALTH_CHECK_WORKFLOW = "GenericPnfHealthCheck";
+ protected static final String GENERIC_PNF_SOFTWARE_UPGRADE_WORKFLOW = "GenericPnfSoftwareUpgrade";
+ protected static final String RESOURCE_TYPE = "RESOURCE_TYPE";
+ protected static final int ERROR_CODE = 601;
+
+ // TODO This value needs to be updated once vnf health check workflow is available
+ protected static final String GENERIC_VNF_HEALTH_CHECK_WORKFLOW = "GenericVNFHealthCheck";
+
+ protected static final Logger LOG = LoggerFactory.getLogger(AbstractServiceLevelPreparable.class);
+
+ @Autowired
+ protected ExceptionBuilder exceptionBuilder;
+
+ /**
+ * This method fetches workflow names to be invoked based on the controller scope .
+ *
+ * @param scope Controller scope
+ * @return String value of Workflow name
+ */
+ protected abstract String fetchWorkflowUsingScope(DelegateExecution execution, final String scope);
+
+ /**
+ * This method validates the execution parameters to be passed for health check workflow.
+ *
+ * @param execution Delegate execution obj
+ * @param scope Controller scope * Throws workflow exception if validation fails
+ */
+ protected void validateParamsWithScope(DelegateExecution execution, final String scope, List<String> params)
+ throws Exception {
+ List<String> invalidVariables = new ArrayList<>();
+ for (String param : params) {
+ if (!execution.hasVariable(param) || execution.getVariable(param) == null
+ || String.valueOf(execution.getVariable(param)).isEmpty()) {
+ invalidVariables.add(param);
+ }
+ }
+ if (invalidVariables.size() > 0) {
+ LOG.error("Validation error for the {} health check attributes: {}", scope, invalidVariables);
+ exceptionBuilder.buildAndThrowWorkflowException(execution, ERROR_CODE,
+ "Validation of health check workflow parameters failed for the scope: " + scope);
+ }
+
+ }
+
+}
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/impl/ServiceLevelPreparation.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/impl/ServiceLevelPreparation.java
new file mode 100644
index 0000000000..52521ce16b
--- /dev/null
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/impl/ServiceLevelPreparation.java
@@ -0,0 +1,77 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 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
+ *
+ * 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.service.level.impl;
+
+import org.camunda.bpm.engine.delegate.DelegateExecution;
+import org.camunda.bpm.engine.delegate.JavaDelegate;
+import org.onap.so.bpmn.infrastructure.service.level.AbstractServiceLevelPreparable;
+import org.springframework.stereotype.Component;
+import java.util.Arrays;
+import java.util.List;
+
+
+/**
+ * Fetches health check workflow based on the controller_scope. Invoke the corresponding health check workflow after
+ * validation.
+ */
+@Component("ServiceLevelPreparation")
+public class ServiceLevelPreparation extends AbstractServiceLevelPreparable implements JavaDelegate {
+
+ // Health check parameters to be validated for pnf resource
+ private static final List<String> PNF_HC_PARAMS = Arrays.asList("SERVICE_MODEL_INFO", "SERVICE_INSTANCE_NAME",
+ "PNF_CORRELATION_ID", "MODEL_UUID", "PNF_UUID", "PRC_BLUEPRINT_NAME", "PRC_BLUEPRINT_VERSION",
+ "PRC_CUSTOMIZATION_UUID", "RESOURCE_CUSTOMIZATION_UUID_PARAM", "PRC_INSTANCE_NAME", "PRC_CONTROLLER_ACTOR",
+ "REQUEST_PAYLOAD");
+
+ @Override
+ public void execute(DelegateExecution execution) throws Exception {
+ if (execution.hasVariable(RESOURCE_TYPE) && execution.getVariable(RESOURCE_TYPE) != null) {
+ final String controllerScope = (String) execution.getVariable(RESOURCE_TYPE);
+ LOG.debug("Scope retrieved from delegate execution: " + controllerScope);
+ final String wflName = fetchWorkflowUsingScope(execution, controllerScope);
+ LOG.debug("Health check workflow fetched for the scope: {}", wflName);
+ validateParamsWithScope(execution, controllerScope, PNF_HC_PARAMS);
+ LOG.info("Parameters validated successfully for {}", wflName);
+ execution.setVariable(WORKFLOW_TO_INVOKE, wflName);
+ } else {
+ exceptionBuilder.buildAndThrowWorkflowException(execution, ERROR_CODE,
+ "Controller scope not found to invoke resource level health check");
+ }
+ }
+
+ @Override
+ public String fetchWorkflowUsingScope(DelegateExecution execution, final String scope) {
+ String wflName = null;
+ switch (scope.toLowerCase()) {
+ case "pnf":
+ wflName = GENERIC_PNF_HEALTH_CHECK_WORKFLOW;
+ break;
+ case "vnf":
+ wflName = GENERIC_VNF_HEALTH_CHECK_WORKFLOW;
+ break;
+ default:
+ exceptionBuilder.buildAndThrowWorkflowException(execution, ERROR_CODE,
+ "No valid health check work flow retrieved for the scope: " + scope);
+ }
+ return wflName;
+ }
+
+}
diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/service/level/ServiceLevelPreparationTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/service/level/ServiceLevelPreparationTest.java
new file mode 100644
index 0000000000..a99ee7d2df
--- /dev/null
+++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/service/level/ServiceLevelPreparationTest.java
@@ -0,0 +1,130 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 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
+ *
+ * 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.service.level;
+
+import org.camunda.bpm.engine.delegate.BpmnError;
+import org.camunda.bpm.engine.delegate.DelegateExecution;
+import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.junit.runner.RunWith;
+import org.onap.so.bpmn.infrastructure.service.level.impl.ServiceLevelPreparation;
+import org.onap.so.client.exception.ExceptionBuilder;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.onap.so.bpmn.infrastructure.service.level.AbstractServiceLevelPreparable.RESOURCE_TYPE;
+import static org.onap.so.bpmn.infrastructure.service.level.AbstractServiceLevelPreparable.WORKFLOW_TO_INVOKE;
+
+
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(classes = {ServiceLevelPreparation.class, ExceptionBuilder.class})
+public class ServiceLevelPreparationTest {
+
+ private static final String TEST_PNF_SCOPE = "pnf";
+ private static final String TEST_PROCESS_KEY = "testProcessKey";
+ private static final String PROCESS_KEY_VALUE = "testProcessKeyValue";
+ private static final List<String> PNF_HEALTH_CHECK_PARAMS = Arrays.asList("SERVICE_MODEL_INFO",
+ "SERVICE_INSTANCE_NAME", "PNF_CORRELATION_ID", "MODEL_UUID", "PNF_UUID", "PRC_BLUEPRINT_NAME",
+ "PRC_BLUEPRINT_VERSION", "PRC_CUSTOMIZATION_UUID", "RESOURCE_CUSTOMIZATION_UUID_PARAM", "PRC_INSTANCE_NAME",
+ "PRC_CONTROLLER_ACTOR", "REQUEST_PAYLOAD");
+ private Map<String, String> pnfHealthCheckTestParams = new HashMap<>();
+
+ @Autowired
+ private ServiceLevelPreparation serviceLevelPrepare;
+
+ @Autowired
+ private ExceptionBuilder exceptionBuilder;
+
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ private DelegateExecution execution = new DelegateExecutionFake();
+ private DelegateExecution invalidExecution = new DelegateExecutionFake();
+
+
+ @Before
+ public void setUpPnfUpgradeTest() {
+ pnfHealthCheckTestParams.put("TEST_SERVICE_MODEL_INFO", "d4c6855e-3be2-5dtu-9390-c999a38829bc");
+ pnfHealthCheckTestParams.put("TEST_SERVICE_INSTANCE_NAME", "test_service_id");
+ pnfHealthCheckTestParams.put("TEST_PNF_CORRELATION_ID", "pnfCorrelationId");
+ pnfHealthCheckTestParams.put("TEST_MODEL_UUID", "6bc0b04d-1873-4721-b53d-6615225b2a28");
+ pnfHealthCheckTestParams.put("TEST_PNF_UUID", "c93g70d9-8de3-57f1-7de1-f5690ac2b005");
+ pnfHealthCheckTestParams.put("TEST_PRC_BLUEPRINT_NAME", "serviceUpgrade");
+ pnfHealthCheckTestParams.put("TEST_PRC_BLUEPRINT_VERSION", "1.0.2");
+ pnfHealthCheckTestParams.put("TEST_PRC_CUSTOMIZATION_UUID", "PRC_customizationUuid");
+ pnfHealthCheckTestParams.put("TEST_RESOURCE_CUSTOMIZATION_UUID_PARAM", "9acb3a83-8a52-412c-9a45-901764938144");
+ pnfHealthCheckTestParams.put("TEST_PRC_INSTANCE_NAME", "Demo_pnf");
+ pnfHealthCheckTestParams.put("TEST_PRC_CONTROLLER_ACTOR", "cds");
+ pnfHealthCheckTestParams.put("TEST_REQUEST_PAYLOAD", "test_payload");
+
+ for (String param : PNF_HEALTH_CHECK_PARAMS) {
+ execution.setVariable(param, pnfHealthCheckTestParams.get("TEST_" + param));
+ }
+ execution.setVariable(RESOURCE_TYPE, TEST_PNF_SCOPE);
+ execution.setVariable(TEST_PROCESS_KEY, PROCESS_KEY_VALUE);
+
+ invalidExecution.setVariables(execution.getVariables());
+ }
+
+ @Test
+ public void executePnfUpgradeSuccessTest() throws Exception {
+ serviceLevelPrepare.execute(execution);
+ // Expect the pnf health check workflow to be set in to execution if validation is successful
+ assertThat(String.valueOf(execution.getVariable(WORKFLOW_TO_INVOKE))).isEqualTo("GenericPnfHealthCheck");
+ }
+
+ @Test
+ public void validateFailureParamsForPnfTest() throws Exception {
+ invalidExecution.removeVariable("PNF_UUID");
+ invalidExecution.setVariable("PRC_BLUEPRINT_NAME", null);
+ // BPMN exception is thrown in case of validation failure or invalid execution
+ thrown.expect(BpmnError.class);
+ serviceLevelPrepare.validateParamsWithScope(invalidExecution, TEST_PNF_SCOPE, PNF_HEALTH_CHECK_PARAMS);
+ }
+
+ @Test
+ public void invalidScopeExecuteTest() throws Exception {
+ invalidExecution.setVariable(RESOURCE_TYPE, "InvalidResource");
+ // BPMN workflow exception is expected incase of invalid resource type other than pnf/vnf
+ thrown.expect(BpmnError.class);
+ serviceLevelPrepare.execute(invalidExecution);
+ }
+
+ @Test
+ public void invokeServiceLevelPrepareWithoutScope() throws Exception {
+ invalidExecution.removeVariable(RESOURCE_TYPE);
+ thrown.expect(BpmnError.class);
+ serviceLevelPrepare.execute(invalidExecution);
+
+ }
+
+}
+
+