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