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);
}
}
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;
}
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);
}
}
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);
}
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();
}
Aggregations