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.Calendar;
29 import java.util.Date;
30 import java.util.HashMap;
31 import java.util.List;
33 import java.util.Map.Entry;
34 import java.util.StringTokenizer;
36 import javax.ws.rs.core.MultivaluedMap;
37 import javax.ws.rs.core.Response;
38 import javax.xml.bind.JAXBContext;
39 import javax.xml.bind.JAXBElement;
40 import javax.xml.bind.JAXBException;
41 import javax.xml.bind.Marshaller;
42 import javax.xml.bind.Unmarshaller;
43 import javax.xml.transform.OutputKeys;
44 import javax.xml.transform.Transformer;
45 import javax.xml.transform.TransformerFactory;
46 import javax.xml.transform.dom.DOMSource;
47 import javax.xml.transform.sax.SAXSource;
48 import javax.xml.transform.stream.StreamResult;
50 import org.codehaus.jackson.map.ObjectMapper;
51 import org.codehaus.jackson.map.SerializationConfig.Feature;
52 import org.codehaus.jackson.map.annotate.JsonSerialize;
53 import org.hibernate.Session;
54 import org.jboss.resteasy.specimpl.MultivaluedMapImpl;
55 import org.w3c.dom.Document;
56 import org.w3c.dom.Element;
57 import org.w3c.dom.Node;
58 import org.w3c.dom.NodeList;
59 import org.xml.sax.InputSource;
61 import org.openecomp.mso.apihandler.common.ErrorNumbers;
62 import org.openecomp.mso.apihandler.common.ValidationException;
63 import org.openecomp.mso.apihandlerinfra.serviceinstancebeans.CloudConfiguration;
64 import org.openecomp.mso.apihandlerinfra.serviceinstancebeans.ModelInfo;
65 import org.openecomp.mso.apihandlerinfra.serviceinstancebeans.PolicyException;
66 import org.openecomp.mso.apihandlerinfra.serviceinstancebeans.RelatedInstance;
67 import org.openecomp.mso.apihandlerinfra.serviceinstancebeans.RelatedInstanceList;
68 import org.openecomp.mso.apihandlerinfra.serviceinstancebeans.RequestError;
69 import org.openecomp.mso.apihandlerinfra.serviceinstancebeans.ServiceException;
70 import org.openecomp.mso.apihandlerinfra.serviceinstancebeans.ServiceInstancesRequest;
71 import org.openecomp.mso.apihandlerinfra.vnfbeans.ActionType;
72 import org.openecomp.mso.apihandlerinfra.vnfbeans.ObjectFactory;
73 import org.openecomp.mso.apihandlerinfra.serviceinstancebeans.RequestInfo;
74 import org.openecomp.mso.apihandlerinfra.vnfbeans.RequestStatusType;
75 import org.openecomp.mso.apihandlerinfra.vnfbeans.VnfInputs;
76 import org.openecomp.mso.apihandlerinfra.vnfbeans.VnfRequest;
77 import org.openecomp.mso.logger.MsoLogger;
78 import org.openecomp.mso.logger.MessageEnum;
79 import org.openecomp.mso.properties.MsoJavaProperties;
80 import org.openecomp.mso.requestsdb.HibernateUtil;
81 import org.openecomp.mso.requestsdb.InfraActiveRequests;
82 import org.openecomp.mso.requestsdb.RequestsDatabase;
83 import org.openecomp.mso.utils.UUIDChecker;
85 public class MsoRequest {
87 private String requestId;
88 private String requestXML;
89 private String requestJSON;
90 private String requestUri;
91 private VnfRequest vnfReq;
92 private RequestInfo requestInfo;
93 private ModelInfo modelInfo;
94 private CloudConfiguration cloudConfiguration ;
95 private VnfInputs vnfInputs;
96 private String vnfParams;
97 private Action action;
98 private String errorMessage;
99 private String errorCode;
100 private String httpResponse;
101 private String responseBody;
102 private RequestStatusType status;
103 private ServiceInstancesRequest sir;
104 private long startTime;
105 private long progress = Constants.PROGRESS_REQUEST_RECEIVED;
106 private String serviceInstanceType;
107 private String vnfType;
108 private String vfModuleType;
109 private String vfModuleModelName;
110 private String networkType;
111 private String asdcServiceModelVersion;
112 private String requestScope;
114 private static MsoLogger msoLogger = MsoLogger.getMsoLogger (MsoLogger.Catalog.APIH);
115 private static final String NOT_PROVIDED = "not provided";
117 MsoRequest (String requestId) {
118 this.requestId = requestId;
119 Calendar startTimeCalendar = Calendar.getInstance ();
120 this.startTime = startTimeCalendar.getTimeInMillis ();
121 MsoLogger.setLogContext (requestId, null);
127 Calendar startTimeCalendar = Calendar.getInstance ();
128 this.startTime = startTimeCalendar.getTimeInMillis ();
129 MsoLogger.setLogContext (requestId, null);
134 public Response buildServiceErrorResponse (int httpResponseCode,
135 MsoException exceptionType,
138 List<String> variables) {
140 this.errorCode = messageId;
143 this.errorMessage = text;
146 this.errorMessage = "";
148 this.httpResponse = Integer.toString(httpResponseCode);
149 if(errorMessage.length() > 1999){
150 errorMessage = errorMessage.substring(0, 1999);
153 RequestError re = new RequestError();
155 if(exceptionType.name().equals("PolicyException")){
157 PolicyException pe = new PolicyException();
158 pe.setMessageId(messageId);
160 if(variables != null){
161 for(String variable: variables){
162 pe.getVariables().add(variable);
165 re.setPolicyException(pe);
169 ServiceException se = new ServiceException();
170 se.setMessageId(messageId);
172 if(variables != null){
173 if(variables != null){
174 for(String variable: variables){
175 se.getVariables().add(variable);
179 re.setServiceException(se);
182 String requestErrorStr = null;
185 ObjectMapper mapper = new ObjectMapper();
186 mapper.setSerializationInclusion(JsonSerialize.Inclusion.NON_DEFAULT);
187 requestErrorStr = mapper.writeValueAsString(re);
189 msoLogger.error (MessageEnum.APIH_VALIDATION_ERROR, "", "", MsoLogger.ErrorCode.DataError, "Exception in buildServiceErrorResponse writing exceptionType to string ", e);
193 return Response.status (httpResponseCode).entity(requestErrorStr).build ();
198 // Parse request JSON
199 void parse (ServiceInstancesRequest sir, HashMap<String,String> instanceIdMap, Action action) throws ValidationException {
201 msoLogger.debug ("Validating the Service Instance request");
204 this.action = action;
207 ObjectMapper mapper = new ObjectMapper();
208 //mapper.configure(Feature.WRAP_ROOT_VALUE, true);
209 requestJSON = mapper.writeValueAsString(sir.getRequestDetails());
211 } catch(Exception e){
212 throw new ValidationException ("Parse ServiceInstanceRequest to JSON string");
215 if(instanceIdMap != null){
216 if(instanceIdMap.get("serviceInstanceId") != null){
217 if (!UUIDChecker.isValidUUID (instanceIdMap.get ("serviceInstanceId"))) {
218 throw new ValidationException ("serviceInstanceId");
220 this.sir.setServiceInstanceId(instanceIdMap.get("serviceInstanceId"));
223 if(instanceIdMap.get("vnfInstanceId") != null){
224 if (!UUIDChecker.isValidUUID (instanceIdMap.get ("vnfInstanceId"))) {
225 throw new ValidationException ("vnfInstanceId");
227 this.sir.setVnfInstanceId(instanceIdMap.get("vnfInstanceId"));
230 if(instanceIdMap.get("vfModuleInstanceId") != null){
231 if (!UUIDChecker.isValidUUID (instanceIdMap.get ("vfModuleInstanceId"))) {
232 throw new ValidationException ("vfModuleInstanceId");
234 this.sir.setVfModuleInstanceId(instanceIdMap.get("vfModuleInstanceId"));
237 if(instanceIdMap.get("volumeGroupInstanceId") != null){
238 if (!UUIDChecker.isValidUUID (instanceIdMap.get ("volumeGroupInstanceId"))) {
239 throw new ValidationException ("volumeGroupInstanceId");
241 this.sir.setVolumeGroupInstanceId(instanceIdMap.get("volumeGroupInstanceId"));
244 if(instanceIdMap.get("networkInstanceId") != null){
245 if (!UUIDChecker.isValidUUID (instanceIdMap.get ("networkInstanceId"))) {
246 throw new ValidationException ("networkInstanceId");
248 this.sir.setNetworkInstanceId(instanceIdMap.get("networkInstanceId"));
252 this.modelInfo = sir.getRequestDetails().getModelInfo();
254 if (this.modelInfo == null) {
255 throw new ValidationException ("model-info");
258 this.requestInfo = sir.getRequestDetails().getRequestInfo();
260 if (this.requestInfo == null) {
261 throw new ValidationException ("requestInfo");
264 if (modelInfo.getModelType () == null) {
265 throw new ValidationException ("modelType");
268 this.requestScope = modelInfo.getModelType().name();
270 if (empty (modelInfo.getModelInvariantId ()) && !(requestScope.equalsIgnoreCase (ModelType.network.name ()) &&
271 (action == Action.createInstance || action == Action.updateInstance))) {
272 throw new ValidationException ("modelInvariantId");
275 if (!empty (modelInfo.getModelInvariantId ()) && !UUIDChecker.isValidUUID (modelInfo.getModelInvariantId ())) {
276 throw new ValidationException ("modelInvariantId format");
279 if (empty (modelInfo.getModelName ()) && (action == Action.createInstance || action == Action.updateInstance || (action == Action.deleteInstance &&
280 (requestScope.equalsIgnoreCase (ModelType.network.name ()) || requestScope.equalsIgnoreCase (ModelType.vfModule.name ()))))) {
281 throw new ValidationException ("modelName");
284 if (empty (modelInfo.getModelVersion ()) && !(requestScope.equalsIgnoreCase (ModelType.network.name ()) &&
285 (action == Action.createInstance || action == Action.updateInstance))) {
286 throw new ValidationException ("modelVersion");
289 if(requestScope.equalsIgnoreCase(ModelType.vnf.name()) && action != Action.deleteInstance && empty (modelInfo.getModelCustomizationName ())) {
290 throw new ValidationException ("modelCustomizationName");
293 this.cloudConfiguration = sir.getRequestDetails ().getCloudConfiguration ();
294 if (!requestScope.equalsIgnoreCase (ModelType.service.name ()) && cloudConfiguration == null) {
295 throw new ValidationException ("cloudConfiguration");
298 if (cloudConfiguration != null) {
299 if (empty (cloudConfiguration.getLcpCloudRegionId ())) {
300 throw new ValidationException ("lcpCloudRegionId");
302 if (empty (cloudConfiguration.getTenantId ())) {
303 throw new ValidationException ("tenantId");
307 if (requestScope.equalsIgnoreCase (ModelType.service.name ()) && action == Action.createInstance) {
308 if (sir.getRequestDetails ().getRequestParameters () == null) {
309 throw new ValidationException ("requestParameters");
311 if (empty (sir.getRequestDetails ().getRequestParameters ().getSubscriptionServiceType ())) {
312 throw new ValidationException ("subscriptionServiceType");
316 if(requestScope.equalsIgnoreCase(ModelType.service.name())){
317 this.serviceInstanceType = modelInfo.getModelName();
320 if(requestScope.equalsIgnoreCase(ModelType.network.name())){
321 this.networkType = modelInfo.getModelName();
324 // Verify instanceName existence and format
325 if (empty (requestInfo.getInstanceName ()) && action == Action.createInstance) {
326 throw new ValidationException ("instanceName");
329 if (!empty (requestInfo.getInstanceName ()) && !requestInfo.getInstanceName ().matches (Constants.VALID_INSTANCE_NAME_FORMAT)) {
330 throw new ValidationException ("instanceName format");
333 if (empty (requestInfo.getProductFamilyId ()) && ((requestScope.equalsIgnoreCase (ModelType.vnf.name ()) && action == Action.createInstance) ||
334 (requestScope.equalsIgnoreCase (ModelType.network.name ()) && (action == Action.createInstance || action == Action.updateInstance)))) {
335 throw new ValidationException ("productFamilyId");
338 if (empty (requestInfo.getSource ())) {
339 throw new ValidationException ("source");
343 RelatedInstanceList[] instanceList = sir.getRequestDetails().getRelatedInstanceList();
345 String serviceModelName = null;
346 String vnfModelName = null;
347 String asdcServiceModelVersion = null;
348 String volumeGroupId = null;
349 boolean isRelatedServiceInstancePresent = false;
350 boolean isRelatedVnfInstancePresent = false;
352 if (instanceList != null) {
353 for(RelatedInstanceList relatedInstanceList : instanceList){
354 RelatedInstance relatedInstance = relatedInstanceList.getRelatedInstance();
356 if (!empty (relatedInstance.getInstanceName ()) && !relatedInstance.getInstanceName ().matches (Constants.VALID_INSTANCE_NAME_FORMAT)) {
357 throw new ValidationException ("instanceName format in relatedInstance");
360 if (empty (relatedInstance.getInstanceId ())) {
361 throw new ValidationException ("instanceId in relatedInstance");
364 if (!UUIDChecker.isValidUUID (relatedInstance.getInstanceId ())) {
365 throw new ValidationException ("instanceId format in relatedInstance");
368 if (relatedInstance.getModelInfo () == null) {
369 throw new ValidationException ("modelInfo in relatedInstance");
372 if (relatedInstance.getModelInfo ().getModelType () == null) {
373 throw new ValidationException ("modelType in relatedInstance");
376 if (action != Action.deleteInstance) {
378 if (empty (relatedInstance.getModelInfo ().getModelInvariantId ()) &&
379 !(requestScope.equalsIgnoreCase (ModelType.vfModule.name ()) && action == Action.createInstance &&
380 relatedInstance.getModelInfo ().getModelType ().equals(ModelType.volumeGroup))) {
381 throw new ValidationException ("modelInvariantId in relatedInstance");
384 if (!empty (relatedInstance.getModelInfo ().getModelInvariantId ()) &&
385 !UUIDChecker.isValidUUID (relatedInstance.getModelInfo ().getModelInvariantId ())) {
386 throw new ValidationException ("modelInvariantId format in relatedInstance");
389 if (empty(relatedInstance.getModelInfo ().getModelName ()) &&
390 !(requestScope.equalsIgnoreCase (ModelType.vfModule.name ()) && action == Action.createInstance &&
391 relatedInstance.getModelInfo ().getModelType ().equals (ModelType.volumeGroup))) {
392 throw new ValidationException ("modelName in relatedInstance");
395 if (empty (relatedInstance.getModelInfo ().getModelVersion ()) &&
396 !(requestScope.equalsIgnoreCase (ModelType.vfModule.name ()) && action == Action.createInstance &&
397 relatedInstance.getModelInfo ().getModelType ().equals (ModelType.volumeGroup))) {
398 throw new ValidationException ("modelVersion in relatedInstance");
402 if (empty (relatedInstance.getModelInfo ().getModelCustomizationName ()) &&
403 relatedInstance.getModelInfo ().getModelType ().equals (ModelType.vnf)) {
404 throw new ValidationException ("modelCustomizationName in relatedInstance");
407 if(relatedInstance.getModelInfo().getModelType().equals(ModelType.service)) {
408 isRelatedServiceInstancePresent = true;
409 if (!relatedInstance.getInstanceId ().equals (this.sir.getServiceInstanceId ())) {
410 throw new ValidationException ("serviceInstanceId matching the serviceInstanceId in request URI");
412 serviceModelName = relatedInstance.getModelInfo ().getModelName ();
413 asdcServiceModelVersion = relatedInstance.getModelInfo().getModelVersion ();
415 else if(relatedInstance.getModelInfo().getModelType().equals(ModelType.vnf)) {
416 isRelatedVnfInstancePresent = true;
417 if (!relatedInstance.getInstanceId ().equals (this.sir.getVnfInstanceId ())) {
418 throw new ValidationException ("vnfInstanceId matching the vnfInstanceId in request URI");
420 vnfModelName = relatedInstance.getModelInfo().getModelCustomizationName();
422 else if(relatedInstance.getModelInfo().getModelType().equals(ModelType.volumeGroup)) {
423 volumeGroupId = relatedInstance.getInstanceId ();
428 if(requestScope.equalsIgnoreCase (ModelType.volumeGroup.name ())) {
429 if (!isRelatedServiceInstancePresent) {
430 throw new ValidationException ("related service instance for volumeGroup request");
432 if (!isRelatedVnfInstancePresent) {
433 throw new ValidationException ("related vnf instance for volumeGroup request");
435 this.serviceInstanceType = serviceModelName;
436 this.vnfType = serviceModelName + "/" + vnfModelName;
437 this.asdcServiceModelVersion = asdcServiceModelVersion;
439 else if(requestScope.equalsIgnoreCase(ModelType.vfModule.name ())) {
440 if (!isRelatedServiceInstancePresent) {
441 throw new ValidationException ("related service instance for vfModule request");
443 if (!isRelatedVnfInstancePresent) {
444 throw new ValidationException ("related vnf instance for vfModule request");
446 String vfModuleModelName = modelInfo.getModelName ();
447 this.vfModuleModelName = vfModuleModelName;
448 this.serviceInstanceType = serviceModelName;
449 this.vnfType = serviceModelName + "/" + vnfModelName;
450 this.asdcServiceModelVersion = asdcServiceModelVersion;
451 this.vfModuleType = vnfType + "::" + vfModuleModelName;
452 this.sir.setVolumeGroupInstanceId (volumeGroupId);
454 else if (requestScope.equalsIgnoreCase (ModelType.vnf.name ())) {
455 if (!isRelatedServiceInstancePresent) {
456 throw new ValidationException ("related service instance for vnf request");
458 this.vnfType = serviceModelName + "/" + sir.getRequestDetails().getModelInfo().getModelCustomizationName();
461 else if (action != Action.deleteInstance && !requestScope.equalsIgnoreCase(ModelType.service.name ()) &&
462 !requestScope.equalsIgnoreCase(ModelType.network.name ())) {
463 throw new ValidationException ("related instances");
468 public Map<String, List<String>> getOrchestrationFilters (MultivaluedMap<String, String> queryParams) throws ValidationException {
470 String queryParam = null;
471 Map<String, List<String>> orchestrationFilterParams = new HashMap<String, List<String>>();
474 for (Entry<String,List<String>> entry : queryParams.entrySet()) {
475 queryParam = entry.getKey();
478 if(queryParam.equalsIgnoreCase("filter")){
480 StringTokenizer st = new StringTokenizer(entry.getValue().get(0), ":");
484 List<String> orchestrationList = new ArrayList<String>();
485 while (st.hasMoreElements()) {
487 mapKey = st.nextElement() + "";
489 orchestrationList.add(st.nextElement() + "");
493 orchestrationFilterParams.put(mapKey, orchestrationList);
497 //msoLogger.error (MessageEnum.APIH_VALIDATION_ERROR, e);
498 throw new ValidationException ("QueryParam ServiceInfo", e);
505 return orchestrationFilterParams;
508 public void createRequestRecord (Status status, Action action) {
510 Session session = null;
513 session = HibernateUtil.getSessionFactory ().openSession ();
514 session.beginTransaction ();
516 InfraActiveRequests aq = new InfraActiveRequests ();
517 aq.setRequestId (requestId);
519 aq.setRequestAction(action.name());
520 aq.setAction(action.name());
522 Timestamp startTimeStamp = new Timestamp (Calendar.getInstance ().getTimeInMillis ());
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());
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());
576 if(requestScope.equalsIgnoreCase(ModelType.volumeGroup.name())){
577 aq.setVolumeGroupId(sir.getVolumeGroupInstanceId());
578 aq.setVolumeGroupName(requestInfo.getInstanceName());
579 aq.setVnfType(vnfType);
583 if(requestScope.equalsIgnoreCase(ModelType.vfModule.name())){
584 aq.setVfModuleName(requestInfo.getInstanceName());
585 aq.setVfModuleModelName(modelInfo.getModelName());
586 aq.setVfModuleId(sir.getVfModuleInstanceId());
587 aq.setVolumeGroupId(sir.getVolumeGroupInstanceId());
588 aq.setVnfType(vnfType);
592 if(requestScope.equalsIgnoreCase(ModelType.vnf.name())){
593 aq.setVnfName(requestInfo.getInstanceName());
594 RelatedInstanceList[] instanceList = sir.getRequestDetails().getRelatedInstanceList();
596 if (instanceList != null) {
598 for(RelatedInstanceList relatedInstanceList : instanceList){
600 RelatedInstance relatedInstance = relatedInstanceList.getRelatedInstance();
601 if(relatedInstance.getModelInfo().getModelType().equals(ModelType.service)){
602 aq.setVnfType(vnfType);
606 //aq.setVnfType(sir.getRequestDetails().getRelatedInstanceList());
610 aq.setRequestBody (this.requestJSON);
613 aq.setRequestStatus (status.toString ());
614 aq.setLastModifiedBy (Constants.MODIFIED_BY_APIHANDLER);
616 if ((status == Status.FAILED) || (status == Status.COMPLETE)) {
617 aq.setStatusMessage (this.errorMessage);
618 aq.setResponseBody (this.responseBody);
619 aq.setProgress(new Long(100));
621 Calendar endTime = Calendar.getInstance ();
622 Timestamp endTimeStamp = new Timestamp (endTime.getTimeInMillis ());
623 aq.setEndTime (endTimeStamp);
626 msoLogger.debug ("About to insert a record");
629 session.getTransaction ().commit ();
631 } catch (Exception e) {
632 msoLogger.error (MessageEnum.APIH_DB_INSERT_EXC, "", "", MsoLogger.ErrorCode.DataError, "Exception when creation record request", e);
633 if (session != null) {
636 if (!status.equals (Status.FAILED)) {
642 public void updateFinalStatus (Status status) {
645 result = RequestsDatabase.updateInfraFinalStatus (requestId,
650 Constants.MODIFIED_BY_APIHANDLER);
651 } catch (Exception e) {
652 msoLogger.error(MessageEnum.APIH_DB_UPDATE_EXC, e.getMessage(), "", "", MsoLogger.ErrorCode.DataError, "Exception when updating record in DB");
653 msoLogger.debug ("Exception: ", e);
657 public Response buildResponse (int httpResponseCode, String errorCode, InfraActiveRequests inProgress) {
658 return buildResponseWithError (httpResponseCode, errorCode, inProgress, null);
661 public Response buildResponseWithError (int httpResponseCode,
663 InfraActiveRequests inProgress,
664 String errorString) {
668 // Log the failed request into the MSO Requests database
670 return Response.status (httpResponseCode).entity (null).build ();
674 public Response buildResponseFailedValidation (int httpResponseCode, String exceptionMessage) {
678 return Response.status (httpResponseCode).entity (null).build ();
681 public String getRequestUri () {
685 public void setRequestUri (String requestUri) {
686 this.requestUri = requestUri;
689 public VnfInputs getVnfInputs () {
693 public RequestInfo getRequestInfo () {
697 public String getResponseBody () {
701 public void setResponseBody (String responseBody) {
702 this.responseBody = responseBody;
705 public String getHttpResponse () {
709 public void setHttpResponse (String httpResponse) {
710 this.httpResponse = httpResponse;
713 public String getRequestId () {
717 public String getRequestXML () {
721 public void setRequestXML (String requestXML) {
722 this.requestXML = requestXML;
725 public RequestStatusType getStatus () {
729 public String getServiceType () {
730 if (this.vnfInputs.getServiceType () != null)
731 return this.vnfInputs.getServiceType ();
732 if (this.vnfInputs.getServiceId () != null)
733 return this.vnfInputs.getServiceId ();
737 public void setStatus (RequestStatusType status) {
738 this.status = status;
742 this.progress = Constants.PROGRESS_REQUEST_COMPLETED;
745 this.progress = Constants.PROGRESS_REQUEST_IN_PROGRESS;
750 public ModelInfo getModelInfo() {
754 public ServiceInstancesRequest getServiceInstancesRequest() {
758 public String getServiceInstanceType () {
759 return serviceInstanceType;
762 public String getNetworkType () {
766 public String getVnfType () {
770 public String getVfModuleModelName () {
771 return vfModuleModelName;
774 public String getVfModuleType () {
778 public String getAsdcServiceModelVersion () {
779 return asdcServiceModelVersion;
782 public static String domToStr (Document doc) {
788 StringWriter sw = new StringWriter ();
789 StreamResult sr = new StreamResult (sw);
790 TransformerFactory tf = TransformerFactory.newInstance ();
791 Transformer t = tf.newTransformer ();
792 t.setOutputProperty (OutputKeys.STANDALONE, "yes");
793 NodeList nl = doc.getDocumentElement ().getChildNodes ();
794 DOMSource source = null;
795 for (int x = 0; x < nl.getLength (); x++) {
796 Node e = nl.item (x);
797 if (e instanceof Element) {
798 source = new DOMSource (e);
802 if (source != null) {
803 t.transform (source, sr);
805 String s = sw.toString ();
811 } catch (Exception e) {
812 msoLogger.error (MessageEnum.APIH_DOM2STR_ERROR, "", "", MsoLogger.ErrorCode.DataError, "Exception in domToStr", e);
817 public void addBPMNSpecificInputs(String personaModelId, String personaModelVersion, Boolean isBaseVfModule,
818 String vnfPersonaModelId, String vnfPersonaModelVersion) {
819 vnfInputs.setPersonaModelId(personaModelId);
820 vnfInputs.setPersonaModelVersion(personaModelVersion);
821 vnfInputs.setIsBaseVfModule(isBaseVfModule);
822 vnfInputs.setVnfPersonaModelId(vnfPersonaModelId);
823 vnfInputs.setVnfPersonaModelVersion(vnfPersonaModelVersion);
825 this.vnfReq.setVnfInputs(vnfInputs);
827 StringWriter stringWriter = new StringWriter ();
829 JAXBContext jaxbContext = JAXBContext.newInstance (VnfRequest.class);
830 Marshaller jaxbMarshaller = jaxbContext.createMarshaller ();
832 // output pretty printed
833 jaxbMarshaller.setProperty (Marshaller.JAXB_FORMATTED_OUTPUT, true);
835 jaxbMarshaller.marshal (this.vnfReq, stringWriter);
837 } catch (JAXBException e) {
838 msoLogger.debug ("Exception: ", e);
841 this.requestXML = stringWriter.toString ();
842 msoLogger.debug("REQUEST XML to BPEL: " + this.requestXML);
847 private static boolean empty(String s) {
848 return (s == null || s.trim().isEmpty());