2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 Bell Canada
6 * ================================================================================
7 * Modifications Copyright (c) 2020 Tech Mahindra
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
23 package org.onap.so.client.cds;
25 import com.google.gson.JsonObject;
26 import org.onap.so.bpmn.common.BuildingBlockExecution;
27 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
28 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
29 import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock;
30 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
31 import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
32 import org.onap.so.client.exception.PayloadGenerationException;
33 import org.springframework.beans.factory.annotation.Autowired;
34 import org.springframework.beans.factory.config.ConfigurableBeanFactory;
35 import org.springframework.context.annotation.Scope;
36 import org.springframework.stereotype.Component;
37 import java.util.List;
39 import java.util.Optional;
40 import static org.onap.so.client.cds.PayloadConstants.PROPERTIES;
41 import static org.onap.so.client.cds.PayloadConstants.SEPARATOR;
44 @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
45 public class VnfCDSRequestProvider implements CDSRequestProvider {
46 private String blueprintName;
47 private String blueprintVersion;
48 private BuildingBlockExecution execution;
51 private ExtractPojosForBB extractPojosForBB;
54 private ConfigureInstanceParamsForVnf configureInstanceParamsForVnf;
57 public String getBlueprintName() {
62 public String getBlueprintVersion() {
63 return blueprintVersion;
67 public <T> void setExecutionObject(T executionObject) {
68 execution = (BuildingBlockExecution) executionObject;
72 public Optional<String> buildRequestPayload(String action) throws PayloadGenerationException {
73 JsonObject cdsPropertyObject = new JsonObject();
74 JsonObject vnfObject = new JsonObject();
77 ServiceInstance serviceInstance =
78 extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
79 GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
81 final String modelCustomizationUuid = genericVnf.getModelInfoGenericVnf().getModelCustomizationUuid();
83 resolutionKey = genericVnf.getVnfName();
84 blueprintName = genericVnf.getModelInfoGenericVnf().getBlueprintName();
85 blueprintVersion = genericVnf.getModelInfoGenericVnf().getBlueprintVersion();
87 vnfObject.addProperty("service-instance-id", serviceInstance.getServiceInstanceId());
88 vnfObject.addProperty("service-model-uuid", serviceInstance.getModelInfoServiceInstance().getModelUuid());
89 vnfObject.addProperty("vnf-id", genericVnf.getVnfId());
90 vnfObject.addProperty("vnf-name", genericVnf.getVnfName());
91 vnfObject.addProperty("vnf-customization-uuid", modelCustomizationUuid);
93 final GeneralBuildingBlock buildingBlock = execution.getGeneralBuildingBlock();
94 List<Map<String, Object>> userParamsFromRequest =
95 buildingBlock.getRequestContext().getRequestParameters().getUserParams();
96 if (userParamsFromRequest != null && userParamsFromRequest.size() != 0) {
97 configureInstanceParamsForVnf.populateInstanceParams(vnfObject, userParamsFromRequest,
98 modelCustomizationUuid);
100 } catch (Exception e) {
101 throw new PayloadGenerationException("Failed to buildPropertyObjectForVnf", e);
104 cdsPropertyObject.addProperty("resolution-key", resolutionKey);
105 cdsPropertyObject.add(action + SEPARATOR + PROPERTIES, vnfObject);
107 return Optional.of(buildRequestJsonObject(cdsPropertyObject, action));