use of org.killbill.bus.api.BusEvent in project killbill by killbill.
the class AdminResource method getQueueEntries.
@GET
@Path("/queues")
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Get queues entries", response = Response.class)
@ApiResponses(value = {})
public Response getQueueEntries(@QueryParam("accountId") final String accountIdStr, @QueryParam("queueName") final String queueName, @QueryParam("serviceName") final String serviceName, @QueryParam("withHistory") @DefaultValue("true") final Boolean withHistory, @QueryParam("minDate") final String minDateOrNull, @QueryParam("maxDate") final String maxDateOrNull, @QueryParam("withInProcessing") @DefaultValue("true") final Boolean withInProcessing, @QueryParam("withBusEvents") @DefaultValue("true") final Boolean withBusEvents, @QueryParam("withNotifications") @DefaultValue("true") final Boolean withNotifications, @javax.ws.rs.core.Context final HttpServletRequest request) {
final TenantContext tenantContext = context.createContext(request);
final Long tenantRecordId = recordIdApi.getRecordId(tenantContext.getTenantId(), ObjectType.TENANT, tenantContext);
final Long accountRecordId = Strings.isNullOrEmpty(accountIdStr) ? null : recordIdApi.getRecordId(UUID.fromString(accountIdStr), ObjectType.ACCOUNT, tenantContext);
// Limit search results by default
final DateTime minDate = Strings.isNullOrEmpty(minDateOrNull) ? clock.getUTCNow().minusDays(2) : DATE_TIME_FORMATTER.parseDateTime(minDateOrNull).toDateTime(DateTimeZone.UTC);
final DateTime maxDate = Strings.isNullOrEmpty(maxDateOrNull) ? clock.getUTCNow().plusDays(2) : DATE_TIME_FORMATTER.parseDateTime(maxDateOrNull).toDateTime(DateTimeZone.UTC);
final StreamingOutput json = new StreamingOutput() {
@Override
public void write(final OutputStream output) throws IOException, WebApplicationException {
Iterator<BusEventWithMetadata<BusEvent>> busEventsIterator = null;
Iterator<NotificationEventWithMetadata<NotificationEvent>> notificationsIterator = null;
try {
final JsonGenerator generator = mapper.getFactory().createGenerator(output);
generator.configure(JsonGenerator.Feature.AUTO_CLOSE_TARGET, false);
generator.writeStartObject();
if (withBusEvents) {
generator.writeFieldName("busEvents");
generator.writeStartArray();
busEventsIterator = getBusEvents(withInProcessing, withHistory, minDate, maxDate, accountRecordId, tenantRecordId).iterator();
while (busEventsIterator.hasNext()) {
final BusEventWithMetadata<BusEvent> busEvent = busEventsIterator.next();
generator.writeObject(new BusEventWithRichMetadata(busEvent));
}
generator.writeEndArray();
}
if (withNotifications) {
generator.writeFieldName("notifications");
generator.writeStartArray();
notificationsIterator = getNotifications(queueName, serviceName, withInProcessing, withHistory, minDate, maxDate, accountRecordId, tenantRecordId).iterator();
while (notificationsIterator.hasNext()) {
final NotificationEventWithMetadata<NotificationEvent> notification = notificationsIterator.next();
generator.writeObject(notification);
}
generator.writeEndArray();
}
generator.writeEndObject();
generator.close();
} finally {
// In case the client goes away (IOException), make sure to close the underlying DB connection
if (busEventsIterator != null) {
while (busEventsIterator.hasNext()) {
busEventsIterator.next();
}
}
if (notificationsIterator != null) {
while (notificationsIterator.hasNext()) {
notificationsIterator.next();
}
}
}
}
};
return Response.status(Status.OK).entity(json).build();
}
use of org.killbill.bus.api.BusEvent in project killbill by killbill.
the class TestBeatrixListener method testAccountCreate.
@Test(groups = "fast")
public void testAccountCreate() throws Exception {
AccountCreationInternalEvent event = mock(AccountCreationInternalEvent.class);
provideCommonBusEventInfo(event);
when(event.getBusEventType()).thenReturn(BusInternalEventType.ACCOUNT_CREATE);
when(event.getId()).thenReturn(ACCOUNT_ID);
ArgumentCaptor<BusEvent> eventCaptor = ArgumentCaptor.forClass(BusEvent.class);
beatrixListener.handleAllInternalKillbillEvents(event);
verify(externalBus, times(1)).post(eventCaptor.capture());
DefaultBusExternalEvent postedEvent = (DefaultBusExternalEvent) eventCaptor.getValue();
assertEquals(postedEvent.getObjectId(), ACCOUNT_ID);
assertEquals(postedEvent.getObjectType(), ObjectType.ACCOUNT);
assertEquals(postedEvent.getEventType(), ExtBusEventType.ACCOUNT_CREATION);
assertNull(postedEvent.getMetaData());
assertCommonFieldsWithAccountId(postedEvent);
}
use of org.killbill.bus.api.BusEvent in project killbill by killbill.
the class TestBeatrixListener method testPaymentInfo.
@Test(groups = "fast")
public void testPaymentInfo() throws Exception {
PaymentInfoInternalEvent event = mock(PaymentInfoInternalEvent.class);
provideCommonBusEventInfo(event);
when(event.getBusEventType()).thenReturn(BusInternalEventType.PAYMENT_INFO);
when(event.getPaymentId()).thenReturn(OBJECT_ID);
provideCommonPaymentInfo(event);
ArgumentCaptor<PaymentMetadata> metadataCaptor = ArgumentCaptor.forClass(PaymentMetadata.class);
when(objectMapper.writeValueAsString(metadataCaptor.capture())).thenReturn(METADATA);
when(internalCallContextFactory.getAccountId(OBJECT_ID, ObjectType.PAYMENT, tenantContext)).thenReturn(ACCOUNT_ID);
ArgumentCaptor<BusEvent> eventCaptor = ArgumentCaptor.forClass(BusEvent.class);
beatrixListener.handleAllInternalKillbillEvents(event);
verify(externalBus).post(eventCaptor.capture());
DefaultBusExternalEvent postedEvent = (DefaultBusExternalEvent) eventCaptor.getValue();
assertEquals(postedEvent.getObjectId(), OBJECT_ID);
assertEquals(postedEvent.getObjectType(), ObjectType.PAYMENT);
assertEquals(postedEvent.getEventType(), ExtBusEventType.PAYMENT_SUCCESS);
assertEquals(postedEvent.getMetaData(), METADATA);
assertCommonFieldsWithAccountId(postedEvent);
PaymentMetadata paymentMetadata = metadataCaptor.getValue();
assertPaymentMetadataFields(paymentMetadata);
}
use of org.killbill.bus.api.BusEvent in project killbill by killbill.
the class TestBeatrixListener method testInvoiceCreation.
@Test(groups = "fast")
public void testInvoiceCreation() throws Exception {
InvoiceCreationInternalEvent event = mock(InvoiceCreationInternalEvent.class);
provideCommonBusEventInfo(event);
when(event.getBusEventType()).thenReturn(BusInternalEventType.INVOICE_CREATION);
when(event.getInvoiceId()).thenReturn(OBJECT_ID);
when(internalCallContextFactory.getAccountId(OBJECT_ID, ObjectType.INVOICE, tenantContext)).thenReturn(ACCOUNT_ID);
ArgumentCaptor<BusEvent> eventCaptor = ArgumentCaptor.forClass(BusEvent.class);
beatrixListener.handleAllInternalKillbillEvents(event);
verify(externalBus).post(eventCaptor.capture());
DefaultBusExternalEvent postedEvent = (DefaultBusExternalEvent) eventCaptor.getValue();
assertEquals(postedEvent.getObjectId(), OBJECT_ID);
assertEquals(postedEvent.getObjectType(), ObjectType.INVOICE);
assertEquals(postedEvent.getEventType(), ExtBusEventType.INVOICE_CREATION);
assertNull(postedEvent.getMetaData());
assertCommonFieldsWithAccountId(postedEvent);
}
use of org.killbill.bus.api.BusEvent in project killbill by killbill.
the class TestBeatrixListener method testBroadcastService.
@Test(groups = "fast")
public void testBroadcastService() throws Exception {
BroadcastInternalEvent event = mock(BroadcastInternalEvent.class);
provideCommonBusEventInfo(event);
when(event.getBusEventType()).thenReturn(BusInternalEventType.BROADCAST_SERVICE);
when(event.getServiceName()).thenReturn(SERVICE_NAME);
when(event.getType()).thenReturn(BROADCAST_EVENT_TYPE);
when(event.getJsonEvent()).thenReturn(BROADCAST_EVENT_JSON);
ArgumentCaptor<BroadcastMetadata> metadataCaptor = ArgumentCaptor.forClass(BroadcastMetadata.class);
when(objectMapper.writeValueAsString(metadataCaptor.capture())).thenReturn(METADATA);
ArgumentCaptor<BusEvent> eventCaptor = ArgumentCaptor.forClass(BusEvent.class);
beatrixListener.handleAllInternalKillbillEvents(event);
verify(externalBus).post(eventCaptor.capture());
DefaultBusExternalEvent postedEvent = (DefaultBusExternalEvent) eventCaptor.getValue();
assertNull(postedEvent.getObjectId());
assertEquals(postedEvent.getObjectType(), ObjectType.SERVICE_BROADCAST);
assertEquals(postedEvent.getEventType(), ExtBusEventType.BROADCAST_SERVICE);
assertCommonFieldsWithNoAccountId(postedEvent);
BroadcastMetadata broadcastMetadata = metadataCaptor.getValue();
assertEquals(broadcastMetadata.getService(), SERVICE_NAME);
assertEquals(broadcastMetadata.getCommandType(), BROADCAST_EVENT_TYPE);
assertEquals(broadcastMetadata.getEventJson(), BROADCAST_EVENT_JSON);
}
Aggregations