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);
}
}
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);
}
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();
}
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();
}
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;
}
}
Aggregations