org.apache.mesos.Protos.OfferID Java Examples

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: InternalSchedulerDriver.java    From jesos with Apache License 2.0 6 votes vote down vote up
@Override
public Status declineOffer(final OfferID offerId, final Filters filters)
{
    checkNotNull(offerId, "offerId is null");
    checkNotNull(filters, "filters is null");

    if (!context.isStateMachine(DRIVER_RUNNING)) {
        return context.getStateMachine();
    }

    final LaunchTasksMessage message = LaunchTasksMessage.newBuilder()
        .setFrameworkId(context.getFrameworkId())
        .addOfferIds(offerId)
        .setFilters(filters)
        .build();

    doLaunchTasks(message);
    return context.getStateMachine();
}
 
Example #2
Source File: StormSchedulerImplTest.java    From storm with Apache License 2.0 6 votes vote down vote up
@Before
public void initialize() {
  driver = null;
  stormSchedulerImpl = new StormSchedulerImpl(driver);
  Map<String, Object> mesosStormConf = new HashMap<>();
  stormSchedulerImpl.prepare(mesosStormConf);

  map = new HashMap<OfferID, Offer>();

  topologiesMissingAssignments = new HashSet<>();
  topologiesMissingAssignments.add("test-topology1-65-1442255385");
  topologiesMissingAssignments.add("test-topology1-65-1442255385");

  existingSupervisors = new ArrayList<>();
  existingSupervisors.add(new SupervisorDetails(MesosCommon.supervisorId(sampleFrameworkName, sampleHost, "test-topology1-65-1442255385"), sampleHost, null, null));
  existingSupervisors.add(new SupervisorDetails(MesosCommon.supervisorId(sampleFrameworkName, sampleHost, "test-topology10-65-1442255385"), sampleHost, null, null));

  topologyMap = new HashMap<>();
  topologyMap.put(sampleTopologyId, TestUtils.constructTopologyDetails(sampleTopologyId, 1, 0.1, 100));
  topologies = new Topologies(topologyMap);

  mesosWorkerSlotMap = new HashMap<>();
}
 
Example #3
Source File: LaunchTaskTest.java    From storm with Apache License 2.0 6 votes vote down vote up
/**
 * Setup testing target & sample data.
 */
public LaunchTaskTest()
{
  SlaveID slaveID = SlaveID.newBuilder().setValue("s1").build();
  this.sampleTaskInfo =
      TaskInfo.newBuilder()
              .setName("t1").setSlaveId(slaveID)
              .setTaskId(TaskID.newBuilder().setValue("id2"))
              .setExecutor(
                  ExecutorInfo.newBuilder()
                              .setExecutorId(ExecutorID.newBuilder().setValue("e1"))
                              .setCommand(CommandInfo.getDefaultInstance()))
              .build();
  this.sampleOffer =
      Offer.newBuilder()
           .setHostname("h1").setSlaveId(slaveID)
           .setId(OfferID.newBuilder().setValue("id1"))
           .setFrameworkId(FrameworkID.newBuilder().setValue("f1").build())
           .build();
  this.target = new LaunchTask(sampleTaskInfo, sampleOffer);
}
 
Example #4
Source File: InternalSchedulerDriver.java    From jesos with Apache License 2.0 6 votes vote down vote up
@Override
public Status declineOffer(final OfferID offerId)
{
    checkNotNull(offerId, "offerId is null");

    if (!context.isStateMachine(DRIVER_RUNNING)) {
        return context.getStateMachine();
    }

    final LaunchTasksMessage message = LaunchTasksMessage.newBuilder()
        .setFrameworkId(context.getFrameworkId())
        .addOfferIds(offerId)
        .setFilters(Filters.newBuilder().build())
        .build();

    doLaunchTasks(message);
    return context.getStateMachine();
}
 
Example #5
Source File: InternalSchedulerDriver.java    From jesos with Apache License 2.0 6 votes vote down vote up
@Override
public Status launchTasks(final Collection<OfferID> offerIds, final Collection<TaskInfo> tasks, final Filters filters)
{
    checkNotNull(offerIds, "offerIds is null");
    checkNotNull(tasks, "tasks is null");
    checkNotNull(filters, "filters is null");

    if (!context.isStateMachine(DRIVER_RUNNING)) {
        return context.getStateMachine();
    }

    final LaunchTasksMessage message = LaunchTasksMessage.newBuilder()
        .setFrameworkId(context.getFrameworkId())
        .addAllOfferIds(offerIds)
        .addAllTasks(tasks)
        .setFilters(filters)
        .build();

    doLaunchTasks(message);
    return context.getStateMachine();
}
 
Example #6
Source File: InternalSchedulerDriver.java    From jesos with Apache License 2.0 6 votes vote down vote up
@Override
public Status launchTasks(final Collection<OfferID> offerIds, final Collection<TaskInfo> tasks)
{
    checkNotNull(offerIds, "offerIds is null");
    checkNotNull(tasks, "tasks is null");

    if (!context.isStateMachine(DRIVER_RUNNING)) {
        return context.getStateMachine();
    }

    final LaunchTasksMessage message = LaunchTasksMessage.newBuilder()
        .setFrameworkId(context.getFrameworkId())
        .addAllOfferIds(offerIds)
        .addAllTasks(tasks)
        .setFilters(Filters.newBuilder().build())
        .build();

    doLaunchTasks(message);
    return context.getStateMachine();
}
 
Example #7
Source File: InternalSchedulerDriver.java    From jesos with Apache License 2.0 6 votes vote down vote up
@Override
public Status launchTasks(final OfferID offerId, final Collection<TaskInfo> tasks, final Filters filters)
{
    checkNotNull(offerId, "offerId is null");
    checkNotNull(tasks, "tasks is null");
    checkNotNull(filters, "filters is null");

    if (!context.isStateMachine(DRIVER_RUNNING)) {
        return context.getStateMachine();
    }

    final LaunchTasksMessage message = LaunchTasksMessage.newBuilder()
        .setFrameworkId(context.getFrameworkId())
        .addOfferIds(offerId)
        .addAllTasks(tasks)
        .setFilters(filters)
        .build();

    doLaunchTasks(message);
    return context.getStateMachine();
}
 
Example #8
Source File: InternalSchedulerDriver.java    From jesos with Apache License 2.0 6 votes vote down vote up
@Override
public Status launchTasks(final OfferID offerId, final Collection<TaskInfo> tasks)
{
    checkNotNull(offerId, "offerId is null");
    checkNotNull(tasks, "tasks is null");

    if (!context.isStateMachine(DRIVER_RUNNING)) {
        return context.getStateMachine();
    }

    final LaunchTasksMessage message = LaunchTasksMessage.newBuilder()
        .setFrameworkId(context.getFrameworkId())
        .addOfferIds(offerId)
        .addAllTasks(tasks)
        .setFilters(Filters.newBuilder().build())
        .build();

    doLaunchTasks(message);
    return context.getStateMachine();
}
 
Example #9
Source File: MesosSchedulerCallbackHandler.java    From titus-control-plane with Apache License 2.0 5 votes vote down vote up
@Override
public void offerRescinded(SchedulerDriver driver, OfferID offerId) {
    String leaseId = offerId.getValue();
    logMesosCallbackInfo("Rescinded offer: %s", leaseId);
    vmLeaseRescindedObserver.onNext(LeaseRescindedEvent.leaseIdEvent(leaseId));
    numOfferRescinded.increment();
}
 
Example #10
Source File: HelloWorldScheduler.java    From tutorials with MIT License 5 votes vote down vote up
@Override
public void resourceOffers(SchedulerDriver schedulerDriver, List<Offer> list) {

    for (Offer offer : list) {
        List<TaskInfo> tasks = new ArrayList<TaskInfo>();
        Protos.TaskID taskId = Protos.TaskID.newBuilder().setValue(Integer.toString(launchedTasks++)).build();

        System.out.println("Launching printHelloWorld " + taskId.getValue() + " Hello World Java");
        TaskInfo printHelloWorld = TaskInfo
                .newBuilder()
                .setName("printHelloWorld " + taskId.getValue())
                .setTaskId(taskId)
                .setSlaveId(offer.getSlaveId())
                .addResources(
                        Protos.Resource.newBuilder().setName("cpus").setType(Protos.Value.Type.SCALAR)
                                .setScalar(Protos.Value.Scalar.newBuilder().setValue(1)))
                .addResources(
                        Protos.Resource.newBuilder().setName("mem").setType(Protos.Value.Type.SCALAR)
                                .setScalar(Protos.Value.Scalar.newBuilder().setValue(128)))
                .setExecutor(ExecutorInfo.newBuilder(helloWorldExecutor)).build();

        List<OfferID> offerIDS = new ArrayList<>();
        offerIDS.add(offer.getId());

        tasks.add(printHelloWorld);

        schedulerDriver.declineOffer(offer.getId());
        schedulerDriver.launchTasks(offerIDS, tasks);
    }

}
 
Example #11
Source File: TaskLaunchScheduledService.java    From shardingsphere-elasticjob-cloud with Apache License 2.0 5 votes vote down vote up
private List<Protos.OfferID> getOfferIDs(final List<VirtualMachineLease> leasesUsed) {
    List<Protos.OfferID> result = new ArrayList<>();
    for (VirtualMachineLease virtualMachineLease: leasesUsed) {
        result.add(virtualMachineLease.getOffer().getId());
    }
    return result;
}
 
Example #12
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 #13
Source File: MesosNimbusTest.java    From storm with Apache License 2.0 5 votes vote down vote up
@Before
public void initialize() {
  map = new HashMap<OfferID, Offer>();
  slotsForTopologiesNeedingAssignments = new HashMap<>();

  mesosStormConf = new HashMap<>();
  mesosStormConf.put(Config.STORM_ZOOKEEPER_SERVERS, new ArrayList<>(Arrays.asList("localhost")));
  mesosStormConf.put(Config.STORM_ZOOKEEPER_PORT, "2181");
  mesosStormConf.put(MesosNimbus.CONF_EXECUTOR_URI, "/fake/path/to/storm-mesos.tgz");
  mesosStormConf.put(MesosCommon.CONF_MESOS_ROLE, FRAMEWORK_ROLE);
  mesosNimbus = Mockito.spy(new MesosNimbus());

  mesosNimbus.initializeMesosStormConf(mesosStormConf, "/mock");
  Mockito.doReturn("http://127.0.0.1/").when(mesosNimbus).getFullConfigUri();
}
 
Example #14
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 #15
Source File: FakeMaster.java    From attic-aurora with Apache License 2.0 5 votes vote down vote up
@Override
public Status launchTasks(
    Collection<OfferID> offerIds,
    Collection<TaskInfo> tasks,
    Filters filters) {

  throw new UnsupportedOperationException();
}
 
Example #16
Source File: TestObjectFactory.java    From incubator-myriad with Apache License 2.0 5 votes vote down vote up
public static Offer getOffer(String host, String slaveId, String frameworkId, String offerId, double cpuCores, double memory) {
  Protos.SlaveID sid = SlaveID.newBuilder().setValue(slaveId).build();
  Protos.FrameworkID fid = FrameworkID.newBuilder().setValue(frameworkId).build();
  Protos.Value.Scalar cores = Protos.Value.Scalar.newBuilder().setValue(cpuCores).build();
  Protos.Value.Scalar mem = Protos.Value.Scalar.newBuilder().setValue(memory).build();
  Protos.Resource cpuResource = Protos.Resource.newBuilder().setName("cpus").setScalar(cores).setType(Type.SCALAR).build();
  Protos.Resource memResource  = Protos.Resource.newBuilder().setName("mem").setScalar(mem).setType(Type.SCALAR).build();
  return Protos.Offer.newBuilder().setHostname(host).setId(OfferID.newBuilder().setValue(offerId)).
      setSlaveId(sid).setFrameworkId(fid).addResources(cpuResource).addResources(memResource).build();  
}
 
Example #17
Source File: MesosNimbus.java    From storm with Apache License 2.0 5 votes vote down vote up
public void doRegistration(final SchedulerDriver driver, Protos.FrameworkID id) {
  _driver = driver;
  // Now that we've set the driver, we can create our scheduler
  _stormScheduler = new StormSchedulerImpl(_driver);

  _state.put(FRAMEWORK_ID, id.getValue());
  _offers = new HashMap<Protos.OfferID, Protos.Offer>();

  if (_enabledLogviewerSidecar) {

    _timer.scheduleAtFixedRate(new TimerTask() {
      @Override
      public void run() {
        // performing "explicit" reconciliation; master will respond with the latest state for all logviewer tasks
        // in the framework scheduler's statusUpdate() method
        List<TaskStatus> taskStatuses = new ArrayList<TaskStatus>();
        List<String> logviewerPaths = _zkClient.getChildren(_logviewerZkDir);
        if (logviewerPaths == null) {
          _driver.reconcileTasks(taskStatuses);
          return;
        }
        for (String path : logviewerPaths) {
          TaskID logviewerTaskId = TaskID.newBuilder()
                                         .setValue(new String(_zkClient.getNodeData(String.format("%s/%s", _logviewerZkDir, path))))
                                         .build();
          TaskStatus logviewerTaskStatus = TaskStatus.newBuilder()
                                                     .setTaskId(logviewerTaskId)
                                                     .setState(TaskState.TASK_RUNNING)
                                                     .build();
          taskStatuses.add(logviewerTaskStatus);
        }
        _driver.reconcileTasks(taskStatuses);
        LOG.info("Performing task reconciliation between scheduler and master on following tasks: {}", taskStatusListToTaskIDsString(taskStatuses));
      }
    }, 0, TASK_RECONCILIATION_INTERVAL); // reconciliation performed every 5 minutes
  }
}
 
Example #18
Source File: OfferUtilsTest.java    From incubator-myriad with Apache License 2.0 5 votes vote down vote up
private List<Offer> generateOffers(List<Resource> resources) {
  FrameworkID fidOne = Protos.FrameworkID.newBuilder().setValue("framework-1").build();
  FrameworkID fidTwo = Protos.FrameworkID.newBuilder().setValue("framework-2").build();
  FrameworkID fidThree = Protos.FrameworkID.newBuilder().setValue("framework-3").build();
  FrameworkID fidFour = Protos.FrameworkID.newBuilder().setValue("framework-4").build();

  OfferID oidOne = Protos.OfferID.newBuilder().setValue("offer-1").build();
  OfferID oidTwo = Protos.OfferID.newBuilder().setValue("offer-2").build(); 
  OfferID oidThree = Protos.OfferID.newBuilder().setValue("offer-3").build(); 
  OfferID oidFour = Protos.OfferID.newBuilder().setValue("offer-4").build(); 

  SlaveID sidOne = Protos.SlaveID.newBuilder().setValue("slave-1").build();
  SlaveID sidTwo = Protos.SlaveID.newBuilder().setValue("slave-2").build();
  SlaveID sidThree = Protos.SlaveID.newBuilder().setValue("slave-3").build();
  SlaveID sidFour = Protos.SlaveID.newBuilder().setValue("slave-4").build();

  Offer offerOne = Protos.Offer.newBuilder().setFrameworkId(fidOne).setHostname("10.0.0.1").setId(oidOne).setSlaveId(sidOne).
      addResources(resources.get(0)).addResources(resources.get(1)).build();
  Offer offerTwo = Protos.Offer.newBuilder().setFrameworkId(fidTwo).setHostname("10.0.0.2").setId(oidTwo).setSlaveId(sidTwo).
      addResources(resources.get(2)).addResources(resources.get(3)).build();
  Offer offerThree = Protos.Offer.newBuilder().setFrameworkId(fidThree).setHostname("10.0.0.3").setId(oidThree).setSlaveId(sidThree).
      addResources(resources.get(0)).addResources(resources.get(3)).build();
  Offer offerFour = Protos.Offer.newBuilder().setFrameworkId(fidFour).setHostname("10.0.0.4").setId(oidFour).setSlaveId(sidFour).
      addResources(resources.get(2)).addResources(resources.get(1)).build();

  return Lists.newArrayList(offerOne, offerTwo, offerThree, offerFour);
}
 
Example #19
Source File: BdsMesosScheduler.java    From BigDataScript with Apache License 2.0 5 votes vote down vote up
protected boolean matchTask(Task task, Collection<OfferID> offerIds, Collection<TaskInfo> taskInfos) {
	for (Host host : cluster) {
		if (host instanceof HostInifinte) {
			// This represents the head node (skip)
		} else if (matchTask(task, host, offerIds, taskInfos)) {
			// Can this task be run on this host?
			return true;
		}
	}

	return false;
}
 
Example #20
Source File: FakeMaster.java    From attic-aurora with Apache License 2.0 5 votes vote down vote up
@Override
public Status acceptOffers(
    Collection<OfferID> offerIds,
    Collection<Offer.Operation> operations,
    Filters filters) {
  throw new UnsupportedOperationException();
}
 
Example #21
Source File: FakeMaster.java    From attic-aurora with Apache License 2.0 5 votes vote down vote up
@Override
public Status launchTasks(Collection<OfferID> offerIds, Collection<TaskInfo> tasks) {
  assertNotStopped();

  OfferID id = Iterables.getOnlyElement(offerIds);
  Offer offer = sentOffers.remove(id);
  checkState(offer != null, "Offer " + id + " is invalid.");

  final TaskInfo task = Iterables.getOnlyElement(tasks);
  synchronized (activeTasks) {
    checkState(
        !activeTasks.containsKey(task.getTaskId()),
        "Task " + task.getTaskId() + " already exists.");
    activeTasks.put(task.getTaskId(), new Task(offer, task));
  }

  executor.schedule(
      () -> Futures.getUnchecked(schedulerFuture).statusUpdate(
          this,
          TaskStatus.newBuilder()
              .setTaskId(task.getTaskId())
              .setState(TaskState.TASK_RUNNING)
              .build()),
      1,
      TimeUnit.SECONDS);

  return Status.DRIVER_RUNNING;
}
 
Example #22
Source File: BdsMesosScheduler.java    From BigDataScript with Apache License 2.0 5 votes vote down vote up
/**
 * Match a task to the offer/s
 */
protected synchronized boolean matchTask(Task task, Host host, Collection<OfferID> offerIds, Collection<TaskInfo> taskInfos) {
	// Not enough resources in this host?
	if (!host.hasResourcesAvailable(task.getResources())) return false;

	if (verbose) Gpr.debug("Matching task: " + task.getId() + "\t resources: " + task.getResources() + "\thost:" + host.getHostName() + ", resources: " + host.getResourcesAvaialble());

	// OK, we should be able to run 'task' in hostName
	String hostName = host.toString();
	Set<Offer> offers = offersByHost.get(hostName);
	if (offers == null) {
		Gpr.debug("Offer accounting problem in host '" + hostName + "': This should ever happen!");
		cluster.remove(host); // Remove any resources since we don't really seem to have any
		return false;
	}

	// Select offers and add taskInfo
	HostResources tr = new HostResources(task.getResources());
	for (Offer offer : offers) {
		// Consume resources until offers fulfill task requirements
		HostResources or = parseOffer(offer);
		tr.consume(or);

		// Add offer and taskInfo to collections
		offerIds.add(offer.getId());
		TaskInfo taskInfo = taskInfo(offer, task);
		taskInfos.add(taskInfo);

		// Are all resources needed for this task satisfied?
		if (tr.isConsumed()) return true;
	}

	Gpr.debug("Resource accounting problem in host '" + hostName + "': This should ever happen!");
	return false;
}
 
Example #23
Source File: SchedulerUtilsTest.java    From storm with Apache License 2.0 4 votes vote down vote up
@Before
public void initialize() {
  map = new HashMap<OfferID, Offer>();
}
 
Example #24
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 #25
Source File: MyriadScheduler.java    From myriad with Apache License 2.0 4 votes vote down vote up
@Override
public void resourceOffers(SchedulerDriver driver, List<Protos.Offer> offers) {
	LOGGER.info("Received offers {}", offers.size());
	driverOperationLock.lock();
	try {
		Set<String> pendingTasks = schedulerState.getPendingTaskIds();
		if (CollectionUtils.isNotEmpty(pendingTasks)) {
			for (Offer offer : offers) {
				boolean offerMatch = false;
				for (String pendingTaskId : pendingTasks) {
					NodeTask taskToLaunch = schedulerState
							.getTask(pendingTaskId);
					NMProfile profile = taskToLaunch.getProfile();
					if (matches(offer, profile)
							&& SchedulerUtils.isUniqueHostname(offer,
									schedulerState.getActiveTasks())) {
						LOGGER.info("Offer {} matched profile {}", offer,
								profile);
						TaskInfo task = TaskUtils.createYARNTask(offer,
								taskToLaunch);
						List<OfferID> offerIds = new ArrayList<>();
						offerIds.add(offer.getId());
						List<TaskInfo> tasks = new ArrayList<>();
						tasks.add(task);
						LOGGER.info("Launching task: {}", task);
						driver.launchTasks(offerIds, tasks);
						schedulerState.makeTaskStaging(pendingTaskId);
						NodeTask taskLaunched = schedulerState
								.getTask(pendingTaskId);
						taskLaunched.setHostname(offer.getHostname());
						offerMatch = true;
						break;
					}
				}
				if (!offerMatch) {
					LOGGER.info(
							"Declining offer {}, as it didn't match any pending task.",
							offer);
					driver.declineOffer(offer.getId());
				}
			}
		} else {
			LOGGER.info("No pending tasks, declining all offers");
			offers.forEach(o -> driver.declineOffer(o.getId()));
		}
	} finally {
		driverOperationLock.unlock();
	}
}
 
Example #26
Source File: MyriadScheduler.java    From myriad with Apache License 2.0 4 votes vote down vote up
@Override
public void offerRescinded(SchedulerDriver sd, Protos.OfferID offerId) {
	LOGGER.info("Rescinded offer {}", offerId);
}
 
Example #27
Source File: ResourceMesosScheduler.java    From oodt with Apache License 2.0 4 votes vote down vote up
@Override
public void offerRescinded(SchedulerDriver schedDriver, OfferID offer) {
    //TODO: take away resources from batch manager...or stand in.
    //Unneeded?
}
 
Example #28
Source File: MesosSchedulerImpl.java    From attic-aurora with Apache License 2.0 4 votes vote down vote up
@Override
public void offerRescinded(SchedulerDriver schedulerDriver, OfferID offerId) {
  handler.handleRescind(convert(offerId));
}
 
Example #29
Source File: FakeMaster.java    From attic-aurora with Apache License 2.0 4 votes vote down vote up
@Override
public Status declineOffer(OfferID offerId, Filters filters) {
  assertNotStopped();

  throw new UnsupportedOperationException();
}
 
Example #30
Source File: PrettyProtobuf.java    From storm with Apache License 2.0 4 votes vote down vote up
public String apply(OfferID o) {
  return o.getValue().toString();
}