use of com.emc.storageos.db.client.constraint.NamedElementQueryResultList 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();
}
use of com.emc.storageos.db.client.constraint.NamedElementQueryResultList in project coprhd-controller by CoprHD.
the class BourneDbClient method queryNamedElementsByConstraint.
protected List<NamedElement> queryNamedElementsByConstraint(Constraint constraint, int maxCount) {
NamedElementQueryResultList queryResults = new NamedElementQueryResultList();
try {
if (maxCount > 0) {
getDbClient().queryByConstraint(constraint, queryResults, null, maxCount);
} else {
getDbClient().queryByConstraint(constraint, queryResults);
}
} catch (DatabaseException e) {
throw new DataAccessException(e);
}
List<NamedElement> results = Lists.newArrayList();
for (NamedElement namedElement : queryResults) {
results.add(namedElement);
}
return results;
}
use of com.emc.storageos.db.client.constraint.NamedElementQueryResultList in project coprhd-controller by CoprHD.
the class UserGroupService method getUserGroupIds.
/**
* Gets the user group list (of URNs).
*
* @brief List active user group URNs
* @return All the user groups details as UserGroupList
* @see UserGroupList
*/
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public UserGroupList getUserGroupIds() {
checkCompatibleVersion();
checkIfUserHasPermissions();
NamedElementQueryResultList userGroups = new NamedElementQueryResultList();
List<URI> uris = _dbClient.queryByType(UserGroup.class, true);
List<UserGroup> configs = _dbClient.queryObject(UserGroup.class, uris);
List<NamedElementQueryResultList.NamedElement> elements = new ArrayList<NamedElementQueryResultList.NamedElement>(configs.size());
for (UserGroup p : configs) {
elements.add(NamedElementQueryResultList.NamedElement.createElement(p.getId(), p.getLabel()));
}
userGroups.setResult(elements.iterator());
UserGroupList list = new UserGroupList();
list.getUserGroups().addAll(DbObjectMapper.map(ResourceTypeEnum.USER_GROUP, userGroups));
return list;
}
Aggregations