diff options
author | 2017-04-11 13:30:42 +0200 | |
---|---|---|
committer | 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/OrchestrationRequests.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/OrchestrationRequests.java')
-rw-r--r-- | mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/OrchestrationRequests.java | 237 |
1 files changed, 171 insertions, 66 deletions
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/OrchestrationRequests.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/OrchestrationRequests.java index 00104daaf6..f42ba97e89 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/OrchestrationRequests.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/OrchestrationRequests.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. @@ -24,10 +24,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; +import javax.ws.rs.*; import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MultivaluedMap; @@ -38,20 +35,14 @@ import org.apache.http.HttpStatus; import org.codehaus.jackson.map.ObjectMapper; import org.openecomp.mso.apihandler.common.ErrorNumbers; -import org.openecomp.mso.apihandlerinfra.serviceinstancebeans.GetOrchestrationListResponse; -import org.openecomp.mso.apihandlerinfra.serviceinstancebeans.GetOrchestrationResponse; -import org.openecomp.mso.apihandlerinfra.serviceinstancebeans.InstanceReferences; -import org.openecomp.mso.apihandlerinfra.serviceinstancebeans.Request; -import org.openecomp.mso.apihandlerinfra.serviceinstancebeans.RequestDetails; -import org.openecomp.mso.apihandlerinfra.serviceinstancebeans.RequestList; -import org.openecomp.mso.apihandlerinfra.serviceinstancebeans.RequestStatus; +import org.openecomp.mso.apihandlerinfra.serviceinstancebeans.*; import org.openecomp.mso.logger.MessageEnum; import org.openecomp.mso.logger.MsoAlarmLogger; import org.openecomp.mso.logger.MsoLogger; import org.openecomp.mso.requestsdb.InfraActiveRequests; import org.openecomp.mso.requestsdb.RequestsDatabase; -@Path("/orchestrationRequests/v2") +@Path("/") public class OrchestrationRequests { public final static String MSO_PROP_APIHANDLER_INFRA = "MSO_PROP_APIHANDLER_INFRA"; @@ -61,28 +52,28 @@ public class OrchestrationRequests { private static MsoAlarmLogger alarmLogger = new MsoAlarmLogger (); /** - * + * */ public OrchestrationRequests() { // TODO Auto-generated constructor stub } @GET - @Path("/{requestId}") + @Path("/orchestrationRequests/{version:[vV][2-3]}/{requestId}") @Produces(MediaType.APPLICATION_JSON) public Response getOrchestrationRequest(@PathParam("requestId") String requestId) { - + GetOrchestrationResponse orchestrationResponse = new GetOrchestrationResponse(); - + MsoRequest msoRequest = new MsoRequest (requestId); - + long startTime = System.currentTimeMillis (); - + InfraActiveRequests requestDB = null; - + try { requestDB = RequestsDatabase.getRequestFromInfraActive(requestId); - + } catch (Exception e) { msoLogger.error (MessageEnum.APIH_DB_ACCESS_EXC, MSO_PROP_APIHANDLER_INFRA, "", "", MsoLogger.ErrorCode.AvailabilityError, "Exception while communciate with Request DB - Infra Request Lookup", e); msoRequest.setStatus (org.openecomp.mso.apihandlerinfra.vnfbeans.RequestStatusType.FAILED); @@ -97,57 +88,57 @@ public class OrchestrationRequests { msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DBAccessError, "Exception while communciate with Request DB"); msoLogger.debug ("End of the transaction, the final response is: " + (String) response.getEntity ()); return response; - + } - + if(requestDB == null) { Response resp = msoRequest.buildServiceErrorResponse (HttpStatus.SC_NO_CONTENT, MsoException.ServiceException, - "Orchestration RequestId " + requestId + " is not found in DB", + "Orchestration RequestId " + requestId + " is not found in DB", ErrorNumbers.SVC_DETAILED_SERVICE_ERROR, null); msoLogger.error (MessageEnum.APIH_BPEL_COMMUNICATE_ERROR, MSO_PROP_APIHANDLER_INFRA, "", "", MsoLogger.ErrorCode.BusinessProcesssError, "Null response from RequestDB when searching by RequestId"); msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DataNotFound, "Null response from RequestDB when searching by RequestId"); msoLogger.debug ("End of the transaction, the final response is: " + (String) resp.getEntity ()); return resp; - + } - + Request request = mapInfraActiveRequestToRequest(requestDB); - + orchestrationResponse.setRequest(request); - + return Response.status(200).entity(orchestrationResponse).build(); } - + @GET - @Path("/") + @Path("/orchestrationRequests/{version:[vV][2-3]}") @Produces(MediaType.APPLICATION_JSON) public Response getOrchestrationRequest(@Context UriInfo ui) { - + long startTime = System.currentTimeMillis (); - + MsoRequest msoRequest = new MsoRequest(); - + MultivaluedMap<String, String> queryParams = ui.getQueryParameters(); - + List<InfraActiveRequests> activeRequests = null; - + GetOrchestrationListResponse orchestrationList = null; - - + + try{ - + Map<String, List<String>> orchestrationMap = msoRequest.getOrchestrationFilters(queryParams); - + activeRequests = RequestsDatabase.getOrchestrationFiltersFromInfraActive(orchestrationMap); - + orchestrationList = new GetOrchestrationListResponse(); List<RequestList> requestLists = new ArrayList<RequestList>(); - + for(InfraActiveRequests infraActive : activeRequests){ - + Request request = mapInfraActiveRequestToRequest(infraActive); RequestList requestList = new RequestList(); requestList.setRequest(request); @@ -155,36 +146,148 @@ public class OrchestrationRequests { requestLists.add(requestList); } - + orchestrationList.setRequestList(requestLists); }catch(Exception e){ msoLogger.debug ("Get Orchestration Request with Filters Failed : ", e); - Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_INTERNAL_SERVER_ERROR, MsoException.ServiceException, - "Get Orchestration Request with Filters Failed. " + e.getMessage(), + Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_INTERNAL_SERVER_ERROR, MsoException.ServiceException, + "Get Orchestration Request with Filters Failed. " + e.getMessage(), ErrorNumbers.SVC_GENERAL_SERVICE_ERROR, null); msoLogger.error (MessageEnum.APIH_GENERAL_EXCEPTION, MSO_PROP_APIHANDLER_INFRA, "", "", MsoLogger.ErrorCode.BusinessProcesssError, "Get Orchestration Request with Filters Failed : " + e); msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DataError, "Get Orchestration Request with Filters Failed"); msoLogger.debug ("End of the transaction, the final response is: " + (String) response.getEntity ()); return response; } - - + + return Response.status(200).entity(orchestrationList).build(); } + + @POST + @Path("/orchestrationRequests/v3/{requestId}/unlock") + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + public Response unlockOrchestrationRequest(String requestJSON, @PathParam("requestId") String requestId) { + + MsoRequest msoRequest = new MsoRequest (requestId); + + long startTime = System.currentTimeMillis (); + msoLogger.debug ("requestId is: " + requestId); + + InfraActiveRequests requestDB = null; + Request request = null; + + msoLogger.debug ("requestId is: " + requestId); + ServiceInstancesRequest sir = null; + + 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"); + } + 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.parseOrchestration(sir); + } 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"); + } + 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; + } + + try { + requestDB = RequestsDatabase.getRequestFromInfraActive(requestId); + + if(requestDB == null) { + Response resp = msoRequest.buildServiceErrorResponse (HttpStatus.SC_NOT_FOUND, + MsoException.ServiceException, + "Orchestration RequestId " + requestId + " is not found in DB", + ErrorNumbers.SVC_DETAILED_SERVICE_ERROR, + null); + msoLogger.error (MessageEnum.APIH_DB_ATTRIBUTE_NOT_FOUND, MSO_PROP_APIHANDLER_INFRA, "", "", MsoLogger.ErrorCode.BusinessProcesssError, "Null response from RequestDB when searching by RequestId"); + msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DataNotFound, "Null response from RequestDB when searching by RequestId"); + msoLogger.debug ("End of the transaction, the final response is: " + (String) resp.getEntity ()); + return resp; + + }else{ + request = mapInfraActiveRequestToRequest(requestDB); + RequestStatus reqStatus = request.getRequestStatus(); + Status status = Status.valueOf(reqStatus.getRequestState()); + if(status == Status.IN_PROGRESS || status == Status.PENDING){ + msoRequest.setStatus (org.openecomp.mso.apihandlerinfra.vnfbeans.RequestStatusType.UNLOCKED); + reqStatus.setRequestState(Status.UNLOCKED.toString ()); + RequestsDatabase.updateInfraStatus (requestId, + Status.UNLOCKED.toString (), + Constants.MODIFIED_BY_APIHANDLER); + + msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "RequestId " + requestId + " has been unlocked"); + + }else{ + Response resp = msoRequest.buildServiceErrorResponse (HttpStatus.SC_BAD_REQUEST, + MsoException.ServiceException, + "Orchestration RequestId " + requestId + " has a status of " + status + " and can not be unlocked", + ErrorNumbers.SVC_DETAILED_SERVICE_ERROR, + null); + msoLogger.error (MessageEnum.APIH_DB_ATTRIBUTE_NOT_FOUND, MSO_PROP_APIHANDLER_INFRA, "", "", MsoLogger.ErrorCode.DataError, "Orchestration RequestId " + requestId + " has a status of " + status + " and can not be unlocked"); + msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DataError, "Orchestration RequestId " + requestId + " has a status of " + status + " and can not be unlocked"); + msoLogger.debug ("End of the transaction, the final response is: " + (String) resp.getEntity ()); + return resp; + } + } + } catch (Exception e) { + msoLogger.error (MessageEnum.APIH_DB_ACCESS_EXC, MSO_PROP_APIHANDLER_INFRA, "", "", MsoLogger.ErrorCode.AvailabilityError, "Exception while communciate with Request DB - Infra Request Lookup", e); + msoRequest.setStatus (org.openecomp.mso.apihandlerinfra.vnfbeans.RequestStatusType.FAILED); + Response response = msoRequest.buildServiceErrorResponse (HttpStatus.SC_NOT_FOUND, + MsoException.ServiceException, + e.getMessage (), + ErrorNumbers.NO_COMMUNICATION_TO_REQUESTS_DB, + null); + alarmLogger.sendAlarm ("MsoDatabaseAccessError", + MsoAlarmLogger.CRITICAL, + Messages.errors.get (ErrorNumbers.NO_COMMUNICATION_TO_REQUESTS_DB)); + msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DBAccessError, "Exception while communciate with Request DB"); + msoLogger.debug ("End of the transaction, the final response is: " + (String) response.getEntity ()); + return response; + + } + + return Response.status (HttpStatus.SC_NO_CONTENT).entity ("").build (); + } + private Request mapInfraActiveRequestToRequest(InfraActiveRequests requestDB) { - - + + Request request = new Request(); - + ObjectMapper mapper = new ObjectMapper(); // mapper.configure(Feature.WRAP_ROOT_VALUE, true); - + request.setRequestId(requestDB.getRequestId()); request.setRequestScope(requestDB.getRequestScope()); request.setRequestType(requestDB.getRequestAction()); - + InstanceReferences ir = new InstanceReferences(); if(requestDB.getNetworkId() != null) ir.setNetworkInstanceId(requestDB.getNetworkId()); @@ -206,46 +309,48 @@ public class OrchestrationRequests { ir.setVolumeGroupInstanceId(requestDB.getVolumeGroupId()); if(requestDB.getVolumeGroupName() != null) ir.setVolumeGroupInstanceName(requestDB.getVolumeGroupName()); + if(requestDB.getRequestorId() != null) + ir.setRequestorId(requestDB.getRequestorId()); + + + request.setInstanceReferences(ir); - - request.setInstanceReferences(ir); - String requestBody = requestDB.getRequestBody(); - + RequestDetails requestDetails = null; - + try{ requestDetails = mapper.readValue(requestBody, RequestDetails.class); - + }catch(Exception e){ msoLogger.debug("Exception caught mapping requestBody to RequestDetails"); } - + request.setRequestDetails(requestDetails); String startTimeStamp = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss").format(requestDB.getStartTime()) + " GMT"; request.setStartTime(startTimeStamp); - + RequestStatus status = new RequestStatus(); if(requestDB.getStatusMessage() != null){ status.setStatusMessage(requestDB.getStatusMessage()); } - + if(requestDB.getEndTime() != null){ String endTimeStamp = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss").format(requestDB.getEndTime()) + " GMT"; status.setFinishTime(endTimeStamp); } - + if(requestDB.getRequestStatus() != null){ status.setRequestState(requestDB.getRequestStatus()); } - + if(requestDB.getProgress() != null){ status.setPercentProgress(requestDB.getProgress().intValue()); } - + request.setRequestStatus(status); - + return request; } } |