use of org.apache.mesos.SchedulerDriver in project dcos-commons by mesosphere.
the class Send method replacePod.
/**
* Initiates the replacement of a pod through a call to {@link PodResource#replacePod(String)}.
*/
public static Send replacePod(String podName) {
return new Send() {
@Override
public void send(ClusterState state, SchedulerDriver mockDriver, Scheduler scheduler) {
PodResource r = (PodResource) state.getResources().stream().filter(resource -> resource instanceof PodResource).findAny().get();
r.replace(podName);
}
@Override
public String getDescription() {
return String.format("Replace pod: %s", podName);
}
};
}
use of org.apache.mesos.SchedulerDriver in project heron by twitter.
the class MesosFrameworkTest method before.
@Before
public void before() throws Exception {
config = Mockito.mock(Config.class);
Mockito.when(config.getStringValue(Key.TOPOLOGY_NAME)).thenReturn(TOPOLOGY_NAME);
Mockito.when(config.getStringValue(Key.ROLE)).thenReturn(ROLE);
Mockito.when(config.getStringValue(Key.CORE_PACKAGE_URI)).thenReturn(CORE_PACKAGE_URI);
runtime = Mockito.mock(Config.class);
Mockito.when(runtime.getLongValue(Key.NUM_CONTAINERS)).thenReturn(NUM_CONTAINER);
Properties properties = new Properties();
properties.put(Key.TOPOLOGY_PACKAGE_URI.value(), TOPOLOGY_PACKAGE_URI);
Mockito.when(runtime.get(Key.SCHEDULER_PROPERTIES)).thenReturn(properties);
mesosFramework = Mockito.spy(new MesosFramework(config, runtime));
SchedulerDriver driver = Mockito.mock(SchedulerDriver.class);
// Register the mesos framework
Protos.FrameworkID frameworkID = Protos.FrameworkID.newBuilder().setValue("framework-id").build();
mesosFramework.registered(driver, frameworkID, Protos.MasterInfo.getDefaultInstance());
}
use of org.apache.mesos.SchedulerDriver in project mesosFramework by zhizuqiu.
the class FrameworkThread method call.
@Override
public String call() throws Exception {
Etcd etcd = EtcdClient.getInstance(AppDataStore.getConfig().getEtcdEndpoints());
try {
watchClient = WatchClientBuilder.builder().etcd(etcd).rootDir(AppDataStore.getConfig().getFrameworkName()).build();
} catch (Exception e) {
logger.error(e.getMessage());
watchClient.close();
return "init watchClient error";
}
// 将会在这里阻塞,直到获取leader
String leaderId = watchClient.selectLeader();
System.out.println("onGetLeader leaderId:" + leaderId);
/*
维持leader状态,直到futureTask.isDone()==true,表示失去leader地位
keeper leader发生异常时,停止两个线程
*/
FutureTask<String> futureTask = watchClient.keepLeader((id) -> {
logger.error("leader is lost:" + id);
AppDataStore.shutdown();
});
AppDataStore.setWatchClient(watchClient);
String frameworkId = watchClient.getFrameworkId();
Protos.FrameworkInfo.Builder frameworkInfoBuilder = Protos.FrameworkInfo.newBuilder().setUser("").setName(AppDataStore.getConfig().getFrameworkName()).setFailoverTimeout(AppDataStore.getConfig().getFailoverTimeout()).setCheckpoint(true);
if (AppDataStore.getConfig().getUser() != null) {
frameworkInfoBuilder.setUser(AppDataStore.getConfig().getUser());
}
if (AppDataStore.getConfig().getRole() != null) {
frameworkInfoBuilder.setRole(AppDataStore.getConfig().getRole());
logger.info("set role:" + AppDataStore.getConfig().getRole());
frameworkInfoBuilder.setPrincipal(AppDataStore.getConfig().getRole());
}
if (frameworkId != null) {
logger.info("frameworkId:" + frameworkId);
frameworkInfoBuilder.setId(Protos.FrameworkID.newBuilder().setValue(frameworkId));
}
if (AppDataStore.getInfo().getHost() != null && AppDataStore.getInfo().getPort() != null) {
frameworkInfoBuilder.setHostname(AppDataStore.getInfo().getHost());
frameworkInfoBuilder.setWebuiUrl("http://" + AppDataStore.getInfo().getHost() + ":" + AppDataStore.getInfo().getPort() + "/");
}
Scheduler dockerScheduler = new DockerScheduler(etcd);
SchedulerDriver driver = new MesosSchedulerDriver(dockerScheduler, frameworkInfoBuilder.build(), AppDataStore.getConfig().getMesosZkUrl());
// 这里如果找不到meososlib会阻塞在这里,下个方法不走
int status = driver.run() == Protos.Status.DRIVER_STOPPED ? 0 : 1;
logger.info(status);
return "framework thread exit";
}
use of org.apache.mesos.SchedulerDriver in project jesos by groupon.
the class LocalSchedulerMessageProcessor method frameworkStatusUpdate.
@Subscribe
public void frameworkStatusUpdate(final StatusUpdateMessageEnvelope envelope) throws IOException {
checkState(envelope.getRecipient().equals(context.getDriverUPID()), "Received a remote message for local delivery");
final UPID sender = envelope.getSender();
if (!driverIsConnected(sender)) {
return;
}
final StatusUpdateMessage statusUpdateMessage = envelope.getMessage();
final FrameworkID frameworkId = context.getFrameworkId();
final FrameworkID messageFrameworkId = statusUpdateMessage.getUpdate().getFrameworkId();
checkState(frameworkId.equals(messageFrameworkId), "Received Message for framework %s, but local id is %s", messageFrameworkId, frameworkId);
final TaskStatus.Builder taskStatusBuilder = TaskStatus.newBuilder(statusUpdateMessage.getUpdate().getStatus());
final TaskStatus taskStatus;
// If the update is driver-generated or master-generated, it does not require acknowledgement (from Mesos source code, sched.cpp).
final Optional<UPID> pid = statusUpdateMessage.hasPid() ? Optional.of(UPID.create(statusUpdateMessage.getPid())) : Optional.<UPID>absent();
final boolean noAckRequired = envelope.getSender().equals(context.getDriverUPID()) || pid.isPresent() && pid.get().equals(context.getDriverUPID());
if (noAckRequired) {
taskStatus = taskStatusBuilder.clearUuid().build();
} else {
taskStatus = taskStatusBuilder.setUuid(statusUpdateMessage.getUpdate().getUuid()).build();
}
eventBus.post(new SchedulerCallback() {
@Override
public Runnable getCallback(final Scheduler scheduler, final SchedulerDriver schedulerDriver) {
return new Runnable() {
@Override
public void run() {
scheduler.statusUpdate(schedulerDriver, taskStatus);
}
};
}
});
if (implicitAcknowledgements && !noAckRequired) {
final StatusUpdateAcknowledgementMessage statusUpdateAcknowledgementMessage = StatusUpdateAcknowledgementMessage.newBuilder().setFrameworkId(frameworkId).setSlaveId(statusUpdateMessage.getUpdate().getSlaveId()).setTaskId(taskStatus.getTaskId()).setUuid(statusUpdateMessage.getUpdate().getUuid()).build();
eventBus.post(new RemoteMessageEnvelope(context.getDriverUPID(), context.getMasterUPID(), statusUpdateAcknowledgementMessage));
}
}
use of org.apache.mesos.SchedulerDriver in project jesos by groupon.
the class LocalSchedulerMessageProcessor method frameworkError.
@Subscribe
public void frameworkError(final FrameworkErrorMessageEnvelope envelope) {
checkState(envelope.getRecipient().equals(context.getDriverUPID()), "Received a remote message for local delivery");
final UPID sender = envelope.getSender();
if (!driverIsConnected(sender)) {
return;
}
final FrameworkErrorMessage frameworkErrorMessage = envelope.getMessage();
eventBus.post(new SchedulerCallback() {
@Override
public Runnable getCallback(final Scheduler scheduler, final SchedulerDriver schedulerDriver) {
return new Runnable() {
@Override
public void run() {
schedulerDriver.abort();
scheduler.error(schedulerDriver, frameworkErrorMessage.getMessage());
}
};
}
});
}
Aggregations