Search in sources :

Example 6 with PluginException

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

the class VerifyCommand method verifyConnection.

private JiraRestClient verifyConnection() {
    final String host = config.getHost();
    final String username = config.getUsername();
    final String password = config.getPassword();
    try {
        System.out.println();
        System.out.println("Try connecting to jira server " + host + " with username: '" + username + "' and password: '" + password + "'...");
        final JiraRestClient connection = JiraConnectionFactory.createConnection(host, username, password);
        final ServerInfo serverInfo = connection.getMetadataClient().getServerInfo().get();
        System.out.println("Successfully connected to jira instance at " + host);
        System.out.println("Server Info:" + serverInfo.toString());
        System.out.println("OK");
        return connection;
    } catch (PluginException | InterruptedException | ExecutionException e) {
        throw new RuntimeException("Could not connect to jira server", e);
    }
}
Also used : ServerInfo(com.atlassian.jira.rest.client.api.domain.ServerInfo) PluginException(org.opennms.api.integration.ticketing.PluginException) JiraRestClient(com.atlassian.jira.rest.client.api.JiraRestClient) ExecutionException(java.util.concurrent.ExecutionException)

Example 7 with PluginException

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

the class DefaultTicketerServiceLayer method closeTicketForAlarm.

/*
     * (non-Javadoc)
     * @see org.opennms.netmgt.ticketd.TicketerServiceLayer#closeTicketForAlarm(int, java.lang.String)
     */
/** {@inheritDoc} */
@Override
public void closeTicketForAlarm(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 closed.", alarmId, ticketId);
        return;
    }
    if (SKIP_CLOSE_WHEN_NOT_CLEARED) {
        final OnmsSeverity currentSeverity = alarm.getSeverity();
        if (currentSeverity != null && !currentSeverity.equals(OnmsSeverity.CLEARED)) {
            LOG.info("Alarm with id {} is not currently cleared. Ticket with id '{}' will not be closed.", alarmId, ticketId);
            return;
        }
    }
    try {
        setTicketState(ticketId, State.CLOSED);
        alarm.setTTicketState(TroubleTicketState.CLOSED);
    } catch (PluginException e) {
        alarm.setTTicketState(TroubleTicketState.CLOSE_FAILED);
        LOG.error("Unable to close ticket for alarm: {}", e.getMessage(), e);
        m_eventIpcManager.sendNow(createEvent(e.getMessage()));
    }
    m_alarmDao.saveOrUpdate(alarm);
}
Also used : OnmsSeverity(org.opennms.netmgt.model.OnmsSeverity) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) PluginException(org.opennms.api.integration.ticketing.PluginException)

Example 8 with PluginException

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

the class DefaultTicketerServiceLayerTest method testFailedCloseTicketForAlarm.

/**
     * Test method for {@link org.opennms.netmgt.ticketd.DefaultTicketerServiceLayer#closeTicketForAlarm(int, java.lang.String)}.
     * Tests for correct alarm TroubleTicketState set as CLOSE_FAILED when ticketer plugin fails
     * @throws PluginException 
     */
@Test
public void testFailedCloseTicketForAlarm() throws PluginException {
    EasyMock.expect(m_alarmDao.get(m_alarm.getId())).andReturn(m_alarm);
    m_ticketerPlugin.get(m_ticket.getId());
    EasyMock.expectLastCall().andThrow(new PluginException("Failed Close"));
    expectNewAlarmState(TroubleTicketState.CLOSE_FAILED);
    m_alarm.setSeverity(OnmsSeverity.CLEARED);
    m_easyMockUtils.replayAll();
    m_defaultTicketerServiceLayer.closeTicketForAlarm(m_alarm.getId(), m_ticket.getId());
    m_easyMockUtils.verifyAll();
}
Also used : PluginException(org.opennms.api.integration.ticketing.PluginException) Test(org.junit.Test)

Example 9 with PluginException

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

the class DefaultTicketerServiceLayerTest method testFailedCancelTicketForAlarm.

/**
     * Test method for {@link org.opennms.netmgt.ticketd.DefaultTicketerServiceLayer#cancelTicketForAlarm(int, java.lang.String)}.
     * Tests for correct alarm TroubleTicketState set as CANCEL_FAILED when ticketer plugin fails
     */
@Test
public void testFailedCancelTicketForAlarm() {
    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();
    }
    EasyMock.expectLastCall().andThrow(new PluginException("Failed Cancel"));
    expectNewAlarmState(TroubleTicketState.CANCEL_FAILED);
    m_easyMockUtils.replayAll();
    m_defaultTicketerServiceLayer.cancelTicketForAlarm(m_alarm.getId(), m_ticket.getId());
    m_easyMockUtils.verifyAll();
}
Also used : PluginException(org.opennms.api.integration.ticketing.PluginException) Test(org.junit.Test)

Example 10 with PluginException

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

the class JiraTicketerPlugin method getInternal.

private Ticket getInternal(String ticketId, JiraRestClient jira) throws PluginException {
    // w00t
    Issue issue;
    try {
        issue = jira.getIssueClient().getIssue(ticketId).get();
    } catch (InterruptedException | ExecutionException e) {
        throw new PluginException("Failed to get issue with id: " + ticketId, e);
    }
    if (issue != null) {
        Ticket ticket = new Ticket();
        ticket.setId(issue.getKey());
        ticket.setModificationTimestamp(String.valueOf(issue.getUpdateDate().toDate().getTime()));
        ticket.setSummary(issue.getSummary());
        ticket.setDetails(issue.getDescription());
        ticket.setState(getStateFromStatusName(issue.getStatus().getName()));
        return ticket;
    } else {
        return null;
    }
}
Also used : Ticket(org.opennms.api.integration.ticketing.Ticket) Issue(com.atlassian.jira.rest.client.api.domain.Issue) BasicIssue(com.atlassian.jira.rest.client.api.domain.BasicIssue) PluginException(org.opennms.api.integration.ticketing.PluginException) ExecutionException(java.util.concurrent.ExecutionException)

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