2 * Copyright (c) 2018 Orange
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 * in compliance with the License. You may obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software distributed under the License
10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11 * or implied. See the License for the specific language governing permissions and limitations under
15 package org.onap.nbi.apis.serviceorder.workflow;
17 import java.io.IOException;
18 import java.util.ArrayList;
19 import java.util.HashMap;
20 import java.util.Iterator;
21 import java.util.List;
23 import java.util.Map.Entry;
24 import java.util.stream.Collectors;
26 import org.onap.nbi.apis.servicecatalog.ServiceSpecificationService;
27 import org.onap.nbi.apis.serviceorder.SoClient;
28 import org.onap.nbi.apis.serviceorder.model.ServiceCharacteristic;
29 import org.onap.nbi.apis.serviceorder.model.ServiceOrder;
30 import org.onap.nbi.apis.serviceorder.model.ServiceOrderItem;
31 import org.onap.nbi.apis.serviceorder.model.StateType;
32 import org.onap.nbi.apis.serviceorder.model.ServiceStateType;
33 import org.onap.nbi.apis.serviceorder.model.consumer.CloudConfiguration;
34 import org.onap.nbi.apis.serviceorder.model.consumer.CreateE2EServiceInstanceResponse;
35 import org.onap.nbi.apis.serviceorder.model.consumer.CreateMacroServiceInstanceResponse;
36 import org.onap.nbi.apis.serviceorder.model.consumer.CreateServiceInstanceResponse;
37 import org.onap.nbi.apis.serviceorder.model.consumer.MSOE2EPayload;
38 import org.onap.nbi.apis.serviceorder.model.consumer.MSOPayload;
39 import org.onap.nbi.apis.serviceorder.model.consumer.ModelInfo;
40 import org.onap.nbi.apis.serviceorder.model.consumer.OwningEntity;
41 import org.onap.nbi.apis.serviceorder.model.consumer.ParametersModel;
42 import org.onap.nbi.apis.serviceorder.model.consumer.Project;
43 import org.onap.nbi.apis.serviceorder.model.consumer.RequestDetails;
44 import org.onap.nbi.apis.serviceorder.model.consumer.RequestInfo;
45 import org.onap.nbi.apis.serviceorder.model.consumer.RequestParameters;
46 import org.onap.nbi.apis.serviceorder.model.consumer.ResourceModel;
47 import org.onap.nbi.apis.serviceorder.model.consumer.ServiceModel;
48 import org.onap.nbi.apis.serviceorder.model.consumer.SubscriberInfo;
49 import org.onap.nbi.apis.serviceorder.model.consumer.UserParams;
50 import org.onap.nbi.apis.serviceorder.model.consumer.VFModelInfo;
51 import org.onap.nbi.apis.serviceorder.model.orchestrator.ServiceOrderInfo;
52 import org.onap.nbi.apis.serviceorder.service.ServiceOrderService;
53 import org.slf4j.Logger;
54 import org.slf4j.LoggerFactory;
55 import org.springframework.beans.factory.annotation.Autowired;
56 import org.springframework.beans.factory.annotation.Value;
57 import org.springframework.http.ResponseEntity;
58 import org.springframework.stereotype.Service;
59 import org.springframework.util.CollectionUtils;
60 import com.fasterxml.jackson.databind.JsonNode;
61 import com.fasterxml.jackson.databind.ObjectMapper;
62 import com.fasterxml.jackson.databind.node.ArrayNode;
63 import com.fasterxml.jackson.databind.node.ObjectNode;
66 public class PostSoProcessor {
68 private static final Logger LOGGER = LoggerFactory.getLogger(PostSoProcessor.class);
70 @Value("${onap.lcpCloudRegionId}")
71 private String lcpCloudRegionId;
73 @Value("${onap.tenantId}")
74 private String tenantId;
76 @Value("${so.owning.entity.id}")
77 private String soOwningEntityId;
79 @Value("${so.owning.entity.name}")
80 private String soOwningEntityName;
82 @Value("${so.project.name}")
83 private String soProjectName;
85 @Value("${onap.cloudOwner}")
86 private String cloudOwner;
88 @Value("${onap.k8sCloudOwner}")
89 private String k8sCloudOwner;
91 @Value("${onap.k8sCloudRegionId}")
92 private String k8sCloudRegionId;
94 @Value("${k8s-rb-profile-name}")
95 private String k8sRbProfileName;
98 private ServiceOrderService serviceOrderService;
101 private SoClient soClient;
104 ServiceSpecificationService serviceSpecificationService;
106 public ResponseEntity<CreateServiceInstanceResponse> postServiceOrderItem(ServiceOrderInfo serviceOrderInfo,
107 ServiceOrderItem serviceOrderItem) {
108 ResponseEntity<CreateServiceInstanceResponse> response = null;
110 response = postSORequest(serviceOrderItem, serviceOrderInfo);
111 } catch (NullPointerException e) {
112 LOGGER.error("Unable to create service instance for serviceOrderItem.id=" + serviceOrderItem.getId(), e);
118 public ResponseEntity<CreateE2EServiceInstanceResponse> postE2EServiceOrderItem(ServiceOrderInfo serviceOrderInfo,
119 ServiceOrderItem serviceOrderItem, ServiceOrder serviceOrder) {
120 ResponseEntity<CreateE2EServiceInstanceResponse> response;
122 response = postE2ESORequest(serviceOrderItem, serviceOrderInfo, serviceOrder);
123 } catch (NullPointerException e) {
124 LOGGER.error("Unable to create service instance for serviceOrderItem.id=" + serviceOrderItem.getId(), e);
130 public ResponseEntity<CreateMacroServiceInstanceResponse> postMacroServiceOrderItem(ServiceOrderInfo serviceOrderInfo,
131 ServiceOrderItem serviceOrderItem) {
132 ResponseEntity<CreateMacroServiceInstanceResponse> response = null;
135 response = postSOMacroRequest(serviceOrderItem, serviceOrderInfo);
136 } catch (NullPointerException e) {
137 LOGGER.error("Unable to create service instance for serviceOrderItem.id=" + serviceOrderItem.getId(), e);
143 private ResponseEntity<CreateServiceInstanceResponse> postSORequest(ServiceOrderItem serviceOrderItem,
144 ServiceOrderInfo serviceOrderInfo) {
145 RequestDetails requestDetails = buildSoRequest(serviceOrderItem, serviceOrderInfo);
146 MSOPayload msoPayload = new MSOPayload(requestDetails);
147 ResponseEntity<CreateServiceInstanceResponse> response = null;
149 switch (serviceOrderItem.getAction()) {
151 response = soClient.callCreateServiceInstance(msoPayload);
154 response = soClient.callDeleteServiceInstance(msoPayload, serviceOrderItem.getService().getId());
157 if (StateType.INPROGRESS_MODIFY_ITEM_TO_CREATE == serviceOrderItem.getState()) {
158 response = soClient.callCreateServiceInstance(msoPayload);
160 if (StateType.ACKNOWLEDGED == serviceOrderItem.getState()) {
161 response = soClient.callDeleteServiceInstance(msoPayload, serviceOrderItem.getService().getId());
170 private ResponseEntity<CreateE2EServiceInstanceResponse> postE2ESORequest(ServiceOrderItem serviceOrderItem,
171 ServiceOrderInfo serviceOrderInfo, ServiceOrder serviceOrder) {
172 ServiceModel service = buildE2ESoRequest(serviceOrderItem,
173 serviceOrderInfo.getServiceOrderItemInfos().get(serviceOrderItem.getId()).getCatalogResponse(),
174 serviceOrderInfo.getSubscriberInfo(), serviceOrder);
175 MSOE2EPayload msoE2EPayload = new MSOE2EPayload(service);
176 ResponseEntity<CreateE2EServiceInstanceResponse> response = null;
177 switch (serviceOrderItem.getAction()) {
179 response = soClient.callE2ECreateServiceInstance(msoE2EPayload);
182 response = soClient.callE2EDeleteServiceInstance(service.getGlobalSubscriberId(),
183 service.getServiceType(), serviceOrderItem.getService().getId());
186 //EXT-API supports E2E service activation/deactivation with action=modify and seviceState=active/inactive
187 boolean isActivateReq = ServiceStateType.ACTIVE == serviceOrderItem.getService().getServiceState() ||
188 ServiceStateType.INACTIVE == serviceOrderItem.getService().getServiceState();
190 if (ServiceStateType.ACTIVE == serviceOrderItem.getService().getServiceState()) {
191 response = soClient.callServiceActivationE2EService(service.getGlobalSubscriberId(),
192 service.getServiceType(), serviceOrderItem.getService().getId(),"activate");
194 if (ServiceStateType.INACTIVE == serviceOrderItem.getService().getServiceState()) {
195 response = soClient.callServiceActivationE2EService(service.getGlobalSubscriberId(),
196 service.getServiceType(), serviceOrderItem.getService().getId(),"deactivate");
198 //Other E2E service modification follows Deletion followed by activation.
199 //For service modification, do not send serviceState=active/inactive
200 if (!isActivateReq && StateType.INPROGRESS_MODIFY_ITEM_TO_CREATE == serviceOrderItem.getState()) {
201 response = soClient.callE2ECreateServiceInstance(msoE2EPayload);
203 if (!isActivateReq && StateType.ACKNOWLEDGED == serviceOrderItem.getState()) {
204 response = soClient.callE2EDeleteServiceInstance(service.getGlobalSubscriberId(),
205 service.getServiceType(), serviceOrderItem.getService().getId());
214 private ResponseEntity<CreateMacroServiceInstanceResponse> postSOMacroRequest(ServiceOrderItem serviceOrderItem,
215 ServiceOrderInfo serviceOrderInfo) {
217 String serviceModuleName = (String) serviceOrderInfo.getServiceOrderItemInfos().get(serviceOrderItem.getId())
218 .getCatalogResponse().get("name");
220 RequestDetails requestDetails = buildSoMacroRequest(serviceOrderItem, serviceOrderInfo);
221 MSOPayload msoMacroPayload = new MSOPayload(requestDetails);
222 ResponseEntity<CreateMacroServiceInstanceResponse> response = null;
224 switch (serviceOrderItem.getAction()) {
226 response = soClient.callMacroCreateServiceInstance(msoMacroPayload);
229 response = soClient.callMacroDeleteServiceInstance(msoMacroPayload,
230 serviceOrderItem.getService().getId());
233 if (StateType.INPROGRESS_MODIFY_ITEM_TO_CREATE == serviceOrderItem.getState()) {
234 // response = soClient.callCreateServiceInstance(msoPayload);
236 if (StateType.ACKNOWLEDGED == serviceOrderItem.getState()) {
237 // response = soClient.callDeleteServiceInstance(msoPayload,
238 // serviceOrderItem.getService().getId());
248 * Build SO MACRO CREATE request from the ServiceOrder and catalog informations from SDC
251 * @param serviceOrderInfo
252 * @param subscriberInfo
255 private RequestDetails buildSoMacroRequest(ServiceOrderItem orderItem, ServiceOrderInfo serviceOrderInfo) {
257 RequestDetails requestDetails = new RequestDetails();
258 Map<String, Object> sdcInfos = serviceOrderInfo.getServiceOrderItemInfos().get(orderItem.getId())
259 .getCatalogResponse();
261 String id = orderItem.getService().getServiceSpecification().getId();
262 Map responseChildRes = serviceSpecificationService.get(id);
263 ArrayList<Map<String, Object>> resourseSpecificationArray = (ArrayList<Map<String, Object>>) responseChildRes
264 .get("resourceSpecification");
266 Map<String, Object> resourseSpecificationMap = resourseSpecificationArray.get(0);
268 Map serviceInstanceParam = (Map) resourseSpecificationMap.get("serviceInstanceParams");
269 Map instanceSpecification = (Map) resourseSpecificationMap.get("InstanceSpecification");
270 ArrayList<VFModelInfo> childResourceSpecification = (ArrayList<VFModelInfo>) resourseSpecificationMap
271 .get("childResourceSpecification");
273 HashMap<String, Object> instanceParamsFromServiceCharacteristics = retrieveInstanceParamsFromServiceCharacteristics(
274 orderItem.getService().getServiceCharacteristic());
276 HashMap<String, Object> instanceParams = (HashMap<String, Object>) buildAndDistinguishServiceAndVnfLevelParams(
277 instanceParamsFromServiceCharacteristics, instanceSpecification, serviceInstanceParam);
279 HashMap<String, Object> vnfInstanceParams = (HashMap<String, Object>) instanceParams.get("vnf");
280 List<Object> serviceObject = new ArrayList<>();
282 ArrayList<Object> vnfInstanceParam = new ArrayList<>();
284 //Differentiating vnf with cnf(Can be discussed and improved)
285 if (instanceSpecification.get("public_net_id") != null) {
286 Map<String, Object> instanceParam = new HashMap<>();
287 //Merge instanceSpecification with vnfInstanceParams
288 instanceSpecification.putAll(vnfInstanceParams);
289 vnfInstanceParam.add(instanceSpecification);
291 //if skip_post_instantiation_configuration is true then add k8s-rb-profile-name
292 if(instanceSpecification.get("skip_post_instantiation_configuration").equals(true))
293 vnfInstanceParams.put("k8s-rb-profile-name", k8sRbProfileName);
294 vnfInstanceParam.add(vnfInstanceParams);
297 List resSpec = (ArrayList) sdcInfos.get("resourceSpecification");
298 Map resSpecMap = (Map) resSpec.get(0);
300 Map<String, String> vnfInfoObject = new HashMap<>();
301 vnfInfoObject.put("modelName", (String) resSpecMap.get("name"));
302 vnfInfoObject.put("modelVersionId", (String) resSpecMap.get("id"));
303 vnfInfoObject.put("modelInvariantUuid", (String) resSpecMap.get("resourceInvariantUUID"));
304 vnfInfoObject.put("modelVersion", (String) resSpecMap.get("version"));
305 vnfInfoObject.put("modelCustomizationId", (String) resSpecMap.get("modelCustomizationId"));
306 vnfInfoObject.put("modelInstanceName", (String) resSpecMap.get("resourceInstanceName"));
309 CloudConfiguration cloudConfiguration = null;
311 //Differentiating vnf with cnf(Can be discussed and improved)
312 if (instanceSpecification.get("public_net_id") != null) {
313 cloudConfiguration = new CloudConfiguration(lcpCloudRegionId, tenantId, cloudOwner);
315 cloudConfiguration = new CloudConfiguration(k8sCloudRegionId, tenantId, k8sCloudOwner);
318 Map<String, String> platformName = new HashMap<>();
319 platformName.put("platformName", "test");
321 Map<String, String> lob = new HashMap<>();
322 lob.put("lineOfBusinessName", "LOB-Demonstration");
324 Map<String, Object> vnfModel = new HashMap<>();
325 vnfModel.put("modelInfo", vnfInfoObject);
326 vnfModel.put("cloudConfiguration", cloudConfiguration);
327 vnfModel.put("platform", platformName);
328 vnfModel.put("lineOfBusiness", lob);
329 vnfModel.put("productFamilyId", "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb");
330 vnfModel.put("instanceName", (String) resSpecMap.get("resourceInstanceName"));
331 vnfModel.put("instanceParams", vnfInstanceParam);
333 List<Object> vfModulesObjects = new ArrayList<>();
334 ArrayList<Map<String, Object>> vfInstanceParam = new ArrayList<>();
336 //Differentiate CNF from VNF
337 if (instanceSpecification.get("public_net_id") != null) {
338 vfInstanceParam.add(instanceSpecification);
341 Map<String, Object> instanceParam = new HashMap<>();
342 if(instanceSpecification.get("skip_post_instantiation_configuration").equals(true))
343 instanceParam.put("k8s-rb-profile-name", k8sRbProfileName);
344 vfInstanceParam.add(instanceParam);
347 for (VFModelInfo crsObject : childResourceSpecification) {
348 Map<String, Object> vfModuleObject = new HashMap<>();
349 Map<String, String> vfModuleInfo = new HashMap<>();
351 vfModuleInfo.put("modelName", crsObject.getModelName());
352 vfModuleInfo.put("modelVersionId", crsObject.getModelUuid());
353 vfModuleInfo.put("modelInvariantUuid", crsObject.getModelInvariantUuid());
354 vfModuleInfo.put("modelVersion", crsObject.getModelVersion());
355 vfModuleInfo.put("modelCustomizationId", crsObject.getModelCustomizationUuid());
356 vfModuleObject.put("modelInfo", vfModuleInfo);
357 vfModuleObject.put("instanceName", crsObject.getModelName());
358 vfModuleObject.put("instanceParams", vfInstanceParam);
360 vfModulesObjects.add(vfModuleObject);
362 vnfModel.put("vfModules", vfModulesObjects);
364 List<Object> vnfObjects = new ArrayList<>();
365 vnfObjects.add(vnfModel);
367 Map<String, Object> vnfData = new HashMap<>();
368 vnfData.put("vnfs", vnfObjects);
370 ModelInfo serviceModelInfo = new ModelInfo();
371 serviceModelInfo.setModelType("service");
372 serviceModelInfo.setModelInvariantId((String) sdcInfos.get("invariantUUID"));
373 serviceModelInfo.setModelVersionId(orderItem.getService().getServiceSpecification().getId());
374 serviceModelInfo.setModelName((String) sdcInfos.get("name"));
375 serviceModelInfo.setModelVersion((String) sdcInfos.get("version"));
377 // Adding List of instanceParams for service
378 // We can add instanceParams Key Value in Map Object and add it to the List, for
379 // For now it is empty to comply with so request
381 List<Map<String, String>> listOfServiceLevelInstanceParams = new ArrayList<>();
382 Map<String, String> serviceInstanceParams = (HashMap<String, String>) instanceParams.get("service");
383 listOfServiceLevelInstanceParams.add(serviceInstanceParams);
385 Map<String, Object> serviceData = new HashMap<>();
386 serviceData.put("instanceParams", listOfServiceLevelInstanceParams);
387 serviceData.put("instanceName", orderItem.getService().getName());
388 serviceData.put("resources", vnfData);
389 serviceData.put("modelInfo", serviceModelInfo);
391 Map<String, String> homingObject = new HashMap<>();
392 homingObject.put("Homing_Solution", "none");
393 serviceObject.add(homingObject);
395 Map<String, Object> serviceObject1 = new HashMap<>();
396 serviceObject1.put("service", serviceData);
397 serviceObject.add(serviceObject1);
398 requestDetails.setSubscriberInfo(serviceOrderInfo.getSubscriberInfo());
400 ModelInfo modelInfo = new ModelInfo();
401 modelInfo.setModelType("service");
402 modelInfo.setModelInvariantId((String) sdcInfos.get("invariantUUID"));
403 modelInfo.setModelVersionId(orderItem.getService().getServiceSpecification().getId());
404 modelInfo.setModelName((String) sdcInfos.get("name"));
405 modelInfo.setModelVersion((String) sdcInfos.get("version"));
406 requestDetails.setModelInfo(modelInfo);
408 RequestInfo requestInfo = new RequestInfo();
409 requestInfo.setInstanceName(orderItem.getService().getName());
410 requestInfo.setSource("VID");
411 requestInfo.setSuppressRollback(false);
412 requestInfo.setRequestorId("NBI");
413 requestInfo.setProductFamilyId("a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb");
414 requestDetails.setRequestInfo(requestInfo);
416 // We are taking RequestParameters as map because it has UserParams which gives value as
417 // "name" : "service"
418 // "value" : "", which SO is not accepting
419 Map<String, Object> requestParameters = new HashMap<>();
421 // Get value from serviceOrder request or generate one
422 String serviceTypeFromJson = orderItem.getService().getServicetype();
423 requestParameters.put("subscriptionServiceType",
424 serviceTypeFromJson != null ? serviceTypeFromJson : (String) sdcInfos.get("name"));
425 requestParameters.put("userParams", serviceObject);
426 requestParameters.put("aLaCarte", false);
427 requestDetails.setRequestParameters(requestParameters);
428 requestDetails.setCloudConfiguration(cloudConfiguration);
430 OwningEntity owningEntity = new OwningEntity();
431 owningEntity.setOwningEntityId(soOwningEntityId);
432 owningEntity.setOwningEntityName(soOwningEntityName);
433 requestDetails.setOwningEntity(owningEntity);
435 Project project = new Project();
436 project.setProjectName(soProjectName);
438 requestDetails.setProject(project);
439 return requestDetails;
443 * Build SO CREATE request from the ServiceOrder and catalog informations from SDC
446 * @param serviceOrderInfo
449 private RequestDetails buildSoRequest(ServiceOrderItem orderItem, ServiceOrderInfo serviceOrderInfo) {
450 RequestDetails requestDetails = new RequestDetails();
452 requestDetails.setSubscriberInfo(serviceOrderInfo.getSubscriberInfo());
453 Map<String, Object> sdcInfos =
454 serviceOrderInfo.getServiceOrderItemInfos().get(orderItem.getId()).getCatalogResponse();
455 ModelInfo modelInfo = new ModelInfo();
456 modelInfo.setModelType("service");
457 modelInfo.setModelInvariantId((String) sdcInfos.get("invariantUUID"));
458 modelInfo.setModelNameVersionId(orderItem.getService().getServiceSpecification().getId());
459 modelInfo.setModelVersionId(orderItem.getService().getServiceSpecification().getId());
460 modelInfo.setModelName((String) sdcInfos.get("name"));
461 modelInfo.setModelVersion((String) sdcInfos.get("version"));
462 requestDetails.setModelInfo(modelInfo);
464 RequestInfo requestInfo = new RequestInfo();
465 requestInfo.setInstanceName(orderItem.getService().getName());
466 requestInfo.setSource("VID");
467 requestInfo.setSuppressRollback(false);
468 requestInfo.setRequestorId("NBI");
469 requestDetails.setRequestInfo(requestInfo);
471 RequestParameters requestParameters = new RequestParameters();
473 String serviceTypeFromJson = orderItem.getService().getServicetype();
474 requestParameters.setSubscriptionServiceType(serviceTypeFromJson != null ? serviceTypeFromJson:(String) sdcInfos.get("name"));
475 requestParameters.setUserParams(
476 retrieveUserParamsFromServiceCharacteristics(orderItem.getService().getServiceCharacteristic()));
477 requestParameters.setaLaCarte(true);
478 requestParameters.setTestApi("GR_API");
479 requestDetails.setRequestParameters(requestParameters);
481 CloudConfiguration cloudConfiguration = new CloudConfiguration(lcpCloudRegionId, tenantId, cloudOwner);
482 requestDetails.setCloudConfiguration(cloudConfiguration);
484 OwningEntity owningEntity = new OwningEntity();
485 owningEntity.setOwningEntityId(serviceOrderInfo.getOwningEntityId());
486 owningEntity.setOwningEntityName(soOwningEntityName);
487 requestDetails.setOwningEntity(owningEntity);
489 Project project = new Project();
490 project.setProjectName(soProjectName);
492 requestDetails.setProject(project);
494 return requestDetails;
498 * Build E2E SO CREATE request from the ServiceOrder and catalog informations from SDC
500 * @param serviceOrderItem
501 * @param serviceOrder
505 // ServiceOrderItem serviceOrderItem --> orderItem?
506 private ServiceModel buildE2ESoRequest(ServiceOrderItem serviceOrderItem, Map<String, Object> sdcInfos,
507 SubscriberInfo subscriberInfo, ServiceOrder serviceOrder) {
509 subscriberInfo.getGlobalSubscriberId();
510 ServiceModel service = new ServiceModel();
511 service.setName(serviceOrderItem.getService().getName());
512 service.setDescription(serviceOrder.getDescription());
513 service.setServiceUuid(serviceOrderItem.getService().getServiceSpecification().getId());
514 service.setServiceInvariantUuid((String) sdcInfos.get("invariantUUID"));
515 service.setGlobalSubscriberId(subscriberInfo.getGlobalSubscriberId());
516 String serviceTypeFromJson = serviceOrderItem.getService().getServicetype();
517 service.setServiceType(serviceTypeFromJson != null ? serviceTypeFromJson : (String) sdcInfos.get("name"));
518 ParametersModel parameters = new ParametersModel();
519 ArrayList<ResourceModel> resources = new ArrayList();
521 ArrayList<Object> resourceObjects = (ArrayList<Object>) sdcInfos.get("resourceSpecification");
523 for (int i = 0; i < resourceObjects.size(); i++) {
525 ResourceModel resourceModel = new ResourceModel((Map<String, Object>) resourceObjects.get(i));
526 ParametersModel resourceParameters = new ParametersModel();
527 resourceModel.setParameters(resourceParameters);
528 resources.add(resourceModel);
531 parameters.setResources(resources);
532 List<UserParams> userParams =
533 retrieveUserParamsFromServiceCharacteristics(serviceOrderItem.getService().getServiceCharacteristic());
535 // If there are ServiceCharacteristics add them to requestInputs
536 if (!userParams.isEmpty()) {
537 Map<String, String> requestInputs = new HashMap<String, String>();
538 for (int i = 0; i < userParams.size(); i++) {
539 requestInputs.put(userParams.get(i).getName(), (String) userParams.get(i).getValue());
542 parameters.setRequestInputs(requestInputs);
544 service.setParameters(parameters);
550 * Build a list of UserParams for the SO request by browsing a list of ServiceCharacteristics from
553 private List<UserParams> retrieveUserParamsFromServiceCharacteristics(List<ServiceCharacteristic> characteristics) {
554 List<UserParams> userParams = new ArrayList<>();
555 UserParams userParam;
557 if (!CollectionUtils.isEmpty(characteristics)) {
558 for (ServiceCharacteristic characteristic : characteristics) {
559 // Check is the characteristic is of type object, if proceed as before to allow for
560 // backwards compatibility.
561 if (characteristic.getValueType() != null && !characteristic.getValueType().isEmpty()
562 && characteristic.getValueType().equals("object")) {
563 ObjectMapper mapper = new ObjectMapper();
564 JsonNode jsonNode = null;
566 jsonNode = mapper.readTree(characteristic.getValue().getServiceCharacteristicValue());
567 } catch (IOException e) {
568 LOGGER.error("Failed to read object json {} , exception is ",
569 characteristic.getValue().getServiceCharacteristicValue(), e.getMessage());
571 ObjectNode objectNode = (ObjectNode) jsonNode;
572 Iterator<Map.Entry<String, JsonNode>> iter = objectNode.fields();
573 while (iter.hasNext()) {
574 Map.Entry<String, JsonNode> entry = iter.next();
575 if (!entry.getValue().isArray()) {
576 userParam = new UserParams(entry.getKey(), entry.getValue().asText());
578 ArrayNode arrayNode = (ArrayNode) entry.getValue();
579 String arrayNodeValueString = arrayNode.toString();
580 userParam = new UserParams(entry.getKey(), arrayNodeValueString);
582 userParams.add(userParam);
585 // as UserParams for all other types, boolean, string, integer etc
587 userParam = new UserParams(characteristic.getName(),
588 characteristic.getValue().getServiceCharacteristicValue());
589 userParams.add(userParam);
598 * Build a list of InstanceParams for the SO Macro request by browsing a list of
599 * ServiceCharacteristics
601 private HashMap<String, Object> retrieveInstanceParamsFromServiceCharacteristics(
602 List<ServiceCharacteristic> characteristics) {
604 HashMap<String, Object> instanceParams = new HashMap<>();
606 if (!CollectionUtils.isEmpty(characteristics)) {
607 for (ServiceCharacteristic characteristic : characteristics) {
608 // Check is the characteristic is of type object, if proceed as before to allow
610 // backwards compatibility.
611 if (characteristic.getValueType() != null && !characteristic.getValueType().isEmpty()
612 && characteristic.getValueType().equals("object")) {
613 ObjectMapper mapper = new ObjectMapper();
614 JsonNode jsonNode = null;
616 jsonNode = mapper.readTree(characteristic.getValue().getServiceCharacteristicValue());
617 } catch (IOException e) {
618 LOGGER.error("Failed to read object json {} , exception is ",
619 characteristic.getValue().getServiceCharacteristicValue(), e.getMessage());
621 ObjectNode objectNode = (ObjectNode) jsonNode;
622 Iterator<Map.Entry<String, JsonNode>> iter = objectNode.fields();
623 while (iter.hasNext()) {
624 Map.Entry<String, JsonNode> entry = iter.next();
625 if (!entry.getValue().isArray()) {
626 instanceParams.put(entry.getKey(), entry.getValue().asText());
628 ArrayNode arrayNode = (ArrayNode) entry.getValue();
629 String arrayNodeValueString = arrayNode.toString();
630 instanceParams.put(entry.getKey(), arrayNodeValueString);
634 instanceParams.put(characteristic.getName(),
635 characteristic.getValue().getServiceCharacteristicValue());
640 return instanceParams;
644 * Build and distinguish InstanceParams at VNF Level and Service level and overwrite values from ServiceOrder JSON Request.
645 * Can be used as buildAndDistinguishServiceAndVnfLevelParams.get("vnf"); or buildAndDistinguishServiceAndVnfLevelParams.get("cnf");
647 private Map<String, Object> buildAndDistinguishServiceAndVnfLevelParams(
648 Map<String, Object> instanceParamsFromServiceCharacteristic, Map<String, Object> existingVNFParams,
649 Map<String, Object> existingServiceParams) {
651 //To be used by passing key as "vnf" or "service" for respective instanceParams
652 Map<String, Object> serviceAndVNFLevelInstanceParams = new HashMap<>();
654 Map<String, Object> resultVNFParams = new HashMap<>();
655 Map<String, Object> resultServiceParams = new HashMap<>();
657 // First Filter VNF level Params From Service Characteristics and overwrite
659 resultVNFParams = instanceParamsFromServiceCharacteristic.entrySet().stream()
660 .filter(entry -> existingVNFParams.containsKey(entry.getKey()))
661 .collect(Collectors.toMap(Entry::getKey, Entry::getValue));
663 //Add it as VNF level Params
664 serviceAndVNFLevelInstanceParams.put("vnf", resultVNFParams);
666 // Filter VNF level Params From Service Level
667 existingServiceParams.entrySet().removeIf(e -> existingVNFParams.containsKey(e.getKey()));
669 // Filter Service level Params From Service Characteristics and overwrite values
670 resultServiceParams = instanceParamsFromServiceCharacteristic.entrySet().stream()
671 .filter(entry -> existingServiceParams.containsKey(entry.getKey()))
672 .collect(Collectors.toMap(Entry::getKey, Entry::getValue));
674 //Add it as Service level params
675 serviceAndVNFLevelInstanceParams.put("service", resultServiceParams);
677 return serviceAndVNFLevelInstanceParams;