Search in sources :

Example 1 with SchedulerBuilder

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

the class Main method createSchedulerBuilder.

private static SchedulerBuilder createSchedulerBuilder(File yamlSpecFile) throws Exception {
    RawServiceSpec rawServiceSpec = RawServiceSpec.newBuilder(yamlSpecFile).build();
    SchedulerConfig schedulerConfig = SchedulerConfig.fromEnv();
    // Allow users to manually specify a ZK location for kafka itself. Otherwise default to our service ZK location:
    String kafkaZookeeperUri = System.getenv(KAFKA_ZK_URI_ENV);
    if (StringUtils.isEmpty(kafkaZookeeperUri)) {
        // "master.mesos:2181" + "/dcos-service-path__to__my__kafka":
        kafkaZookeeperUri = FrameworkConfig.fromRawServiceSpec(rawServiceSpec).getZookeeperHostPort() + CuratorUtils.getServiceRootPath(rawServiceSpec.getName());
    }
    LOGGER.info("Running Kafka with zookeeper path: {}", kafkaZookeeperUri);
    SchedulerBuilder schedulerBuilder = DefaultScheduler.newBuilder(DefaultServiceSpec.newGenerator(rawServiceSpec, schedulerConfig, yamlSpecFile.getParentFile()).setAllPodsEnv(KAFKA_ZK_URI_ENV, kafkaZookeeperUri).build(), schedulerConfig).setCustomConfigValidators(Arrays.asList(new KafkaZoneValidator())).setPlansFrom(rawServiceSpec);
    return schedulerBuilder.setEndpointProducer("zookeeper", EndpointProducer.constant(kafkaZookeeperUri)).setCustomResources(getResources(kafkaZookeeperUri)).withSingleRegionConstraint();
}
Also used : RawServiceSpec(com.mesosphere.sdk.specification.yaml.RawServiceSpec) SchedulerBuilder(com.mesosphere.sdk.scheduler.SchedulerBuilder) SchedulerConfig(com.mesosphere.sdk.scheduler.SchedulerConfig)

Example 2 with SchedulerBuilder

use of com.mesosphere.sdk.scheduler.SchedulerBuilder 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 SchedulerBuilder

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

the class Main method main.

public static void main(String[] args) throws Exception {
    final SchedulerConfig schedulerConfig = SchedulerConfig.fromEnv();
    final SchedulerRunner runner;
    File yamlSpecFile;
    ServiceSpec serviceSpec;
    SchedulerBuilder builder;
    Scenario scenario = getScenario();
    LOGGER.info("Scheduler operating under scenario: {}", scenario.name());
    switch(scenario) {
        case Java:
            // Create a sample config in Java
            runner = SchedulerRunner.fromServiceSpec(createSampleServiceSpec(schedulerConfig), schedulerConfig);
            break;
        case YAML:
            // Read config from provided file, and assume any config templates
            // are in the same directory as the file:
            yamlSpecFile = new File(args[0]);
            runner = SchedulerRunner.fromRawServiceSpec(RawServiceSpec.newBuilder(yamlSpecFile).build(), schedulerConfig, yamlSpecFile.getParentFile());
            break;
        case MULTI_REGION:
            yamlSpecFile = new File(args[0]);
            serviceSpec = DefaultServiceSpec.newGenerator(yamlSpecFile, SchedulerConfig.fromEnv()).build();
            builder = DefaultScheduler.newBuilder(serviceSpec, SchedulerConfig.fromEnv()).withSingleRegionConstraint();
            runner = SchedulerRunner.fromSchedulerBuilder(builder);
            break;
        case CUSTOM_PLAN:
            yamlSpecFile = new File(args[0]);
            serviceSpec = DefaultServiceSpec.newGenerator(yamlSpecFile, SchedulerConfig.fromEnv()).build();
            builder = DefaultScheduler.newBuilder(serviceSpec, SchedulerConfig.fromEnv()).setPlanCustomizer(new ReversePhasesCustomizer());
            runner = SchedulerRunner.fromSchedulerBuilder(builder);
            break;
        case CUSTOM_DECOMMISSION:
            yamlSpecFile = new File(args[0]);
            serviceSpec = DefaultServiceSpec.newGenerator(yamlSpecFile, SchedulerConfig.fromEnv()).build();
            builder = DefaultScheduler.newBuilder(serviceSpec, SchedulerConfig.fromEnv()).setPlanCustomizer(new DecomissionCustomizer());
            runner = SchedulerRunner.fromSchedulerBuilder(builder);
            break;
        default:
            throw new IllegalStateException(String.format("Unexpected scnenario '%s'", scenario.name()));
    }
    runner.run();
}
Also used : SchedulerRunner(com.mesosphere.sdk.scheduler.SchedulerRunner) RawServiceSpec(com.mesosphere.sdk.specification.yaml.RawServiceSpec) SchedulerBuilder(com.mesosphere.sdk.scheduler.SchedulerBuilder) SchedulerConfig(com.mesosphere.sdk.scheduler.SchedulerConfig) File(java.io.File)

Aggregations

SchedulerBuilder (com.mesosphere.sdk.scheduler.SchedulerBuilder)3 SchedulerConfig (com.mesosphere.sdk.scheduler.SchedulerConfig)3 RawServiceSpec (com.mesosphere.sdk.specification.yaml.RawServiceSpec)3 Capabilities (com.mesosphere.sdk.dcos.Capabilities)1 AbstractScheduler (com.mesosphere.sdk.scheduler.AbstractScheduler)1 SchedulerRunner (com.mesosphere.sdk.scheduler.SchedulerRunner)1 File (java.io.File)1 SchedulerDriver (org.apache.mesos.SchedulerDriver)1