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