Search in sources :

Example 11 with ExecutionWindowHelper

use of com.emc.storageos.db.client.util.ExecutionWindowHelper in project coprhd-controller by CoprHD.

the class SchedulerDataManager method isExpiredOrder.

private boolean isExpiredOrder(Order order, ExecutionWindow window) {
    ExecutionWindowHelper windowHelper = new ExecutionWindowHelper(window);
    if (windowHelper.isExpired(order.getScheduledTime())) {
        order.setOrderStatus(OrderStatus.ERROR.name());
        LOG.info("order {} has expired.", order.getId());
        models.save(order);
        return true;
    }
    return false;
}
Also used : ExecutionWindowHelper(com.emc.storageos.db.client.util.ExecutionWindowHelper)

Example 12 with ExecutionWindowHelper

use of com.emc.storageos.db.client.util.ExecutionWindowHelper in project coprhd-controller by CoprHD.

the class ExecutionWindowHelperTest method testDailySpanningMidnight.

@Test
public void testDailySpanningMidnight() {
    // Daily at 11:30pm
    ExecutionWindow window = createDailyWindow(23, 30);
    setLengthInHours(window, 1);
    ExecutionWindowHelper helper = new ExecutionWindowHelper(window);
    Calendar beforeTime = getDateTimeUTC(2013, Calendar.MAY, 6, 23, 0, 0);
    assertDateTime(helper.calculateNext(beforeTime), 2013, Calendar.MAY, 6, 23, 30, 0);
    assertDateTime(helper.calculateCurrentOrNext(beforeTime), 2013, Calendar.MAY, 6, 23, 30, 0);
    Calendar duringTime = getDateTimeUTC(2013, Calendar.MAY, 6, 23, 45, 0);
    assertDateTime(helper.calculateNext(duringTime), 2013, Calendar.MAY, 7, 23, 30, 0);
    assertDateTime(helper.calculateCurrentOrNext(duringTime), 2013, Calendar.MAY, 6, 23, 30, 0);
    duringTime = getDateTimeUTC(2013, Calendar.MAY, 7, 0, 15, 0);
    assertDateTime(helper.calculateNext(duringTime), 2013, Calendar.MAY, 7, 23, 30, 0);
    assertDateTime(helper.calculateCurrentOrNext(duringTime), 2013, Calendar.MAY, 6, 23, 30, 0);
    Calendar afterTime = getDateTimeUTC(2013, Calendar.MAY, 7, 1, 0, 0);
    assertDateTime(helper.calculateNext(afterTime), 2013, Calendar.MAY, 7, 23, 30, 0);
    assertDateTime(helper.calculateCurrentOrNext(afterTime), 2013, Calendar.MAY, 7, 23, 30, 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 13 with ExecutionWindowHelper

use of com.emc.storageos.db.client.util.ExecutionWindowHelper in project coprhd-controller by CoprHD.

the class ExecutionWindowHelperTest method testWeeklyAfterTime.

@Test
public void testWeeklyAfterTime() {
    // Weekly on Sunday at 1:15am
    ExecutionWindow window = createWeeklyWindow(Calendar.SUNDAY, 1, 15);
    setLengthInHours(window, 1);
    ExecutionWindowHelper helper = new ExecutionWindowHelper(window);
    Calendar afterTime = getDateTimeUTC(2013, Calendar.MAY, 5, 3, 15, 0);
    assertDateTime(helper.calculateNext(afterTime), 2013, Calendar.MAY, 12, 1, 15, 0);
    assertDateTime(helper.calculateCurrentOrNext(afterTime), 2013, Calendar.MAY, 12, 1, 15, 0);
    afterTime = getDateTimeUTC(2013, Calendar.MAY, 6, 1, 10, 0);
    assertDateTime(helper.calculateNext(afterTime), 2013, Calendar.MAY, 12, 1, 15, 0);
    assertDateTime(helper.calculateCurrentOrNext(afterTime), 2013, Calendar.MAY, 12, 1, 15, 0);
    afterTime = getDateTimeUTC(2013, Calendar.MAY, 7, 1, 10, 0);
    assertDateTime(helper.calculateNext(afterTime), 2013, Calendar.MAY, 12, 1, 15, 0);
    assertDateTime(helper.calculateCurrentOrNext(afterTime), 2013, Calendar.MAY, 12, 1, 15, 0);
    afterTime = getDateTimeUTC(2013, Calendar.MAY, 8, 1, 10, 0);
    assertDateTime(helper.calculateNext(afterTime), 2013, Calendar.MAY, 12, 1, 15, 0);
    assertDateTime(helper.calculateCurrentOrNext(afterTime), 2013, Calendar.MAY, 12, 1, 15, 0);
    afterTime = getDateTimeUTC(2013, Calendar.MAY, 9, 1, 10, 0);
    assertDateTime(helper.calculateNext(afterTime), 2013, Calendar.MAY, 12, 1, 15, 0);
    assertDateTime(helper.calculateCurrentOrNext(afterTime), 2013, Calendar.MAY, 12, 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 14 with ExecutionWindowHelper

use of com.emc.storageos.db.client.util.ExecutionWindowHelper in project coprhd-controller by CoprHD.

the class ExecutionWindowHelperTest method testDailyWindowAfterTime.

@Test
public void testDailyWindowAfterTime() {
    // Daily at 1:15am
    ExecutionWindow window = createDailyWindow(1, 15);
    setLengthInHours(window, 1);
    ExecutionWindowHelper helper = new ExecutionWindowHelper(window);
    // Right after the window ends
    Calendar afterTime = getDateTimeUTC(2000, Calendar.FEBRUARY, 5, 2, 16, 0);
    assertDateTime(helper.calculateNext(afterTime), 2000, Calendar.FEBRUARY, 6, 1, 15, 0);
    assertDateTime(helper.calculateCurrentOrNext(afterTime), 2000, Calendar.FEBRUARY, 6, 1, 15, 0);
    // Should be the next day
    afterTime = getDateTimeUTC(2000, Calendar.FEBRUARY, 5, 10, 16, 0);
    assertDateTime(helper.calculateNext(afterTime), 2000, Calendar.FEBRUARY, 6, 1, 15, 0);
    assertDateTime(helper.calculateCurrentOrNext(afterTime), 2000, Calendar.FEBRUARY, 6, 1, 15, 0);
    // Last day of the month, check for rollover
    afterTime = getDateTimeUTC(2000, Calendar.JANUARY, 31, 5, 0, 0);
    assertDateTime(helper.calculateNext(afterTime), 2000, Calendar.FEBRUARY, 1, 1, 15, 0);
    assertDateTime(helper.calculateCurrentOrNext(afterTime), 2000, Calendar.FEBRUARY, 1, 1, 15, 0);
    // Last day of the year, check for rollover
    afterTime = getDateTimeUTC(2000, Calendar.DECEMBER, 31, 5, 0, 0);
    assertDateTime(helper.calculateNext(afterTime), 2001, Calendar.JANUARY, 1, 1, 15, 0);
    assertDateTime(helper.calculateCurrentOrNext(afterTime), 2001, 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 15 with ExecutionWindowHelper

use of com.emc.storageos.db.client.util.ExecutionWindowHelper in project coprhd-controller by CoprHD.

the class ExecutionWindowHelperTest method testDailyWindowDuringTime.

@Test
public void testDailyWindowDuringTime() {
    // Daily at 1:15am
    ExecutionWindow window = createDailyWindow(1, 15);
    setLengthInHours(window, 1);
    ExecutionWindowHelper helper = new ExecutionWindowHelper(window);
    // Right at the start of the window
    Calendar duringTime = getDateTimeUTC(2000, Calendar.JANUARY, 10, 1, 15, 0);
    // Next will be the day after
    assertDateTime(helper.calculateNext(duringTime), 2000, Calendar.JANUARY, 11, 1, 15, 0);
    // Current or next will be today
    assertDateTime(helper.calculateCurrentOrNext(duringTime), 2000, Calendar.JANUARY, 10, 1, 15, 0);
    Assert.assertTrue(helper.isActive(duringTime));
    // One minute after the start of the window
    duringTime = getDateTimeUTC(2000, Calendar.JANUARY, 10, 1, 16, 0);
    // Next will be the day after
    assertDateTime(helper.calculateNext(duringTime), 2000, Calendar.JANUARY, 11, 1, 15, 0);
    // Current or next will be today
    assertDateTime(helper.calculateCurrentOrNext(duringTime), 2000, Calendar.JANUARY, 10, 1, 15, 0);
    Assert.assertTrue(helper.isActive(duringTime));
    // One minute before the end of the window
    duringTime = getDateTimeUTC(2000, Calendar.JANUARY, 10, 2, 14, 0);
    // Next will be the day after
    assertDateTime(helper.calculateNext(duringTime), 2000, Calendar.JANUARY, 11, 1, 15, 0);
    // Current or next will be today
    assertDateTime(helper.calculateCurrentOrNext(duringTime), 2000, Calendar.JANUARY, 10, 1, 15, 0);
    Assert.assertTrue(helper.isActive(duringTime));
    // Right at the end of the window
    duringTime = getDateTimeUTC(2000, Calendar.JANUARY, 10, 2, 15, 0);
    // Next will be the day after
    assertDateTime(helper.calculateNext(duringTime), 2000, Calendar.JANUARY, 11, 1, 15, 0);
    // Current or next will be tomorrow
    assertDateTime(helper.calculateCurrentOrNext(duringTime), 2000, Calendar.JANUARY, 11, 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)

Aggregations

ExecutionWindowHelper (com.emc.storageos.db.client.util.ExecutionWindowHelper)15 ExecutionWindow (com.emc.storageos.db.client.model.uimodels.ExecutionWindow)11 Calendar (java.util.Calendar)10 Test (org.junit.Test)9 URI (java.net.URI)3 NamedURI (com.emc.storageos.db.client.model.NamedURI)2 Order (com.emc.storageos.db.client.model.uimodels.Order)2 ServiceDescriptor (com.emc.sa.descriptor.ServiceDescriptor)1 ServiceField (com.emc.sa.descriptor.ServiceField)1 DbClient (com.emc.storageos.db.client.DbClient)1 URIUtil.asString (com.emc.storageos.db.client.URIUtil.asString)1 TimeSeriesConstraint (com.emc.storageos.db.client.constraint.TimeSeriesConstraint)1 ScheduledEvent (com.emc.storageos.db.client.model.uimodels.ScheduledEvent)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 OrderCreateParam (com.emc.vipr.model.catalog.OrderCreateParam)1 ScheduleInfo (com.emc.vipr.model.catalog.ScheduleInfo)1 URISyntaxException (java.net.URISyntaxException)1 InvalidParameterException (java.security.InvalidParameterException)1