aboutsummaryrefslogtreecommitdiffstats
path: root/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/ServiceInstances.java
diff options
context:
space:
mode:
Diffstat (limited to 'mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/ServiceInstances.java')
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/ServiceInstances.java1400
1 files changed, 785 insertions, 615 deletions
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/ServiceInstances.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/ServiceInstances.java
index 988d72cc6f..91888f8a35 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/ServiceInstances.java
+++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/ServiceInstances.java
@@ -36,55 +36,91 @@ import javax.ws.rs.core.Response;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.codehaus.jackson.map.ObjectMapper;
-
-import org.openecomp.mso.apihandler.common.*;
-import org.openecomp.mso.apihandlerinfra.serviceinstancebeans.*;
+import org.openecomp.mso.apihandler.common.ErrorNumbers;
+import org.openecomp.mso.apihandler.common.RequestClient;
+import org.openecomp.mso.apihandler.common.RequestClientFactory;
+import org.openecomp.mso.apihandler.common.ResponseHandler;
+import org.openecomp.mso.apihandler.common.ValidationException;
+import org.openecomp.mso.apihandlerinfra.serviceinstancebeans.ModelInfo;
+import org.openecomp.mso.apihandlerinfra.serviceinstancebeans.RelatedInstance;
+import org.openecomp.mso.apihandlerinfra.serviceinstancebeans.RelatedInstanceList;
+import org.openecomp.mso.apihandlerinfra.serviceinstancebeans.RequestParameters;
+import org.openecomp.mso.apihandlerinfra.serviceinstancebeans.RequestReferences;
+import org.openecomp.mso.apihandlerinfra.serviceinstancebeans.ServiceInstancesRequest;
+import org.openecomp.mso.apihandlerinfra.serviceinstancebeans.ServiceInstancesResponse;
import org.openecomp.mso.db.catalog.CatalogDatabase;
-import org.openecomp.mso.db.catalog.beans.*;
+import org.openecomp.mso.db.catalog.beans.NetworkResource;
+import org.openecomp.mso.db.catalog.beans.Recipe;
+import org.openecomp.mso.db.catalog.beans.Service;
+import org.openecomp.mso.db.catalog.beans.ServiceRecipe;
+import org.openecomp.mso.db.catalog.beans.VfModule;
+import org.openecomp.mso.db.catalog.beans.VfModuleCustomization;
+import org.openecomp.mso.db.catalog.beans.VnfRecipe;
+import org.openecomp.mso.db.catalog.beans.VnfResource;
+import org.openecomp.mso.db.catalog.beans.VnfResourceCustomization;
import org.openecomp.mso.logger.MessageEnum;
import org.openecomp.mso.logger.MsoAlarmLogger;
import org.openecomp.mso.logger.MsoLogger;
-import org.openecomp.mso.properties.MsoJavaProperties;
-import org.openecomp.mso.properties.MsoPropertiesFactory;
import org.openecomp.mso.requestsdb.InfraActiveRequests;
import org.openecomp.mso.requestsdb.RequestsDatabase;
import org.openecomp.mso.utils.UUIDChecker;
-@Path("/serviceInstances/{version:[vV][2-3]}")
+import com.wordnik.swagger.annotations.Api;
+import com.wordnik.swagger.annotations.ApiOperation;
+
+@Path("/serviceInstances")
+@Api(value="/serviceInstances",description="API Requests for Service Instances")
public class ServiceInstances {
- private HashMap<String, String> instanceIdMap = new HashMap<String,String>();
+ private HashMap<String, String> instanceIdMap = new HashMap<String,String>();
+ private static MsoLogger msoLogger = MsoLogger.getMsoLogger (MsoLogger.Catalog.APIH);
+ private static MsoAlarmLogger alarmLogger = new MsoAlarmLogger ();
+ public final static String MSO_PROP_APIHANDLER_INFRA = "MSO_PROP_APIHANDLER_INFRA";
- private static MsoLogger msoLogger = MsoLogger.getMsoLogger (MsoLogger.Catalog.APIH);
+ @POST
+ @Path("/{version:[vV][3-5]}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value="Create a Service Instance on a version provided",response=Response.class)
+ public Response createServiceInstance(String request, @PathParam("version") String version) {
- private static MsoAlarmLogger alarmLogger = new MsoAlarmLogger ();
+ Response response = serviceInstances(request, Action.createInstance, null, version);
- public final static String MSO_PROP_APIHANDLER_INFRA = "MSO_PROP_APIHANDLER_INFRA";
+ return response;
+ }
+
+ @POST
+ @Path("/{version:[vV][5]}/{serviceInstanceId}/activate")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value="Activate provided Service Instance",response=Response.class)
+ public Response activateServiceInstance(String request, @PathParam("version") String version, @PathParam("serviceInstanceId") String serviceInstanceId) {
- private static MsoJavaProperties props = MsoPropertiesUtils.loadMsoProperties ();
+ instanceIdMap.put("serviceInstanceId", serviceInstanceId);
+ Response response = serviceInstances(request, Action.activateInstance, instanceIdMap, version);
- /**
- *
- */
- public ServiceInstances() {
- // TODO Auto-generated constructor stub
+ return response;
}
-
+
@POST
- @Path("/")
+ @Path("/{version:[vV][5]}/{serviceInstanceId}/deactivate")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
- public Response createServiceInstance(String request, @PathParam("version") String version) {
+ @ApiOperation(value="Deactivate provided Service Instance",response=Response.class)
+ public Response deactivateServiceInstance(String request, @PathParam("version") String version, @PathParam("serviceInstanceId") String serviceInstanceId) {
- Response response = serviceInstances(request, Action.createInstance, null, version);
+ instanceIdMap.put("serviceInstanceId", serviceInstanceId);
+ Response response = serviceInstances(request, Action.deactivateInstance, instanceIdMap, version);
return response;
}
+
@DELETE
- @Path("/{serviceInstanceId}")
+ @Path("/{version:[vV][3-5]}/{serviceInstanceId}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value="Delete provided Service Instance",response=Response.class)
public Response deleteServiceInstance(String request, @PathParam("version") String version, @PathParam("serviceInstanceId") String serviceInstanceId) {
instanceIdMap.put("serviceInstanceId", serviceInstanceId);
@@ -93,23 +129,56 @@ public class ServiceInstances {
}
@POST
- @Path("/{serviceInstanceId}/vnfs")
+ @Path("/{version:[vV][3-5]}/{serviceInstanceId}/vnfs")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value="Create VNF on a specified version and serviceInstance",response=Response.class)
public Response createVnfInstance(String request, @PathParam("version") String version, @PathParam("serviceInstanceId") String serviceInstanceId) {
- msoLogger.debug ("version is: " + version);
+ msoLogger.debug ("version is: " + version);
instanceIdMap.put("serviceInstanceId", serviceInstanceId);
Response response = serviceInstances(request, Action.createInstance, instanceIdMap, version);
return response;
}
+
+ @POST
+ @Path("/{version:[vV][5]}/{serviceInstanceId}/vnfs/{vnfInstanceId}/replace")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value="Replace provided VNF instance",response=Response.class)
+ public Response replaceVnfInstance(String request, @PathParam("version") String version, @PathParam("serviceInstanceId") String serviceInstanceId,
+ @PathParam("vnfInstanceId") String vnfInstanceId) {
+ msoLogger.debug ("version is: " + version);
+ instanceIdMap.put("serviceInstanceId", serviceInstanceId);
+ instanceIdMap.put("vnfInstanceId", vnfInstanceId);
+ Response response = serviceInstances(request, Action.replaceInstance, instanceIdMap, version);
+
+ return response;
+ }
+
+ @PUT
+ @Path("/{version:[vV][5]}/{serviceInstanceId}/vnfs/{vnfInstanceId}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value="Update VNF on a specified version, serviceInstance and vnfInstance",response=Response.class)
+ public Response updateVnfInstance(String request, @PathParam("version") String version, @PathParam("serviceInstanceId") String serviceInstanceId,
+ @PathParam("vnfInstanceId") String vnfInstanceId) {
+
+ instanceIdMap.put("serviceInstanceId", serviceInstanceId);
+ instanceIdMap.put("vnfInstanceId", vnfInstanceId);
+ Response response = serviceInstances(request, Action.updateInstance, instanceIdMap, version);
+
+ return response;
+ }
+
@DELETE
- @Path("/{serviceInstanceId}/vnfs/{vnfInstanceId}")
+ @Path("/{version:[vV][3-5]}/{serviceInstanceId}/vnfs/{vnfInstanceId}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value="Delete provided VNF instance",response=Response.class)
public Response deleteVnfInstance(String request, @PathParam("version") String version, @PathParam("serviceInstanceId") String serviceInstanceId,
- @PathParam("vnfInstanceId") String vnfInstanceId) {
+ @PathParam("vnfInstanceId") String vnfInstanceId) {
instanceIdMap.put("serviceInstanceId", serviceInstanceId);
instanceIdMap.put("vnfInstanceId", vnfInstanceId);
@@ -119,26 +188,46 @@ public class ServiceInstances {
}
@POST
- @Path("/{serviceInstanceId}/vnfs/{vnfInstanceId}/vfModules")
+ @Path("/{version:[vV][3-5]}/{serviceInstanceId}/vnfs/{vnfInstanceId}/vfModules")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value="Create VfModule on a specified version, serviceInstance and vnfInstance",response=Response.class)
public Response createVfModuleInstance(String request, @PathParam("version") String version, @PathParam("serviceInstanceId") String serviceInstanceId,
- @PathParam("vnfInstanceId") String vnfInstanceId) {
- msoLogger.debug ("version is: " + version);
+ @PathParam("vnfInstanceId") String vnfInstanceId) {
+ msoLogger.debug ("version is: " + version);
instanceIdMap.put("serviceInstanceId", serviceInstanceId);
instanceIdMap.put("vnfInstanceId", vnfInstanceId);
Response response = serviceInstances(request, Action.createInstance, instanceIdMap, version);
return response;
}
+
+ @POST
+ @Path("/{version:[vV][5]}/{serviceInstanceId}/vnfs/{vnfInstanceId}/vfModules/{vfmoduleInstanceId}/replace")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value="Create VfModule on a specified version, serviceInstance and vnfInstance",response=Response.class)
+ public Response replaceVfModuleInstance(String request, @PathParam("version") String version, @PathParam("serviceInstanceId") String serviceInstanceId,
+ @PathParam("vnfInstanceId") String vnfInstanceId,
+ @PathParam("vfmoduleInstanceId") String vfmoduleInstanceId) {
+
+ msoLogger.debug ("version is: " + version);
+ instanceIdMap.put("serviceInstanceId", serviceInstanceId);
+ instanceIdMap.put("vnfInstanceId", vnfInstanceId);
+ instanceIdMap.put("vfModuleInstanceId", vfmoduleInstanceId);
+ Response response = serviceInstances(request, Action.replaceInstance, instanceIdMap, version);
+
+ return response;
+ }
@PUT
- @Path("/{serviceInstanceId}/vnfs/{vnfInstanceId}/vfModules/{vfmoduleInstanceId}")
+ @Path("/{version:[vV][3-5]}/{serviceInstanceId}/vnfs/{vnfInstanceId}/vfModules/{vfmoduleInstanceId}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value="Update VfModule on a specified version, serviceInstance, vnfInstance and vfModule",response=Response.class)
public Response updateVfModuleInstance(String request, @PathParam("version") String version, @PathParam("serviceInstanceId") String serviceInstanceId,
- @PathParam("vnfInstanceId") String vnfInstanceId,
- @PathParam("vfmoduleInstanceId") String vfmoduleInstanceId) {
+ @PathParam("vnfInstanceId") String vnfInstanceId,
+ @PathParam("vfmoduleInstanceId") String vfmoduleInstanceId) {
instanceIdMap.put("serviceInstanceId", serviceInstanceId);
instanceIdMap.put("vnfInstanceId", vnfInstanceId);
@@ -149,12 +238,13 @@ public class ServiceInstances {
}
@DELETE
- @Path("/{serviceInstanceId}/vnfs/{vnfInstanceId}/vfModules/{vfmoduleInstanceId}")
+ @Path("/{version:[vV][3-5]}/{serviceInstanceId}/vnfs/{vnfInstanceId}/vfModules/{vfmoduleInstanceId}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value="Delete provided VfModule instance",response=Response.class)
public Response deleteVfModuleInstance(String request, @PathParam("version") String version, @PathParam("serviceInstanceId") String serviceInstanceId,
- @PathParam("vnfInstanceId") String vnfInstanceId,
- @PathParam("vfmoduleInstanceId") String vfmoduleInstanceId) {
+ @PathParam("vnfInstanceId") String vnfInstanceId,
+ @PathParam("vfmoduleInstanceId") String vfmoduleInstanceId) {
instanceIdMap.put("serviceInstanceId", serviceInstanceId);
@@ -167,11 +257,12 @@ public class ServiceInstances {
@POST
- @Path("/{serviceInstanceId}/vnfs/{vnfInstanceId}/volumeGroups")
+ @Path("/{version:[vV][3-5]}/{serviceInstanceId}/vnfs/{vnfInstanceId}/volumeGroups")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value="Create VolumeGroup on a specified version, serviceInstance, vnfInstance",response=Response.class)
public Response createVolumeGroupInstance(String request, @PathParam("version") String version, @PathParam("serviceInstanceId") String serviceInstanceId,
- @PathParam("vnfInstanceId") String vnfInstanceId) {
+ @PathParam("vnfInstanceId") String vnfInstanceId) {
instanceIdMap.put("serviceInstanceId", serviceInstanceId);
instanceIdMap.put("vnfInstanceId", vnfInstanceId);
@@ -181,12 +272,13 @@ public class ServiceInstances {
}
@PUT
- @Path("/{serviceInstanceId}/vnfs/{vnfInstanceId}/volumeGroups/{volumeGroupInstanceId}")
+ @Path("/{version:[vV][3-5]}/{serviceInstanceId}/vnfs/{vnfInstanceId}/volumeGroups/{volumeGroupInstanceId}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value="Update VolumeGroup on a specified version, serviceInstance, vnfInstance and volumeGroup",response=Response.class)
public Response updateVolumeGroupInstance(String request, @PathParam("version") String version, @PathParam("serviceInstanceId") String serviceInstanceId,
- @PathParam("vnfInstanceId") String vnfInstanceId,
- @PathParam("volumeGroupInstanceId") String volumeGroupInstanceId) {
+ @PathParam("vnfInstanceId") String vnfInstanceId,
+ @PathParam("volumeGroupInstanceId") String volumeGroupInstanceId) {
instanceIdMap.put("serviceInstanceId", serviceInstanceId);
@@ -198,12 +290,13 @@ public class ServiceInstances {
}
@DELETE
- @Path("/{serviceInstanceId}/vnfs/{vnfInstanceId}/volumeGroups/{volumeGroupInstanceId}")
+ @Path("/{version:[vV][3-5]}/{serviceInstanceId}/vnfs/{vnfInstanceId}/volumeGroups/{volumeGroupInstanceId}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value="Delete provided VolumeGroup instance",response=Response.class)
public Response deleteVolumeGroupInstance(String request, @PathParam("version") String version, @PathParam("serviceInstanceId") String serviceInstanceId,
- @PathParam("vnfInstanceId") String vnfInstanceId,
- @PathParam("volumeGroupInstanceId") String volumeGroupInstanceId) {
+ @PathParam("vnfInstanceId") String vnfInstanceId,
+ @PathParam("volumeGroupInstanceId") String volumeGroupInstanceId) {
instanceIdMap.put("serviceInstanceId", serviceInstanceId);
@@ -215,9 +308,10 @@ public class ServiceInstances {
}
@POST
- @Path("/{serviceInstanceId}/networks")
+ @Path("/{version:[vV][3-5]}/{serviceInstanceId}/networks")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value="Create NetworkInstance on a specified version and serviceInstance ",response=Response.class)
public Response createNetworkInstance(String request, @PathParam("version") String version, @PathParam("serviceInstanceId") String serviceInstanceId) {
instanceIdMap.put("serviceInstanceId", serviceInstanceId);
@@ -227,11 +321,12 @@ public class ServiceInstances {
}
@PUT
- @Path("/{serviceInstanceId}/networks/{networkInstanceId}")
+ @Path("/{version:[vV][3-5]}/{serviceInstanceId}/networks/{networkInstanceId}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value="Update VolumeGroup on a specified version, serviceInstance, networkInstance",response=Response.class)
public Response updateNetworkInstance(String request, @PathParam("version") String version, @PathParam("serviceInstanceId") String serviceInstanceId,
- @PathParam("networkInstanceId") String networkInstanceId) {
+ @PathParam("networkInstanceId") String networkInstanceId) {
instanceIdMap.put("serviceInstanceId", serviceInstanceId);
instanceIdMap.put("networkInstanceId", networkInstanceId);
@@ -241,11 +336,12 @@ public class ServiceInstances {
}
@DELETE
- @Path("/{serviceInstanceId}/networks/{networkInstanceId}")
+ @Path("/{version:[vV][3-5]}/{serviceInstanceId}/networks/{networkInstanceId}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value="Delete provided Network instance",response=Response.class)
public Response deleteNetworkInstance(String request, @PathParam("version") String version, @PathParam("serviceInstanceId") String serviceInstanceId,
- @PathParam("networkInstanceId") String networkInstanceId) {
+ @PathParam("networkInstanceId") String networkInstanceId) {
instanceIdMap.put("serviceInstanceId", serviceInstanceId);
instanceIdMap.put("networkInstanceId", networkInstanceId);
@@ -258,573 +354,647 @@ public class ServiceInstances {
private Response serviceInstances(String requestJSON, Action action, HashMap<String,String> instanceIdMap, String version) {
- String requestId = UUIDChecker.generateUUID(msoLogger);
- long startTime = System.currentTimeMillis ();
- msoLogger.debug ("requestId is: " + requestId);
- ServiceInstancesRequest sir = null;
-
- MsoRequest msoRequest = new MsoRequest (requestId);
-
-
- try{
- ObjectMapper mapper = new ObjectMapper();
- sir = mapper.readValue(requestJSON, ServiceInstancesRequest.class);
-
- } catch(Exception e){
- msoLogger.debug ("Mapping of request to JSON object failed : ", e);
- Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_BAD_REQUEST, MsoException.ServiceException,
- "Mapping of request to JSON object failed. " + e.getMessage(),
- ErrorNumbers.SVC_BAD_PARAMETER, null);
- if (msoRequest.getRequestId () != null) {
- msoLogger.debug ("Mapping of request to JSON object failed");
- msoRequest.createRequestRecord (Status.FAILED, action);
- }
- msoLogger.error (MessageEnum.APIH_REQUEST_VALIDATION_ERROR, MSO_PROP_APIHANDLER_INFRA, "", "", MsoLogger.ErrorCode.SchemaError, requestJSON, e);
- msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.SchemaError, "Mapping of request to JSON object failed");
- msoLogger.debug ("End of the transaction, the final response is: " + (String) response.getEntity ());
- return response;
- }
-
-
- try{
- msoRequest.parse(sir, instanceIdMap, action, version);
- } catch (Exception e) {
- msoLogger.debug ("Validation failed: ", e);
- Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_BAD_REQUEST, MsoException.ServiceException,
- "Error parsing request. " + e.getMessage(),
- ErrorNumbers.SVC_BAD_PARAMETER, null);
- if (msoRequest.getRequestId () != null) {
- msoLogger.debug ("Logging failed message to the database");
- msoRequest.createRequestRecord (Status.FAILED, action);
- }
- msoLogger.error (MessageEnum.APIH_REQUEST_VALIDATION_ERROR, MSO_PROP_APIHANDLER_INFRA, "", "", MsoLogger.ErrorCode.SchemaError, requestJSON, e);
- msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.SchemaError, "Validation of the input request failed");
- msoLogger.debug ("End of the transaction, the final response is: " + (String) response.getEntity ());
- return response;
- }
-
- InfraActiveRequests dup = null;
- String instanceName = sir.getRequestDetails().getRequestInfo().getInstanceName();
- String requestScope = sir.getRequestDetails().getModelInfo().getModelType().name();
- try {
- if(!(instanceName==null && requestScope.equals("service") && action == Action.createInstance)){
- dup = RequestsDatabase.checkInstanceNameDuplicate (instanceIdMap, instanceName, requestScope);
- }
- } catch (Exception e) {
- msoLogger.error (MessageEnum.APIH_DUPLICATE_CHECK_EXC, MSO_PROP_APIHANDLER_INFRA, "", "", MsoLogger.ErrorCode.DataError, "Error during duplicate check ", e);
-
- Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_INTERNAL_SERVER_ERROR, MsoException.ServiceException,
- e.getMessage(),
- ErrorNumbers.SVC_DETAILED_SERVICE_ERROR,
- null) ;
-
-
- msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DBAccessError, "Error during duplicate check");
- msoLogger.debug ("End of the transaction, the final response is: " + (String) response.getEntity ());
- return response;
- }
-
- if (dup != null) {
- // Found the duplicate record. Return the appropriate error.
- String instance = null;
- if(instanceName != null){
- instance = instanceName;
- }else{
- instance = instanceIdMap.get(requestScope + "InstanceId");
- }
- String dupMessage = "Error: Locked instance - This " + requestScope + " (" + instance + ") " + "already has a request being worked with a status of " + dup.getRequestStatus() + " (RequestId - " + dup.getRequestId() + "). The existing request must finish or be cleaned up before proceeding.";
- //List<String> variables = new ArrayList<String>();
- //variables.add(dup.getRequestStatus());
-
- Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_CONFLICT, MsoException.ServiceException,
- dupMessage,
- ErrorNumbers.SVC_DETAILED_SERVICE_ERROR,
- null) ;
-
-
- msoLogger.warn (MessageEnum.APIH_DUPLICATE_FOUND, dupMessage, "", "", MsoLogger.ErrorCode.SchemaError, "Duplicate request - Subscriber already has a request for this service");
- msoRequest.createRequestRecord (Status.FAILED, action);
- msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.Conflict, dupMessage);
- msoLogger.debug ("End of the transaction, the final response is: " + (String) response.getEntity ());
- return response;
- }
-
-
- ServiceInstancesResponse serviceResponse = new ServiceInstancesResponse();
-
- RequestReferences referencesResponse = new RequestReferences();
-
- referencesResponse.setRequestId(requestId);
-
- serviceResponse.setRequestReferences(referencesResponse);
-
- CatalogDatabase db = null;
- try {
- db = new CatalogDatabase ();
- } catch (Exception e) {
- msoLogger.error (MessageEnum.APIH_DB_ACCESS_EXC, MSO_PROP_APIHANDLER_INFRA, "", "", MsoLogger.ErrorCode.AvailabilityError, "Exception while communciate with Catalog DB", e);
- msoRequest.setStatus (org.openecomp.mso.apihandlerinfra.vnfbeans.RequestStatusType.FAILED);
- Response response = msoRequest.buildServiceErrorResponse (HttpStatus.SC_NOT_FOUND,
- MsoException.ServiceException,
- "No communication to catalog DB " + e.getMessage (),
- ErrorNumbers.SVC_NO_SERVER_RESOURCES,
- null);
- alarmLogger.sendAlarm ("MsoDatabaseAccessError",
- MsoAlarmLogger.CRITICAL,
- Messages.errors.get (ErrorNumbers.NO_COMMUNICATION_TO_CATALOG_DB));
- msoRequest.createRequestRecord (Status.FAILED,action);
- msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DBAccessError, "Exception while communciate with DB");
- msoLogger.debug ("End of the transaction, the final response is: " + (String) response.getEntity ());
- return response;
- }
-
-
-
- RecipeLookupResult recipeLookupResult = null;
- try {
- recipeLookupResult = getServiceInstanceOrchestrationURI (db, msoRequest, action);
- } catch (ValidationException e) {
- msoLogger.debug ("Validation failed: ", e);
- Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_BAD_REQUEST, MsoException.ServiceException,
- "Error validating request. " + e.getMessage(),
- ErrorNumbers.SVC_BAD_PARAMETER, null);
- if (msoRequest.getRequestId () != null) {
- msoLogger.debug ("Logging failed message to the database");
- msoRequest.createRequestRecord (Status.FAILED, action);
- }
- msoLogger.error (MessageEnum.APIH_REQUEST_VALIDATION_ERROR, MSO_PROP_APIHANDLER_INFRA, "", "", MsoLogger.ErrorCode.SchemaError, requestJSON, e);
- msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.SchemaError, "Validation of the input request failed");
- msoLogger.debug ("End of the transaction, the final response is: " + (String) response.getEntity ());
- return response;
- } catch (Exception e) {
- msoLogger.error (MessageEnum.APIH_DB_ACCESS_EXC, MSO_PROP_APIHANDLER_INFRA, "", "", MsoLogger.ErrorCode.DataError, "Exception while querying Catalog DB", e);
- msoRequest.setStatus (org.openecomp.mso.apihandlerinfra.vnfbeans.RequestStatusType.FAILED);
- Response response = msoRequest.buildServiceErrorResponse (HttpStatus.SC_NOT_FOUND,
- MsoException.ServiceException,
- "Recipe could not be retrieved from catalog DB " + e.getMessage (),
- ErrorNumbers.SVC_GENERAL_SERVICE_ERROR,
- null);
- alarmLogger.sendAlarm ("MsoDatabaseAccessError",
- MsoAlarmLogger.CRITICAL,
- Messages.errors.get (ErrorNumbers.ERROR_FROM_CATALOG_DB));
- msoRequest.createRequestRecord (Status.FAILED,action);
- msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DBAccessError, "Exception while querying Catalog DB");
- msoLogger.debug ("End of the transaction, the final response is: " + (String) response.getEntity ());
- db.close();
- return response;
- }
-
- if (recipeLookupResult == null) {
- msoLogger.error (MessageEnum.APIH_DB_ATTRIBUTE_NOT_FOUND, MSO_PROP_APIHANDLER_INFRA, "", "", MsoLogger.ErrorCode.DataError, "No recipe found in DB");
- msoRequest.setStatus (org.openecomp.mso.apihandlerinfra.vnfbeans.RequestStatusType.FAILED);
- Response response = msoRequest.buildServiceErrorResponse (HttpStatus.SC_NOT_FOUND,
- MsoException.ServiceException,
- "Recipe does not exist in catalog DB",
- ErrorNumbers.SVC_GENERAL_SERVICE_ERROR,
- null);
- msoRequest.createRequestRecord (Status.FAILED, action);
- msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DataNotFound, "No recipe found in DB");
- msoLogger.debug ("End of the transaction, the final response is: " + (String) response.getEntity ());
- db.close();
- return response;
- }
-
-
- Boolean isBaseVfModule = false;
-
- if (msoRequest.getModelInfo().getModelType().equals(ModelType.vfModule)) {
- String asdcServiceModelVersion = msoRequest.getAsdcServiceModelVersion ();
-
- // Get VF Module-specific base module indicator
- VfModule vfm = null;
-
- if (asdcServiceModelVersion != null && !asdcServiceModelVersion.isEmpty ()) {
- vfm = db.getVfModuleType (msoRequest.getVfModuleType (), asdcServiceModelVersion);
- }
- else {
- vfm = db.getVfModuleType (msoRequest.getVfModuleType ());
- }
-
- if (vfm != null) {
- if (vfm.getIsBase() == 1) {
- isBaseVfModule = true;
- }
- }
- else if (action == Action.createInstance || action == Action.updateInstance){
- // There is no entry for this vfModuleType with this version, if specified, in VF_MODULE table in Catalog DB.
- // This request cannot proceed
- msoLogger.error (MessageEnum.APIH_DB_ATTRIBUTE_NOT_FOUND, MSO_PROP_APIHANDLER_INFRA, "VF Module Type", "", MsoLogger.ErrorCode.DataError, "No VfModuleType found in DB");
- msoRequest.setStatus (org.openecomp.mso.apihandlerinfra.vnfbeans.RequestStatusType.FAILED);
- String serviceVersionText = "";
- if (asdcServiceModelVersion != null && !asdcServiceModelVersion.isEmpty ()) {
- serviceVersionText = " with version " + asdcServiceModelVersion;
- }
- Response response = msoRequest.buildServiceErrorResponse (HttpStatus.SC_NOT_FOUND,
- MsoException.ServiceException,
- "VnfType " + msoRequest.getVnfType () + " and VF Module Model Name " + msoRequest.getVfModuleModelName() + serviceVersionText + " not found in MSO Catalog DB",
- ErrorNumbers.SVC_BAD_PARAMETER,
- null);
- msoRequest.createRequestRecord (Status.FAILED, action);
- msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DataNotFound, "No matching vfModuleType found in DB");
- msoLogger.debug ("End of the transaction, the final response is: " + (String) response.getEntity ());
- db.close();
- return response;
- }
- }
-
- db.close();
-
- String serviceInstanceId = "";
- String vnfId = "";
- String vfModuleId = "";
- String volumeGroupId = "";
- String networkId = "";
- ServiceInstancesRequest siReq = msoRequest.getServiceInstancesRequest();
-
- if(siReq.getServiceInstanceId () != null){
- serviceInstanceId = siReq.getServiceInstanceId ();
- }
-
- if(siReq.getVnfInstanceId () != null){
- vnfId = siReq.getVnfInstanceId ();
- }
-
- if(siReq.getVfModuleInstanceId () != null){
- vfModuleId = siReq.getVfModuleInstanceId ();
- }
-
- if(siReq.getVolumeGroupInstanceId () != null){
- volumeGroupId = siReq.getVolumeGroupInstanceId ();
- }
-
- if(siReq.getNetworkInstanceId () != null){
- networkId = siReq.getNetworkInstanceId ();
- }
-
-
- requestId = msoRequest.getRequestId ();
- msoLogger.debug ("requestId is: " + requestId);
- msoLogger.debug ("About to insert a record");
-
- try {
- msoRequest.createRequestRecord (Status.PENDING, action);
- } catch (Exception e) {
- msoLogger.error (MessageEnum.APIH_DB_ACCESS_EXC_REASON, "Exception while creating record in DB", "", "", MsoLogger.ErrorCode.SchemaError, "Exception while creating record in DB", e);
- msoRequest.setStatus (org.openecomp.mso.apihandlerinfra.vnfbeans.RequestStatusType.FAILED);
- Response response = msoRequest.buildServiceErrorResponse (HttpStatus.SC_INTERNAL_SERVER_ERROR,
- MsoException.ServiceException,
- "Exception while creating record in DB " + e.getMessage(),
- ErrorNumbers.SVC_BAD_PARAMETER,
- null);
- msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DBAccessError, "Exception while creating record in DB");
- msoLogger.debug ("End of the transaction, the final response is: " + (String) response.getEntity ());
- return response;
- }
-
- RequestClient requestClient = null;
- HttpResponse response = null;
- long subStartTime = System.currentTimeMillis();
- try {
- requestClient = RequestClientFactory.getRequestClient (recipeLookupResult.getOrchestrationURI (), props);
- // Capture audit event
- msoLogger.debug ("MSO API Handler Posting call to BPEL engine for url: " + requestClient.getUrl ());
-
- System.out.println("URL : " + requestClient.getUrl ());
-
- response = requestClient.post(requestId, isBaseVfModule, recipeLookupResult.getRecipeTimeout (), action.name (),
- serviceInstanceId, vnfId, vfModuleId, volumeGroupId, networkId,
- msoRequest.getServiceInstanceType (),
- msoRequest.getVnfType (), msoRequest.getVfModuleType (),
- msoRequest.getNetworkType (), msoRequest.getRequestJSON());
-
- msoLogger.recordMetricEvent (subStartTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully received response from BPMN engine", "BPMN", recipeLookupResult.getOrchestrationURI (), null);
- } catch (Exception e) {
- msoLogger.recordMetricEvent (subStartTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, "Exception while communicate with BPMN engine", "BPMN", recipeLookupResult.getOrchestrationURI (), null);
- msoRequest.setStatus (org.openecomp.mso.apihandlerinfra.vnfbeans.RequestStatusType.FAILED);
- Response resp = msoRequest.buildServiceErrorResponse (HttpStatus.SC_BAD_GATEWAY,
- MsoException.ServiceException,
- "Failed calling bpmn " + e.getMessage (),
- ErrorNumbers.SVC_NO_SERVER_RESOURCES,
- null);
- alarmLogger.sendAlarm ("MsoConfigurationError",
- MsoAlarmLogger.CRITICAL,
- Messages.errors.get (ErrorNumbers.NO_COMMUNICATION_TO_BPEL));
- msoRequest.updateFinalStatus (Status.FAILED);
- msoLogger.error (MessageEnum.APIH_BPEL_COMMUNICATE_ERROR, MSO_PROP_APIHANDLER_INFRA, "", "", MsoLogger.ErrorCode.AvailabilityError, "Exception while communicate with BPMN engine");
- msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, "Exception while communicate with BPMN engine");
- msoLogger.debug ("End of the transaction, the final response is: " + (String) resp.getEntity ());
- return resp;
- }
-
- if (response == null) {
- msoRequest.setStatus (org.openecomp.mso.apihandlerinfra.vnfbeans.RequestStatusType.FAILED);
- Response resp = msoRequest.buildServiceErrorResponse (HttpStatus.SC_BAD_GATEWAY,
- MsoException.ServiceException,
- "bpelResponse is null",
- ErrorNumbers.SVC_NO_SERVER_RESOURCES,
- null);
- msoRequest.updateFinalStatus (Status.FAILED);
- msoLogger.error (MessageEnum.APIH_BPEL_COMMUNICATE_ERROR, MSO_PROP_APIHANDLER_INFRA, "", "", MsoLogger.ErrorCode.BusinessProcesssError, "Null response from BPEL");
- msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.InternalError, "Null response from BPMN");
- msoLogger.debug ("End of the transaction, the final response is: " + (String) resp.getEntity ());
- return resp;
- }
-
- ResponseHandler respHandler = new ResponseHandler (response, requestClient.getType ());
- int bpelStatus = respHandler.getStatus ();
-
- // BPEL accepted the request, the request is in progress
- if (bpelStatus == HttpStatus.SC_ACCEPTED) {
- String camundaJSONResponseBody = respHandler.getResponseBody ();
- msoLogger.debug ("Received from Camunda: " + camundaJSONResponseBody);
- msoRequest.setStatus (org.openecomp.mso.apihandlerinfra.vnfbeans.RequestStatusType.IN_PROGRESS);
- RequestsDatabase.updateInfraStatus (msoRequest.getRequestId (),
- Status.IN_PROGRESS.toString (),
- Constants.PROGRESS_REQUEST_IN_PROGRESS,
- Constants.MODIFIED_BY_APIHANDLER);
- msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "BPMN accepted the request, the request is in progress");
- msoLogger.debug ("End of the transaction, the final response is: " + (String) camundaJSONResponseBody);
- return Response.status (HttpStatus.SC_ACCEPTED).entity (camundaJSONResponseBody).build ();
- } else {
- List<String> variables = new ArrayList<String>();
- variables.add(bpelStatus + "");
- String camundaJSONResponseBody = respHandler.getResponseBody ();
- if (camundaJSONResponseBody != null && !camundaJSONResponseBody.isEmpty ()) {
- msoRequest.setStatus (org.openecomp.mso.apihandlerinfra.vnfbeans.RequestStatusType.FAILED);
- Response resp = msoRequest.buildServiceErrorResponse(bpelStatus,
- MsoException.ServiceException,
- "Request Failed due to BPEL error with HTTP Status= %1 " + '\n' + camundaJSONResponseBody,
- ErrorNumbers.SVC_DETAILED_SERVICE_ERROR,
- variables);
- msoRequest.updateFinalStatus (Status.FAILED);
- msoLogger.error (MessageEnum.APIH_BPEL_RESPONSE_ERROR, requestClient.getUrl (), "", "", MsoLogger.ErrorCode.BusinessProcesssError, "Response from BPEL engine is failed with HTTP Status=" + bpelStatus);
- msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.InternalError, "Response from BPMN engine is failed");
- msoLogger.debug ("End of the transaction, the final response is: " + (String) resp.getEntity ());
- return resp;
- } else {
- msoRequest.setStatus (org.openecomp.mso.apihandlerinfra.vnfbeans.RequestStatusType.FAILED);
- Response resp = msoRequest.buildServiceErrorResponse(bpelStatus,
- MsoException.ServiceException,
- "Request Failed due to BPEL error with HTTP Status= %1" ,
- ErrorNumbers.SVC_DETAILED_SERVICE_ERROR,
- variables);
- msoRequest.updateFinalStatus (Status.FAILED);
- msoLogger.error (MessageEnum.APIH_BPEL_RESPONSE_ERROR, requestClient.getUrl (), "", "", MsoLogger.ErrorCode.BusinessProcesssError, "Response from BPEL engine is empty");
- msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.InternalError, "Response from BPEL engine is empty");
- msoLogger.debug ("End of the transaction, the final response is: " + (String) resp.getEntity ());
- return resp;
- }
- }
-
- //return Response.status (HttpStatus.SC_ACCEPTED).entity (serviceResponse).build ();
- // return serviceResponse;
+ String requestId = UUIDChecker.generateUUID(msoLogger);
+ long startTime = System.currentTimeMillis ();
+ msoLogger.debug ("requestId is: " + requestId);
+ ServiceInstancesRequest sir = null;
+
+ MsoRequest msoRequest = new MsoRequest (requestId);
+
+
+ try{
+ ObjectMapper mapper = new ObjectMapper();
+ sir = mapper.readValue(requestJSON, ServiceInstancesRequest.class);
+
+ } catch(Exception e){
+ msoLogger.debug ("Mapping of request to JSON object failed : ", e);
+ Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_BAD_REQUEST, MsoException.ServiceException,
+ "Mapping of request to JSON object failed. " + e.getMessage(),
+ ErrorNumbers.SVC_BAD_PARAMETER, null);
+ if (msoRequest.getRequestId () != null) {
+ msoLogger.debug ("Mapping of request to JSON object failed");
+ msoRequest.createRequestRecord (Status.FAILED, action);
+ }
+ msoLogger.error (MessageEnum.APIH_REQUEST_VALIDATION_ERROR, MSO_PROP_APIHANDLER_INFRA, "", "", MsoLogger.ErrorCode.SchemaError, requestJSON, e);
+ msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.SchemaError, "Mapping of request to JSON object failed");
+ msoLogger.debug ("End of the transaction, the final response is: " + (String) response.getEntity ());
+ return response;
+ }
+
+
+ try{
+ msoRequest.parse(sir, instanceIdMap, action, version);
+ } catch (Exception e) {
+ msoLogger.debug ("Validation failed: ", e);
+ Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_BAD_REQUEST, MsoException.ServiceException,
+ "Error parsing request. " + e.getMessage(),
+ ErrorNumbers.SVC_BAD_PARAMETER, null);
+ if (msoRequest.getRequestId () != null) {
+ msoLogger.debug ("Logging failed message to the database");
+ msoRequest.createRequestRecord (Status.FAILED, action);
+ }
+ msoLogger.error (MessageEnum.APIH_REQUEST_VALIDATION_ERROR, MSO_PROP_APIHANDLER_INFRA, "", "", MsoLogger.ErrorCode.SchemaError, requestJSON, e);
+ msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.SchemaError, "Validation of the input request failed");
+ msoLogger.debug ("End of the transaction, the final response is: " + (String) response.getEntity ());
+ return response;
+ }
+
+ InfraActiveRequests dup = null;
+ String instanceName = sir.getRequestDetails().getRequestInfo().getInstanceName();
+ String requestScope = sir.getRequestDetails().getModelInfo().getModelType().name();
+ try {
+ if(!(instanceName==null && requestScope.equals("service") && (action == Action.createInstance || action == Action.activateInstance))){
+ dup = (RequestsDatabase.getInstance()).checkInstanceNameDuplicate (instanceIdMap, instanceName, requestScope);
+ }
+ } catch (Exception e) {
+ msoLogger.error (MessageEnum.APIH_DUPLICATE_CHECK_EXC, MSO_PROP_APIHANDLER_INFRA, "", "", MsoLogger.ErrorCode.DataError, "Error during duplicate check ", e);
+
+ Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_INTERNAL_SERVER_ERROR, MsoException.ServiceException,
+ e.getMessage(),
+ ErrorNumbers.SVC_DETAILED_SERVICE_ERROR,
+ null) ;
+
+
+ msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DBAccessError, "Error during duplicate check");
+ msoLogger.debug ("End of the transaction, the final response is: " + (String) response.getEntity ());
+ return response;
+ }
+
+ if (dup != null) {
+ // Found the duplicate record. Return the appropriate error.
+ String instance = null;
+ if(instanceName != null){
+ instance = instanceName;
+ }else{
+ instance = instanceIdMap.get(requestScope + "InstanceId");
+ }
+ String dupMessage = "Error: Locked instance - This " + requestScope + " (" + instance + ") " + "already has a request being worked with a status of " + dup.getRequestStatus() + " (RequestId - " + dup.getRequestId() + "). The existing request must finish or be cleaned up before proceeding.";
+ //List<String> variables = new ArrayList<String>();
+ //variables.add(dup.getRequestStatus());
+
+ Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_CONFLICT, MsoException.ServiceException,
+ dupMessage,
+ ErrorNumbers.SVC_DETAILED_SERVICE_ERROR,
+ null) ;
+
+
+ msoLogger.warn (MessageEnum.APIH_DUPLICATE_FOUND, dupMessage, "", "", MsoLogger.ErrorCode.SchemaError, "Duplicate request - Subscriber already has a request for this service");
+ msoRequest.createRequestRecord (Status.FAILED, action);
+ msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.Conflict, dupMessage);
+ msoLogger.debug ("End of the transaction, the final response is: " + (String) response.getEntity ());
+ return response;
+ }
+
+
+ ServiceInstancesResponse serviceResponse = new ServiceInstancesResponse();
+
+ RequestReferences referencesResponse = new RequestReferences();
+
+ referencesResponse.setRequestId(requestId);
+
+ serviceResponse.setRequestReferences(referencesResponse);
+
+ CatalogDatabase db = null;
+ try {
+ db = CatalogDatabase.getInstance();
+ } catch (Exception e) {
+ msoLogger.error (MessageEnum.APIH_DB_ACCESS_EXC, MSO_PROP_APIHANDLER_INFRA, "", "", MsoLogger.ErrorCode.AvailabilityError, "Exception while communciate with Catalog DB", e);
+ msoRequest.setStatus (org.openecomp.mso.apihandlerinfra.vnfbeans.RequestStatusType.FAILED);
+ Response response = msoRequest.buildServiceErrorResponse (HttpStatus.SC_NOT_FOUND,
+ MsoException.ServiceException,
+ "No communication to catalog DB " + e.getMessage (),
+ ErrorNumbers.SVC_NO_SERVER_RESOURCES,
+ null);
+ alarmLogger.sendAlarm ("MsoDatabaseAccessError",
+ MsoAlarmLogger.CRITICAL,
+ Messages.errors.get (ErrorNumbers.NO_COMMUNICATION_TO_CATALOG_DB));
+ msoRequest.createRequestRecord (Status.FAILED,action);
+ msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DBAccessError, "Exception while communciate with DB");
+ msoLogger.debug ("End of the transaction, the final response is: " + (String) response.getEntity ());
+ return response;
+ }
+
+
+
+ RecipeLookupResult recipeLookupResult = null;
+ try {
+ recipeLookupResult = getServiceInstanceOrchestrationURI (db, msoRequest, action);
+ } catch (ValidationException e) {
+ msoLogger.debug ("Validation failed: ", e);
+ Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_BAD_REQUEST, MsoException.ServiceException,
+ "Error validating request. " + e.getMessage(),
+ ErrorNumbers.SVC_BAD_PARAMETER, null);
+ if (msoRequest.getRequestId () != null) {
+ msoLogger.debug ("Logging failed message to the database");
+ msoRequest.createRequestRecord (Status.FAILED, action);
+ }
+ msoLogger.error (MessageEnum.APIH_REQUEST_VALIDATION_ERROR, MSO_PROP_APIHANDLER_INFRA, "", "", MsoLogger.ErrorCode.SchemaError, requestJSON, e);
+ msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.SchemaError, "Validation of the input request failed");
+ msoLogger.debug ("End of the transaction, the final response is: " + (String) response.getEntity ());
+ return response;
+ } catch (Exception e) {
+ msoLogger.error (MessageEnum.APIH_DB_ACCESS_EXC, MSO_PROP_APIHANDLER_INFRA, "", "", MsoLogger.ErrorCode.DataError, "Exception while querying Catalog DB", e);
+ msoRequest.setStatus (org.openecomp.mso.apihandlerinfra.vnfbeans.RequestStatusType.FAILED);
+ Response response = msoRequest.buildServiceErrorResponse (HttpStatus.SC_NOT_FOUND,
+ MsoException.ServiceException,
+ "Recipe could not be retrieved from catalog DB " + e.getMessage (),
+ ErrorNumbers.SVC_GENERAL_SERVICE_ERROR,
+ null);
+ alarmLogger.sendAlarm ("MsoDatabaseAccessError",
+ MsoAlarmLogger.CRITICAL,
+ Messages.errors.get (ErrorNumbers.ERROR_FROM_CATALOG_DB));
+ msoRequest.createRequestRecord (Status.FAILED,action);
+ msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DBAccessError, "Exception while querying Catalog DB");
+ msoLogger.debug ("End of the transaction, the final response is: " + (String) response.getEntity ());
+ db.close();
+ return response;
+ }
+
+ if (recipeLookupResult == null) {
+ msoLogger.error (MessageEnum.APIH_DB_ATTRIBUTE_NOT_FOUND, MSO_PROP_APIHANDLER_INFRA, "", "", MsoLogger.ErrorCode.DataError, "No recipe found in DB");
+ msoRequest.setStatus (org.openecomp.mso.apihandlerinfra.vnfbeans.RequestStatusType.FAILED);
+ Response response = msoRequest.buildServiceErrorResponse (HttpStatus.SC_NOT_FOUND,
+ MsoException.ServiceException,
+ "Recipe does not exist in catalog DB",
+ ErrorNumbers.SVC_GENERAL_SERVICE_ERROR,
+ null);
+ msoRequest.createRequestRecord (Status.FAILED, action);
+ msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DataNotFound, "No recipe found in DB");
+ msoLogger.debug ("End of the transaction, the final response is: " + (String) response.getEntity ());
+ db.close();
+ return response;
+ }
+
+
+ Boolean isBaseVfModule = false;
+
+ if (msoRequest.getModelInfo().getModelType().equals(ModelType.vfModule)) {
+ String asdcServiceModelVersion = msoRequest.getAsdcServiceModelVersion ();
+
+ // Get VF Module-specific base module indicator
+ VfModule vfm = null;
+
+ String modelVersionId = msoRequest.getModelInfo().getModelVersionId();
+
+ if(modelVersionId != null) {
+ vfm = db.getVfModuleByModelUuid(modelVersionId);
+ } else {
+ vfm = db.getVfModuleByModelInvariantUuidAndModelVersion(msoRequest.getModelInfo().getModelInvariantId(), msoRequest.getModelInfo().getModelVersion());
+ }
+
+ if (vfm != null) {
+ if (vfm.getIsBase() == 1) {
+ isBaseVfModule = true;
+ }
+ }
+ else if (action == Action.createInstance || action == Action.updateInstance){
+ // There is no entry for this vfModuleType with this version, if specified, in VF_MODULE table in Catalog DB.
+ // This request cannot proceed
+ msoLogger.error (MessageEnum.APIH_DB_ATTRIBUTE_NOT_FOUND, MSO_PROP_APIHANDLER_INFRA, "VF Module Type", "", MsoLogger.ErrorCode.DataError, "No VfModuleType found in DB");
+ msoRequest.setStatus (org.openecomp.mso.apihandlerinfra.vnfbeans.RequestStatusType.FAILED);
+ String serviceVersionText = "";
+ if (asdcServiceModelVersion != null && !asdcServiceModelVersion.isEmpty ()) {
+ serviceVersionText = " with version " + asdcServiceModelVersion;
+ }
+ Response response = msoRequest.buildServiceErrorResponse (HttpStatus.SC_NOT_FOUND,
+ MsoException.ServiceException,
+ "VnfType " + msoRequest.getVnfType () + " and VF Module Model Name " + msoRequest.getVfModuleModelName() + serviceVersionText + " not found in MSO Catalog DB",
+ ErrorNumbers.SVC_BAD_PARAMETER,
+ null);
+ msoRequest.createRequestRecord (Status.FAILED, action);
+ msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DataNotFound, "No matching vfModuleType found in DB");
+ msoLogger.debug ("End of the transaction, the final response is: " + (String) response.getEntity ());
+ db.close();
+ return response;
+ }
+ }
+
+ db.close();
+
+ String serviceInstanceId = "";
+ String vnfId = "";
+ String vfModuleId = "";
+ String volumeGroupId = "";
+ String networkId = "";
+ ServiceInstancesRequest siReq = msoRequest.getServiceInstancesRequest();
+
+ if(siReq.getServiceInstanceId () != null){
+ serviceInstanceId = siReq.getServiceInstanceId ();
+ }
+
+ if(siReq.getVnfInstanceId () != null){
+ vnfId = siReq.getVnfInstanceId ();
+ }
+
+ if(siReq.getVfModuleInstanceId () != null){
+ vfModuleId = siReq.getVfModuleInstanceId ();
+ }
+
+ if(siReq.getVolumeGroupInstanceId () != null){
+ volumeGroupId = siReq.getVolumeGroupInstanceId ();
+ }
+
+ if(siReq.getNetworkInstanceId () != null){
+ networkId = siReq.getNetworkInstanceId ();
+ }
+
+
+ requestId = msoRequest.getRequestId ();
+ msoLogger.debug ("requestId is: " + requestId);
+ msoLogger.debug ("About to insert a record");
+
+ try {
+ msoRequest.createRequestRecord (Status.PENDING, action);
+ } catch (Exception e) {
+ msoLogger.error (MessageEnum.APIH_DB_ACCESS_EXC_REASON, "Exception while creating record in DB", "", "", MsoLogger.ErrorCode.SchemaError, "Exception while creating record in DB", e);
+ msoRequest.setStatus (org.openecomp.mso.apihandlerinfra.vnfbeans.RequestStatusType.FAILED);
+ Response response = msoRequest.buildServiceErrorResponse (HttpStatus.SC_INTERNAL_SERVER_ERROR,
+ MsoException.ServiceException,
+ "Exception while creating record in DB " + e.getMessage(),
+ ErrorNumbers.SVC_BAD_PARAMETER,
+ null);
+ msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DBAccessError, "Exception while creating record in DB");
+ msoLogger.debug ("End of the transaction, the final response is: " + (String) response.getEntity ());
+ return response;
+ }
+
+ RequestClient requestClient = null;
+ HttpResponse response = null;
+ long subStartTime = System.currentTimeMillis();
+ try {
+ requestClient = RequestClientFactory.getRequestClient (recipeLookupResult.getOrchestrationURI (), MsoPropertiesUtils.loadMsoProperties ());
+ // Capture audit event
+ msoLogger.debug ("MSO API Handler Posting call to BPEL engine for url: " + requestClient.getUrl ());
+
+ System.out.println("URL : " + requestClient.getUrl ());
+
+ response = requestClient.post(requestId, isBaseVfModule, recipeLookupResult.getRecipeTimeout (), action.name (),
+ serviceInstanceId, vnfId, vfModuleId, volumeGroupId, networkId,
+ msoRequest.getServiceInstanceType (),
+ msoRequest.getVnfType (), msoRequest.getVfModuleType (),
+ msoRequest.getNetworkType (), msoRequest.getRequestJSON());
+
+ msoLogger.recordMetricEvent (subStartTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully received response from BPMN engine", "BPMN", recipeLookupResult.getOrchestrationURI (), null);
+ } catch (Exception e) {
+ msoLogger.recordMetricEvent (subStartTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, "Exception while communicate with BPMN engine", "BPMN", recipeLookupResult.getOrchestrationURI (), null);
+ msoRequest.setStatus (org.openecomp.mso.apihandlerinfra.vnfbeans.RequestStatusType.FAILED);
+ Response resp = msoRequest.buildServiceErrorResponse (HttpStatus.SC_BAD_GATEWAY,
+ MsoException.ServiceException,
+ "Failed calling bpmn " + e.getMessage (),
+ ErrorNumbers.SVC_NO_SERVER_RESOURCES,
+ null);
+ alarmLogger.sendAlarm ("MsoConfigurationError",
+ MsoAlarmLogger.CRITICAL,
+ Messages.errors.get (ErrorNumbers.NO_COMMUNICATION_TO_BPEL));
+ msoRequest.updateFinalStatus (Status.FAILED);
+ msoLogger.error (MessageEnum.APIH_BPEL_COMMUNICATE_ERROR, MSO_PROP_APIHANDLER_INFRA, "", "", MsoLogger.ErrorCode.AvailabilityError, "Exception while communicate with BPMN engine");
+ msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, "Exception while communicate with BPMN engine");
+ msoLogger.debug ("End of the transaction, the final response is: " + (String) resp.getEntity ());
+ return resp;
+ }
+
+ if (response == null) {
+ msoRequest.setStatus (org.openecomp.mso.apihandlerinfra.vnfbeans.RequestStatusType.FAILED);
+ Response resp = msoRequest.buildServiceErrorResponse (HttpStatus.SC_BAD_GATEWAY,
+ MsoException.ServiceException,
+ "bpelResponse is null",
+ ErrorNumbers.SVC_NO_SERVER_RESOURCES,
+ null);
+ msoRequest.updateFinalStatus (Status.FAILED);
+ msoLogger.error (MessageEnum.APIH_BPEL_COMMUNICATE_ERROR, MSO_PROP_APIHANDLER_INFRA, "", "", MsoLogger.ErrorCode.BusinessProcesssError, "Null response from BPEL");
+ msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.InternalError, "Null response from BPMN");
+ msoLogger.debug ("End of the transaction, the final response is: " + (String) resp.getEntity ());
+ return resp;
+ }
+
+ ResponseHandler respHandler = new ResponseHandler (response, requestClient.getType ());
+ int bpelStatus = respHandler.getStatus ();
+
+ // BPEL accepted the request, the request is in progress
+ if (bpelStatus == HttpStatus.SC_ACCEPTED) {
+ String camundaJSONResponseBody = respHandler.getResponseBody ();
+ msoLogger.debug ("Received from Camunda: " + camundaJSONResponseBody);
+ msoRequest.setStatus (org.openecomp.mso.apihandlerinfra.vnfbeans.RequestStatusType.IN_PROGRESS);
+ (RequestsDatabase.getInstance()).updateInfraStatus (msoRequest.getRequestId (),
+ Status.IN_PROGRESS.toString (),
+ Constants.PROGRESS_REQUEST_IN_PROGRESS,
+ Constants.MODIFIED_BY_APIHANDLER);
+ msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "BPMN accepted the request, the request is in progress");
+ msoLogger.debug ("End of the transaction, the final response is: " + (String) camundaJSONResponseBody);
+ return Response.status (HttpStatus.SC_ACCEPTED).entity (camundaJSONResponseBody).build ();
+ } else {
+ List<String> variables = new ArrayList<String>();
+ variables.add(bpelStatus + "");
+ String camundaJSONResponseBody = respHandler.getResponseBody ();
+ if (camundaJSONResponseBody != null && !camundaJSONResponseBody.isEmpty ()) {
+ msoRequest.setStatus (org.openecomp.mso.apihandlerinfra.vnfbeans.RequestStatusType.FAILED);
+ Response resp = msoRequest.buildServiceErrorResponse(bpelStatus,
+ MsoException.ServiceException,
+ "Request Failed due to BPEL error with HTTP Status= %1 " + '\n' + camundaJSONResponseBody,
+ ErrorNumbers.SVC_DETAILED_SERVICE_ERROR,
+ variables);
+ msoRequest.updateFinalStatus (Status.FAILED);
+ msoLogger.error (MessageEnum.APIH_BPEL_RESPONSE_ERROR, requestClient.getUrl (), "", "", MsoLogger.ErrorCode.BusinessProcesssError, "Response from BPEL engine is failed with HTTP Status=" + bpelStatus);
+ msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.InternalError, "Response from BPMN engine is failed");
+ msoLogger.debug ("End of the transaction, the final response is: " + (String) resp.getEntity ());
+ return resp;
+ } else {
+ msoRequest.setStatus (org.openecomp.mso.apihandlerinfra.vnfbeans.RequestStatusType.FAILED);
+ Response resp = msoRequest.buildServiceErrorResponse(bpelStatus,
+ MsoException.ServiceException,
+ "Request Failed due to BPEL error with HTTP Status= %1" ,
+ ErrorNumbers.SVC_DETAILED_SERVICE_ERROR,
+ variables);
+ msoRequest.updateFinalStatus (Status.FAILED);
+ msoLogger.error (MessageEnum.APIH_BPEL_RESPONSE_ERROR, requestClient.getUrl (), "", "", MsoLogger.ErrorCode.BusinessProcesssError, "Response from BPEL engine is empty");
+ msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.InternalError, "Response from BPEL engine is empty");
+ msoLogger.debug ("End of the transaction, the final response is: " + (String) resp.getEntity ());
+ return resp;
+ }
+ }
+
+ //return Response.status (HttpStatus.SC_ACCEPTED).entity (serviceResponse).build ();
+ // return serviceResponse;
}
- private RecipeLookupResult getServiceInstanceOrchestrationURI (CatalogDatabase db, MsoRequest msoRequest, Action action) throws Exception {
- RecipeLookupResult recipeLookupResult = null;
- //if the aLaCarte flag is set to TRUE, the API-H should choose the “VID_DEFAULT” recipe for the requested action
-
- msoLogger.debug("aLaCarteFlag is " + msoRequest.getALaCarteFlag());
- // Query MSO Catalog DB
-
- if (msoRequest.getModelInfo().getModelType().equals(ModelType.service)) {
- recipeLookupResult = getServiceURI(db, msoRequest, action);
- }
- else if (msoRequest.getModelInfo().getModelType().equals(ModelType.vfModule) ||
- msoRequest.getModelInfo().getModelType().equals(ModelType.volumeGroup) || msoRequest.getModelInfo().getModelType().equals(ModelType.vnf)) {
-
- recipeLookupResult = getVnfOrVfModuleUri(db, msoRequest, action);
-
- }else if (msoRequest.getModelInfo().getModelType().equals(ModelType.network)) {
-
- recipeLookupResult = getNetworkUri(db, msoRequest, action);
- }
-
- if (recipeLookupResult != null) {
- msoLogger.debug ("Orchestration URI is: " + recipeLookupResult.getOrchestrationURI() + ", recipe Timeout is: " + Integer.toString(recipeLookupResult.getRecipeTimeout ()));
- }
- else {
- msoLogger.debug("No matching recipe record found");
- }
- return recipeLookupResult;
- }
-
-
- private RecipeLookupResult getServiceURI (CatalogDatabase db, MsoRequest msoRequest, Action action) throws Exception {
- // SERVICE REQUEST
- // Construct the default service name
- // TODO need to make this a configurable property
- String sourceDefaultServiceName = msoRequest.getRequestInfo().getSource() + "_DEFAULT";
- String defaultService = "*";
-
- Service serviceRecord = null;
- int serviceId;
- ServiceRecipe recipe = null;
-
- //if an aLaCarte flag was Not sent in the request, look first if there is a custom recipe for the specific model version
- if(!msoRequest.getALaCarteFlag()){
- serviceRecord = db.getServiceByVersionAndInvariantId(msoRequest.getModelInfo().getModelInvariantId(), msoRequest.getModelInfo().getModelVersion());
- if(serviceRecord !=null){
- serviceId = serviceRecord.getId();
- recipe = db.getServiceRecipe(serviceId, action.name());
- }
- }
-
- if (recipe == null) {
- //find source(initiator) default recipe
- recipe = db.getServiceRecipeByServiceNameAndAction(sourceDefaultServiceName, action.name());
- }
- if (recipe == null) {
- //find default recipe
- recipe = db.getServiceRecipeByServiceNameAndAction(defaultService, action.name());
- }
- if(recipe==null){
- return null;
- }
- return new RecipeLookupResult (recipe.getOrchestrationUri (), recipe.getRecipeTimeout ());
-
- }
-
-
- private RecipeLookupResult getVnfOrVfModuleUri (CatalogDatabase db, MsoRequest msoRequest, Action action) throws Exception {
-
- String vnfComponentType = msoRequest.getModelInfo().getModelType().name();
-
- RelatedInstanceList[] instanceList = null;
- if (msoRequest.getServiceInstancesRequest().getRequestDetails() != null) {
- instanceList = msoRequest.getServiceInstancesRequest().getRequestDetails().getRelatedInstanceList();
- }
-
- String serviceModelName = null;
- String vnfModelName = null;
- String asdcServiceModelVersion = null;
- String modelVersion = msoRequest.getModelInfo().getModelVersion();
- Recipe recipe = null;
- String defaultVnfType = msoRequest.getRequestInfo().getSource() + "_DEFAULT";
- String modelCustomizationId = msoRequest.getModelInfo().getModelCustomizationId();
- String vfModuleModelName = msoRequest.getModelInfo().getModelName();
- if (instanceList != null) {
-
- for(RelatedInstanceList relatedInstanceList : instanceList){
-
- RelatedInstance relatedInstance = relatedInstanceList.getRelatedInstance();
- ModelInfo modelInfo = relatedInstance.getModelInfo();
- if(modelInfo.getModelType().equals(ModelType.service)){
- serviceModelName = modelInfo.getModelName();
- asdcServiceModelVersion = modelInfo.getModelVersion();
- }
-
- if(modelInfo.getModelType().equals(ModelType.vnf)){
- vnfModelName = modelInfo.getModelCustomizationName();
- if (null == vnfModelName || vnfModelName.trim().isEmpty()) {
- VnfResource vnfResource = db.getVnfResourceByModelCustomizationId(modelInfo.getModelCustomizationUuid(), modelInfo.getModelVersion());
- vnfModelName = vnfResource.getModelName();
- }
- }
- }
-
- if(msoRequest.getModelInfo().getModelType().equals(ModelType.vnf)) {
- String modelCustomizationName = msoRequest.getModelInfo().getModelCustomizationName();
-
- VnfResource vnfResource = null;
-
- // Validation for vnfResource
- if(modelCustomizationName!=null) {
- vnfResource = db.getVnfResource(serviceModelName + "/" + modelCustomizationName, asdcServiceModelVersion);
- }else{
- vnfResource = db.getVnfResourceByModelCustomizationId(modelCustomizationId, asdcServiceModelVersion);
- }
-
- if(vnfResource==null){
- throw new ValidationException("catalog entry");
- }
-
- VnfRecipe vnfRecipe = db.getVnfRecipe(defaultVnfType, action.name());
-
- if (vnfRecipe == null) {
- return null;
- }
-
- return new RecipeLookupResult (vnfRecipe.getOrchestrationUri(), vnfRecipe.getRecipeTimeout());
- }else{
- String vnfType = serviceModelName + "/" + vnfModelName;
- String vfModuleType = vnfType + "::" + vfModuleModelName;
- List<VfModule> vfModule = db.getVfModule(vfModuleType, modelCustomizationId, asdcServiceModelVersion, modelVersion, action.name());
- if(vfModule==null || vfModule.isEmpty()){
- throw new ValidationException("catalog entry");
- }else{
- if(!msoRequest.getALaCarteFlag() && action != Action.deleteInstance){
- recipe = db.getVnfComponentsRecipeByVfModule(vfModule, action.name());
- }
- }
- if (recipe == null) {
- msoLogger.debug("recipe is null, getting default");
- recipe = db.getVnfComponentsRecipeByVfModuleId("VID_DEFAULT", vnfComponentType, action.name());
-
- if (recipe == null) {
- return null;
- }
- }
-
- }
- } else {
- msoLogger.debug("recipe is null, getting default");
-
- if(msoRequest.getModelInfo().getModelType().equals(ModelType.vnf)) {
- recipe = db.getVnfRecipe(defaultVnfType, action.name());
- if (recipe == null) {
- return null;
- }
- } else {
- recipe = db.getVnfComponentsRecipeByVfModuleId("VID_DEFAULT", vnfComponentType, action.name());
-
- if (recipe == null) {
- return null;
- }
- }
- }
-
- return new RecipeLookupResult (recipe.getOrchestrationUri (), recipe.getRecipeTimeout ());
- }
-
- private RecipeLookupResult getNetworkUri (CatalogDatabase db, MsoRequest msoRequest, Action action) throws Exception {
-
- String sourceDefaultNetworkType = msoRequest.getRequestInfo().getSource() + "_DEFAULT";
- String defaultNetworkType = "*";
-
- String modelName = msoRequest.getModelInfo().getModelName();
- Recipe recipe = null;
- //if an aLaCarte flag was Not sent in the request, look first if there is a custom recipe for the specific ModelCustomizationId
- if(!msoRequest.getALaCarteFlag()){
- String networkType = null;
-
- if(msoRequest.getModelInfo().getModelCustomizationId()!=null){
- NetworkResource networkResource = db.getNetworkResourceByModelCustUuid(msoRequest.getModelInfo().getModelCustomizationId());
- if(networkResource!=null){
- networkType = networkResource.getNetworkType();
- }else{
- throw new ValidationException("no catalog entry found");
- }
- }else{
- //ok for version < 3
- networkType = modelName;
- }
-
- //find latest version Recipe for the given networkType and action
- recipe = db.getNetworkRecipe(networkType, action.name());
- }
-
- if(recipe == null){
- //find source(initiator) default recipe
- recipe = db.getNetworkRecipe(sourceDefaultNetworkType, action.name());
- }
- if(recipe == null){
- //find default recipe
- recipe = db.getNetworkRecipe(defaultNetworkType, action.name());
- }
- if (recipe == null) {
- return null;
- }
- return new RecipeLookupResult (recipe.getOrchestrationUri (), recipe.getRecipeTimeout ());
- }
+ private RecipeLookupResult getServiceInstanceOrchestrationURI (CatalogDatabase db, MsoRequest msoRequest, Action action) throws Exception {
+ RecipeLookupResult recipeLookupResult = null;
+ //if the aLaCarte flag is set to TRUE, the API-H should choose the “VID_DEFAULT” recipe for the requested action
+
+ msoLogger.debug("aLaCarteFlag is " + msoRequest.getALaCarteFlag());
+ // Query MSO Catalog DB
+
+ if (msoRequest.getModelInfo().getModelType().equals(ModelType.service)) {
+ recipeLookupResult = getServiceURI(db, msoRequest, action);
+ }
+ else if (msoRequest.getModelInfo().getModelType().equals(ModelType.vfModule) ||
+ msoRequest.getModelInfo().getModelType().equals(ModelType.volumeGroup) || msoRequest.getModelInfo().getModelType().equals(ModelType.vnf)) {
+
+ recipeLookupResult = getVnfOrVfModuleUri(db, msoRequest, action);
+
+ }else if (msoRequest.getModelInfo().getModelType().equals(ModelType.network)) {
+
+ recipeLookupResult = getNetworkUri(db, msoRequest, action);
+ }
+
+ if (recipeLookupResult != null) {
+ msoLogger.debug ("Orchestration URI is: " + recipeLookupResult.getOrchestrationURI() + ", recipe Timeout is: " + Integer.toString(recipeLookupResult.getRecipeTimeout ()));
+ }
+ else {
+ msoLogger.debug("No matching recipe record found");
+ }
+ return recipeLookupResult;
+ }
+
+
+ private RecipeLookupResult getServiceURI (CatalogDatabase db, MsoRequest msoRequest, Action action) throws Exception {
+ // SERVICE REQUEST
+ // Construct the default service name
+ // TODO need to make this a configurable property
+ String defaultServiceModelName = msoRequest.getRequestInfo().getSource() + "_DEFAULT";
+
+ Service serviceRecord = null;
+ ModelInfo modelInfo = msoRequest.getModelInfo();
+ if(msoRequest.getALaCarteFlag()){
+ serviceRecord = db.getServiceByModelName(defaultServiceModelName);
+ }else{
+ serviceRecord = db.getServiceByModelUUID(modelInfo.getModelVersionId()); // ModelVersionId is not required in v3
+ if(serviceRecord == null) {
+ serviceRecord = db.getServiceByVersionAndInvariantId(modelInfo.getModelInvariantId(), modelInfo.getModelVersion());
+ }
+ }
+
+ ServiceRecipe recipe = null;
+ if(serviceRecord !=null){
+ recipe = db.getServiceRecipeByModelUUID(serviceRecord.getModelUUID(), action.name());
+ }
+ //if an aLaCarte flag was sent in the request, throw an error if the recipe was not found
+ RequestParameters reqParam = msoRequest.getServiceInstancesRequest().getRequestDetails().getRequestParameters();
+ if(reqParam!=null && reqParam.isALaCarteSet() && recipe==null){
+ return null;
+ }else if (recipe == null) { //aLaCarte wasn't sent, so we'll try the default
+ serviceRecord = db.getServiceByModelName(defaultServiceModelName);
+ recipe = db.getServiceRecipeByModelUUID(serviceRecord.getModelUUID(), action.name());
+ }
+
+ if(modelInfo.getModelVersionId() == null) {
+ modelInfo.setModelVersionId(serviceRecord.getModelUUID());
+ }
+ if(recipe==null){
+ return null;
+ }
+ return new RecipeLookupResult (recipe.getOrchestrationUri (), recipe.getRecipeTimeout ());
+ }
+
+
+ private RecipeLookupResult getVnfOrVfModuleUri (CatalogDatabase db, MsoRequest msoRequest, Action action) throws Exception {
+
+ ModelInfo modelInfo = msoRequest.getModelInfo();
+ String vnfComponentType = modelInfo.getModelType().name();
+
+ RelatedInstanceList[] instanceList = null;
+ if (msoRequest.getServiceInstancesRequest().getRequestDetails() != null) {
+ instanceList = msoRequest.getServiceInstancesRequest().getRequestDetails().getRelatedInstanceList();
+ }
+
+ Recipe recipe = null;
+ String defaultVnfType = msoRequest.getRequestInfo().getSource() + "_DEFAULT";
+ String modelCustomizationId = modelInfo.getModelCustomizationId();
+ String modelCustomizationName = modelInfo.getModelCustomizationName();
+ String relatedInstanceModelVersionId = null;
+ String relatedInstanceModelInvariantId = null;
+ String relatedInstanceVersion = null;
+ String relatedInstanceModelCustomizationName = null;
+
+ if (instanceList != null) {
+
+ for(RelatedInstanceList relatedInstanceList : instanceList){
+
+ RelatedInstance relatedInstance = relatedInstanceList.getRelatedInstance();
+ ModelInfo relatedInstanceModelInfo = relatedInstance.getModelInfo();
+ if(relatedInstanceModelInfo.getModelType().equals(ModelType.service)){
+ relatedInstanceModelVersionId = relatedInstanceModelInfo.getModelVersionId();
+ relatedInstanceVersion = relatedInstanceModelInfo.getModelVersion();
+ }
+
+ if(relatedInstanceModelInfo.getModelType().equals(ModelType.vnf)){
+ relatedInstanceModelVersionId = relatedInstanceModelInfo.getModelVersionId();
+ relatedInstanceModelInvariantId = relatedInstanceModelInfo.getModelInvariantId();
+ relatedInstanceVersion = relatedInstanceModelInfo.getModelVersion();
+ relatedInstanceModelCustomizationName = relatedInstanceModelInfo.getModelCustomizationName();
+ }
+ }
+
+ if(modelInfo.getModelType().equals(ModelType.vnf)) {
+ // a. For a vnf request (only create, no update currently):
+ // i. (v3-v4) If modelInfo.modelCustomizationId is provided, use it to validate catalog DB has record in vnf_resource_customization.model_customization_uuid.
+ // ii. (v2-v4) If modelInfo.modelCustomizationId is NOT provided (because it is a pre-1702 ASDC model or pre-v3), then modelInfo.modelCustomizationName must have
+ // been provided (else create request should be rejected). APIH should use the relatedInstance.modelInfo[service].modelVersionId** + modelInfo[vnf].modelCustomizationName
+ // to “join” service_to_resource_customizations with vnf_resource_customization to confirm a vnf_resource_customization.model_customization_uuid record exists.
+ // **If relatedInstance.modelInfo[service].modelVersionId was not provided, use relatedInstance.modelInfo[service].modelInvariantId + modelVersion instead to lookup modelVersionId
+ // (MODEL_UUID) in SERVICE table.
+ // iii. Regardless of how the value was provided/obtained above, APIH must always populate vnfModelCustomizationId in bpmnRequest. It would be assumed it was MSO generated
+ // during 1707 data migration if VID did not provide it originally on request.
+ // iv. Note: continue to construct the “vnf-type” value and pass to BPMN (must still be populated in A&AI).
+ // 1. If modelCustomizationName is NOT provided on a vnf/vfModule request, use modelCustomizationId to look it up in our catalog to construct vnf-type value to pass to BPMN.
+
+ VnfResource vnfResource = null;
+ VnfResourceCustomization vrc = null;
+ // Validation for vnfResource
+
+ if(modelCustomizationId!=null) {
+ vnfResource = db.getVnfResourceByModelCustomizationId(modelCustomizationId);
+ } else {
+ Service service = db.getServiceByModelUUID(relatedInstanceModelVersionId);
+ if(service == null) {
+ service = db.getServiceByVersionAndInvariantId(relatedInstanceModelInvariantId, relatedInstanceVersion);
+ }
+
+ if(service == null) {
+ throw new ValidationException("service in relatedInstance");
+ }
+
+ vrc = db.getVnfResourceCustomizationByModelCustomizationName(modelCustomizationName, service.getModelUUID());
+ if(vrc != null) {
+ vnfResource = vrc.getVnfResource();
+ modelInfo.setModelCustomizationId(vrc.getModelCustomizationUuid());
+ modelInfo.setModelCustomizationUuid(vrc.getModelCustomizationUuid());
+ }
+ }
+
+ if(vnfResource==null){
+ throw new ValidationException("catalog entry");
+ } else {
+ if(modelInfo.getModelVersionId() == null) {
+ modelInfo.setModelVersionId(vnfResource.getModelUuid());
+ }
+ }
+
+ VnfRecipe vnfRecipe = db.getVnfRecipe(defaultVnfType, action.name());
+
+ if (vnfRecipe == null) {
+ return null;
+ }
+
+ return new RecipeLookupResult (vnfRecipe.getOrchestrationUri(), vnfRecipe.getRecipeTimeout());
+ } else {
+ // ii. (v2-v4) If modelInfo.modelCustomizationId is NOT provided (because it is a pre-1702 ASDC model or pre-v3), then modelInfo.modelCustomizationName must have
+ // been provided (else create request should be rejected). APIH should use the relatedInstance.modelInfo[vnf].modelVersionId** + modelInfo[vnf].modelCustomizationName
+ // to “join” vnf_to_resource_customizations with vf_resource_customization to confirm a vf_resource_customization.model_customization_uuid record exists.
+ // **If relatedInstance.modelInfo[vnf].modelVersionId was not provided, use relatedInstance.modelInfo[vnf].modelInvariantId + modelVersion instead
+ // to lookup modelVersionId (MODEL_UUID) in vnf_resource table. Once the vnf’s model_customization_uuid has been obtained, use it to find all vfModule customizations
+ // for that vnf customization in the vnf_res_custom_to_vf_module_custom join table. For each vf_module_cust_model_customization_uuid value returned,
+ // use that UUID to query vf_module_customization table along with modelInfo[vfModule|volumeGroup].modelVersionId** to confirm record matches request data
+ // (and to identify the modelCustomizationId associated with the vfModule in the request). **If modelInfo[vfModule|volumeGroup].modelVersionId was not
+ // provided (potentially in v2/v3), use modelInfo[vfModule|volumeGroup].modelInvariantId + modelVersion instead. This means taking each record found
+ // in vf_module_customization and looking up in vf_module (using vf_module_customization’s FK into vf_module) to find a match on MODEL_INVARIANT_UUID (modelInvariantId)
+ // and MODEL_VERSION (modelVersion).
+
+ if(!msoRequest.getALaCarteFlag()) {
+ VfModuleCustomization vfmc = null;
+ VnfResourceCustomization vnfrc = null;
+ VfModule vfModule = null;
+
+ if( modelInfo.getModelCustomizationId() != null) {
+ vfmc = db.getVfModuleCustomizationByModelCustomizationId(modelInfo.getModelCustomizationId());
+ } else {
+ vnfrc =db.getVnfResourceCustomizationByVnfModelCustomizationNameAndModelVersionId(relatedInstanceModelCustomizationName, relatedInstanceModelVersionId);
+ if(vnfrc == null) {
+ vnfrc = db.getVnfResourceCustomizationByModelInvariantId(relatedInstanceModelInvariantId, relatedInstanceVersion, relatedInstanceModelCustomizationName);
+ }
+
+ List<VfModuleCustomization> list = db.getVfModuleCustomizationByVnfModuleCustomizationUuid(vnfrc.getModelCustomizationUuid());
+
+ String vfModuleModelUUID = modelInfo.getModelVersionId();
+ for(VfModuleCustomization vf : list) {
+ if(vfModuleModelUUID != null) {
+ vfModule = db.getVfModuleByModelCustomizationIdAndVersion(vf.getModelCustomizationUuid(), vfModuleModelUUID);
+ } else {
+ vfModule = db.getVfModuleByModelCustomizationIdModelVersionAndModelInvariantId(vf.getModelCustomizationUuid(), modelInfo.getModelVersion(), modelInfo.getModelInvariantId());
+ }
+
+ if(vfModule != null) {
+ modelInfo.setModelCustomizationId(vf.getModelCustomizationUuid());
+ modelInfo.setModelCustomizationUuid(vf.getModelCustomizationUuid());
+ break;
+ }
+ }
+ }
+
+ if(vfmc == null && vfModule == null) {
+ throw new ValidationException("no catalog entry found");
+ } else if (vfModule == null && vfmc != null) {
+ vfModule = vfmc.getVfModule(); // can't be null as vfModuleModelUUID is not-null property in VfModuleCustomization table
+ }
+
+ if(modelInfo.getModelVersionId() == null) {
+ modelInfo.setModelVersionId(vfModule.getModelUUID());
+ }
+ recipe = db.getVnfComponentsRecipeByVfModuleModelUUId(vfModule.getModelUUID(), vnfComponentType, action.name());
+ }
+
+ if(recipe == null) {
+ recipe = db.getVnfComponentsRecipeByVfModuleModelUUId(defaultVnfType, vnfComponentType, action.name());
+ if (recipe == null) {
+ recipe = db.getVnfComponentsRecipeByVfModuleModelUUId("*", vnfComponentType, action.name());
+ }
+
+ if(recipe == null) {
+ return null;
+ }
+ }
+ }
+ } else {
+ msoLogger.debug("recipe is null, getting default");
+
+ if(modelInfo.getModelType().equals(ModelType.vnf)) {
+ recipe = db.getVnfRecipe(defaultVnfType, action.name());
+ if (recipe == null) {
+ return null;
+ }
+ } else {
+ recipe = db.getVnfComponentsRecipeByVfModuleModelUUId("VID_DEFAULT", vnfComponentType, action.name());
+
+ if (recipe == null) {
+ return null;
+ }
+ }
+ }
+
+ return new RecipeLookupResult (recipe.getOrchestrationUri (), recipe.getRecipeTimeout ());
+ }
+
+ private RecipeLookupResult getNetworkUri (CatalogDatabase db, MsoRequest msoRequest, Action action) throws Exception {
+
+ String defaultNetworkType = msoRequest.getRequestInfo().getSource() + "_DEFAULT";
+
+ ModelInfo modelInfo = msoRequest.getModelInfo();
+ String modelName = modelInfo.getModelName();
+ Recipe recipe = null;
+ if(msoRequest.getALaCarteFlag()){
+ recipe = db.getNetworkRecipe(defaultNetworkType, action.name());
+ }else{
+ if(modelInfo.getModelCustomizationId()!=null){
+ NetworkResource networkResource = db.getNetworkResourceByModelCustUuid(modelInfo.getModelCustomizationId());
+ if(networkResource!=null){
+ if(modelInfo.getModelVersionId() == null) {
+ modelInfo.setModelVersionId(networkResource.getModelUUID());
+ }
+ recipe = db.getNetworkRecipe(networkResource.getModelName(), action.name());
+ }else{
+ throw new ValidationException("no catalog entry found");
+ }
+ }else{
+ //ok for version < 3 and action delete
+ recipe = db.getNetworkRecipe(modelName, action.name());
+ }
+ if(recipe == null){
+ recipe = db.getNetworkRecipe(defaultNetworkType, action.name());
+ }
+ }
+ if (recipe == null) {
+ return null;
+ }
+ return new RecipeLookupResult (recipe.getOrchestrationUri (), recipe.getRecipeTimeout ());
+ }
}