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.apache.commons.lang3.StringUtils;
27 import org.onap.so.bpmn.common.BuildingBlockExecution;
28 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
29 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
30 import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock;
31 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
32 import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
33 import org.onap.so.client.exception.PayloadGenerationException;
34 import org.springframework.beans.factory.annotation.Autowired;
35 import org.springframework.beans.factory.config.ConfigurableBeanFactory;
36 import org.springframework.context.annotation.Scope;
37 import org.springframework.stereotype.Component;
38 import java.util.List;
40 import java.util.Optional;
41 import static org.onap.so.client.cds.PayloadConstants.PROPERTIES;
42 import static org.onap.so.client.cds.PayloadConstants.SEPARATOR;
45 @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
46 public class VnfCDSRequestProvider implements CDSRequestProvider {
47 private String blueprintName;
48 private String blueprintVersion;
49 private BuildingBlockExecution execution;
52 private ExtractPojosForBB extractPojosForBB;
55 private ConfigureInstanceParamsForVnf configureInstanceParamsForVnf;
58 public String getBlueprintName() {
63 public String getBlueprintVersion() {
64 return blueprintVersion;
68 public <T> void setExecutionObject(T executionObject) {
69 execution = (BuildingBlockExecution) executionObject;
73 public Optional<String> buildRequestPayload(String action) throws PayloadGenerationException {
74 JsonObject cdsPropertyObject = new JsonObject();
75 JsonObject vnfObject = new JsonObject();
78 ServiceInstance serviceInstance =
79 extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
80 GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
82 final String modelCustomizationUuid = genericVnf.getModelInfoGenericVnf().getModelCustomizationUuid();
84 resolutionKey = genericVnf.getVnfName();
85 blueprintName = genericVnf.getModelInfoGenericVnf().getBlueprintName();
86 blueprintVersion = genericVnf.getModelInfoGenericVnf().getBlueprintVersion();
88 vnfObject.addProperty("service-instance-id", serviceInstance.getServiceInstanceId());
89 vnfObject.addProperty("service-model-uuid", serviceInstance.getModelInfoServiceInstance().getModelUuid());
90 vnfObject.addProperty("vnf-id", genericVnf.getVnfId());
91 vnfObject.addProperty("vnf-name", genericVnf.getVnfName());
92 vnfObject.addProperty("vnf-customization-uuid", modelCustomizationUuid);
94 final GeneralBuildingBlock buildingBlock = execution.getGeneralBuildingBlock();
95 List<Map<String, Object>> userParamsFromRequest =
96 buildingBlock.getRequestContext().getRequestParameters().getUserParams();
97 String vnfInstanceName = execution.getLookupMap().getOrDefault(ResourceKey.VNF_INSTANCE_NAME, "");
98 if (userParamsFromRequest != null && userParamsFromRequest.size() != 0) {
99 configureInstanceParamsForVnf.populateInstanceParams(vnfObject, userParamsFromRequest,
100 modelCustomizationUuid, vnfInstanceName);
102 } catch (Exception e) {
103 throw new PayloadGenerationException("Failed to buildPropertyObjectForVnf", e);
106 cdsPropertyObject.addProperty("resolution-key", resolutionKey);
107 cdsPropertyObject.add(action + SEPARATOR + PROPERTIES, vnfObject);
109 return Optional.of(buildRequestJsonObject(cdsPropertyObject, action));