Search in sources :

Example 1 with OrderServiceJob

use of com.emc.sa.api.utils.OrderServiceJob in project coprhd-controller by CoprHD.

the class OrderService method deleteOrders.

/**
 * @brief delete orders (that can be deleted) under given tenants within a time range
 * @param startTimeStr the start time of the range (exclusive)
 * @param endTimeStr the end time of the range (inclusive)
 * @param tenantIDsStr A list of tenant IDs separated by ','
 * @param statusStr Order status
 * @return OK if a background job is submitted successfully
 */
@DELETE
@Path("")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.TENANT_ADMIN })
public Response deleteOrders(@DefaultValue("") @QueryParam(SearchConstants.START_TIME_PARAM) String startTimeStr, @DefaultValue("") @QueryParam(SearchConstants.END_TIME_PARAM) String endTimeStr, @DefaultValue("") @QueryParam(SearchConstants.TENANT_IDS_PARAM) String tenantIDsStr, @DefaultValue("") @QueryParam(SearchConstants.ORDER_STATUS_PARAM2) String statusStr) {
    long startTimeInMS = getTime(startTimeStr, 0);
    long endTimeInMS = getTime(endTimeStr, System.currentTimeMillis());
    if (startTimeInMS > endTimeInMS) {
        throw APIException.badRequests.endTimeBeforeStartTime(startTimeStr, endTimeStr);
    }
    if (tenantIDsStr.isEmpty()) {
        throw APIException.badRequests.invalidParameterWithCause(SearchConstants.TENANT_IDS_PARAM, tenantIDsStr, new InvalidParameterException("tenant IDs should not be empty"));
    }
    OrderStatus orderStatus = getOrderStatus(statusStr, true);
    if (isJobRunning()) {
        throw APIException.badRequests.cannotExecuteOperationWhilePendingTask("Deleting/Downloading orders");
    }
    List<URI> tids = toIDs(SearchConstants.TENANT_IDS_PARAM, tenantIDsStr);
    StorageOSUser user = getUserFromContext();
    URI tid = URI.create(user.getTenantId());
    URI uid = URI.create(user.getName());
    OrderJobStatus status = new OrderJobStatus(OrderServiceJob.JobType.DELETE_ORDER, startTimeInMS, endTimeInMS, tids, tid, uid, orderStatus);
    try {
        saveJobInfo(status);
    } catch (Exception e) {
        log.error("Failed to save job info e=", e);
        throw APIException.internalServerErrors.getLockFailed();
    }
    OrderServiceJob job = new OrderServiceJob(OrderServiceJob.JobType.DELETE_ORDER);
    try {
        queue.put(job);
    } catch (Exception e) {
        String errMsg = String.format("Failed to put the job into the queue %s", ORDER_SERVICE_QUEUE_NAME);
        log.error("{} e=", errMsg, e);
        APIException.internalServerErrors.genericApisvcError(errMsg, e);
    }
    String auditLogMsg = genDeletingOrdersMessage(startTimeStr, endTimeStr);
    auditOpSuccess(OperationTypeEnum.DELETE_ORDER, auditLogMsg);
    return Response.status(Response.Status.ACCEPTED).build();
}
Also used : InvalidParameterException(java.security.InvalidParameterException) OrderStatus(com.emc.storageos.db.client.model.uimodels.OrderStatus) StorageOSUser(com.emc.storageos.security.authentication.StorageOSUser) URIUtil.asString(com.emc.storageos.db.client.URIUtil.asString) OrderJobStatus(com.emc.sa.api.utils.OrderJobStatus) URI(java.net.URI) InvalidParameterException(java.security.InvalidParameterException) WebApplicationException(javax.ws.rs.WebApplicationException) URISyntaxException(java.net.URISyntaxException) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) OrderServiceJob(com.emc.sa.api.utils.OrderServiceJob) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Aggregations

OrderJobStatus (com.emc.sa.api.utils.OrderJobStatus)1 OrderServiceJob (com.emc.sa.api.utils.OrderServiceJob)1 URIUtil.asString (com.emc.storageos.db.client.URIUtil.asString)1 OrderStatus (com.emc.storageos.db.client.model.uimodels.OrderStatus)1 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)1 StorageOSUser (com.emc.storageos.security.authentication.StorageOSUser)1 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)1 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 InvalidParameterException (java.security.InvalidParameterException)1 DELETE (javax.ws.rs.DELETE)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 WebApplicationException (javax.ws.rs.WebApplicationException)1