Search in sources :

Example 1 with Outage

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));
        }
    }
}
Also used : Outage(org.opennms.netmgt.config.poller.outages.Outage) HashMap(java.util.HashMap) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 2 with Outage

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();
}
Also used : Outage(org.opennms.netmgt.config.poller.outages.Outage) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 3 with Outage

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();
    }
}
Also used : Outage(org.opennms.netmgt.config.poller.outages.Outage) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes)

Example 4 with Outage

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");
}
Also used : Outage(org.opennms.netmgt.config.poller.outages.Outage) Test(org.junit.Test)

Example 5 with Outage

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);
}
Also used : Outage(org.opennms.netmgt.config.poller.outages.Outage) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar)

Aggregations

Outage (org.opennms.netmgt.config.poller.outages.Outage)12 Test (org.junit.Test)4 Time (org.opennms.netmgt.config.poller.outages.Time)3 SimpleDateFormat (java.text.SimpleDateFormat)2 Calendar (java.util.Calendar)2 Date (java.util.Date)2 GregorianCalendar (java.util.GregorianCalendar)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 Interface (org.opennms.netmgt.config.poller.outages.Interface)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 PatternSyntaxException (java.util.regex.PatternSyntaxException)1 Consumes (javax.ws.rs.Consumes)1 POST (javax.ws.rs.POST)1 ThreshdConfigManager (org.opennms.netmgt.config.ThreshdConfigManager)1 Node (org.opennms.netmgt.config.poller.outages.Node)1