Search in sources :

Example 91 with Subscribe

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));
    }
}
Also used : Scheduler(org.apache.mesos.Scheduler) TaskStatus(org.apache.mesos.Protos.TaskStatus) UPID(com.groupon.mesos.util.UPID) RemoteMessageEnvelope(com.groupon.mesos.scheduler.SchedulerMessageEnvelope.RemoteMessageEnvelope) StatusUpdateAcknowledgementMessage(mesos.internal.Messages.StatusUpdateAcknowledgementMessage) StatusUpdateMessage(mesos.internal.Messages.StatusUpdateMessage) FrameworkID(org.apache.mesos.Protos.FrameworkID) SchedulerDriver(org.apache.mesos.SchedulerDriver) Subscribe(com.google.common.eventbus.Subscribe)

Example 92 with Subscribe

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);
    }
}
Also used : MasterInfo(org.apache.mesos.Protos.MasterInfo) ArrayList(java.util.ArrayList) Subscribe(com.google.common.eventbus.Subscribe)

Example 93 with Subscribe

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);
    }
}
Also used : MasterInfo(org.apache.mesos.Protos.MasterInfo) Subscribe(com.google.common.eventbus.Subscribe)

Example 94 with Subscribe

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());
                }
            };
        }
    });
}
Also used : Scheduler(org.apache.mesos.Scheduler) FrameworkRegisteredMessage(mesos.internal.Messages.FrameworkRegisteredMessage) FrameworkID(org.apache.mesos.Protos.FrameworkID) SchedulerDriver(org.apache.mesos.SchedulerDriver) Subscribe(com.google.common.eventbus.Subscribe)

Example 95 with Subscribe

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);
    }
}
Also used : Account(org.killbill.billing.account.api.Account) ArrayList(java.util.ArrayList) PaymentApiException(org.killbill.billing.payment.api.PaymentApiException) InternalCallContext(org.killbill.billing.callcontext.InternalCallContext) InternalCallContext(org.killbill.billing.callcontext.InternalCallContext) CallContext(org.killbill.billing.util.callcontext.CallContext) BigDecimal(java.math.BigDecimal) PaymentTransaction(org.killbill.billing.payment.api.PaymentTransaction) PluginProperty(org.killbill.billing.payment.api.PluginProperty) Payment(org.killbill.billing.payment.api.Payment) AccountApiException(org.killbill.billing.account.api.AccountApiException) AllowConcurrentEvents(com.google.common.eventbus.AllowConcurrentEvents) Subscribe(com.google.common.eventbus.Subscribe)

Aggregations

Subscribe (com.google.common.eventbus.Subscribe)179 GuildMessageReceivedEvent (net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent)46 SimpleCommand (net.kodehawa.mantarobot.core.modules.commands.SimpleCommand)44 MessageEmbed (net.dv8tion.jda.core.entities.MessageEmbed)29 EmoteReference (net.kodehawa.mantarobot.utils.commands.EmoteReference)26 MantaroData (net.kodehawa.mantarobot.data.MantaroData)25 List (java.util.List)23 Category (net.kodehawa.mantarobot.core.modules.commands.base.Category)22 Utils (net.kodehawa.mantarobot.utils.Utils)22 CommandRegistry (net.kodehawa.mantarobot.core.CommandRegistry)21 Module (net.kodehawa.mantarobot.core.modules.Module)21 EmbedBuilder (net.dv8tion.jda.core.EmbedBuilder)18 TimeUnit (java.util.concurrent.TimeUnit)16 Collectors (java.util.stream.Collectors)16 MantaroBot (net.kodehawa.mantarobot.MantaroBot)15 Player (net.kodehawa.mantarobot.db.entities.Player)15 DiscordUtils (net.kodehawa.mantarobot.utils.DiscordUtils)15 RateLimiter (net.kodehawa.mantarobot.utils.commands.RateLimiter)14 SubCommand (net.kodehawa.mantarobot.core.modules.commands.SubCommand)13 DBGuild (net.kodehawa.mantarobot.db.entities.DBGuild)13