Search in sources :

Example 21 with SchedulerDriver

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);
        }
    };
}
Also used : Protos(org.apache.mesos.Protos) SchedulerDriver(org.apache.mesos.SchedulerDriver) Arrays(java.util.Arrays) Scheduler(org.apache.mesos.Scheduler) PodResource(com.mesosphere.sdk.http.endpoints.PodResource) PodResource(com.mesosphere.sdk.http.endpoints.PodResource) Scheduler(org.apache.mesos.Scheduler) SchedulerDriver(org.apache.mesos.SchedulerDriver)

Example 22 with SchedulerDriver

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());
}
Also used : Protos(org.apache.mesos.Protos) Config(org.apache.heron.spi.common.Config) Properties(java.util.Properties) SchedulerDriver(org.apache.mesos.SchedulerDriver) Before(org.junit.Before)

Example 23 with SchedulerDriver

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";
}
Also used : Etcd(com.chinaunicom.etcd.v2.Etcd) Scheduler(org.apache.mesos.Scheduler) MesosSchedulerDriver(org.apache.mesos.MesosSchedulerDriver) SchedulerDriver(org.apache.mesos.SchedulerDriver) MesosSchedulerDriver(org.apache.mesos.MesosSchedulerDriver)

Example 24 with SchedulerDriver

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));
    }
}
Also used : Scheduler(org.apache.mesos.Scheduler) TaskStatus(org.apache.mesos.Protos.TaskStatus) UPID(com.groupon.mesos.util.UPID) RemoteMessageEnvelope(com.groupon.mesos.scheduler.SchedulerMessageEnvelope.RemoteMessageEnvelope) StatusUpdateAcknowledgementMessage(mesos.internal.Messages.StatusUpdateAcknowledgementMessage) StatusUpdateMessage(mesos.internal.Messages.StatusUpdateMessage) FrameworkID(org.apache.mesos.Protos.FrameworkID) SchedulerDriver(org.apache.mesos.SchedulerDriver) Subscribe(com.google.common.eventbus.Subscribe)

Example 25 with SchedulerDriver

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());
                }
            };
        }
    });
}
Also used : UPID(com.groupon.mesos.util.UPID) Scheduler(org.apache.mesos.Scheduler) FrameworkErrorMessage(mesos.internal.Messages.FrameworkErrorMessage) SchedulerDriver(org.apache.mesos.SchedulerDriver) Subscribe(com.google.common.eventbus.Subscribe)

Aggregations

SchedulerDriver (org.apache.mesos.SchedulerDriver)26 Scheduler (org.apache.mesos.Scheduler)10 Subscribe (com.google.common.eventbus.Subscribe)8 Protos (org.apache.mesos.Protos)8 UPID (com.groupon.mesos.util.UPID)6 Properties (java.util.Properties)6 Before (org.junit.Before)6 Config (com.twitter.heron.spi.common.Config)4 StateStore (com.mesosphere.sdk.state.StateStore)3 FrameworkID (org.apache.mesos.Protos.FrameworkID)3 Test (org.junit.Test)3 Plan (com.mesosphere.sdk.scheduler.plan.Plan)2 BaseContainer (com.twitter.heron.scheduler.mesos.framework.BaseContainer)2 MesosFramework (com.twitter.heron.scheduler.mesos.framework.MesosFramework)2 Config (org.apache.heron.spi.common.Config)2 Offer (org.apache.mesos.Protos.Offer)2 TaskStatus (org.apache.mesos.Protos.TaskStatus)2 Etcd (com.chinaunicom.etcd.v2.Etcd)1 RestfulServerConfiguration (com.dangdang.ddframe.job.cloud.scheduler.env.RestfulServerConfiguration)1 ProducerManager (com.dangdang.ddframe.job.cloud.scheduler.producer.ProducerManager)1