Java Code Examples for org.apache.mesos.v1.Protos#OfferID

The following examples show how to use org.apache.mesos.v1.Protos#OfferID . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OfferManagerImpl.java    From attic-aurora with Apache License 2.0 6 votes vote down vote up
@Timed("offer_manager_launch_task")
@Override
public void launchTask(Protos.OfferID offerId, Protos.TaskInfo task) throws LaunchException {
  // Guard against an offer being removed after we grabbed it from the iterator.
  // If that happens, the offer will not exist in hostOffers, and we can immediately
  // send it back to LOST for quick reschedule.
  // Removing while iterating counts on the use of a weakly-consistent iterator being used,
  // which is a feature of ConcurrentSkipListSet.
  if (hostOffers.remove(offerId)) {
    try {
      Protos.Offer.Operation launch = Protos.Offer.Operation.newBuilder()
          .setType(Protos.Offer.Operation.Type.LAUNCH)
          .setLaunch(Protos.Offer.Operation.Launch.newBuilder().addTaskInfos(task))
          .build();
      driver.acceptOffers(offerId, ImmutableList.of(launch), getOfferFilter());
    } catch (IllegalStateException e) {
      // TODO(William Farner): Catch only the checked exception produced by Driver
      // once it changes from throwing IllegalStateException when the driver is not yet
      // registered.
      throw new LaunchException("Failed to launch task.", e);
    }
  } else {
    offerRaces.incrementAndGet();
    throw new LaunchException("Offer no longer exists in offer queue, likely data race.");
  }
}
 
Example 2
Source File: SchedulerCalls.java    From mesos-rxjava with Apache License 2.0 5 votes vote down vote up
/**
 * Utility method to more succinctly construct a {@link Call Call} of type {@link Type#DECLINE DECLINE}.
 * <p>
 *
 * @param frameworkId    The {@link Protos.FrameworkID FrameworkID} to be set on the {@link Call}
 * @param offerIds       A list of {@link Protos.OfferID OfferID} from the
 *                       {@link Protos.Offer}s received from Mesos.
 * @return  A {@link Call} with a configured {@link Decline}.
 */
@NotNull
public static Call decline(@NotNull final Protos.FrameworkID frameworkId, @NotNull final List<Protos.OfferID> offerIds) {
    return newBuilder()
        .setFrameworkId(frameworkId)
        .setType(Type.DECLINE)
        .setDecline(
            Decline.newBuilder()
                .addAllOfferIds(offerIds)
        )
        .build();
}
 
Example 3
Source File: SchedulerDriverService.java    From attic-aurora with Apache License 2.0 5 votes vote down vote up
@Override
public void acceptOffers(
    Protos.OfferID offerId,
    Collection<Protos.Offer.Operation> operations,
    Protos.Filters filter) {
  ensureRunning();

  OfferID convertedOfferId = ProtosConversion.convert(offerId);
  Collection<Operation> convertedOperations =
      Collections2.transform(operations, ProtosConversion::convert);
  Filters convertedFilter = ProtosConversion.convert(filter);

  Futures.getUnchecked(driverFuture)
      .acceptOffers(ImmutableList.of(convertedOfferId), convertedOperations, convertedFilter);
}
 
Example 4
Source File: SchedulerDriverService.java    From attic-aurora with Apache License 2.0 5 votes vote down vote up
@Override
public void declineOffer(Protos.OfferID offerId, Protos.Filters filter) {
  ensureRunning();

  OfferID convertedOfferId = ProtosConversion.convert(offerId);
  Filters convertedFilter = ProtosConversion.convert(filter);

  Futures.getUnchecked(driverFuture).declineOffer(convertedOfferId, convertedFilter);
}
 
Example 5
Source File: HostOffers.java    From attic-aurora with Apache License 2.0 5 votes vote down vote up
synchronized boolean remove(Protos.OfferID id) {
  HostOffer removed = offersById.remove(id);
  if (removed != null) {
    offers.remove(removed);
    offersBySlave.remove(removed.getOffer().getAgentId());
    offersByHost.remove(removed.getOffer().getHostname());
  }
  globallyBannedOffers.remove(id);
  return removed != null;
}
 
Example 6
Source File: OfferManagerImpl.java    From attic-aurora with Apache License 2.0 5 votes vote down vote up
@Override
public boolean cancel(final Protos.OfferID offerId) {
  boolean success = removeFromHostOffers(offerId);
  if (!success) {
    // This will happen rarely when we race to process this rescind against accepting the offer
    // to launch a task.
    // If it happens frequently, we are likely processing rescinds before the offer itself.
    LOG.warn("Failed to cancel offer: {}.", offerId.getValue());
    this.offerCancelFailures.incrementAndGet();
  }
  return success;
}
 
Example 7
Source File: OfferManagerImpl.java    From attic-aurora with Apache License 2.0 5 votes vote down vote up
private boolean removeFromHostOffers(final Protos.OfferID offerId) {
  requireNonNull(offerId);

  // The small risk of inconsistency is acceptable here - if we have an accept/remove race
  // on an offer, the master will mark the task as LOST and it will be retried.
  return hostOffers.remove(offerId);
}
 
Example 8
Source File: FakeDriver.java    From attic-aurora with Apache License 2.0 4 votes vote down vote up
@Override
public void acceptOffers(Protos.OfferID offerId, Collection<Protos.Offer.Operation> operations,
    Protos.Filters filter) {
  // no-op
}
 
Example 9
Source File: HostOffers.java    From attic-aurora with Apache License 2.0 4 votes vote down vote up
@VisibleForTesting
synchronized Set<Pair<Protos.OfferID, TaskGroupKey>> getStaticBans() {
  return staticallyBannedOffers.asMap().keySet();
}
 
Example 10
Source File: HostOffers.java    From attic-aurora with Apache License 2.0 4 votes vote down vote up
@VisibleForTesting
synchronized void addStaticGroupBan(Protos.OfferID offerId, TaskGroupKey groupKey) {
  if (offersById.containsKey(offerId)) {
    staticallyBannedOffers.put(Pair.of(offerId, groupKey), true);
  }
}
 
Example 11
Source File: FakeOfferManager.java    From attic-aurora with Apache License 2.0 4 votes vote down vote up
@Override
public void ban(Protos.OfferID offerId) {
  // no-op
}
 
Example 12
Source File: OfferManagerImpl.java    From attic-aurora with Apache License 2.0 4 votes vote down vote up
/**
 * Exclude an offer that results in a static mismatch from further attempts to match against all
 * tasks from the same group.
 */
@VisibleForTesting
void banForTaskGroup(Protos.OfferID offerId, TaskGroupKey groupKey) {
  hostOffers.addStaticGroupBan(offerId, groupKey);
}
 
Example 13
Source File: OfferManagerImpl.java    From attic-aurora with Apache License 2.0 4 votes vote down vote up
/**
 * Get all static bans.
 */
@VisibleForTesting
Set<Pair<Protos.OfferID, TaskGroupKey>> getStaticBans() {
  return hostOffers.getStaticBans();
}
 
Example 14
Source File: OfferManagerImpl.java    From attic-aurora with Apache License 2.0 4 votes vote down vote up
@Override
public void ban(Protos.OfferID offerId) {
  hostOffers.addGlobalBan(offerId);
}
 
Example 15
Source File: OfferManagerImpl.java    From attic-aurora with Apache License 2.0 4 votes vote down vote up
private void decline(Protos.OfferID id) {
  LOG.debug("Declining offer {}", id);
  driver.declineOffer(id, getOfferFilter());
}
 
Example 16
Source File: FakeOfferManager.java    From attic-aurora with Apache License 2.0 4 votes vote down vote up
@Override
public boolean cancel(Protos.OfferID offerId) {
  return false;
}
 
Example 17
Source File: SchedulerDriverService.java    From attic-aurora with Apache License 2.0 4 votes vote down vote up
@Override
public void acceptInverseOffer(Protos.OfferID offerID, Protos.Filters filter) {
  throw new UnsupportedOperationException("SchedulerDriver does not support inverse offers");
}
 
Example 18
Source File: FakeDriver.java    From attic-aurora with Apache License 2.0 4 votes vote down vote up
@Override
public void declineOffer(Protos.OfferID offerId, Protos.Filters filters) {
  // no-op
}
 
Example 19
Source File: ProtosConversion.java    From attic-aurora with Apache License 2.0 4 votes vote down vote up
public static org.apache.mesos.Protos.OfferID convert(Protos.OfferID id) {
  return convert(id, org.apache.mesos.Protos.OfferID.newBuilder());
}
 
Example 20
Source File: ProtosConversion.java    From attic-aurora with Apache License 2.0 4 votes vote down vote up
public static Protos.OfferID convert(org.apache.mesos.Protos.OfferID id) {
  return convert(id, Protos.OfferID.newBuilder());
}