Search in sources :

Example 16 with PluginException

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

the class RtTicketerPlugin method saveOrUpdate.

/**
	 * {@inheritDoc}
	 *
	 * Creates a new ticket (if none exists) or updates an existing ticket in the
	 * RT trouble ticket system. Ticket updates are currently limited to updating
	 * the ticket status only.
	 */
@Override
public void saveOrUpdate(final Ticket newTicket) throws PluginException {
    String newTicketID;
    Ticket currentTicket = null;
    try {
        if ((newTicket.getId() == null)) {
            LOG.debug("TicketId is null creating a new ticket");
            RTTicket ticket = rtTicketFromTicket(newTicket);
            Long rtTicketNumber = null;
            try {
                rtTicketNumber = m_requestTracker.createTicket(ticket);
            } catch (final Exception e) {
                throw new PluginException(e);
            }
            if (rtTicketNumber == null) {
                throw new PluginException("Received no ticket number from RT");
            }
            newTicketID = rtTicketNumber.toString();
            newTicket.setId(newTicketID);
            LOG.debug("created new ticket: {}", newTicket.getId());
        } else {
            currentTicket = get(newTicket.getId());
            LOG.debug("updating existing ticket: {}", currentTicket.getId());
            if (currentTicket.getState() != newTicket.getState()) {
                updateRtStatus(newTicket);
            } else {
            // There is no else at the moment
            // Tickets are _only_ updated with new state
            }
        }
    } catch (final PluginException e) {
        LOG.error("Failed to create or update RT ticket", e);
        throw e;
    }
}
Also used : RTTicket(org.opennms.netmgt.rt.RTTicket) Ticket(org.opennms.api.integration.ticketing.Ticket) RTTicket(org.opennms.netmgt.rt.RTTicket) PluginException(org.opennms.api.integration.ticketing.PluginException) PluginException(org.opennms.api.integration.ticketing.PluginException) RequestTrackerException(org.opennms.netmgt.rt.RequestTrackerException)

Example 17 with PluginException

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

the class RtTicketerPluginTest method testSaveAndGet.

public void testSaveAndGet() {
    try {
        m_ticketer.saveOrUpdate(m_ticket);
        Ticket retrievedTicket = m_ticketer.get(m_ticket.getId());
        assertTicketEquals(m_ticket, retrievedTicket);
    } catch (final PluginException e) {
        e.printStackTrace();
        fail("Something failed in the ticketer plugin");
    }
}
Also used : Ticket(org.opennms.api.integration.ticketing.Ticket) PluginException(org.opennms.api.integration.ticketing.PluginException)

Example 18 with PluginException

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

the class DefaultTicketerServiceLayerTest method testFailedUpdateTicketForAlarm.

/**
     * Test method for {@link org.opennms.netmgt.ticketd.DefaultTicketerServiceLayer#updateTicketForAlarm(int, java.lang.String)}.
     * Tests for correct alarm TroubleTicketState set as CANCEL_FAILED when ticketer plugin fails
     */
@Test
public void testFailedUpdateTicketForAlarm() {
    m_ticket.setState(Ticket.State.CANCELLED);
    EasyMock.expect(m_alarmDao.get(m_alarm.getId())).andReturn(m_alarm);
    try {
        m_ticketerPlugin.get(m_ticket.getId());
    } catch (PluginException e) {
    // TODO Auto-generated catch block
    // e.printStackTrace();
    }
    //expectUpdatedTicket();
    EasyMock.expectLastCall().andThrow(new PluginException("Failed Update"));
    expectNewAlarmState(TroubleTicketState.UPDATE_FAILED);
    m_easyMockUtils.replayAll();
    m_defaultTicketerServiceLayer.updateTicketForAlarm(m_alarm.getId(), m_ticket.getId());
    m_easyMockUtils.verifyAll();
}
Also used : PluginException(org.opennms.api.integration.ticketing.PluginException) Test(org.junit.Test)

Example 19 with PluginException

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

the class DroolsTicketerServiceLayerTest method testFailedCreateTicketForAlarm.

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

Example 20 with PluginException

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

the class DefaultTicketerServiceLayer method setTicketState.

private void setTicketState(String ticketId, State state) throws PluginException {
    try {
        Ticket ticket = m_ticketerPlugin.get(ticketId);
        ticket.setState(state);
        m_ticketerPlugin.saveOrUpdate(ticket);
    } catch (PluginException e) {
        LOG.error("Unable to set ticket state");
        throw e;
    }
}
Also used : Ticket(org.opennms.api.integration.ticketing.Ticket) PluginException(org.opennms.api.integration.ticketing.PluginException)

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