diff options
author | Seshu Kumar M <seshu.kumar.m@huawei.com> | 2019-09-11 12:10:36 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2019-09-11 12:10:36 +0000 |
commit | b8c0e788a07b6f7c9f72239fa6c2baf48a72332f (patch) | |
tree | f72012c358fae07a89b671bb6b395ccb1a074274 /bpmn/so-bpmn-tasks/src/main | |
parent | 87e1477bed790d26a5c946a834725b6179cd6796 (diff) | |
parent | 787fcef801d6c47caf10b06312b83ff103d6f1ae (diff) |
Merge "fix of the instanceParams adding to the CDS request"
Diffstat (limited to 'bpmn/so-bpmn-tasks/src/main')
-rw-r--r-- | bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/ConfigAssignVnf.java | 94 |
1 files changed, 65 insertions, 29 deletions
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/ConfigAssignVnf.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/ConfigAssignVnf.java index bc71fc6f67..9413e8ef2e 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/ConfigAssignVnf.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/ConfigAssignVnf.java @@ -3,13 +3,14 @@ * ONAP - SO * ================================================================================ * Copyright (C) 2019 TechMahindra. + * Copyright (C) 2019 Nokia. * ================================================================================ * 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. @@ -20,8 +21,10 @@ package org.onap.so.bpmn.infrastructure.flowspecific.tasks; +import com.fasterxml.jackson.databind.ObjectMapper; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.UUID; import org.onap.so.bpmn.common.BuildingBlockExecution; import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; @@ -33,15 +36,15 @@ import org.onap.so.client.cds.beans.AbstractCDSPropertiesBean; import org.onap.so.client.cds.beans.ConfigAssignPropertiesForVnf; import org.onap.so.client.cds.beans.ConfigAssignRequestVnf; import org.onap.so.client.exception.ExceptionBuilder; +import org.onap.so.serviceinstancebeans.Service; +import org.onap.so.serviceinstancebeans.Vnfs; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; /** - * * Get vnf related data and config assign - * */ @Component public class ConfigAssignVnf { @@ -51,48 +54,42 @@ public class ConfigAssignVnf { private static final String ACTION_NAME = "config-assign"; private static final String MODE = "sync"; + private final ExtractPojosForBB extractPojosForBB; + private final ExceptionBuilder exceptionBuilder; + @Autowired - private ExceptionBuilder exceptionUtil; - @Autowired - private ExtractPojosForBB extractPojosForBB; + public ConfigAssignVnf(ExtractPojosForBB extractPojosForBB, ExceptionBuilder exceptionBuilder) { + this.extractPojosForBB = extractPojosForBB; + this.exceptionBuilder = exceptionBuilder; + } /** * Getting the vnf data, blueprint name, blueprint version etc and setting them in execution object and calling the * subprocess. - * - * @param execution */ public void preProcessAbstractCDSProcessing(BuildingBlockExecution execution) { logger.info("Start preProcessAbstractCDSProcessing "); try { - GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID); + GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID); ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID); - - List<Map<String, Object>> userParams = - execution.getGeneralBuildingBlock().getRequestContext().getRequestParameters().getUserParams(); - ConfigAssignPropertiesForVnf configAssignPropertiesForVnf = new ConfigAssignPropertiesForVnf(); configAssignPropertiesForVnf.setServiceInstanceId(serviceInstance.getServiceInstanceId()); configAssignPropertiesForVnf .setServiceModelUuid(serviceInstance.getModelInfoServiceInstance().getModelUuid()); configAssignPropertiesForVnf - .setVnfCustomizationUuid(vnf.getModelInfoGenericVnf().getModelCustomizationUuid()); - configAssignPropertiesForVnf.setVnfId(vnf.getVnfId()); - configAssignPropertiesForVnf.setVnfName(vnf.getVnfName()); - - for (Map<String, Object> params : userParams) { - for (Map.Entry<String, Object> entry : params.entrySet()) { - configAssignPropertiesForVnf.setUserParam(entry.getKey(), entry.getValue()); - } - } - + .setVnfCustomizationUuid(genericVnf.getModelInfoGenericVnf().getModelCustomizationUuid()); + configAssignPropertiesForVnf.setVnfId(genericVnf.getVnfId()); + configAssignPropertiesForVnf.setVnfName(genericVnf.getVnfName()); + setUserParamsInConfigAssignPropertiesForVnf(configAssignPropertiesForVnf, + execution.getGeneralBuildingBlock().getRequestContext().getRequestParameters().getUserParams(), + genericVnf); ConfigAssignRequestVnf configAssignRequestVnf = new ConfigAssignRequestVnf(); - configAssignRequestVnf.setResolutionKey(vnf.getVnfName()); + configAssignRequestVnf.setResolutionKey(genericVnf.getVnfName()); configAssignRequestVnf.setConfigAssignPropertiesForVnf(configAssignPropertiesForVnf); - String blueprintName = vnf.getModelInfoGenericVnf().getBlueprintName(); - String blueprintVersion = vnf.getModelInfoGenericVnf().getBlueprintVersion(); + String blueprintName = genericVnf.getModelInfoGenericVnf().getBlueprintName(); + String blueprintVersion = genericVnf.getModelInfoGenericVnf().getBlueprintVersion(); logger.debug(" BlueprintName : " + blueprintName + " BlueprintVersion : " + blueprintVersion); AbstractCDSPropertiesBean abstractCDSPropertiesBean = new AbstractCDSPropertiesBean(); @@ -109,9 +106,48 @@ public class ConfigAssignVnf { abstractCDSPropertiesBean.setActionName(ACTION_NAME); abstractCDSPropertiesBean.setMode(MODE); execution.setVariable("executionObject", abstractCDSPropertiesBean); - } catch (Exception ex) { - exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex); + logger.error("An exception occurred when creating ConfigAssignPropertiesForVnf for CDS request", ex); + exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, ex); + } + } + + private void setUserParamsInConfigAssignPropertiesForVnf(ConfigAssignPropertiesForVnf configAssignProperties, + List<Map<String, Object>> userParamsFromRequest, GenericVnf vnf) throws Exception { + Service service = getServiceFromRequestUserParams(userParamsFromRequest); + List<Map<String, String>> instanceParamsList = + getInstanceParamForVnf(service, vnf.getModelInfoGenericVnf().getModelCustomizationUuid()); + instanceParamsList + .forEach(instanceParamsMap -> instanceParamsMap.forEach(configAssignProperties::setUserParam)); + } + + private Service getServiceFromRequestUserParams(List<Map<String, Object>> userParams) throws Exception { + Map<String, Object> serviceMap = userParams.stream().filter(key -> key.containsKey("service")).findFirst() + .orElseThrow(() -> new Exception("Can not find service in userParams section in generalBuildingBlock")); + return convertServiceFromJsonToServiceObject((String) serviceMap.get("service")); + } + + private Service convertServiceFromJsonToServiceObject(String serviceFromJson) throws Exception { + try { + return new ObjectMapper().readValue(serviceFromJson, Service.class); + } catch (Exception e) { + logger.error(String.format( + "An exception occurred while converting json object to Service object. The json is: %s", + serviceFromJson), e); + throw e; + } + } + + private List<Map<String, String>> getInstanceParamForVnf(Service service, String genericVnfModelCustomizationUuid) + throws Exception { + Optional<Vnfs> foundedVnf = service.getResources().getVnfs().stream() + .filter(vnfs -> vnfs.getModelInfo().getModelCustomizationId().equals(genericVnfModelCustomizationUuid)) + .findFirst(); + if (foundedVnf.isPresent()) { + return foundedVnf.get().getInstanceParams(); + } else { + throw new Exception(String.format("Can not find vnf for genericVnfModelCustomizationUuid: %s", + genericVnfModelCustomizationUuid)); } } |