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