Search in sources :

Example 1 with SchedulerDriver

use of org.apache.mesos.SchedulerDriver in project elastic-job by dangdangdotcom.

the class SchedulerEngineTest method assertResourceOffers.

@Test
public void assertResourceOffers() {
    SchedulerDriver schedulerDriver = mock(SchedulerDriver.class);
    List<Protos.Offer> offers = Arrays.asList(OfferBuilder.createOffer("offer_0"), OfferBuilder.createOffer("offer_1"));
    when(facadeService.getEligibleJobContext()).thenReturn(Collections.singletonList(JobContext.from(CloudJobConfigurationBuilder.createCloudJobConfiguration("failover_job"), ExecutionType.FAILOVER)));
    schedulerEngine.resourceOffers(schedulerDriver, offers);
    assertThat(LeasesQueue.getInstance().drainTo().size(), is(2));
}
Also used : SchedulerDriver(org.apache.mesos.SchedulerDriver) Test(org.junit.Test)

Example 2 with SchedulerDriver

use of org.apache.mesos.SchedulerDriver in project heron by twitter.

the class MesosSchedulerTest method before.

@Before
public void before() throws Exception {
    Config 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);
    Config 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.mock(MesosFramework.class);
    SchedulerDriver driver = Mockito.mock(SchedulerDriver.class);
    baseContainer = Mockito.mock(BaseContainer.class);
    scheduler = Mockito.spy(MesosScheduler.class);
    Mockito.doReturn(mesosFramework).when(scheduler).getMesosFramework();
    Mockito.doReturn(driver).when(scheduler).getSchedulerDriver(Mockito.anyString(), Mockito.eq(mesosFramework));
    Mockito.doNothing().when(scheduler).startSchedulerDriver();
    scheduler.initialize(config, runtime);
}
Also used : BaseContainer(com.twitter.heron.scheduler.mesos.framework.BaseContainer) MesosFramework(com.twitter.heron.scheduler.mesos.framework.MesosFramework) Config(com.twitter.heron.spi.common.Config) Properties(java.util.Properties) SchedulerDriver(org.apache.mesos.SchedulerDriver) Before(org.junit.Before)

Example 3 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(com.twitter.heron.spi.common.Config) Properties(java.util.Properties) SchedulerDriver(org.apache.mesos.SchedulerDriver) Before(org.junit.Before)

Example 4 with SchedulerDriver

use of org.apache.mesos.SchedulerDriver in project incubator-myriad by apache.

the class MyriadDriverTest method testGetDriver.

@Test
public void testGetDriver() throws Exception {
    MyriadDriver driver = new MyriadDriver(new MockSchedulerDriver());
    SchedulerDriver sDriver = driver.getDriver();
    assertTrue(sDriver instanceof MockSchedulerDriver);
}
Also used : SchedulerDriver(org.apache.mesos.SchedulerDriver) Test(org.junit.Test)

Example 5 with SchedulerDriver

use of org.apache.mesos.SchedulerDriver in project dcos-commons by mesosphere.

the class ServiceTest method transientToCustomPermanentFailureTransition.

@Test
public void transientToCustomPermanentFailureTransition() throws Exception {
    Protos.Offer unacceptableOffer = Protos.Offer.newBuilder().setId(Protos.OfferID.newBuilder().setValue(UUID.randomUUID().toString())).setFrameworkId(TestConstants.FRAMEWORK_ID).setSlaveId(TestConstants.AGENT_ID).setHostname(TestConstants.HOSTNAME).addResources(Protos.Resource.newBuilder().setName("mem").setType(Protos.Value.Type.SCALAR).setScalar(Protos.Value.Scalar.newBuilder().setValue(1.0))).build();
    Collection<SimulationTick> ticks = new ArrayList<>();
    ticks.add(Send.register());
    ticks.add(Expect.reconciledImplicitly());
    // Verify that service launches 1 hello pod then 2 world pods.
    ticks.add(Send.offerBuilder("hello").build());
    ticks.add(Expect.launchedTasks("hello-0-server"));
    // Send another offer before hello-0 is finished:
    ticks.add(Send.offerBuilder("world").build());
    ticks.add(Expect.declinedLastOffer());
    // Running, no readiness check is applicable:
    ticks.add(Send.taskStatus("hello-0-server", Protos.TaskState.TASK_RUNNING).build());
    // Now world-0 will deploy:
    ticks.add(Send.offerBuilder("world").build());
    ticks.add(Expect.launchedTasks("world-0-server"));
    // With world-0's readiness check passing, world-1 still won't launch due to a hostname placement constraint:
    ticks.add(Send.taskStatus("world-0-server", Protos.TaskState.TASK_RUNNING).setReadinessCheckExitCode(0).build());
    // world-1 will finally launch if the offered hostname is different:
    ticks.add(Send.offerBuilder("world").setHostname("host-foo").build());
    ticks.add(Expect.launchedTasks("world-1-server"));
    ticks.add(Send.taskStatus("world-1-server", Protos.TaskState.TASK_RUNNING).setReadinessCheckExitCode(0).build());
    // *** Complete initial deployment. ***
    ticks.add(Expect.allPlansComplete());
    // Kill hello-0 to trigger transient recovery
    ticks.add(Send.taskStatus("hello-0-server", Protos.TaskState.TASK_FAILED).build());
    // Send an unused offer to trigger an evaluation of the recovery plan
    ticks.add(Send.offer(unacceptableOffer));
    // Expect default transient recovery triggered
    ticks.add(Expect.recoveryStepStatus("hello-0:[server]", "hello-0:[server]", Status.PREPARED));
    // Now trigger custom permanent replacement of that pod
    ticks.add(Send.replacePod("hello-0"));
    // Send an unused offer to trigger an evaluation of the recovery plan
    ticks.add(Send.offer(unacceptableOffer));
    // Custom expectation not relevant to other tests
    Expect expectSingleRecoveryPhase = new Expect() {

        @Override
        public void expect(ClusterState state, SchedulerDriver mockDriver) throws AssertionError {
            Plan recoveryPlan = state.getPlans().stream().filter(plan -> plan.getName().equals("recovery")).findAny().get();
            Assert.assertEquals(1, recoveryPlan.getChildren().size());
        }

        @Override
        public String getDescription() {
            return "Single recovery phase";
        }
    };
    ticks.add(expectSingleRecoveryPhase);
    ticks.add(Expect.recoveryStepStatus("custom-hello-recovery", "hello-0", Status.PREPARED));
    // Complete recovery
    ticks.add(Send.offerBuilder("hello").build());
    ticks.add(Expect.launchedTasks("hello-0-server"));
    ticks.add(Send.taskStatus("hello-0-server", Protos.TaskState.TASK_RUNNING).build());
    ticks.add(Expect.allPlansComplete());
    new ServiceTestRunner().setRecoveryManagerFactory(new RecoveryPlanOverriderFactory() {

        @Override
        public RecoveryPlanOverrider create(StateStore stateStore, Collection<Plan> plans) {
            return new RecoveryPlanOverrider() {

                @Override
                public Optional<Phase> override(PodInstanceRequirement podInstanceRequirement) {
                    if (podInstanceRequirement.getPodInstance().getPod().getType().equals("hello") && podInstanceRequirement.getRecoveryType().equals(RecoveryType.PERMANENT)) {
                        Phase phase = new DefaultPhase("custom-hello-recovery", Arrays.asList(new RecoveryStep(podInstanceRequirement.getPodInstance().getName(), podInstanceRequirement, new UnconstrainedLaunchConstrainer(), stateStore)), new SerialStrategy<>(), Collections.emptyList());
                        return Optional.of(phase);
                    }
                    return Optional.empty();
                }
            };
        }
    }).run(ticks);
}
Also used : StateStore(com.mesosphere.sdk.state.StateStore) RecoveryPlanOverriderFactory(com.mesosphere.sdk.scheduler.recovery.RecoveryPlanOverriderFactory) RecoveryStep(com.mesosphere.sdk.scheduler.recovery.RecoveryStep) RecoveryPlanOverrider(com.mesosphere.sdk.scheduler.recovery.RecoveryPlanOverrider) Protos(org.apache.mesos.Protos) UnconstrainedLaunchConstrainer(com.mesosphere.sdk.scheduler.recovery.constrain.UnconstrainedLaunchConstrainer) SchedulerDriver(org.apache.mesos.SchedulerDriver) Test(org.junit.Test)

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