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