Search in sources :

Example 16 with NamedElementQueryResultList

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

Example 17 with NamedElementQueryResultList

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;
}
Also used : NamedElementQueryResultList(com.emc.storageos.db.client.constraint.NamedElementQueryResultList) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) NamedElement(com.emc.storageos.db.client.constraint.NamedElementQueryResultList.NamedElement)

Example 18 with NamedElementQueryResultList

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;
}
Also used : NamedElementQueryResultList(com.emc.storageos.db.client.constraint.NamedElementQueryResultList) URI(java.net.URI) UserGroup(com.emc.storageos.db.client.model.UserGroup) MapUserGroup(com.emc.storageos.api.mapper.functions.MapUserGroup)

Aggregations

NamedElementQueryResultList (com.emc.storageos.db.client.constraint.NamedElementQueryResultList)18 URI (java.net.URI)11 ArrayList (java.util.ArrayList)6 NamedURI (com.emc.storageos.db.client.model.NamedURI)5 AlternateIdConstraint (com.emc.storageos.db.client.constraint.AlternateIdConstraint)4 AlternateIdConstraintImpl (com.emc.storageos.db.client.constraint.impl.AlternateIdConstraintImpl)4 DataObjectType (com.emc.storageos.db.client.impl.DataObjectType)4 TenantOrg (com.emc.storageos.db.client.model.TenantOrg)4 UserPreferences (com.emc.storageos.db.client.model.UserPreferences)4 StorageOSUser (com.emc.storageos.security.authentication.StorageOSUser)4 HashSet (java.util.HashSet)4 GET (javax.ws.rs.GET)4 Produces (javax.ws.rs.Produces)4 AbstractChangeTrackingSet (com.emc.storageos.db.client.model.AbstractChangeTrackingSet)3 StringSet (com.emc.storageos.db.client.model.StringSet)3 Set (java.util.Set)3 Path (javax.ws.rs.Path)3 NamedElement (com.emc.storageos.db.client.constraint.NamedElementQueryResultList.NamedElement)2 TimeSeriesConstraint (com.emc.storageos.db.client.constraint.TimeSeriesConstraint)2 Order (com.emc.storageos.db.client.model.uimodels.Order)2