Search in sources :

Example 1 with OrderJobStatus

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

the class OrderService method downloadOrders.

/**
 * Get log data from the specified virtual machines that are filtered, merged,
 * and sorted based on the passed request parameters and streams the log
 * messages back to the client as JSON formatted strings.
 *
 * @brief Show logs from all or specified virtual machine
 * @param startTimeStr The start datetime of the desired time window. Value is
 *            inclusive.
 *            Allowed values: "yyyy-MM-dd_HH:mm:ss" formatted date or
 *            datetime in ms.
 *            Default: Set to yesterday same time
 * @param endTimeStr The end datetime of the desired time window. Value is
 *            inclusive.
 *            Allowed values: "yyyy-MM-dd_HH:mm:ss" formatted date or
 *            datetime in ms.
 * @param tenantIDsStr a list of tenant IDs separated by ','
 * @param orderIDsStr a list of order IDs separated by ','
 * @prereq one of tenantIDsStr and orderIDsStr should be empty
 * @return A reference to the StreamingOutput to which the log data is
 *         written.
 * @throws WebApplicationException When an invalid request is made.
 */
@GET
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.SYSTEM_MONITOR, Role.SECURITY_ADMIN })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN })
@Path("/download")
public Response downloadOrders(@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 orderStatusStr, @DefaultValue("") @QueryParam(SearchConstants.ORDER_IDS) String orderIDsStr) throws Exception {
    if (tenantIDsStr.isEmpty() && orderIDsStr.isEmpty()) {
        InvalidParameterException cause = new InvalidParameterException("Both tenant and order IDs are empty");
        throw APIException.badRequests.invalidParameterWithCause(SearchConstants.TENANT_ID_PARAM, tenantIDsStr, cause);
    }
    final long startTimeInMS = getTime(startTimeStr, 0);
    final long endTimeInMS = getTime(endTimeStr, System.currentTimeMillis());
    if (startTimeInMS > endTimeInMS) {
        throw APIException.badRequests.endTimeBeforeStartTime(startTimeStr, endTimeStr);
    }
    OrderStatus orderStatus = getOrderStatus(orderStatusStr, false);
    if (isJobRunning()) {
        throw APIException.badRequests.cannotExecuteOperationWhilePendingTask("Deleting/Downloading orders");
    }
    final List<URI> tids = toIDs(SearchConstants.TENANT_IDS_PARAM, tenantIDsStr);
    StorageOSUser user = getUserFromContext();
    URI tid = URI.create(user.getTenantId());
    URI uid = URI.create(user.getName());
    final OrderJobStatus status = new OrderJobStatus(OrderServiceJob.JobType.DOWNLOAD_ORDER, startTimeInMS, endTimeInMS, tids, tid, uid, orderStatus);
    List<URI> orderIDs = toIDs(SearchConstants.ORDER_IDS, orderIDsStr);
    status.setTotal(orderIDs.size());
    if (!orderIDs.isEmpty()) {
        status.setStartTime(0);
        status.setEndTime(0);
    }
    try {
        saveJobInfo(status);
    } catch (Exception e) {
        log.error("Failed to save job info e=", e);
        throw APIException.internalServerErrors.getLockFailed();
    }
    StreamingOutput out = new StreamingOutput() {

        @Override
        public void write(OutputStream outputStream) {
            exportOrders(tids, orderIDsStr, startTimeInMS, endTimeInMS, outputStream, status);
        }
    };
    return Response.ok(out).build();
}
Also used : InvalidParameterException(java.security.InvalidParameterException) OrderStatus(com.emc.storageos.db.client.model.uimodels.OrderStatus) StorageOSUser(com.emc.storageos.security.authentication.StorageOSUser) OutputStream(java.io.OutputStream) StreamingOutput(javax.ws.rs.core.StreamingOutput) 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) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 2 with OrderJobStatus

use of com.emc.sa.api.utils.OrderJobStatus 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)

Example 3 with OrderJobStatus

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

the class OrderService method isDeletingJobRunning.

private boolean isDeletingJobRunning() {
    OrderJobStatus jobStatus = queryJobInfo(OrderServiceJob.JobType.DELETE_ORDER);
    if (jobStatus == null) {
        // no job running
        return false;
    }
    long deletedOrdersInCurrentPeriod = getDeletedOrdersInCurrentPeriod(jobStatus);
    if (deletedOrdersInCurrentPeriod > maxOrderDeletedPerGC) {
        // There are already max number of orders deleted within the current GC
        return true;
    }
    return !jobStatus.isFinished();
}
Also used : OrderJobStatus(com.emc.sa.api.utils.OrderJobStatus)

Example 4 with OrderJobStatus

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

the class OrderService method getJobStatus.

/**
 * @brief Query status of deleting/downloading orders
 * @param typeStr the type of the job which can be 'DELETE' or 'DOWNLOAD'
 * @return job status
 */
@GET
@Path("/job-status")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.TENANT_ADMIN })
public OrderJobInfo getJobStatus(@DefaultValue("DELETE_ORDER") @QueryParam(SearchConstants.JOB_TYPE) String typeStr) {
    OrderServiceJob.JobType type;
    try {
        type = OrderServiceJob.JobType.valueOf(typeStr);
    } catch (Exception e) {
        log.error("Failed to get job type e=", e);
        throw APIException.badRequests.invalidParameterWithCause(SearchConstants.JOB_TYPE, typeStr, e);
    }
    OrderJobStatus status = queryJobInfo(type);
    return status != null ? status.toOrderJobInfo() : new OrderJobInfo();
}
Also used : OrderJobInfo(com.emc.vipr.model.catalog.OrderJobInfo) OrderJobStatus(com.emc.sa.api.utils.OrderJobStatus) 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) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Aggregations

OrderJobStatus (com.emc.sa.api.utils.OrderJobStatus)4 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)3 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)3 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)3 URISyntaxException (java.net.URISyntaxException)3 InvalidParameterException (java.security.InvalidParameterException)3 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 WebApplicationException (javax.ws.rs.WebApplicationException)3 OrderServiceJob (com.emc.sa.api.utils.OrderServiceJob)2 OrderStatus (com.emc.storageos.db.client.model.uimodels.OrderStatus)2 StorageOSUser (com.emc.storageos.security.authentication.StorageOSUser)2 URI (java.net.URI)2 GET (javax.ws.rs.GET)2 URIUtil.asString (com.emc.storageos.db.client.URIUtil.asString)1 OrderJobInfo (com.emc.vipr.model.catalog.OrderJobInfo)1 OutputStream (java.io.OutputStream)1 DELETE (javax.ws.rs.DELETE)1 StreamingOutput (javax.ws.rs.core.StreamingOutput)1