Search in sources :

Example 11 with Querier

use of org.opennms.core.utils.Querier in project opennms by OpenNMS.

the class MockDatabase method findNoticesForEvent.

/**
 * @param event
 * @return
 */
public Collection<Integer> findNoticesForEvent(Event event) {
    final List<Integer> notifyIds = new LinkedList<>();
    Querier loadExisting = new Querier(this, "select notifyId from notifications where eventID = ?") {

        @Override
        public void processRow(ResultSet rs) throws SQLException {
            notifyIds.add(rs.getInt(1));
        }
    };
    loadExisting.execute(Integer.valueOf(event.getDbid()));
    return notifyIds;
}
Also used : Querier(org.opennms.core.utils.Querier) SingleResultQuerier(org.opennms.core.utils.SingleResultQuerier) ResultSet(java.sql.ResultSet) LinkedList(java.util.LinkedList)

Example 12 with Querier

use of org.opennms.core.utils.Querier in project opennms by OpenNMS.

the class NotificationManager method getServiceNames.

/**
 * <p>getServiceNames</p>
 *
 * @return a {@link java.util.List} object.
 */
public List<String> getServiceNames() throws SQLException {
    final List<String> services = new ArrayList<>();
    Querier querier = new Querier(m_dataSource, "SELECT servicename FROM service", new RowProcessor() {

        @Override
        public void processRow(ResultSet rs) throws SQLException {
            services.add(rs.getString(1));
        }
    });
    querier.execute(new Object[] {});
    return services;
}
Also used : Querier(org.opennms.core.utils.Querier) SingleResultQuerier(org.opennms.core.utils.SingleResultQuerier) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) RowProcessor(org.opennms.core.utils.RowProcessor)

Example 13 with Querier

use of org.opennms.core.utils.Querier in project opennms by OpenNMS.

the class NotificationManager method forEachUserNotification.

/**
 * <p>forEachUserNotification</p>
 *
 * @param notifId a int.
 * @param rp a {@link org.opennms.netmgt.utils.RowProcessor} object.
 */
public void forEachUserNotification(final int notifId, final RowProcessor rp) {
    final Querier querier = new Querier(m_dataSource, "select * from usersNotified where notifyId = ? order by notifytime", rp);
    querier.execute(notifId);
}
Also used : Querier(org.opennms.core.utils.Querier) SingleResultQuerier(org.opennms.core.utils.SingleResultQuerier)

Example 14 with Querier

use of org.opennms.core.utils.Querier in project opennms by OpenNMS.

the class PollablesIT method createPollableNetwork.

private PollableNetwork createPollableNetwork(final DataSource db, final ScheduleTimer scheduler, final PollerConfig pollerConfig, final PollOutagesConfig pollOutageConfig, PollContext pollContext) throws UnknownHostException {
    final PollableNetwork pNetwork = new PollableNetwork(pollContext);
    String sql = "select node.nodeId as nodeId, node.nodeLabel as nodeLabel, ipInterface.ipAddr as ipAddr, ifServices.serviceId as serviceId, service.serviceName as serviceName, outages.svcLostEventId as svcLostEventId, events.eventUei as svcLostEventUei, outages.ifLostService as ifLostService, outages.ifRegainedService as ifRegainedService " + "from ifServices " + "join ipInterface on ifServices.ipInterfaceId = ipInterface.id " + "join node on ipInterface.nodeId = node.nodeId " + "join service on ifServices.serviceId = service.serviceId " + "left outer join outages on " + "ifServices.id = outages.ifServiceId and " + "ifRegainedService is null " + "left outer join events on outages.svcLostEventId = events.eventid " + "where ifServices.status = 'A'";
    Querier querier = new Querier(db, sql) {

        @Override
        public void processRow(ResultSet rs) throws SQLException {
            int nodeId = rs.getInt("nodeId");
            String nodeLabel = rs.getString("nodeLabel");
            String ipAddr = rs.getString("ipAddr");
            String serviceName = rs.getString("serviceName");
            Date date = rs.getTimestamp("ifLostService");
            Number svcLostEventId = (Number) rs.getObject("svcLostEventId");
            String svcLostUei = rs.getString("svcLostEventUei");
            addServiceToNetwork(pNetwork, nodeId, nodeLabel, null, ipAddr, serviceName, svcLostEventId, svcLostUei, date, scheduler, pollerConfig, pollOutageConfig);
        // schedule.schedule();
        // MockUtil.println("Created Pollable Service "+svc+" with package "+pkg.getName());
        }
    };
    querier.execute();
    pNetwork.recalculateStatus();
    pNetwork.propagateInitialCause();
    pNetwork.resetStatusChanged();
    return pNetwork;
}
Also used : Querier(org.opennms.core.utils.Querier) ResultSet(java.sql.ResultSet) Date(java.util.Date)

Aggregations

Querier (org.opennms.core.utils.Querier)14 ResultSet (java.sql.ResultSet)12 SingleResultQuerier (org.opennms.core.utils.SingleResultQuerier)7 SQLException (java.sql.SQLException)3 RowProcessor (org.opennms.core.utils.RowProcessor)3 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 MockNode (org.opennms.netmgt.mock.MockNode)2 MockService (org.opennms.netmgt.mock.MockService)2 Event (org.opennms.netmgt.xml.event.Event)2 IOException (java.io.IOException)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Notification (org.opennms.netmgt.config.notifications.Notification)1 MockInterface (org.opennms.netmgt.mock.MockInterface)1 MockPathOutage (org.opennms.netmgt.mock.MockPathOutage)1 Outage (org.opennms.netmgt.mock.Outage)1 PollStatus (org.opennms.netmgt.poller.PollStatus)1 Tticket (org.opennms.netmgt.xml.event.Tticket)1