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