summaryrefslogtreecommitdiffstats
path: root/bpmn/so-bpmn-tasks/src/main/java
diff options
context:
space:
mode:
authorByung-Woo Jun <byung-woo.jun@est.tech>2020-08-05 13:21:40 +0000
committerGerrit Code Review <gerrit@onap.org>2020-08-05 13:21:40 +0000
commit14b7e6971d6c0a9279b8e9b278861821553081fd (patch)
tree13c6897009f277e1c05490b3ff2a13934f098cd6 /bpmn/so-bpmn-tasks/src/main/java
parent0c496d47c9084f9cc062f4b1353d420e96924d73 (diff)
parentfeb5d0d4d4ba80857b059776d5e85049a10fa34e (diff)
Merge "Delegate class for service level preparation BB"
Diffstat (limited to 'bpmn/so-bpmn-tasks/src/main/java')
-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
2 files changed, 158 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;
+ }
+
+}