diff options
Diffstat (limited to 'bpmn/so-bpmn-tasks/src')
20 files changed, 957 insertions, 125 deletions
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnf/tasks/CnfAdapter.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnf/tasks/CnfAdapter.java new file mode 100644 index 0000000000..c21b467a95 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnf/tasks/CnfAdapter.java @@ -0,0 +1,36 @@ +package org.onap.so.bpmn.infrastructure.adapter.cnf.tasks; + +import java.io.IOException; +import org.camunda.bpm.engine.delegate.DelegateExecution; +import org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowAction; +import org.onap.so.client.adapter.cnf.CnfAdapterClient; +import org.onap.so.client.adapter.cnf.CnfAdapterClientException; +import org.onap.so.client.adapter.cnf.entities.InstanceRequest; +import org.onap.so.client.adapter.cnf.entities.InstanceResponse; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; + +@Component +public class CnfAdapter { + + @Autowired + private CnfAdapterClient cnfAdapterClient; + + private static final Logger logger = LoggerFactory.getLogger(CnfAdapter.class); + + public void callCnfAdapter(DelegateExecution execution) throws Exception { + try { + final String instanceRequest = (String) execution.getVariable("instanceRequest"); + InstanceRequest request = new ObjectMapper().readValue(instanceRequest, InstanceRequest.class); + InstanceResponse response = cnfAdapterClient.createVfModule(request); + } catch (Exception ex) { + logger.error("Exception in callCnfAdapter", ex); + throw ex; + } + } +} diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnf/tasks/CnfAdapterCreateTasks.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnf/tasks/CnfAdapterCreateTasks.java new file mode 100644 index 0000000000..93d30512b6 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnf/tasks/CnfAdapterCreateTasks.java @@ -0,0 +1,121 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Modifications Copyright (c) 2019 Samsung + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.bpmn.infrastructure.adapter.cnf.tasks; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion; +import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; +import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; +import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule; +import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock; +import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; +import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext; +import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB; +import org.onap.so.client.adapter.cnf.CnfAdapterClient; +import org.onap.so.client.adapter.cnf.entities.InstanceRequest; +import org.onap.so.client.adapter.cnf.entities.InstanceResponse; +import org.onap.so.client.adapter.vnf.mapper.AttributeNameValue; +import org.onap.so.client.adapter.vnf.mapper.Attributes; +import org.onap.so.client.adapter.vnf.mapper.VnfAdapterVfModuleObjectMapper; +import org.onap.so.client.exception.ExceptionBuilder; +import org.onap.so.openstack.utils.MsoMulticloudUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; + +@Component +public class CnfAdapterCreateTasks { + private static final Logger logger = LoggerFactory.getLogger(CnfAdapterCreateTasks.class); + public static final String SDNCQUERY_RESPONSE = "SDNCQueryResponse_"; + + @Autowired + private ExtractPojosForBB extractPojosForBB; + @Autowired + private ExceptionBuilder exceptionUtil; + @Autowired + private CnfAdapterClient cnfAdapterClient; + @Autowired + private VnfAdapterVfModuleObjectMapper vfModuleMapper; + + private ObjectMapper mapper = new ObjectMapper(); + + /** + * This method is used for creating the request for an Instance in Multicloud K8s Plugin. + * + * @param execution + * @return + */ + public void createInstance(BuildingBlockExecution execution) { + try { + GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock(); + ServiceInstance serviceInstance = + gBBInput.getCustomer().getServiceSubscription().getServiceInstances().get(0); + GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID); + VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID); + RequestContext requestContext = gBBInput.getRequestContext(); + CloudRegion cloudRegion = gBBInput.getCloudRegion(); + String sdncVfModuleQueryResponse = execution.getVariable(SDNCQUERY_RESPONSE + vfModule.getVfModuleId()); + String sdncVnfQueryResponse = execution.getVariable(SDNCQUERY_RESPONSE + genericVnf.getVnfId()); + Map<String, Object> paramsMap = vfModuleMapper.buildVfModuleParamsMap(requestContext, serviceInstance, + genericVnf, vfModule, sdncVnfQueryResponse, sdncVfModuleQueryResponse); + Map<String, String> sdncDirectives = getSdncDirectives(paramsMap); + InstanceRequest createInstanceRequest = createInstanceRequest(vfModule, cloudRegion, sdncDirectives); + InstanceResponse response = cnfAdapterClient.createVfModule(createInstanceRequest); + execution.setVariable("heatStackId", response.getId()); + } catch (Exception ex) { + logger.error("Exception occurred", ex); + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex); + } + } + + protected Map<String, String> getSdncDirectives(Map<String, Object> paramsMap) + throws JsonParseException, JsonMappingException, IOException { + Map<String, String> sdncDirectivesMap = new HashMap<>(); + String sdncDirectivesString = (String) paramsMap.get(MsoMulticloudUtils.SDNC_DIRECTIVES); + Attributes sdncDirectives = mapper.readValue(sdncDirectivesString, Attributes.class); + for (AttributeNameValue nameVal : sdncDirectives.getAttributes()) { + sdncDirectivesMap.put(nameVal.getAttributeName(), (String) nameVal.getAttributeValue()); + } + return sdncDirectivesMap; + } + + protected InstanceRequest createInstanceRequest(VfModule vfModule, CloudRegion cloudRegion, + Map<String, String> sdncDirectives) { + InstanceRequest request = new InstanceRequest(); + request.setRbName(vfModule.getModelInfoVfModule().getModelInvariantUUID()); + request.setRbVersion(vfModule.getModelInfoVfModule().getModelUUID()); + request.setCloudRegion(cloudRegion.getLcpCloudRegionId()); + request.setReleaseName(vfModule.getVfModuleId()); + request.setProfileName(sdncDirectives.get("k8s-rb-profile-name")); + request.setOverrideValues(sdncDirectives); + return request; + } + +} 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/ServiceLevel.java index 0671354bd6..b8f5ec9674 100644 --- 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/ServiceLevel.java @@ -20,32 +20,63 @@ 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; -import java.util.ArrayList; -import java.util.List; /** - * Abstract class for Service level upgrade Execution, it should be extended for service level upgrade tasks. + * Parent class for Service level upgrade Execution, it should be extended for service level upgrade tasks. */ -public abstract class AbstractServiceLevelPreparable { +public class ServiceLevel { - protected static final Logger LOG = LoggerFactory.getLogger(AbstractServiceLevelPreparable.class); + 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"; + /** - * This method fetches workflow names to be invoked based on the controller scope . + * 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 abstract String fetchWorkflowUsingScope(DelegateExecution execution, final String scope); + protected String fetchWorkflowUsingScope(final String scope, String operationName) { + Optional<String> wflName = Optional.empty(); + try { + List<Workflow> 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. @@ -69,4 +100,20 @@ public abstract class AbstractServiceLevelPreparable { } + /** + * 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<String> pnfNameList = (List<String>) 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/impl/ServiceLevelConstants.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/impl/ServiceLevelConstants.java index 34ebb308c3..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 @@ -1,5 +1,29 @@ +/*- + * ============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 java.util.Arrays; +import java.util.List; +import java.util.Map; + public class ServiceLevelConstants { public static final String BPMN_REQUEST = "bpmnRequest"; public static final String RESOURCE_TYPE = "resourceType"; @@ -8,13 +32,31 @@ public class ServiceLevelConstants { public static final String PNF = "pnf"; public static final String VNF = "vnf"; public static final String EMPTY_STRING = ""; - public static final String WORKFLOW_TO_INVOKE = "healthCheckWorkflow"; + public static final String HEALTH_CHECK_WORKFLOW_TO_INVOKE = "healthCheckWorkflow"; public static final String SOFTWARE_WORKFLOW_TO_INVOKE = "softwareUpgradeWorkflow"; - public static final String GENERIC_PNF_HEALTH_CHECK_WORKFLOW = "GenericPnfHealthCheck"; - public static final String PNF_SOFTWARE_UPGRADE_WORKFLOW = "PNFSoftwareUpgrade"; + public static final String HEALTH_CHECK_OPERATION = "ResourceHealthCheck"; + public static final String SW_UP_OPERATION = "ResourceSoftwareUpgrade"; public static final String CONTROLLER_STATUS = "ControllerStatus"; public 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"; + 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. + public static final Map<String, String> DEFAULT_HEALTH_CHECK_WORKFLOWS = + Map.of(PNF, "GenericPnfHealthCheck", VNF, "GenericVNFHealthCheck"); + + public static final Map<String, String> DEFAULT_SOFTWARE_UP_WORKFLOWS = + Map.of(PNF, "GenericPnfSoftwareUpgrade", VNF, "GenericVnfSoftwareUpgrade"); + + // Maps operation name with workflows + public static final Map<String, Map<String, String>> WORKFLOW_OPERATIONS_MAP = Map.of(HEALTH_CHECK_OPERATION, + DEFAULT_HEALTH_CHECK_WORKFLOWS, SW_UP_OPERATION, DEFAULT_SOFTWARE_UP_WORKFLOWS); + + public static final List<String> VALID_CONTROLLER_SCOPE = Arrays.asList(PNF, VNF); + + } 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 5b772760f0..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 @@ -20,59 +20,58 @@ package org.onap.so.bpmn.infrastructure.service.level.impl; +import java.util.Arrays; +import java.util.Collections; +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.AbstractServiceLevelPreparable; +import org.onap.so.bpmn.infrastructure.service.level.ServiceLevel; 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 { +public class ServiceLevelPreparation extends ServiceLevel implements JavaDelegate { + + private static final List<String> PNF_HEALTH_CHECK_PARAMS = Arrays.asList(ServiceLevelConstants.SERVICE_INSTANCE_ID, + ServiceLevelConstants.RESOURCE_TYPE, ServiceLevelConstants.BPMN_REQUEST); - private static final List<String> PNF_HC_PARAMS = Arrays.asList(ServiceLevelConstants.SERVICE_INSTANCE_ID, - ServiceLevelConstants.RESOURCE_TYPE, ServiceLevelConstants.BPMN_REQUEST, ServiceLevelConstants.PNF_NAME); + // TODO Update the list with vnf health check parameters if any validation needed + private static final List<String> VNF_HEALTH_CHECK_PARAMS = Collections.emptyList(); + + private static final Map<String, List<String>> HEALTH_CHECK_PARAMS_MAP = Map.of(ServiceLevelConstants.PNF, + PNF_HEALTH_CHECK_PARAMS, ServiceLevelConstants.VNF, VNF_HEALTH_CHECK_PARAMS); @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); LOG.debug("Scope retrieved from delegate execution: " + controllerScope); - final String wflName = fetchWorkflowUsingScope(execution, controllerScope); - LOG.debug("Health check workflow fetched for the scope: {} is: {}", controllerScope, wflName); - - if (ServiceLevelConstants.PNF.equalsIgnoreCase(controllerScope)) { - validateParamsWithScope(execution, controllerScope, PNF_HC_PARAMS); + if (ServiceLevelConstants.VALID_CONTROLLER_SCOPE.contains(controllerScope)) { + final String wflName = + fetchWorkflowUsingScope(controllerScope, ServiceLevelConstants.HEALTH_CHECK_OPERATION); + LOG.debug("Health check workflow fetched for the scope: {} is: {}", controllerScope, wflName); + validateParamsWithScope(execution, controllerScope, HEALTH_CHECK_PARAMS_MAP.get(controllerScope)); 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"); } - execution.setVariable(ServiceLevelConstants.WORKFLOW_TO_INVOKE, wflName); - execution.setVariable(ServiceLevelConstants.CONTROLLER_STATUS, ServiceLevelConstants.EMPTY_STRING); } else { exceptionBuilder.buildAndThrowWorkflowException(execution, ServiceLevelConstants.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 ServiceLevelConstants.PNF: - wflName = ServiceLevelConstants.GENERIC_PNF_HEALTH_CHECK_WORKFLOW; - break; - case ServiceLevelConstants.VNF: - wflName = ServiceLevelConstants.GENERIC_VNF_HEALTH_CHECK_WORKFLOW; - break; - default: - exceptionBuilder.buildAndThrowWorkflowException(execution, ServiceLevelConstants.ERROR_CODE, - "No valid health check work flow retrieved for the scope: " + scope); + "Resource type not found in the execution to invoke resource level health check"); } - return wflName; } } 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<ServiceInstance> 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<String> 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 dfc77d6f0c..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 @@ -1,54 +1,71 @@ +/*- + * ============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 java.util.Arrays; +import java.util.Collections; +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.AbstractServiceLevelPreparable; +import org.onap.so.bpmn.infrastructure.service.level.ServiceLevel; import org.springframework.stereotype.Component; -import java.util.Arrays; -import java.util.List; @Component -public class ServiceLevelUpgrade extends AbstractServiceLevelPreparable implements JavaDelegate { +public class ServiceLevelUpgrade extends ServiceLevel implements JavaDelegate { - private static final List<String> PNF_SWU_PARAMS = Arrays.asList(ServiceLevelConstants.SERVICE_INSTANCE_ID, - ServiceLevelConstants.RESOURCE_TYPE, ServiceLevelConstants.BPMN_REQUEST, ServiceLevelConstants.PNF_NAME); + private static final List<String> PNF_SOFTWARE_UP_PARAMS = Arrays.asList(ServiceLevelConstants.SERVICE_INSTANCE_ID, + ServiceLevelConstants.RESOURCE_TYPE, ServiceLevelConstants.BPMN_REQUEST); + + // TODO Update the list with vnf software upgrade parameters if any validation needed + private static final List<String> VNF_SOFTWARE_UP_PARAMS = Collections.emptyList(); + + private static final Map<String, List<String>> SOFTWARE_UP_PARAMS_MAP = Map.of(ServiceLevelConstants.PNF, + PNF_SOFTWARE_UP_PARAMS, ServiceLevelConstants.VNF, VNF_SOFTWARE_UP_PARAMS); - @Override - protected String fetchWorkflowUsingScope(DelegateExecution execution, String scope) { - String wflName = null; - switch (scope.toLowerCase()) { - case ServiceLevelConstants.PNF: - wflName = ServiceLevelConstants.PNF_SOFTWARE_UPGRADE_WORKFLOW; - break; - case ServiceLevelConstants.VNF: - wflName = ServiceLevelConstants.GENERIC_VNF_HEALTH_CHECK_WORKFLOW; - break; - default: - exceptionBuilder.buildAndThrowWorkflowException(execution, ServiceLevelConstants.ERROR_CODE, - "No valid health check work flow retrieved for the scope: " + scope); - } - return wflName; - } @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); LOG.debug("Scope retrieved from delegate execution: " + controllerScope); - final String wflName = fetchWorkflowUsingScope(execution, controllerScope); - LOG.debug("Health check workflow fetched for the scope: {} is: {}", controllerScope, wflName); - - if ("pnf".equalsIgnoreCase(controllerScope)) { - validateParamsWithScope(execution, controllerScope, PNF_SWU_PARAMS); + if (ServiceLevelConstants.VALID_CONTROLLER_SCOPE.contains(controllerScope)) { + final String wflName = fetchWorkflowUsingScope(controllerScope, ServiceLevelConstants.SW_UP_OPERATION); + LOG.debug("Software Upgrade workflow fetched for the scope: {} is: {}", controllerScope, wflName); + 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"); } - } else { exceptionBuilder.buildAndThrowWorkflowException(execution, ServiceLevelConstants.ERROR_CODE, - "Controller scope not found to invoke resource level health check"); + "Resource type not found in the execution to invoke resource level software upgrade"); } } } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java index 75d3ddf2e6..9b9433afdb 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java @@ -300,6 +300,9 @@ public class WorkflowAction { || ("recreateInstance".equalsIgnoreCase(requestAction)))) { traverseAAIVnf(execution, resourceList, workflowResourceIds.getServiceInstanceId(), workflowResourceIds.getVnfId(), aaiResourceIds); + } else if (resourceType == WorkflowType.VNF && "updateInstance".equalsIgnoreCase(requestAction)) { + customTraverseAAIVnf(execution, resourceList, workflowResourceIds.getServiceInstanceId(), + workflowResourceIds.getVnfId(), aaiResourceIds); } else { buildAndThrowException(execution, "Current Macro Request is not supported"); } @@ -568,6 +571,10 @@ public class WorkflowAction { WorkflowResourceIds workflowIdsCopy = SerializationUtils.clone(dataObj.getWorkflowResourceIds()); org.onap.aai.domain.yang.Configuration configuration = getRelatedResourcesInVnfc(vnfc, org.onap.aai.domain.yang.Configuration.class, AAIObjectType.CONFIGURATION); + if (configuration == null) { + logger.warn(String.format("No configuration found for VNFC %s in AAI", vnfc.getVnfcName())); + continue; + } workflowIdsCopy.setConfigurationId(configuration.getConfigurationId()); for (OrchestrationFlow orchFlow : result) { dataObj.getResourceKey().setVfModuleCustomizationId(vfModuleCustomizationUUID); @@ -584,7 +591,6 @@ public class WorkflowAction { dataObj.getRequestAction(), dataObj.isaLaCarte(), dataObj.getVnfType(), workflowIdsCopy, dataObj.getRequestDetails(), false, null, vnfcName, true, null); flowsToExecuteConfigs.add(ebb); - } } return flowsToExecuteConfigs; @@ -1108,6 +1114,51 @@ public class WorkflowAction { } } + private void customTraverseAAIVnf(DelegateExecution execution, List<Resource> resourceList, String serviceId, + String vnfId, List<Pair<WorkflowType, String>> aaiResourceIds) { + try { + ServiceInstance serviceInstanceAAI = bbInputSetupUtils.getAAIServiceInstanceById(serviceId); + org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance serviceInstanceMSO = + bbInputSetup.getExistingServiceInstance(serviceInstanceAAI); + resourceList.add(new Resource(WorkflowType.SERVICE, serviceInstanceMSO.getServiceInstanceId(), false)); + if (serviceInstanceMSO.getVnfs() != null) { + for (org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf vnf : serviceInstanceMSO.getVnfs()) { + if (vnf.getVnfId().equals(vnfId)) { + aaiResourceIds.add(new Pair<>(WorkflowType.VNF, vnf.getVnfId())); + + String vnfCustomizationUUID = + bbInputSetupUtils.getAAIGenericVnf(vnfId).getModelCustomizationId(); + resourceList.add(new Resource(WorkflowType.VNF, vnfCustomizationUUID, false)); + + if (vnf.getVfModules() != null) { + for (VfModule vfModule : vnf.getVfModules()) { + aaiResourceIds.add(new Pair<>(WorkflowType.VFMODULE, vfModule.getVfModuleId())); + resourceList.add(new Resource(WorkflowType.VFMODULE, vfModule.getVfModuleId(), false)); + findConfigurationsInsideVfModule(execution, vnf.getVnfId(), vfModule.getVfModuleId(), + resourceList, aaiResourceIds); + } + } + if (vnf.getVolumeGroups() != null) { + for (org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup volumeGroup : vnf + .getVolumeGroups()) { + aaiResourceIds + .add(new Pair<>(WorkflowType.VOLUMEGROUP, volumeGroup.getVolumeGroupId())); + resourceList.add( + new Resource(WorkflowType.VOLUMEGROUP, volumeGroup.getVolumeGroupId(), false)); + } + } + break; + } + } + } + } catch (Exception ex) { + logger.error("Exception in customTraverseAAIVnf", ex); + buildAndThrowException(execution, + "Could not find existing Vnf or related Instances to execute the request on."); + } + + } + private void findConfigurationsInsideVfModule(DelegateExecution execution, String vnfId, String vfModuleId, List<Resource> resourceList, List<Pair<WorkflowType, String>> aaiResourceIds) { try { diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/CnfAdapterClient.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/CnfAdapterClient.java new file mode 100644 index 0000000000..f44c15ac54 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/CnfAdapterClient.java @@ -0,0 +1,97 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.client.adapter.cnf; + +import java.util.ArrayList; +import java.util.List; +import javax.persistence.EntityNotFoundException; +import javax.ws.rs.core.UriBuilder; +import org.apache.http.HttpStatus; +import org.onap.so.client.adapter.cnf.entities.InstanceRequest; +import org.onap.so.client.adapter.cnf.entities.InstanceResponse; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.env.Environment; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.ResponseEntity; +import org.springframework.retry.annotation.Backoff; +import org.springframework.retry.annotation.Retryable; +import org.springframework.stereotype.Component; +import org.springframework.web.client.HttpClientErrorException; +import org.springframework.web.client.HttpServerErrorException; +import org.springframework.web.client.RestTemplate; + +@Component +public class CnfAdapterClient { + + private static final Logger logger = LoggerFactory.getLogger(CnfAdapterClient.class); + + @Autowired + private RestTemplate restTemplate; + + @Autowired + private Environment env; + + private static final String INSTANCE_CREATE_PATH = "/api/multicloud-k8s/v1/v1/instance"; + + @Retryable(value = {HttpServerErrorException.class}, maxAttempts = 3, backoff = @Backoff(delay = 3000)) + public InstanceResponse createVfModule(InstanceRequest request) throws CnfAdapterClientException { + try { + // String uri = env.getRequiredProperty("mso.cnf.adapter.endpoint"); //TODO: This needs to be added as well + // for configuration + String uri = "https://localhost:32780"; // TODO: What is the correct uri? + String endpoint = UriBuilder.fromUri(uri).path(INSTANCE_CREATE_PATH).build().toString(); + HttpEntity<?> entity = getHttpEntity(request); + ResponseEntity<InstanceResponse> result = + restTemplate.exchange(endpoint, HttpMethod.POST, entity, InstanceResponse.class); + return result.getBody(); + } catch (HttpClientErrorException e) { + logger.error("Error Calling CNF Adapter, e"); + if (HttpStatus.SC_NOT_FOUND == e.getStatusCode().value()) { + throw new EntityNotFoundException(e.getResponseBodyAsString()); + } + throw e; + } + } + + protected HttpHeaders getHttpHeaders() { + HttpHeaders headers = new HttpHeaders(); + List<org.springframework.http.MediaType> acceptableMediaTypes = new ArrayList<>(); + acceptableMediaTypes.add(org.springframework.http.MediaType.APPLICATION_JSON); + headers.setAccept(acceptableMediaTypes); + /* + * try { String userCredentials = CryptoUtils.decrypt(env.getRequiredProperty("mso.cnf.adapter.auth"), + * env.getRequiredProperty("mso.msoKey")); if (userCredentials != null) { headers.add(HttpHeaders.AUTHORIZATION, + * "Basic " + DatatypeConverter.printBase64Binary(userCredentials.getBytes())); } } catch + * (GeneralSecurityException e) { logger.error("Security exception", e); } + */ + return headers; + } + + protected HttpEntity<?> getHttpEntity(InstanceRequest request) { + HttpHeaders headers = getHttpHeaders(); + return new HttpEntity<>(request, headers); + } + +} diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/CnfAdapterClientException.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/CnfAdapterClientException.java new file mode 100644 index 0000000000..d716070ffa --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/CnfAdapterClientException.java @@ -0,0 +1,34 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.client.adapter.cnf; + +public class CnfAdapterClientException extends Exception { + + /** + * + */ + private static final long serialVersionUID = -7154784472485852602L; + + public CnfAdapterClientException(String message) { + super(message); + } + +} diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/GVK.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/GVK.java new file mode 100644 index 0000000000..3ed6894fcf --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/GVK.java @@ -0,0 +1,49 @@ + +package org.onap.so.client.adapter.cnf.entities; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonPropertyOrder({"Group", "Version", "Kind"}) +public class GVK { + + @JsonProperty("Group") + private String group; + @JsonProperty("Version") + private String version; + @JsonProperty("Kind") + private String kind; + + @JsonProperty("Group") + public String getGroup() { + return group; + } + + @JsonProperty("Group") + public void setGroup(String group) { + this.group = group; + } + + @JsonProperty("Version") + public String getVersion() { + return version; + } + + @JsonProperty("Version") + public void setVersion(String version) { + this.version = version; + } + + @JsonProperty("Kind") + public String getKind() { + return kind; + } + + @JsonProperty("Kind") + public void setKind(String kind) { + this.kind = kind; + } + +} diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/InstanceRequest.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/InstanceRequest.java new file mode 100644 index 0000000000..e4058097ab --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/InstanceRequest.java @@ -0,0 +1,95 @@ + +package org.onap.so.client.adapter.cnf.entities; + +import java.util.Map; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonPropertyOrder({"rb-name", "rb-version", "profile-name", "release-name", "cloud-region", "labels", + "override-values"}) +public class InstanceRequest { + + @JsonProperty("rb-name") + private String rbName; + @JsonProperty("rb-version") + private String rbVersion; + @JsonProperty("profile-name") + private String profileName; + @JsonProperty("release-name") + private String releaseName; + @JsonProperty("cloud-region") + private String cloudRegion; + @JsonProperty("labels") + private Labels labels; + @JsonProperty(value = "override-values") + private Map<String, String> overrideValues; + + @JsonProperty("rb-name") + public String getRbName() { + return rbName; + } + + @JsonProperty("rb-name") + public void setRbName(String rbName) { + this.rbName = rbName; + } + + @JsonProperty("rb-version") + public String getRbVersion() { + return rbVersion; + } + + @JsonProperty("rb-version") + public void setRbVersion(String rbVersion) { + this.rbVersion = rbVersion; + } + + @JsonProperty("profile-name") + public String getProfileName() { + return profileName; + } + + @JsonProperty("profile-name") + public void setProfileName(String profileName) { + this.profileName = profileName; + } + + @JsonProperty("cloud-region") + public String getCloudRegion() { + return cloudRegion; + } + + @JsonProperty("cloud-region") + public void setCloudRegion(String cloudRegion) { + this.cloudRegion = cloudRegion; + } + + @JsonProperty("labels") + public Labels getLabels() { + return labels; + } + + @JsonProperty("labels") + public void setLabels(Labels labels) { + this.labels = labels; + } + + public String getReleaseName() { + return releaseName; + } + + public void setReleaseName(String releaseName) { + this.releaseName = releaseName; + } + + public Map<String, String> getOverrideValues() { + return overrideValues; + } + + public void setOverrideValues(Map<String, String> overrideValues) { + this.overrideValues = overrideValues; + } + +} diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/InstanceResponse.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/InstanceResponse.java new file mode 100644 index 0000000000..e38bcc2664 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/InstanceResponse.java @@ -0,0 +1,62 @@ + +package org.onap.so.client.adapter.cnf.entities; + +import java.util.List; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonPropertyOrder({"id", "request", "namespace", "resources"}) +public class InstanceResponse { + + @JsonProperty("id") + private String id; + @JsonProperty("request") + private InstanceRequest request; + @JsonProperty("namespace") + private String namespace; + @JsonProperty("resources") + private List<Resource> resources = null; + + @JsonProperty("id") + public String getId() { + return id; + } + + @JsonProperty("id") + public void setId(String id) { + this.id = id; + } + + @JsonProperty("request") + public InstanceRequest getRequest() { + return request; + } + + @JsonProperty("request") + public void setRequest(InstanceRequest request) { + this.request = request; + } + + @JsonProperty("namespace") + public String getNamespace() { + return namespace; + } + + @JsonProperty("namespace") + public void setNamespace(String namespace) { + this.namespace = namespace; + } + + @JsonProperty("resources") + public List<Resource> getResources() { + return resources; + } + + @JsonProperty("resources") + public void setResources(List<Resource> resources) { + this.resources = resources; + } + +} diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/Labels.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/Labels.java new file mode 100644 index 0000000000..1df2e59459 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/Labels.java @@ -0,0 +1,25 @@ + +package org.onap.so.client.adapter.cnf.entities; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonPropertyOrder({"testCaseName"}) +public class Labels { + + @JsonProperty("testCaseName") + private String testCaseName; + + @JsonProperty("testCaseName") + public String getTestCaseName() { + return testCaseName; + } + + @JsonProperty("testCaseName") + public void setTestCaseName(String testCaseName) { + this.testCaseName = testCaseName; + } + +} diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/Resource.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/Resource.java new file mode 100644 index 0000000000..bde495aaa2 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/Resource.java @@ -0,0 +1,37 @@ + +package org.onap.so.client.adapter.cnf.entities; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonPropertyOrder({"GVK", "Name"}) +public class Resource { + + @JsonProperty("GVK") + private GVK gVK; + @JsonProperty("Name") + private String name; + + @JsonProperty("GVK") + public GVK getGVK() { + return gVK; + } + + @JsonProperty("GVK") + public void setGVK(GVK gVK) { + this.gVK = gVK; + } + + @JsonProperty("Name") + public String getName() { + return name; + } + + @JsonProperty("Name") + public void setName(String name) { + this.name = name; + } + +} diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/vnf/mapper/Attributes.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/vnf/mapper/Attributes.java new file mode 100644 index 0000000000..6d79c20616 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/vnf/mapper/Attributes.java @@ -0,0 +1,23 @@ +package org.onap.so.client.adapter.vnf.mapper; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; +import com.fasterxml.jackson.annotation.JsonProperty; + +public class Attributes implements Serializable { + + private static final long serialVersionUID = -5782985934617532582L; + + @JsonProperty("attributes") + private List<AttributeNameValue> attributes = new ArrayList<>(); + + public List<AttributeNameValue> getAttributes() { + return attributes; + } + + public void setAttributes(List<AttributeNameValue> attributes) { + this.attributes = attributes; + } + +} diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/vnf/mapper/VnfAdapterVfModuleObjectMapper.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/vnf/mapper/VnfAdapterVfModuleObjectMapper.java index bc618e17de..59da22f8e1 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/vnf/mapper/VnfAdapterVfModuleObjectMapper.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/vnf/mapper/VnfAdapterVfModuleObjectMapper.java @@ -178,7 +178,7 @@ public class VnfAdapterVfModuleObjectMapper { return msoRequest; } - private Map<String, Object> buildVfModuleParamsMap(RequestContext requestContext, ServiceInstance serviceInstance, + public Map<String, Object> buildVfModuleParamsMap(RequestContext requestContext, ServiceInstance serviceInstance, GenericVnf genericVnf, VfModule vfModule, String sdncVnfQueryResponse, String sdncVfModuleQueryResponse) throws IOException, MissingValueTagException { 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 index 340b2776a4..0b1c5b0f5e 100644 --- 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 @@ -20,6 +20,13 @@ package org.onap.so.bpmn.infrastructure.service.level; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.when; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Map; import org.camunda.bpm.engine.delegate.BpmnError; import org.camunda.bpm.engine.delegate.DelegateExecution; import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake; @@ -27,23 +34,16 @@ import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; -import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Spy; +import org.onap.so.bpmn.BaseTaskTest; import org.onap.so.bpmn.infrastructure.service.level.impl.ServiceLevelConstants; 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 org.onap.so.db.catalog.beans.Workflow; -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = {ServiceLevelPreparation.class, ExceptionBuilder.class}) -public class ServiceLevelPreparationTest { +public class ServiceLevelPreparationTest extends BaseTaskTest { private static final String TEST_PNF_SCOPE = "pnf"; private static final String TEST_PROCESS_KEY = "testProcessKey"; @@ -52,42 +52,29 @@ public class ServiceLevelPreparationTest { private static final String RESOURCE_TYPE = "resourceType"; private static final String SERVICE_INSTANCE_ID = "serviceInstanceId"; private static final String PNF_NAME = "pnfName"; - private static final List<String> PNF_HEALTH_CHECK_PARAMS = Arrays.asList(ServiceLevelConstants.SERVICE_INSTANCE_ID, - ServiceLevelConstants.RESOURCE_TYPE, ServiceLevelConstants.BPMN_REQUEST, ServiceLevelConstants.PNF_NAME); + private static final String HEALTH_CHECK_OPERATION = "ResourceHealthCheck"; + private static final String PNF_HEALTH_CHECK_WORKFLOW = "PNFHealthCheck"; + private static final Map<String, List<String>> HEALTH_CHECK_PARAMS_MAP = Map.of(TEST_PNF_SCOPE, + Arrays.asList(SERVICE_INSTANCE_ID, RESOURCE_TYPE, BPMN_REQUEST, PNF_NAME), "vnf", Collections.emptyList()); + + private List<Workflow> workflowList = new ArrayList<>(); - private Map<String, String> pnfHealthCheckTestParams = new HashMap<>(); + @Rule + public ExpectedException thrown = ExpectedException.none(); - @Autowired + @InjectMocks private ServiceLevelPreparation serviceLevelPrepare; - @Autowired + @InjectMocks + @Spy 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); execution.setVariable(BPMN_REQUEST, "bpmnRequestValue"); @@ -95,14 +82,22 @@ public class ServiceLevelPreparationTest { execution.setVariable(PNF_NAME, "PnfDemo"); invalidExecution.setVariables(execution.getVariables()); + + Workflow pnfWorkflow = new Workflow(); + pnfWorkflow.setName(PNF_HEALTH_CHECK_WORKFLOW); + pnfWorkflow.setOperationName(HEALTH_CHECK_OPERATION); + pnfWorkflow.setResourceTarget(TEST_PNF_SCOPE); + workflowList.add(pnfWorkflow); + + when(catalogDbClient.findWorkflowByOperationName(HEALTH_CHECK_OPERATION)).thenReturn(workflowList); } @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(ServiceLevelConstants.WORKFLOW_TO_INVOKE))) - .isEqualTo("GenericPnfHealthCheck"); + assertThat(String.valueOf(execution.getVariable(ServiceLevelConstants.HEALTH_CHECK_WORKFLOW_TO_INVOKE))) + .isEqualTo("PNFHealthCheck"); } @Test @@ -110,7 +105,8 @@ public class ServiceLevelPreparationTest { invalidExecution.removeVariable(BPMN_REQUEST); // 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); + serviceLevelPrepare.validateParamsWithScope(invalidExecution, TEST_PNF_SCOPE, + HEALTH_CHECK_PARAMS_MAP.get(TEST_PNF_SCOPE)); } @Test @@ -129,6 +125,32 @@ public class ServiceLevelPreparationTest { } + @Test + public void validateDefaultWorkflowIsSetWithoutDBData() throws Exception { + // Mock empty workflow list in db response + when(catalogDbClient.findWorkflowByOperationName(HEALTH_CHECK_OPERATION)).thenReturn(new ArrayList<Workflow>()); + serviceLevelPrepare.execute(execution); + // Expect default workflow gets assigned when workflow name not found in db. + assertThat(String.valueOf(execution.getVariable(ServiceLevelConstants.HEALTH_CHECK_WORKFLOW_TO_INVOKE))) + .isEqualTo(ServiceLevelConstants.DEFAULT_HEALTH_CHECK_WORKFLOWS.get(TEST_PNF_SCOPE)); + } + + @Test + public void validateWorkflowSetFromDb() throws Exception { + Workflow vnfWorkflow = new Workflow(); + vnfWorkflow.setName("VNFHealthCheck"); + vnfWorkflow.setOperationName(HEALTH_CHECK_OPERATION); + vnfWorkflow.setResourceTarget("vnf"); + workflowList.add(vnfWorkflow); + // Mock db response with multiple worklfows mapped with same operation name + when(catalogDbClient.findWorkflowByOperationName(HEALTH_CHECK_OPERATION)).thenReturn(workflowList); + serviceLevelPrepare.execute(execution); + + // Expect right workflow gets assigned from db based on the controller scope. + assertThat(String.valueOf(execution.getVariable(ServiceLevelConstants.HEALTH_CHECK_WORKFLOW_TO_INVOKE))) + .isEqualTo(PNF_HEALTH_CHECK_WORKFLOW); + } + } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionTest.java index 407a844c4e..c1970ec32c 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionTest.java @@ -1601,6 +1601,79 @@ public class WorkflowActionTest extends BaseTaskTest { } @Test + public void getConfigBuildingBlocksNullConfigurationTest() throws Exception { + String gAction = "deleteInstance"; + ObjectMapper mapper = new ObjectMapper(); + mapper.disable(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES); + + WorkflowType resourceType = WorkflowType.VFMODULE; + execution.setVariable("mso-request-id", "00f704ca-c5e5-4f95-a72c-6889db7b0688"); + execution.setVariable("requestAction", gAction); + String bpmnRequest = + new String(Files.readAllBytes(Paths.get("src/test/resources/__files/VfModuleCreateWithFabric.json"))); + execution.setVariable("bpmnRequest", bpmnRequest); + execution.setVariable("vnfId", "1234"); + execution.setVariable("vfModuleId", "vfModuleId1234"); + execution.setVariable("requestUri", + "v7/serviceInstances/f647e3ef-6d2e-4cd3-bff4-8df4634208de/vnfs/b80b16a5-f80d-4ffa-91c8-bd47c7438a3d/vfModules"); + ServiceInstancesRequest sIRequest = mapper.readValue(bpmnRequest, ServiceInstancesRequest.class); + RequestDetails requestDetails = sIRequest.getRequestDetails(); + String requestAction = "deleteInstance"; + String requestId = "9c944122-d161-4280-8594-48c06a9d96d5"; + boolean aLaCarte = true; + String apiVersion = "7"; + String vnfType = "vnfType"; + String key = "00d15ebb-c80e-43c1-80f0-90c40dde70b0"; + String resourceId = "d1d35800-783d-42d3-82f6-d654c5054a6e"; + Resource resourceKey = new Resource(resourceType, key, aLaCarte); + WorkflowResourceIds workflowResourceIds = SPY_workflowAction.populateResourceIdsFromApiHandler(execution); + + List<OrchestrationFlow> orchFlows = createFlowList("DeactivateVfModuleBB", "DeleteVfModuleBB", + "UnassignVfModuleBB", "DeleteFabricConfigurationBB"); + + ConfigBuildingBlocksDataObject dataObj = new ConfigBuildingBlocksDataObject().setsIRequest(sIRequest) + .setOrchFlows(orchFlows).setRequestId(requestId).setResourceKey(resourceKey).setApiVersion(apiVersion) + .setResourceId(resourceId).setRequestAction(requestAction).setaLaCarte(aLaCarte).setVnfType(vnfType) + .setWorkflowResourceIds(workflowResourceIds).setRequestDetails(requestDetails).setExecution(execution); + + org.onap.aai.domain.yang.GenericVnf vnf = new org.onap.aai.domain.yang.GenericVnf(); + vnf.setVnfId("vnf0"); + vnf.setModelCustomizationId("modelCustomizationId"); + when(bbSetupUtils.getAAIGenericVnf(any())).thenReturn(vnf); + + org.onap.aai.domain.yang.VfModule vfModule = new org.onap.aai.domain.yang.VfModule(); + vfModule.setModelCustomizationId("modelCustomizationId"); + + /* this is a test case where configuration for vnfc is null */ + org.onap.aai.domain.yang.Configuration config1 = null; + org.onap.aai.domain.yang.Configuration config2 = new org.onap.aai.domain.yang.Configuration(); + config2.setConfigurationId("config2"); + + List<org.onap.aai.domain.yang.Vnfc> vnfcs = new ArrayList<org.onap.aai.domain.yang.Vnfc>(); + org.onap.aai.domain.yang.Vnfc vnfc1 = new org.onap.aai.domain.yang.Vnfc(); + vnfc1.setVnfcName("zauk53avetd02svm001"); + org.onap.aai.domain.yang.Vnfc vnfc2 = new org.onap.aai.domain.yang.Vnfc(); + vnfc2.setVnfcName("zauk53avetd02tvm001"); + vnfcs.add(vnfc1); + vnfcs.add(vnfc2); + + when(bbSetupUtils.getAAIVfModule(any(), any())).thenReturn(vfModule); + doReturn(vnfcs).when(SPY_workflowAction).getRelatedResourcesInVfModule(any(), any(), + eq(org.onap.aai.domain.yang.Vnfc.class), eq(AAIObjectType.VNFC)); + doReturn(config1).when(SPY_workflowAction).getRelatedResourcesInVnfc(eq(vnfc1), + eq(org.onap.aai.domain.yang.Configuration.class), eq(AAIObjectType.CONFIGURATION)); + doReturn(config2).when(SPY_workflowAction).getRelatedResourcesInVnfc(eq(vnfc2), + eq(org.onap.aai.domain.yang.Configuration.class), eq(AAIObjectType.CONFIGURATION)); + + List<ExecuteBuildingBlock> results = SPY_workflowAction.getConfigBuildingBlocks(dataObj); + + assertFalse(results.isEmpty()); + assertEquals(1, results.size()); + assertEquals("config2", results.get(0).getWorkflowResourceIds().getConfigurationId()); + assertEquals("zauk53avetd02tvm001", results.get(0).getConfigurationResourceKeys().getVnfcName()); + } + + @Test public void selectExecutionListALaCarteVfModuleNoFabricDeleteTest() throws Exception { String gAction = "deleteInstance"; String resource = "VfModule"; |