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

The following examples show how to use org.apache.mesos.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: AbstractCassandraSchedulerTest.java    From cassandra-mesos-deprecated with Apache License 2.0 6 votes vote down vote up
protected Tuple2<Protos.TaskInfo, CassandraFrameworkProtos.TaskDetails> launchTask(final Tuple2<Protos.SlaveID, String> slave, final CassandraFrameworkProtos.TaskDetails.TaskDetailsType taskType) throws InvalidProtocolBufferException {
    final Protos.Offer offer = createOffer(slave);

    scheduler.resourceOffers(driver, Collections.singletonList(offer));

    assertTrue(driver.declinedOffers().isEmpty());
    final Tuple2<Collection<Protos.OfferID>, Collection<Protos.TaskInfo>> launchTasks = driver.launchTasks();
    assertTrue(driver.submitTasks().isEmpty());
    assertTrue(driver.killTasks().isEmpty());

    assertEquals(1, launchTasks._2.size());

    final Protos.TaskInfo taskInfo = launchTasks._2.iterator().next();

    final CassandraFrameworkProtos.TaskDetails taskDetails = taskDetails(taskInfo);
    assertEquals(taskType, taskDetails.getType());
    return Tuple2.tuple2(taskInfo, taskDetails);
}
 
Example 2
Source File: OfferAccepter.java    From dcos-commons with Apache License 2.0 6 votes vote down vote up
private static void logOperations(
    String agentId,
    Collection<Protos.OfferID> offerIds,
    Collection<Protos.Offer.Operation> operations)
{
  LOGGER.info("Accepting {} offer{} for agent {} with {} operation{}: {}",
      offerIds.size(),
      offerIds.size() == 1 ? "" : "s",
      agentId,
      operations.size(),
      operations.size() == 1 ? "" : "s",
      offerIds.stream().map(Protos.OfferID::getValue).collect(Collectors.toSet()));
  for (Protos.Offer.Operation op : operations) {
    LOGGER.info("  {}", TextFormat.shortDebugString(op));
  }
}
 
Example 3
Source File: OfferProcessor.java    From dcos-commons with Apache License 2.0 6 votes vote down vote up
/**
 * Decline unused {@link org.apache.mesos.Protos.Offer}s.
 *
 * @param unusedOffers  The collection of Offers to decline
 * @param refuseSeconds The number of seconds for which the offers should be refused
 */
private static void declineOffers(Collection<Protos.Offer> unusedOffers, int refuseSeconds) {
  Collection<Protos.OfferID> offerIds = unusedOffers.stream()
      .map(offer -> offer.getId())
      .collect(Collectors.toList());
  LOGGER.info("Declining {} unused offer{} for {} seconds: {}",
      offerIds.size(),
      offerIds.size() == 1 ? "" : "s",
      refuseSeconds,
      offerIds.stream().map(Protos.OfferID::getValue).collect(Collectors.toList()));

  final Protos.Filters filters = Protos.Filters.newBuilder()
      .setRefuseSeconds(refuseSeconds)
      .build();

  offerIds.forEach(offerId -> Driver.getInstance().declineOffer(offerId, filters));
}
 
Example 4
Source File: CassandraSchedulerTest.java    From dcos-cassandra-service with Apache License 2.0 6 votes vote down vote up
private void runReconcile(QueuedSchedulerDriver driver) {
    while (!scheduler.getReconciler().isReconciled()) {

        final Protos.Offer offer = TestUtils.generateOffer(frameworkId.getValue(), 4, 10240, 10240);
        scheduler.resourceOffers(driver, Arrays.asList(offer));
        final Collection<Protos.TaskStatus> taskStatuses = driver.drainReconciling();
        if (taskStatuses.isEmpty()) {
            // All reconciled
            cassandraState.getTaskStatuses().forEach(status -> scheduler.statusUpdate(driver, status));
        } else {
            taskStatuses.forEach(status -> scheduler.statusUpdate(driver, status));
        }

        if (!scheduler.getReconciler().isReconciled()) {
            final Collection<Protos.OfferID> declined = driver.drainDeclined();
            assertEquals(1, declined.size());
            assertEquals(declined.iterator().next(), offer.getId());
        }
    }
}
 
Example 5
Source File: AbstractCassandraSchedulerTest.java    From cassandra-mesos-deprecated with Apache License 2.0 6 votes vote down vote up
protected CassandraFrameworkProtos.TaskDetails submitTask(final Tuple2<Protos.SlaveID, String> slave, final CassandraFrameworkProtos.TaskDetails.TaskDetailsType taskType) {
    final Protos.Offer offer = createOffer(slave);

    scheduler.resourceOffers(driver, Collections.singletonList(offer));

    assertFalse(driver.declinedOffers().isEmpty());
    final Tuple2<Collection<Protos.OfferID>, Collection<Protos.TaskInfo>> launchTasks = driver.launchTasks();
    assertTrue(launchTasks._2.isEmpty());
    final Collection<Tuple2<Protos.ExecutorID, CassandraFrameworkProtos.TaskDetails>> submitTasks = driver.submitTasks();
    assertTrue(driver.killTasks().isEmpty());

    assertEquals(1, submitTasks.size());

    final CassandraFrameworkProtos.TaskDetails taskDetails = submitTasks.iterator().next()._2;
    assertEquals(taskType, taskDetails.getType());
    return taskDetails;
}
 
Example 6
Source File: AbstractCassandraSchedulerTest.java    From cassandra-mesos-deprecated with Apache License 2.0 6 votes vote down vote up
protected Protos.TaskInfo launchTaskOnAny(final CassandraFrameworkProtos.TaskDetails.TaskDetailsType taskType) throws InvalidProtocolBufferException {
    for (final Tuple2<Protos.SlaveID, String> slave : slaves) {
        final Protos.Offer offer = createOffer(slave);

        scheduler.resourceOffers(driver, Collections.singletonList(offer));

        final Tuple2<Collection<Protos.OfferID>, Collection<Protos.TaskInfo>> launchTasks = driver.launchTasks();
        if (!driver.declinedOffers().isEmpty())
            continue;

        assertEquals(1, launchTasks._2.size());
        assertTrue(driver.submitTasks().isEmpty());
        assertTrue(driver.killTasks().isEmpty());

        final Protos.TaskInfo taskInfo = launchTasks._2.iterator().next();

        final CassandraFrameworkProtos.TaskDetails taskDetails = taskDetails(taskInfo);
        assertEquals(taskType, taskDetails.getType());
        return taskInfo;
    }
    return null;
}
 
Example 7
Source File: IgniteSchedulerSelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override public Protos.Status launchTasks(Collection<Protos.OfferID> offerIds,
    Collection<Protos.TaskInfo> tasks, Protos.Filters filters) {
    launchedTask = tasks;

    return null;
}
 
Example 8
Source File: IgniteSchedulerSelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override public Protos.Status launchTasks(Protos.OfferID offerId, Collection<Protos.TaskInfo> tasks,
    Protos.Filters filters) {
    launchedTask = tasks;

    return null;
}
 
Example 9
Source File: MultiServiceEventClient.java    From dcos-commons with Apache License 2.0 5 votes vote down vote up
/**
 * Finds the requested {@link OfferResources} value in the provided map[offerId], initializing the entry if needed.
 */
private static OfferResources getEntry(
    Map<Protos.OfferID, OfferResources> map,
    Protos.Offer offer)
{
  // Initialize entry if absent
  return map.computeIfAbsent(offer.getId(), k -> new OfferResources(offer));
}
 
Example 10
Source File: OfferProcessorTest.java    From dcos-commons with Apache License 2.0 5 votes vote down vote up
@Test
public void testDeclineCall() {
    final List<Protos.Offer> offers = Arrays.asList(getOffer());
    final List<Protos.OfferID> offerIds = offers.stream().map(Protos.Offer::getId).collect(Collectors.toList());
    Driver.setDriver(mockSchedulerDriver);
    OfferProcessor.declineShort(offers);
    verify(mockSchedulerDriver).declineOffer(eq(offerIds.get(0)), any());
}
 
Example 11
Source File: OfferUtils.java    From dcos-commons with Apache License 2.0 5 votes vote down vote up
/**
 * Filters out Offers which have pending Operations against Mesos, and returns a list of any remaining offers.
 *
 * @param offers          An {@link org.apache.mesos.Protos.Offer} collection containing both ACCEPTED and
 *                        UNACCEPTED offers
 * @param recommendations A collection of offer recommendations, which hold accepted offers
 * @return Offers that are not ACCEPTED yet, or an empty list if there are no UNACCEPTED offers left
 */
public static List<Protos.Offer> filterOutAcceptedOffers(
    Collection<Protos.Offer> offers, Collection<? extends OfferRecommendation> recommendations)
{
  // Only filter out offers which specifically have operations to be sent to Mesos. If an offer just led to some
  // internal bookkeeping updates then don't consider it "used".
  Set<Protos.OfferID> usedOfferIds = recommendations.stream()
      .filter(rec -> rec.getOperation().isPresent())
      .map(rec -> rec.getOfferId())
      .collect(Collectors.toSet());
  return offers.stream()
      .filter(offer -> !usedOfferIds.contains(offer.getId()))
      .collect(Collectors.toList());
}
 
Example 12
Source File: MesosResourceManager.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void offerRescinded(SchedulerDriver driver, final Protos.OfferID offerId) {
	runAsync(new Runnable() {
		@Override
		public void run() {
			MesosResourceManager.this.offerRescinded(new OfferRescinded(offerId));
		}
	});
}
 
Example 13
Source File: FakeSchedulerDriver.java    From attic-aurora with Apache License 2.0 5 votes vote down vote up
@Override
public Protos.Status launchTasks(
    Protos.OfferID offerId,
    Collection<Protos.TaskInfo> tasks,
    Protos.Filters filters) {
  return null;
}
 
Example 14
Source File: SimulatedRemoteMesosSchedulerDriver.java    From titus-control-plane with Apache License 2.0 4 votes vote down vote up
@Override
public Protos.Status launchTasks(Protos.OfferID offerId, Collection<Protos.TaskInfo> tasks, Protos.Filters filters) {
    return launchTasks(Collections.singleton(offerId), tasks);
}
 
Example 15
Source File: DefaultRecoveryPlanManagerTest.java    From dcos-commons with Apache License 2.0 4 votes vote down vote up
private static Collection<Protos.OfferID> distinctOffers(Collection<OfferRecommendation> recs) {
    return recs.stream().map(rec -> rec.getOfferId()).distinct().collect(Collectors.toList());
}
 
Example 16
Source File: IgniteSchedulerSelfTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/** {@inheritDoc} */
@Override public Protos.Status launchTasks(Protos.OfferID offerId, Collection<Protos.TaskInfo> tasks) {
    launchedTask = tasks;

    return null;
}
 
Example 17
Source File: SchedulerProxy.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public void offerRescinded(SchedulerDriver driver, Protos.OfferID offerId) {
	mesosActor.tell(new OfferRescinded(offerId), ActorRef.noSender());
}
 
Example 18
Source File: IgniteSchedulerSelfTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/** {@inheritDoc} */
@Override public Protos.Status declineOffer(Protos.OfferID offerId, Protos.Filters filters) {
    declinedOffer = offerId;

    return null;
}
 
Example 19
Source File: AcceptOffers.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
public AcceptOffers(String hostname, Collection<Protos.OfferID> offerIds, Collection<Protos.Offer.Operation> operations) {
	this.hostname = hostname;
	this.offerIds = offerIds;
	this.operations = operations;
	this.filters = Protos.Filters.newBuilder().build();
}
 
Example 20
Source File: IgniteSchedulerSelfTest.java    From ignite with Apache License 2.0 3 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testDeclineByMem() throws Exception {
    Protos.Offer offer = createOffer("hostname", 4, 1024);

    DriverMock mock = new DriverMock();

    ClusterProperties clustProp = new ClusterProperties();
    clustProp.memory(512);

    scheduler.setClusterProps(clustProp);

    scheduler.resourceOffers(mock, Collections.singletonList(offer));

    assertNotNull(mock.launchedTask);
    assertEquals(1, mock.launchedTask.size());

    Protos.TaskInfo taskInfo = mock.launchedTask.iterator().next();

    assertEquals(4.0, resources(taskInfo.getResourcesList(), IgniteScheduler.CPU), 0);
    assertEquals(512.0, resources(taskInfo.getResourcesList(), IgniteScheduler.MEM), 0);

    mock.clear();

    scheduler.resourceOffers(mock, Collections.singletonList(offer));

    assertNull(mock.launchedTask);

    Protos.OfferID declinedOffer = mock.declinedOffer;

    assertEquals(offer.getId(), declinedOffer);
}