Search in sources :

Example 21 with PluginException

use of org.opennms.api.integration.ticketing.PluginException in project opennms by OpenNMS.

the class DefaultTicketerServiceLayer method updateTicketForAlarm.

/*
     * (non-Javadoc)
     * @see org.opennms.netmgt.ticketd.TicketerServiceLayer#updateTicketForAlarm(int, java.lang.String)
     */
/** {@inheritDoc} */
@Override
public void updateTicketForAlarm(int alarmId, String ticketId) {
    OnmsAlarm alarm = m_alarmDao.get(alarmId);
    if (alarm == null) {
        LOG.error("No alarm with id {} was found. Ticket with id '{}' will not be updated.", alarmId, ticketId);
        return;
    }
    Ticket ticket = null;
    try {
        ticket = m_ticketerPlugin.get(ticketId);
        if (ticket.getState() == Ticket.State.CANCELLED) {
            alarm.setTTicketState(TroubleTicketState.CANCELLED);
        } else if (ticket.getState() == Ticket.State.CLOSED) {
            alarm.setTTicketState(TroubleTicketState.CLOSED);
        } else if (ticket.getState() == Ticket.State.OPEN) {
            alarm.setTTicketState(TroubleTicketState.OPEN);
        } else {
            alarm.setTTicketState(TroubleTicketState.OPEN);
        }
    } catch (PluginException e) {
        alarm.setTTicketState(TroubleTicketState.UPDATE_FAILED);
        LOG.error("Unable to update ticket for alarm: {}", e.getMessage());
        m_eventIpcManager.sendNow(createEvent(e.getMessage()));
    }
    m_alarmDao.saveOrUpdate(alarm);
}
Also used : Ticket(org.opennms.api.integration.ticketing.Ticket) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) PluginException(org.opennms.api.integration.ticketing.PluginException)

Example 22 with PluginException

use of org.opennms.api.integration.ticketing.PluginException in project opennms by OpenNMS.

the class DefaultTicketerServiceLayer method cancelTicketForAlarm.

/*
     * (non-Javadoc)
     * @see org.opennms.netmgt.ticketd.TicketerServiceLayer#cancelTicketForAlarm(int, java.lang.String)
     */
/** {@inheritDoc} */
@Override
public void cancelTicketForAlarm(int alarmId, String ticketId) {
    OnmsAlarm alarm = m_alarmDao.get(alarmId);
    if (alarm == null) {
        LOG.error("No alarm with id {} was found. Ticket with id '{}' will not be canceled.", alarmId, ticketId);
        return;
    }
    try {
        setTicketState(ticketId, Ticket.State.CANCELLED);
        alarm.setTTicketState(TroubleTicketState.CANCELLED);
    } catch (PluginException e) {
        alarm.setTTicketState(TroubleTicketState.CANCEL_FAILED);
        LOG.error("Unable to cancel ticket for alarm: {}", e.getMessage(), e);
        m_eventIpcManager.sendNow(createEvent(e.getMessage()));
    }
    m_alarmDao.saveOrUpdate(alarm);
}
Also used : OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) PluginException(org.opennms.api.integration.ticketing.PluginException)

Example 23 with PluginException

use of org.opennms.api.integration.ticketing.PluginException in project opennms by OpenNMS.

the class DefaultTicketerServiceLayerTest method testFailedCreateTicketForAlarm.

/**
     * Test method for {@link org.opennms.netmgt.ticketd.DefaultTicketerServiceLayer#createTicketForAlarm(int)}.
     * Tests for correct alarm TroubleTicketState set as CREATE_FAILED when ticketer plugin fails
     */
@Test
public void testFailedCreateTicketForAlarm() {
    EasyMock.expect(m_alarmDao.get(m_alarm.getId())).andReturn(m_alarm);
    try {
        m_ticketerPlugin.saveOrUpdate(EasyMock.isA(Ticket.class));
    } catch (PluginException e) {
    //e.printStackTrace();
    }
    EasyMock.expectLastCall().andThrow(new PluginException("Failed Create"));
    expectNewAlarmState(TroubleTicketState.CREATE_FAILED);
    m_easyMockUtils.replayAll();
    m_defaultTicketerServiceLayer.createTicketForAlarm(m_alarm.getId(), new HashMap<String, String>());
    m_easyMockUtils.verifyAll();
}
Also used : Ticket(org.opennms.api.integration.ticketing.Ticket) PluginException(org.opennms.api.integration.ticketing.PluginException) Test(org.junit.Test)

Aggregations

PluginException (org.opennms.api.integration.ticketing.PluginException)23 Ticket (org.opennms.api.integration.ticketing.Ticket)16 Test (org.junit.Test)5 OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)4 ExecutionException (java.util.concurrent.ExecutionException)3 BasicIssue (com.atlassian.jira.rest.client.api.domain.BasicIssue)2 Issue (com.atlassian.jira.rest.client.api.domain.Issue)2 OnmsSeverity (org.opennms.netmgt.model.OnmsSeverity)2 RTTicket (org.opennms.netmgt.rt.RTTicket)2 RequestTrackerException (org.opennms.netmgt.rt.RequestTrackerException)2 JiraRestClient (com.atlassian.jira.rest.client.api.JiraRestClient)1 Comment (com.atlassian.jira.rest.client.api.domain.Comment)1 ServerInfo (com.atlassian.jira.rest.client.api.domain.ServerInfo)1 Transition (com.atlassian.jira.rest.client.api.domain.Transition)1 IssueInputBuilder (com.atlassian.jira.rest.client.api.domain.input.IssueInputBuilder)1 TransitionInput (com.atlassian.jira.rest.client.api.domain.input.TransitionInput)1 TicketIDAndNumber (org.opennms.integration.otrs.ticketservice.TicketIDAndNumber)1