diff options
author | tragait <rahul.tyagi@est.tech> | 2019-12-05 18:04:31 +0000 |
---|---|---|
committer | tragait <rahul.tyagi@est.tech> | 2020-02-20 13:33:16 +0000 |
commit | 5fa8680d198315cfd11fc043a6f686ebd1d15cb6 (patch) | |
tree | 9426708b4470d848e456d4d6af16a86b8f44fce7 /bpmn/MSOCommonBPMN/src/main/java/org | |
parent | 4e6227a98b2fe5b3c6ae78f5fc3d4d0553b119c1 (diff) |
SO-CDS PNF BB
This commit implements code for PNF BB for pnf
software upgrade usecase.
Issue-ID: SO-2090
Signed-off-by: tragait <rahul.tyagi@est.tech>
Change-Id: I3da3ba965bc92fda0ecc542d42afe694f19e06e1
Signed-off-by: tragait <rahul.tyagi@est.tech>
Diffstat (limited to 'bpmn/MSOCommonBPMN/src/main/java/org')
3 files changed, 155 insertions, 10 deletions
diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/GeneratePayloadForCds.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/GeneratePayloadForCds.java index 0766dae8e1..fb79880572 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/GeneratePayloadForCds.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/GeneratePayloadForCds.java @@ -4,6 +4,8 @@ * ================================================================================ * Copyright (C) 2019 Bell Canada * ================================================================================ + * Modifications Copyright (c) 2020 Nordix + * ================================================================================ * 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 @@ -20,6 +22,7 @@ package org.onap.so.client.cds; +import org.camunda.bpm.engine.delegate.DelegateExecution; import org.onap.so.bpmn.common.BuildingBlockExecution; import org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock; import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock; @@ -34,8 +37,9 @@ import java.util.UUID; public class GeneratePayloadForCds { private static final String ORIGINATOR_ID = "SO"; - private static final String MODE = "sync"; private static final String BUILDING_BLOCK = "buildingBlock"; + private static final String DEFAULT_SYNC_MODE = "sync"; + private static final String MSO_REQUEST_ID = "msoRequestId"; @Autowired private VnfCDSRequestProvider vnfCDSRequestProvider; @@ -49,8 +53,12 @@ public class GeneratePayloadForCds { @Autowired private ExtractPojosForBB extractPojosForBB; + @Autowired + private PnfCDSRequestProvider pnfCDSRequestProvider; + /** - * Build properties like (blueprint name, version, action etc..) along with the request payload. + * Build properties like (blueprint name, version, action etc..) along with the request payload for vnf, vf-module + * and service. * * @param execution - A building block execution object. * @return AbstractCDSPropertiesBean - A POJO which contains CDS related information. @@ -61,8 +69,9 @@ public class GeneratePayloadForCds { ExecuteBuildingBlock executeBuildingBlock = execution.getVariable(BUILDING_BLOCK); BuildingBlock buildingBlock = executeBuildingBlock.getBuildingBlock(); - String scope = buildingBlock.getBpmnScope(); - String action = buildingBlock.getBpmnAction(); + final String requestId = execution.getGeneralBuildingBlock().getRequestContext().getMsoRequestId(); + final String scope = buildingBlock.getBpmnScope(); + final String action = buildingBlock.getBpmnAction(); CDSRequestProvider requestProvider = getRequestProviderByScope(scope); @@ -71,7 +80,35 @@ public class GeneratePayloadForCds { final String requestPayload = requestProvider.buildRequestPayload(action) .orElseThrow(() -> new PayloadGenerationException("Failed to build payload for CDS")); - final String requestId = execution.getGeneralBuildingBlock().getRequestContext().getMsoRequestId(); + return prepareAndSetCdsPropertyBean(requestProvider, requestPayload, requestId, action, DEFAULT_SYNC_MODE); + } + + /** + * Build properties like (blueprint name, version, action etc..) along with the request payload for pnf. + * + * @param execution - A building block execution object. + * @return AbstractCDSPropertiesBean - A POJO which contains CDS related information. + * @throws PayloadGenerationException - Throw an exception if it fails to build payload for CDS. + */ + public AbstractCDSPropertiesBean buildCdsPropertiesBean(DelegateExecution execution) + throws PayloadGenerationException { + + final String scope = String.valueOf(execution.getVariable(PayloadConstants.SCOPE)); + final String action = String.valueOf(execution.getVariable(PayloadConstants.ACTION)); + final String requestId = String.valueOf(execution.getVariable(MSO_REQUEST_ID)); + final String mode = extractAndSetMode(execution); + + CDSRequestProvider requestProvider = getRequestProviderByScope(scope); + requestProvider.setExecutionObject(execution); + + final String requestPayload = requestProvider.buildRequestPayload(action) + .orElseThrow(() -> new PayloadGenerationException("Failed to build payload for CDS")); + + return prepareAndSetCdsPropertyBean(requestProvider, requestPayload, requestId, action, mode); + } + + private AbstractCDSPropertiesBean prepareAndSetCdsPropertyBean(CDSRequestProvider requestProvider, + String requestPayload, String requestId, String action, String mode) { final AbstractCDSPropertiesBean cdsPropertiesBean = new AbstractCDSPropertiesBean(); cdsPropertiesBean.setRequestObject(requestPayload); cdsPropertiesBean.setBlueprintName(requestProvider.getBlueprintName()); @@ -80,23 +117,34 @@ public class GeneratePayloadForCds { cdsPropertiesBean.setOriginatorId(ORIGINATOR_ID); cdsPropertiesBean.setSubRequestId(UUID.randomUUID().toString()); cdsPropertiesBean.setActionName(action); - cdsPropertiesBean.setMode(MODE); - + cdsPropertiesBean.setMode(mode); return cdsPropertiesBean; } + private String extractAndSetMode(DelegateExecution execution) { + String mode = DEFAULT_SYNC_MODE; + Object obj = execution.getVariable(PayloadConstants.MODE); + if (obj != null && !String.valueOf(obj).isEmpty()) { + mode = String.valueOf(obj); + } + return mode; + } + private CDSRequestProvider getRequestProviderByScope(String scope) throws PayloadGenerationException { CDSRequestProvider requestProvider; switch (scope) { - case "vnf": + case PayloadConstants.VNF_SCOPE: requestProvider = vnfCDSRequestProvider; break; - case "vfModule": + case PayloadConstants.VF_MODULE_SCOPE: requestProvider = vfModuleCDSRequestProvider; break; - case "service": + case PayloadConstants.SERVICE_SCOPE: requestProvider = serviceCDSRequestProvider; break; + case PayloadConstants.PNF_SCOPE: + requestProvider = pnfCDSRequestProvider; + break; default: throw new PayloadGenerationException("No scope defined with " + scope); } diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/PayloadConstants.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/PayloadConstants.java index e758f548f7..808d427d65 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/PayloadConstants.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/PayloadConstants.java @@ -4,6 +4,8 @@ * ================================================================================ * Copyright (C) 2019 Bell Canada * ================================================================================ + * Modifications Copyright (C) 2020 Nordix + * ================================================================================ * 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 @@ -30,5 +32,22 @@ public final class PayloadConstants { public static final String PROPERTIES = "properties"; public static final String SCOPE = "scope"; public static final String ACTION = "action"; + public static final String MODE = "mode"; public static final String SEPARATOR = "-"; + public static final String PNF_SCOPE = "pnf"; + public static final String VNF_SCOPE = "vnf"; + public static final String VF_MODULE_SCOPE = "vfModule"; + public static final String SERVICE_SCOPE = "service"; + public static final String RESOLUTION_KEY = "resolution-key"; + public static final String CDS_ACTOR = "cds"; + + public static final String PRC_BLUEPRINT_NAME = "PRC_blueprintName"; + public static final String PRC_BLUEPRINT_VERSION = "PRC_blueprintVersion"; + public static final String PRC_CUSTOMIZATION_UUID = "PRC_customizationUuid"; + public static final String PRC_TARGET_SOFTWARE_VERSION = "targetSoftwareVersion"; + + public final static String PNF_CORRELATION_ID = "pnfCorrelationId"; + public final static String PNF_UUID = "pnfUuid"; + public final static String SERVICE_INSTANCE_ID = "serviceInstanceId"; + public final static String MODEL_UUID = "modelUuid"; } diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/PnfCDSRequestProvider.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/PnfCDSRequestProvider.java new file mode 100644 index 0000000000..86bca755ed --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/PnfCDSRequestProvider.java @@ -0,0 +1,78 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix + * ================================================================================ + * 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.client.cds; + +import com.google.gson.JsonObject; +import org.camunda.bpm.engine.delegate.DelegateExecution; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; +import java.util.Optional; +import static org.onap.so.client.cds.PayloadConstants.*; + +@Component +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +public class PnfCDSRequestProvider implements CDSRequestProvider { + private String blueprintName; + private String blueprintVersion; + private DelegateExecution execution; + + @Override + public String getBlueprintName() { + return blueprintName; + } + + @Override + public String getBlueprintVersion() { + return blueprintVersion; + } + + @Override + public <T> void setExecutionObject(T executionObject) { + execution = (DelegateExecution) executionObject; + } + + @Override + public Optional<String> buildRequestPayload(String action) { + + final JsonObject pnfObject = new JsonObject(); + final String resolutionKey = String.valueOf(execution.getVariable(PNF_CORRELATION_ID)); + blueprintName = String.valueOf(execution.getVariable(PRC_BLUEPRINT_NAME)); + blueprintVersion = String.valueOf(execution.getVariable(PRC_BLUEPRINT_VERSION)); + + extractAndSetExecutionVariable("service-instance-id", SERVICE_INSTANCE_ID, pnfObject); + extractAndSetExecutionVariable("service-model-uuid", MODEL_UUID, pnfObject); + extractAndSetExecutionVariable("pnf-id", PNF_UUID, pnfObject); + extractAndSetExecutionVariable("pnf-name", PNF_CORRELATION_ID, pnfObject); + extractAndSetExecutionVariable("pnf-customization-uuid", PRC_CUSTOMIZATION_UUID, pnfObject); + extractAndSetExecutionVariable("target-software-version", PRC_TARGET_SOFTWARE_VERSION, pnfObject); + + final JsonObject cdsPropertyObject = new JsonObject(); + cdsPropertyObject.addProperty(RESOLUTION_KEY, resolutionKey); + cdsPropertyObject.add(action + SEPARATOR + PROPERTIES, pnfObject); + + return Optional.of(buildRequestJsonObject(cdsPropertyObject, action)); + } + + private void extractAndSetExecutionVariable(String jsonProperty, String executionProperty, JsonObject pnfObject) { + if (execution.getVariable(executionProperty) != null) { + pnfObject.addProperty(jsonProperty, String.valueOf(execution.getVariable(executionProperty))); + } + } +} |