@Override public void registered( SchedulerDriver schedulerDriver, Protos.FrameworkID frameworkID, Protos.MasterInfo masterInfo) { LOGGER.info("Registered! ID = " + frameworkID.getValue()); }
@Override public void registered( final SchedulerDriver driver, Protos.FrameworkID frameworkId, Protos.MasterInfo masterInfo) { Runtime.getRuntime() .addShutdownHook( new Thread( new Runnable() { @Override public void run() { driver.stop(); } })); LOG.info( "Registered framework {} with master {}:{}", frameworkId.getValue(), masterInfo.getHostname(), masterInfo.getPort()); }
public static void main(String[] args) throws Exception { BasicConfigurator.configure(); Configuration configuration = parseConfiguration(args); final double frameworkFailoverTimeout = 31536000d; // 60 * 60 * 24 * 365 = 1y final String host = System.getenv("MESOS_HOSTNAME"); final String webUri = UriBuilder.fromPath("/cluster") .scheme("http") .host(host == null ? currentHost() : host) .port(configuration.apiPort) .build() .toString(); Protos.FrameworkInfo.Builder frameworkBuilder = Protos.FrameworkInfo.newBuilder() .setName(configuration.frameworkName) .setUser(configuration.user) .setRole(configuration.role) .setWebuiUrl(webUri) .setCheckpoint(true) // will be enabled by default in Mesos 0.22 .setFailoverTimeout(frameworkFailoverTimeout); PersistentStateStore stateStore = new PersistentStateStore( new ZooKeeperState( configuration.zookeeper, 20_000, TimeUnit.MILLISECONDS, String.format("/%s/%s", configuration.frameworkName, configuration.clusterName)), configuration.nodeCount); Optional<String> frameworkId = stateStore.state().frameworkId(); if (frameworkId.isPresent()) { frameworkBuilder.setId(Protos.FrameworkID.newBuilder().setValue(frameworkId.get()).build()); } final Scheduler scheduler = new CrateScheduler(stateStore, configuration); // create the driver MesosSchedulerDriver driver; String mesosMaster = configuration.mesosMaster(); Optional<Protos.Credential> credential = readCredentials(); if (credential.isPresent()) { frameworkBuilder.setPrincipal(credential.get().getPrincipal()); driver = new MesosSchedulerDriver( scheduler, frameworkBuilder.build(), mesosMaster, credential.get()); } else { frameworkBuilder.setPrincipal("crate-framework"); driver = new MesosSchedulerDriver(scheduler, frameworkBuilder.build(), mesosMaster); } CrateHttpService api = new CrateHttpService(stateStore, configuration); api.start(); int status = driver.run() == Protos.Status.DRIVER_STOPPED ? 0 : 1; // Ensure that the driver process terminates. api.stop(); driver.stop(); System.exit(status); }