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));
}
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);
}
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;
}
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;
}
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);
}
Aggregations