@Override protected void configure() { install(new SettingsModule()); bind(Environment.class).toInstance(_environment); bind(HealthCheckRegistry.class).to(DropwizardHealthCheckRegistry.class).asEagerSingleton(); bind(LifeCycleRegistry.class).to(DropwizardLifeCycleRegistry.class).asEagerSingleton(); bind(ZooKeeperConfiguration.class).toInstance(_configuration.getZooKeeperConfiguration()); bind(String.class).annotatedWith(ServerCluster.class).toInstance(_configuration.getCluster()); bind(MetricRegistry.class).toInstance(_environment.metrics()); bind(ServerFactory.class).toInstance(_configuration.getServerFactory()); bind(DataCenterConfiguration.class).toInstance(_configuration.getDataCenterConfiguration()); bind(CqlDriverConfiguration.class).toInstance(_configuration.getCqlDriverConfiguration()); bind(Clock.class).toInstance(Clock.systemUTC()); }
private static void updatePortsToAvoidCollision(ServerFactory serverFactory) { if (serverFactory instanceof DefaultServerFactory) { DefaultServerFactory defaultServerFactory = (DefaultServerFactory)serverFactory; updatePortsToAvoidCollision(defaultServerFactory.getApplicationConnectors()); updatePortsToAvoidCollision(defaultServerFactory.getAdminConnectors()); } else if (serverFactory instanceof SimpleServerFactory) { SimpleServerFactory simpleServerFactory = (SimpleServerFactory)serverFactory; updatePortsToAvoidCollision(Collections.singleton(simpleServerFactory.getConnector())); } else { throw new IllegalStateException("Encountered an unexpected ServerFactory type"); } }
@Provides @Singleton @SelfHostAndPort public HostAndPort provideSelfHostAndPort(ServerFactory serverFactory) { // Our method for obtaining connector factories from the server factory varies depending on the latter's type List<ConnectorFactory> appConnectorFactories; if (serverFactory instanceof DefaultServerFactory) { appConnectorFactories = ((DefaultServerFactory) serverFactory).getApplicationConnectors(); } else if (serverFactory instanceof SimpleServerFactory) { appConnectorFactories = Collections.singletonList(((SimpleServerFactory) serverFactory).getConnector()); } else { throw new IllegalStateException("Encountered an unexpected ServerFactory type"); } return getHostAndPortFromConnectorFactories(appConnectorFactories); }
@Provides @Singleton @SelfAdminHostAndPort public HostAndPort provideSelfAdminHostAndPort(ServerFactory serverFactory) { // Our method for obtaining connector factories from the server factory varies depending on the latter's type List<ConnectorFactory> adminConnectorFactories; if (serverFactory instanceof DefaultServerFactory) { adminConnectorFactories = ((DefaultServerFactory) serverFactory).getAdminConnectors(); } else if (serverFactory instanceof SimpleServerFactory) { adminConnectorFactories = Collections.singletonList(((SimpleServerFactory) serverFactory).getConnector()); } else { throw new IllegalStateException("Encountered an unexpected ServerFactory type"); } return getHostAndPortFromConnectorFactories(adminConnectorFactories); }
@Override public void start() throws Exception { EurekaClientConfiguration eurekaClientConfiguration = configuration.getEureka(); ServerFactory serverFactory = configuration.getServerFactory(); BaseConfiguration baseConfiguration = new BaseConfiguration(); baseConfiguration.setProperty(eurekaNamespace + "name", eurekaClientConfiguration.getName()); baseConfiguration.setProperty(eurekaNamespace + "vipAddress", eurekaClientConfiguration.getVipAddress()); baseConfiguration.setProperty(eurekaNamespace + "serviceUrl.default", eurekaClientConfiguration.getDefaultServiceUrl()); baseConfiguration.setProperty(eurekaNamespace + "port", eurekaClientConfiguration.getPort()); Integer port = DropwizardServerHelpers.getPort(serverFactory); Integer adminPort = DropwizardServerHelpers.getAdminPort(serverFactory); baseConfiguration.setProperty(eurekaNamespace + "healthCheckUrl", String.format("http://${eureka.hostname}:%d/healthcheck", adminPort)); baseConfiguration.setProperty(eurekaNamespace + "secureHealthCheckUrl", String.format("http://${eureka.hostname}:%d/healthcheck", adminPort)); baseConfiguration.setProperty(eurekaNamespace + "statusPageUrl", String.format("http://${eureka.hostname}:%d/healthcheck", adminPort)); ConfigurationManager.loadPropertiesFromConfiguration(baseConfiguration); EurekaInstanceConfig eurekaInstanceConfig = createEurekaInstanceConfig(discoveryMetadataProviders); DiscoveryManager.getInstance().initComponent(eurekaInstanceConfig, new DefaultEurekaClientConfig(eurekaNamespace)); DiscoveryManager.getInstance().getDiscoveryClient().registerHealthCheckCallback(healthCheck); markAsUp(); }
public static Integer getPort(ServerFactory serverFactory) { if(serverFactory instanceof SimpleServerFactory) { return getPort(((SimpleServerFactory)serverFactory).getConnector()); } else if(serverFactory instanceof DefaultServerFactory) { return getPort(((DefaultServerFactory)serverFactory).getApplicationConnectors().get(0)); } throw new RuntimeException("Unable to infer Port of " + serverFactory); }
public static Integer getAdminPort(ServerFactory serverFactory) { if(serverFactory instanceof SimpleServerFactory) { return getPort(((SimpleServerFactory)serverFactory).getConnector()); } else if(serverFactory instanceof DefaultServerFactory) { return getPort(((DefaultServerFactory)serverFactory).getAdminConnectors().get(0)); } throw new RuntimeException("Unable to infer AdminPort of " + serverFactory); }
private @Nonnull HttpConnectorFactory getConnectorFactoy(ServerFactory serverFactory) { if(serverFactory instanceof DefaultServerFactory) { return getDefaultServerFactory(serverFactory); } else if(serverFactory instanceof SimpleServerFactory) { return getSimpleServerFactory(serverFactory); } throw new IllegalArgumentException( String.format("Unknonw ServerFactory instance '%s'", serverFactory.getClass().getName())); }
private @Nonnull HttpConnectorFactory getSimpleServerFactory(ServerFactory serverFactory) { HttpConnectorFactory connector = (HttpConnectorFactory) ((SimpleServerFactory)serverFactory).getConnector(); if (connector.getClass().isAssignableFrom(HttpConnectorFactory.class)) { return connector; } throw new IllegalArgumentException(String.format("Failed to find any server ConnectorFactory in serverFactory '%s'", serverFactory.getClass().getName())); }
private @Nonnull HttpConnectorFactory getDefaultServerFactory(ServerFactory serverFactory) { for (ConnectorFactory connector : ((DefaultServerFactory)serverFactory).getApplicationConnectors()) { if (connector.getClass().isAssignableFrom(HttpConnectorFactory.class)) { return (HttpConnectorFactory) connector; } } throw new IllegalArgumentException(String.format("Failed to find any server ConnectorFactory in serverFactory '%s'", serverFactory.getClass().getName())); }
/** * @param conf orient server configuration object * @param mapper for serializing orient security json from yaml configuration * @param serverFactory dropwizard connectors configuration */ public EmbeddedOrientServer(final OrientServerConfiguration conf, final ObjectMapper mapper, final ServerFactory serverFactory) { this.conf = validateConfiguration(conf); this.mapper = mapper; this.dwServer = serverFactory; }
protected void configureHystrix(T configuration, Environment environment) { final ServerFactory serverFactory = configuration.getServerFactory(); final Duration shutdownGracePeriod = (serverFactory instanceof AbstractServerFactory) ? ((AbstractServerFactory) serverFactory).getShutdownGracePeriod() : Duration.seconds(30L); environment.lifecycle().manage(new ManagedHystrix(shutdownGracePeriod)); }
@BeforeClass public void setup() throws Exception { _lifeCycle = new SimpleLifeCycleRegistry(); _healthChecks = mock(HealthCheckRegistry.class); // Start test instance of ZooKeeper in the current JVM TestingServer testingServer = new TestingServer(); _lifeCycle.manage(testingServer); // Connect to ZooKeeper final CuratorFramework curator = CuratorFrameworkFactory.newClient(testingServer.getConnectString(), new BoundedExponentialBackoffRetry(100, 1000, 5)); _lifeCycle.manage(curator).start(); // Setup the DataStoreModule Injector injector = Guice.createInjector(new AbstractModule() { @Override protected void configure() { bind(LifeCycleRegistry.class).toInstance(_lifeCycle); bind(HealthCheckRegistry.class).toInstance(_healthChecks); bind(TaskRegistry.class).toInstance(mock(TaskRegistry.class)); bind(DataStoreConfiguration.class).toInstance(new DataStoreConfiguration() .setSystemTablePlacement("app_global:sys") .setValidTablePlacements(ImmutableSet.of("app_global:sys", "ugc_global:ugc")) .setCassandraClusters(ImmutableMap.<String, CassandraConfiguration>of( "ugc_global", new TestCassandraConfiguration("ugc_global", "ugc_delta"), "app_global", new TestCassandraConfiguration("app_global", "sys_delta"))) .setHistoryTtl(Period.days(2))); bind(DataStore.class).annotatedWith(SystemDataStore.class).toInstance(mock(DataStore.class)); bind(JobService.class).toInstance(mock(JobService.class)); bind(JobHandlerRegistry.class).toInstance(mock(JobHandlerRegistry.class)); bind(DataCenterConfiguration.class).toInstance(new DataCenterConfiguration() .setCurrentDataCenter("datacenter1") .setSystemDataCenter("datacenter1") .setDataCenterServiceUri(URI.create("http://localhost:8080")) .setDataCenterAdminUri(URI.create("http://localhost:8080"))); bind(CqlDriverConfiguration.class).toInstance(new CqlDriverConfiguration()); bind(KeyspaceDiscovery.class).annotatedWith(Names.named("blob")).toInstance(mock(KeyspaceDiscovery.class)); bind(String.class).annotatedWith(ServerCluster.class).toInstance("local_default"); bind(String.class).annotatedWith(ReplicationKey.class).toInstance("password"); bind(String.class).annotatedWith(InvalidationService.class).toInstance("emodb-cachemgr"); bind(CuratorFramework.class).annotatedWith(Global.class).toInstance(curator); bind(CuratorFramework.class).annotatedWith(DataStoreZooKeeper.class) .toInstance(ZKNamespaces.usingChildNamespace(curator, "applications/emodb-sor")); bind(CuratorFramework.class).annotatedWith(GlobalFullConsistencyZooKeeper.class) .toInstance(ZKNamespaces.usingChildNamespace(curator, "applications/emodb-fct")); bind(new TypeLiteral<Supplier<Boolean>>(){}).annotatedWith(CqlForScans.class) .toInstance(Suppliers.ofInstance(true)); bind(new TypeLiteral<Supplier<Boolean>>(){}).annotatedWith(CqlForMultiGets.class) .toInstance(Suppliers.ofInstance(true)); bind(ServerFactory.class).toInstance(new SimpleServerFactory()); bind(ServiceRegistry.class).toInstance(mock(ServiceRegistry.class)); bind(Clock.class).toInstance(Clock.systemDefaultZone()); EmoServiceMode serviceMode = EmoServiceMode.STANDARD_ALL; install(new SelfHostAndPortModule()); install(new DataCenterModule(serviceMode)); install(new CacheManagerModule()); install(new DataStoreModule(serviceMode)); } }); _store = injector.getInstance(DataStore.class); _lifeCycle.start(); Map<String, Object> template = Collections.emptyMap(); _store.createTable(TABLE, new TableOptionsBuilder().setPlacement("ugc_global:ugc").build(), template, newAudit("create table")); }
public void run(T configuration, Environment environment) { handler = determineHandler(configuration, environment); ServerFactory serverFactory = configuration.getServerFactory(); ServerFactoryWrapper factoryWrapper = new ServerFactoryWrapper(serverFactory, handler); configuration.setServerFactory(factoryWrapper); }
public ServerFactoryWrapper(ServerFactory serverFactory, WebsocketHandler handler) { this.serverFactory = serverFactory; this.handler = handler; }
public AutoSslConfigurator(final ServerFactory dwServer, final OServerConfiguration conf) { this.dwServer = dwServer; this.conf = conf; }
@Override @JsonProperty("server") @Value.Default public ServerFactory getServerFactory() { return new DefaultServerFactory(); }
ServerFactory getServerFactory();