use of org.apache.mesos.MesosSchedulerDriver in project elastic-job by dangdangdotcom.
the class SchedulerService method getSchedulerDriver.
private SchedulerDriver getSchedulerDriver(final TaskScheduler taskScheduler, final JobEventBus jobEventBus, final FrameworkIDService frameworkIDService) {
MesosConfiguration mesosConfig = env.getMesosConfiguration();
Optional<String> frameworkIDOptional = frameworkIDService.fetch();
Protos.FrameworkInfo.Builder builder = Protos.FrameworkInfo.newBuilder();
if (frameworkIDOptional.isPresent()) {
builder.setId(Protos.FrameworkID.newBuilder().setValue(frameworkIDOptional.get()).build());
}
Protos.FrameworkInfo frameworkInfo = builder.setUser(mesosConfig.getUser()).setName(FRAMEWORK_NAME).setHostname(mesosConfig.getHostname()).setFailoverTimeout(FRAMEWORK_FAILOVER_TIMEOUT).setWebuiUrl(WEB_UI_PROTOCOL + env.getFrameworkHostPort()).build();
return new MesosSchedulerDriver(new SchedulerEngine(taskScheduler, facadeService, jobEventBus, frameworkIDService, statisticManager), frameworkInfo, mesosConfig.getUrl());
}
use of org.apache.mesos.MesosSchedulerDriver in project storm-mesos by nathanmarz.
the class MesosNimbus method prepare.
@Override
public void prepare(Map conf, String localDir) {
try {
_conf = conf;
_state = new LocalState(localDir);
String id = (String) _state.get(FRAMEWORK_ID);
_allowedHosts = listIntoSet((List) _conf.get(CONF_MESOS_ALLOWED_HOSTS));
_disallowedHosts = listIntoSet((List) _conf.get(CONF_MESOS_DISALLOWED_HOSTS));
Semaphore initter = new Semaphore(0);
_scheduler = new NimbusScheduler(initter);
Number failoverTimeout = (Number) conf.get(CONF_MASTER_FAILOVER_TIMEOUT_SECS);
if (failoverTimeout == null)
failoverTimeout = 3600;
FrameworkInfo.Builder finfo = FrameworkInfo.newBuilder().setName("Storm-0.8.0").setFailoverTimeout(failoverTimeout.doubleValue()).setUser("");
if (id != null) {
finfo.setId(FrameworkID.newBuilder().setValue(id).build());
}
MesosSchedulerDriver driver = new MesosSchedulerDriver(_scheduler, finfo.build(), (String) conf.get(CONF_MASTER_URL));
driver.start();
LOG.info("Waiting for scheduler to initialize...");
initter.acquire();
LOG.info("Scheduler initialized...");
} catch (IOException e) {
throw new RuntimeException(e);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
use of org.apache.mesos.MesosSchedulerDriver in project alluxio by Alluxio.
the class AlluxioFramework method run.
/**
* Runs the mesos framework.
*/
public void run() {
Protos.FrameworkInfo.Builder frameworkInfo = Protos.FrameworkInfo.newBuilder().setName("alluxio").setCheckpoint(true);
if (Configuration.containsKey(PropertyKey.INTEGRATION_MESOS_ROLE)) {
frameworkInfo.setRole(Configuration.get(PropertyKey.INTEGRATION_MESOS_ROLE));
}
// Setting the user to an empty string will prompt Mesos to set it to the current user.
if (Configuration.containsKey(PropertyKey.INTEGRATION_MESOS_USER)) {
frameworkInfo.setUser(Configuration.get(PropertyKey.INTEGRATION_MESOS_USER));
}
if (Configuration.containsKey(PropertyKey.INTEGRATION_MESOS_PRINCIPAL)) {
frameworkInfo.setPrincipal(Configuration.get(PropertyKey.INTEGRATION_MESOS_PRINCIPAL));
}
Scheduler scheduler = new AlluxioScheduler(mAlluxioMasterHostname);
Protos.Credential cred = createCredential();
MesosSchedulerDriver driver;
if (cred == null) {
driver = new MesosSchedulerDriver(scheduler, frameworkInfo.build(), mMesosMaster);
} else {
driver = new MesosSchedulerDriver(scheduler, frameworkInfo.build(), mMesosMaster, cred);
}
int status = driver.run() == Protos.Status.DRIVER_STOPPED ? 0 : 1;
System.exit(status);
}
use of org.apache.mesos.MesosSchedulerDriver in project ignite by apache.
the class IgniteFramework method main.
/**
* Main methods has only one optional parameter - path to properties files.
*
* @param args Args.
* @throws Exception If failed.
*/
public static void main(String[] args) throws Exception {
IgniteFramework igniteFramework = new IgniteFramework();
ClusterProperties clusterProps = ClusterProperties.from(args.length >= 1 ? args[0] : null);
String baseUrl = String.format("http://%s:%d", clusterProps.httpServerHost(), clusterProps.httpServerPort());
JettyServer httpSrv = new JettyServer();
httpSrv.start(new ResourceHandler(clusterProps.userLibs(), clusterProps.igniteCfg(), clusterProps.igniteWorkDir()), clusterProps);
ResourceProvider provider = new ResourceProvider();
IgniteProvider igniteProvider = new IgniteProvider(clusterProps.igniteWorkDir());
provider.init(clusterProps, igniteProvider, baseUrl);
// Create the scheduler.
Scheduler scheduler = new IgniteScheduler(clusterProps, provider);
// Create the driver.
MesosSchedulerDriver driver;
if (System.getenv(MESOS_AUTHENTICATE) != null) {
log.info("Enabling authentication for the framework");
if (System.getenv(DEFAULT_PRINCIPAL) == null) {
log.log(Level.SEVERE, "Expecting authentication principal in the environment");
System.exit(1);
}
if (System.getenv(DEFAULT_SECRET) == null) {
log.log(Level.SEVERE, "Expecting authentication secret in the environment");
System.exit(1);
}
Protos.Credential cred = Protos.Credential.newBuilder().setPrincipal(System.getenv(DEFAULT_PRINCIPAL)).setSecret(ByteString.copyFrom(System.getenv(DEFAULT_SECRET).getBytes())).build();
driver = new MesosSchedulerDriver(scheduler, igniteFramework.getFrameworkInfo(), clusterProps.masterUrl(), cred);
} else
driver = new MesosSchedulerDriver(scheduler, igniteFramework.getFrameworkInfo(), clusterProps.masterUrl());
int status = driver.run() == Protos.Status.DRIVER_STOPPED ? 0 : 1;
httpSrv.stop();
// Ensure that the driver process terminates.
driver.stop();
System.exit(status);
}
use of org.apache.mesos.MesosSchedulerDriver in project cassandra-mesos-deprecated by mesosphere.
the class Main method _main.
private static int _main() throws UnknownHostException {
final Optional<String> portOption = Env.option("PORT0");
if (!portOption.isPresent()) {
throw new SystemExitException("Environment variable PORT0 must be defined", 5);
}
final int port0 = Integer.parseInt(portOption.get());
final String host = Env.option("HOST").or("localhost");
final Optional<String> clusterNameOpt = Env.option("CASSANDRA_CLUSTER_NAME");
final int executorCount = Integer.parseInt(Env.option("CASSANDRA_NODE_COUNT").or("3"));
final int seedCount = Integer.parseInt(Env.option("CASSANDRA_SEED_COUNT").or("2"));
final double resourceCpuCores = Double.parseDouble(Env.option("CASSANDRA_RESOURCE_CPU_CORES").or("2.0"));
final long resourceMemoryMegabytes = Long.parseLong(Env.option("CASSANDRA_RESOURCE_MEM_MB").or("2048"));
final long resourceDiskMegabytes = Long.parseLong(Env.option("CASSANDRA_RESOURCE_DISK_MB").or("2048"));
final long javaHeapMb = Long.parseLong(Env.option("CASSANDRA_RESOURCE_HEAP_MB").or("0"));
final long healthCheckIntervalSec = Long.parseLong(Env.option("CASSANDRA_HEALTH_CHECK_INTERVAL_SECONDS").or("60"));
final long bootstrapGraceTimeSec = Long.parseLong(Env.option("CASSANDRA_BOOTSTRAP_GRACE_TIME_SECONDS").or("120"));
final String cassandraVersion = "2.1.4";
final String clusterName = clusterNameOpt.or("cassandra");
final String frameworkName = frameworkName(clusterNameOpt);
final String zkUrl = Env.option("CASSANDRA_ZK").or("zk://localhost:2181/cassandra-mesos");
final long zkTimeoutMs = Long.parseLong(Env.option("CASSANDRA_ZK_TIMEOUT_MS").or("10000"));
final String mesosMasterZkUrl = Env.option("MESOS_ZK").or("zk://localhost:2181/mesos");
final String mesosUser = Env.option("MESOS_USER").or("");
final long failoverTimeout = Long.parseLong(Env.option("CASSANDRA_FAILOVER_TIMEOUT_SECONDS").or(String.valueOf(Period.days(7).toStandardSeconds().getSeconds())));
final String mesosRole = Env.option("CASSANDRA_FRAMEWORK_MESOS_ROLE").or("*");
// TODO: Temporary. Will be removed when MESOS-1554 is released
final String dataDirectory = Env.option("CASSANDRA_DATA_DIRECTORY").or(DEFAULT_DATA_DIRECTORY);
final String backupDirectory = Env.option("CASSANDRA_BACKUP_DIRECTORY").or(DEFAULT_BACKUP_DIRECTORY);
final boolean jmxLocal = Boolean.parseBoolean(Env.option("CASSANDRA_JMX_LOCAL").or("true"));
final boolean jmxNoAuthentication = Boolean.parseBoolean(Env.option("CASSANDRA_JMX_NO_AUTHENTICATION").or("false"));
final String defaultRack = Env.option("CASSANDRA_DEFAULT_RACK").or("RAC1");
final String defaultDc = Env.option("CASSANDRA_DEFAULT_DC").or("DC1");
final List<ExternalDc> externalDcs = getExternalDcs(Env.filterStartsWith("CASSANDRA_EXTERNAL_DC_", true));
final Matcher matcher = validateZkUrl(zkUrl);
final State state = new ZooKeeperState(matcher.group(1), zkTimeoutMs, TimeUnit.MILLISECONDS, matcher.group(2));
if (seedCount > executorCount || seedCount <= 0 || executorCount <= 0) {
throw new IllegalArgumentException("number of nodes (" + executorCount + ") and/or number of seeds (" + seedCount + ") invalid");
}
final PersistedCassandraFrameworkConfiguration configuration = new PersistedCassandraFrameworkConfiguration(state, frameworkName, healthCheckIntervalSec, bootstrapGraceTimeSec, cassandraVersion, resourceCpuCores, resourceDiskMegabytes, resourceMemoryMegabytes, javaHeapMb, executorCount, seedCount, mesosRole, backupDirectory, dataDirectory, jmxLocal, jmxNoAuthentication, defaultRack, defaultDc, externalDcs, clusterName);
final FrameworkInfo.Builder frameworkBuilder = FrameworkInfo.newBuilder().setFailoverTimeout(failoverTimeout).setUser(mesosUser).setName(frameworkName).setRole(mesosRole).setCheckpoint(true);
final Optional<String> frameworkId = configuration.frameworkId();
if (frameworkId.isPresent()) {
frameworkBuilder.setId(frameworkId(frameworkId.get()));
}
final URI httpServerBaseUri = URI.create("http://" + host + ":" + port0 + "/");
final Clock clock = new SystemClock();
final PersistedCassandraClusterHealthCheckHistory healthCheckHistory = new PersistedCassandraClusterHealthCheckHistory(state);
final PersistedCassandraClusterState clusterState = new PersistedCassandraClusterState(state);
final SeedManager seedManager = new SeedManager(configuration, new ObjectMapper(), new SystemClock());
final CassandraCluster cassandraCluster = new CassandraCluster(clock, httpServerBaseUri.toString(), new ExecutorCounter(state, 0L), clusterState, healthCheckHistory, new PersistedCassandraClusterJobs(state), configuration, seedManager);
final HealthReportService healthReportService = new HealthReportService(clusterState, configuration, healthCheckHistory, clock);
final Scheduler scheduler = new CassandraScheduler(configuration, cassandraCluster, clock);
final JsonFactory factory = new JsonFactory();
final ObjectMapper objectMapper = new ObjectMapper(factory);
objectMapper.registerModule(new GuavaModule());
// create JsonProvider to provide custom ObjectMapper
JacksonJaxbJsonProvider provider = new JacksonJaxbJsonProvider();
provider.setMapper(objectMapper);
final ResourceConfig rc = new ResourceConfig().registerInstances(new FileResourceController(cassandraVersion), new ApiController(factory), new ClusterCleanupController(cassandraCluster, factory), new ClusterRepairController(cassandraCluster, factory), new ClusterRollingRestartController(cassandraCluster, factory), new ClusterBackupController(cassandraCluster, factory), new ClusterRestoreController(cassandraCluster, factory), new ConfigController(cassandraCluster, factory), new LiveEndpointsController(cassandraCluster, factory), new NodeController(cassandraCluster, factory), new HealthCheckController(healthReportService), new QaReportController(cassandraCluster, factory), new ScaleOutController(cassandraCluster, factory), provider);
final HttpServer httpServer = GrizzlyHttpServerFactory.createHttpServer(httpServerBaseUri, rc);
final MesosSchedulerDriver driver;
final Optional<Credential> credentials = getCredential();
if (credentials.isPresent()) {
frameworkBuilder.setPrincipal(credentials.get().getPrincipal());
driver = new MesosSchedulerDriver(scheduler, frameworkBuilder.build(), mesosMasterZkUrl, credentials.get());
} else {
frameworkBuilder.setPrincipal("cassandra-framework");
driver = new MesosSchedulerDriver(scheduler, frameworkBuilder.build(), mesosMasterZkUrl);
}
seedManager.startSyncingSeeds(60);
final int status;
switch(driver.run()) {
case DRIVER_STOPPED:
status = 0;
break;
case DRIVER_ABORTED:
status = 1;
break;
case DRIVER_NOT_STARTED:
status = 2;
break;
default:
status = 3;
break;
}
httpServer.shutdownNow();
// Ensure that the driver process terminates.
driver.stop(true);
return status;
}
Aggregations