Search in sources :

Example 1 with TimeSeriesConstraint

use of com.emc.storageos.db.client.constraint.TimeSeriesConstraint in project coprhd-controller by CoprHD.

the class OrderService method exportOrders.

private void exportOrders(List<URI> tids, long startTime, long endTime, OutputStream outputStream, OrderJobStatus status) {
    PrintStream out = new PrintStream(outputStream);
    out.println("ORDER DETAILS");
    out.println("-------------");
    List<URI> orderIDs = status.getOrderIDs();
    if (!orderIDs.isEmpty()) {
        dumpOrders(out, orderIDs, status);
    } else {
        long completed = 0;
        long failed = 0;
        for (URI tid : tids) {
            TimeSeriesConstraint constraint = TimeSeriesConstraint.Factory.getOrders(tid, startTime, endTime);
            DbClientImpl dbclient = (DbClientImpl) _dbClient;
            constraint.setKeyspace(dbclient.getKeyspace(Order.class));
            NamedElementQueryResultList ids = new NamedElementQueryResultList();
            _dbClient.queryByConstraint(constraint, ids);
            for (NamedElementQueryResultList.NamedElement namedID : ids) {
                URI id = namedID.getId();
                try {
                    dumpOrder(out, id, status);
                    completed++;
                } catch (Exception e) {
                    failed++;
                }
            }
        }
        status.setTotal(completed + failed);
    }
    try {
        saveJobInfo(status);
    } catch (Exception e) {
        log.error("Failed to save job info status={} e=", status, e);
    }
}
Also used : Order(com.emc.storageos.db.client.model.uimodels.Order) PrintStream(java.io.PrintStream) TimeSeriesConstraint(com.emc.storageos.db.client.constraint.TimeSeriesConstraint) DbClientImpl(com.emc.storageos.db.client.impl.DbClientImpl) URI(java.net.URI) NamedElementQueryResultList(com.emc.storageos.db.client.constraint.NamedElementQueryResultList) 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)

Example 2 with TimeSeriesConstraint

use of com.emc.storageos.db.client.constraint.TimeSeriesConstraint in project coprhd-controller by CoprHD.

the class BourneDbClient method getOrderCount.

@Override
public Map<String, Long> getOrderCount(List<URI> tids, String fieldName, long startTime, long endTime) {
    LOG.debug("getOrderCount(tids={} cf={}, startTime={}, endTime={})", new Object[] { tids, fieldName, startTime, endTime });
    Map<String, Long> counts = new HashMap();
    for (URI tid : tids) {
        TimeSeriesConstraint constraint = TimeSeriesConstraint.Factory.getOrders(tid, startTime, endTime);
        DbClientImpl dbclient = (DbClientImpl) getDbClient();
        constraint.setKeyspace(dbclient.getKeyspace(Order.class));
        try {
            counts.put(tid.toString(), constraint.count());
        } catch (ConnectionException e) {
            throw new DataAccessException(e);
        }
    }
    return counts;
}
Also used : Order(com.emc.storageos.db.client.model.uimodels.Order) HashMap(java.util.HashMap) TimeSeriesConstraint(com.emc.storageos.db.client.constraint.TimeSeriesConstraint) DbClientImpl(com.emc.storageos.db.client.impl.DbClientImpl) URI(java.net.URI) ConnectionException(com.netflix.astyanax.connectionpool.exceptions.ConnectionException)

Example 3 with TimeSeriesConstraint

use of com.emc.storageos.db.client.constraint.TimeSeriesConstraint in project coprhd-controller by CoprHD.

the class BourneDbClient method getOrderCount.

@Override
public long getOrderCount(String userId, String fieldName, long startTime, long endTime) {
    LOG.debug("getOrderCount(userId={} cf={}, startTime={}, endTime={})", new Object[] { userId, fieldName, startTime, endTime });
    TimeSeriesConstraint constraint = TimeSeriesConstraint.Factory.getOrdersByUser(userId, startTime, endTime);
    DbClientImpl dbclient = (DbClientImpl) getDbClient();
    constraint.setKeyspace(dbclient.getKeyspace(Order.class));
    try {
        return constraint.count();
    } catch (ConnectionException e) {
        throw new DataAccessException(e);
    }
}
Also used : Order(com.emc.storageos.db.client.model.uimodels.Order) TimeSeriesConstraint(com.emc.storageos.db.client.constraint.TimeSeriesConstraint) DbClientImpl(com.emc.storageos.db.client.impl.DbClientImpl) ConnectionException(com.netflix.astyanax.connectionpool.exceptions.ConnectionException)

Example 4 with TimeSeriesConstraint

use of com.emc.storageos.db.client.constraint.TimeSeriesConstraint in project coprhd-controller by CoprHD.

the class BourneDbClient method findOrdersByAlternateId.

@Override
public List<NamedElement> findOrdersByAlternateId(String columnField, String userId, long startTime, long endTime, int maxCount) throws DataAccessException {
    LOG.debug("findOrdersByAlternateId(columnField={}, userId={}, maxCount={})", new Object[] { columnField, userId, maxCount });
    TimeSeriesConstraint constraint = TimeSeriesConstraint.Factory.getOrdersByUser(userId, startTime, endTime);
    return queryNamedElementsByConstraint(constraint, maxCount);
}
Also used : TimeSeriesConstraint(com.emc.storageos.db.client.constraint.TimeSeriesConstraint)

Example 5 with TimeSeriesConstraint

use of com.emc.storageos.db.client.constraint.TimeSeriesConstraint in project coprhd-controller by CoprHD.

the class OrderServiceJobConsumer method consumeItem.

/**
 * @param job The object provisioning job which is being worked on. This could be either creation or deletion job
 * @param callback This must be executed, after the item is processed successfully to remove the item
 *            from the distributed queue
 *
 * @throws Exception
 */
@Override
public void consumeItem(OrderServiceJob job, DistributedQueueItemProcessedCallback callback) throws Exception {
    while (true) {
        try {
            OrderJobStatus jobStatus = orderService.queryJobInfo(OrderServiceJob.JobType.DELETE_ORDER);
            long startTime = jobStatus.getStartTime();
            long endTime = jobStatus.getEndTime();
            OrderStatus status = jobStatus.getStatus();
            List<URI> tids = jobStatus.getTids();
            List<URI> orderIds = new ArrayList();
            log.info("jobstatus={}", jobStatus);
            long total = 0;
            long numberOfOrdersDeletedInGC = orderService.getDeletedOrdersInCurrentPeriodWithSort(jobStatus);
            long numberOfOrdersCanBeDeletedInGC = maxOrderDeletedPerGC - numberOfOrdersDeletedInGC;
            if (numberOfOrdersCanBeDeletedInGC <= 0) {
                log.info("Max number of order objects ({}) have been deleted in the current GC period", maxOrderDeletedPerGC);
                Thread.sleep(CHECK_INTERVAL);
                continue;
            }
            boolean stop = false;
            for (URI tid : tids) {
                TimeSeriesConstraint constraint = TimeSeriesConstraint.Factory.getOrders(tid, startTime, endTime);
                NamedElementQueryResultList ids = new NamedElementQueryResultList();
                dbClient.queryByConstraint(constraint, ids);
                for (NamedElementQueryResultList.NamedElement namedID : ids) {
                    URI id = namedID.getId();
                    Order order = orderManager.getOrderById(id);
                    try {
                        orderManager.canBeDeleted(order, status);
                        if (orderIds.size() < numberOfOrdersCanBeDeletedInGC) {
                            orderIds.add(id);
                        } else if (jobStatus.getTotal() != -1) {
                            stop = true;
                            break;
                        }
                        total++;
                    } catch (Exception e) {
                        continue;
                    }
                }
                if (stop) {
                    break;
                }
            }
            if (jobStatus.getTotal() == -1) {
                // It's the first time to run the job, so get the total number of orders to be deleted
                jobStatus.setTotal(total);
                orderService.saveJobInfo(jobStatus);
                if (total == 0) {
                    log.info("No orders can be deleted");
                    break;
                }
            }
            log.info("{} orders to be deleted within current GC period", orderIds.size());
            long nDeleted = 0;
            long nFailed = 0;
            long start = System.currentTimeMillis();
            long tempCount = 0;
            for (URI id : orderIds) {
                Order order = orderManager.getOrderById(id);
                try {
                    log.info("To delete order {}", order.getId());
                    orderManager.deleteOrder(order);
                    nDeleted++;
                    tempCount++;
                    if (tempCount >= NUMBER_PER_RECORD) {
                        jobStatus.addCompleted(tempCount);
                        orderService.saveJobInfo(jobStatus);
                        tempCount = 0;
                    }
                } catch (BadRequestException e) {
                    log.warn("Failed to delete order {} e=", id, e);
                    nFailed++;
                    jobStatus.setFailed(nFailed);
                    orderService.saveJobInfo(jobStatus);
                } catch (Exception e) {
                    log.warn("Failed to delete order={} e=", id, e);
                    nFailed++;
                    jobStatus.setFailed(nFailed);
                    orderService.saveJobInfo(jobStatus);
                }
            }
            if (tempCount > 0) {
                jobStatus.addCompleted(tempCount);
                orderService.saveJobInfo(jobStatus);
                tempCount = 0;
            }
            long end = System.currentTimeMillis();
            long speed = (end - start) / (nDeleted + nFailed);
            jobStatus.setTimeUsedPerOrder(speed);
            orderService.saveJobInfo(jobStatus);
            if (jobStatus.isFinished()) {
                break;
            }
            Thread.sleep(CHECK_INTERVAL);
        } catch (Exception e) {
            log.error("e=", e);
            throw e;
        }
    }
    log.info("remove order job from the queue");
    callback.itemProcessed();
}
Also used : Order(com.emc.storageos.db.client.model.uimodels.Order) TimeSeriesConstraint(com.emc.storageos.db.client.constraint.TimeSeriesConstraint) ArrayList(java.util.ArrayList) URI(java.net.URI) BadRequestException(com.emc.storageos.svcs.errorhandling.resources.BadRequestException) OrderStatus(com.emc.storageos.db.client.model.uimodels.OrderStatus) BadRequestException(com.emc.storageos.svcs.errorhandling.resources.BadRequestException) NamedElementQueryResultList(com.emc.storageos.db.client.constraint.NamedElementQueryResultList)

Aggregations

TimeSeriesConstraint (com.emc.storageos.db.client.constraint.TimeSeriesConstraint)6 Order (com.emc.storageos.db.client.model.uimodels.Order)4 DbClientImpl (com.emc.storageos.db.client.impl.DbClientImpl)3 URI (java.net.URI)3 NamedElementQueryResultList (com.emc.storageos.db.client.constraint.NamedElementQueryResultList)2 ConnectionException (com.netflix.astyanax.connectionpool.exceptions.ConnectionException)2 NamedElement (com.emc.storageos.db.client.constraint.NamedElementQueryResultList.NamedElement)1 OrderStatus (com.emc.storageos.db.client.model.uimodels.OrderStatus)1 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)1 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)1 BadRequestException (com.emc.storageos.svcs.errorhandling.resources.BadRequestException)1 PrintStream (java.io.PrintStream)1 URISyntaxException (java.net.URISyntaxException)1 InvalidParameterException (java.security.InvalidParameterException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 WebApplicationException (javax.ws.rs.WebApplicationException)1