diff options
author | xg353y <xg353y@intl.att.com> | 2017-04-11 13:30:42 +0200 |
---|---|---|
committer | xg353y <xg353y@intl.att.com> | 2017-04-11 15:34:19 +0200 |
commit | b6b7bef8bdcad15af01ac88a038dd763ce59f68f (patch) | |
tree | 399d39da23aaa37701e487df064e3e0c27709ef3 /mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/MsoRequest.java | |
parent | 19340cad94eeaa1b580f7c0c99531de499e8ca14 (diff) |
[MSO-8] Update the maven dependency
Update the maven depenency for sdc-distribution-client to cooperate with the sdc changes.
Change-Id: I2da936e5c40cb68c7181bb78307192dd5655b5dc
Signed-off-by: xg353y <xg353y@intl.att.com>
Diffstat (limited to 'mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/MsoRequest.java')
-rw-r--r-- | mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/MsoRequest.java | 955 |
1 files changed, 531 insertions, 424 deletions
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/MsoRequest.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/MsoRequest.java index 64bdc3f269..5b84a59b6b 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/MsoRequest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/MsoRequest.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -22,10 +22,9 @@ package org.openecomp.mso.apihandlerinfra; import java.io.StringReader; import java.io.StringWriter; +import java.io.IOException; import java.sql.Timestamp; -import java.text.SimpleDateFormat; import java.util.ArrayList; -import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -35,29 +34,25 @@ import java.util.StringTokenizer; import javax.ws.rs.core.MultivaluedMap; import javax.ws.rs.core.Response; import javax.xml.bind.JAXBContext; -import javax.xml.bind.JAXBElement; import javax.xml.bind.JAXBException; import javax.xml.bind.Marshaller; -import javax.xml.bind.Unmarshaller; import javax.xml.transform.OutputKeys; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; -import javax.xml.transform.sax.SAXSource; import javax.xml.transform.stream.StreamResult; +import org.codehaus.jackson.JsonGenerationException; +import org.codehaus.jackson.map.JsonMappingException; import org.codehaus.jackson.map.ObjectMapper; -import org.codehaus.jackson.map.SerializationConfig.Feature; import org.codehaus.jackson.map.annotate.JsonSerialize; +import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion; import org.hibernate.Session; -import org.jboss.resteasy.specimpl.MultivaluedMapImpl; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; -import org.xml.sax.InputSource; -import org.openecomp.mso.apihandler.common.ErrorNumbers; import org.openecomp.mso.apihandler.common.ValidationException; import org.openecomp.mso.apihandlerinfra.serviceinstancebeans.CloudConfiguration; import org.openecomp.mso.apihandlerinfra.serviceinstancebeans.ModelInfo; @@ -65,18 +60,17 @@ import org.openecomp.mso.apihandlerinfra.serviceinstancebeans.PolicyException; import org.openecomp.mso.apihandlerinfra.serviceinstancebeans.RelatedInstance; import org.openecomp.mso.apihandlerinfra.serviceinstancebeans.RelatedInstanceList; import org.openecomp.mso.apihandlerinfra.serviceinstancebeans.RequestError; +import org.openecomp.mso.apihandlerinfra.serviceinstancebeans.RequestInfo; +import org.openecomp.mso.apihandlerinfra.serviceinstancebeans.RequestParameters; import org.openecomp.mso.apihandlerinfra.serviceinstancebeans.ServiceException; import org.openecomp.mso.apihandlerinfra.serviceinstancebeans.ServiceInstancesRequest; -import org.openecomp.mso.apihandlerinfra.vnfbeans.ActionType; -import org.openecomp.mso.apihandlerinfra.vnfbeans.ObjectFactory; -import org.openecomp.mso.apihandlerinfra.serviceinstancebeans.RequestInfo; import org.openecomp.mso.apihandlerinfra.vnfbeans.RequestStatusType; import org.openecomp.mso.apihandlerinfra.vnfbeans.VnfInputs; import org.openecomp.mso.apihandlerinfra.vnfbeans.VnfRequest; -import org.openecomp.mso.logger.MsoLogger; +import org.openecomp.mso.db.HibernateUtils; import org.openecomp.mso.logger.MessageEnum; -import org.openecomp.mso.properties.MsoJavaProperties; -import org.openecomp.mso.requestsdb.HibernateUtil; +import org.openecomp.mso.logger.MsoLogger; +import org.openecomp.mso.requestsdb.HibernateUtilsRequestsDb; import org.openecomp.mso.requestsdb.InfraActiveRequests; import org.openecomp.mso.requestsdb.RequestsDatabase; import org.openecomp.mso.utils.UUIDChecker; @@ -107,235 +101,292 @@ public class MsoRequest { private String vfModuleType; private String vfModuleModelName; private String networkType; - private String asdcServiceModelVersion; + private String asdcServiceModelVersion; private String requestScope; + private int reqVersion; + private boolean aLaCarteFlag = false; private static MsoLogger msoLogger = MsoLogger.getMsoLogger (MsoLogger.Catalog.APIH); private static final String NOT_PROVIDED = "not provided"; + protected HibernateUtils hibernateUtils = new HibernateUtilsRequestsDb (); + MsoRequest (String requestId) { this.requestId = requestId; this.startTime = System.currentTimeMillis(); MsoLogger.setLogContext (requestId, null); - } - + } + MsoRequest () { this.startTime = System.currentTimeMillis(); MsoLogger.setLogContext (requestId, null); } - - + + public Response buildServiceErrorResponse (int httpResponseCode, MsoException exceptionType, String text, String messageId, List<String> variables) { - this.errorCode = messageId; - - if (text != null) { - this.errorMessage = text; - } - else { - this.errorMessage = ""; - } - this.httpResponse = Integer.toString(httpResponseCode); - if(errorMessage.length() > 1999){ - errorMessage = errorMessage.substring(0, 1999); - } - - RequestError re = new RequestError(); - - if(exceptionType.name().equals("PolicyException")){ - - PolicyException pe = new PolicyException(); - pe.setMessageId(messageId); - pe.setText(text); - if(variables != null){ - for(String variable: variables){ - pe.getVariables().add(variable); - } - } - re.setPolicyException(pe); - - } else { - - ServiceException se = new ServiceException(); - se.setMessageId(messageId); - se.setText(text); - if(variables != null){ - if(variables != null){ - for(String variable: variables){ - se.getVariables().add(variable); - } - } - } - re.setServiceException(se); - } + this.errorCode = messageId; + + if (text != null) { + this.errorMessage = text; + } + else { + this.errorMessage = ""; + } + this.httpResponse = Integer.toString(httpResponseCode); + if(errorMessage.length() > 1999){ + errorMessage = errorMessage.substring(0, 1999); + } + + RequestError re = new RequestError(); + + if(exceptionType.name().equals("PolicyException")){ + + PolicyException pe = new PolicyException(); + pe.setMessageId(messageId); + pe.setText(text); + if(variables != null){ + for(String variable: variables){ + pe.getVariables().add(variable); + } + } + re.setPolicyException(pe); + + } else { + + ServiceException se = new ServiceException(); + se.setMessageId(messageId); + se.setText(text); + if(variables != null){ + if(variables != null){ + for(String variable: variables){ + se.getVariables().add(variable); + } + } + } + re.setServiceException(se); + } String requestErrorStr = null; try{ - ObjectMapper mapper = new ObjectMapper(); - mapper.setSerializationInclusion(JsonSerialize.Inclusion.NON_DEFAULT); - requestErrorStr = mapper.writeValueAsString(re); + ObjectMapper mapper = new ObjectMapper(); + mapper.setSerializationInclusion(JsonSerialize.Inclusion.NON_DEFAULT); + requestErrorStr = mapper.writeValueAsString(re); }catch(Exception e){ - msoLogger.error (MessageEnum.APIH_VALIDATION_ERROR, "", "", MsoLogger.ErrorCode.DataError, "Exception in buildServiceErrorResponse writing exceptionType to string ", e); + msoLogger.error (MessageEnum.APIH_VALIDATION_ERROR, "", "", MsoLogger.ErrorCode.DataError, "Exception in buildServiceErrorResponse writing exceptionType to string ", e); } - + return Response.status (httpResponseCode).entity(requestErrorStr).build (); - + } + private int reqVersionToInt(String version){ + if(version!=null){ + return Integer.parseInt(version.substring(1)); + }else{ + return 0; + } + } // Parse request JSON - void parse (ServiceInstancesRequest sir, HashMap<String,String> instanceIdMap, Action action) throws ValidationException { + void parse (ServiceInstancesRequest sir, HashMap<String,String> instanceIdMap, Action action, String version) throws ValidationException { msoLogger.debug ("Validating the Service Instance request"); - + this.sir = sir; this.action = action; - + this.reqVersion = reqVersionToInt(version); + msoLogger.debug ("Incoming version is: " + version + " coverting to int: " + this.reqVersion); + + try{ - ObjectMapper mapper = new ObjectMapper(); - //mapper.configure(Feature.WRAP_ROOT_VALUE, true); - requestJSON = mapper.writeValueAsString(sir.getRequestDetails()); + ObjectMapper mapper = new ObjectMapper(); + //mapper.configure(Feature.WRAP_ROOT_VALUE, true); + requestJSON = mapper.writeValueAsString(sir.getRequestDetails()); } catch(Exception e){ - throw new ValidationException ("Parse ServiceInstanceRequest to JSON string"); - } - + throw new ValidationException ("Parse ServiceInstanceRequest to JSON string"); + } + if(instanceIdMap != null){ - if(instanceIdMap.get("serviceInstanceId") != null){ - if (!UUIDChecker.isValidUUID (instanceIdMap.get ("serviceInstanceId"))) { - throw new ValidationException ("serviceInstanceId"); - } - this.sir.setServiceInstanceId(instanceIdMap.get("serviceInstanceId")); - } - - if(instanceIdMap.get("vnfInstanceId") != null){ - if (!UUIDChecker.isValidUUID (instanceIdMap.get ("vnfInstanceId"))) { - throw new ValidationException ("vnfInstanceId"); - } - this.sir.setVnfInstanceId(instanceIdMap.get("vnfInstanceId")); - } - - if(instanceIdMap.get("vfModuleInstanceId") != null){ - if (!UUIDChecker.isValidUUID (instanceIdMap.get ("vfModuleInstanceId"))) { - throw new ValidationException ("vfModuleInstanceId"); - } - this.sir.setVfModuleInstanceId(instanceIdMap.get("vfModuleInstanceId")); - } - - if(instanceIdMap.get("volumeGroupInstanceId") != null){ - if (!UUIDChecker.isValidUUID (instanceIdMap.get ("volumeGroupInstanceId"))) { - throw new ValidationException ("volumeGroupInstanceId"); - } - this.sir.setVolumeGroupInstanceId(instanceIdMap.get("volumeGroupInstanceId")); - } - - if(instanceIdMap.get("networkInstanceId") != null){ - if (!UUIDChecker.isValidUUID (instanceIdMap.get ("networkInstanceId"))) { - throw new ValidationException ("networkInstanceId"); - } - this.sir.setNetworkInstanceId(instanceIdMap.get("networkInstanceId")); - } + if(instanceIdMap.get("serviceInstanceId") != null){ + if (!UUIDChecker.isValidUUID (instanceIdMap.get ("serviceInstanceId"))) { + throw new ValidationException ("serviceInstanceId"); + } + this.sir.setServiceInstanceId(instanceIdMap.get("serviceInstanceId")); + } + + if(instanceIdMap.get("vnfInstanceId") != null){ + if (!UUIDChecker.isValidUUID (instanceIdMap.get ("vnfInstanceId"))) { + throw new ValidationException ("vnfInstanceId"); + } + this.sir.setVnfInstanceId(instanceIdMap.get("vnfInstanceId")); + } + + if(instanceIdMap.get("vfModuleInstanceId") != null){ + if (!UUIDChecker.isValidUUID (instanceIdMap.get ("vfModuleInstanceId"))) { + throw new ValidationException ("vfModuleInstanceId"); + } + this.sir.setVfModuleInstanceId(instanceIdMap.get("vfModuleInstanceId")); + } + + if(instanceIdMap.get("volumeGroupInstanceId") != null){ + if (!UUIDChecker.isValidUUID (instanceIdMap.get ("volumeGroupInstanceId"))) { + throw new ValidationException ("volumeGroupInstanceId"); + } + this.sir.setVolumeGroupInstanceId(instanceIdMap.get("volumeGroupInstanceId")); + } + + if(instanceIdMap.get("networkInstanceId") != null){ + if (!UUIDChecker.isValidUUID (instanceIdMap.get ("networkInstanceId"))) { + throw new ValidationException ("networkInstanceId"); + } + this.sir.setNetworkInstanceId(instanceIdMap.get("networkInstanceId")); + } } - + + RequestParameters requestParameters = sir.getRequestDetails().getRequestParameters(); + if(this.reqVersion >= 3){ + if(requestParameters!=null){ + this.aLaCarteFlag = sir.getRequestDetails().getRequestParameters().getALaCarte(); + }else{ + this.aLaCarteFlag = false; + } + }else{ + this.aLaCarteFlag = true; + } + + if(requestParameters != null && (reqVersion < 3) && requestParameters.getAutoBuildVfModules()){ + throw new ValidationException("AutoBuildVfModule", version); + } + this.modelInfo = sir.getRequestDetails().getModelInfo(); - + if (this.modelInfo == null) { throw new ValidationException ("model-info"); } - + this.requestInfo = sir.getRequestDetails().getRequestInfo(); - + if (this.requestInfo == null) { throw new ValidationException ("requestInfo"); } - + if (modelInfo.getModelType () == null) { - throw new ValidationException ("modelType"); - } - + throw new ValidationException ("modelType"); + } + this.requestScope = modelInfo.getModelType().name(); - - if (empty (modelInfo.getModelInvariantId ()) && !(requestScope.equalsIgnoreCase (ModelType.network.name ()) && - (action == Action.createInstance || action == Action.updateInstance))) { - throw new ValidationException ("modelInvariantId"); + + //is required for serviceInstance delete macro when aLaCarte=false (v3) + //create and updates except for network + if (empty (modelInfo.getModelInvariantId ()) && ((this.reqVersion >2 && !this.aLaCarteFlag && requestScope.equalsIgnoreCase(ModelType.service.name()) && action == Action.deleteInstance) || + !(requestScope.equalsIgnoreCase (ModelType.network.name ())) && (action == Action.createInstance || action == Action.updateInstance))) { + throw new ValidationException ("modelInvariantId"); } - + if (!empty (modelInfo.getModelInvariantId ()) && !UUIDChecker.isValidUUID (modelInfo.getModelInvariantId ())) { - throw new ValidationException ("modelInvariantId format"); - } - - if (empty (modelInfo.getModelName ()) && (action == Action.createInstance || action == Action.updateInstance || (action == Action.deleteInstance && - (requestScope.equalsIgnoreCase (ModelType.network.name ()) || requestScope.equalsIgnoreCase (ModelType.vfModule.name ()))))) { - throw new ValidationException ("modelName"); - } - - if (empty (modelInfo.getModelVersion ()) && !(requestScope.equalsIgnoreCase (ModelType.network.name ()) && - (action == Action.createInstance || action == Action.updateInstance))) { - throw new ValidationException ("modelVersion"); - } - + throw new ValidationException ("modelInvariantId format"); + } + + if (this.reqVersion <= 2 && empty (modelInfo.getModelName ()) && (action == Action.createInstance || action == Action.updateInstance || (action == Action.deleteInstance && + (requestScope.equalsIgnoreCase (ModelType.network.name ()) || requestScope.equalsIgnoreCase (ModelType.vfModule.name ()))))) { + throw new ValidationException ("modelName"); + } + if(this.reqVersion > 2 && empty (modelInfo.getModelName ()) && (action == Action.createInstance || action == Action.updateInstance || (action == Action.deleteInstance && + (requestScope.equalsIgnoreCase (ModelType.vfModule.name ()))))){ + throw new ValidationException ("modelName"); + } + + if (empty (modelInfo.getModelVersion ()) && ((this.reqVersion >2 && !this.aLaCarteFlag && requestScope.equalsIgnoreCase(ModelType.service.name()) && action == Action.deleteInstance) || + !(requestScope.equalsIgnoreCase (ModelType.network.name ())) && (action == Action.createInstance || action == Action.updateInstance))) { + throw new ValidationException ("modelVersion"); + } + if(requestScope.equalsIgnoreCase(ModelType.vnf.name()) && action != Action.deleteInstance && empty (modelInfo.getModelCustomizationName ())) { - throw new ValidationException ("modelCustomizationName"); + if(this.reqVersion<=2){ + throw new ValidationException ("modelCustomizationName"); + } else if (!UUIDChecker.isValidUUID (modelInfo.getModelCustomizationId())) { + throw new ValidationException ("modelCustomizationId or modelCustomizationName"); + } + } + + if(this.reqVersion > 2 && (!UUIDChecker.isValidUUID (modelInfo.getModelCustomizationId())) && requestScope.equalsIgnoreCase (ModelType.network.name ()) + && (action == Action.updateInstance || action == Action.createInstance)){ + throw new ValidationException ("modelCustomizationId"); } - + + if(!empty(modelInfo.getModelNameVersionId())){ + modelInfo.setModelVersionId(modelInfo.getModelNameVersionId()); + } + if(!empty(modelInfo.getModelVersionId())){ + modelInfo.setModelNameVersionId(modelInfo.getModelVersionId()); + } + this.cloudConfiguration = sir.getRequestDetails ().getCloudConfiguration (); - if (!requestScope.equalsIgnoreCase (ModelType.service.name ()) && cloudConfiguration == null) { - throw new ValidationException ("cloudConfiguration"); + if ( (((!this.aLaCarteFlag && requestScope.equalsIgnoreCase (ModelType.service.name ())) || + (!requestScope.equalsIgnoreCase (ModelType.service.name ())) && action != Action.updateInstance)) + && cloudConfiguration == null) { + throw new ValidationException ("cloudConfiguration"); } - + if (cloudConfiguration != null) { - if (empty (cloudConfiguration.getLcpCloudRegionId ())) { - throw new ValidationException ("lcpCloudRegionId"); - } - if (empty (cloudConfiguration.getTenantId ())) { - throw new ValidationException ("tenantId"); - } + if (empty (cloudConfiguration.getLcpCloudRegionId ())) { + throw new ValidationException ("lcpCloudRegionId"); + } + if (empty (cloudConfiguration.getTenantId ())) { + throw new ValidationException ("tenantId"); + } } - + + + if (requestScope.equalsIgnoreCase (ModelType.service.name ()) && action == Action.createInstance) { - if (sir.getRequestDetails ().getRequestParameters () == null) { - throw new ValidationException ("requestParameters"); - } - if (empty (sir.getRequestDetails ().getRequestParameters ().getSubscriptionServiceType ())) { - throw new ValidationException ("subscriptionServiceType"); - } - } - + if (requestParameters == null) { + throw new ValidationException ("requestParameters"); + } + if (empty (requestParameters.getSubscriptionServiceType ())) { + throw new ValidationException ("subscriptionServiceType"); + } + } + if(requestScope.equalsIgnoreCase(ModelType.service.name())){ - this.serviceInstanceType = modelInfo.getModelName(); + this.serviceInstanceType = modelInfo.getModelName(); } - + if(requestScope.equalsIgnoreCase(ModelType.network.name())){ - this.networkType = modelInfo.getModelName(); - } - - // Verify instanceName existence and format - if (empty (requestInfo.getInstanceName ()) && action == Action.createInstance) { - throw new ValidationException ("instanceName"); - } - - if (!empty (requestInfo.getInstanceName ()) && !requestInfo.getInstanceName ().matches (Constants.VALID_INSTANCE_NAME_FORMAT)) { - throw new ValidationException ("instanceName format"); - } - + this.networkType = modelInfo.getModelName(); + } + + // Verify instanceName existence and format except for macro serviceInstance + if (this.reqVersion < 3 && requestScope.equalsIgnoreCase (ModelType.service.name ()) && empty (requestInfo.getInstanceName ()) && action == Action.createInstance) { + throw new ValidationException ("instanceName"); + } + + if (!empty (requestInfo.getInstanceName ())) { + if (!requestInfo.getInstanceName ().matches (Constants.VALID_INSTANCE_NAME_FORMAT)) { + throw new ValidationException ("instanceName format"); + } + } + if (empty (requestInfo.getProductFamilyId ()) && ((requestScope.equalsIgnoreCase (ModelType.vnf.name ()) && action == Action.createInstance) || - (requestScope.equalsIgnoreCase (ModelType.network.name ()) && (action == Action.createInstance || action == Action.updateInstance)))) { - throw new ValidationException ("productFamilyId"); - } - + (requestScope.equalsIgnoreCase (ModelType.network.name ()) && (action == Action.createInstance || action == Action.updateInstance)))) { + throw new ValidationException ("productFamilyId"); + } + if (empty (requestInfo.getSource ())) { - throw new ValidationException ("source"); + throw new ValidationException ("source"); } - + RelatedInstanceList[] instanceList = sir.getRequestDetails().getRelatedInstanceList(); @@ -344,169 +395,202 @@ public class MsoRequest { String asdcServiceModelVersion = null; String volumeGroupId = null; boolean isRelatedServiceInstancePresent = false; - boolean isRelatedVnfInstancePresent = false; + boolean isRelatedVnfInstancePresent = false; if (instanceList != null) { - for(RelatedInstanceList relatedInstanceList : instanceList){ - RelatedInstance relatedInstance = relatedInstanceList.getRelatedInstance(); + for(RelatedInstanceList relatedInstanceList : instanceList){ + RelatedInstance relatedInstance = relatedInstanceList.getRelatedInstance(); + + if (relatedInstance.getModelInfo () == null) { + throw new ValidationException ("modelInfo in relatedInstance"); + } + + if (relatedInstance.getModelInfo ().getModelType () == null) { + throw new ValidationException ("modelType in relatedInstance"); + } + + + if (!empty (relatedInstance.getInstanceName ())) { + if (!relatedInstance.getInstanceName ().matches (Constants.VALID_INSTANCE_NAME_FORMAT)) { + throw new ValidationException ("instanceName format in relatedInstance"); + } + } + + if (empty (relatedInstance.getInstanceId ())) { + throw new ValidationException ("instanceId in relatedInstance"); + } + + if (!UUIDChecker.isValidUUID (relatedInstance.getInstanceId ())) { + throw new ValidationException ("instanceId format in relatedInstance"); + } + + + if (action != Action.deleteInstance) { + + // ModelInvariantId is not required in volumeGroup relatedInstance + if(!(relatedInstance.getModelInfo ().getModelType ().equals(ModelType.volumeGroup)) && + empty (relatedInstance.getModelInfo ().getModelInvariantId ())) { + throw new ValidationException ("modelInvariantId in relatedInstance"); + } + + if (!empty (relatedInstance.getModelInfo ().getModelInvariantId ()) && + !UUIDChecker.isValidUUID (relatedInstance.getModelInfo ().getModelInvariantId ())) { + throw new ValidationException ("modelInvariantId format in relatedInstance"); + } + + if (empty(relatedInstance.getModelInfo ().getModelName ()) && + !(relatedInstance.getModelInfo ().getModelType ().equals (ModelType.volumeGroup))) { + throw new ValidationException ("modelName in relatedInstance"); + } + + if (empty (relatedInstance.getModelInfo ().getModelVersion ()) && + !(relatedInstance.getModelInfo ().getModelType ().equals (ModelType.volumeGroup))) { + throw new ValidationException ("modelVersion in relatedInstance"); + } + } + + if (empty (relatedInstance.getModelInfo ().getModelCustomizationName ()) && + relatedInstance.getModelInfo ().getModelType ().equals (ModelType.vnf)) { + throw new ValidationException ("modelCustomizationName in relatedInstance"); + } + + if(relatedInstance.getModelInfo().getModelType().equals(ModelType.service)) { + isRelatedServiceInstancePresent = true; + if (!relatedInstance.getInstanceId ().equals (this.sir.getServiceInstanceId ())) { + throw new ValidationException ("serviceInstanceId matching the serviceInstanceId in request URI"); + } + serviceModelName = relatedInstance.getModelInfo ().getModelName (); + asdcServiceModelVersion = relatedInstance.getModelInfo().getModelVersion (); + } + else if(relatedInstance.getModelInfo().getModelType().equals(ModelType.vnf)) { + isRelatedVnfInstancePresent = true; + if (!relatedInstance.getInstanceId ().equals (this.sir.getVnfInstanceId ())) { + throw new ValidationException ("vnfInstanceId matching the vnfInstanceId in request URI"); + } + vnfModelName = relatedInstance.getModelInfo().getModelCustomizationName(); + } + else if(relatedInstance.getModelInfo().getModelType().equals(ModelType.volumeGroup)) { + volumeGroupId = relatedInstance.getInstanceId (); + } + } + + + if(requestScope.equalsIgnoreCase (ModelType.volumeGroup.name ())) { + if (!isRelatedServiceInstancePresent) { + throw new ValidationException ("related service instance for volumeGroup request"); + } + if (!isRelatedVnfInstancePresent) { + throw new ValidationException ("related vnf instance for volumeGroup request"); + } + this.serviceInstanceType = serviceModelName; + this.vnfType = serviceModelName + "/" + vnfModelName; + this.asdcServiceModelVersion = asdcServiceModelVersion; + } + else if(requestScope.equalsIgnoreCase(ModelType.vfModule.name ())) { + if (!isRelatedServiceInstancePresent) { + throw new ValidationException ("related service instance for vfModule request"); + } + if (!isRelatedVnfInstancePresent) { + throw new ValidationException ("related vnf instance for vfModule request"); + } + String vfModuleModelName = modelInfo.getModelName (); + this.vfModuleModelName = vfModuleModelName; + this.serviceInstanceType = serviceModelName; + this.vnfType = serviceModelName + "/" + vnfModelName; + this.asdcServiceModelVersion = asdcServiceModelVersion; + this.vfModuleType = vnfType + "::" + vfModuleModelName; + this.sir.setVolumeGroupInstanceId (volumeGroupId); + } + else if (requestScope.equalsIgnoreCase (ModelType.vnf.name ())) { + if (!isRelatedServiceInstancePresent) { + throw new ValidationException ("related service instance for vnf request"); + } + this.vnfType = serviceModelName + "/" + sir.getRequestDetails().getModelInfo().getModelCustomizationName(); + } + } + else if ((( requestScope.equalsIgnoreCase(ModelType.vnf.name ()) || requestScope.equalsIgnoreCase(ModelType.volumeGroup.name ()) || requestScope.equalsIgnoreCase(ModelType.vfModule.name ()) ) && (action == Action.createInstance)) || + (this.reqVersion > 2 && (requestScope.equalsIgnoreCase(ModelType.volumeGroup.name ()) || requestScope.equalsIgnoreCase(ModelType.vfModule.name ())) && action == Action.updateInstance)){ + msoLogger.debug ("related instance exception"); + throw new ValidationException ("related instances"); + } - if (!empty (relatedInstance.getInstanceName ()) && !relatedInstance.getInstanceName ().matches (Constants.VALID_INSTANCE_NAME_FORMAT)) { - throw new ValidationException ("instanceName format in relatedInstance"); - } + } - if (empty (relatedInstance.getInstanceId ())) { - throw new ValidationException ("instanceId in relatedInstance"); - } + void parseOrchestration (ServiceInstancesRequest sir) throws ValidationException { - if (!UUIDChecker.isValidUUID (relatedInstance.getInstanceId ())) { - throw new ValidationException ("instanceId format in relatedInstance"); - } + msoLogger.debug ("Validating the Orchestration request"); - if (relatedInstance.getModelInfo () == null) { - throw new ValidationException ("modelInfo in relatedInstance"); - } + this.sir = sir; - if (relatedInstance.getModelInfo ().getModelType () == null) { - throw new ValidationException ("modelType in relatedInstance"); - } + try{ + ObjectMapper mapper = new ObjectMapper(); + //mapper.configure(Feature.WRAP_ROOT_VALUE, true); + requestJSON = mapper.writeValueAsString(sir.getRequestDetails()); - if (action != Action.deleteInstance) { - - if (empty (relatedInstance.getModelInfo ().getModelInvariantId ()) && - !(requestScope.equalsIgnoreCase (ModelType.vfModule.name ()) && action == Action.createInstance && - relatedInstance.getModelInfo ().getModelType ().equals(ModelType.volumeGroup))) { - throw new ValidationException ("modelInvariantId in relatedInstance"); - } - - if (!empty (relatedInstance.getModelInfo ().getModelInvariantId ()) && - !UUIDChecker.isValidUUID (relatedInstance.getModelInfo ().getModelInvariantId ())) { - throw new ValidationException ("modelInvariantId format in relatedInstance"); - } - - if (empty(relatedInstance.getModelInfo ().getModelName ()) && - !(requestScope.equalsIgnoreCase (ModelType.vfModule.name ()) && action == Action.createInstance && - relatedInstance.getModelInfo ().getModelType ().equals (ModelType.volumeGroup))) { - throw new ValidationException ("modelName in relatedInstance"); - } - - if (empty (relatedInstance.getModelInfo ().getModelVersion ()) && - !(requestScope.equalsIgnoreCase (ModelType.vfModule.name ()) && action == Action.createInstance && - relatedInstance.getModelInfo ().getModelType ().equals (ModelType.volumeGroup))) { - throw new ValidationException ("modelVersion in relatedInstance"); - } - } + } catch(Exception e){ + throw new ValidationException ("Parse ServiceInstanceRequest to JSON string", e); + } - if (empty (relatedInstance.getModelInfo ().getModelCustomizationName ()) && - relatedInstance.getModelInfo ().getModelType ().equals (ModelType.vnf)) { - throw new ValidationException ("modelCustomizationName in relatedInstance"); - } + this.requestInfo = sir.getRequestDetails().getRequestInfo(); - if(relatedInstance.getModelInfo().getModelType().equals(ModelType.service)) { - isRelatedServiceInstancePresent = true; - if (!relatedInstance.getInstanceId ().equals (this.sir.getServiceInstanceId ())) { - throw new ValidationException ("serviceInstanceId matching the serviceInstanceId in request URI"); - } - serviceModelName = relatedInstance.getModelInfo ().getModelName (); - asdcServiceModelVersion = relatedInstance.getModelInfo().getModelVersion (); - } - else if(relatedInstance.getModelInfo().getModelType().equals(ModelType.vnf)) { - isRelatedVnfInstancePresent = true; - if (!relatedInstance.getInstanceId ().equals (this.sir.getVnfInstanceId ())) { - throw new ValidationException ("vnfInstanceId matching the vnfInstanceId in request URI"); - } - vnfModelName = relatedInstance.getModelInfo().getModelCustomizationName(); - } - else if(relatedInstance.getModelInfo().getModelType().equals(ModelType.volumeGroup)) { - volumeGroupId = relatedInstance.getInstanceId (); - } - } - - - if(requestScope.equalsIgnoreCase (ModelType.volumeGroup.name ())) { - if (!isRelatedServiceInstancePresent) { - throw new ValidationException ("related service instance for volumeGroup request"); - } - if (!isRelatedVnfInstancePresent) { - throw new ValidationException ("related vnf instance for volumeGroup request"); - } - this.serviceInstanceType = serviceModelName; - this.vnfType = serviceModelName + "/" + vnfModelName; - this.asdcServiceModelVersion = asdcServiceModelVersion; - } - else if(requestScope.equalsIgnoreCase(ModelType.vfModule.name ())) { - if (!isRelatedServiceInstancePresent) { - throw new ValidationException ("related service instance for vfModule request"); - } - if (!isRelatedVnfInstancePresent) { - throw new ValidationException ("related vnf instance for vfModule request"); - } - String vfModuleModelName = modelInfo.getModelName (); - this.vfModuleModelName = vfModuleModelName; - this.serviceInstanceType = serviceModelName; - this.vnfType = serviceModelName + "/" + vnfModelName; - this.asdcServiceModelVersion = asdcServiceModelVersion; - this.vfModuleType = vnfType + "::" + vfModuleModelName; - this.sir.setVolumeGroupInstanceId (volumeGroupId); - } - else if (requestScope.equalsIgnoreCase (ModelType.vnf.name ())) { - if (!isRelatedServiceInstancePresent) { - throw new ValidationException ("related service instance for vnf request"); - } - this.vnfType = serviceModelName + "/" + sir.getRequestDetails().getModelInfo().getModelCustomizationName(); - } + if (this.requestInfo == null) { + throw new ValidationException ("requestInfo"); } - else if (action != Action.deleteInstance && !requestScope.equalsIgnoreCase(ModelType.service.name ()) && - !requestScope.equalsIgnoreCase(ModelType.network.name ())) { - throw new ValidationException ("related instances"); + + if (empty (requestInfo.getSource ())) { + throw new ValidationException ("source"); + } + if (empty (requestInfo.getRequestorId ())) { + throw new ValidationException ("requestorId"); } - } - + public Map<String, List<String>> getOrchestrationFilters (MultivaluedMap<String, String> queryParams) throws ValidationException { - String queryParam = null; + String queryParam = null; Map<String, List<String>> orchestrationFilterParams = new HashMap<String, List<String>>(); - - + + for (Entry<String,List<String>> entry : queryParams.entrySet()) { queryParam = entry.getKey(); - + try{ - if(queryParam.equalsIgnoreCase("filter")){ - - StringTokenizer st = new StringTokenizer(entry.getValue().get(0), ":"); - - int counter=0; - String mapKey=null; - List<String> orchestrationList = new ArrayList<String>(); - while (st.hasMoreElements()) { - if(counter == 0){ - mapKey = st.nextElement() + ""; - } else{ - orchestrationList.add(st.nextElement() + ""); - } - counter++; - } - orchestrationFilterParams.put(mapKey, orchestrationList); - } + if(queryParam.equalsIgnoreCase("filter")){ + + StringTokenizer st = new StringTokenizer(entry.getValue().get(0), ":"); + + int counter=0; + String mapKey=null; + List<String> orchestrationList = new ArrayList<String>(); + while (st.hasMoreElements()) { + if(counter == 0){ + mapKey = st.nextElement() + ""; + } else{ + orchestrationList.add(st.nextElement() + ""); + } + counter++; + } + orchestrationFilterParams.put(mapKey, orchestrationList); + } }catch(Exception e){ //msoLogger.error (MessageEnum.APIH_VALIDATION_ERROR, e); throw new ValidationException ("QueryParam ServiceInfo", e); - } - + } + } + return orchestrationFilterParams; - } + } public void createRequestRecord (Status status, Action action) { Session session = null; try { - session = HibernateUtil.getSessionFactory ().openSession (); + session = hibernateUtils.getSessionFactory ().openSession (); session.beginTransaction (); if (null == sir) { @@ -515,108 +599,106 @@ public class MsoRequest { InfraActiveRequests aq = new InfraActiveRequests (); aq.setRequestId (requestId); - + aq.setRequestAction(action.name()); aq.setAction(action.name()); - + Timestamp startTimeStamp = new Timestamp (System.currentTimeMillis()); - + aq.setStartTime (startTimeStamp); - - if (requestInfo != null) { - if(requestInfo.getSource() != null){ - aq.setSource(requestInfo.getSource()); - } - if(requestInfo.getCallbackUrl() != null){ - aq.setCallBackUrl(requestInfo.getCallbackUrl()); - } - if(requestInfo.getCorrelator() != null){ - aq.setCorrelator(requestInfo.getCorrelator()); - } - + if (requestInfo != null) { + + if(requestInfo.getSource() != null){ + aq.setSource(requestInfo.getSource()); + } + if(requestInfo.getCallbackUrl() != null){ + aq.setCallBackUrl(requestInfo.getCallbackUrl()); + } + if(requestInfo.getCorrelator() != null){ + aq.setCorrelator(requestInfo.getCorrelator()); + } + + if(requestInfo.getRequestorId() != null) { + aq.setRequestorId(requestInfo.getRequestorId()); + } } - - if (modelInfo != null) { - aq.setRequestScope(requestScope); + + if (modelInfo != null) { + aq.setRequestScope(requestScope); } - + if (cloudConfiguration != null) { - if(cloudConfiguration.getLcpCloudRegionId() != null) { - aq.setAicCloudRegion(cloudConfiguration.getLcpCloudRegionId()); - } + if(cloudConfiguration.getLcpCloudRegionId() != null) { + aq.setAicCloudRegion(cloudConfiguration.getLcpCloudRegionId()); + } - if(cloudConfiguration.getTenantId() != null) { - aq.setTenantId(cloudConfiguration.getTenantId()); - } + if(cloudConfiguration.getTenantId() != null) { + aq.setTenantId(cloudConfiguration.getTenantId()); + } } - + if(sir.getServiceInstanceId() != null){ - aq.setServiceInstanceId(sir.getServiceInstanceId()); + aq.setServiceInstanceId(sir.getServiceInstanceId()); } - + if(sir.getVnfInstanceId() != null){ - aq.setVnfId(sir.getVnfInstanceId()); + aq.setVnfId(sir.getVnfInstanceId()); } - if (null != requestScope) { - if (requestScope.equalsIgnoreCase(ModelType.service.name())) { - if (requestInfo.getInstanceName() != null) { - aq.setServiceInstanceName(requestInfo.getInstanceName()); - } - } - - if (requestScope.equalsIgnoreCase(ModelType.network.name())) { - aq.setNetworkName(requestInfo.getInstanceName()); - aq.setNetworkType(networkType); - aq.setNetworkId(sir.getNetworkInstanceId()); - } + if(ModelType.service.name().equalsIgnoreCase(requestScope)){ + if(requestInfo.getInstanceName() != null){ + aq.setServiceInstanceName(requestInfo.getInstanceName()); + } + } - if (requestScope.equalsIgnoreCase(ModelType.volumeGroup.name())) { - aq.setVolumeGroupId(sir.getVolumeGroupInstanceId()); - aq.setVolumeGroupName(requestInfo.getInstanceName()); - aq.setVnfType(vnfType); + if(ModelType.network.name().equalsIgnoreCase(requestScope)){ + aq.setNetworkName(requestInfo.getInstanceName()); + aq.setNetworkType(networkType); + aq.setNetworkId(sir.getNetworkInstanceId()); + } - } + if(ModelType.volumeGroup.name().equalsIgnoreCase(requestScope)){ + aq.setVolumeGroupId(sir.getVolumeGroupInstanceId()); + aq.setVolumeGroupName(requestInfo.getInstanceName()); + aq.setVnfType(vnfType); - if (requestScope.equalsIgnoreCase(ModelType.vfModule.name())) { - aq.setVfModuleName(requestInfo.getInstanceName()); - aq.setVfModuleModelName(modelInfo.getModelName()); - aq.setVfModuleId(sir.getVfModuleInstanceId()); - aq.setVolumeGroupId(sir.getVolumeGroupInstanceId()); - aq.setVnfType(vnfType); + } - } + if(ModelType.vfModule.name().equalsIgnoreCase(requestScope)){ + aq.setVfModuleName(requestInfo.getInstanceName()); + aq.setVfModuleModelName(modelInfo.getModelName()); + aq.setVfModuleId(sir.getVfModuleInstanceId()); + aq.setVolumeGroupId(sir.getVolumeGroupInstanceId()); + aq.setVnfType(vnfType); - if (requestScope.equalsIgnoreCase(ModelType.vnf.name())) { - aq.setVnfName(requestInfo.getInstanceName()); - if (null != sir.getRequestDetails()) { - RelatedInstanceList[] instanceList = sir.getRequestDetails().getRelatedInstanceList(); + } - if (instanceList != null) { + if(ModelType.vnf.name().equalsIgnoreCase(requestScope)){ + aq.setVnfName(requestInfo.getInstanceName()); + if (null != sir.getRequestDetails()) { + RelatedInstanceList[] instanceList = sir.getRequestDetails().getRelatedInstanceList(); - for (RelatedInstanceList relatedInstanceList : instanceList) { + if (instanceList != null) { - RelatedInstance relatedInstance = relatedInstanceList.getRelatedInstance(); - if (relatedInstance.getModelInfo().getModelType().equals(ModelType.service)) { - aq.setVnfType(vnfType); - } - } - } - } - //aq.setVnfType(sir.getRequestDetails().getRelatedInstanceList()); + for(RelatedInstanceList relatedInstanceList : instanceList){ - } + RelatedInstance relatedInstance = relatedInstanceList.getRelatedInstance(); + if(relatedInstance.getModelInfo().getModelType().equals(ModelType.service)){ + aq.setVnfType(vnfType); + } + } + } + } } aq.setRequestBody (this.requestJSON); - - + aq.setRequestStatus (status.toString ()); aq.setLastModifiedBy (Constants.MODIFIED_BY_APIHANDLER); - + if ((status == Status.FAILED) || (status == Status.COMPLETE)) { aq.setStatusMessage (this.errorMessage); aq.setResponseBody (this.responseBody); @@ -625,14 +707,14 @@ public class MsoRequest { Timestamp endTimeStamp = new Timestamp (System.currentTimeMillis()); aq.setEndTime (endTimeStamp); } - + msoLogger.debug ("About to insert a record"); session.save (aq); session.getTransaction ().commit (); session.close (); } catch (Exception e) { - msoLogger.error (MessageEnum.APIH_DB_INSERT_EXC, "", "", MsoLogger.ErrorCode.DataError, "Exception when creation record request", e); + msoLogger.error (MessageEnum.APIH_DB_INSERT_EXC, "", "", MsoLogger.ErrorCode.DataError, "Exception when creation record request", e); if (session != null) { session.close (); } @@ -652,7 +734,7 @@ public class MsoRequest { this.responseBody, Constants.MODIFIED_BY_APIHANDLER); } catch (Exception e) { - msoLogger.error(MessageEnum.APIH_DB_UPDATE_EXC, e.getMessage(), "", "", MsoLogger.ErrorCode.DataError, "Exception when updating record in DB"); + msoLogger.error(MessageEnum.APIH_DB_UPDATE_EXC, e.getMessage(), "", "", MsoLogger.ErrorCode.DataError, "Exception when updating record in DB"); msoLogger.debug ("Exception: ", e); } } @@ -666,8 +748,8 @@ public class MsoRequest { InfraActiveRequests inProgress, String errorString) { - - + + // Log the failed request into the MSO Requests database return Response.status (httpResponseCode).entity (null).build (); @@ -676,7 +758,7 @@ public class MsoRequest { public Response buildResponseFailedValidation (int httpResponseCode, String exceptionMessage) { - + return Response.status (httpResponseCode).entity (null).build (); } @@ -728,13 +810,13 @@ public class MsoRequest { public RequestStatusType getStatus () { return status; } - + public String getServiceType () { - if (this.vnfInputs.getServiceType () != null) - return this.vnfInputs.getServiceType (); - if (this.vnfInputs.getServiceId () != null) - return this.vnfInputs.getServiceId (); - return null; + if (this.vnfInputs.getServiceType () != null) + return this.vnfInputs.getServiceType (); + if (this.vnfInputs.getServiceId () != null) + return this.vnfInputs.getServiceId (); + return null; } public void setStatus (RequestStatusType status) { @@ -742,46 +824,46 @@ public class MsoRequest { switch (status) { case FAILED: case COMPLETE: - this.progress = Constants.PROGRESS_REQUEST_COMPLETED; - break; + this.progress = Constants.PROGRESS_REQUEST_COMPLETED; + break; case IN_PROGRESS: - this.progress = Constants.PROGRESS_REQUEST_IN_PROGRESS; - break; + this.progress = Constants.PROGRESS_REQUEST_IN_PROGRESS; + break; } } - + public ModelInfo getModelInfo() { - return modelInfo; + return modelInfo; } - + public ServiceInstancesRequest getServiceInstancesRequest() { - return sir; + return sir; } - + public String getServiceInstanceType () { - return serviceInstanceType; - } - + return serviceInstanceType; + } + public String getNetworkType () { - return networkType; + return networkType; } - + public String getVnfType () { - return vnfType; + return vnfType; } - + public String getVfModuleModelName () { - return vfModuleModelName; + return vfModuleModelName; } - + public String getVfModuleType () { - return vfModuleType; + return vfModuleType; } - + public String getAsdcServiceModelVersion () { - return asdcServiceModelVersion; + return asdcServiceModelVersion; } - + public static String domToStr (Document doc) { if (doc == null) { return null; @@ -816,16 +898,16 @@ public class MsoRequest { } return null; } - + public void addBPMNSpecificInputs(String personaModelId, String personaModelVersion, Boolean isBaseVfModule, - String vnfPersonaModelId, String vnfPersonaModelVersion) { - vnfInputs.setPersonaModelId(personaModelId); - vnfInputs.setPersonaModelVersion(personaModelVersion); - vnfInputs.setIsBaseVfModule(isBaseVfModule); - vnfInputs.setVnfPersonaModelId(vnfPersonaModelId); - vnfInputs.setVnfPersonaModelVersion(vnfPersonaModelVersion); + String vnfPersonaModelId, String vnfPersonaModelVersion) { + vnfInputs.setPersonaModelId(personaModelId); + vnfInputs.setPersonaModelVersion(personaModelVersion); + vnfInputs.setIsBaseVfModule(isBaseVfModule); + vnfInputs.setVnfPersonaModelId(vnfPersonaModelId); + vnfInputs.setVnfPersonaModelVersion(vnfPersonaModelVersion); - this.vnfReq.setVnfInputs(vnfInputs); + this.vnfReq.setVnfInputs(vnfInputs); StringWriter stringWriter = new StringWriter (); try { @@ -846,8 +928,33 @@ public class MsoRequest { } - + private static boolean empty(String s) { - return (s == null || s.trim().isEmpty()); + return (s == null || s.trim().isEmpty()); + } + + public String getRequestJSON() throws JsonGenerationException, JsonMappingException, IOException { + ObjectMapper mapper = new ObjectMapper(); + mapper.setSerializationInclusion(Inclusion.NON_NULL); + //mapper.configure(Feature.WRAP_ROOT_VALUE, true); + msoLogger.debug ("building sir from object " + sir); + requestJSON = mapper.writeValueAsString(sir); + return requestJSON; } -} + + public boolean getALaCarteFlag() { + return aLaCarteFlag; + } + + public void setaLaCarteFlag(boolean aLaCarteFlag) { + this.aLaCarteFlag = aLaCarteFlag; + } + + public int getReqVersion() { + return reqVersion; + } + + public void setReqVersion(int reqVersion) { + this.reqVersion = reqVersion; + } +}
\ No newline at end of file |