Search in sources :

Example 16 with ExecutionWindow

use of com.emc.storageos.db.client.model.uimodels.ExecutionWindow in project coprhd-controller by CoprHD.

the class ExecutionWindowService method getExecutionWindowById.

private ExecutionWindow getExecutionWindowById(URI id, boolean checkInactive) {
    ExecutionWindow executionWindow = executionWindowManager.getExecutionWindowById(id);
    ArgValidator.checkEntity(executionWindow, id, isIdEmbeddedInURL(id), checkInactive);
    return executionWindow;
}
Also used : ExecutionWindow(com.emc.storageos.db.client.model.uimodels.ExecutionWindow)

Example 17 with ExecutionWindow

use of com.emc.storageos.db.client.model.uimodels.ExecutionWindow 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 18 with ExecutionWindow

use of com.emc.storageos.db.client.model.uimodels.ExecutionWindow in project coprhd-controller by CoprHD.

the class ExecutionWindowMapper method createNewObject.

public static ExecutionWindow createNewObject(ExecutionWindowCreateParam param) {
    ExecutionWindow newObject = new ExecutionWindow();
    newObject.setTenant(asString(param.getTenant()));
    updateObject(newObject, param);
    return newObject;
}
Also used : ExecutionWindow(com.emc.storageos.db.client.model.uimodels.ExecutionWindow)

Example 19 with ExecutionWindow

use of com.emc.storageos.db.client.model.uimodels.ExecutionWindow in project coprhd-controller by CoprHD.

the class ExecutionWindowTest method create.

private static ExecutionWindow create(String tenant, String label) {
    ExecutionWindow model = new ExecutionWindow();
    model.setLabel(label);
    model.setHourOfDayInUTC(11);
    model.setMinuteOfHourInUTC(53);
    Integer length = new Integer(4);
    model.setExecutionWindowLength(length);
    model.setExecutionWindowLengthType(ExecutionWindowLengthType.HOURS.name());
    model.setExecutionWindowType(ExecutionWindowType.DAILY.name());
    model.setDayOfWeek(Calendar.TUESDAY);
    model.setDayOfMonth(12);
    model.setTenant(tenant);
    return model;
}
Also used : ExecutionWindow(com.emc.storageos.db.client.model.uimodels.ExecutionWindow)

Example 20 with ExecutionWindow

use of com.emc.storageos.db.client.model.uimodels.ExecutionWindow in project coprhd-controller by CoprHD.

the class ExecutionWindowTest method testPersistObject.

@Test
public void testPersistObject() throws Exception {
    _logger.info("Starting persist ExecutionWindow test");
    ExecutionWindow model = new ExecutionWindow();
    model.setLabel("foo");
    Integer hour = new Integer(11);
    Integer minute = new Integer(53);
    model.setHourOfDayInUTC(hour);
    model.setMinuteOfHourInUTC(minute);
    Integer length = new Integer(4);
    model.setExecutionWindowLength(length);
    model.setExecutionWindowLengthType(ExecutionWindowLengthType.HOURS.name());
    model.setExecutionWindowType(ExecutionWindowType.DAILY.name());
    model.setDayOfWeek(Calendar.TUESDAY);
    model.setDayOfMonth(12);
    model.setTenant(DEFAULT_TENANT);
    save(model);
    model = findById(model.getId());
    Assert.assertNotNull(model);
    Assert.assertEquals("foo", model.getLabel());
    Assert.assertEquals(hour, model.getHourOfDayInUTC());
    Assert.assertEquals(minute, model.getMinuteOfHourInUTC());
    Assert.assertEquals(length, model.getExecutionWindowLength());
    Assert.assertEquals(ExecutionWindowLengthType.HOURS.name(), model.getExecutionWindowLengthType());
    Assert.assertEquals(ExecutionWindowType.DAILY.name(), model.getExecutionWindowType());
    Assert.assertEquals(new Integer(Calendar.TUESDAY), model.getDayOfWeek());
    Assert.assertEquals(new Integer(12), model.getDayOfMonth());
    Assert.assertEquals(DEFAULT_TENANT, model.getTenant());
}
Also used : ExecutionWindow(com.emc.storageos.db.client.model.uimodels.ExecutionWindow) BaseModelTest(com.emc.sa.model.BaseModelTest) Test(org.junit.Test)

Aggregations

ExecutionWindow (com.emc.storageos.db.client.model.uimodels.ExecutionWindow)25 ExecutionWindowHelper (com.emc.storageos.db.client.util.ExecutionWindowHelper)11 Test (org.junit.Test)11 Calendar (java.util.Calendar)10 StorageOSUser (com.emc.storageos.security.authentication.StorageOSUser)4 Path (javax.ws.rs.Path)4 Produces (javax.ws.rs.Produces)4 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)3 BaseModelTest (com.emc.sa.model.BaseModelTest)2 Order (com.emc.storageos.db.client.model.uimodels.Order)2 URI (java.net.URI)2 Consumes (javax.ws.rs.Consumes)2 POST (javax.ws.rs.POST)2 ModelClient (com.emc.sa.model.dao.ModelClient)1 DbClient (com.emc.storageos.db.client.DbClient)1 TimeSeriesConstraint (com.emc.storageos.db.client.constraint.TimeSeriesConstraint)1 NamedURI (com.emc.storageos.db.client.model.NamedURI)1 ScheduledEvent (com.emc.storageos.db.client.model.uimodels.ScheduledEvent)1 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)1 NamedRelatedResourceRep (com.emc.storageos.model.NamedRelatedResourceRep)1