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));
}
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));
}
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);
}
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();
}
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;
}
Aggregations