Search in sources :

Example 1 with ExecutionWindow

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

the class OrderScheduleTimeCallback method process.

@Override
public void process() throws MigrationCallbackException {
    log.info("Handle Order schedule time ...");
    DbClient dbClient = getDbClient();
    List<URI> orders = dbClient.queryByType(Order.class, true);
    for (URI uri : orders) {
        Order order = dbClient.queryObject(Order.class, uri);
        if (order == null)
            continue;
        if (order.getScheduledEventId() == null) {
            if (order.getExecutionWindowId() == null || order.getExecutionWindowId().getURI().equals(ExecutionWindow.NEXT)) {
                Calendar scheduleTime = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
                scheduleTime.setTime(order.getLastUpdated());
                order.setExecutionWindowId(new NamedURI(ExecutionWindow.NEXT, "NEXT"));
                order.setScheduledTime(scheduleTime);
            } else {
                // For original orders, set schedule time to
                // either 1) the next execution window starting time
                // or     2) the current time if it is in current execution window
                ExecutionWindow executionWindow = dbClient.queryObject(ExecutionWindow.class, order.getExecutionWindowId().getURI());
                if (executionWindow == null)
                    continue;
                ExecutionWindowHelper helper = new ExecutionWindowHelper(executionWindow);
                order.setScheduledTime(helper.getScheduledTime());
            }
            dbClient.updateObject(order);
        }
    }
    return;
}
Also used : Order(com.emc.storageos.db.client.model.uimodels.Order) ExecutionWindowHelper(com.emc.storageos.db.client.util.ExecutionWindowHelper) DbClient(com.emc.storageos.db.client.DbClient) NamedURI(com.emc.storageos.db.client.model.NamedURI) ExecutionWindow(com.emc.storageos.db.client.model.uimodels.ExecutionWindow) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI)

Example 2 with ExecutionWindow

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

the class ExecutionWindowHelperTest method createWeeklyWindow.

private static ExecutionWindow createWeeklyWindow(int dayOfWeek, int hour, int minute) {
    // Convert from Calendar day of week to JODA day of week
    if (dayOfWeek == 1) {
        dayOfWeek = 7;
    } else {
        dayOfWeek--;
    }
    ExecutionWindow window = new ExecutionWindow();
    window.setExecutionWindowType(ExecutionWindowType.WEEKLY.name());
    window.setHourOfDayInUTC(hour);
    window.setMinuteOfHourInUTC(minute);
    window.setDayOfWeek(dayOfWeek);
    return window;
}
Also used : ExecutionWindow(com.emc.storageos.db.client.model.uimodels.ExecutionWindow)

Example 3 with ExecutionWindow

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

the class ExecutionWindowHelperTest method testWeeklyDuringTime.

@Test
public void testWeeklyDuringTime() {
    // Weekly on Sunday at 1:15am
    ExecutionWindow window = createWeeklyWindow(Calendar.SUNDAY, 1, 15);
    setLengthInHours(window, 1);
    ExecutionWindowHelper helper = new ExecutionWindowHelper(window);
    // Start of the window
    Calendar duringTime = getDateTimeUTC(2013, Calendar.MAY, 5, 1, 15, 0);
    assertDateTime(helper.calculateNext(duringTime), 2013, Calendar.MAY, 12, 1, 15, 0);
    assertDateTime(helper.calculateCurrentOrNext(duringTime), 2013, Calendar.MAY, 5, 1, 15, 0);
    Assert.assertTrue(helper.isActive(duringTime));
    // One minute after start
    duringTime = getDateTimeUTC(2013, Calendar.MAY, 5, 1, 16, 0);
    assertDateTime(helper.calculateNext(duringTime), 2013, Calendar.MAY, 12, 1, 15, 0);
    assertDateTime(helper.calculateCurrentOrNext(duringTime), 2013, Calendar.MAY, 5, 1, 15, 0);
    Assert.assertTrue(helper.isActive(duringTime));
    // One minute before end
    duringTime = getDateTimeUTC(2013, Calendar.MAY, 5, 2, 14, 0);
    assertDateTime(helper.calculateNext(duringTime), 2013, Calendar.MAY, 12, 1, 15, 0);
    assertDateTime(helper.calculateCurrentOrNext(duringTime), 2013, Calendar.MAY, 5, 1, 15, 0);
    Assert.assertTrue(helper.isActive(duringTime));
    // End of the window
    duringTime = getDateTimeUTC(2013, Calendar.MAY, 5, 2, 15, 0);
    assertDateTime(helper.calculateNext(duringTime), 2013, Calendar.MAY, 12, 1, 15, 0);
    assertDateTime(helper.calculateCurrentOrNext(duringTime), 2013, Calendar.MAY, 12, 1, 15, 0);
    Assert.assertFalse(helper.isActive(duringTime));
}
Also used : ExecutionWindowHelper(com.emc.storageos.db.client.util.ExecutionWindowHelper) ExecutionWindow(com.emc.storageos.db.client.model.uimodels.ExecutionWindow) Calendar(java.util.Calendar) Test(org.junit.Test)

Example 4 with ExecutionWindow

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

the class ExecutionWindowHelperTest method testDailyWindowBeforeTime.

@Test
public void testDailyWindowBeforeTime() {
    // Daily at 1:15am
    ExecutionWindow window = createDailyWindow(1, 15);
    setLengthInHours(window, 1);
    ExecutionWindowHelper helper = new ExecutionWindowHelper(window);
    // before, different hour
    Calendar beforeTime = getDateTimeUTC(2000, Calendar.JANUARY, 1, 0, 10, 0);
    // Should be the same date
    assertDateTime(helper.calculateNext(beforeTime), 2000, Calendar.JANUARY, 1, 1, 15, 0);
    assertDateTime(helper.calculateCurrentOrNext(beforeTime), 2000, Calendar.JANUARY, 1, 1, 15, 0);
    // a few minutes before, the same hour
    beforeTime = getDateTimeUTC(2000, Calendar.JANUARY, 1, 1, 10, 0);
    // Should be the same date
    assertDateTime(helper.calculateNext(beforeTime), 2000, Calendar.JANUARY, 1, 1, 15, 0);
    assertDateTime(helper.calculateCurrentOrNext(beforeTime), 2000, Calendar.JANUARY, 1, 1, 15, 0);
}
Also used : ExecutionWindowHelper(com.emc.storageos.db.client.util.ExecutionWindowHelper) ExecutionWindow(com.emc.storageos.db.client.model.uimodels.ExecutionWindow) Calendar(java.util.Calendar) Test(org.junit.Test)

Example 5 with ExecutionWindow

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

the class ExecutionWindowHelperTest method testMonthlyNearEndOfMonth.

@Test
public void testMonthlyNearEndOfMonth() {
    // Monthly on the 31st at 1:15am
    ExecutionWindow window = createMonthlyWindow(31, 1, 15);
    setLengthInHours(window, 1);
    ExecutionWindowHelper helper = new ExecutionWindowHelper(window);
    // February
    Calendar february = getDateTimeUTC(2013, Calendar.FEBRUARY, 1, 0, 0, 0);
    assertDateTime(helper.calculateNext(february), 2013, Calendar.FEBRUARY, 28, 1, 15, 0);
    assertDateTime(helper.calculateCurrentOrNext(february), 2013, Calendar.FEBRUARY, 28, 1, 15, 0);
    // March
    Calendar march = getDateTimeUTC(2013, Calendar.MARCH, 1, 0, 0, 0);
    assertDateTime(helper.calculateNext(march), 2013, Calendar.MARCH, 31, 1, 15, 0);
    assertDateTime(helper.calculateCurrentOrNext(march), 2013, Calendar.MARCH, 31, 1, 15, 0);
    // April
    Calendar april = getDateTimeUTC(2013, Calendar.APRIL, 1, 0, 0, 0);
    assertDateTime(helper.calculateNext(april), 2013, Calendar.APRIL, 30, 1, 15, 0);
    assertDateTime(helper.calculateCurrentOrNext(april), 2013, Calendar.APRIL, 30, 1, 15, 0);
}
Also used : ExecutionWindowHelper(com.emc.storageos.db.client.util.ExecutionWindowHelper) ExecutionWindow(com.emc.storageos.db.client.model.uimodels.ExecutionWindow) Calendar(java.util.Calendar) 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