Search in sources :

Example 1 with SchedulerConfig

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

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

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

the class Main method createSchedulerBuilder.

private static SchedulerBuilder createSchedulerBuilder(File yamlSpecFile) throws Exception {
    SchedulerConfig schedulerConfig = SchedulerConfig.fromEnv();
    RawServiceSpec rawServiceSpec = RawServiceSpec.newBuilder(yamlSpecFile).build();
    List<String> localSeeds = CassandraSeedUtils.getLocalSeeds(rawServiceSpec.getName(), schedulerConfig);
    return DefaultScheduler.newBuilder(DefaultServiceSpec.newGenerator(rawServiceSpec, schedulerConfig, yamlSpecFile.getParentFile()).setAllPodsEnv("LOCAL_SEEDS", Joiner.on(',').join(localSeeds)).build(), schedulerConfig).setCustomConfigValidators(Arrays.asList(new CassandraZoneValidator(), new TaskEnvCannotChange("node", "server", "CASSANDRA_LOCATION_DATA_CENTER", TaskEnvCannotChange.Rule.ALLOW_UNSET_TO_SET))).setPlansFrom(rawServiceSpec).setCustomResources(getResources(localSeeds)).setRecoveryManagerFactory(new CassandraRecoveryPlanOverriderFactory()).withSingleRegionConstraint();
}
Also used : TaskEnvCannotChange(com.mesosphere.sdk.config.validate.TaskEnvCannotChange) RawServiceSpec(com.mesosphere.sdk.specification.yaml.RawServiceSpec) SchedulerConfig(com.mesosphere.sdk.scheduler.SchedulerConfig)

Example 4 with SchedulerConfig

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

the class EndpointsQueriesTest method allEndpointsTest.

@SuppressWarnings("PMD.AvoidUsingHardCodedIP")
private void allEndpointsTest(String serviceName, String serviceNetworkName) {
    SchedulerConfig mockSchedulerConfig = SchedulerConfigTestUtils.getTestSchedulerConfig();
    when(mockStateStore.fetchTasks()).thenReturn(TASK_INFOS);
    Response response = EndpointsQueries.getEndpoints(mockStateStore, serviceName, CUSTOM_ENDPOINTS, mockSchedulerConfig);
    assertEquals(200, response.getStatus());
    JSONArray json = new JSONArray((String) response.getEntity());
    assertEquals(json.toString(), 4, json.length());
    assertEquals(CUSTOM_KEY, json.get(0));
    assertEquals("novip", json.get(1));
    assertEquals("porta", json.get(2));
    assertEquals("portb", json.get(3));
    assertEquals(CUSTOM_VALUE, EndpointsQueries.getEndpoint(mockStateStore, serviceName, CUSTOM_ENDPOINTS, CUSTOM_KEY, mockSchedulerConfig).getEntity());
    // 'novip' port is listed across the two 'vips-' tasks
    JSONObject endpointNoVip = new JSONObject((String) EndpointsQueries.getEndpoint(mockStateStore, serviceName, CUSTOM_ENDPOINTS, "novip", mockSchedulerConfig).getEntity());
    assertEquals(2, endpointNoVip.length());
    JSONArray dns = endpointNoVip.getJSONArray("dns");
    assertEquals(2, dns.length());
    assertEquals("vips-1." + serviceNetworkName + EXPECTED_DNS_TLD + ":2348", dns.get(0));
    assertEquals("vips-2." + serviceNetworkName + EXPECTED_DNS_TLD + ":3459", dns.get(1));
    JSONArray address = endpointNoVip.getJSONArray("address");
    assertEquals(2, address.length());
    assertEquals(TestConstants.HOSTNAME + ":2348", address.get(0));
    assertEquals(TestConstants.HOSTNAME + ":3459", address.get(1));
    // 'porta' is listed across the two 'ports-' tasks and the two 'vips-' tasks
    JSONObject endpointPortA = new JSONObject((String) EndpointsQueries.getEndpoint(mockStateStore, serviceName, CUSTOM_ENDPOINTS, "porta", mockSchedulerConfig).getEntity());
    assertEquals(3, endpointPortA.length());
    assertEquals("vip1." + serviceNetworkName + ".l4lb.thisdcos.directory:5432", endpointPortA.get("vip"));
    dns = endpointPortA.getJSONArray("dns");
    assertEquals(4, dns.length());
    assertEquals("ports-1." + serviceNetworkName + EXPECTED_DNS_TLD + ":1234", dns.get(0));
    assertEquals("ports-2." + serviceNetworkName + EXPECTED_DNS_TLD + ":1243", dns.get(1));
    assertEquals("vips-1." + serviceNetworkName + EXPECTED_DNS_TLD + ":2345", dns.get(2));
    assertEquals("vips-2." + serviceNetworkName + EXPECTED_DNS_TLD + ":3456", dns.get(3));
    address = endpointPortA.getJSONArray("address");
    assertEquals(4, address.length());
    assertEquals(TestConstants.HOSTNAME + ":1234", address.get(0));
    assertEquals(TestConstants.HOSTNAME + ":1243", address.get(1));
    assertEquals(TestConstants.HOSTNAME + ":2345", address.get(2));
    assertEquals(TestConstants.HOSTNAME + ":3456", address.get(3));
    // 'portb' is just listed in the 'ports-1' and 'vips-2' tasks
    JSONObject endpointPortB = new JSONObject((String) EndpointsQueries.getEndpoint(mockStateStore, serviceName, CUSTOM_ENDPOINTS, "portb", mockSchedulerConfig).getEntity());
    assertEquals(3, endpointPortB.length());
    dns = endpointPortB.getJSONArray("dns");
    assertEquals(2, dns.length());
    assertEquals("ports-1." + serviceNetworkName + EXPECTED_DNS_TLD + ":1235", dns.get(0));
    assertEquals("vips-2." + serviceNetworkName + EXPECTED_DNS_TLD + ":3457", dns.get(1));
    address = endpointPortB.getJSONArray("address");
    assertEquals(2, address.length());
    assertEquals(TestConstants.HOSTNAME + ":1235", address.get(0));
    assertEquals(TestConstants.HOSTNAME + ":3457", address.get(1));
}
Also used : Response(javax.ws.rs.core.Response) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) SchedulerConfig(com.mesosphere.sdk.scheduler.SchedulerConfig)

Example 5 with SchedulerConfig

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

the class SchedulerConfigTestUtils method getTestSchedulerConfig.

public static SchedulerConfig getTestSchedulerConfig() {
    SchedulerConfig schedulerConfig = mock(SchedulerConfig.class);
    when(schedulerConfig.getApiServerPort()).thenReturn(TestConstants.PORT_API_VALUE);
    when(schedulerConfig.getExecutorURI()).thenReturn("test-executor-uri");
    when(schedulerConfig.getJavaURI()).thenReturn("test-java-uri");
    when(schedulerConfig.getBootstrapURI()).thenReturn("test-bootstrap-uri");
    when(schedulerConfig.getLibmesosURI()).thenReturn("test-libmesos-uri");
    when(schedulerConfig.getDcosSpace()).thenReturn("/");
    when(schedulerConfig.getSecretsNamespace(TestConstants.SERVICE_NAME)).thenReturn(TestConstants.SERVICE_NAME);
    when(schedulerConfig.getApiServerInitTimeout()).thenReturn(Duration.ofSeconds(10));
    when(schedulerConfig.getServiceTLD()).thenReturn(Constants.DNS_TLD);
    when(schedulerConfig.getSchedulerRegion()).thenReturn(Optional.of("test-region"));
    return schedulerConfig;
}
Also used : SchedulerConfig(com.mesosphere.sdk.scheduler.SchedulerConfig)

Aggregations

SchedulerConfig (com.mesosphere.sdk.scheduler.SchedulerConfig)10 RawServiceSpec (com.mesosphere.sdk.specification.yaml.RawServiceSpec)5 SchedulerBuilder (com.mesosphere.sdk.scheduler.SchedulerBuilder)3 File (java.io.File)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 TextFormat (com.google.protobuf.TextFormat)1 TaskEnvCannotChange (com.mesosphere.sdk.config.validate.TaskEnvCannotChange)1 Capabilities (com.mesosphere.sdk.dcos.Capabilities)1 ArtifactQueries (com.mesosphere.sdk.http.queries.ArtifactQueries)1 com.mesosphere.sdk.offer (com.mesosphere.sdk.offer)1 OfferOutcome (com.mesosphere.sdk.offer.history.OfferOutcome)1 OfferOutcomeTracker (com.mesosphere.sdk.offer.history.OfferOutcomeTracker)1 TaskLabelReader (com.mesosphere.sdk.offer.taskdata.TaskLabelReader)1 AbstractScheduler (com.mesosphere.sdk.scheduler.AbstractScheduler)1 SchedulerRunner (com.mesosphere.sdk.scheduler.SchedulerRunner)1 PodInstanceRequirement (com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement)1 FailureUtils (com.mesosphere.sdk.scheduler.recovery.FailureUtils)1 RecoveryType (com.mesosphere.sdk.scheduler.recovery.RecoveryType)1 com.mesosphere.sdk.specification (com.mesosphere.sdk.specification)1 FrameworkStore (com.mesosphere.sdk.state.FrameworkStore)1