2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.mso.apihandlerinfra;
23 import java.io.StringReader;
24 import java.io.StringWriter;
25 import java.sql.Timestamp;
26 import java.text.SimpleDateFormat;
27 import java.util.ArrayList;
28 import java.util.Date;
29 import java.util.HashMap;
30 import java.util.List;
32 import java.util.Map.Entry;
33 import java.util.StringTokenizer;
35 import javax.ws.rs.core.MultivaluedMap;
36 import javax.ws.rs.core.Response;
37 import javax.xml.bind.JAXBContext;
38 import javax.xml.bind.JAXBElement;
39 import javax.xml.bind.JAXBException;
40 import javax.xml.bind.Marshaller;
41 import javax.xml.bind.Unmarshaller;
42 import javax.xml.transform.OutputKeys;
43 import javax.xml.transform.Transformer;
44 import javax.xml.transform.TransformerFactory;
45 import javax.xml.transform.dom.DOMSource;
46 import javax.xml.transform.sax.SAXSource;
47 import javax.xml.transform.stream.StreamResult;
49 import org.codehaus.jackson.map.ObjectMapper;
50 import org.codehaus.jackson.map.SerializationConfig.Feature;
51 import org.codehaus.jackson.map.annotate.JsonSerialize;
52 import org.hibernate.Session;
53 import org.jboss.resteasy.specimpl.MultivaluedMapImpl;
54 import org.w3c.dom.Document;
55 import org.w3c.dom.Element;
56 import org.w3c.dom.Node;
57 import org.w3c.dom.NodeList;
58 import org.xml.sax.InputSource;
60 import org.openecomp.mso.apihandler.common.ErrorNumbers;
61 import org.openecomp.mso.apihandler.common.ValidationException;
62 import org.openecomp.mso.apihandlerinfra.serviceinstancebeans.CloudConfiguration;
63 import org.openecomp.mso.apihandlerinfra.serviceinstancebeans.ModelInfo;
64 import org.openecomp.mso.apihandlerinfra.serviceinstancebeans.PolicyException;
65 import org.openecomp.mso.apihandlerinfra.serviceinstancebeans.RelatedInstance;
66 import org.openecomp.mso.apihandlerinfra.serviceinstancebeans.RelatedInstanceList;
67 import org.openecomp.mso.apihandlerinfra.serviceinstancebeans.RequestError;
68 import org.openecomp.mso.apihandlerinfra.serviceinstancebeans.ServiceException;
69 import org.openecomp.mso.apihandlerinfra.serviceinstancebeans.ServiceInstancesRequest;
70 import org.openecomp.mso.apihandlerinfra.vnfbeans.ActionType;
71 import org.openecomp.mso.apihandlerinfra.vnfbeans.ObjectFactory;
72 import org.openecomp.mso.apihandlerinfra.serviceinstancebeans.RequestInfo;
73 import org.openecomp.mso.apihandlerinfra.vnfbeans.RequestStatusType;
74 import org.openecomp.mso.apihandlerinfra.vnfbeans.VnfInputs;
75 import org.openecomp.mso.apihandlerinfra.vnfbeans.VnfRequest;
76 import org.openecomp.mso.logger.MsoLogger;
77 import org.openecomp.mso.logger.MessageEnum;
78 import org.openecomp.mso.properties.MsoJavaProperties;
79 import org.openecomp.mso.requestsdb.HibernateUtil;
80 import org.openecomp.mso.requestsdb.InfraActiveRequests;
81 import org.openecomp.mso.requestsdb.RequestsDatabase;
82 import org.openecomp.mso.utils.UUIDChecker;
84 public class MsoRequest {
86 private String requestId;
87 private String requestXML;
88 private String requestJSON;
89 private String requestUri;
90 private VnfRequest vnfReq;
91 private RequestInfo requestInfo;
92 private ModelInfo modelInfo;
93 private CloudConfiguration cloudConfiguration ;
94 private VnfInputs vnfInputs;
95 private String vnfParams;
96 private Action action;
97 private String errorMessage;
98 private String errorCode;
99 private String httpResponse;
100 private String responseBody;
101 private RequestStatusType status;
102 private ServiceInstancesRequest sir;
103 private long startTime;
104 private long progress = Constants.PROGRESS_REQUEST_RECEIVED;
105 private String serviceInstanceType;
106 private String vnfType;
107 private String vfModuleType;
108 private String vfModuleModelName;
109 private String networkType;
110 private String asdcServiceModelVersion;
111 private String requestScope;
113 private static MsoLogger msoLogger = MsoLogger.getMsoLogger (MsoLogger.Catalog.APIH);
114 private static final String NOT_PROVIDED = "not provided";
116 MsoRequest (String requestId) {
117 this.requestId = requestId;
118 this.startTime = System.currentTimeMillis();
119 MsoLogger.setLogContext (requestId, null);
125 this.startTime = System.currentTimeMillis();
126 MsoLogger.setLogContext (requestId, null);
131 public Response buildServiceErrorResponse (int httpResponseCode,
132 MsoException exceptionType,
135 List<String> variables) {
137 this.errorCode = messageId;
140 this.errorMessage = text;
143 this.errorMessage = "";
145 this.httpResponse = Integer.toString(httpResponseCode);
146 if(errorMessage.length() > 1999){
147 errorMessage = errorMessage.substring(0, 1999);
150 RequestError re = new RequestError();
152 if(exceptionType.name().equals("PolicyException")){
154 PolicyException pe = new PolicyException();
155 pe.setMessageId(messageId);
157 if(variables != null){
158 for(String variable: variables){
159 pe.getVariables().add(variable);
162 re.setPolicyException(pe);
166 ServiceException se = new ServiceException();
167 se.setMessageId(messageId);
169 if(variables != null){
170 if(variables != null){
171 for(String variable: variables){
172 se.getVariables().add(variable);
176 re.setServiceException(se);
179 String requestErrorStr = null;
182 ObjectMapper mapper = new ObjectMapper();
183 mapper.setSerializationInclusion(JsonSerialize.Inclusion.NON_DEFAULT);
184 requestErrorStr = mapper.writeValueAsString(re);
186 msoLogger.error (MessageEnum.APIH_VALIDATION_ERROR, "", "", MsoLogger.ErrorCode.DataError, "Exception in buildServiceErrorResponse writing exceptionType to string ", e);
190 return Response.status (httpResponseCode).entity(requestErrorStr).build ();
195 // Parse request JSON
196 void parse (ServiceInstancesRequest sir, HashMap<String,String> instanceIdMap, Action action) throws ValidationException {
198 msoLogger.debug ("Validating the Service Instance request");
201 this.action = action;
204 ObjectMapper mapper = new ObjectMapper();
205 //mapper.configure(Feature.WRAP_ROOT_VALUE, true);
206 requestJSON = mapper.writeValueAsString(sir.getRequestDetails());
208 } catch(Exception e){
209 throw new ValidationException ("Parse ServiceInstanceRequest to JSON string");
212 if(instanceIdMap != null){
213 if(instanceIdMap.get("serviceInstanceId") != null){
214 if (!UUIDChecker.isValidUUID (instanceIdMap.get ("serviceInstanceId"))) {
215 throw new ValidationException ("serviceInstanceId");
217 this.sir.setServiceInstanceId(instanceIdMap.get("serviceInstanceId"));
220 if(instanceIdMap.get("vnfInstanceId") != null){
221 if (!UUIDChecker.isValidUUID (instanceIdMap.get ("vnfInstanceId"))) {
222 throw new ValidationException ("vnfInstanceId");
224 this.sir.setVnfInstanceId(instanceIdMap.get("vnfInstanceId"));
227 if(instanceIdMap.get("vfModuleInstanceId") != null){
228 if (!UUIDChecker.isValidUUID (instanceIdMap.get ("vfModuleInstanceId"))) {
229 throw new ValidationException ("vfModuleInstanceId");
231 this.sir.setVfModuleInstanceId(instanceIdMap.get("vfModuleInstanceId"));
234 if(instanceIdMap.get("volumeGroupInstanceId") != null){
235 if (!UUIDChecker.isValidUUID (instanceIdMap.get ("volumeGroupInstanceId"))) {
236 throw new ValidationException ("volumeGroupInstanceId");
238 this.sir.setVolumeGroupInstanceId(instanceIdMap.get("volumeGroupInstanceId"));
241 if(instanceIdMap.get("networkInstanceId") != null){
242 if (!UUIDChecker.isValidUUID (instanceIdMap.get ("networkInstanceId"))) {
243 throw new ValidationException ("networkInstanceId");
245 this.sir.setNetworkInstanceId(instanceIdMap.get("networkInstanceId"));
249 this.modelInfo = sir.getRequestDetails().getModelInfo();
251 if (this.modelInfo == null) {
252 throw new ValidationException ("model-info");
255 this.requestInfo = sir.getRequestDetails().getRequestInfo();
257 if (this.requestInfo == null) {
258 throw new ValidationException ("requestInfo");
261 if (modelInfo.getModelType () == null) {
262 throw new ValidationException ("modelType");
265 this.requestScope = modelInfo.getModelType().name();
267 if (empty (modelInfo.getModelInvariantId ()) && !(requestScope.equalsIgnoreCase (ModelType.network.name ()) &&
268 (action == Action.createInstance || action == Action.updateInstance))) {
269 throw new ValidationException ("modelInvariantId");
272 if (!empty (modelInfo.getModelInvariantId ()) && !UUIDChecker.isValidUUID (modelInfo.getModelInvariantId ())) {
273 throw new ValidationException ("modelInvariantId format");
276 if (empty (modelInfo.getModelName ()) && (action == Action.createInstance || action == Action.updateInstance || (action == Action.deleteInstance &&
277 (requestScope.equalsIgnoreCase (ModelType.network.name ()) || requestScope.equalsIgnoreCase (ModelType.vfModule.name ()))))) {
278 throw new ValidationException ("modelName");
281 if (empty (modelInfo.getModelVersion ()) && !(requestScope.equalsIgnoreCase (ModelType.network.name ()) &&
282 (action == Action.createInstance || action == Action.updateInstance))) {
283 throw new ValidationException ("modelVersion");
286 if(requestScope.equalsIgnoreCase(ModelType.vnf.name()) && action != Action.deleteInstance && empty (modelInfo.getModelCustomizationName ())) {
287 throw new ValidationException ("modelCustomizationName");
290 this.cloudConfiguration = sir.getRequestDetails ().getCloudConfiguration ();
291 if (!requestScope.equalsIgnoreCase (ModelType.service.name ()) && cloudConfiguration == null) {
292 throw new ValidationException ("cloudConfiguration");
295 if (cloudConfiguration != null) {
296 if (empty (cloudConfiguration.getLcpCloudRegionId ())) {
297 throw new ValidationException ("lcpCloudRegionId");
299 if (empty (cloudConfiguration.getTenantId ())) {
300 throw new ValidationException ("tenantId");
304 if (requestScope.equalsIgnoreCase (ModelType.service.name ()) && action == Action.createInstance) {
305 if (sir.getRequestDetails ().getRequestParameters () == null) {
306 throw new ValidationException ("requestParameters");
308 if (empty (sir.getRequestDetails ().getRequestParameters ().getSubscriptionServiceType ())) {
309 throw new ValidationException ("subscriptionServiceType");
313 if(requestScope.equalsIgnoreCase(ModelType.service.name())){
314 this.serviceInstanceType = modelInfo.getModelName();
317 if(requestScope.equalsIgnoreCase(ModelType.network.name())){
318 this.networkType = modelInfo.getModelName();
321 // Verify instanceName existence and format
322 if (empty (requestInfo.getInstanceName ()) && action == Action.createInstance) {
323 throw new ValidationException ("instanceName");
326 if (!empty (requestInfo.getInstanceName ()) && !requestInfo.getInstanceName ().matches (Constants.VALID_INSTANCE_NAME_FORMAT)) {
327 throw new ValidationException ("instanceName format");
330 if (empty (requestInfo.getProductFamilyId ()) && ((requestScope.equalsIgnoreCase (ModelType.vnf.name ()) && action == Action.createInstance) ||
331 (requestScope.equalsIgnoreCase (ModelType.network.name ()) && (action == Action.createInstance || action == Action.updateInstance)))) {
332 throw new ValidationException ("productFamilyId");
335 if (empty (requestInfo.getSource ())) {
336 throw new ValidationException ("source");
340 RelatedInstanceList[] instanceList = sir.getRequestDetails().getRelatedInstanceList();
342 String serviceModelName = null;
343 String vnfModelName = null;
344 String asdcServiceModelVersion = null;
345 String volumeGroupId = null;
346 boolean isRelatedServiceInstancePresent = false;
347 boolean isRelatedVnfInstancePresent = false;
349 if (instanceList != null) {
350 for(RelatedInstanceList relatedInstanceList : instanceList){
351 RelatedInstance relatedInstance = relatedInstanceList.getRelatedInstance();
353 if (!empty (relatedInstance.getInstanceName ()) && !relatedInstance.getInstanceName ().matches (Constants.VALID_INSTANCE_NAME_FORMAT)) {
354 throw new ValidationException ("instanceName format in relatedInstance");
357 if (empty (relatedInstance.getInstanceId ())) {
358 throw new ValidationException ("instanceId in relatedInstance");
361 if (!UUIDChecker.isValidUUID (relatedInstance.getInstanceId ())) {
362 throw new ValidationException ("instanceId format in relatedInstance");
365 if (relatedInstance.getModelInfo () == null) {
366 throw new ValidationException ("modelInfo in relatedInstance");
369 if (relatedInstance.getModelInfo ().getModelType () == null) {
370 throw new ValidationException ("modelType in relatedInstance");
373 if (action != Action.deleteInstance) {
375 if (empty (relatedInstance.getModelInfo ().getModelInvariantId ()) &&
376 !(requestScope.equalsIgnoreCase (ModelType.vfModule.name ()) && action == Action.createInstance &&
377 relatedInstance.getModelInfo ().getModelType ().equals(ModelType.volumeGroup))) {
378 throw new ValidationException ("modelInvariantId in relatedInstance");
381 if (!empty (relatedInstance.getModelInfo ().getModelInvariantId ()) &&
382 !UUIDChecker.isValidUUID (relatedInstance.getModelInfo ().getModelInvariantId ())) {
383 throw new ValidationException ("modelInvariantId format in relatedInstance");
386 if (empty(relatedInstance.getModelInfo ().getModelName ()) &&
387 !(requestScope.equalsIgnoreCase (ModelType.vfModule.name ()) && action == Action.createInstance &&
388 relatedInstance.getModelInfo ().getModelType ().equals (ModelType.volumeGroup))) {
389 throw new ValidationException ("modelName in relatedInstance");
392 if (empty (relatedInstance.getModelInfo ().getModelVersion ()) &&
393 !(requestScope.equalsIgnoreCase (ModelType.vfModule.name ()) && action == Action.createInstance &&
394 relatedInstance.getModelInfo ().getModelType ().equals (ModelType.volumeGroup))) {
395 throw new ValidationException ("modelVersion in relatedInstance");
399 if (empty (relatedInstance.getModelInfo ().getModelCustomizationName ()) &&
400 relatedInstance.getModelInfo ().getModelType ().equals (ModelType.vnf)) {
401 throw new ValidationException ("modelCustomizationName in relatedInstance");
404 if(relatedInstance.getModelInfo().getModelType().equals(ModelType.service)) {
405 isRelatedServiceInstancePresent = true;
406 if (!relatedInstance.getInstanceId ().equals (this.sir.getServiceInstanceId ())) {
407 throw new ValidationException ("serviceInstanceId matching the serviceInstanceId in request URI");
409 serviceModelName = relatedInstance.getModelInfo ().getModelName ();
410 asdcServiceModelVersion = relatedInstance.getModelInfo().getModelVersion ();
412 else if(relatedInstance.getModelInfo().getModelType().equals(ModelType.vnf)) {
413 isRelatedVnfInstancePresent = true;
414 if (!relatedInstance.getInstanceId ().equals (this.sir.getVnfInstanceId ())) {
415 throw new ValidationException ("vnfInstanceId matching the vnfInstanceId in request URI");
417 vnfModelName = relatedInstance.getModelInfo().getModelCustomizationName();
419 else if(relatedInstance.getModelInfo().getModelType().equals(ModelType.volumeGroup)) {
420 volumeGroupId = relatedInstance.getInstanceId ();
425 if(requestScope.equalsIgnoreCase (ModelType.volumeGroup.name ())) {
426 if (!isRelatedServiceInstancePresent) {
427 throw new ValidationException ("related service instance for volumeGroup request");
429 if (!isRelatedVnfInstancePresent) {
430 throw new ValidationException ("related vnf instance for volumeGroup request");
432 this.serviceInstanceType = serviceModelName;
433 this.vnfType = serviceModelName + "/" + vnfModelName;
434 this.asdcServiceModelVersion = asdcServiceModelVersion;
436 else if(requestScope.equalsIgnoreCase(ModelType.vfModule.name ())) {
437 if (!isRelatedServiceInstancePresent) {
438 throw new ValidationException ("related service instance for vfModule request");
440 if (!isRelatedVnfInstancePresent) {
441 throw new ValidationException ("related vnf instance for vfModule request");
443 String vfModuleModelName = modelInfo.getModelName ();
444 this.vfModuleModelName = vfModuleModelName;
445 this.serviceInstanceType = serviceModelName;
446 this.vnfType = serviceModelName + "/" + vnfModelName;
447 this.asdcServiceModelVersion = asdcServiceModelVersion;
448 this.vfModuleType = vnfType + "::" + vfModuleModelName;
449 this.sir.setVolumeGroupInstanceId (volumeGroupId);
451 else if (requestScope.equalsIgnoreCase (ModelType.vnf.name ())) {
452 if (!isRelatedServiceInstancePresent) {
453 throw new ValidationException ("related service instance for vnf request");
455 this.vnfType = serviceModelName + "/" + sir.getRequestDetails().getModelInfo().getModelCustomizationName();
458 else if (action != Action.deleteInstance && !requestScope.equalsIgnoreCase(ModelType.service.name ()) &&
459 !requestScope.equalsIgnoreCase(ModelType.network.name ())) {
460 throw new ValidationException ("related instances");
465 public Map<String, List<String>> getOrchestrationFilters (MultivaluedMap<String, String> queryParams) throws ValidationException {
467 String queryParam = null;
468 Map<String, List<String>> orchestrationFilterParams = new HashMap<String, List<String>>();
471 for (Entry<String,List<String>> entry : queryParams.entrySet()) {
472 queryParam = entry.getKey();
475 if(queryParam.equalsIgnoreCase("filter")){
477 StringTokenizer st = new StringTokenizer(entry.getValue().get(0), ":");
481 List<String> orchestrationList = new ArrayList<String>();
482 while (st.hasMoreElements()) {
484 mapKey = st.nextElement() + "";
486 orchestrationList.add(st.nextElement() + "");
490 orchestrationFilterParams.put(mapKey, orchestrationList);
494 //msoLogger.error (MessageEnum.APIH_VALIDATION_ERROR, e);
495 throw new ValidationException ("QueryParam ServiceInfo", e);
501 return orchestrationFilterParams;
504 public void createRequestRecord (Status status, Action action) {
506 Session session = null;
509 session = HibernateUtil.getSessionFactory ().openSession ();
510 session.beginTransaction ();
513 sir = new ServiceInstancesRequest ();
516 InfraActiveRequests aq = new InfraActiveRequests ();
517 aq.setRequestId (requestId);
519 aq.setRequestAction(action.name());
520 aq.setAction(action.name());
522 Timestamp startTimeStamp = new Timestamp (System.currentTimeMillis());
524 aq.setStartTime (startTimeStamp);
526 if (requestInfo != null) {
528 if(requestInfo.getSource() != null){
529 aq.setSource(requestInfo.getSource());
531 if(requestInfo.getCallbackUrl() != null){
532 aq.setCallBackUrl(requestInfo.getCallbackUrl());
534 if(requestInfo.getCorrelator() != null){
535 aq.setCorrelator(requestInfo.getCorrelator());
540 if (modelInfo != null) {
541 aq.setRequestScope(requestScope);
544 if (cloudConfiguration != null) {
545 if(cloudConfiguration.getLcpCloudRegionId() != null) {
546 aq.setAicCloudRegion(cloudConfiguration.getLcpCloudRegionId());
549 if(cloudConfiguration.getTenantId() != null) {
550 aq.setTenantId(cloudConfiguration.getTenantId());
555 if(sir.getServiceInstanceId() != null){
556 aq.setServiceInstanceId(sir.getServiceInstanceId());
559 if(sir.getVnfInstanceId() != null){
560 aq.setVnfId(sir.getVnfInstanceId());
563 if (null != requestScope) {
564 if (requestScope.equalsIgnoreCase(ModelType.service.name())) {
565 if (requestInfo.getInstanceName() != null) {
566 aq.setServiceInstanceName(requestInfo.getInstanceName());
570 if (requestScope.equalsIgnoreCase(ModelType.network.name())) {
571 aq.setNetworkName(requestInfo.getInstanceName());
572 aq.setNetworkType(networkType);
573 aq.setNetworkId(sir.getNetworkInstanceId());
577 if (requestScope.equalsIgnoreCase(ModelType.volumeGroup.name())) {
578 aq.setVolumeGroupId(sir.getVolumeGroupInstanceId());
579 aq.setVolumeGroupName(requestInfo.getInstanceName());
580 aq.setVnfType(vnfType);
584 if (requestScope.equalsIgnoreCase(ModelType.vfModule.name())) {
585 aq.setVfModuleName(requestInfo.getInstanceName());
586 aq.setVfModuleModelName(modelInfo.getModelName());
587 aq.setVfModuleId(sir.getVfModuleInstanceId());
588 aq.setVolumeGroupId(sir.getVolumeGroupInstanceId());
589 aq.setVnfType(vnfType);
593 if (requestScope.equalsIgnoreCase(ModelType.vnf.name())) {
594 aq.setVnfName(requestInfo.getInstanceName());
595 if (null != sir.getRequestDetails()) {
596 RelatedInstanceList[] instanceList = sir.getRequestDetails().getRelatedInstanceList();
598 if (instanceList != null) {
600 for (RelatedInstanceList relatedInstanceList : instanceList) {
602 RelatedInstance relatedInstance = relatedInstanceList.getRelatedInstance();
603 if (relatedInstance.getModelInfo().getModelType().equals(ModelType.service)) {
604 aq.setVnfType(vnfType);
609 //aq.setVnfType(sir.getRequestDetails().getRelatedInstanceList());
614 aq.setRequestBody (this.requestJSON);
617 aq.setRequestStatus (status.toString ());
618 aq.setLastModifiedBy (Constants.MODIFIED_BY_APIHANDLER);
620 if ((status == Status.FAILED) || (status == Status.COMPLETE)) {
621 aq.setStatusMessage (this.errorMessage);
622 aq.setResponseBody (this.responseBody);
623 aq.setProgress(new Long(100));
625 Timestamp endTimeStamp = new Timestamp (System.currentTimeMillis());
626 aq.setEndTime (endTimeStamp);
629 msoLogger.debug ("About to insert a record");
632 session.getTransaction ().commit ();
634 } catch (Exception e) {
635 msoLogger.error (MessageEnum.APIH_DB_INSERT_EXC, "", "", MsoLogger.ErrorCode.DataError, "Exception when creation record request", e);
636 if (session != null) {
639 if (!status.equals (Status.FAILED)) {
645 public void updateFinalStatus (Status status) {
648 result = RequestsDatabase.updateInfraFinalStatus (requestId,
653 Constants.MODIFIED_BY_APIHANDLER);
654 } catch (Exception e) {
655 msoLogger.error(MessageEnum.APIH_DB_UPDATE_EXC, e.getMessage(), "", "", MsoLogger.ErrorCode.DataError, "Exception when updating record in DB");
656 msoLogger.debug ("Exception: ", e);
660 public Response buildResponse (int httpResponseCode, String errorCode, InfraActiveRequests inProgress) {
661 return buildResponseWithError (httpResponseCode, errorCode, inProgress, null);
664 public Response buildResponseWithError (int httpResponseCode,
666 InfraActiveRequests inProgress,
667 String errorString) {
671 // Log the failed request into the MSO Requests database
673 return Response.status (httpResponseCode).entity (null).build ();
677 public Response buildResponseFailedValidation (int httpResponseCode, String exceptionMessage) {
681 return Response.status (httpResponseCode).entity (null).build ();
684 public String getRequestUri () {
688 public void setRequestUri (String requestUri) {
689 this.requestUri = requestUri;
692 public VnfInputs getVnfInputs () {
696 public RequestInfo getRequestInfo () {
700 public String getResponseBody () {
704 public void setResponseBody (String responseBody) {
705 this.responseBody = responseBody;
708 public String getHttpResponse () {
712 public void setHttpResponse (String httpResponse) {
713 this.httpResponse = httpResponse;
716 public String getRequestId () {
720 public String getRequestXML () {
724 public void setRequestXML (String requestXML) {
725 this.requestXML = requestXML;
728 public RequestStatusType getStatus () {
732 public String getServiceType () {
733 if (this.vnfInputs.getServiceType () != null)
734 return this.vnfInputs.getServiceType ();
735 if (this.vnfInputs.getServiceId () != null)
736 return this.vnfInputs.getServiceId ();
740 public void setStatus (RequestStatusType status) {
741 this.status = status;
745 this.progress = Constants.PROGRESS_REQUEST_COMPLETED;
748 this.progress = Constants.PROGRESS_REQUEST_IN_PROGRESS;
753 public ModelInfo getModelInfo() {
757 public ServiceInstancesRequest getServiceInstancesRequest() {
761 public String getServiceInstanceType () {
762 return serviceInstanceType;
765 public String getNetworkType () {
769 public String getVnfType () {
773 public String getVfModuleModelName () {
774 return vfModuleModelName;
777 public String getVfModuleType () {
781 public String getAsdcServiceModelVersion () {
782 return asdcServiceModelVersion;
785 public static String domToStr (Document doc) {
791 StringWriter sw = new StringWriter ();
792 StreamResult sr = new StreamResult (sw);
793 TransformerFactory tf = TransformerFactory.newInstance ();
794 Transformer t = tf.newTransformer ();
795 t.setOutputProperty (OutputKeys.STANDALONE, "yes");
796 NodeList nl = doc.getDocumentElement ().getChildNodes ();
797 DOMSource source = null;
798 for (int x = 0; x < nl.getLength (); x++) {
799 Node e = nl.item (x);
800 if (e instanceof Element) {
801 source = new DOMSource (e);
805 if (source != null) {
806 t.transform (source, sr);
808 String s = sw.toString ();
814 } catch (Exception e) {
815 msoLogger.error (MessageEnum.APIH_DOM2STR_ERROR, "", "", MsoLogger.ErrorCode.DataError, "Exception in domToStr", e);
820 public void addBPMNSpecificInputs(String personaModelId, String personaModelVersion, Boolean isBaseVfModule,
821 String vnfPersonaModelId, String vnfPersonaModelVersion) {
822 vnfInputs.setPersonaModelId(personaModelId);
823 vnfInputs.setPersonaModelVersion(personaModelVersion);
824 vnfInputs.setIsBaseVfModule(isBaseVfModule);
825 vnfInputs.setVnfPersonaModelId(vnfPersonaModelId);
826 vnfInputs.setVnfPersonaModelVersion(vnfPersonaModelVersion);
828 this.vnfReq.setVnfInputs(vnfInputs);
830 StringWriter stringWriter = new StringWriter ();
832 JAXBContext jaxbContext = JAXBContext.newInstance (VnfRequest.class);
833 Marshaller jaxbMarshaller = jaxbContext.createMarshaller ();
835 // output pretty printed
836 jaxbMarshaller.setProperty (Marshaller.JAXB_FORMATTED_OUTPUT, true);
838 jaxbMarshaller.marshal (this.vnfReq, stringWriter);
840 } catch (JAXBException e) {
841 msoLogger.debug ("Exception: ", e);
844 this.requestXML = stringWriter.toString ();
845 msoLogger.debug("REQUEST XML to BPEL: " + this.requestXML);
850 private static boolean empty(String s) {
851 return (s == null || s.trim().isEmpty());