Search in sources :

Example 1 with ExecutionWindowHelper

use of com.emc.storageos.db.client.util.ExecutionWindowHelper 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 ExecutionWindowHelper

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

the class ScheduledEventService method getNextExecutionWindow.

public URI getNextExecutionWindow(Collection<URI> windows, Calendar time) {
    Calendar nextWindowTime = null;
    URI nextWindow = null;
    for (URI window : windows) {
        ExecutionWindow executionWindow = _dbClient.queryObject(ExecutionWindow.class, window);
        if (executionWindow == null)
            continue;
        ExecutionWindowHelper helper = new ExecutionWindowHelper(executionWindow);
        Calendar windowTime = helper.calculateCurrentOrNext(time);
        if (nextWindowTime == null || nextWindowTime.after(windowTime)) {
            nextWindowTime = windowTime;
            nextWindow = window;
        }
    }
    return nextWindow;
}
Also used : ExecutionWindowHelper(com.emc.storageos.db.client.util.ExecutionWindowHelper) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI)

Example 3 with ExecutionWindowHelper

use of com.emc.storageos.db.client.util.ExecutionWindowHelper 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 4 with ExecutionWindowHelper

use of com.emc.storageos.db.client.util.ExecutionWindowHelper 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 5 with ExecutionWindowHelper

use of com.emc.storageos.db.client.util.ExecutionWindowHelper 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

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