1f3008aa1ac9e205ce01c0827fb1fbcba2d8ac23
[so.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 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.openecomp.mso.apihandlerinfra;
22
23
24 import java.io.StringReader;
25 import java.io.StringWriter;
26 import java.sql.Timestamp;
27 import java.text.SimpleDateFormat;
28 import java.util.Date;
29 import java.util.List;
30
31 import javax.ws.rs.core.Response;
32 import javax.xml.bind.JAXBContext;
33 import javax.xml.bind.JAXBException;
34 import javax.xml.bind.Marshaller;
35 import javax.xml.bind.Unmarshaller;
36 import javax.xml.transform.OutputKeys;
37 import javax.xml.transform.Transformer;
38 import javax.xml.transform.TransformerFactory;
39 import javax.xml.transform.dom.DOMSource;
40 import javax.xml.transform.sax.SAXSource;
41 import javax.xml.transform.stream.StreamResult;
42
43 import org.hibernate.Session;
44
45 import org.w3c.dom.Document;
46 import org.w3c.dom.Element;
47 import org.w3c.dom.Node;
48 import org.w3c.dom.NodeList;
49 import org.xml.sax.InputSource;
50
51 import org.openecomp.mso.apihandler.common.ErrorNumbers;
52 import org.openecomp.mso.apihandler.common.ValidationException;
53 import org.openecomp.mso.apihandlerinfra.vnfbeans.ActionType;
54 import org.openecomp.mso.apihandlerinfra.vnfbeans.ObjectFactory;
55 import org.openecomp.mso.apihandlerinfra.vnfbeans.RequestInfo;
56 import org.openecomp.mso.apihandlerinfra.vnfbeans.RequestStatusType;
57 import org.openecomp.mso.apihandlerinfra.vnfbeans.VnfInputs;
58 import org.openecomp.mso.apihandlerinfra.vnfbeans.VnfRequest;
59 import org.openecomp.mso.logger.MsoLogger;
60 import org.openecomp.mso.logger.MessageEnum;
61 import org.openecomp.mso.properties.MsoJavaProperties;
62 import org.openecomp.mso.db.AbstractSessionFactoryManager;
63 import org.openecomp.mso.requestsdb.InfraActiveRequests;
64 import org.openecomp.mso.requestsdb.RequestsDatabase;
65 import org.openecomp.mso.requestsdb.RequestsDbSessionFactoryManager;
66
67 public class VnfMsoInfraRequest {
68
69     private String requestId;
70     private String requestXML;
71     private String requestUri;
72     private VnfRequest vnfReq;
73     private RequestInfo rinfo;
74     private VnfInputs vnfInputs;
75     private String vnfParams;
76     private ActionType action;
77     private String errorMessage;
78     private String httpResponse;
79     private String responseBody;
80     private RequestStatusType status;
81     private long startTime;
82     private long progress = Constants.PROGRESS_REQUEST_RECEIVED;
83
84     private static MsoLogger msoLogger = MsoLogger.getMsoLogger (MsoLogger.Catalog.APIH);
85     private static final String NOT_PROVIDED = "not provided";
86
87     protected AbstractSessionFactoryManager requestsDbSessionFactoryManager = new RequestsDbSessionFactoryManager ();
88     
89     VnfMsoInfraRequest (String requestId) {
90         this.requestId = requestId;
91         this.startTime = System.currentTimeMillis();
92         MsoLogger.setLogContext (requestId, null);
93
94     }
95
96     // Parse request XML
97     void parse (String reqXML, String version, MsoJavaProperties props) throws ValidationException {
98
99         msoLogger.debug ("Validating the request");
100
101         this.requestXML = reqXML;
102
103         VnfRequest vnfReq = null;
104         boolean isWrongRootElement = false;
105
106         try {
107             JAXBContext jaxbContext = JAXBContext.newInstance (VnfRequest.class);
108             Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller ();
109
110             InputSource inputSource = new InputSource (new StringReader (reqXML));
111             SAXSource source = new SAXSource (inputSource);
112
113             if (reqXML.contains ("vnf-request") && !reqXML.contains ("network-request")) {
114                 vnfReq = jaxbUnmarshaller.unmarshal (source, VnfRequest.class).getValue ();
115             } else {
116                 isWrongRootElement = true;
117             }
118
119         } catch (Exception e) {
120                 msoLogger.error (MessageEnum.APIH_VNFREQUEST_VALIDATION_ERROR, "", "", MsoLogger.ErrorCode.DataError, "Exception in format for vnf request ", e);
121             throw new ValidationException ("format for vnf request");
122         }
123
124         if (isWrongRootElement) {
125                 msoLogger.error (MessageEnum.APIH_REQUEST_VALIDATION_ERROR_REASON, "root element is not correct", "", "", MsoLogger.ErrorCode.DataError, "root element is not correct");
126             throw new ValidationException ("root element <vnf-request> expected");
127         }
128
129         if (vnfReq == null) {
130             throw new ValidationException ("vnf-request");
131         }
132         this.vnfReq = vnfReq;
133
134         this.rinfo = vnfReq.getRequestInfo ();
135
136         if (this.rinfo == null) {
137             throw new ValidationException ("request-info");
138         }
139         if (this.rinfo.getRequestId () != null) {
140             msoLogger.info (MessageEnum.APIH_GENERATED_REQUEST_ID, requestId, this.rinfo.getRequestId ());
141         }
142
143         action = this.rinfo.getAction ();
144         if (action == null) {
145             throw new ValidationException ("action");
146         }
147
148         this.vnfInputs = vnfReq.getVnfInputs ();
149         if (this.vnfInputs == null) {
150             throw new ValidationException ("vnf-inputs");
151         }
152         
153         // Verify that BPMN-specific elements are not in the APIH incoming request
154         if (this.vnfInputs.getPersonaModelId () != null || this.vnfInputs.getPersonaModelVersion () != null ||
155                         this.vnfInputs.getIsBaseVfModule () != null || this.vnfInputs.getVnfPersonaModelId () != null ||
156                         this.vnfInputs.getVnfPersonaModelVersion () != null) {
157                  throw new ValidationException ("format for vnf request");              
158         }
159         // Verify that the elements correspond to the version
160
161         switch (version) {
162             case Constants.SCHEMA_VERSION_V1:
163                 if (this.vnfInputs.getVfModuleName() != null || this.vnfInputs.getVfModuleId() != null ||
164                     this.vnfInputs.getVfModuleModelName() != null || this.vnfInputs.getAsdcServiceModelVersion() != null
165                     ||
166                     this.vnfInputs.getBackoutOnFailure() != null || this.vnfInputs.getAicCloudRegion() != null ||
167                     this.vnfInputs.getServiceInstanceId() != null) {
168                     throw new ValidationException("format for v1 version of vnf request");
169                 }
170                 break;
171             case Constants.SCHEMA_VERSION_V2:
172                 if (this.vnfInputs.getServiceType() != null || this.vnfInputs.getAicNodeClli() != null
173                     || this.vnfInputs.getServiceInstanceId() != null) {
174                     throw new ValidationException("format for v2 version of vnf request");
175                 }
176                 break;
177             case Constants.SCHEMA_VERSION_V3:
178                 if (this.vnfInputs.getServiceType() != null || this.vnfInputs.getAicNodeClli() != null) {
179                     throw new ValidationException("format for v3 version of vnf request");
180                 }
181                 break;
182         }
183         
184         
185         if (!InfraUtils.isActionAllowed (props, "vnf", version, action.value ())) {
186                 throw new ValidationException ("action allowable for version " + version + " of vnf request");          
187         }
188         
189         if ((ActionType.UPDATE.equals(action) || ActionType.DELETE.equals(action)) && this.vnfInputs.getVnfId () == null) {
190                 throw new ValidationException("vnf-id");                
191         }
192              
193         if ((ActionType.UPDATE_VF_MODULE.equals (action) || ActionType.DELETE_VF_MODULE.equals (action)) && this.vnfInputs.getVfModuleId () == null) {
194             throw new ValidationException ("vf-module-id");
195         }
196         
197         if (ActionType.CREATE.equals (action) && this.vnfInputs.getVnfName () == null) {
198             throw new ValidationException ("vnf-name");
199         }         
200          
201         if (ActionType.CREATE_VF_MODULE.equals (action)) {
202                 if (this.vnfInputs.getVfModuleName () == null) {
203                         throw new ValidationException ("vf-module-name");
204                 }
205                 if (!InfraUtils.isValidHeatName(this.vnfInputs.getVfModuleName ())) {
206                         throw new ValidationException ("vf-module-name: no value meeting heat stack name syntax requirements");
207                 }
208         }        
209
210         if (this.vnfInputs.getVnfType () == null) {
211             throw new ValidationException ("vnf-type");
212         }
213         
214         if ((ActionType.CREATE_VF_MODULE.equals (action) || ActionType.UPDATE_VF_MODULE.equals (action) || ActionType.DELETE_VF_MODULE.equals (action)) && this.vnfInputs.getVfModuleModelName () == null) {
215             throw new ValidationException ("vf-module-model-name");
216         }        
217         
218         if (!version.equals(Constants.SCHEMA_VERSION_V1) && this.vnfInputs.getServiceId () == null) {
219                 throw new ValidationException ("service-id ");
220         }
221         
222         if (this.vnfInputs.getServiceType () != null && this.vnfInputs.getServiceId () != null) {
223                 throw new ValidationException ("service-type or service-id ");
224         }
225         
226         if (version.equals(Constants.SCHEMA_VERSION_V1) && this.vnfInputs.getAicNodeClli () == null) {
227                 throw new ValidationException ("aic-node-clli");
228         }
229         
230         if ((version.equals(Constants.SCHEMA_VERSION_V2) || version.equals(Constants.SCHEMA_VERSION_V3)) && (this.vnfInputs.getAicCloudRegion () == null || this.vnfInputs.getAicCloudRegion ().isEmpty())) {
231                 throw new ValidationException ("aic-cloud-region");
232         }
233         
234         if (version.equals(Constants.SCHEMA_VERSION_V3) && this.vnfInputs.getServiceInstanceId () == null) {
235                 throw new ValidationException ("service-instance-id");
236         }
237
238         
239         if (this.vnfInputs.getTenantId () == null) {
240                 throw new ValidationException ("tenant-id");            
241         }
242
243         Object vp = vnfReq.getVnfParams ();
244
245         if (vp != null) {
246             msoLogger.debug ("This object is not null");
247
248             Node node = (Node) vp;
249             Document doc = node.getOwnerDocument ();
250             this.vnfParams = domToStr (doc);
251         }
252
253         msoLogger.debug ("VNFParams: " + this.vnfParams);
254
255         msoLogger.debug ("Request valid");
256
257         // Rebuild the request string for BPEL to include request-id 
258         rinfo.setRequestId (this.requestId);        
259         this.vnfReq.setRequestInfo (rinfo);        
260       
261         StringWriter stringWriter = new StringWriter ();
262         try {
263             JAXBContext jaxbContext = JAXBContext.newInstance (VnfRequest.class);
264             Marshaller jaxbMarshaller = jaxbContext.createMarshaller ();
265
266             // output pretty printed
267             jaxbMarshaller.setProperty (Marshaller.JAXB_FORMATTED_OUTPUT, true);
268
269             jaxbMarshaller.marshal (this.vnfReq, stringWriter);
270
271         } catch (JAXBException e) {
272             msoLogger.debug ("Exception: ", e);
273         }
274
275         this.requestXML = stringWriter.toString ();
276         msoLogger.debug("REQUEST XML to BPEL: " + this.requestXML);
277
278     }
279
280     public void createRequestRecord (Status status) {
281
282         Session session = null;
283         try {
284
285             session = requestsDbSessionFactoryManager.getSessionFactory ().openSession ();
286             session.beginTransaction ();
287
288             InfraActiveRequests aq = new InfraActiveRequests ();
289             aq.setRequestId (requestId);
290             aq.setClientRequestId(rinfo.getRequestId());
291
292             Timestamp startTimeStamp = new Timestamp (System.currentTimeMillis());
293             if (rinfo != null) {
294                 if (rinfo.getAction () != null) {
295                     aq.setAction (rinfo.getAction ().value ());
296                     aq.setRequestAction (RequestActionMap.getMappedRequestAction (rinfo.getAction ().value ()));
297                 }
298                 aq.setSource (rinfo.getSource ());
299             } else {
300                 // Set up mandatory parameters
301                 aq.setAction (NOT_PROVIDED);
302                 aq.setRequestAction (NOT_PROVIDED);
303             }
304
305             aq.setRequestBody (this.requestXML);
306             aq.setRequestScope ("");
307
308             if (vnfInputs != null) {
309                 if (vnfInputs.getVnfId () != null) {
310                     aq.setVnfId (vnfInputs.getVnfId ());
311                 }
312                 if (vnfInputs.getVnfName () != null) {
313                     aq.setVnfName (vnfInputs.getVnfName ());
314                 }
315                 if (vnfInputs.getVnfType () != null) {
316                     aq.setVnfType (vnfInputs.getVnfType ());
317                 }
318                 if (vnfInputs.getServiceInstanceId () != null) {
319                     aq.setServiceInstanceId (vnfInputs.getServiceInstanceId ());
320                 }
321                 if (vnfInputs.getServiceType () != null) {
322                     aq.setServiceType (vnfInputs.getServiceType ());
323                 }
324                 if (vnfInputs.getServiceId () != null) {
325                     aq.setAaiServiceId (vnfInputs.getServiceId ());
326                 }
327                 if (vnfInputs.getAicNodeClli () != null) {
328                     aq.setAicNodeClli (vnfInputs.getAicNodeClli ());
329                 }
330                 if (vnfInputs.getAicCloudRegion () != null) {
331                     aq.setAicCloudRegion (vnfInputs.getAicCloudRegion ());
332                 }
333                 if (vnfInputs.getTenantId () != null) {
334                     aq.setTenantId (vnfInputs.getTenantId ());
335                 }
336                 if (vnfInputs.getProvStatus () != null) {
337                     aq.setProvStatus (vnfInputs.getProvStatus ());
338                 }
339                 if (vnfInputs.getVolumeGroupName () != null) {
340                     aq.setVolumeGroupName (vnfInputs.getVolumeGroupName ());
341                 }
342                 if (vnfInputs.getVolumeGroupId () != null) {
343                     aq.setVolumeGroupId (vnfInputs.getVolumeGroupId ());
344                 }
345                 if (vnfInputs.getVfModuleId () != null) {
346                     aq.setVfModuleId (vnfInputs.getVfModuleId ());
347                 }
348                 if (vnfInputs.getVfModuleName () != null) {
349                     aq.setVfModuleName (vnfInputs.getVfModuleName ());
350                 }
351                 if (vnfInputs.getVfModuleModelName () != null) {
352                     aq.setVfModuleModelName (vnfInputs.getVfModuleModelName ());
353                 }
354                 
355                 if (vnfInputs.getVfModuleName () != null || vnfInputs.getVfModuleId () != null) {
356                         aq.setRequestScope (ModelType.vfModule.name ());
357                 }
358                 else {
359                         aq.setRequestScope (ModelType.vnf.name ());
360                 }
361
362
363             }
364
365             aq.setStartTime (startTimeStamp);
366             aq.setRequestStatus (status.toString ());
367             aq.setLastModifiedBy (Constants.MODIFIED_BY_APIHANDLER);
368             aq.setRequestType ("VNF");
369
370             if (vnfParams != null) {
371                 msoLogger.debug ("Storing vnfParams: " + vnfParams);
372                 aq.setVnfParams (this.vnfParams);
373             }
374
375             if ((status == Status.FAILED) || (status == Status.COMPLETE)) {
376                 aq.setStatusMessage (this.errorMessage);
377                 aq.setResponseBody (this.responseBody);
378
379                 Timestamp endTimeStamp = new Timestamp (System.currentTimeMillis());
380                 aq.setEndTime (endTimeStamp);
381             }
382                 
383             aq.setProgress (this.progress);
384             
385
386             msoLogger.debug ("About to insert a record");
387
388             session.save (aq);
389             session.getTransaction ().commit ();
390             session.close ();
391         } catch (Exception e) {
392                 msoLogger.error (MessageEnum.APIH_DB_INSERT_EXC, "", "", MsoLogger.ErrorCode.AvailabilityError, "Exception in createRequestRecord", e);
393             if (session != null) {
394                 session.close ();
395             }
396             if (!status.equals (Status.FAILED)) {
397                 throw e;
398             }
399         }
400     }
401
402     public void updateFinalStatus (Status status) {
403         int result = 0;
404         try {
405             result = (RequestsDatabase.getInstance()).updateInfraFinalStatus (requestId,
406                                                               status.toString (),
407                                                               this.errorMessage,
408                                                               this.progress,
409                                                               this.responseBody,
410                                                               Constants.MODIFIED_BY_APIHANDLER);
411         } catch (Exception e) {
412                 msoLogger.error (MessageEnum.APIH_DB_UPDATE_EXC, e.getMessage (), "", "", MsoLogger.ErrorCode.AvailabilityError, "Exception in updateFinalStatus");
413             msoLogger.debug ("Exception: ", e);
414         }
415     }
416
417     public Response buildResponse (int httpResponseCode, String errorCode, InfraActiveRequests inProgress) {
418         return buildResponseWithError (httpResponseCode, errorCode, inProgress, null);
419     }
420
421     public Response buildResponseWithError (int httpResponseCode,
422                                             String errorCode,
423                                             InfraActiveRequests inProgress,
424                                             String errorString) {
425
426         ObjectFactory beansObjectFactory = new ObjectFactory ();
427
428         VnfRequest vr = beansObjectFactory.createVnfRequest ();
429
430         RequestInfo ri = beansObjectFactory.createRequestInfo ();
431
432         ri.setRequestId (requestId);
433         ri.setRequestStatus (this.status);
434         ri.setAction (this.rinfo.getAction ());
435         ri.setSource (this.rinfo.getSource ());
436
437         String errorMsg = null;
438         if (errorCode != null) {
439             // If error code is actually an XML error response from BPEL, treat it specially:
440             if (!Messages.errors.containsKey (errorCode)) {
441                 if (errorCode.length () > 300) {
442                     errorMsg = errorCode.substring (0, 299);
443                 } else {
444                     errorMsg = errorCode;
445                 }
446
447             } else {
448
449                 if (inProgress == null) {
450                     if (errorCode.equals (ErrorNumbers.RECIPE_DOES_NOT_EXIST)) {
451                         errorMsg = String.format (Messages.errors.get (errorCode), "vnf", errorString);
452                     } else {
453                         errorMsg = String.format (Messages.errors.get (errorCode), errorString);
454                     }
455                 } else if (errorCode.equals (ErrorNumbers.LOCKED_CREATE_ON_THE_SAME_VNF_NAME_IN_PROGRESS)) {
456                     errorMsg = String.format (Messages.errors.get (errorCode),
457                                               "vnf",
458                                               inProgress.getVnfName (),
459                                               inProgress.getRequestStatus (),
460                                               "vnf");
461                 } else if (errorCode.equals (ErrorNumbers.LOCKED_SAME_ACTION_AND_VNF_ID)) {
462                     errorMsg = String.format (Messages.errors.get (errorCode),
463                                               "vnf",
464                                               inProgress.getVnfId (),
465                                               inProgress.getRequestStatus (),
466                                               inProgress.getAction (),
467                                               "vnf");
468                 }
469             }
470
471             ri.setStatusMessage (errorMsg);
472             this.errorMessage = errorMsg;
473         }
474         ri.setProgress ((int) this.progress);
475
476         Date startDate = new Date (this.startTime);
477         SimpleDateFormat sdf = new SimpleDateFormat ("yyyy-MM-dd HH:mm:ss.SSS");
478         String startTimeString = sdf.format (startDate);
479
480         ri.setStartTime (startTimeString);
481         
482         if (this.progress == Constants.PROGRESS_REQUEST_COMPLETED) {
483                 ri.setEndTime(startTimeString);
484         }
485
486         vr.setRequestInfo (ri);
487         
488         this.vnfInputs.setIsBaseVfModule(null);
489         this.vnfInputs.setPersonaModelId(null);
490         this.vnfInputs.setPersonaModelVersion(null);
491         this.vnfInputs.setVnfPersonaModelId(null);
492         this.vnfInputs.setVnfPersonaModelVersion(null);
493
494         vr.setVnfInputs (this.vnfInputs);
495
496         StringWriter stringWriter = new StringWriter ();
497         try {
498             JAXBContext jaxbContext = JAXBContext.newInstance (VnfRequest.class);
499             Marshaller jaxbMarshaller = jaxbContext.createMarshaller ();
500             jaxbMarshaller.setProperty (Marshaller.JAXB_FORMATTED_OUTPUT, true);
501
502             jaxbMarshaller.marshal (vr, stringWriter);
503
504         } catch (JAXBException e) {
505             msoLogger.debug ("Exception: ", e);
506         }
507
508         String response = stringWriter.toString ();
509
510         this.httpResponse = Integer.toString (httpResponseCode);
511         this.responseBody = response;
512         
513         
514         // Log the failed request into the MSO Requests database
515
516         return Response.status (httpResponseCode).entity (response).build ();
517
518     }
519
520     public Response buildResponseFailedValidation (int httpResponseCode, String exceptionMessage) {
521
522         ObjectFactory beansObjectFactory = new ObjectFactory ();
523         VnfRequest vr = beansObjectFactory.createVnfRequest ();
524
525         RequestInfo ri = beansObjectFactory.createRequestInfo ();
526         ri.setRequestId (requestId);
527
528         if (this.rinfo != null) {
529             if (this.rinfo.getAction () != null) {
530                 ri.setAction (this.rinfo.getAction ());
531             } else {
532                 ri.setAction (ActionType.NOT_PROVIDED);
533             }
534             if (this.rinfo.getSource () != null) {
535                 ri.setSource (this.rinfo.getSource ());
536             }
537         } else {
538             ri.setAction (ActionType.NOT_PROVIDED);
539         }
540
541         // Nothing more is expected for this request
542
543         String errorMsg = String.format (Messages.errors.get (ErrorNumbers.REQUEST_FAILED_SCHEMA_VALIDATION
544                                                               + "_service"),
545                                          exceptionMessage);
546         ri.setStatusMessage (errorMsg);
547         this.errorMessage = errorMsg;
548
549         ri.setProgress ((int) this.progress);
550         ri.setRequestStatus (RequestStatusType.FAILED);
551         Date startDate = new Date (this.startTime);
552         SimpleDateFormat sdf = new SimpleDateFormat ("yyyy-MM-dd HH:mm:ss.SSS");
553         String startTimeString = sdf.format (startDate);
554
555         ri.setStartTime (startTimeString);
556         ri.setEndTime(startTimeString);
557         
558         vr.setRequestInfo (ri);
559
560         vr.setVnfInputs (this.vnfInputs);
561
562         StringWriter stringWriter = new StringWriter ();
563         try {
564             JAXBContext jaxbContext = JAXBContext.newInstance (VnfRequest.class);
565             Marshaller jaxbMarshaller = jaxbContext.createMarshaller ();
566
567             // output pretty printed
568             jaxbMarshaller.setProperty (Marshaller.JAXB_FORMATTED_OUTPUT, true);
569
570             jaxbMarshaller.marshal (vr, stringWriter);
571
572         } catch (JAXBException e) {
573             msoLogger.debug ("Error marshalling", e);
574         }
575
576         String response = stringWriter.toString ();
577
578         this.httpResponse = Integer.toString (httpResponseCode);
579         this.responseBody = response;
580
581         return Response.status (httpResponseCode).entity (response).build ();
582     }
583
584     public String getRequestUri () {
585         return requestUri;
586     }
587
588     public void setRequestUri (String requestUri) {
589         this.requestUri = requestUri;
590     }
591
592     public VnfInputs getVnfInputs () {
593         return vnfInputs;
594     }
595
596     public RequestInfo getRequestInfo () {
597         return rinfo;
598     }
599
600     public String getResponseBody () {
601         return responseBody;
602     }
603
604     public void setResponseBody (String responseBody) {
605         this.responseBody = responseBody;
606     }
607
608     public String getHttpResponse () {
609         return httpResponse;
610     }
611
612     public void setHttpResponse (String httpResponse) {
613         this.httpResponse = httpResponse;
614     }
615
616     public String getRequestId () {
617         return requestId;
618     }
619
620     public String getRequestXML () {
621         return requestXML;
622     }
623
624     public void setRequestXML (String requestXML) {
625         this.requestXML = requestXML;
626     }
627
628     public RequestStatusType getStatus () {
629         return status;
630     }
631     
632     public String getServiceType () {
633         if (this.vnfInputs.getServiceType () != null) 
634                 return this.vnfInputs.getServiceType ();
635         if (this.vnfInputs.getServiceId () != null) 
636                 return this.vnfInputs.getServiceId ();
637         return null;
638     }
639
640     public void setStatus (RequestStatusType status) {
641         this.status = status;
642         switch (status) {
643         case FAILED:
644         case COMPLETE:
645                 this.progress = Constants.PROGRESS_REQUEST_COMPLETED;
646                 break;
647         case IN_PROGRESS:
648                 this.progress = Constants.PROGRESS_REQUEST_IN_PROGRESS;
649                 break;
650         }
651     }
652
653     public static String domToStr (Document doc) {
654         if (doc == null) {
655             return null;
656         }
657
658         try {
659             StringWriter sw = new StringWriter ();
660             StreamResult sr = new StreamResult (sw);
661             TransformerFactory tf = TransformerFactory.newInstance ();
662             Transformer t = tf.newTransformer ();
663             t.setOutputProperty (OutputKeys.STANDALONE, "yes");
664             NodeList nl = doc.getDocumentElement ().getChildNodes ();
665             DOMSource source = null;
666             for (int x = 0; x < nl.getLength (); x++) {
667                 Node e = nl.item (x);
668                 if (e instanceof Element) {
669                     source = new DOMSource (e);
670                     break;
671                 }
672             }
673             if (source != null) {
674                 t.transform (source, sr);
675
676                 String s = sw.toString ();
677                 return s;
678             }
679
680             return null;
681
682         } catch (Exception e) {
683                 msoLogger.error (MessageEnum.APIH_DOM2STR_ERROR, "", "", MsoLogger.ErrorCode.DataError, "Exception in domToStr", e);
684         }
685         return null;
686     }
687     
688     public void addBPMNSpecificInputs(String personaModelId, String personaModelVersion, Boolean isBaseVfModule,
689                         String vnfPersonaModelId, String vnfPersonaModelVersion) {
690         vnfInputs.setPersonaModelId(personaModelId);
691         vnfInputs.setPersonaModelVersion(personaModelVersion);
692         vnfInputs.setIsBaseVfModule(isBaseVfModule);
693         vnfInputs.setVnfPersonaModelId(vnfPersonaModelId);
694         vnfInputs.setVnfPersonaModelVersion(vnfPersonaModelVersion);
695         
696         this.vnfReq.setVnfInputs(vnfInputs);
697                    
698           StringWriter stringWriter = new StringWriter ();
699           try {
700               JAXBContext jaxbContext = JAXBContext.newInstance (VnfRequest.class);
701               Marshaller jaxbMarshaller = jaxbContext.createMarshaller ();
702
703               // output pretty printed
704               jaxbMarshaller.setProperty (Marshaller.JAXB_FORMATTED_OUTPUT, true);
705
706               jaxbMarshaller.marshal (this.vnfReq, stringWriter);
707
708           } catch (JAXBException e) {
709               msoLogger.debug ("Exception: ", e);
710           }
711
712           this.requestXML = stringWriter.toString ();
713           msoLogger.debug("REQUEST XML to BPEL: " + this.requestXML);
714         
715         
716     }
717 }