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