From 44ffcde54cb7d832232a32fe7a60b4849bef447a Mon Sep 17 00:00:00 2001 From: tragait Date: Fri, 4 Sep 2020 13:34:35 +0100 Subject: multiple pnf fix Signed-off-by: tragait Change-Id: I3d9d0ebb38da1fb286f097828551e981a0f95a65 Signed-off-by: tragait Issue-ID: SO-3223 Signed-off-by: tragait --- .../infrastructure/service/level/ServiceLevel.java | 119 +++++++++++++++++++++ .../service/level/ServiceLevelPreparable.java | 98 ----------------- .../service/level/impl/ServiceLevelConstants.java | 4 + .../service/level/impl/ServiceLevelPostcheck.java | 2 +- .../level/impl/ServiceLevelPreparation.java | 10 +- .../level/impl/ServiceLevelRequestDispatcher.java | 22 ++-- .../service/level/impl/ServiceLevelUpgrade.java | 12 ++- 7 files changed, 151 insertions(+), 116 deletions(-) create mode 100644 bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/ServiceLevel.java delete mode 100644 bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/ServiceLevelPreparable.java (limited to 'bpmn/so-bpmn-tasks') diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/ServiceLevel.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/ServiceLevel.java new file mode 100644 index 0000000000..b8f5ec9674 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/ServiceLevel.java @@ -0,0 +1,119 @@ +/*- + * ============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 java.util.ArrayList; +import java.util.List; +import java.util.Optional; +import jline.internal.Log; +import org.camunda.bpm.engine.delegate.DelegateExecution; +import org.onap.so.bpmn.infrastructure.service.level.impl.ServiceLevelConstants; +import org.onap.so.client.exception.ExceptionBuilder; +import org.onap.so.db.catalog.beans.Workflow; +import org.onap.so.db.catalog.client.CatalogDbClient; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; + +/** + * Parent class for Service level upgrade Execution, it should be extended for service level upgrade tasks. + */ +public class ServiceLevel { + + protected static final Logger LOG = LoggerFactory.getLogger(ServiceLevel.class); + + @Autowired + protected ExceptionBuilder exceptionBuilder; + + @Autowired + protected CatalogDbClient catalogDbClient; + + private static final String PNF_NAME_LIST = "pnfNameList"; + + private static final String PNF_COUNTER = "pnfCounter"; + + /** + * Fetches workflow names based on the controller scope and operation name. + * + * @param scope Controller scope + * @param operationName healthcheck/softwareUpgrade + * @return String value of Workflow name + */ + protected String fetchWorkflowUsingScope(final String scope, String operationName) { + Optional wflName = Optional.empty(); + try { + List workflows = catalogDbClient.findWorkflowByOperationName(operationName); + if (!workflows.isEmpty()) { + wflName = Optional.ofNullable( + workflows.stream().filter(workflow -> workflow.getResourceTarget().equalsIgnoreCase(scope)) + .findFirst().get().getName()); + } + } catch (Exception e) { + // do nothing and assign the default workflow in finally + LOG.error("Error occurred while fetching workflow name from CatalogDb {}", e); + } finally { + if (wflName.isEmpty()) { + wflName = Optional.of(ServiceLevelConstants.WORKFLOW_OPERATIONS_MAP.get(operationName).get(scope)); + } + } + return wflName.get(); + + } + + /** + * 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 params) { + List 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, ServiceLevelConstants.ERROR_CODE, + "Validation of health check workflow parameters failed for the scope: " + scope); + } + + } + + /** + * This method set correct value of pnf name for health check and software upgrade workflow. + * + * @param delegateExecution Delegate execution obj + */ + public void pnfCounterExecution(DelegateExecution delegateExecution) { + LOG.debug("Running execute block for activity id: {}, name: {}", delegateExecution.getCurrentActivityId(), + delegateExecution.getCurrentActivityName()); + + final List pnfNameList = (List) delegateExecution.getVariable(PNF_NAME_LIST); + final int pnfCounter = (int) delegateExecution.getVariable(PNF_COUNTER); + + delegateExecution.setVariable(ServiceLevelConstants.PNF_NAME, pnfNameList.get(pnfCounter)); + delegateExecution.setVariable(PNF_COUNTER, pnfCounter + 1); + } + +} diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/ServiceLevelPreparable.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/ServiceLevelPreparable.java deleted file mode 100644 index e26195158d..0000000000 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/ServiceLevelPreparable.java +++ /dev/null @@ -1,98 +0,0 @@ -/*- - * ============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 java.util.ArrayList; -import java.util.List; -import java.util.Optional; -import org.camunda.bpm.engine.delegate.DelegateExecution; -import org.onap.so.bpmn.infrastructure.service.level.impl.ServiceLevelConstants; -import org.onap.so.client.exception.ExceptionBuilder; -import org.onap.so.db.catalog.beans.Workflow; -import org.onap.so.db.catalog.client.CatalogDbClient; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; - -/** - * Parent class for Service level upgrade Execution, it should be extended for service level upgrade tasks. - */ -public class ServiceLevelPreparable { - - protected static final Logger LOG = LoggerFactory.getLogger(ServiceLevelPreparable.class); - - @Autowired - protected ExceptionBuilder exceptionBuilder; - - @Autowired - protected CatalogDbClient catalogDbClient; - - /** - * Fetches workflow names based on the controller scope and operation name. - * - * @param scope Controller scope - * @param operationName healthcheck/softwareUpgrade - * @return String value of Workflow name - */ - protected String fetchWorkflowUsingScope(final String scope, String operationName) { - Optional wflName = Optional.empty(); - try { - List workflows = catalogDbClient.findWorkflowByOperationName(operationName); - if (!workflows.isEmpty()) { - wflName = Optional.ofNullable( - workflows.stream().filter(workflow -> workflow.getResourceTarget().equalsIgnoreCase(scope)) - .findFirst().get().getName()); - } - } catch (Exception e) { - // do nothing and assign the default workflow in finally - LOG.error("Error occurred while fetching workflow name from CatalogDb {}", e); - } finally { - if (wflName.isEmpty()) { - wflName = Optional.of(ServiceLevelConstants.WORKFLOW_OPERATIONS_MAP.get(operationName).get(scope)); - } - } - return wflName.get(); - - } - - /** - * 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 params) { - List 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, ServiceLevelConstants.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/ServiceLevelConstants.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/impl/ServiceLevelConstants.java index 7b73fff20c..b0b12b5276 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/impl/ServiceLevelConstants.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/impl/ServiceLevelConstants.java @@ -38,6 +38,10 @@ public class ServiceLevelConstants { public static final String SW_UP_OPERATION = "ResourceSoftwareUpgrade"; public static final String CONTROLLER_STATUS = "ControllerStatus"; public static final int ERROR_CODE = 601; + public static final String PNF_COUNTER = "pnfCounter"; + public static final int COUNT_ZERO = 0; + public static final String PNF_NAME_LIST = "pnfNameList"; + public static final String PNF_SIZE = "pnfSize"; // TODO GenericVNFHealthCheck and GenericVnfSoftwareUpgrade workflow names should be updated once the workflow is // implemented. diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/impl/ServiceLevelPostcheck.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/impl/ServiceLevelPostcheck.java index fad28e315e..8e720c3e53 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/impl/ServiceLevelPostcheck.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/impl/ServiceLevelPostcheck.java @@ -8,6 +8,6 @@ import org.springframework.stereotype.Component; public class ServiceLevelPostcheck implements JavaDelegate { @Override public void execute(DelegateExecution delegateExecution) throws Exception { - // TODO : Set serviceInstance to aai + // Write your postcheck operations here, if any } } 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 index 59884ecbc2..6cb3461001 100644 --- 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 @@ -26,7 +26,7 @@ import java.util.List; import java.util.Map; import org.camunda.bpm.engine.delegate.DelegateExecution; import org.camunda.bpm.engine.delegate.JavaDelegate; -import org.onap.so.bpmn.infrastructure.service.level.ServiceLevelPreparable; +import org.onap.so.bpmn.infrastructure.service.level.ServiceLevel; import org.springframework.stereotype.Component; @@ -35,10 +35,10 @@ import org.springframework.stereotype.Component; * validation. */ @Component("ServiceLevelPreparation") -public class ServiceLevelPreparation extends ServiceLevelPreparable implements JavaDelegate { +public class ServiceLevelPreparation extends ServiceLevel implements JavaDelegate { private static final List PNF_HEALTH_CHECK_PARAMS = Arrays.asList(ServiceLevelConstants.SERVICE_INSTANCE_ID, - ServiceLevelConstants.RESOURCE_TYPE, ServiceLevelConstants.BPMN_REQUEST, ServiceLevelConstants.PNF_NAME); + ServiceLevelConstants.RESOURCE_TYPE, ServiceLevelConstants.BPMN_REQUEST); // TODO Update the list with vnf health check parameters if any validation needed private static final List VNF_HEALTH_CHECK_PARAMS = Collections.emptyList(); @@ -48,6 +48,9 @@ public class ServiceLevelPreparation extends ServiceLevelPreparable implements J @Override public void execute(DelegateExecution execution) throws Exception { + LOG.debug("Running execute block for activity id: {}, name: {}", execution.getCurrentActivityId(), + execution.getCurrentActivityName()); + if (execution.hasVariable(ServiceLevelConstants.RESOURCE_TYPE) && execution.getVariable(ServiceLevelConstants.RESOURCE_TYPE) != null) { final String controllerScope = (String) execution.getVariable(ServiceLevelConstants.RESOURCE_TYPE); @@ -60,6 +63,7 @@ public class ServiceLevelPreparation extends ServiceLevelPreparable implements J LOG.info("Parameters validated successfully for {}", wflName); execution.setVariable(ServiceLevelConstants.HEALTH_CHECK_WORKFLOW_TO_INVOKE, wflName); execution.setVariable(ServiceLevelConstants.CONTROLLER_STATUS, ServiceLevelConstants.EMPTY_STRING); + execution.setVariable(ServiceLevelConstants.PNF_COUNTER, ServiceLevelConstants.COUNT_ZERO); } else { exceptionBuilder.buildAndThrowWorkflowException(execution, ServiceLevelConstants.ERROR_CODE, "Invalid Controller scope to prepare resource level health check"); diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/impl/ServiceLevelRequestDispatcher.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/impl/ServiceLevelRequestDispatcher.java index 5b20a86cb7..5d9295dc95 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/impl/ServiceLevelRequestDispatcher.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/impl/ServiceLevelRequestDispatcher.java @@ -23,6 +23,7 @@ package org.onap.so.bpmn.infrastructure.service.level.impl; import com.fasterxml.jackson.databind.ObjectMapper; import org.camunda.bpm.engine.delegate.DelegateExecution; import org.camunda.bpm.engine.delegate.JavaDelegate; +import org.onap.aai.domain.yang.Relationship; import org.onap.aai.domain.yang.ServiceInstance; import org.onap.aaiclient.client.aai.AAIRestClientI; import org.onap.aaiclient.client.aai.AAIRestClientImpl; @@ -34,7 +35,11 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.io.IOException; +import java.util.ArrayList; +import java.util.List; import java.util.Optional; +import java.util.stream.Collector; +import java.util.stream.Collectors; import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.*; /** @@ -83,21 +88,18 @@ public class ServiceLevelRequestDispatcher implements JavaDelegate { Optional optionalSi = restClient.getServiceInstanceById(serviceInstanceId, serviceType, globalSubscriberId); - if (!optionalSi.isPresent()) { - - } - optionalSi.ifPresentOrElse(serviceInstance -> { - final String pnfName = serviceInstance.getRelationshipList().getRelationship().stream() - .filter(x -> x.getRelatedTo().contains("pnf")).findFirst().get().getRelationshipData().stream() - .filter(data -> data.getRelationshipKey().contains("pnf.pnf-name")).findFirst().get() - .getRelationshipValue(); - if (pnfName == null || pnfName.isEmpty()) { + final List pnfNameList = serviceInstance.getRelationshipList().getRelationship().stream() + .filter(x -> x.getRelatedTo().contains("pnf")).flatMap(x -> x.getRelationshipData().stream()) + .filter(data -> data.getRelationshipKey().contains("pnf.pnf-name")) + .map(x -> x.getRelationshipValue()).collect(Collectors.toList()); + if (pnfNameList == null || pnfNameList.size() == 0) { logger.warn( "Unable to find the PNF for service instance id: " + serviceInstance.getServiceInstanceId()); return; } - delegateExecution.setVariable(ServiceLevelConstants.PNF_NAME, pnfName); + delegateExecution.setVariable(ServiceLevelConstants.PNF_NAME_LIST, pnfNameList); + delegateExecution.setVariable(ServiceLevelConstants.PNF_SIZE, pnfNameList.size()); delegateExecution.setVariable(ServiceLevelConstants.RESOURCE_TYPE, ServiceLevelConstants.PNF); }, () -> { throwExceptionWithWarn(delegateExecution, "Unable to find the service instance: " + serviceInstanceId); diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/impl/ServiceLevelUpgrade.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/impl/ServiceLevelUpgrade.java index 9d7d8efb65..a3a8f6e714 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/impl/ServiceLevelUpgrade.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/impl/ServiceLevelUpgrade.java @@ -26,14 +26,14 @@ import java.util.List; import java.util.Map; import org.camunda.bpm.engine.delegate.DelegateExecution; import org.camunda.bpm.engine.delegate.JavaDelegate; -import org.onap.so.bpmn.infrastructure.service.level.ServiceLevelPreparable; +import org.onap.so.bpmn.infrastructure.service.level.ServiceLevel; import org.springframework.stereotype.Component; @Component -public class ServiceLevelUpgrade extends ServiceLevelPreparable implements JavaDelegate { +public class ServiceLevelUpgrade extends ServiceLevel implements JavaDelegate { private static final List PNF_SOFTWARE_UP_PARAMS = Arrays.asList(ServiceLevelConstants.SERVICE_INSTANCE_ID, - ServiceLevelConstants.RESOURCE_TYPE, ServiceLevelConstants.BPMN_REQUEST, ServiceLevelConstants.PNF_NAME); + ServiceLevelConstants.RESOURCE_TYPE, ServiceLevelConstants.BPMN_REQUEST); // TODO Update the list with vnf software upgrade parameters if any validation needed private static final List VNF_SOFTWARE_UP_PARAMS = Collections.emptyList(); @@ -44,6 +44,9 @@ public class ServiceLevelUpgrade extends ServiceLevelPreparable implements JavaD @Override public void execute(DelegateExecution execution) throws Exception { + LOG.debug("Running execute block for activity id: {}, name: {}", execution.getCurrentActivityId(), + execution.getCurrentActivityName()); + if (execution.hasVariable(ServiceLevelConstants.RESOURCE_TYPE) && execution.getVariable(ServiceLevelConstants.RESOURCE_TYPE) != null) { final String controllerScope = (String) execution.getVariable(ServiceLevelConstants.RESOURCE_TYPE); @@ -54,7 +57,8 @@ public class ServiceLevelUpgrade extends ServiceLevelPreparable implements JavaD validateParamsWithScope(execution, controllerScope, SOFTWARE_UP_PARAMS_MAP.get(controllerScope)); LOG.info("Parameters validated successfully for {}", wflName); execution.setVariable(ServiceLevelConstants.SOFTWARE_WORKFLOW_TO_INVOKE, wflName); - execution.setVariable(ServiceLevelConstants.CONTROLLER_STATUS, ""); + execution.setVariable(ServiceLevelConstants.CONTROLLER_STATUS, ServiceLevelConstants.EMPTY_STRING); + execution.setVariable(ServiceLevelConstants.PNF_COUNTER, ServiceLevelConstants.COUNT_ZERO); } else { exceptionBuilder.buildAndThrowWorkflowException(execution, ServiceLevelConstants.ERROR_CODE, "Invalid Controller scope for resource level software upgrade"); -- cgit 1.2.3-korg