Search in sources :

Example 1 with ScheduledEventCreateParam

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

the class OrderExecution method createScheduledOrder.

protected static ScheduledEventCreateParam createScheduledOrder(OrderCreateParam orderParam) {
    if (!isSchedulerEnabled()) {
        return null;
    }
    ScheduleInfo scheduleInfo = new ScheduleInfo();
    String cycleFrequency = params.get("scheduler.cycleFrequency");
    if (cycleFrequency != null) {
        scheduleInfo.setCycleFrequency(Integer.parseInt(cycleFrequency));
    } else {
        scheduleInfo.setCycleFrequency(1);
    }
    String cycleType = params.get("scheduler.cycleType");
    if (cycleType != null) {
        ScheduleCycleType cycleTypeEnum = ScheduleCycleType.valueOf(cycleType);
        scheduleInfo.setCycleType(cycleTypeEnum);
        List<String> sectionsInCycleList = Lists.newArrayList();
        if (cycleTypeEnum == ScheduleCycleType.WEEKLY) {
            String sectionsInCycle = params.get("scheduler.dayOfWeek");
            sectionsInCycleList.add(sectionsInCycle);
        } else if (cycleTypeEnum == ScheduleCycleType.MONTHLY) {
            String sectionsInCycle = params.get("scheduler.dayOfMonth");
            sectionsInCycleList.add(sectionsInCycle);
        }
        scheduleInfo.setSectionsInCycle(sectionsInCycleList);
    } else {
        scheduleInfo.setCycleType(ScheduleCycleType.DAILY);
    }
    String currentTimezoneOffsetInMins = params.get("scheduler.currentTimezoneOffsetInMins");
    Integer timezoneOffset = Integer.parseInt(currentTimezoneOffsetInMins);
    String startDate = params.get("scheduler.startDate");
    String startTime = params.get("scheduler.startTime");
    String isoDateTimeStr = String.format("%sT%s", startDate, startTime);
    DateTime startDateTime = DateTime.parse(isoDateTimeStr, ISODateTimeFormat.localDateOptionalTimeParser().withZone(TimeUtils.getLocalTimeZone(timezoneOffset)));
    startDateTime = startDateTime.withZone(DateTimeZone.UTC);
    scheduleInfo.setHourOfDay(startDateTime.getHourOfDay());
    scheduleInfo.setMinuteOfHour(startDateTime.getMinuteOfHour());
    scheduleInfo.setStartDate(String.format("%d-%02d-%02d", startDateTime.getYear(), startDateTime.getMonthOfYear(), startDateTime.getDayOfMonth()));
    String recurrence = params.get("scheduler.recurrence");
    int recurrenceNum = 1;
    if (recurrence != null) {
        recurrenceNum = Integer.parseInt(recurrence);
        if (recurrenceNum == -1) {
            String range = params.get("scheduler.rangeOfRecurrence");
            recurrenceNum = Integer.parseInt(range);
        }
    }
    scheduleInfo.setReoccurrence(recurrenceNum);
    /*
         * if reoccurence number large than 1, we must make sure the name contains patten {datetime},
         * with the pattern in the name, vipr know how to generate dynamic name for each snaphot/fullcopy.
         */
    if (recurrenceNum != 1) {
        List<Parameter> parameters = orderParam.getParameters();
        CatalogServiceRestRep service = CatalogServiceUtils.getCatalogService(orderParam.getCatalogService());
        Logger.info("creating order with parameter for: " + service.getBaseService());
        String nameToValidate = SCHEDULED_SERVICE.get(service.getBaseService());
        for (Parameter parameter : parameters) {
            if (parameter.getLabel().equals(nameToValidate) && !parameter.getValue().contains("{datetime}")) {
                Validation.addError(nameToValidate, "need to add patten '{datetime}' in the name for reoccuring scheduled operation");
            }
            Logger.info(parameter.getLabel() + " = " + parameter.getValue() + ", " + parameter.getFriendlyLabel() + " = " + parameter.getFriendlyValue());
        }
    }
    String maxNumOfCopies = params.get("scheduler.maxNumOfCopies");
    if (maxNumOfCopies != null) {
        orderParam.setAdditionalScheduleInfo(maxNumOfCopies);
    }
    scheduleInfo.setDurationLength(3600);
    ScheduledEventCreateParam eventParam = new ScheduledEventCreateParam();
    eventParam.setOrderCreateParam(orderParam);
    eventParam.setScheduleInfo(scheduleInfo);
    return eventParam;
}
Also used : Parameter(com.emc.vipr.model.catalog.Parameter) CatalogServiceRestRep(com.emc.vipr.model.catalog.CatalogServiceRestRep) ScheduledEventCreateParam(com.emc.vipr.model.catalog.ScheduledEventCreateParam) ScheduleInfo(com.emc.vipr.model.catalog.ScheduleInfo) DateTime(org.joda.time.DateTime) ScheduleCycleType(com.emc.vipr.model.catalog.ScheduleCycleType)

Example 2 with ScheduledEventCreateParam

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

the class Orders method submitOrder.

public static void submitOrder(String serviceId) {
    checkAuthenticity();
    OrderCreateParam order = createAndValidateOrder(serviceId);
    String status = null;
    String orderId = null;
    try {
        if (isSchedulerEnabled()) {
            ScheduledEventCreateParam event = createScheduledOrder(order);
            if (Validation.hasErrors()) {
                Validation.keep();
                Common.flashParamsExcept("json", "body");
                Services.showForm(serviceId);
            }
            ScheduledEventRestRep submittedEvent = getCatalogClient().orders().submitScheduledEvent(event);
            status = submittedEvent.getEventStatus();
            orderId = submittedEvent.getLatestOrderId().toString();
        } else {
            OrderRestRep submittedOrder = getCatalogClient().orders().submit(order);
            status = submittedOrder.getOrderStatus();
            orderId = submittedOrder.getId().toString();
        }
    } catch (Exception e) {
        Logger.error(e, MessagesUtils.get("order.submitFailedWithDetail", e.getMessage()));
        flash.error(MessagesUtils.get("order.submitFailedWithDetail", e.getMessage()));
        Common.handleError();
    }
    if (OrderRestRep.ERROR.equalsIgnoreCase(status)) {
        flash.error(MessagesUtils.get("order.submitFailed"));
    } else {
        flash.success(MessagesUtils.get("order.submitSuccess"));
    }
    Http.Cookie cookie = request.cookies.get(RECENT_ACTIVITIES);
    response.setCookie(RECENT_ACTIVITIES, updateRecentActivitiesCookie(cookie, serviceId));
    receipt(orderId);
}
Also used : OrderCreateParam(com.emc.vipr.model.catalog.OrderCreateParam) OrderRestRep(com.emc.vipr.model.catalog.OrderRestRep) Http(play.mvc.Http) ScheduledEventCreateParam(com.emc.vipr.model.catalog.ScheduledEventCreateParam) ScheduledEventRestRep(com.emc.vipr.model.catalog.ScheduledEventRestRep) FlashException(controllers.util.FlashException)

Aggregations

ScheduledEventCreateParam (com.emc.vipr.model.catalog.ScheduledEventCreateParam)2 CatalogServiceRestRep (com.emc.vipr.model.catalog.CatalogServiceRestRep)1 OrderCreateParam (com.emc.vipr.model.catalog.OrderCreateParam)1 OrderRestRep (com.emc.vipr.model.catalog.OrderRestRep)1 Parameter (com.emc.vipr.model.catalog.Parameter)1 ScheduleCycleType (com.emc.vipr.model.catalog.ScheduleCycleType)1 ScheduleInfo (com.emc.vipr.model.catalog.ScheduleInfo)1 ScheduledEventRestRep (com.emc.vipr.model.catalog.ScheduledEventRestRep)1 FlashException (controllers.util.FlashException)1 DateTime (org.joda.time.DateTime)1 Http (play.mvc.Http)1