use of org.opennms.netmgt.config.poller.outages.Outage in project opennms by OpenNMS.
the class BasicScheduleUtilsTest method testNms6013IsTimeInScheduleWithDay.
@Test
public void testNms6013IsTimeInScheduleWithDay() throws Exception {
String schedSpec = "" + "<outage name=\"debtoct\" type=\"weekly\"> \n" + " <time day=\"monday\" begins=\"00:00:00\" ends=\"08:30:00\"/> \n" + " <time day=\"monday\" begins=\"16:15:00\" ends=\"23:59:59\"/> \n" + " <time day=\"tuesday\" begins=\"00:00:00\" ends=\"08:30:00\"/> \n" + " <time day=\"tuesday\" begins=\"16:15:00\" ends=\"23:59:59\"/> \n" + " <time day=\"wednesday\" begins=\"00:00:00\" ends=\"08:30:00\"/> \n" + " <time day=\"wednesday\" begins=\"16:15:00\" ends=\"23:59:59\"/> \n" + " <time day=\"thursday\" begins=\"00:00:00\" ends=\"08:30:00\"/> \n" + " <time day=\"thursday\" begins=\"16:15:00\" ends=\"23:59:59\"/> \n" + " <time day=\"friday\" begins=\"00:00:00\" ends=\"08:30:00\"/> \n" + " <time day=\"friday\" begins=\"16:15:00\" ends=\"23:59:59\"/> \n" + " <time day=\"saturday\" begins=\"00:00:00\" ends=\"23:59:59\"/> \n" + " <time day=\"sunday\" begins=\"00:00:00\" ends=\"23:59:59\"/> \n" + " <interface address=\"10.85.34.61\"/> \n" + "</outage> \n";
final Outage out = JaxbUtils.unmarshal(Outage.class, schedSpec);
final BasicSchedule schedule = BasicScheduleUtils.getBasicOutageSchedule(out);
final Map<Calendar, Boolean> daySchedules = new HashMap<Calendar, Boolean>();
// monday, august 5, 9:00am
daySchedules.put(new GregorianCalendar(2013, 7, 5, 9, 0), false);
// monday, august 5, 17:00pm
daySchedules.put(new GregorianCalendar(2013, 7, 5, 17, 0), true);
// tuesday, august 6, 1:00am
daySchedules.put(new GregorianCalendar(2013, 7, 6, 1, 0), true);
// tuesday, august 6, 10:00am
daySchedules.put(new GregorianCalendar(2013, 7, 6, 10, 0), false);
// wednesday, august 7, 1:00am
daySchedules.put(new GregorianCalendar(2013, 7, 7, 1, 0), true);
// wednesday, august 7, 1:00pm
daySchedules.put(new GregorianCalendar(2013, 7, 7, 13, 0), false);
// wednesday, august 7, 11:004m
daySchedules.put(new GregorianCalendar(2013, 7, 7, 23, 0), true);
for (final Map.Entry<Calendar, Boolean> entry : daySchedules.entrySet()) {
if (entry.getValue()) {
assertTrue(entry.getKey().getTime() + " should be in the schedule", BasicScheduleUtils.isTimeInSchedule(entry.getKey(), schedule));
} else {
assertFalse(entry.getKey().getTime() + " should not be in the schedule", BasicScheduleUtils.isTimeInSchedule(entry.getKey(), schedule));
}
}
}
use of org.opennms.netmgt.config.poller.outages.Outage in project opennms by OpenNMS.
the class ScheduledOutagesRestService method isNodeInOutage.
@GET
@Path("{outageName}/nodeInOutage/{nodeId}")
@Produces(MediaType.TEXT_PLAIN)
public String isNodeInOutage(@PathParam("outageName") String outageName, @PathParam("nodeId") Integer nodeId) {
Outage outage = getOutage(outageName);
Boolean inOutage = m_pollOutagesConfigFactory.isNodeIdInOutage(nodeId, outage) && m_pollOutagesConfigFactory.isCurTimeInOutage(outage);
return inOutage.toString();
}
use of org.opennms.netmgt.config.poller.outages.Outage in project opennms by OpenNMS.
the class ScheduledOutagesRestService method saveOrUpdateOutage.
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response saveOrUpdateOutage(@Context final UriInfo uriInfo, final Outage newOutage) {
writeLock();
try {
if (newOutage == null)
throw getException(Status.BAD_REQUEST, "Outage object can't be null");
Outage oldOutage = m_pollOutagesConfigFactory.getOutage(newOutage.getName());
if (oldOutage == null) {
LOG.debug("saveOrUpdateOutage: adding outage {}", newOutage.getName());
m_pollOutagesConfigFactory.addOutage(newOutage);
} else {
LOG.debug("saveOrUpdateOutage: updating outage {}", newOutage.getName());
m_pollOutagesConfigFactory.replaceOutage(oldOutage, newOutage);
}
try {
m_pollOutagesConfigFactory.saveCurrent();
} catch (Exception e) {
throw getException(Status.INTERNAL_SERVER_ERROR, "Can't save or update the scheduled outage {} because, {}", newOutage.getName(), e.getMessage());
}
sendConfigChangedEvent();
return oldOutage == null ? Response.created(getRedirectUri(uriInfo, newOutage.getName())).build() : Response.noContent().build();
} finally {
writeUnlock();
}
}
use of org.opennms.netmgt.config.poller.outages.Outage in project opennms by OpenNMS.
the class PollOutagesConfigManagerTest method testPerformance.
@Test
public void testPerformance() throws Exception {
long start = System.currentTimeMillis();
for (int i = 1; i <= 200; i++) {
String outageName = "o" + Integer.toString(i);
Outage outage = m_manager.getOutage(outageName);
assertTrue(outage != null);
assertTrue(m_manager.isNodeIdInOutage(i, outageName));
}
long end = System.currentTimeMillis();
System.out.println("Test took " + (end - start) + " ms");
}
use of org.opennms.netmgt.config.poller.outages.Outage in project opennms by OpenNMS.
the class PollOutagesConfigManager method isTimeInOutage.
/**
* {@inheritDoc}
*
* Return if time is part of specified outage.
*/
@Override
public boolean isTimeInOutage(final long time, final String outName) {
final Outage out = getOutage(outName);
if (out == null)
return false;
final Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(time);
return isTimeInOutage(cal, out);
}
Aggregations