use of org.apache.myriad.state.NodeTask in project incubator-myriad by apache.
the class MyriadOperations method flexUpCluster.
public void flexUpCluster(ServiceResourceProfile serviceResourceProfile, int instances, Constraint constraint) {
Collection<NodeTask> nodes = new HashSet<>();
for (int i = 0; i < instances; i++) {
NodeTask nodeTask = new NodeTask(serviceResourceProfile, constraint);
nodeTask.setTaskPrefix(NodeManagerConfiguration.DEFAULT_NM_TASK_PREFIX);
nodes.add(nodeTask);
}
LOGGER.info("Adding {} NM instances to cluster", nodes.size());
this.schedulerState.addNodes(nodes);
}
use of org.apache.myriad.state.NodeTask in project incubator-myriad by apache.
the class MyriadOperations method flexDownAService.
/**
* Flexing down any service defined in the configuration
*
* @param numInstancesToScaleDown
* @param serviceName - name of the service
*/
public void flexDownAService(int numInstancesToScaleDown, String serviceName) {
LOGGER.info("About to flex down {} instances of {}", numInstancesToScaleDown, serviceName);
int numScaledDown = 0;
// Flex down Pending tasks, if any
if (numScaledDown < numInstancesToScaleDown) {
Collection<Protos.TaskID> pendingTasks = this.schedulerState.getPendingTaskIds(serviceName);
for (Protos.TaskID taskId : pendingTasks) {
this.schedulerState.makeTaskKillable(taskId);
numScaledDown++;
if (numScaledDown >= numInstancesToScaleDown) {
break;
}
}
}
int numPendingTasksScaledDown = numScaledDown;
// Flex down Staging tasks, if any
if (numScaledDown < numInstancesToScaleDown) {
Collection<Protos.TaskID> stagingTasks = this.schedulerState.getStagingTaskIds(serviceName);
for (Protos.TaskID taskId : stagingTasks) {
this.schedulerState.makeTaskKillable(taskId);
numScaledDown++;
if (numScaledDown >= numInstancesToScaleDown) {
break;
}
}
}
int numStagingTasksScaledDown = numScaledDown - numPendingTasksScaledDown;
Set<NodeTask> activeTasks = this.schedulerState.getActiveTasksByType(serviceName);
if (numScaledDown < numInstancesToScaleDown) {
for (NodeTask nodeTask : activeTasks) {
this.schedulerState.makeTaskKillable(nodeTask.getTaskStatus().getTaskId());
numScaledDown++;
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Marked NodeTask {} on host {} for kill.", nodeTask.getTaskStatus().getTaskId(), nodeTask.getHostname());
}
if (numScaledDown >= numInstancesToScaleDown) {
break;
}
}
}
LOGGER.info("Flexed down {} of {} instances including {} staging instances, and {} pending instances of {}", numScaledDown, numInstancesToScaleDown, numStagingTasksScaledDown, numPendingTasksScaledDown, serviceName);
}
use of org.apache.myriad.state.NodeTask in project incubator-myriad by apache.
the class TaskTerminator method handleNonPendingTask.
private void handleNonPendingTask(TaskID taskId) {
/*
* Kill the task and decline additional offers for it, but hold off removing from SchedulerState.
* Removal of the killable task must be done following invocation of statusUpdate callback method
* which constitutes acknowledgement from Mesos that the kill task request succeeded.
*/
Status status = this.driverManager.kill(taskId);
NodeTask task = schedulerState.getTask(taskId);
if (task != null) {
offerLifeCycleManager.declineOutstandingOffers(task.getHostname());
}
if (status.equals(Status.DRIVER_RUNNING)) {
LOGGER.info("Kill request for {} was submitted to a running SchedulerDriver", taskId);
} else {
LOGGER.warn("Kill task request for {} submitted to non-running SchedulerDriver, may fail", taskId);
}
}
use of org.apache.myriad.state.NodeTask in project incubator-myriad by apache.
the class ByteBufferSupportTest method testNodeTaskToFromByteBuffer.
@Test
public void testNodeTaskToFromByteBuffer() throws Exception {
ByteBuffer bb = ByteBufferSupport.toByteBuffer(task);
NodeTask sTask = ByteBufferSupport.toNodeTask(bb);
assertEquals(task.getClass().getName(), sTask.getClass().getName());
assertEquals(task.getHostname(), sTask.getHostname());
assertEquals(task.getSlaveId(), sTask.getSlaveId());
assertEquals(task.getTaskPrefix(), sTask.getTaskPrefix());
assertEquals(task.getProfile(), sTask.getProfile());
assertEquals(task.getSlaveAttributes(), sTask.getSlaveAttributes());
assertEquals(task.getConstraint(), sTask.getConstraint());
assertEquals(task.getExecutorInfo(), sTask.getExecutorInfo());
}
use of org.apache.myriad.state.NodeTask in project incubator-myriad by apache.
the class ResourceOffersEventHandler method onEvent.
@Override
public void onEvent(ResourceOffersEvent event, long sequence, boolean endOfBatch) throws Exception {
SchedulerDriver driver = event.getDriver();
List<Offer> offers = event.getOffers();
// to not process any offers unless Myriad receives a "framework registered" notification.
if (schedulerState.getFrameworkID() == null) {
LOGGER.warn("Received {} offers, but declining them since Framework ID is not yet set", offers.size());
for (Offer offer : offers) {
driver.declineOffer(offer.getId());
}
return;
}
LOGGER.debug("Received offers {}", offers.size());
LOGGER.debug("Pending tasks: {}", this.schedulerState.getPendingTaskIds());
// Let Myriad use reserved resources firstly.
Collections.sort(offers, new Comparator<Offer>() {
boolean isReserved(Offer o) {
for (Protos.Resource resource : o.getResourcesList()) {
if (resource.hasRole() && !Objects.equals(resource.getRole(), DEFAULT_ROLE)) {
return true;
}
}
return false;
}
@Override
public int compare(Offer o1, Offer o2) {
boolean reserved1 = isReserved(o1);
boolean reserved2 = isReserved(o2);
if (reserved1 == reserved2) {
return 0;
}
return reserved1 ? -1 : 1;
}
});
driverOperationLock.lock();
try {
for (Iterator<Offer> iterator = offers.iterator(); iterator.hasNext(); ) {
Offer offer = iterator.next();
Set<NodeTask> nodeTasks = schedulerState.getNodeTasks(offer.getSlaveId());
for (NodeTask nodeTask : nodeTasks) {
nodeTask.setSlaveAttributes(offer.getAttributesList());
}
// keep this in case SchedulerState gets out of sync. This should not happen with
// synchronizing addNodes method in SchedulerState
// but to keep it safe
final Set<Protos.TaskID> missingTasks = Sets.newHashSet();
Set<Protos.TaskID> pendingTasks = schedulerState.getPendingTaskIds();
if (CollectionUtils.isNotEmpty(pendingTasks)) {
for (Protos.TaskID pendingTaskId : pendingTasks) {
NodeTask taskToLaunch = schedulerState.getTask(pendingTaskId);
if (taskToLaunch == null) {
missingTasks.add(pendingTaskId);
LOGGER.warn("Node task for TaskID: {} does not exist", pendingTaskId);
continue;
}
String taskPrefix = taskToLaunch.getTaskPrefix();
ServiceResourceProfile profile = taskToLaunch.getProfile();
Constraint constraint = taskToLaunch.getConstraint();
Set<NodeTask> launchedTasks = new HashSet<>();
launchedTasks.addAll(schedulerState.getActiveTasksByType(taskPrefix));
launchedTasks.addAll(schedulerState.getStagingTasksByType(taskPrefix));
ResourceOfferContainer resourceOfferContainer = new ResourceOfferContainer(offer, taskToLaunch.getProfile(), role);
if (SchedulerUtils.isUniqueHostname(offer, taskToLaunch, launchedTasks) && resourceOfferContainer.satisfies(taskToLaunch.getProfile(), constraint)) {
try {
final TaskInfo task = taskFactoryMap.get(taskPrefix).createTask(resourceOfferContainer, schedulerState.getFrameworkID().get(), pendingTaskId, taskToLaunch);
LOGGER.info("Launching task: {} using offer: {}", task.getTaskId().getValue(), offer.getId());
LOGGER.debug("Launching task: {} with profile: {} using offer: {}", task, profile, offer);
driver.launchTasks(Collections.singleton(offer.getId()), Collections.singleton(task));
schedulerState.makeTaskStaging(pendingTaskId);
// For every NM Task that we launch, we currently
// need to backup the ExecutorInfo for that NM Task in the State Store.
// Without this, we will not be able to launch tasks corresponding to yarn
// containers. This is specially important in case the RM restarts.
taskToLaunch.setExecutorInfo(task.getExecutor());
taskToLaunch.setHostname(offer.getHostname());
taskToLaunch.setSlaveId(offer.getSlaveId());
schedulerState.addTask(pendingTaskId, taskToLaunch);
// remove the used offer from offers list
iterator.remove();
break;
} catch (Throwable t) {
LOGGER.error("Exception thrown while trying to create a task for {}", taskPrefix, t);
}
}
}
for (Protos.TaskID taskId : missingTasks) {
schedulerState.removeTask(taskId);
}
}
}
for (Offer offer : offers) {
if (SchedulerUtils.isEligibleForFineGrainedScaling(offer.getHostname(), schedulerState)) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Picking an offer from slave with hostname {} for fine grained scaling.", offer.getHostname());
}
offerLifecycleMgr.addOffers(offer);
} else {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Declining offer {} from slave {}.", offer, offer.getHostname());
}
driver.declineOffer(offer.getId());
}
}
} finally {
driverOperationLock.unlock();
}
}
Aggregations