Merge "Removal of unused local variables. Removal of unused local variables as per...
[so.git] / bpmn / so-bpmn-tasks / src / main / java / org / onap / so / bpmn / buildingblock / OofHomingV2.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2019 Intel Corp. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.so.bpmn.buildingblock;
22
23 import org.apache.commons.lang.SerializationUtils;
24 import org.apache.commons.lang.exception.ExceptionUtils;
25 import org.camunda.bpm.engine.delegate.BpmnError;
26 import java.util.ArrayList;
27 import org.json.JSONArray;
28 import org.json.JSONObject;
29 import org.onap.so.bpmn.common.BuildingBlockExecution;
30 import org.onap.so.bpmn.core.json.JsonUtils;
31 import org.onap.so.bpmn.servicedecomposition.bbobjects.AllottedResource;
32 import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
33 import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer;
34 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
35 import org.onap.so.bpmn.servicedecomposition.bbobjects.Pnf;
36 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
37 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceProxy;
38 import org.onap.so.bpmn.servicedecomposition.bbobjects.VpnBondingLink;
39 import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock;
40 import org.onap.so.bpmn.servicedecomposition.generalobjects.License;
41 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
42 import org.onap.so.bpmn.servicedecomposition.homingobjects.Candidate;
43 import org.onap.so.bpmn.servicedecomposition.homingobjects.CandidateType;
44 import org.onap.so.bpmn.servicedecomposition.homingobjects.SolutionCandidates;
45 import org.onap.so.bpmn.servicedecomposition.homingobjects.SolutionInfo;
46 import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoMetadata;
47 import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoServiceInstance;
48 import org.onap.so.client.exception.BadResponseException;
49 import org.onap.so.client.exception.ExceptionBuilder;
50 import org.onap.so.client.oof.OofClient;
51 import org.onap.so.client.oof.OofValidator;
52 import org.onap.so.client.oof.beans.LicenseDemand;
53 import org.onap.so.client.oof.beans.LicenseInfo;
54 import org.onap.so.client.oof.beans.ModelInfo;
55 import org.onap.so.client.oof.beans.OofRequest;
56 import org.onap.so.client.oof.beans.OofRequestParameters;
57 import org.onap.so.client.oof.beans.PlacementDemand;
58 import org.onap.so.client.oof.beans.PlacementInfo;
59 import org.onap.so.client.oof.beans.RequestInfo;
60 import org.onap.so.client.oof.beans.ServiceInfo;
61 import org.onap.so.client.oof.beans.SubscriberInfo;
62 import org.onap.so.db.catalog.beans.OrchestrationStatus;
63 import org.slf4j.Logger;
64 import org.slf4j.LoggerFactory;
65 import org.springframework.beans.factory.annotation.Autowired;
66 import org.springframework.core.env.Environment;
67 import org.springframework.stereotype.Component;
68 import org.springframework.web.util.UriUtils;
69 import java.time.Duration;
70 import java.util.List;
71 import java.util.Map;
72 import java.util.UUID;
73 import static org.apache.commons.lang3.StringUtils.isBlank;
74 import static org.apache.commons.lang3.StringUtils.isNotBlank;
75
76
77 /**
78  * The oof homing building block obtains licensing and homing solutions for a given resource or set of resources.
79  *
80  */
81 @Component("OofHoming")
82 public class OofHomingV2 {
83
84     public static final String ERROR_WHILE_PREPARING_OOF_REQUEST = " Error - while preparing oof request: ";
85     private static final Logger logger = LoggerFactory.getLogger(OofHomingV2.class);
86     private JsonUtils jsonUtils = new JsonUtils();
87     @Autowired
88     private Environment env;
89     @Autowired
90     private OofClient oofClient;
91     @Autowired
92     private OofValidator oofValidator;
93     @Autowired
94     private ExceptionBuilder exceptionUtil;
95     private static final String MODEL_INVARIANT_ID = "modelInvariantId";
96     private static final String MODEL_VERSION_ID = "modelVersionId";
97     private static final String SERVICE_RESOURCE_ID = "serviceResourceId";
98     private static final String IDENTIFIER_TYPE = "identifierType";
99     private static final String SOLUTIONS = "solutions";
100     private static final String RESOURCE_MISSING_DATA = "Resource does not contain: ";
101     private static final String SERVICE_MISSING_DATA = "Service Instance does not contain: ";
102     private static final String UNPROCESSABLE = "422";
103     private static final int INTERNAL = 500;
104
105     /**
106      * Generates the request payload then sends to Oof to perform homing and licensing for the provided demands
107      *
108      * @param execution
109      */
110     public void callOof(BuildingBlockExecution execution) {
111         logger.trace("Started Oof Homing Call Oof");
112         try {
113             GeneralBuildingBlock bb = execution.getGeneralBuildingBlock();
114
115             RequestContext requestContext = bb.getRequestContext();
116             String requestId = requestContext.getMsoRequestId();
117
118             ServiceInstance serviceInstance = bb.getCustomer().getServiceSubscription().getServiceInstances().get(0);
119             Customer customer = bb.getCustomer();
120
121             String timeout = execution.getVariable("timeout");
122             if (isBlank(timeout)) {
123                 timeout = env.getProperty("oof.timeout", "PT30M");
124             }
125
126             OofRequest oofRequest = new OofRequest();
127
128             RequestInfo requestInfo = buildRequestInfo(requestId, timeout);
129             oofRequest.setRequestInformation(requestInfo);
130
131             ServiceInfo serviceInfo = buildServiceInfo(serviceInstance);
132             oofRequest.setServiceInformation(serviceInfo);
133
134             PlacementInfo placementInfo = buildPlacementInfo(customer);
135
136             placementInfo = buildPlacementDemands(serviceInstance, placementInfo);
137             oofRequest.setPlacementInformation(placementInfo);
138
139             LicenseInfo licenseInfo = buildLicenseInfo(serviceInstance);
140             oofRequest.setLicenseInformation(licenseInfo);
141
142             if (!placementInfo.getPlacementDemands().isEmpty() || !licenseInfo.getLicenseDemands().isEmpty()) {
143                 oofClient.postDemands(oofRequest);
144             } else {
145                 logger.debug(SERVICE_MISSING_DATA + " resources eligible for homing or licensing");
146                 throw new BpmnError(UNPROCESSABLE,
147                         SERVICE_MISSING_DATA + " resources eligible for homing or licensing");
148             }
149
150             // Variables for ReceiveWorkflowMessage subflow
151             execution.setVariable("asyncCorrelator", requestId);
152             execution.setVariable("asyncMessageType", "OofResponse");
153             execution.setVariable("asyncTimeout", timeout);
154
155             logger.trace("Completed Oof Homing Call Oof");
156         } catch (BpmnError e) {
157             logger.debug(ERROR_WHILE_PREPARING_OOF_REQUEST + e.getStackTrace());
158             exceptionUtil.buildAndThrowWorkflowException(execution, Integer.parseInt(e.getErrorCode()), e.getMessage());
159         } catch (BadResponseException e) {
160             logger.debug(ERROR_WHILE_PREPARING_OOF_REQUEST + e.getStackTrace());
161             exceptionUtil.buildAndThrowWorkflowException(execution, 400, e.getMessage());
162         } catch (Exception e) {
163             logger.debug(ERROR_WHILE_PREPARING_OOF_REQUEST + e.getStackTrace());
164             exceptionUtil.buildAndThrowWorkflowException(execution, INTERNAL, "Internal Error - occurred while "
165                     + "preparing oof request: " + e + "   Stack:" + ExceptionUtils.getFullStackTrace(e));
166         }
167     }
168
169     /**
170      * Validates, processes, and sets the homing and licensing solutions that are returned by Oof
171      *
172      * @param execution
173      * @param asyncResponse
174      */
175     public void processSolution(BuildingBlockExecution execution, String asyncResponse) {
176         logger.trace("Started Oof Homing Process Solution");
177         try {
178             oofValidator.validateSolution(asyncResponse);
179             ServiceInstance serviceInstance = execution.getGeneralBuildingBlock().getCustomer().getServiceSubscription()
180                     .getServiceInstances().get(0);
181
182             logger.debug("Processing Oof asyncronous response");
183             JSONObject response = new JSONObject(asyncResponse);
184             if (response.has(SOLUTIONS)) {
185                 JSONObject allSolutions = response.getJSONObject(SOLUTIONS);
186                 if (allSolutions.has("placementSolutions")) {
187                     JSONArray placementSolutions = allSolutions.getJSONArray("placementSolutions");
188                     for (int i = 0; i < placementSolutions.length(); i++) {
189                         JSONArray placements = placementSolutions.getJSONArray(i);
190                         processPlacementSolution(serviceInstance, placements, i);
191                     }
192                 }
193                 if (allSolutions.has("licenseSolutions")) {
194                     JSONArray licenseSolutions = allSolutions.getJSONArray("licenseSolutions");
195                     if (licenseSolutions.length() > 0) {
196                         processLicenseSolution(serviceInstance, licenseSolutions);
197                     }
198                 }
199             } else {
200                 throw new BpmnError(UNPROCESSABLE, "Oof response does not contain: " + SOLUTIONS);
201             }
202
203             execution.setVariable("generalBuildingBlock", execution.getGeneralBuildingBlock());
204
205             logger.trace("Completed Oof Homing Process Solution");
206         } catch (BpmnError e) {
207             exceptionUtil.buildAndThrowWorkflowException(execution, Integer.parseInt(e.getErrorCode()), e.getMessage());
208         } catch (BadResponseException e) {
209             exceptionUtil.buildAndThrowWorkflowException(execution, 400, e.getMessage());
210         } catch (Exception e) {
211             exceptionUtil.buildAndThrowWorkflowException(execution, INTERNAL,
212                     "Internal Error - occurred while processing Oof asynchronous response: " + e.getMessage());
213         }
214     }
215
216     /**
217      * Builds the request information section for the homing/licensing request
218      *
219      * @throws Exception
220      */
221     private RequestInfo buildRequestInfo(String requestId, String timeout) throws Exception {
222         logger.trace("Building request information");
223         RequestInfo requestInfo = new RequestInfo();
224         if (requestId != null) {
225             String host = env.getProperty("mso.workflow.message.endpoint");
226             String callbackUrl = host + "/" + UriUtils.encodePathSegment("OofResponse", "UTF-8") + "/"
227                     + UriUtils.encodePathSegment(requestId, "UTF-8");
228
229             Duration d = Duration.parse(timeout);
230             long timeoutSeconds = d.getSeconds();
231
232             requestInfo.setTransactionId(requestId);
233             requestInfo.setRequestId(requestId);
234             requestInfo.setCallbackUrl(callbackUrl);
235             requestInfo.setSourceId("mso");
236             requestInfo.setRequestType("create");
237             requestInfo.setTimeout(timeoutSeconds);
238             requestInfo.setNumSolutions(1);
239             ArrayList optimizers = new ArrayList();
240             optimizers.add("placement");
241             requestInfo.setOptimizers(optimizers);
242         } else {
243             throw new BpmnError(UNPROCESSABLE, "Request Context does not contain: requestId");
244         }
245         return requestInfo;
246     }
247
248     /**
249      * Builds the request information section for the homing/licensing request
250      *
251      */
252     private ServiceInfo buildServiceInfo(ServiceInstance serviceInstance) {
253         logger.trace("Building service information");
254         ServiceInfo info = new ServiceInfo();
255         ModelInfoServiceInstance modelInfo = serviceInstance.getModelInfoServiceInstance();
256         if (isNotBlank(modelInfo.getModelInvariantUuid()) && isNotBlank(modelInfo.getModelUuid())) {
257             info.setServiceInstanceId(serviceInstance.getServiceInstanceId());
258             if (modelInfo.getServiceType() != null && modelInfo.getServiceType().length() > 0) { // temp solution
259                 info.setServiceName(modelInfo.getServiceType());
260             }
261             info.setModelInfo(buildModelInfo(serviceInstance.getModelInfoServiceInstance()));
262         } else {
263             throw new BpmnError(UNPROCESSABLE, SERVICE_MISSING_DATA + MODEL_VERSION_ID + ", " + MODEL_INVARIANT_ID);
264         }
265         return info;
266     }
267
268     /**
269      * Builds initial section of placement info for the homing/licensing request
270      *
271      */
272     private PlacementInfo buildPlacementInfo(Customer customer) {
273         PlacementInfo placementInfo = new PlacementInfo();
274         if (customer != null) {
275             logger.debug("Adding subscriber to placement information");
276             SubscriberInfo subscriberInfo = new SubscriberInfo();
277             subscriberInfo.setGlobalSubscriberId(customer.getGlobalCustomerId());
278             subscriberInfo.setSubscriberName(customer.getSubscriberName());
279             subscriberInfo.setSubscriberCommonSiteId(customer.getSubscriberCommonSiteId());
280             placementInfo.setSubscriberInfo(subscriberInfo);
281             OofRequestParameters oofRequestParams = new OofRequestParameters();
282             oofRequestParams.setCustomerLatitude(customer.getCustomerLatitude());
283             oofRequestParams.setCustomerLongitude(customer.getCustomerLongitude());
284             oofRequestParams.setCustomerName(customer.getSubscriberName());
285             placementInfo.setRequestParameters(oofRequestParams);
286         } else {
287             throw new BpmnError(UNPROCESSABLE, SERVICE_MISSING_DATA + "customer");
288         }
289         return placementInfo;
290
291     }
292
293     /**
294      * Builds the placement demand list for the homing/licensing request
295      *
296      */
297     private PlacementInfo buildPlacementDemands(ServiceInstance serviceInstance, PlacementInfo placementInfo) {
298         logger.trace("Building placement information demands");
299
300         List<AllottedResource> allottedResourceList = serviceInstance.getAllottedResources();
301         if (!allottedResourceList.isEmpty()) {
302             logger.debug("Adding allotted resources to placement demands list");
303             for (AllottedResource ar : allottedResourceList) {
304                 if (isBlank(ar.getId())) {
305                     ar.setId(UUID.randomUUID().toString());
306                 }
307                 PlacementDemand demand = buildDemand(ar.getId(), ar.getModelInfoAllottedResource());
308                 // addCandidates(ar, demand);
309                 placementInfo.getPlacementDemands().add(demand);
310             }
311         }
312         List<VpnBondingLink> vpnBondingLinkList = serviceInstance.getVpnBondingLinks();
313         if (!vpnBondingLinkList.isEmpty()) {
314             logger.debug("Adding vpn bonding links to placement demands list");
315             for (VpnBondingLink vbl : vpnBondingLinkList) {
316                 List<ServiceProxy> serviceProxyList = vbl.getServiceProxies();
317                 for (ServiceProxy sp : serviceProxyList) {
318                     if (isBlank(sp.getId())) {
319                         sp.setId(UUID.randomUUID().toString());
320                     }
321                     PlacementDemand demand = buildDemand(sp.getId(), sp.getModelInfoServiceProxy());
322                     // addCandidates(sp, demand);
323                     placementInfo.getPlacementDemands().add(demand);
324                 }
325             }
326         }
327         return placementInfo;
328     }
329
330     /**
331      * Builds the license demand list for the homing/licensing request
332      *
333      */
334     private LicenseInfo buildLicenseInfo(ServiceInstance serviceInstance) {
335         logger.trace("Building license information");
336         LicenseInfo licenseInfo = new LicenseInfo();
337         List<GenericVnf> vnfList = serviceInstance.getVnfs();
338         if (!vnfList.isEmpty()) {
339             logger.debug("Adding vnfs to license demands list");
340             for (GenericVnf vnf : vnfList) {
341                 LicenseDemand demand = buildLicenseDemand(vnf.getVnfId(), vnf.getModelInfoGenericVnf());
342                 licenseInfo.getLicenseDemands().add(demand);
343             }
344         }
345         return licenseInfo;
346     }
347
348     /**
349      * Builds a single license demand object
350      *
351      */
352     private LicenseDemand buildLicenseDemand(String id, ModelInfoMetadata metadata) {
353         logger.debug("Building demand for service or resource: " + id);
354         LicenseDemand demand = new LicenseDemand();
355         if (isNotBlank(id) && isNotBlank(metadata.getModelInstanceName())) {
356
357             demand.setServiceResourceId(id);
358             demand.setResourceModuleName(metadata.getModelInstanceName());
359             demand.setResourceModelInfo(buildModelInfo(metadata));
360         } else {
361             throw new BpmnError(UNPROCESSABLE, RESOURCE_MISSING_DATA + "modelInstanceName");
362         }
363         return demand;
364     }
365
366     /**
367      * Builds a single demand object
368      *
369      */
370     private PlacementDemand buildDemand(String id, ModelInfoMetadata metadata) {
371         logger.debug("Building demand for service or resource: " + id);
372         PlacementDemand placementDemand = new PlacementDemand();
373         if (isNotBlank(id) && isNotBlank(metadata.getModelInstanceName())) {
374             placementDemand.setServiceResourceId(id);
375             placementDemand.setResourceModuleName(metadata.getModelInstanceName());
376             placementDemand.setResourceModelInfo(buildModelInfo(metadata));
377         } else {
378             throw new BpmnError(UNPROCESSABLE, RESOURCE_MISSING_DATA + "modelInstanceName");
379         }
380         return placementDemand;
381     }
382
383     /**
384      * Builds the resource model info section
385      *
386      */
387     private ModelInfo buildModelInfo(ModelInfoMetadata metadata) {
388         ModelInfo modelInfo = new ModelInfo();
389         String invariantUuid = metadata.getModelInvariantUuid();
390         String modelUuid = metadata.getModelUuid();
391         if (isNotBlank(invariantUuid) && isNotBlank(modelUuid)) {
392             modelInfo.setModelInvariantId(invariantUuid);
393             modelInfo.setModelVersionId(modelUuid);
394             modelInfo.setModelName(metadata.getModelName());
395             modelInfo.setModelVersion(metadata.getModelVersion());
396         } else if (isNotBlank(invariantUuid)) {
397             throw new BpmnError(UNPROCESSABLE, RESOURCE_MISSING_DATA + MODEL_VERSION_ID);
398         } else {
399             throw new BpmnError(UNPROCESSABLE, RESOURCE_MISSING_DATA + MODEL_INVARIANT_ID);
400         }
401         return modelInfo;
402     }
403
404     /**
405      * Adds required, excluded, and existing candidates to a demand
406      *
407      */
408     private void addCandidates(SolutionCandidates candidates, JSONObject demand) {
409         List<Candidate> required = candidates.getRequiredCandidates();
410         List<Candidate> excluded = candidates.getExcludedCandidates();
411         if (!required.isEmpty()) {
412             demand.put("requiredCandidates", required);
413         }
414         if (!excluded.isEmpty()) {
415             demand.put("excludedCandidates", excluded);
416         }
417         // TODO support existing candidates
418     }
419
420     /**
421      * Processes the license solutions and sets to the corresponding generic vnf
422      *
423      */
424     private void processLicenseSolution(ServiceInstance serviceInstance, JSONArray licenseSolutions) {
425         List<GenericVnf> vnfs = serviceInstance.getVnfs();
426
427         logger.debug("Processing the license solution");
428         for (int i = 0; i < licenseSolutions.length(); i++) {
429             JSONObject licenseSolution = licenseSolutions.getJSONObject(i);
430             for (GenericVnf vnf : vnfs) {
431                 if (licenseSolution.getString(SERVICE_RESOURCE_ID).equals(vnf.getVnfId())) {
432                     License license = new License();
433                     JSONArray entitlementPools = licenseSolution.getJSONArray("entitlementPoolUUID");
434                     List<String> entitlementPoolsList = jsonUtils.StringArrayToList(entitlementPools);
435                     license.setEntitlementPoolUuids(entitlementPoolsList);
436                     JSONArray licenseKeys = licenseSolution.getJSONArray("licenseKeyGroupUUID");
437                     List<String> licenseKeysList = jsonUtils.StringArrayToList(licenseKeys);
438                     license.setLicenseKeyGroupUuids(licenseKeysList);
439
440                     vnf.setLicense(license);
441                 }
442             }
443         }
444     }
445
446     /**
447      * Processes a placement solution list then correlates and sets each placement solution to its corresponding
448      * resource
449      *
450      */
451     private void processPlacementSolution(ServiceInstance serviceInstance, JSONArray placements, int i) {
452         List<VpnBondingLink> links = serviceInstance.getVpnBondingLinks();
453         List<AllottedResource> allottes = serviceInstance.getAllottedResources();
454         List<GenericVnf> vnfs = serviceInstance.getVnfs();
455
456         logger.debug("Processing placement solution " + i + 1);
457         for (int p = 0; p < placements.length(); p++) {
458             JSONObject placement = placements.getJSONObject(p);
459             SolutionInfo solutionInfo = new SolutionInfo();
460             solutionInfo.setSolutionId(i + 1);
461             search: {
462                 for (VpnBondingLink vbl : links) {
463                     List<ServiceProxy> proxies = vbl.getServiceProxies();
464                     for (ServiceProxy sp : proxies) {
465                         if (placement.getString(SERVICE_RESOURCE_ID).equals(sp.getId())) {
466                             if (i > 0) {
467                                 if (p % 2 == 0) {
468                                     VpnBondingLink vblNew = (VpnBondingLink) SerializationUtils.clone(vbl);
469                                     vblNew.setVpnBondingLinkId(UUID.randomUUID().toString());
470                                     links.add(vblNew);
471                                 }
472                                 links.get(links.size() - 1).getServiceProxy(sp.getId())
473                                         .setServiceInstance(setSolution(solutionInfo, placement));
474                             } else {
475                                 sp.setServiceInstance(setSolution(solutionInfo, placement));
476                             }
477                             break search;
478                         }
479                     }
480                 }
481                 for (AllottedResource ar : allottes) {
482                     if (placement.getString(SERVICE_RESOURCE_ID).equals(ar.getId())) {
483                         ar.setParentServiceInstance(setSolution(solutionInfo, placement));
484                         break search;
485                     }
486                 }
487                 for (GenericVnf vnf : vnfs) {
488                     if (placement.getString(SERVICE_RESOURCE_ID).equals(vnf.getVnfId())) {
489                         ServiceInstance si = setSolution(solutionInfo, placement);
490                         serviceInstance.setSolutionInfo(si.getSolutionInfo());
491                         serviceInstance.getVnfs().add(si.getVnfs().get(0));
492                         break search;
493                     }
494                 }
495             }
496         }
497     }
498
499
500     /**
501      * Creates and sets necessary pojos with placement solution data for a given demand
502      *
503      */
504     private ServiceInstance setSolution(SolutionInfo solutionInfo, JSONObject placement) {
505         logger.debug("Mapping placement solution");
506         String invalidMessage = "Oof Response contains invalid: ";
507
508         JSONObject solution = placement.getJSONObject("solution");
509         String identifierType = solution.getString(IDENTIFIER_TYPE);
510         List<String> identifiersList = jsonUtils.StringArrayToList(solution.getJSONArray("identifiers").toString());
511         String identifierValue = identifiersList.get(0);
512
513         JSONArray assignments = placement.getJSONArray("assignmentInfo");
514         Map<String, String> assignmentsMap = jsonUtils.entryArrayToMap(assignments.toString(), "key", "value");
515         solutionInfo.setRehome(Boolean.parseBoolean(assignmentsMap.get("isRehome")));
516         String type = identifierType;
517
518         ServiceInstance si = new ServiceInstance();
519         CloudRegion cloud = setCloud(assignmentsMap);
520         if (type.equals("serviceInstanceId")) {
521             if (identifierType.equals(CandidateType.SERVICE_INSTANCE_ID.toString())) {
522                 solutionInfo.setHomed(true);
523                 si.setServiceInstanceId(identifierValue);
524                 si.setOrchestrationStatus(OrchestrationStatus.CREATED);
525                 cloud.setLcpCloudRegionId(assignmentsMap.get("cloudRegionId"));
526                 if (assignmentsMap.containsKey("vnfHostName")) {
527                     logger.debug("Resources has been homed to a vnf");
528                     GenericVnf vnf = setVnf(assignmentsMap);
529                     vnf.setCloudRegion(cloud);
530                     si.getVnfs().add(vnf);
531
532                 } else if (assignmentsMap.containsKey("primaryPnfName")) {
533                     logger.debug("Resources has been homed to a pnf");
534                     Pnf priPnf = setPnf(assignmentsMap, "primary");
535                     priPnf.setCloudRegion(cloud);
536                     si.getPnfs().add(priPnf);
537                     if (assignmentsMap.containsKey("secondaryPnfName")) {
538                         Pnf secPnf = setPnf(assignmentsMap, "secondary");
539                         secPnf.setCloudRegion(cloud);
540                         si.getPnfs().add(secPnf);
541                     }
542                 }
543             } else {
544                 logger.debug(invalidMessage + IDENTIFIER_TYPE);
545                 throw new BpmnError(UNPROCESSABLE, invalidMessage + IDENTIFIER_TYPE);
546             }
547         } else if (type.equals("cloudRegionId")) {
548             if (identifierType.equals(CandidateType.CLOUD_REGION_ID.toString())) {
549                 logger.debug("Resources has been homed to a cloud region");
550                 cloud.setLcpCloudRegionId(identifierValue);
551                 solutionInfo.setHomed(false);
552                 solutionInfo.setTargetedCloudRegion(cloud);
553                 si.setOrchestrationStatus(OrchestrationStatus.PRECREATED);
554             } else {
555                 logger.debug(invalidMessage + IDENTIFIER_TYPE);
556                 throw new BpmnError(UNPROCESSABLE, invalidMessage + IDENTIFIER_TYPE);
557             }
558         }
559         si.setSolutionInfo(solutionInfo);
560         return si;
561     }
562
563     /**
564      * Sets the cloud data to a cloud region object
565      *
566      */
567     private CloudRegion setCloud(Map<String, String> assignmentsMap) {
568         CloudRegion cloud = new CloudRegion();
569         cloud.setCloudOwner(assignmentsMap.get("cloudOwner"));
570         cloud.setCloudRegionVersion(assignmentsMap.get("aicVersion"));
571         cloud.setComplex(assignmentsMap.get("aicClli"));
572         return cloud;
573     }
574
575     /**
576      * Sets the vnf data to a generic vnf object
577      *
578      */
579     private GenericVnf setVnf(Map<String, String> assignmentsMap) {
580         GenericVnf vnf = new GenericVnf();
581         vnf.setOrchestrationStatus(OrchestrationStatus.CREATED);
582         vnf.setVnfName(assignmentsMap.get("vnfHostName"));
583         vnf.setVnfId(assignmentsMap.get("vnfId"));
584         return vnf;
585     }
586
587     /**
588      * Sets the pnf data to a pnf object
589      *
590      */
591     private Pnf setPnf(Map<String, String> assignmentsMap, String role) {
592         Pnf pnf = new Pnf();
593         pnf.setRole(role);
594         pnf.setOrchestrationStatus(OrchestrationStatus.CREATED);
595         pnf.setPnfName(assignmentsMap.get(role + "PnfName"));
596         return pnf;
597     }
598
599
600
601 }