Search in sources :

Example 1 with OrderCreateParam

use of com.emc.vipr.model.catalog.OrderCreateParam in project coprhd-controller by CoprHD.

the class OrderExecution method createOrder.

@Util
public static OrderCreateParam createOrder(CatalogServiceRestRep service, ServiceDescriptorRestRep descriptor, Map<String, String> parameters) {
    OrderCreateParam order = new OrderCreateParam();
    order.setTenantId(uri(Models.currentAdminTenant()));
    order.setCatalogService(service.getId());
    List<Parameter> orderParameters = Lists.newArrayList();
    List<ServiceFieldRestRep> fields = ServiceDescriptorUtils.getAllFieldList(descriptor.getItems());
    for (ServiceFieldRestRep field : fields) {
        String value = parameters.get(field.getName());
        if (StringUtils.isNotBlank(value)) {
            orderParameters.add(createOrderParameter(field, value));
        }
    }
    order.setParameters(orderParameters);
    return order;
}
Also used : CatalogServiceFieldRestRep(com.emc.vipr.model.catalog.CatalogServiceFieldRestRep) ServiceFieldRestRep(com.emc.vipr.model.catalog.ServiceFieldRestRep) OrderCreateParam(com.emc.vipr.model.catalog.OrderCreateParam) Parameter(com.emc.vipr.model.catalog.Parameter) Util(play.mvc.Util)

Example 2 with OrderCreateParam

use of com.emc.vipr.model.catalog.OrderCreateParam in project coprhd-controller by CoprHD.

the class ViPRService method findObsoleteReplica.

/**
 * Find obsolete replicas for given resource according to defined retention policy of this order
 *
 * @param resourceId
 * @return the replica to be removed. Otherwise null in case of no removal required
 */
protected List<RetainedReplica> findObsoleteReplica(String resourceId) {
    List<RetainedReplica> obsoleteReplicas = new ArrayList<RetainedReplica>();
    ScheduledEvent event = ExecutionUtils.currentContext().getScheduledEvent();
    Integer maxNumOfCopies = Integer.MAX_VALUE;
    try {
        OrderCreateParam param = OrderCreateParam.deserialize(org.apache.commons.codec.binary.Base64.decodeBase64(event.getOrderCreationParam().getBytes(UTF_8)));
        String additionalScheduleInfo = param.getAdditionalScheduleInfo();
        maxNumOfCopies = Integer.parseInt(additionalScheduleInfo);
    } catch (Exception ex) {
        error("Unexpected exception when checking scheduler retention", ex);
        return obsoleteReplicas;
    }
    List<NamedElement> replicaIdList = modelClient.findBy(RetainedReplica.class, "scheduledEventId", event.getId());
    List<RetainedReplica> replicas = new ArrayList<RetainedReplica>();
    for (NamedElement uri : replicaIdList) {
        RetainedReplica retention = modelClient.findById(RetainedReplica.class, uri.getId());
        if (retention.getResourceId().toString().equals(resourceId)) {
            replicas.add(retention);
        }
    }
    if (replicas.size() >= maxNumOfCopies) {
        Collections.sort(replicas, new Comparator<RetainedReplica>() {

            public int compare(RetainedReplica o1, RetainedReplica o2) {
                return o1.getCreationTime().compareTo(o2.getCreationTime());
            }
        });
        // get top oldest records
        int endIndex = replicas.size() - maxNumOfCopies + 1;
        obsoleteReplicas.addAll(replicas.subList(0, endIndex));
    }
    return obsoleteReplicas;
}
Also used : ScheduledEvent(com.emc.storageos.db.client.model.uimodels.ScheduledEvent) ArrayList(java.util.ArrayList) OrderCreateParam(com.emc.vipr.model.catalog.OrderCreateParam) RetainedReplica(com.emc.storageos.db.client.model.uimodels.RetainedReplica) NamedElement(com.emc.storageos.db.client.constraint.NamedElementQueryResultList.NamedElement) IOException(java.io.IOException)

Example 3 with OrderCreateParam

use of com.emc.vipr.model.catalog.OrderCreateParam in project coprhd-controller by CoprHD.

the class ViPRService method isRetentionRequired.

/**
 * Check if it is a recurrent order and retention policy is defined
 *
 * @return true if retention policy defined
 */
protected boolean isRetentionRequired() {
    ScheduledEvent event = ExecutionUtils.currentContext().getScheduledEvent();
    if (event == null) {
        return false;
    }
    try {
        OrderCreateParam param = OrderCreateParam.deserialize(org.apache.commons.codec.binary.Base64.decodeBase64(event.getOrderCreationParam().getBytes(UTF_8)));
        String additionalScheduleInfo = param.getAdditionalScheduleInfo();
        if (additionalScheduleInfo == null) {
            return false;
        }
        Integer.parseInt(additionalScheduleInfo);
    } catch (Exception ex) {
        error("Unexpected exception when checking scheduler retention", ex);
        return false;
    }
    return true;
}
Also used : ScheduledEvent(com.emc.storageos.db.client.model.uimodels.ScheduledEvent) OrderCreateParam(com.emc.vipr.model.catalog.OrderCreateParam) IOException(java.io.IOException)

Example 4 with OrderCreateParam

use of com.emc.vipr.model.catalog.OrderCreateParam in project coprhd-controller by CoprHD.

the class OrderService method scheduleReoccurenceOrders.

private void scheduleReoccurenceOrders() throws Exception {
    lock = coordinatorClient.getLock(LOCK_NAME);
    try {
        lock.acquire();
        List<ScheduledEvent> scheduledEvents = dataManager.getAllReoccurrenceEvents();
        for (ScheduledEvent event : scheduledEvents) {
            if (event.getEventStatus() != ScheduledEventStatus.APPROVED) {
                log.debug("Skipping event {} which is not in APPROVED status.", event.getId());
                continue;
            }
            URI orderId = event.getLatestOrderId();
            Order order = getOrderById(orderId, false);
            if (!(OrderStatus.valueOf(order.getOrderStatus()).equals(OrderStatus.SUCCESS) || OrderStatus.valueOf(order.getOrderStatus()).equals(OrderStatus.PARTIAL_SUCCESS) || OrderStatus.valueOf(order.getOrderStatus()).equals(OrderStatus.ERROR) || OrderStatus.valueOf(order.getOrderStatus()).equals(OrderStatus.CANCELLED))) {
                log.debug("Skipping event {} whose latest order {} is not finished yet.", event.getId(), order.getId());
                continue;
            }
            log.info("Trying to schedule a new order for event {} : {}", event.getId(), ScheduleInfo.deserialize(org.apache.commons.codec.binary.Base64.decodeBase64(event.getScheduleInfo().getBytes(UTF_8))).toString());
            StorageOSUser user = StorageOSUser.deserialize(org.apache.commons.codec.binary.Base64.decodeBase64(event.getStorageOSUser().getBytes(UTF_8)));
            OrderCreateParam createParam = OrderCreateParam.deserialize(org.apache.commons.codec.binary.Base64.decodeBase64(event.getOrderCreationParam().getBytes(UTF_8)));
            ScheduleInfo scheduleInfo = ScheduleInfo.deserialize(org.apache.commons.codec.binary.Base64.decodeBase64(event.getScheduleInfo().getBytes(UTF_8)));
            Calendar nextScheduledTime = ScheduleTimeHelper.getNextScheduledTime(order.getScheduledTime(), scheduleInfo);
            int retry = 0;
            if (order.getExecutionWindowId() != null && !order.getExecutionWindowId().getURI().equals(ExecutionWindow.NEXT)) {
                ExecutionWindow window = client.executionWindows().findById(order.getExecutionWindowId().getURI());
                if (window != null) {
                    ExecutionWindowHelper helper = new ExecutionWindowHelper(window);
                    if (nextScheduledTime != null && !helper.isActive(nextScheduledTime)) {
                        log.warn("Execution window {} might be changed after the event is scheduled.", order.getExecutionWindowId().getURI());
                        log.warn("Otherwise it is a HOURLY scheduled event");
                        do {
                            nextScheduledTime = ScheduleTimeHelper.getNextScheduledTime(nextScheduledTime, scheduleInfo);
                            retry++;
                        } while (nextScheduledTime != null && !helper.isActive(nextScheduledTime) && retry < ScheduleTimeHelper.SCHEDULE_TIME_RETRY_THRESHOLD);
                        if (retry == ScheduleTimeHelper.SCHEDULE_TIME_RETRY_THRESHOLD) {
                            log.error("Failed to find next scheduled time that match with {}", order.getExecutionWindowId().getURI());
                            nextScheduledTime = null;
                        }
                    }
                } else {
                    log.error("Execution window {} does not exist.", order.getExecutionWindowId().getURI());
                }
            }
            if (nextScheduledTime == null) {
                log.info("Scheduled event {} should be set finished.", event.getId());
                event.setEventStatus(ScheduledEventStatus.FINISHED);
            } else {
                createParam.setScheduledTime(ScheduleTimeHelper.convertCalendarToStr(nextScheduledTime));
                order = createNewOrder(user, uri(order.getTenant()), createParam);
                orderManager.processOrder(order);
                event.setLatestOrderId(order.getId());
                log.info("Scheduled an new order {} for event {} ...", order.getId(), event.getId());
            }
            client.save(event);
        }
    } catch (Exception e) {
        log.error("Failed to schedule next orders", e);
    } finally {
        try {
            lock.release();
        } catch (Exception e) {
            log.error("Error releasing order scheduler lock", e);
        }
    }
}
Also used : Order(com.emc.storageos.db.client.model.uimodels.Order) ScheduledEvent(com.emc.storageos.db.client.model.uimodels.ScheduledEvent) ExecutionWindowHelper(com.emc.storageos.db.client.util.ExecutionWindowHelper) ExecutionWindow(com.emc.storageos.db.client.model.uimodels.ExecutionWindow) StorageOSUser(com.emc.storageos.security.authentication.StorageOSUser) Calendar(java.util.Calendar) OrderCreateParam(com.emc.vipr.model.catalog.OrderCreateParam) URI(java.net.URI) ScheduleInfo(com.emc.vipr.model.catalog.ScheduleInfo) TimeSeriesConstraint(com.emc.storageos.db.client.constraint.TimeSeriesConstraint) 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 5 with OrderCreateParam

use of com.emc.vipr.model.catalog.OrderCreateParam in project coprhd-controller by CoprHD.

the class CatalogApi method createAndValidateOrder.

private static OrderCreateParam createAndValidateOrder(String serviceId) {
    CatalogServiceRestRep service = CatalogServiceUtils.getCatalogService(uri(serviceId));
    ServiceDescriptorRestRep descriptor = service.getServiceDescriptor();
    // Filter out actual Service Parameters
    Map<String, String> parameters = parseParameters(service, descriptor);
    if (Validation.hasErrors()) {
        response.status = HttpStatus.SC_BAD_REQUEST;
        renderApi(getValidationErrors());
    }
    // Create request and perform selection
    OrderCreateParam order = createOrder(service, descriptor, parameters);
    return order;
}
Also used : ServiceDescriptorRestRep(com.emc.vipr.model.catalog.ServiceDescriptorRestRep) OrderCreateParam(com.emc.vipr.model.catalog.OrderCreateParam) CatalogServiceRestRep(com.emc.vipr.model.catalog.CatalogServiceRestRep)

Aggregations

OrderCreateParam (com.emc.vipr.model.catalog.OrderCreateParam)7 ScheduledEvent (com.emc.storageos.db.client.model.uimodels.ScheduledEvent)3 OrderRestRep (com.emc.vipr.model.catalog.OrderRestRep)2 IOException (java.io.IOException)2 NamedElement (com.emc.storageos.db.client.constraint.NamedElementQueryResultList.NamedElement)1 TimeSeriesConstraint (com.emc.storageos.db.client.constraint.TimeSeriesConstraint)1 ExecutionWindow (com.emc.storageos.db.client.model.uimodels.ExecutionWindow)1 Order (com.emc.storageos.db.client.model.uimodels.Order)1 RetainedReplica (com.emc.storageos.db.client.model.uimodels.RetainedReplica)1 ExecutionWindowHelper (com.emc.storageos.db.client.util.ExecutionWindowHelper)1 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)1 StorageOSUser (com.emc.storageos.security.authentication.StorageOSUser)1 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)1 CatalogServiceFieldRestRep (com.emc.vipr.model.catalog.CatalogServiceFieldRestRep)1 CatalogServiceRestRep (com.emc.vipr.model.catalog.CatalogServiceRestRep)1 Parameter (com.emc.vipr.model.catalog.Parameter)1 ScheduleInfo (com.emc.vipr.model.catalog.ScheduleInfo)1 ScheduledEventCreateParam (com.emc.vipr.model.catalog.ScheduledEventCreateParam)1 ScheduledEventRestRep (com.emc.vipr.model.catalog.ScheduledEventRestRep)1 ServiceDescriptorRestRep (com.emc.vipr.model.catalog.ServiceDescriptorRestRep)1