Search in sources :

Example 11 with ExecutionWindow

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

the class ExecutionWindowHelperTest method testMonthly.

@Test
public void testMonthly() {
    // Monthly on the 15th at 1:15am
    ExecutionWindow window = createMonthlyWindow(15, 1, 15);
    setLengthInHours(window, 1);
    ExecutionWindowHelper helper = new ExecutionWindowHelper(window);
    // Just before window
    Calendar beforeTime = getDateTimeUTC(2013, Calendar.MAY, 15, 1, 10, 0);
    assertDateTime(helper.calculateNext(beforeTime), 2013, Calendar.MAY, 15, 1, 15, 0);
    assertDateTime(helper.calculateCurrentOrNext(beforeTime), 2013, Calendar.MAY, 15, 1, 15, 0);
    // Just after the window
    Calendar afterTime = getDateTimeUTC(2013, Calendar.APRIL, 16, 1, 10, 0);
    assertDateTime(helper.calculateNext(afterTime), 2013, Calendar.MAY, 15, 1, 15, 0);
    assertDateTime(helper.calculateCurrentOrNext(afterTime), 2013, Calendar.MAY, 15, 1, 15, 0);
    // Start of the window
    Calendar duringTime = getDateTimeUTC(2013, Calendar.MAY, 15, 1, 15, 0);
    assertDateTime(helper.calculateNext(duringTime), 2013, Calendar.JUNE, 15, 1, 15, 0);
    assertDateTime(helper.calculateCurrentOrNext(duringTime), 2013, Calendar.MAY, 15, 1, 15, 0);
    Assert.assertTrue(helper.isActive(duringTime));
    // One minute after start
    duringTime = getDateTimeUTC(2013, Calendar.MAY, 15, 1, 16, 0);
    assertDateTime(helper.calculateNext(duringTime), 2013, Calendar.JUNE, 15, 1, 15, 0);
    assertDateTime(helper.calculateCurrentOrNext(duringTime), 2013, Calendar.MAY, 15, 1, 15, 0);
    Assert.assertTrue(helper.isActive(duringTime));
    // One minute before end
    duringTime = getDateTimeUTC(2013, Calendar.MAY, 15, 2, 14, 0);
    assertDateTime(helper.calculateNext(duringTime), 2013, Calendar.JUNE, 15, 1, 15, 0);
    assertDateTime(helper.calculateCurrentOrNext(duringTime), 2013, Calendar.MAY, 15, 1, 15, 0);
    Assert.assertTrue(helper.isActive(duringTime));
    // End of the window
    duringTime = getDateTimeUTC(2013, Calendar.MAY, 15, 2, 15, 0);
    assertDateTime(helper.calculateNext(duringTime), 2013, Calendar.JUNE, 15, 1, 15, 0);
    assertDateTime(helper.calculateCurrentOrNext(duringTime), 2013, Calendar.JUNE, 15, 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 12 with ExecutionWindow

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

the class ExecutionWindowHelperTest method testWeeklyBeforeTime.

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

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

the class ExecutionWindowService method getExecutionWindows.

/**
 * Gets the list of execution windows
 *
 * @param tenantId the URN of a tenant
 * @brief List Execution Windows
 * @return a list of execution windows
 * @throws DatabaseException when a DB error occurs
 */
@GET
@Path("")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public ExecutionWindowList getExecutionWindows(@DefaultValue("") @QueryParam(SearchConstants.TENANT_ID_PARAM) String tenantId) throws DatabaseException {
    StorageOSUser user = getUserFromContext();
    if (StringUtils.isBlank(tenantId)) {
        tenantId = user.getTenantId();
    }
    verifyAuthorizedInTenantOrg(uri(tenantId), getUserFromContext());
    List<ExecutionWindow> executionWindows = executionWindowManager.getExecutionWindows(uri(tenantId));
    ExecutionWindowList list = new ExecutionWindowList();
    for (ExecutionWindow executionWindow : executionWindows) {
        NamedRelatedResourceRep resourceRep = toNamedRelatedResource(ResourceTypeEnum.EXECUTION_WINDOW, executionWindow.getId(), executionWindow.getLabel());
        list.getExecutionWindows().add(resourceRep);
    }
    return list;
}
Also used : ExecutionWindow(com.emc.storageos.db.client.model.uimodels.ExecutionWindow) StorageOSUser(com.emc.storageos.security.authentication.StorageOSUser) ExecutionWindowList(com.emc.vipr.model.catalog.ExecutionWindowList) NamedRelatedResourceRep(com.emc.storageos.model.NamedRelatedResourceRep) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 15 with ExecutionWindow

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

the class ExecutionWindowService method createExecutionWindow.

/**
 * Creates a new execution window
 *
 * @param createParam
 *            the parameter to create a new execution window
 * @prereq none
 * @brief Create Execution Window
 * @return none
 */
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN })
@Path("")
public ExecutionWindowRestRep createExecutionWindow(ExecutionWindowCreateParam createParam) {
    StorageOSUser user = getUserFromContext();
    verifyAuthorizedInTenantOrg(createParam.getTenant(), user);
    validateParam(createParam, null, user.getTenantId());
    ExecutionWindow executionWindow = createNewObject(createParam);
    executionWindowManager.createExecutionWindow(executionWindow);
    auditOpSuccess(OperationTypeEnum.CREATE_EXECUTION_WINDOW, executionWindow.auditParameters());
    return map(executionWindow);
}
Also used : ExecutionWindow(com.emc.storageos.db.client.model.uimodels.ExecutionWindow) StorageOSUser(com.emc.storageos.security.authentication.StorageOSUser) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

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