Search in sources :

Example 1 with Capabilities

use of com.mesosphere.sdk.dcos.Capabilities in project dcos-commons by mesosphere.

the class FrameworkRunner method getFrameworkInfo.

public Protos.FrameworkInfo getFrameworkInfo(Optional<Protos.FrameworkID> frameworkId) {
    Protos.FrameworkInfo.Builder fwkInfoBuilder = Protos.FrameworkInfo.newBuilder().setName(frameworkConfig.getFrameworkName()).setPrincipal(frameworkConfig.getPrincipal()).setUser(frameworkConfig.getUser()).setFailoverTimeout(TWO_WEEK_SEC).setCheckpoint(true);
    // The framework ID is not available when we're being started for the first time.
    frameworkId.ifPresent(fwkInfoBuilder::setId);
    if (frameworkConfig.getPreReservedRoles().isEmpty()) {
        setRole(fwkInfoBuilder, frameworkConfig.getRole());
    } else {
        fwkInfoBuilder.addCapabilitiesBuilder().setType(Protos.FrameworkInfo.Capability.Type.MULTI_ROLE);
        fwkInfoBuilder.addRoles(frameworkConfig.getRole()).addAllRoles(frameworkConfig.getPreReservedRoles());
    }
    if (!StringUtils.isEmpty(frameworkConfig.getWebUrl())) {
        fwkInfoBuilder.setWebuiUrl(frameworkConfig.getWebUrl());
    }
    Capabilities capabilities = Capabilities.getInstance();
    if (usingGpus && capabilities.supportsGpuResource()) {
        fwkInfoBuilder.addCapabilitiesBuilder().setType(Protos.FrameworkInfo.Capability.Type.GPU_RESOURCES);
    }
    if (capabilities.supportsPreReservedResources()) {
        fwkInfoBuilder.addCapabilitiesBuilder().setType(Protos.FrameworkInfo.Capability.Type.RESERVATION_REFINEMENT);
    }
    // Only enable if opted-in by the developer or user.
    if (usingRegions && capabilities.supportsDomains()) {
        fwkInfoBuilder.addCapabilitiesBuilder().setType(Protos.FrameworkInfo.Capability.Type.REGION_AWARE);
    }
    return fwkInfoBuilder.build();
}
Also used : Capabilities(com.mesosphere.sdk.dcos.Capabilities)

Example 2 with Capabilities

use of com.mesosphere.sdk.dcos.Capabilities in project dcos-commons by mesosphere.

the class ServiceTestRunner method run.

/**
 * Exercises the service's packaging and resulting Service Specification YAML file, then runs the provided
 * simulation ticks, if any are provided.
 *
 * @return a {@link ServiceTestResult} containing the resulting scheduler environment and spec information
 * @throws Exception if the test failed
 */
public ServiceTestResult run(Collection<SimulationTick> ticks) throws Exception {
    SchedulerConfig mockSchedulerConfig = Mockito.mock(SchedulerConfig.class);
    Mockito.when(mockSchedulerConfig.getExecutorURI()).thenReturn("test-executor-uri");
    Mockito.when(mockSchedulerConfig.getLibmesosURI()).thenReturn("test-libmesos-uri");
    Mockito.when(mockSchedulerConfig.getJavaURI()).thenReturn("test-java-uri");
    Mockito.when(mockSchedulerConfig.getBootstrapURI()).thenReturn("bootstrap-uri");
    Mockito.when(mockSchedulerConfig.getApiServerPort()).thenReturn(8080);
    Mockito.when(mockSchedulerConfig.getDcosSpace()).thenReturn("test-space");
    Mockito.when(mockSchedulerConfig.getServiceTLD()).thenReturn(Constants.DNS_TLD);
    Mockito.when(mockSchedulerConfig.getSchedulerRegion()).thenReturn(Optional.of("test-scheduler-region"));
    Capabilities mockCapabilities = Mockito.mock(Capabilities.class);
    Mockito.when(mockCapabilities.supportsGpuResource()).thenReturn(true);
    Mockito.when(mockCapabilities.supportsCNINetworking()).thenReturn(true);
    Mockito.when(mockCapabilities.supportsNamedVips()).thenReturn(true);
    Mockito.when(mockCapabilities.supportsRLimits()).thenReturn(true);
    Mockito.when(mockCapabilities.supportsPreReservedResources()).thenReturn(true);
    Mockito.when(mockCapabilities.supportsFileBasedSecrets()).thenReturn(true);
    Mockito.when(mockCapabilities.supportsEnvBasedSecretsProtobuf()).thenReturn(true);
    Mockito.when(mockCapabilities.supportsEnvBasedSecretsDirectiveLabel()).thenReturn(true);
    Mockito.when(mockCapabilities.supportsDomains()).thenReturn(true);
    Mockito.when(mockCapabilities.supportsDefaultExecutor()).thenReturn(supportsDefaultExecutor);
    Capabilities.overrideCapabilities(mockCapabilities);
    // Disable background TaskKiller thread, to avoid erroneous kill invocations
    TaskKiller.reset(false);
    Map<String, String> schedulerEnvironment = CosmosRenderer.renderSchedulerEnvironment(cosmosOptions, buildTemplateParams);
    schedulerEnvironment.putAll(customSchedulerEnv);
    // Test 1: Does RawServiceSpec render?
    RawServiceSpec rawServiceSpec = RawServiceSpec.newBuilder(specPath).setEnv(schedulerEnvironment).build();
    // Test 2: Does ServiceSpec render?
    ServiceSpec serviceSpec = DefaultServiceSpec.newGenerator(rawServiceSpec, mockSchedulerConfig, schedulerEnvironment, configTemplateDir).build();
    // Test 3: Does the scheduler build?
    SchedulerBuilder schedulerBuilder = DefaultScheduler.newBuilder(serviceSpec, mockSchedulerConfig, persister).setPlansFrom(rawServiceSpec).setRecoveryManagerFactory(recoveryManagerFactory).setCustomConfigValidators(validators);
    if (namespace.isPresent()) {
        schedulerBuilder.setNamespace(namespace.get());
    }
    AbstractScheduler abstractScheduler = schedulerBuilder.build().disableThreading().disableApiServer();
    // Test 4: Can we render the per-task config templates without any missing values?
    Collection<ServiceTestResult.TaskConfig> taskConfigs = getTaskConfigs(serviceSpec, mockSchedulerConfig);
    // Test 5: Run simulation, if any was provided
    ClusterState clusterState;
    if (oldClusterState == null) {
        // Initialize new cluster state
        clusterState = ClusterState.create(serviceSpec, abstractScheduler);
    } else {
        // Carry over prior cluster state
        clusterState = ClusterState.withUpdatedConfig(oldClusterState, serviceSpec, abstractScheduler);
    }
    SchedulerDriver mockDriver = Mockito.mock(SchedulerDriver.class);
    for (SimulationTick tick : ticks) {
        if (tick instanceof Expect) {
            LOGGER.info("EXPECT: {}", tick.getDescription());
            try {
                ((Expect) tick).expect(clusterState, mockDriver);
            } catch (Throwable e) {
                throw buildSimulationError(ticks, tick, e);
            }
        } else if (tick instanceof Send) {
            LOGGER.info("SEND:   {}", tick.getDescription());
            ((Send) tick).send(clusterState, mockDriver, abstractScheduler.getMesosScheduler().get());
        } else {
            throw new IllegalArgumentException(String.format("Unrecognized tick type: %s", tick));
        }
    }
    // Reset Capabilities API to default behavior:
    Capabilities.overrideCapabilities(null);
    // Re-enable background TaskKiller thread for other tests
    TaskKiller.reset(true);
    return new ServiceTestResult(serviceSpec, rawServiceSpec, schedulerEnvironment, taskConfigs, persister, clusterState);
}
Also used : RawServiceSpec(com.mesosphere.sdk.specification.yaml.RawServiceSpec) RawServiceSpec(com.mesosphere.sdk.specification.yaml.RawServiceSpec) Capabilities(com.mesosphere.sdk.dcos.Capabilities) SchedulerBuilder(com.mesosphere.sdk.scheduler.SchedulerBuilder) SchedulerConfig(com.mesosphere.sdk.scheduler.SchedulerConfig) AbstractScheduler(com.mesosphere.sdk.scheduler.AbstractScheduler) SchedulerDriver(org.apache.mesos.SchedulerDriver)

Example 3 with Capabilities

use of com.mesosphere.sdk.dcos.Capabilities in project dcos-commons by mesosphere.

the class DefaultStepFactoryTest method testTaskWithFinishGoalStateCanReachGoalState.

@Test
public void testTaskWithFinishGoalStateCanReachGoalState() throws Exception {
    Capabilities mockCapabilities = Mockito.mock(Capabilities.class);
    Mockito.when(mockCapabilities.supportsDefaultExecutor()).thenReturn(true);
    Capabilities.overrideCapabilities(mockCapabilities);
    PodInstance podInstance = getPodInstanceWithGoalState(GoalState.FINISH);
    List<String> tasksToLaunch = podInstance.getPod().getTasks().stream().map(taskSpec -> taskSpec.getName()).collect(Collectors.toList());
    UUID configId = UUID.randomUUID();
    configStore.setTargetConfig(configId);
    String taskName = podInstance.getName() + '-' + tasksToLaunch.get(0);
    stateStore.storeTasks(ImmutableList.of(Protos.TaskInfo.newBuilder().setName(taskName).setTaskId(CommonIdUtils.toTaskId(TestConstants.SERVICE_NAME, taskName)).setSlaveId(Protos.SlaveID.newBuilder().setValue("proto-field-required")).setLabels(new TaskLabelWriter(TestConstants.TASK_INFO).setTargetConfiguration(configId).toProto()).build()));
    Protos.TaskInfo taskInfo = stateStore.fetchTask(taskName).get();
    stateStore.storeStatus(taskName, Protos.TaskStatus.newBuilder().setState(Protos.TaskState.TASK_RUNNING).setTaskId(taskInfo.getTaskId()).build());
    assertThat(((DefaultStepFactory) stepFactory).hasReachedGoalState(podInstance, stateStore.fetchTask(taskName).get()), is(false));
    stateStore.storeStatus(taskName, Protos.TaskStatus.newBuilder().setState(Protos.TaskState.TASK_FINISHED).setTaskId(taskInfo.getTaskId()).build());
    assertThat(((DefaultStepFactory) stepFactory).hasReachedGoalState(podInstance, stateStore.fetchTask(taskName).get()), is(true));
}
Also used : SchedulerConfigTestUtils(com.mesosphere.sdk.testutils.SchedulerConfigTestUtils) Protos(org.apache.mesos.Protos) SchedulerConfig(com.mesosphere.sdk.scheduler.SchedulerConfig) Arrays(java.util.Arrays) TestConstants(com.mesosphere.sdk.testutils.TestConstants) CommonIdUtils(com.mesosphere.sdk.offer.CommonIdUtils) Test(org.junit.Test) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) MemPersister(com.mesosphere.sdk.storage.MemPersister) TaskLabelWriter(com.mesosphere.sdk.offer.taskdata.TaskLabelWriter) ConfigStore(com.mesosphere.sdk.state.ConfigStore) Assert.assertThat(org.junit.Assert.assertThat) Mockito(org.mockito.Mockito) Capabilities(com.mesosphere.sdk.dcos.Capabilities) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) com.mesosphere.sdk.specification(com.mesosphere.sdk.specification) StateStore(com.mesosphere.sdk.state.StateStore) Persister(com.mesosphere.sdk.storage.Persister) Matchers.is(org.hamcrest.Matchers.is) TestPodFactory(com.mesosphere.sdk.testutils.TestPodFactory) Assert(org.junit.Assert) Protos(org.apache.mesos.Protos) Capabilities(com.mesosphere.sdk.dcos.Capabilities) TaskLabelWriter(com.mesosphere.sdk.offer.taskdata.TaskLabelWriter) UUID(java.util.UUID) Test(org.junit.Test)

Example 4 with Capabilities

use of com.mesosphere.sdk.dcos.Capabilities in project dcos-commons by mesosphere.

the class DefaultStepFactoryTest method testInitialStateForRunningTaskOnCustomExecutorIsRunning.

@Test
public void testInitialStateForRunningTaskOnCustomExecutorIsRunning() throws Exception {
    Capabilities mockCapabilities = Mockito.mock(Capabilities.class);
    Mockito.when(mockCapabilities.supportsDefaultExecutor()).thenReturn(false);
    Capabilities.overrideCapabilities(mockCapabilities);
    PodInstance podInstance = getPodInstanceWithASingleTask();
    List<String> tasksToLaunch = podInstance.getPod().getTasks().stream().map(taskSpec -> taskSpec.getName()).collect(Collectors.toList());
    UUID configId = UUID.randomUUID();
    configStore.setTargetConfig(configId);
    String taskName = podInstance.getName() + '-' + tasksToLaunch.get(0);
    stateStore.storeTasks(ImmutableList.of(Protos.TaskInfo.newBuilder().setName(taskName).setTaskId(CommonIdUtils.toTaskId(TestConstants.SERVICE_NAME, taskName)).setSlaveId(Protos.SlaveID.newBuilder().setValue("proto-field-required")).setLabels(new TaskLabelWriter(TestConstants.TASK_INFO).setTargetConfiguration(configId).setReadinessCheck(Protos.HealthCheck.newBuilder().build()).toProto()).build()));
    Protos.TaskInfo taskInfo = stateStore.fetchTask(taskName).get();
    stateStore.storeStatus(taskName, Protos.TaskStatus.newBuilder().setState(Protos.TaskState.TASK_RUNNING).setTaskId(taskInfo.getTaskId()).setLabels(Protos.Labels.newBuilder().addLabels(Protos.Label.newBuilder().setKey("readiness_check_passed").setValue("false").build()).build()).build());
    assertThat(((DefaultStepFactory) stepFactory).hasReachedGoalState(podInstance, stateStore.fetchTask(taskName).get()), is(true));
    final Step step = stepFactory.getStep(podInstance, tasksToLaunch);
    assertThat(step.isComplete(), is(true));
    assertThat(step.isPending(), is(false));
}
Also used : SchedulerConfigTestUtils(com.mesosphere.sdk.testutils.SchedulerConfigTestUtils) Protos(org.apache.mesos.Protos) SchedulerConfig(com.mesosphere.sdk.scheduler.SchedulerConfig) Arrays(java.util.Arrays) TestConstants(com.mesosphere.sdk.testutils.TestConstants) CommonIdUtils(com.mesosphere.sdk.offer.CommonIdUtils) Test(org.junit.Test) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) MemPersister(com.mesosphere.sdk.storage.MemPersister) TaskLabelWriter(com.mesosphere.sdk.offer.taskdata.TaskLabelWriter) ConfigStore(com.mesosphere.sdk.state.ConfigStore) Assert.assertThat(org.junit.Assert.assertThat) Mockito(org.mockito.Mockito) Capabilities(com.mesosphere.sdk.dcos.Capabilities) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) com.mesosphere.sdk.specification(com.mesosphere.sdk.specification) StateStore(com.mesosphere.sdk.state.StateStore) Persister(com.mesosphere.sdk.storage.Persister) Matchers.is(org.hamcrest.Matchers.is) TestPodFactory(com.mesosphere.sdk.testutils.TestPodFactory) Assert(org.junit.Assert) Protos(org.apache.mesos.Protos) Capabilities(com.mesosphere.sdk.dcos.Capabilities) TaskLabelWriter(com.mesosphere.sdk.offer.taskdata.TaskLabelWriter) UUID(java.util.UUID) Test(org.junit.Test)

Example 5 with Capabilities

use of com.mesosphere.sdk.dcos.Capabilities in project dcos-commons by mesosphere.

the class DefaultStepFactoryTest method testInitialStateForRunningTaskOnDefaultExecutorDependsOnReadinessCheck.

@Test
public void testInitialStateForRunningTaskOnDefaultExecutorDependsOnReadinessCheck() throws Exception {
    Capabilities mockCapabilities = Mockito.mock(Capabilities.class);
    Mockito.when(mockCapabilities.supportsDefaultExecutor()).thenReturn(true);
    Capabilities.overrideCapabilities(mockCapabilities);
    PodInstance podInstance = getPodInstanceWithASingleTask();
    List<String> tasksToLaunch = podInstance.getPod().getTasks().stream().map(taskSpec -> taskSpec.getName()).collect(Collectors.toList());
    UUID configId = UUID.randomUUID();
    configStore.setTargetConfig(configId);
    String taskName = podInstance.getName() + '-' + tasksToLaunch.get(0);
    stateStore.storeTasks(ImmutableList.of(Protos.TaskInfo.newBuilder().setName(taskName).setTaskId(CommonIdUtils.toTaskId(TestConstants.SERVICE_NAME, taskName)).setSlaveId(Protos.SlaveID.newBuilder().setValue("proto-field-required")).setLabels(new TaskLabelWriter(TestConstants.TASK_INFO).setTargetConfiguration(configId).setReadinessCheck(Protos.HealthCheck.newBuilder().build()).toProto()).build()));
    Protos.TaskInfo taskInfo = stateStore.fetchTask(taskName).get();
    stateStore.storeStatus(taskName, Protos.TaskStatus.newBuilder().setState(Protos.TaskState.TASK_RUNNING).setTaskId(taskInfo.getTaskId()).setLabels(Protos.Labels.newBuilder().addLabels(Protos.Label.newBuilder().setKey("readiness_check_passed").setValue("false").build()).build()).build());
    assertThat(((DefaultStepFactory) stepFactory).hasReachedGoalState(podInstance, stateStore.fetchTask(taskName).get()), is(false));
    Step step = stepFactory.getStep(podInstance, tasksToLaunch);
    assertThat(step.isComplete(), is(false));
    assertThat(step.isPending(), is(true));
    stateStore.storeStatus(taskName, Protos.TaskStatus.newBuilder().setState(Protos.TaskState.TASK_RUNNING).setTaskId(taskInfo.getTaskId()).setLabels(Protos.Labels.newBuilder().addLabels(Protos.Label.newBuilder().setKey("readiness_check_passed").setValue("true").build()).build()).build());
    assertThat(((DefaultStepFactory) stepFactory).hasReachedGoalState(podInstance, stateStore.fetchTask(taskName).get()), is(true));
    step = stepFactory.getStep(podInstance, tasksToLaunch);
    assertThat(step.isComplete(), is(true));
    assertThat(step.isPending(), is(false));
}
Also used : SchedulerConfigTestUtils(com.mesosphere.sdk.testutils.SchedulerConfigTestUtils) Protos(org.apache.mesos.Protos) SchedulerConfig(com.mesosphere.sdk.scheduler.SchedulerConfig) Arrays(java.util.Arrays) TestConstants(com.mesosphere.sdk.testutils.TestConstants) CommonIdUtils(com.mesosphere.sdk.offer.CommonIdUtils) Test(org.junit.Test) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) MemPersister(com.mesosphere.sdk.storage.MemPersister) TaskLabelWriter(com.mesosphere.sdk.offer.taskdata.TaskLabelWriter) ConfigStore(com.mesosphere.sdk.state.ConfigStore) Assert.assertThat(org.junit.Assert.assertThat) Mockito(org.mockito.Mockito) Capabilities(com.mesosphere.sdk.dcos.Capabilities) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) com.mesosphere.sdk.specification(com.mesosphere.sdk.specification) StateStore(com.mesosphere.sdk.state.StateStore) Persister(com.mesosphere.sdk.storage.Persister) Matchers.is(org.hamcrest.Matchers.is) TestPodFactory(com.mesosphere.sdk.testutils.TestPodFactory) Assert(org.junit.Assert) Protos(org.apache.mesos.Protos) Capabilities(com.mesosphere.sdk.dcos.Capabilities) TaskLabelWriter(com.mesosphere.sdk.offer.taskdata.TaskLabelWriter) UUID(java.util.UUID) Test(org.junit.Test)

Aggregations

Capabilities (com.mesosphere.sdk.dcos.Capabilities)10 SchedulerConfig (com.mesosphere.sdk.scheduler.SchedulerConfig)6 MemPersister (com.mesosphere.sdk.storage.MemPersister)6 ImmutableList (com.google.common.collect.ImmutableList)5 CommonIdUtils (com.mesosphere.sdk.offer.CommonIdUtils)5 TaskLabelWriter (com.mesosphere.sdk.offer.taskdata.TaskLabelWriter)5 com.mesosphere.sdk.specification (com.mesosphere.sdk.specification)5 ConfigStore (com.mesosphere.sdk.state.ConfigStore)5 StateStore (com.mesosphere.sdk.state.StateStore)5 Persister (com.mesosphere.sdk.storage.Persister)5 SchedulerConfigTestUtils (com.mesosphere.sdk.testutils.SchedulerConfigTestUtils)5 TestConstants (com.mesosphere.sdk.testutils.TestConstants)5 TestPodFactory (com.mesosphere.sdk.testutils.TestPodFactory)5 Arrays (java.util.Arrays)5 List (java.util.List)5 UUID (java.util.UUID)5 Collectors (java.util.stream.Collectors)5 Protos (org.apache.mesos.Protos)5 Matchers.is (org.hamcrest.Matchers.is)5 Assert (org.junit.Assert)5