Search in sources :

Example 6 with SchedulerConfig

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

the class ApiServerTest method getSchedulerConfig.

private SchedulerConfig getSchedulerConfig(int port, Duration timeout) {
    SchedulerConfig mockSchedulerConfig = mock(SchedulerConfig.class);
    when(mockSchedulerConfig.getApiServerInitTimeout()).thenReturn(timeout);
    when(mockSchedulerConfig.getApiServerPort()).thenReturn(port);
    return mockSchedulerConfig;
}
Also used : SchedulerConfig(com.mesosphere.sdk.scheduler.SchedulerConfig)

Example 7 with SchedulerConfig

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

the class OfferEvaluator method evaluate.

public List<OfferRecommendation> evaluate(PodInstanceRequirement podInstanceRequirement, List<Protos.Offer> offers) throws InvalidRequirementException, IOException {
    // All tasks in the service (used by some PlacementRules):
    Map<String, Protos.TaskInfo> allTasks = stateStore.fetchTasks().stream().collect(Collectors.toMap(Protos.TaskInfo::getName, Function.identity()));
    // Preexisting tasks for this pod (if any):
    Map<String, Protos.TaskInfo> thisPodTasks = TaskUtils.getTaskNames(podInstanceRequirement.getPodInstance()).stream().map(taskName -> allTasks.get(taskName)).filter(taskInfo -> taskInfo != null).collect(Collectors.toMap(Protos.TaskInfo::getName, Function.identity()));
    for (int i = 0; i < offers.size(); ++i) {
        List<OfferEvaluationStage> evaluationStages = getEvaluationPipeline(podInstanceRequirement, allTasks.values(), thisPodTasks);
        Protos.Offer offer = offers.get(i);
        MesosResourcePool resourcePool = new MesosResourcePool(offer, OfferEvaluationUtils.getRole(podInstanceRequirement.getPodInstance().getPod()));
        Map<TaskSpec, GoalStateOverride> overrideMap = new HashMap<>();
        for (TaskSpec taskSpec : podInstanceRequirement.getPodInstance().getPod().getTasks()) {
            GoalStateOverride override = stateStore.fetchGoalOverrideStatus(TaskSpec.getInstanceName(podInstanceRequirement.getPodInstance(), taskSpec)).target;
            overrideMap.put(taskSpec, override);
        }
        PodInfoBuilder podInfoBuilder = new PodInfoBuilder(podInstanceRequirement, serviceName, getTargetConfig(podInstanceRequirement, thisPodTasks.values()), templateUrlFactory, schedulerConfig, thisPodTasks.values(), frameworkStore.fetchFrameworkId().get(), useDefaultExecutor, overrideMap);
        List<EvaluationOutcome> outcomes = new ArrayList<>();
        int failedOutcomeCount = 0;
        for (OfferEvaluationStage evaluationStage : evaluationStages) {
            EvaluationOutcome outcome = evaluationStage.evaluate(resourcePool, podInfoBuilder);
            outcomes.add(outcome);
            if (!outcome.isPassing()) {
                failedOutcomeCount++;
            }
        }
        StringBuilder outcomeDetails = new StringBuilder();
        for (EvaluationOutcome outcome : outcomes) {
            logOutcome(outcomeDetails, outcome, "");
        }
        if (outcomeDetails.length() != 0) {
            // trim extra trailing newline:
            outcomeDetails.deleteCharAt(outcomeDetails.length() - 1);
        }
        if (failedOutcomeCount != 0) {
            logger.info("Offer {}, {}: failed {} of {} evaluation stages:\n{}", i + 1, offer.getId().getValue(), failedOutcomeCount, evaluationStages.size(), outcomeDetails.toString());
            offerOutcomeTracker.track(new OfferOutcome(podInstanceRequirement.getName(), false, offer, outcomeDetails.toString()));
        } else {
            List<OfferRecommendation> recommendations = outcomes.stream().map(outcome -> outcome.getOfferRecommendations()).flatMap(xs -> xs.stream()).collect(Collectors.toList());
            logger.info("Offer {}: passed all {} evaluation stages, returning {} recommendations:\n{}", i + 1, evaluationStages.size(), recommendations.size(), outcomeDetails.toString());
            offerOutcomeTracker.track(new OfferOutcome(podInstanceRequirement.getName(), true, offer, outcomeDetails.toString()));
            return recommendations;
        }
    }
    return Collections.emptyList();
}
Also used : OfferOutcomeTracker(com.mesosphere.sdk.offer.history.OfferOutcomeTracker) Protos(org.apache.mesos.Protos) SchedulerConfig(com.mesosphere.sdk.scheduler.SchedulerConfig) java.util(java.util) com.mesosphere.sdk.offer(com.mesosphere.sdk.offer) Logger(org.slf4j.Logger) IOException(java.io.IOException) RecoveryType(com.mesosphere.sdk.scheduler.recovery.RecoveryType) TaskLabelReader(com.mesosphere.sdk.offer.taskdata.TaskLabelReader) ArtifactQueries(com.mesosphere.sdk.http.queries.ArtifactQueries) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) PodInstanceRequirement(com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement) com.mesosphere.sdk.specification(com.mesosphere.sdk.specification) StateStore(com.mesosphere.sdk.state.StateStore) GoalStateOverride(com.mesosphere.sdk.state.GoalStateOverride) VisibleForTesting(com.google.common.annotations.VisibleForTesting) FailureUtils(com.mesosphere.sdk.scheduler.recovery.FailureUtils) TextFormat(com.google.protobuf.TextFormat) OfferOutcome(com.mesosphere.sdk.offer.history.OfferOutcome) FrameworkStore(com.mesosphere.sdk.state.FrameworkStore) GoalStateOverride(com.mesosphere.sdk.state.GoalStateOverride) OfferOutcome(com.mesosphere.sdk.offer.history.OfferOutcome) Protos(org.apache.mesos.Protos)

Example 8 with SchedulerConfig

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

Example 9 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();
    File configDir = yamlSpecFile.getParentFile();
    SchedulerConfig schedulerConfig = SchedulerConfig.fromEnv();
    DefaultServiceSpec serviceSpec = DefaultServiceSpec.newGenerator(rawServiceSpec, schedulerConfig, configDir).setPodEnv("name", SERVICE_ZK_ROOT_TASKENV, CuratorUtils.getServiceRootPath(rawServiceSpec.getName())).setAllPodsEnv(DECODED_AUTH_TO_LOCAL, getHDFSUserAuthMappings(System.getenv(), TASKCFG_ALL_AUTH_TO_LOCAL)).build();
    return DefaultScheduler.newBuilder(setPlacementRules(serviceSpec), schedulerConfig).setRecoveryManagerFactory(new HdfsRecoveryPlanOverriderFactory()).setPlansFrom(rawServiceSpec).setEndpointProducer(HDFS_SITE_XML, EndpointProducer.constant(renderTemplate(new File(configDir, HDFS_SITE_XML), serviceSpec.getName(), schedulerConfig))).setEndpointProducer(CORE_SITE_XML, EndpointProducer.constant(renderTemplate(new File(configDir, CORE_SITE_XML), serviceSpec.getName(), schedulerConfig))).setCustomConfigValidators(Arrays.asList(new HDFSZoneValidator())).withSingleRegionConstraint();
}
Also used : RawServiceSpec(com.mesosphere.sdk.specification.yaml.RawServiceSpec) File(java.io.File) SchedulerConfig(com.mesosphere.sdk.scheduler.SchedulerConfig)

Example 10 with SchedulerConfig

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

the class EndpointUtilsTest method testToAutoIpEndpointCustomTLD.

@Test
public void testToAutoIpEndpointCustomTLD() {
    SchedulerConfig mockSchedulerConfig = SchedulerConfigTestUtils.getTestSchedulerConfig();
    Mockito.when(mockSchedulerConfig.getServiceTLD()).thenReturn("what.a.fun.test.tld");
    assertEquals("task.svc.what.a.fun.test.tld:5", EndpointUtils.toAutoIpEndpoint("svc", "task", 5, mockSchedulerConfig));
    assertEquals("task.pathtosvc.what.a.fun.test.tld:5", EndpointUtils.toAutoIpEndpoint("/path/to/svc", "task", 5, mockSchedulerConfig));
    assertEquals("task.pathtosvc.what.a.fun.test.tld:5", EndpointUtils.toAutoIpEndpoint("path/to/svc", "task", 5, mockSchedulerConfig));
    assertEquals("task.pathtosvc-with-dots.what.a.fun.test.tld:5", EndpointUtils.toAutoIpEndpoint("path/to/svc.with.dots", "task", 5, mockSchedulerConfig));
}
Also used : SchedulerConfig(com.mesosphere.sdk.scheduler.SchedulerConfig) Test(org.junit.Test)

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