org.apache.flink.mesos.scheduler.messages.AcceptOffers Java Examples

The following examples show how to use org.apache.flink.mesos.scheduler.messages.AcceptOffers. 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: MesosResourceManager.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
/**
 * Accept offers as advised by the launch coordinator.
 *
 * <p>Acceptance is routed through the RM to update the persistent state before
 * forwarding the message to Mesos.
 */
public void acceptOffers(AcceptOffers msg) {
	try {
		List<TaskMonitor.TaskGoalStateUpdated> toMonitor = new ArrayList<>(msg.operations().size());

		// transition the persistent state of some tasks to Launched
		for (Protos.Offer.Operation op : msg.operations()) {
			if (op.getType() == Protos.Offer.Operation.Type.LAUNCH) {
				for (Protos.TaskInfo info : op.getLaunch().getTaskInfosList()) {
					MesosWorkerStore.Worker worker = workersInNew.remove(extractResourceID(info.getTaskId()));
					assert (worker != null);

					worker = worker.launchWorker(info.getSlaveId(), msg.hostname());
					workerStore.putWorker(worker);
					workersInLaunch.put(extractResourceID(worker.taskID()), worker);

					LOG.info("Launching Mesos task {} on host {}.",
						worker.taskID().getValue(), worker.hostname().get());

					toMonitor.add(new TaskMonitor.TaskGoalStateUpdated(extractGoalState(worker)));
				}
			}
		}

		// tell the task monitor about the new plans
		for (TaskMonitor.TaskGoalStateUpdated update : toMonitor) {
			taskMonitor.tell(update, selfActor);
		}

		// send the acceptance message to Mesos
		schedulerDriver.acceptOffers(msg.offerIds(), msg.operations(), msg.filters());
	} catch (Exception ex) {
		onFatalError(new ResourceManagerException("unable to accept offers", ex));
	}
}
 
Example #2
Source File: MesosResourceManager.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public void onReceive(final Object message) throws Exception {
	if (message instanceof ReconciliationCoordinator.Reconcile) {
		runAsync(new Runnable() {
			@Override
			public void run() {
				reconcile((ReconciliationCoordinator.Reconcile) message);
			}
		});
	} else if (message instanceof TaskMonitor.TaskTerminated) {
		runAsync(new Runnable() {
			@Override
			public void run() {
				taskTerminated((TaskMonitor.TaskTerminated) message);
			}
		});
	} else if (message instanceof AcceptOffers) {
		runAsync(new Runnable() {
			@Override
			public void run() {
				acceptOffers((AcceptOffers) message);
			}
		});
	} else {
		MesosResourceManager.LOG.error("unrecognized message: " + message);
	}
}
 
Example #3
Source File: MesosResourceManagerTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
/**
 * Test offer acceptance.
 */
@Test
public void testAcceptOffers() throws Exception {
	new Context() {{
		startResourceManager();

		// allocate a new worker
		MesosWorkerStore.Worker worker1 = allocateWorker(task1, resourceProfile1);

		// send an AcceptOffers message as the LaunchCoordinator would
		// to launch task1 onto slave1 with offer1
		Protos.TaskInfo task1info = Protos.TaskInfo.newBuilder()
			.setTaskId(task1).setName("").setSlaveId(slave1).build();
		AcceptOffers msg = new AcceptOffers(slave1host, singletonList(offer1), singletonList(launch(task1info)));
		resourceManager.acceptOffers(msg);

		// verify that the worker was persisted, the internal state was updated,
		// Mesos was asked to launch task1, and the task router was notified
		MesosWorkerStore.Worker worker1launched = worker1.launchWorker(slave1, slave1host);
		verify(rmServices.workerStore).putWorker(worker1launched);
		assertThat(resourceManager.workersInNew.entrySet(), empty());
		assertThat(resourceManager.workersInLaunch, hasEntry(extractResourceID(task1), worker1launched));
		resourceManager.taskRouter.expectMsg(
			new TaskMonitor.TaskGoalStateUpdated(extractGoalState(worker1launched)));
		verify(rmServices.schedulerDriver).acceptOffers(msg.offerIds(), msg.operations(), msg.filters());
	}};
}
 
Example #4
Source File: MesosResourceManager.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Accept offers as advised by the launch coordinator.
 *
 * <p>Acceptance is routed through the RM to update the persistent state before
 * forwarding the message to Mesos.
 */
public void acceptOffers(AcceptOffers msg) {
	try {
		List<TaskMonitor.TaskGoalStateUpdated> toMonitor = new ArrayList<>(msg.operations().size());

		// transition the persistent state of some tasks to Launched
		for (Protos.Offer.Operation op : msg.operations()) {
			if (op.getType() == Protos.Offer.Operation.Type.LAUNCH) {
				for (Protos.TaskInfo info : op.getLaunch().getTaskInfosList()) {
					MesosWorkerStore.Worker worker = workersInNew.remove(extractResourceID(info.getTaskId()));
					assert (worker != null);

					worker = worker.launchWorker(info.getSlaveId(), msg.hostname());
					workerStore.putWorker(worker);
					workersInLaunch.put(extractResourceID(worker.taskID()), worker);

					LOG.info("Launching Mesos task {} on host {}.",
						worker.taskID().getValue(), worker.hostname().get());

					toMonitor.add(new TaskMonitor.TaskGoalStateUpdated(extractGoalState(worker)));
				}
			}
		}

		// tell the task monitor about the new plans
		for (TaskMonitor.TaskGoalStateUpdated update : toMonitor) {
			taskMonitor.tell(update, selfActor);
		}

		// send the acceptance message to Mesos
		schedulerDriver.acceptOffers(msg.offerIds(), msg.operations(), msg.filters());
	} catch (Exception ex) {
		onFatalError(new ResourceManagerException("unable to accept offers", ex));
	}
}
 
Example #5
Source File: MesosResourceManager.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void onReceive(final Object message) throws Exception {
	if (message instanceof ReconciliationCoordinator.Reconcile) {
		runAsync(new Runnable() {
			@Override
			public void run() {
				reconcile((ReconciliationCoordinator.Reconcile) message);
			}
		});
	} else if (message instanceof TaskMonitor.TaskTerminated) {
		runAsync(new Runnable() {
			@Override
			public void run() {
				taskTerminated((TaskMonitor.TaskTerminated) message);
			}
		});
	} else if (message instanceof AcceptOffers) {
		runAsync(new Runnable() {
			@Override
			public void run() {
				acceptOffers((AcceptOffers) message);
			}
		});
	} else {
		MesosResourceManager.LOG.error("unrecognized message: " + message);
	}
}
 
Example #6
Source File: MesosResourceManagerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Test offer acceptance.
 */
@Test
public void testAcceptOffers() throws Exception {
	new Context() {{
		startResourceManager();

		// allocate a new worker
		MesosWorkerStore.Worker worker1 = allocateWorker(task1, resourceProfile1);

		// send an AcceptOffers message as the LaunchCoordinator would
		// to launch task1 onto slave1 with offer1
		Protos.TaskInfo task1info = Protos.TaskInfo.newBuilder()
			.setTaskId(task1).setName("").setSlaveId(slave1).build();
		AcceptOffers msg = new AcceptOffers(slave1host, singletonList(offer1), singletonList(launch(task1info)));
		resourceManager.acceptOffers(msg);

		// verify that the worker was persisted, the internal state was updated,
		// Mesos was asked to launch task1, and the task router was notified
		MesosWorkerStore.Worker worker1launched = worker1.launchWorker(slave1, slave1host);
		verify(rmServices.workerStore).putWorker(worker1launched);
		assertThat(resourceManager.workersInNew.entrySet(), empty());
		assertThat(resourceManager.workersInLaunch, hasEntry(extractResourceID(task1), worker1launched));
		resourceManager.taskRouter.expectMsg(
			new TaskMonitor.TaskGoalStateUpdated(extractGoalState(worker1launched)));
		verify(rmServices.schedulerDriver).acceptOffers(msg.offerIds(), msg.operations(), msg.filters());
	}};
}
 
Example #7
Source File: MesosResourceManager.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Accept offers as advised by the launch coordinator.
 *
 * <p>Acceptance is routed through the RM to update the persistent state before
 * forwarding the message to Mesos.
 */
public void acceptOffers(AcceptOffers msg) {
	try {
		List<TaskMonitor.TaskGoalStateUpdated> toMonitor = new ArrayList<>(msg.operations().size());

		// transition the persistent state of some tasks to Launched
		for (Protos.Offer.Operation op : msg.operations()) {
			if (op.getType() == Protos.Offer.Operation.Type.LAUNCH) {
				for (Protos.TaskInfo info : op.getLaunch().getTaskInfosList()) {
					MesosWorkerStore.Worker worker = workersInNew.remove(extractResourceID(info.getTaskId()));
					assert (worker != null);

					worker = worker.launchWorker(info.getSlaveId(), msg.hostname());
					workerStore.putWorker(worker);
					workersInLaunch.put(extractResourceID(worker.taskID()), worker);

					LOG.info("Launching Mesos task {} on host {}.",
						worker.taskID().getValue(), worker.hostname().get());

					toMonitor.add(new TaskMonitor.TaskGoalStateUpdated(extractGoalState(worker)));
				}
			}
		}

		// tell the task monitor about the new plans
		for (TaskMonitor.TaskGoalStateUpdated update : toMonitor) {
			taskMonitor.tell(update, selfActor);
		}

		// send the acceptance message to Mesos
		schedulerDriver.acceptOffers(msg.offerIds(), msg.operations(), msg.filters());
	} catch (Exception ex) {
		onFatalError(new ResourceManagerException("unable to accept offers", ex));
	}
}
 
Example #8
Source File: MesosResourceManager.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void onReceive(final Object message) throws Exception {
	if (message instanceof ReconciliationCoordinator.Reconcile) {
		runAsync(new Runnable() {
			@Override
			public void run() {
				reconcile((ReconciliationCoordinator.Reconcile) message);
			}
		});
	} else if (message instanceof TaskMonitor.TaskTerminated) {
		runAsync(new Runnable() {
			@Override
			public void run() {
				taskTerminated((TaskMonitor.TaskTerminated) message);
			}
		});
	} else if (message instanceof AcceptOffers) {
		runAsync(new Runnable() {
			@Override
			public void run() {
				acceptOffers((AcceptOffers) message);
			}
		});
	} else {
		MesosResourceManager.LOG.error("unrecognized message: " + message);
	}
}
 
Example #9
Source File: MesosResourceManagerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Test offer acceptance.
 */
@Test
public void testAcceptOffers() throws Exception {
	new Context() {{
		startResourceManager();

		// allocate a new worker
		MesosWorkerStore.Worker worker1 = allocateWorker(task1, workerResourceSpec);

		// send an AcceptOffers message as the LaunchCoordinator would
		// to launch task1 onto slave1 with offer1
		Protos.TaskInfo task1info = Protos.TaskInfo.newBuilder()
			.setTaskId(task1).setName("").setSlaveId(slave1).build();
		AcceptOffers msg = new AcceptOffers(slave1host, singletonList(offer1), singletonList(launch(task1info)));
		resourceManager.acceptOffers(msg);

		// verify that the worker was persisted, the internal state was updated,
		// Mesos was asked to launch task1, and the task router was notified
		MesosWorkerStore.Worker worker1launched = worker1.launchWorker(slave1, slave1host);
		verify(rmServices.workerStore).putWorker(worker1launched);
		assertThat(resourceManager.workersInNew.entrySet(), empty());
		assertThat(resourceManager.workersInLaunch, hasEntry(extractResourceID(task1), worker1launched));
		resourceManager.taskRouter.expectMsg(
			new TaskMonitor.TaskGoalStateUpdated(extractGoalState(worker1launched)));
		verify(rmServices.schedulerDriver).acceptOffers(msg.offerIds(), msg.operations(), msg.filters());
	}};
}
 
Example #10
Source File: MesosResourceManagerActions.java    From Flink-CEPplus with Apache License 2.0 2 votes vote down vote up
/**
 * Accept the given offers as advised by the launch coordinator.
 *
 * <p>Note: This method is a callback for the {@link LaunchCoordinator}.
 *
 * @param offersToAccept Offers to accept from Mesos
 */
void acceptOffers(AcceptOffers offersToAccept);
 
Example #11
Source File: MesosResourceManagerActions.java    From flink with Apache License 2.0 2 votes vote down vote up
/**
 * Accept the given offers as advised by the launch coordinator.
 *
 * <p>Note: This method is a callback for the {@link LaunchCoordinator}.
 *
 * @param offersToAccept Offers to accept from Mesos
 */
void acceptOffers(AcceptOffers offersToAccept);
 
Example #12
Source File: MesosResourceManagerActions.java    From flink with Apache License 2.0 2 votes vote down vote up
/**
 * Accept the given offers as advised by the launch coordinator.
 *
 * <p>Note: This method is a callback for the {@link LaunchCoordinator}.
 *
 * @param offersToAccept Offers to accept from Mesos
 */
void acceptOffers(AcceptOffers offersToAccept);