Dynamic Cloud Owner Support
[so.git] / bpmn / so-bpmn-tasks / src / main / java / org / onap / so / bpmn / buildingblock / SniroHomingV2.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 - 2018 AT&T Intellectual Property. 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 static org.apache.commons.lang3.StringUtils.*;
24
25 import java.time.Duration;
26 import java.util.List;
27 import java.util.Map;
28 import java.util.UUID;
29
30 import org.apache.commons.lang.SerializationUtils;
31 import org.camunda.bpm.engine.delegate.BpmnError;
32 import org.camunda.bpm.engine.delegate.DelegateExecution;
33 import org.json.JSONArray;
34 import org.json.JSONObject;
35 import org.onap.so.bpmn.common.BuildingBlockExecution;
36 import org.onap.so.bpmn.core.json.JsonUtils;
37 import org.onap.so.bpmn.servicedecomposition.bbobjects.AllottedResource;
38 import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
39 import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer;
40 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
41 import org.onap.so.bpmn.servicedecomposition.bbobjects.Pnf;
42 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
43 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceProxy;
44 import org.onap.so.bpmn.servicedecomposition.bbobjects.VpnBondingLink;
45 import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock;
46 import org.onap.so.bpmn.servicedecomposition.generalobjects.License;
47 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
48 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestParameters;
49 import org.onap.so.bpmn.servicedecomposition.homingobjects.Candidate;
50 import org.onap.so.bpmn.servicedecomposition.homingobjects.CandidateType;
51 import org.onap.so.bpmn.servicedecomposition.homingobjects.SolutionCandidates;
52 import org.onap.so.bpmn.servicedecomposition.homingobjects.SolutionInfo;
53 import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoMetadata;
54 import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoServiceInstance;
55 import org.onap.so.client.exception.BadResponseException;
56 import org.onap.so.client.exception.ExceptionBuilder;
57
58 import org.onap.so.client.sniro.SniroClient;
59 import static org.onap.so.client.sniro.SniroValidator.*;
60
61 import org.onap.so.client.sniro.beans.SniroManagerRequest;
62 import org.onap.so.db.catalog.beans.OrchestrationStatus;
63 import org.onap.so.logger.MsoLogger;
64 import org.springframework.beans.factory.annotation.Autowired;
65 import org.springframework.core.env.Environment;
66 import org.springframework.stereotype.Component;
67 import org.springframework.web.util.UriUtils;
68
69
70 /**
71  * The sniro homing building block obtains licensing and homing solutions for a given
72  * resource or set of resources.
73  *
74  * @author cb645j
75  *
76  */
77 @Component("SniroHoming")
78 public class SniroHomingV2 {
79
80         private static final MsoLogger log = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, SniroHomingV2.class);
81         private JsonUtils jsonUtils = new JsonUtils();
82         @Autowired
83         private Environment env;
84         @Autowired
85         private SniroClient client;
86         @Autowired
87         private ExceptionBuilder exceptionUtil;
88         private static final String MODEL_NAME = "modelName";
89         private static final String MODEL_INVARIANT_ID = "modelInvariantId";
90         private static final String MODEL_VERSION_ID = "modelVersionId";
91         private static final String MODEL_VERSION = "modelVersion";
92         private static final String SERVICE_RESOURCE_ID = "serviceResourceId";
93         private static final String RESOURCE_MODULE_NAME = "resourceModuleName";
94         private static final String RESOURCE_MODEL_INFO = "resourceModelInfo";
95         private static final String IDENTIFIER_TYPE = "identifierType";
96         private static final String INVENTORY_TYPE = "inventoryType";
97         private static final String SOLUTIONS = "solutions";
98         private static final String RESOURCE_MISSING_DATA = "Resource does not contain: ";
99         private static final String SERVICE_MISSING_DATA = "Service Instance does not contain: ";
100         private static final String UNPROCESSABLE = "422";
101         private static final int INTERNAL = 500;
102
103         /**
104          * Generates the request payload then sends to sniro manager to perform homing and
105          * licensing for the provided demands
106          *
107          * @param execution
108          */
109         public void callSniro(BuildingBlockExecution execution){
110                 log.trace("Started Sniro Homing Call Sniro");
111                 try{
112                         GeneralBuildingBlock bb = execution.getGeneralBuildingBlock();
113
114                         RequestContext requestContext = bb.getRequestContext();
115                         RequestParameters requestParams = requestContext.getRequestParameters();
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("sniro.manager.timeout", "PT30M");
124                         }
125
126                         SniroManagerRequest request = new SniroManagerRequest(); //TODO Add additional pojos for each section
127
128                         JSONObject requestInfo = buildRequestInfo(requestId, timeout);
129                         request.setRequestInformation(requestInfo.toString());
130
131                         JSONObject serviceInfo = buildServiceInfo(serviceInstance);
132                         request.setServiceInformation(serviceInfo.toString());
133
134                         JSONObject placementInfo = buildPlacementInfo(customer, requestParams);
135
136                         JSONArray placementDemands = buildPlacementDemands(serviceInstance);
137                         placementInfo.put("placementDemands", placementDemands);
138                         request.setPlacementInformation(placementInfo.toString());
139
140                         JSONObject licenseInfo = new JSONObject();
141
142                         JSONArray licenseDemands = buildLicenseDemands(serviceInstance);
143                         licenseInfo.put("licenseDemands", licenseDemands);
144                         request.setLicenseInformation(licenseInfo.toString());
145
146                         if(placementDemands.length() > 0 || licenseDemands.length() > 0){
147                                 client.postDemands(request);
148                         }else{
149                                 log.debug(SERVICE_MISSING_DATA + "resources eligible for homing or licensing");
150                                 throw new BpmnError(UNPROCESSABLE, SERVICE_MISSING_DATA + "resources eligible for homing or licensing");
151                         }
152
153                         //Variables for ReceiveWorkflowMessage subflow
154                         execution.setVariable("asyncCorrelator", requestId);
155                         execution.setVariable("asyncMessageType", "SNIROResponse");
156                         execution.setVariable("asyncTimeout", timeout);
157
158                         log.trace("Completed Sniro Homing Call Sniro");
159                 }catch(BpmnError e){
160                         exceptionUtil.buildAndThrowWorkflowException(execution, Integer.parseInt(e.getErrorCode()), e.getMessage());
161                 }catch(BadResponseException e){
162                         exceptionUtil.buildAndThrowWorkflowException(execution, 400, e.getMessage());
163                 }catch(Exception e){
164                         exceptionUtil.buildAndThrowWorkflowException(execution, INTERNAL, "Internal Error - occurred while preparing sniro request: " + e.getMessage());
165                 }
166         }
167
168         /**
169          * Validates, processes, and sets the homing and licensing solutions that are returned by
170          * sniro manager
171          *
172          * @param execution
173          * @param asyncResponse
174          */
175         public void processSolution(BuildingBlockExecution execution, String asyncResponse){
176                 log.trace("Started Sniro Homing Process Solution");
177                 try{
178                         //TODO improve handling multiple solutions but is dependent on sniro enhancing api + work with sniro conductor to improve "inventoryType" representation
179                         validateSolution(asyncResponse);
180                         ServiceInstance serviceInstance = execution.getGeneralBuildingBlock().getCustomer().getServiceSubscription().getServiceInstances().get(0);
181
182                         log.debug("Processing sniro manager 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, "Sniro Managers response does not contain: " + SOLUTIONS);
201                         }
202
203                         execution.setVariable("generalBuildingBlock", execution.getGeneralBuildingBlock());
204
205                         log.trace("Completed Sniro 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, "Internal Error - occurred while processing sniro asynchronous response: " + e.getMessage());
212                 }
213         }
214
215         /**
216          * Builds the request information section for the homing/licensing request
217          *
218          * @throws Exception
219          */
220         private JSONObject buildRequestInfo(String requestId, String timeout) throws Exception{
221                 log.trace("Building request information");
222                 JSONObject requestInfo = new JSONObject();
223                 if(requestId != null){
224                         String host = env.getProperty("mso.workflow.message.endpoint");
225                         String callbackUrl = host + "/" + UriUtils.encodePathSegment("SNIROResponse", "UTF-8") + "/" + UriUtils.encodePathSegment(requestId, "UTF-8");
226
227                         Duration d = Duration.parse(timeout);
228                         long timeoutSeconds = d.getSeconds();
229
230                         requestInfo.put("transactionId", requestId).put("requestId", requestId).put("callbackUrl", callbackUrl).put("sourceId", "mso").put("requestType", "create")
231                                         .put("timeout", timeoutSeconds);
232                 } else{
233                         throw new BpmnError(UNPROCESSABLE, "Request Context does not contain: requestId");
234                 }
235                 return requestInfo;
236         }
237
238         /**
239          * Builds the request information section for the homing/licensing request
240          *
241          */
242         private JSONObject buildServiceInfo(ServiceInstance serviceInstance){
243                 log.trace("Building service information");
244                 JSONObject info = new JSONObject();
245                 ModelInfoServiceInstance modelInfo = serviceInstance.getModelInfoServiceInstance();
246                 if(isNotBlank(modelInfo.getModelInvariantUuid()) && isNotBlank(modelInfo.getModelUuid())){
247                         info.put("serviceInstanceId", serviceInstance.getServiceInstanceId());
248                         if(modelInfo.getServiceType() != null && modelInfo.getServiceType().length() > 0){ //temp solution
249                                 info.put("serviceName", modelInfo.getServiceType());
250                         }
251                         info.put("modelInfo", buildModelInfo(serviceInstance.getModelInfoServiceInstance()));
252                 }else{
253                         throw new BpmnError(UNPROCESSABLE, SERVICE_MISSING_DATA + MODEL_VERSION_ID + ", " + MODEL_INVARIANT_ID);
254                 }
255                 return info;
256         }
257
258         /**
259          * Builds initial section of placement info for the homing/licensing request
260          *
261          */
262         private JSONObject buildPlacementInfo(Customer customer, RequestParameters requestParams){
263                 JSONObject placementInfo = new JSONObject();
264                 if(customer != null){
265                         log.debug("Adding subscriber to placement information");
266                         placementInfo.put("subscriberInfo", new JSONObject().put("globalSubscriberId", customer.getGlobalCustomerId()).put("subscriberName", customer.getSubscriberName()).put("subscriberCommonSiteId", customer.getSubscriberCommonSiteId()));
267                         if(requestParams != null){
268                                 log.debug("Adding request parameters to placement information");
269                                 placementInfo.put("requestParameters", new JSONObject(requestParams.toJsonString()));
270                         }
271                 }else{
272                         throw new BpmnError(UNPROCESSABLE, SERVICE_MISSING_DATA + "customer");
273                 }
274                 return placementInfo;
275
276         }
277
278         /**
279          * Builds the placement demand list for the homing/licensing request
280          *
281          */
282         private JSONArray buildPlacementDemands(ServiceInstance serviceInstance){
283                 log.trace("Building placement information demands");
284                 JSONArray placementDemands = new JSONArray();
285
286                 List<AllottedResource> allottedResourceList = serviceInstance.getAllottedResources();
287                 if(!allottedResourceList.isEmpty()){
288                         log.debug("Adding allotted resources to placement demands list");
289                         for(AllottedResource ar : allottedResourceList){
290                                 if(isBlank(ar.getId())){
291                                         ar.setId(UUID.randomUUID().toString());
292                                 }
293                                 JSONObject demand = buildDemand(ar.getId(), ar.getModelInfoAllottedResource());
294                                 addCandidates(ar, demand);
295                                 placementDemands.put(demand);
296                         }
297                 }
298                 List<VpnBondingLink> vpnBondingLinkList = serviceInstance.getVpnBondingLinks();
299                 if(!vpnBondingLinkList.isEmpty()){
300                         log.debug("Adding vpn bonding links to placement demands list");
301                         for(VpnBondingLink vbl:vpnBondingLinkList){
302                                 List<ServiceProxy> serviceProxyList = vbl.getServiceProxies();
303                                 for(ServiceProxy sp : serviceProxyList){
304                                         if(isBlank(sp.getId())){
305                                                 sp.setId(UUID.randomUUID().toString());
306                                         }
307                                         JSONObject demand = buildDemand(sp.getId(), sp.getModelInfoServiceProxy());
308                                         addCandidates(sp, demand);
309                                         placementDemands.put(demand);
310                                 }
311                         }
312                 }
313                 return placementDemands;
314         }
315
316         /**
317          * Builds the license demand list for the homing/licensing request
318          *
319          */
320         private JSONArray buildLicenseDemands(ServiceInstance serviceInstance){
321                 log.trace("Building license information");
322                 JSONArray licenseDemands = new JSONArray();
323                 List<GenericVnf> vnfList = serviceInstance.getVnfs();
324                 if(!vnfList.isEmpty()){
325                         log.debug("Adding vnfs to license demands list");
326                         for(GenericVnf vnf : vnfList){
327                                 JSONObject demand = buildDemand(vnf.getVnfId(), vnf.getModelInfoGenericVnf());
328                                 licenseDemands.put(demand);
329                         }
330                 }
331                 return licenseDemands;
332         }
333
334         /**
335          * Builds a single demand object
336          *
337          */
338         private JSONObject buildDemand(String id, ModelInfoMetadata metadata){
339                 log.debug("Building demand for service or resource: " + id);
340                 JSONObject demand = new JSONObject();
341                 if(isNotBlank(id) && isNotBlank(metadata.getModelInstanceName())){
342                         demand.put(SERVICE_RESOURCE_ID, id);
343                         demand.put(RESOURCE_MODULE_NAME, metadata.getModelInstanceName());
344                         demand.put(RESOURCE_MODEL_INFO, buildModelInfo(metadata));
345                 }else{
346                         throw new BpmnError(UNPROCESSABLE, RESOURCE_MISSING_DATA + "modelInstanceName");
347                 }
348                 return demand;
349         }
350
351         /**
352          * Builds the resource model info section
353          *
354          */
355         private JSONObject buildModelInfo(ModelInfoMetadata metadata){
356                 JSONObject object = new JSONObject();
357                 String invariantUuid = metadata.getModelInvariantUuid();
358                 String modelUuid = metadata.getModelUuid();
359                 if(isNotBlank(invariantUuid) && isNotBlank(modelUuid)){
360                         object.put(MODEL_INVARIANT_ID, invariantUuid).put(MODEL_VERSION_ID, modelUuid).put(MODEL_NAME, metadata.getModelName()).put(MODEL_VERSION, metadata.getModelVersion());
361                 }else if(isNotBlank(invariantUuid)){
362                         throw new BpmnError(UNPROCESSABLE, RESOURCE_MISSING_DATA + MODEL_VERSION_ID);
363                 }else{
364                         throw new BpmnError(UNPROCESSABLE, RESOURCE_MISSING_DATA + MODEL_INVARIANT_ID);
365                 }
366                 return object;
367         }
368
369         /**
370          * Adds required, excluded, and existing candidates to a demand
371          *
372          */
373         private void addCandidates(SolutionCandidates candidates, JSONObject demand){
374                 List<Candidate> required = candidates.getRequiredCandidates();
375                 List<Candidate> excluded = candidates.getExcludedCandidates();
376                 if(!required.isEmpty()){
377                         demand.put("requiredCandidates", required);
378                 }
379                 if(!excluded.isEmpty()){
380                         demand.put("excludedCandidates", excluded);
381                 }
382                 //TODO support existing candidates
383         }
384
385         /**
386          * Processes the license solutions and sets to the corresponding generic vnf
387          *
388          */
389         private void processLicenseSolution(ServiceInstance serviceInstance, JSONArray licenseSolutions){
390                 List<GenericVnf> vnfs = serviceInstance.getVnfs();
391
392                 log.debug("Processing the license solution");
393                 for(int i = 0; i < licenseSolutions.length(); i++){
394                         JSONObject licenseSolution = licenseSolutions.getJSONObject(i);
395                         for(GenericVnf vnf:vnfs){
396                                 if(licenseSolution.getString(SERVICE_RESOURCE_ID).equals(vnf.getVnfId())){
397                                         License license = new License();
398                                         JSONArray entitlementPools = licenseSolution.getJSONArray("entitlementPoolUUID");
399                                         List<String> entitlementPoolsList = jsonUtils.StringArrayToList(entitlementPools);
400                                         license.setEntitlementPoolUuids(entitlementPoolsList);
401                                         JSONArray licenseKeys = licenseSolution.getJSONArray("licenseKeyGroupUUID");
402                                         List<String> licenseKeysList = jsonUtils.StringArrayToList(licenseKeys);
403                                         license.setLicenseKeyGroupUuids(licenseKeysList);
404
405                                         vnf.setLicense(license);
406                                 }
407                         }
408                 }
409         }
410
411         /**
412          * Processes a placement solution list then correlates and sets each placement solution
413          * to its corresponding resource
414          *
415          */
416         private void processPlacementSolution(ServiceInstance serviceInstance, JSONArray placements, int i){
417                 List<VpnBondingLink> links = serviceInstance.getVpnBondingLinks();
418                 List<AllottedResource> allottes = serviceInstance.getAllottedResources();
419                 List<GenericVnf> vnfs = serviceInstance.getVnfs();
420
421                 log.debug("Processing placement solution " + i+1);
422                 for(int p = 0; p < placements.length(); p++){
423                         JSONObject placement = placements.getJSONObject(p);
424                         SolutionInfo solutionInfo = new SolutionInfo();
425                         solutionInfo.setSolutionId(i + 1);
426                         search: {
427                                 for(VpnBondingLink vbl:links){
428                                         List<ServiceProxy> proxies = vbl.getServiceProxies();
429                                         for(ServiceProxy sp:proxies){
430                                                 if(placement.getString(SERVICE_RESOURCE_ID).equals(sp.getId())){
431                                                         if(i > 0){
432                                                                 if(p % 2 == 0){
433                                                                         VpnBondingLink vblNew = (VpnBondingLink) SerializationUtils.clone(vbl);
434                                                                         vblNew.setVpnBondingLinkId(UUID.randomUUID().toString());
435                                                                         links.add(vblNew);
436                                                                 }
437                                                                 links.get(links.size() - 1).getServiceProxy(sp.getId()).setServiceInstance(setSolution(solutionInfo, placement));
438                                                         }else{
439                                                                 sp.setServiceInstance(setSolution(solutionInfo, placement));
440                                                         }
441                                                         break search;
442                                                 }
443                                         }
444                                 }
445                                 for(AllottedResource ar:allottes){
446                                         if(placement.getString(SERVICE_RESOURCE_ID).equals(ar.getId())){
447                                                 ar.setParentServiceInstance(setSolution(solutionInfo, placement));
448                                                 break search;
449                                         }
450                                 }
451                                 for(GenericVnf vnf:vnfs){
452                                         if(placement.getString(SERVICE_RESOURCE_ID).equals(vnf.getVnfId())){
453                                                 ServiceInstance si = setSolution(solutionInfo, placement);
454                                                 serviceInstance.setSolutionInfo(si.getSolutionInfo());
455                                                 serviceInstance.getVnfs().add(si.getVnfs().get(0));
456                                                 break search;
457                                         }
458                                 }
459                         }
460                 }
461         }
462
463
464         /**
465          * Creates and sets necessary pojos with placement solution data for a given demand
466          *
467          */
468         private ServiceInstance setSolution(SolutionInfo solutionInfo, JSONObject placement){
469                 log.debug("Mapping placement solution");
470                 String invalidMessage = "Sniro Managers Response contains invalid: ";
471
472                 JSONObject solution = placement.getJSONObject("solution");
473                 String identifierType = solution.getString(IDENTIFIER_TYPE);
474                 List<String> identifiersList = jsonUtils.StringArrayToList(solution.getJSONArray("identifiers").toString());
475                 String identifierValue = identifiersList.get(0);
476
477                 JSONArray assignments = placement.getJSONArray("assignmentInfo");
478                 Map<String, String> assignmentsMap = jsonUtils.entryArrayToMap(assignments.toString(), "key", "value");
479                 solutionInfo.setRehome(Boolean.parseBoolean(assignmentsMap.get("isRehome")));
480                 String type = placement.getString(INVENTORY_TYPE);
481
482                 ServiceInstance si = new ServiceInstance();
483                 CloudRegion cloud = setCloud(assignmentsMap);
484                 if(type.equals("service")){
485                         if(identifierType.equals(CandidateType.SERVICE_INSTANCE_ID.toString())){
486                                 solutionInfo.setHomed(true);
487                                 si.setServiceInstanceId(identifierValue);
488                                 si.setOrchestrationStatus(OrchestrationStatus.CREATED);
489                                 cloud.setLcpCloudRegionId(assignmentsMap.get("cloudRegionId"));
490                                 if(assignmentsMap.containsKey("vnfHostName")){
491                                         log.debug("Resources has been homed to a vnf");
492                                         GenericVnf vnf = setVnf(assignmentsMap);
493                                         vnf.setCloudRegion(cloud);
494                                         si.getVnfs().add(vnf);
495
496                                 }else if(assignmentsMap.containsKey("primaryPnfName")){
497                                         log.debug("Resources has been homed to a pnf");
498                                         Pnf priPnf = setPnf(assignmentsMap, "primary");
499                                         priPnf.setCloudRegion(cloud);
500                                         si.getPnfs().add(priPnf);
501                                         if(assignmentsMap.containsKey("secondaryPnfName")){
502                                                 Pnf secPnf = setPnf(assignmentsMap, "secondary");
503                                                 secPnf.setCloudRegion(cloud);
504                                                 si.getPnfs().add(secPnf);
505                                         }
506                                 }
507                         }else{
508                                 log.debug(invalidMessage + IDENTIFIER_TYPE);
509                                 throw new BpmnError(UNPROCESSABLE, invalidMessage + IDENTIFIER_TYPE);
510                         }
511                 }else if(type.equals("cloud")){
512                         if(identifierType.equals(CandidateType.CLOUD_REGION_ID.toString())){
513                                 log.debug("Resources has been homed to a cloud region");
514                                 cloud.setLcpCloudRegionId(identifierValue);
515                                 solutionInfo.setHomed(false);
516                                 solutionInfo.setTargetedCloudRegion(cloud);
517                                 si.setOrchestrationStatus(OrchestrationStatus.PRECREATED);
518                         }else{
519                                 log.debug(invalidMessage + IDENTIFIER_TYPE);
520                                 throw new BpmnError(UNPROCESSABLE, invalidMessage + IDENTIFIER_TYPE);
521                         }
522                 }else{
523                         log.debug(invalidMessage + INVENTORY_TYPE);
524                         throw new BpmnError(UNPROCESSABLE, invalidMessage + INVENTORY_TYPE);
525                 }
526                 si.setSolutionInfo(solutionInfo);
527                 return si;
528         }
529
530         /**
531          * Sets the cloud data to a cloud region object
532          *
533          */
534         private CloudRegion setCloud(Map<String, String> assignmentsMap){
535                 CloudRegion cloud = new CloudRegion();
536                 cloud.setCloudOwner(assignmentsMap.get("cloudOwner"));
537                 cloud.setCloudRegionVersion(assignmentsMap.get("aicVersion"));
538                 cloud.setComplex(assignmentsMap.get("aicClli"));
539                 return cloud;
540         }
541
542         /**
543          * Sets the vnf data to a generic vnf object
544          *
545          */
546         private GenericVnf setVnf(Map<String, String> assignmentsMap){
547                 GenericVnf vnf = new GenericVnf();
548                 vnf.setOrchestrationStatus(OrchestrationStatus.CREATED);
549                 vnf.setVnfName(assignmentsMap.get("vnfHostName"));
550                 vnf.setVnfId(assignmentsMap.get("vnfId"));
551                 return vnf;
552         }
553
554         /**
555          * Sets the pnf data to a pnf object
556          *
557          */
558         private Pnf setPnf(Map<String, String> assignmentsMap, String role){
559                 Pnf pnf = new Pnf();
560                 pnf.setRole(role);
561                 pnf.setOrchestrationStatus(OrchestrationStatus.CREATED);
562                 pnf.setPnfName(assignmentsMap.get(role + "PnfName"));
563                 return pnf;
564         }
565
566
567
568 }