@Override protected void configure() { bind(Runnable.class) .annotatedWith(Names.named(AbortHandler.ABORT_HANDLER_KEY)) .to(AbortCallback.class); bind(AbortCallback.class).in(Singleton.class); bind(Runnable.class) .annotatedWith(Names.named(QuitHandler.QUIT_HANDLER_KEY)) .to(QuitCallback.class); bind(QuitCallback.class).in(Singleton.class); bind(new TypeLiteral<Supplier<Boolean>>() {}) .annotatedWith(Names.named(HealthHandler.HEALTH_CHECKER_KEY)) .toInstance(Suppliers.ofInstance(true)); final Optional<String> hostnameOverride = Optional.fromNullable(HOSTNAME_OVERRIDE.get()); if (hostnameOverride.isPresent()) { try { InetAddress.getByName(hostnameOverride.get()); } catch (UnknownHostException e) { /* Possible misconfiguration, so warn the user. */ LOG.warning( "Unable to resolve name specified in -hostname. " + "Depending on your environment, this may be valid."); } } install( new PrivateModule() { @Override protected void configure() { bind(new TypeLiteral<Optional<String>>() {}).toInstance(hostnameOverride); bind(HttpService.class).to(HttpServerLauncher.class); bind(HttpServerLauncher.class).in(Singleton.class); expose(HttpServerLauncher.class); expose(HttpService.class); } }); SchedulerServicesModule.addAppStartupServiceBinding(binder()).to(HttpServerLauncher.class); bind(LeaderRedirect.class).in(Singleton.class); SchedulerServicesModule.addAppStartupServiceBinding(binder()).to(RedirectMonitor.class); if (production) { install(PRODUCTION_SERVLET_CONTEXT_LISTENER); } }
@Override protected void startUp() { server = new Server(); ServletContextHandler servletHandler = new ServletContextHandler(server, "/", ServletContextHandler.NO_SESSIONS); servletHandler.addServlet(DefaultServlet.class, "/"); servletHandler.addFilter(GuiceFilter.class, "/*", EnumSet.allOf(DispatcherType.class)); servletHandler.addEventListener(servletContextListener); HandlerCollection rootHandler = new HandlerList(); RequestLogHandler logHandler = new RequestLogHandler(); logHandler.setRequestLog(new Slf4jRequestLog()); rootHandler.addHandler(logHandler); rootHandler.addHandler(servletHandler); ServerConnector connector = new ServerConnector(server); connector.setPort(HTTP_PORT.get()); server.addConnector(connector); server.setHandler(getGzipHandler(getRewriteHandler(rootHandler))); try { connector.open(); server.start(); } catch (Exception e) { throw Throwables.propagate(e); } String host; if (connector.getHost() == null) { // Resolve the local host name. try { host = InetAddress.getLocalHost().getHostAddress(); } catch (UnknownHostException e) { throw new RuntimeException("Failed to resolve local host address: " + e, e); } } else { // If jetty was configured with a specific host to bind to, use that. host = connector.getHost(); } serverAddress = HostAndPort.fromParts(host, connector.getLocalPort()); }
/** * Check validity of and populates defaults in a task configuration. This will return a deep copy * of the provided task configuration with default configuration values applied, and configuration * map values sanitized and applied to their respective struct fields. * * @param config Task config to validate and populate. * @return A reference to the modified {@code config} (for chaining). * @throws TaskDescriptionException If the task is invalid. */ public static ITaskConfig validateAndPopulate(ITaskConfig config) throws TaskDescriptionException { TaskConfig builder = config.newBuilder(); if (!builder.isSetRequestedPorts()) { builder.setRequestedPorts(ImmutableSet.of()); } maybeFillLinks(builder); if (!isGoodIdentifier(config.getJobName())) { throw new TaskDescriptionException( "Job name contains illegal characters: " + config.getJobName()); } if (!isGoodIdentifier(config.getEnvironment())) { throw new TaskDescriptionException( "Environment contains illegal characters: " + config.getEnvironment()); } if (config.isSetTier() && !isGoodIdentifier(config.getTier())) { throw new TaskDescriptionException("Tier contains illegal characters: " + config.getTier()); } if (config.isSetJob()) { if (!JobKeys.isValid(config.getJob())) { // Job key is set but invalid throw new TaskDescriptionException("Job key " + config.getJob() + " is invalid."); } if (!config.getJob().getRole().equals(config.getOwner().getRole())) { // Both owner and job key are set but don't match throw new TaskDescriptionException("Role must match job owner."); } } else { // TODO(maxim): Make sure both key and owner are populated to support older clients. // Remove in 0.7.0. (AURORA-749). // Job key is not set -> populate from owner, environment and name assertOwnerValidity(config.getOwner()); builder.setJob( JobKeys.from(config.getOwner().getRole(), config.getEnvironment(), config.getJobName()) .newBuilder()); } if (!builder.isSetExecutorConfig()) { throw new TaskDescriptionException("Configuration may not be null"); } // Maximize the usefulness of any thrown error message by checking required fields first. for (RequiredFieldValidator<?> validator : REQUIRED_FIELDS_VALIDATORS) { validator.validate(builder); } IConstraint constraint = getDedicatedConstraint(config); if (constraint != null) { if (!isValueConstraint(constraint.getConstraint())) { throw new TaskDescriptionException("A dedicated constraint must be of value type."); } IValueConstraint valueConstraint = constraint.getConstraint().getValue(); if (valueConstraint.getValues().size() != 1) { throw new TaskDescriptionException("A dedicated constraint must have exactly one value"); } String dedicatedRole = getRole(valueConstraint); if (!config.getOwner().getRole().equals(dedicatedRole)) { throw new TaskDescriptionException( "Only " + dedicatedRole + " may use hosts dedicated for that role."); } } Optional<Container._Fields> containerType; if (config.isSetContainer()) { IContainer containerConfig = config.getContainer(); containerType = Optional.of(containerConfig.getSetField()); if (containerConfig.isSetDocker()) { if (!containerConfig.getDocker().isSetImage()) { throw new TaskDescriptionException("A container must specify an image"); } if (containerConfig.getDocker().isSetParameters() && !containerConfig.getDocker().getParameters().isEmpty() && !ENABLE_DOCKER_PARAMETERS.get()) { throw new TaskDescriptionException("Docker parameters not allowed."); } } } else { // Default to mesos container type if unset. containerType = Optional.of(Container._Fields.MESOS); } if (!containerType.isPresent()) { throw new TaskDescriptionException("A job must have a container type."); } if (!ALLOWED_CONTAINER_TYPES.get().contains(containerType.get())) { throw new TaskDescriptionException( "The container type " + containerType.get().toString() + " is not allowed"); } return ITaskConfig.build(builder); }
public AopModule() { this( ImmutableMap.of( "createJob", ENABLE_JOB_CREATION.get(), "acquireLock", ENABLE_UPDATES.get())); }