Skip to content

Commit

Permalink
simplify logging #2
Browse files Browse the repository at this point in the history
  • Loading branch information
xstefank committed Nov 10, 2017
1 parent 6835583 commit af9e2c8
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,11 @@ public List<Event> process(CompensateInvoiceCommand command) {
}

public void apply(InvoiceProcessedEvent event) {
log.info("on InvoiceProcessedEvent");
this.invoice = event.getInvoice();
}

public void apply(InvoicePreparationFailedEvent event) {
log.info("invoice preparation failed with cause " + event.getCause());
this.invoice = "N/A";
}

public void apply(ConfirmCompensationEvent event) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ public class InvoiceEventSubscriber {

@EventHandlerMethod
public void onInvoiceProcessedEvent(DispatchedEvent<InvoiceProcessedEvent> dispatchedEvent) {
log.info("subcriber - on InvoiceProcessedEvent");

InvoiceProcessedEvent event = dispatchedEvent.getEvent();
InvoiceInfo invoiceInfo = new InvoiceInfo(event.getSagaInfo().getSagaId(),
dispatchedEvent.getEntityId(), event.getInvoice());
Expand All @@ -34,17 +32,16 @@ public void onInvoiceProcessedEvent(DispatchedEvent<InvoiceProcessedEvent> dispa

@EventHandlerMethod
public void onConfirmCompensationEvent(DispatchedEvent<ConfirmCompensationEvent> dispatchedEvent) {
log.info("subscriber - on ConfirmCompensationEvent");
invoiceService.confirmCompensation(dispatchedEvent.getEvent().getSagaId());
}

@EventHandlerMethod
public void onInvoicePreparationFailedEvent(DispatchedEvent<InvoicePreparationFailedEvent> dispatchedEvent) {
log.info("subscriber - on InvoicePreparationFailedEvent");

InvoicePreparationFailedEvent event = dispatchedEvent.getEvent();
log.info("invoice preparation failed with cause " + event.getCause());

invoiceService.failInvoicePreparation(event.getSagaId(),
dispatchedEvent.getEntityId(), event.getSagaId());
dispatchedEvent.getEntityId(), event.getCause());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,53 +23,37 @@ public class OrderSagaController {

@RequestMapping(method = RequestMethod.POST, path = "/shipment")
public String shipmentResponse(@RequestBody ShipmentInfo shipmentInfo) {

log.info("received shipment for saga - " + shipmentInfo.getSagaId());
orderSagaService.processShipment(shipmentInfo);

return String.format("Shipment for saga %s recived by order-service", shipmentInfo.getSagaId());
}

@RequestMapping(method = RequestMethod.POST, path = "/shipment/fail")
public String shipmentFailure(@RequestBody ParticipantFailureInfo failureInfo) {

log.info("received shipment failure for saga - " + failureInfo.getSagaId());
orderSagaService.processShipmentFailure(failureInfo);

return String.format("Shipment failure for saga %s recived by order-service", failureInfo.getSagaId());
return String.format("Shipment failure for saga %s received by order-service", failureInfo.getSagaId());
}

@RequestMapping(method = RequestMethod.POST, path = "/shipment/compensation")
public String shipmentCompensated(@RequestBody String sagaId) {
log.info("received shipment compensation confirmation for saga - " + sagaId);
orderSagaService.notifyShipmentCompensated(sagaId);

return "Shipment compensation is received by order-service";
}

@RequestMapping(method = RequestMethod.POST, path = "/invoice")
public String invoiceResponse(@RequestBody InvoiceInfo invoiceInfo) {

log.info("received invoice for saga - " + invoiceInfo.getSagaId());
orderSagaService.processInvoice(invoiceInfo);

return String.format("Invoice for saga %s received by order-service", invoiceInfo.getSagaId());
}

@RequestMapping(method = RequestMethod.POST, path = "/invoice/fail")
public String invoiceFailure(@RequestBody ParticipantFailureInfo failureInfo) {

log.info("received invoice failure for saga - " + failureInfo.getSagaId());
orderSagaService.processInvoiceFailure(failureInfo);

return String.format("Invoice failure for saga %s recived by order-service", failureInfo.getSagaId());
return String.format("Invoice failure for saga %s received by order-service", failureInfo.getSagaId());
}

@RequestMapping(method = RequestMethod.POST, path = "/invoice/compensation")
public String invoiceCompensated(@RequestBody String sagaId) {
log.info("received invoice compensation confirmation for saga - " + sagaId);
orderSagaService.notifyInvoiceCompensated(sagaId);

return "Invoice compensation is received by order-service";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,10 @@ public class OrderAggregate extends ReflectiveMutableCommandProcessingAggregate<
private static final Logger log = LoggerFactory.getLogger(OrderAggregate.class);

public List<Event> process(FileOrderCommand command) {
log.info("received FileOrderCommand");
return EventUtil.events(new OrderFiledEvent(command.getOrderId(), command.getProductInfo()));
}

public List<Event> process(OrderCompletedCommand command) {
log.info("received OrderCompletedCommand");
return EventUtil.events(new OrderCompletedEvent(command.getOrderId(), command.getProductInfo()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public void compensateSaga(String sagaId, CompensateSagaEvent compensationEvent)

private void compensateShipment(String sagaId, CompensateSagaEvent compensationEvent) {
final String url = properties.getShipmentUrl() + COMPENSATION;
log.info("posting shipement compensation request for saga " + sagaId + " to " + url);
log.info("posting shipment compensation request for saga " + sagaId + " to " + url);

ParticipantFailureInfo failureInfo = new ParticipantFailureInfo(sagaId,
compensationEvent.getShipmentId(), compensationEvent.getCause());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import io.eventuate.Event;
import io.eventuate.EventUtil;
import io.eventuate.ReflectiveMutableCommandProcessingAggregate;
import org.learn.eventuate.coreapi.ParticipantFailureInfo;
import org.learn.eventuate.coreapi.ProductInfo;
import org.learn.eventuate.orderservice.command.saga.InitSagaCompensationCommand;
import org.learn.eventuate.orderservice.command.saga.InvoiceCompensatedCommand;
Expand All @@ -18,12 +17,10 @@
import org.learn.eventuate.orderservice.domain.event.InvoiceCompensatedEvent;
import org.learn.eventuate.orderservice.domain.event.InvoiceCompletedEvent;
import org.learn.eventuate.orderservice.domain.event.InvoiceFailedEvent;
import org.learn.eventuate.orderservice.domain.event.InvoiceRequestedEvent;
import org.learn.eventuate.orderservice.domain.event.OrderSagaCreatedEvent;
import org.learn.eventuate.orderservice.domain.event.ShipmentCompensatedEvent;
import org.learn.eventuate.orderservice.domain.event.ShipmentCompletedEvent;
import org.learn.eventuate.orderservice.domain.event.ShipmentFailedEvent;
import org.learn.eventuate.orderservice.domain.event.ShipmentRequestedEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -41,21 +38,18 @@ public class OrderSagaAggregate extends ReflectiveMutableCommandProcessingAggreg

public List<Event> process(StartOrderSagaCommand command) {
log.info("STARTING SAGA for order " + command.getOrderId());

productInfo = command.getProductInfo();

return EventUtil.events(new OrderSagaCreatedEvent(command.getOrderId(), command.getProductInfo()));
}

public List<Event> process(ProcessShipmentCommand command) {
log.info("received ProcessShipmentCommand for order " + orderId);

return EventUtil.events(new ShipmentCompletedEvent(command.getShipmentInfo().getShipmentId()));
}

public List<Event> process(ProcessInvoiceCommand command) {
log.info("received ProcessInvoiceCommand for order " + orderId);

return EventUtil.events(new InvoiceCompletedEvent(command.getInvoiceInfo().getInvoiceId()));
}

Expand Down Expand Up @@ -86,13 +80,11 @@ private void checkSagaCompleted() {

public List<Event> process(ProcessShipmentFailureCommand command) {
log.info("received ProcessShipmentFailureCommand for order " + orderId);

return EventUtil.events(new ShipmentFailedEvent(command.getFailureInfo()));
}

public List<Event> process(ProcessInvoiceFailureCommand command) {
log.info("received ProcessInvoiceFailureCommand for order " + orderId);

return EventUtil.events(new InvoiceFailedEvent(command.getFailureInfo()));
}

Expand All @@ -115,15 +107,16 @@ public List<Event> process(InitSagaCompensationCommand command) {
}

public List<Event> process(ShipmentCompensatedCommand command) {
log.info("received ShipmentCompensatedCommand for order " + orderId);
return EventUtil.events(new ShipmentCompensatedEvent());
}

public List<Event> process(InvoiceCompensatedCommand command) {
log.info("received InvoiceCompensatedCommand for order " + orderId);
return EventUtil.events(new InvoiceCompensatedEvent());
}

public void apply(CompensateSagaEvent event) {
log.info("Saga for order " + orderId + " is being compensated");
}

public void apply(ShipmentCompensatedEvent event) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@
import org.learn.eventuate.coreapi.OrderFiledEvent;
import org.learn.eventuate.orderservice.domain.event.CompensateSagaEvent;
import org.learn.eventuate.orderservice.domain.event.InvoiceFailedEvent;
import org.learn.eventuate.orderservice.domain.event.InvoiceRequestedEvent;
import org.learn.eventuate.orderservice.domain.event.OrderSagaCreatedEvent;
import org.learn.eventuate.orderservice.domain.event.ShipmentFailedEvent;
import org.learn.eventuate.orderservice.domain.event.ShipmentRequestedEvent;
import org.learn.eventuate.orderservice.domain.service.OrderSagaService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -28,36 +26,30 @@ public class SagaEventSubscriber {

@EventHandlerMethod
public void onOrderFiledEvent(DispatchedEvent<OrderFiledEvent> dispatchedEvent) {
//order is created - start saga
log.info("Event listener is starting saga");
OrderFiledEvent event = dispatchedEvent.getEvent();
orderSagaService.startSaga(event.getOrderId(), event.getProductInfo());
}

@EventHandlerMethod
public void onOrderSagaCreatedEvent(DispatchedEvent<OrderSagaCreatedEvent> dispatchedEvent) {
log.info("on OrderSagaCreatedEvent");
orderSagaService.requestShipment(dispatchedEvent.getEntityId(), dispatchedEvent.getEvent().getProductInfo());
orderSagaService.requestInvoice(dispatchedEvent.getEntityId(), dispatchedEvent.getEvent().getProductInfo());
}

@EventHandlerMethod
public void onShipmentFailedEvent(DispatchedEvent<ShipmentFailedEvent> dispatchedEvent) {
log.info("on ShipmentFailedEvent");
orderSagaService.initSagaCompensation(dispatchedEvent.getEntityId(),
dispatchedEvent.getEvent().getFailureInfo().getCause());
}

@EventHandlerMethod
public void onInvoiceFailedEvent(DispatchedEvent<InvoiceFailedEvent> dispatchedEvent) {
log.info("on InvoiceFailedEvent");
orderSagaService.initSagaCompensation(dispatchedEvent.getEntityId(),
dispatchedEvent.getEvent().getFailureInfo().getCause());
}

@EventHandlerMethod
public void onCompensateSagaEvent(DispatchedEvent<CompensateSagaEvent> dispatchedEvent) {
log.info("on CompensateSagaEvent");
orderSagaService.compensateSaga(dispatchedEvent.getEntityId(), dispatchedEvent.getEvent());
}
}

0 comments on commit af9e2c8

Please sign in to comment.