use of com.google.common.eventbus.Subscribe in project jesos by groupon.
the class LocalSchedulerMessageProcessor method frameworkStatusUpdate.
@Subscribe
public void frameworkStatusUpdate(final StatusUpdateMessageEnvelope envelope) throws IOException {
checkState(envelope.getRecipient().equals(context.getDriverUPID()), "Received a remote message for local delivery");
final UPID sender = envelope.getSender();
if (!driverIsConnected(sender)) {
return;
}
final StatusUpdateMessage statusUpdateMessage = envelope.getMessage();
final FrameworkID frameworkId = context.getFrameworkId();
final FrameworkID messageFrameworkId = statusUpdateMessage.getUpdate().getFrameworkId();
checkState(frameworkId.equals(messageFrameworkId), "Received Message for framework %s, but local id is %s", messageFrameworkId, frameworkId);
final TaskStatus.Builder taskStatusBuilder = TaskStatus.newBuilder(statusUpdateMessage.getUpdate().getStatus());
final TaskStatus taskStatus;
// If the update is driver-generated or master-generated, it does not require acknowledgement (from Mesos source code, sched.cpp).
final Optional<UPID> pid = statusUpdateMessage.hasPid() ? Optional.of(UPID.create(statusUpdateMessage.getPid())) : Optional.<UPID>absent();
final boolean noAckRequired = envelope.getSender().equals(context.getDriverUPID()) || pid.isPresent() && pid.get().equals(context.getDriverUPID());
if (noAckRequired) {
taskStatus = taskStatusBuilder.clearUuid().build();
} else {
taskStatus = taskStatusBuilder.setUuid(statusUpdateMessage.getUpdate().getUuid()).build();
}
eventBus.post(new SchedulerCallback() {
@Override
public Runnable getCallback(final Scheduler scheduler, final SchedulerDriver schedulerDriver) {
return new Runnable() {
@Override
public void run() {
scheduler.statusUpdate(schedulerDriver, taskStatus);
}
};
}
});
if (implicitAcknowledgements && !noAckRequired) {
final StatusUpdateAcknowledgementMessage statusUpdateAcknowledgementMessage = StatusUpdateAcknowledgementMessage.newBuilder().setFrameworkId(frameworkId).setSlaveId(statusUpdateMessage.getUpdate().getSlaveId()).setTaskId(taskStatus.getTaskId()).setUuid(statusUpdateMessage.getUpdate().getUuid()).build();
eventBus.post(new RemoteMessageEnvelope(context.getDriverUPID(), context.getMasterUPID(), statusUpdateAcknowledgementMessage));
}
}
use of com.google.common.eventbus.Subscribe in project jesos by groupon.
the class ZookeeperMasterDetector method processMasterUpdate.
@Subscribe
public void processMasterUpdate(final MasterUpdateMessage message) {
final Set<String> currentNodes = message.getNodes();
final Set<String> nodesToRemove = ImmutableSet.copyOf(Sets.difference(nodeCache.keySet(), currentNodes));
final Set<String> nodesToAdd = ImmutableSet.copyOf(Sets.difference(currentNodes, nodeCache.keySet()));
for (final String node : nodesToAdd) {
final String path = zookeeperPath + "/" + node;
final MasterInfo masterInfo = client.readData(path);
nodeCache.put(node, masterInfo);
}
for (final String node : nodesToRemove) {
nodeCache.remove(node);
}
LOG.debug("Processed event, active nodes are %s", nodeCache.entrySet());
final MasterInfo masterInfo = getMaster();
if (masterInfo == null) {
LOG.debug("No current master exists!");
} else {
LOG.debug("Current master is %s", UPID.create(masterInfo.getPid()).asString());
}
final List<DetectMessage> detectMessages = new ArrayList<>(futures.size());
futures.drainTo(detectMessages);
for (final DetectMessage detectMessage : detectMessages) {
processDetect(detectMessage);
}
}
use of com.google.common.eventbus.Subscribe in project jesos by groupon.
the class ZookeeperMasterDetector method processDetect.
@Subscribe
public void processDetect(final DetectMessage message) {
final SettableFuture<MasterInfo> future = message.getFuture();
final MasterInfo previous = message.getPrevious();
final MasterInfo currentLeader = getMaster();
if (!Objects.equal(currentLeader, previous)) {
LOG.debug("Master has changed: %s -> %s", previous, currentLeader);
future.set(currentLeader);
} else {
LOG.debug("Master unchanged, queueing");
futures.add(message);
}
}
use of com.google.common.eventbus.Subscribe in project jesos by groupon.
the class LocalSchedulerMessageProcessor method frameworkRegistered.
@Subscribe
public void frameworkRegistered(final FrameworkRegisteredMessageEnvelope envelope) {
checkState(envelope.getRecipient().equals(context.getDriverUPID()), "Received a remote message for local delivery");
final FrameworkRegisteredMessage frameworkRegisteredMessage = envelope.getMessage();
if (!masterIsValid(frameworkRegisteredMessage.getMasterInfo())) {
return;
}
final FrameworkID frameworkId = frameworkRegisteredMessage.getFrameworkId();
context.connected();
context.setFailover(false);
context.setFrameworkId(frameworkId);
eventBus.post(new SchedulerCallback() {
@Override
public Runnable getCallback(final Scheduler scheduler, final SchedulerDriver schedulerDriver) {
return new Runnable() {
@Override
public void run() {
scheduler.registered(schedulerDriver, frameworkId, context.getMaster());
}
};
}
});
}
use of com.google.common.eventbus.Subscribe in project killbill by killbill.
the class PaymentBusEventHandler method processInvoiceEvent.
@AllowConcurrentEvents
@Subscribe
public void processInvoiceEvent(final InvoiceCreationInternalEvent event) {
log.info("Received invoice creation notification for accountId='{}', invoiceId='{}'", event.getAccountId(), event.getInvoiceId());
final Collection<PluginProperty> properties = new ArrayList<PluginProperty>();
final PluginProperty propertyInvoiceId = new PluginProperty(InvoicePaymentControlPluginApi.PROP_IPCD_INVOICE_ID, event.getInvoiceId().toString(), false);
properties.add(propertyInvoiceId);
final InternalCallContext internalContext = internalCallContextFactory.createInternalCallContext(event.getSearchKey2(), event.getSearchKey1(), "PaymentRequestProcessor", CallOrigin.INTERNAL, UserType.SYSTEM, event.getUserToken());
final CallContext callContext = internalCallContextFactory.createCallContext(internalContext);
// We let the plugin compute how much should be paid
final BigDecimal amountToBePaid = null;
final List<String> paymentControlPluginNames = paymentConfig.getPaymentControlPluginNames(internalContext) != null ? new LinkedList<String>(paymentConfig.getPaymentControlPluginNames(internalContext)) : new LinkedList<String>();
paymentControlPluginNames.add(InvoicePaymentControlPluginApi.PLUGIN_NAME);
final String transactionType = TransactionType.PURCHASE.name();
Account account = null;
Payment payment = null;
PaymentTransaction paymentTransaction = null;
try {
account = accountApi.getAccountById(event.getAccountId(), internalContext);
logEnterAPICall(log, transactionType, account, account.getPaymentMethodId(), null, null, amountToBePaid, account.getCurrency(), null, null, null, paymentControlPluginNames);
payment = pluginControlPaymentProcessor.createPurchase(false, account, account.getPaymentMethodId(), null, amountToBePaid, account.getCurrency(), null, null, properties, paymentControlPluginNames, callContext, internalContext);
paymentTransaction = payment.getTransactions().get(payment.getTransactions().size() - 1);
} catch (final AccountApiException e) {
log.warn("Failed to process invoice payment", e);
} catch (final PaymentApiException e) {
// Log as warn unless nothing left to be paid
if (e.getCode() != ErrorCode.PAYMENT_PLUGIN_API_ABORTED.getCode()) {
log.warn("Failed to process invoice payment {}", e.toString());
}
} finally {
logExitAPICall(log, transactionType, account, payment != null ? payment.getPaymentMethodId() : null, payment != null ? payment.getId() : null, paymentTransaction != null ? paymentTransaction.getId() : null, paymentTransaction != null ? paymentTransaction.getProcessedAmount() : null, paymentTransaction != null ? paymentTransaction.getProcessedCurrency() : null, payment != null ? payment.getExternalKey() : null, paymentTransaction != null ? paymentTransaction.getExternalKey() : null, paymentTransaction != null ? paymentTransaction.getTransactionStatus() : null, paymentControlPluginNames, null);
}
}
Aggregations