Search in sources :

Example 6 with Capabilities

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

the class DefaultStepFactoryTest method testTaskWithOnceGoalStateCanReachGoalState.

@Test
public void testTaskWithOnceGoalStateCanReachGoalState() throws Exception {
    Capabilities mockCapabilities = Mockito.mock(Capabilities.class);
    Mockito.when(mockCapabilities.supportsDefaultExecutor()).thenReturn(true);
    Capabilities.overrideCapabilities(mockCapabilities);
    PodInstance podInstance = getPodInstanceWithGoalState(GoalState.ONCE);
    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 7 with Capabilities

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

the class DefaultStepFactoryTest method testTaskWithFinishedGoalStateCanReachGoalState.

@Test
public void testTaskWithFinishedGoalStateCanReachGoalState() throws Exception {
    Capabilities mockCapabilities = Mockito.mock(Capabilities.class);
    Mockito.when(mockCapabilities.supportsDefaultExecutor()).thenReturn(true);
    Capabilities.overrideCapabilities(mockCapabilities);
    PodInstance podInstance = getPodInstanceWithGoalState(GoalState.FINISHED);
    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 8 with Capabilities

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

the class DefaultCapabilitiesTestSuite method beforeAllSuites.

@BeforeClass
public static final void beforeAllSuites() throws Exception {
    Capabilities capabilities = mock(Capabilities.class);
    when(capabilities.supportsGpuResource()).thenReturn(true);
    when(capabilities.supportsCNINetworking()).thenReturn(true);
    when(capabilities.supportsNamedVips()).thenReturn(true);
    when(capabilities.supportsRLimits()).thenReturn(true);
    when(capabilities.supportsPreReservedResources()).thenReturn(true);
    when(capabilities.supportsFileBasedSecrets()).thenReturn(true);
    when(capabilities.supportsEnvBasedSecretsProtobuf()).thenReturn(true);
    when(capabilities.supportsEnvBasedSecretsDirectiveLabel()).thenReturn(true);
    context = new ResourceRefinementCapabilityContext(capabilities);
}
Also used : Capabilities(com.mesosphere.sdk.dcos.Capabilities) ResourceRefinementCapabilityContext(com.mesosphere.sdk.dcos.ResourceRefinementCapabilityContext) BeforeClass(org.junit.BeforeClass)

Example 9 with Capabilities

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

the class DefaultServiceSpecTest method validateServiceSpec.

private void validateServiceSpec(String fileName, Boolean supportGpu) throws Exception {
    ClassLoader classLoader = getClass().getClassLoader();
    File file = new File(classLoader.getResource(fileName).getFile());
    DefaultServiceSpec serviceSpec = DefaultServiceSpec.newGenerator(file, SCHEDULER_CONFIG).build();
    capabilities = mock(Capabilities.class);
    when(capabilities.supportsGpuResource()).thenReturn(supportGpu);
    when(capabilities.supportsCNINetworking()).thenReturn(true);
    when(capabilities.supportsDomains()).thenReturn(true);
    Capabilities.overrideCapabilities(capabilities);
    DefaultScheduler.newBuilder(serviceSpec, SCHEDULER_CONFIG, new MemPersister()).build();
}
Also used : MemPersister(com.mesosphere.sdk.storage.MemPersister) Capabilities(com.mesosphere.sdk.dcos.Capabilities) File(java.io.File)

Example 10 with Capabilities

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

the class PodSpecsCannotUseUnsupportedFeatures method validate.

@Override
public Collection<ConfigValidationError> validate(Optional<ServiceSpec> oldConfig, ServiceSpec newConfig) {
    Collection<ConfigValidationError> errors = new ArrayList<>();
    Capabilities capabilities = Capabilities.getInstance();
    boolean supportsPreReservedResources = capabilities.supportsPreReservedResources();
    boolean supportsGpus = capabilities.supportsGpuResource();
    boolean supportsRLimits = capabilities.supportsRLimits();
    boolean supportsCNI = capabilities.supportsCNINetworking();
    boolean supportsEnvBasedSecrets = capabilities.supportsEnvBasedSecretsProtobuf();
    boolean supportsFileBasedSecrets = capabilities.supportsFileBasedSecrets();
    for (PodSpec podSpec : newConfig.getPods()) {
        if (!supportsGpus && podRequestsGpuResources(podSpec)) {
            errors.add(ConfigValidationError.valueError("pod:" + podSpec.getType(), Constants.GPUS_RESOURCE_TYPE, "This DC/OS cluster does not support GPU resources"));
        }
        if (!supportsPreReservedResources && !podSpec.getPreReservedRole().equals(Constants.ANY_ROLE)) {
            errors.add(ConfigValidationError.valueError("pod:" + podSpec.getType(), "pre-reserved-role", "This DC/OS cluster does not support consuming pre-reserved resources."));
        }
        if (!supportsRLimits && !podSpec.getRLimits().isEmpty()) {
            errors.add(ConfigValidationError.valueError("pod:" + podSpec.getType(), "rlimits", "This DC/OS cluster does not support setting rlimits"));
        }
        if (!supportsCNI && podRequestsCNI(podSpec)) {
            errors.add(ConfigValidationError.valueError("pod:" + podSpec.getType(), "network", "This DC/OS cluster does not support CNI port mapping"));
        }
        // TODO(MB) : Change validator if we decide to support DCOS_DIRECTIVE label
        if (!supportsEnvBasedSecrets && podRequestsEnvBasedSecrets(podSpec)) {
            errors.add(ConfigValidationError.valueError("pod:" + podSpec.getType(), "secrets:env", "This DC/OS cluster does not support environment-based secrets"));
        }
        if (!supportsFileBasedSecrets && podRequestsFileBasedSecrets(podSpec)) {
            errors.add(ConfigValidationError.valueError("pod:" + podSpec.getType(), "secrets:file", "This DC/OS cluster does not support file-based secrets"));
        }
    }
    return errors;
}
Also used : Capabilities(com.mesosphere.sdk.dcos.Capabilities) ArrayList(java.util.ArrayList)

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