@Test public void testBadRegistrationOfDataCenterInfo() throws Exception { try { // test 400 when configured to return client error ConfigurationManager.getConfigInstance() .setProperty("eureka.experimental.registration.validation.dataCenterInfoId", "true"); InstanceInfo instanceInfo = spy(InstanceInfoGenerator.takeOne()); when(instanceInfo.getDataCenterInfo()).thenReturn(new TestDataCenterInfo()); Response response = applicationResource.addInstance(instanceInfo, false + ""); assertThat(response.getStatus(), is(400)); // test backfill of data for AmazonInfo ConfigurationManager.getConfigInstance() .setProperty("eureka.experimental.registration.validation.dataCenterInfoId", "false"); instanceInfo = spy(InstanceInfoGenerator.takeOne()); assertThat(instanceInfo.getDataCenterInfo(), instanceOf(AmazonInfo.class)); ((AmazonInfo) instanceInfo.getDataCenterInfo()) .getMetadata() .remove(AmazonInfo.MetaDataKey.instanceId.getName()); // clear the Id response = applicationResource.addInstance(instanceInfo, false + ""); assertThat(response.getStatus(), is(204)); } finally { ConfigurationManager.getConfigInstance() .clearProperty("eureka.experimental.registration.validation.dataCenterInfoId"); } }
@Test public void testExecuteWithLB() throws Exception { ConfigurationManager.getConfigInstance() .setProperty("allservices.ribbon." + CommonClientConfigKey.ReadTimeout, "10000"); ConfigurationManager.getConfigInstance() .setProperty("allservices.ribbon." + CommonClientConfigKey.FollowRedirects, "true"); RestClient client = (RestClient) ClientFactory.getNamedClient("allservices"); BaseLoadBalancer lb = new BaseLoadBalancer(); Server[] servers = new Server[] {new Server("localhost", server.getServerPort())}; lb.addServers(Arrays.asList(servers)); client.setLoadBalancer(lb); Set<URI> expected = new HashSet<URI>(); expected.add(new URI(server.getServerPath("/"))); Set<URI> result = new HashSet<URI>(); HttpRequest request = HttpRequest.newBuilder().uri(new URI("/")).build(); for (int i = 0; i < 5; i++) { HttpResponse response = client.executeWithLoadBalancer(request); assertStatusIsOk(response.getStatus()); assertTrue(response.isSuccess()); String content = response.getEntity(String.class); response.close(); assertFalse(content.isEmpty()); result.add(response.getRequestedURI()); } assertEquals(expected, result); request = HttpRequest.newBuilder().uri(server.getServerURI()).build(); HttpResponse response = client.executeWithLoadBalancer(request); assertEquals(200, response.getStatus()); }
public void start() { this.host = ConfigurationManager.getConfigInstance() .getString("netty.http.host", "not-found-in-configuration"); this.port = ConfigurationManager.getConfigInstance().getInt("netty.http.port", Integer.MIN_VALUE); final PackagesResourceConfig rcf = new PackagesResourceConfig( ConfigurationManager.getConfigInstance() .getString("jersey.resources.package", "not-found-in-configuration")); nettyServer = NettyServer.builder() .host(host) .port(port) .addHandler( "jerseyHandler", ContainerFactory.createContainer(NettyHandlerContainer.class, rcf)) .numBossThreads(NettyServer.cpus) .numWorkerThreads(NettyServer.cpus * 4) .build(); try { karyonServer.start(); } catch (Exception exc) { throw new RuntimeException("Cannot start karyon server.", exc); } }
@Override public void initWithNiwsConfig(IClientConfig clientConfig) { clientName = clientConfig.getClientName(); vipAddresses = clientConfig.resolveDeploymentContextbasedVipAddresses(); if (vipAddresses == null && ConfigurationManager.getConfigInstance() .getBoolean("DiscoveryEnabledNIWSServerList.failFastOnNullVip", true)) { throw new NullPointerException("VIP address for client " + clientName + " is null"); } isSecure = Boolean.parseBoolean( "" + clientConfig.getProperty(CommonClientConfigKey.IsSecure, "false")); prioritizeVipAddressBasedServers = Boolean.parseBoolean( "" + clientConfig.getProperty( CommonClientConfigKey.PrioritizeVipAddressBasedServers, prioritizeVipAddressBasedServers)); datacenter = ConfigurationManager.getDeploymentContext().getDeploymentDatacenter(); targetRegion = (String) clientConfig.getProperty(CommonClientConfigKey.TargetRegion); // override client configuration and use client-defined port if (clientConfig.getPropertyAsBoolean( CommonClientConfigKey.ForceClientPortConfiguration, false)) { if (isSecure) { if (clientConfig.containsProperty(CommonClientConfigKey.SecurePort)) { overridePort = clientConfig.getPropertyAsInteger( CommonClientConfigKey.SecurePort, DefaultClientConfigImpl.DEFAULT_PORT); shouldUseOverridePort = true; } else { logger.warn( clientName + " set to force client port but no secure port is set, so ignoring"); } } else { if (clientConfig.containsProperty(CommonClientConfigKey.Port)) { overridePort = clientConfig.getPropertyAsInteger( CommonClientConfigKey.Port, DefaultClientConfigImpl.DEFAULT_PORT); shouldUseOverridePort = true; } else { logger.warn(clientName + " set to force client port but no port is set, so ignoring"); } } } }
@Test public void testVipAsURI() throws Exception { ConfigurationManager.getConfigInstance() .setProperty("test1.ribbon.DeploymentContextBasedVipAddresses", server.getServerPath("/")); ConfigurationManager.getConfigInstance() .setProperty("test1.ribbon.InitializeNFLoadBalancer", "false"); RestClient client = (RestClient) ClientFactory.getNamedClient("test1"); assertNull(client.getLoadBalancer()); HttpRequest request = HttpRequest.newBuilder().uri(new URI("/")).build(); HttpResponse response = client.executeWithLoadBalancer(request); assertStatusIsOk(response.getStatus()); assertEquals(server.getServerPath("/"), response.getRequestedURI().toString()); }
@Test public void testZoneAffinityEnabled() throws Exception { ConfigurationManager.getConfigInstance() .setProperty( "DefaultNIWSServerListFilterTest1.ribbon.DeploymentContextBasedVipAddresses", "l10nservicegeneral.cloud.netflix.net:7001"); ConfigurationManager.getConfigInstance() .setProperty( "DefaultNIWSServerListFilterTest1.ribbon.NFLoadBalancerClassName", DynamicServerListLoadBalancer.class.getName()); ConfigurationManager.getConfigInstance() .setProperty( "DefaultNIWSServerListFilterTest1.ribbon.NIWSServerListClassName", DiscoveryEnabledNIWSServerList.class.getName()); ConfigurationManager.getConfigInstance() .setProperty("DefaultNIWSServerListFilterTest1.ribbon.EnableZoneAffinity", "true"); DynamicServerListLoadBalancer lb = (DynamicServerListLoadBalancer) ClientFactory.getNamedLoadBalancer("DefaultNIWSServerListFilterTest1"); assertTrue(lb.getRule() instanceof AvailabilityFilteringRule); ZoneAffinityServerListFilter filter = (ZoneAffinityServerListFilter) lb.getFilter(); LoadBalancerStats loadBalancerStats = lb.getLoadBalancerStats(); List<DiscoveryEnabledServer> servers = new ArrayList<DiscoveryEnabledServer>(); servers.add(createServer(1, "a")); servers.add(createServer(2, "a")); servers.add(createServer(3, "a")); servers.add(createServer(4, "a")); servers.add(createServer(1, "b")); servers.add(createServer(2, "b")); servers.add(createServer(3, "b")); servers.add(createServer(1, "c")); servers.add(createServer(2, "c")); servers.add(createServer(3, "c")); servers.add(createServer(4, "c")); servers.add(createServer(5, "c")); List<DiscoveryEnabledServer> filtered = filter.getFilteredListOfServers(servers); List<DiscoveryEnabledServer> expected = new ArrayList<DiscoveryEnabledServer>(); expected.add(createServer(1, "c")); expected.add(createServer(2, "c")); expected.add(createServer(3, "c")); expected.add(createServer(4, "c")); expected.add(createServer(5, "c")); assertEquals(expected, filtered); lb.setServersList(filtered); for (int i = 1; i <= 4; i++) { loadBalancerStats.incrementActiveRequestsCount(createServer(i, "c")); } filtered = filter.getFilteredListOfServers(servers); assertEquals(servers, filtered); }
private void init() { String env = ConfigurationManager.getConfigInstance().getString(EUREKA_ENVIRONMENT, TEST); ConfigurationManager.getConfigInstance().setProperty(ARCHAIUS_DEPLOYMENT_ENVIRONMENT, env); String eurekaPropsFile = EUREKA_PROPS_FILE.get(); try { // ConfigurationManager // .loadPropertiesFromResources(eurekaPropsFile); ConfigurationManager.loadCascadedPropertiesFromResources(eurekaPropsFile); } catch (IOException e) { logger.warn( "Cannot find the properties specified : {}. This may be okay if there are other environment specific properties or the configuration is installed with a different mechanism.", eurekaPropsFile); } }
@Test public void overrideThreadIsolationTimeout() { ConfigurationManager.getConfigInstance() .setProperty( "hystrix.command.THREAD_ISOLATION_TIMEOUT.execution.isolation.thread.timeoutInMilliseconds", "987"); class ThreadIsolationCommand extends TenacityCommand<String> { private ThreadIsolationCommand() { super(DependencyKey.THREAD_ISOLATION_TIMEOUT); } @Override protected String run() throws Exception { return "value"; } @Override protected String getFallback() { return "fallback"; } } final ThreadIsolationCommand threadIsolationCommand = new ThreadIsolationCommand(); assertEquals(threadIsolationCommand.execute(), "value"); final HystrixCommandProperties commandProperties = threadIsolationCommand.getCommandProperties(); assertEquals( commandProperties.executionIsolationThreadTimeoutInMilliseconds().get().intValue(), 987); }
private static void initializeHystrixSettings() { hystrixConfig = ConfigurationManager.getConfigInstance(); hystrixConfig.setProperty(CORE_SIZE_CONFIG, "20"); hystrixConfig.setProperty(MAX_QUEUE_SIZE_CONFIG, "20"); hystrixConfig.setProperty(QUEUE_REJECTION_THRESHOLD_CONFIG, "10"); hystrixConfig.setProperty(COLLAPSER_TIMER_DELAY, "50"); }
@Test public void testPropertyChange() throws Exception { BlobStoreConfigurationSource source = new BlobStoreConfigurationSource(ctx); FixedDelayPollingScheduler scheduler = new FixedDelayPollingScheduler(0, 1000, false); DynamicConfiguration dynamicConfig = new DynamicConfiguration(source, scheduler); ConfigurationManager.loadPropertiesFromConfiguration(dynamicConfig); DynamicStringProperty test1 = DynamicPropertyFactory.getInstance().getStringProperty("test1", ""); DynamicStringProperty test2 = DynamicPropertyFactory.getInstance().getStringProperty("test2", ""); DynamicStringProperty test3 = DynamicPropertyFactory.getInstance().getStringProperty("test3", ""); assertEquals("val1", test1.get()); assertEquals("val2", test2.get()); assertEquals("val3", test3.get()); update(); Thread.sleep(1000); assertEquals("vala", test1.get()); assertEquals("valb", test2.get()); assertEquals("valc", test3.get()); }
protected void setProp(String serviceId, String suffix, String value) { // how to set the namespace properly? String key = getKey(serviceId, suffix); DynamicStringProperty property = getProperty(key); if (property.get().equals(VALUE_NOT_SET)) { ConfigurationManager.getConfigInstance().setProperty(key, value); } }
private HystrixPlugins() { try { // Load configuration from hystrix-plugins.properties, if that file exists ConfigurationManager.loadCascadedPropertiesFromResources("hystrix-plugins"); } catch (IOException e) { // fail silently } }
@Test public void testSecureClient() throws Exception { ConfigurationManager.getConfigInstance().setProperty("test2.ribbon.IsSecure", "true"); RestClient client = (RestClient) ClientFactory.getNamedClient("test2"); HttpRequest request = HttpRequest.newBuilder().uri(server.getServerURI()).build(); HttpResponse response = client.executeWithLoadBalancer(request); assertStatusIsOk(response.getStatus()); }
protected void putDefaultTimeUnitProperty(IClientConfigKey propName, TimeUnit defaultValue) { TimeUnit value = defaultValue; String propValue = ConfigurationManager.getConfigInstance().getString(getDefaultPropName(propName)); if (propValue != null && propValue.length() > 0) { value = TimeUnit.valueOf(propValue); } setPropertyInternal(propName, value); }
@Test public void testDynamicProperty() throws IOException { String spec = "{\n" + " \"type\": \"dynamic\",\n" + " \"format\": \"property(prop1)\"\n" + "}"; ConfigurationManager.getConfigInstance().setProperty("prop1", "prop1"); ObjectMapper mapper = injector.getInstance(ObjectMapper.class); RemotePrefixFormatter formatter = mapper.readValue(spec, new TypeReference<RemotePrefixFormatter>() {}); assertEquals(formatter.get(), "prop1/"); }
@Test public void testSecureClient2() throws Exception { ConfigurationManager.getConfigInstance() .setProperty("test3.ribbon." + CommonClientConfigKey.IsSecure, "true"); ConfigurationManager.getConfigInstance() .setProperty( "test3.ribbon." + CommonClientConfigKey.TrustStore, secureServer.getTrustStore().getAbsolutePath()); ConfigurationManager.getConfigInstance() .setProperty( "test3.ribbon." + CommonClientConfigKey.TrustStorePassword, SecureGetTest.PASSWORD); RestClient client = (RestClient) ClientFactory.getNamedClient("test3"); BaseLoadBalancer lb = new BaseLoadBalancer(); Server[] servers = new Server[] {new Server("localhost", secureServer.getServerPort())}; lb.addServers(Arrays.asList(servers)); client.setLoadBalancer(lb); HttpRequest request = HttpRequest.newBuilder().uri(new URI("/")).build(); HttpResponse response = client.executeWithLoadBalancer(request); assertStatusIsOk(response.getStatus()); assertEquals(secureServer.getServerPath("/"), response.getRequestedURI().toString()); }
@Override public Map<String, Object> invoke() { Map<String, Object> map = new LinkedHashMap<String, Object>(); AbstractConfiguration config = ConfigurationManager.getConfigInstance(); if (config instanceof ConcurrentCompositeConfiguration) { ConcurrentCompositeConfiguration composite = (ConcurrentCompositeConfiguration) config; for (Configuration item : composite.getConfigurations()) { append(map, item); } } else { append(map, config); } return map; }
@Test public void testDynamicCombination() throws IOException { String spec = "{\n" + " \"type\": \"dynamic\",\n" + " \"format\": \"static(routing_key)/date(YYYYMMDD)/property(prop1)\"\n" + "}"; ConfigurationManager.getConfigInstance().setProperty("prop1", "propvalue1"); DateTimeFormatter format = DateTimeFormat.forPattern("YYYYMMDD"); ObjectMapper mapper = injector.getInstance(ObjectMapper.class); RemotePrefixFormatter formatter = mapper.readValue(spec, new TypeReference<RemotePrefixFormatter>() {}); assertEquals(formatter.get(), "routing_key/" + format.print(new DateTime()) + "/propvalue1/"); }
/** * Load properties for a given client. It first loads the default values for all properties, and * any properties already defined with Archaius ConfigurationManager. */ @Override public void loadProperties(String restClientName) { enableDynamicProperties = true; setClientName(restClientName); loadDefaultValues(); Configuration props = ConfigurationManager.getConfigInstance().subset(restClientName); for (Iterator<String> keys = props.getKeys(); keys.hasNext(); ) { String key = keys.next(); String prop = key; try { if (prop.startsWith(getNameSpace())) { prop = prop.substring(getNameSpace().length() + 1); } setPropertyInternal(prop, getStringValue(props, key)); } catch (Exception ex) { throw new RuntimeException(String.format("Property %s is invalid", prop)); } } }
@Before public void setupOrg() { originalShardSize = ConfigurationManager.getConfigInstance().getProperty(GraphFig.SHARD_SIZE); originalShardTimeout = ConfigurationManager.getConfigInstance().getProperty(GraphFig.SHARD_CACHE_TIMEOUT); originalShardDelta = ConfigurationManager.getConfigInstance().getProperty(GraphFig.SHARD_MIN_DELTA); ConfigurationManager.getConfigInstance().setProperty(GraphFig.SHARD_SIZE, 500); final long cacheTimeout = 2000; // set our cache timeout to the above value ConfigurationManager.getConfigInstance() .setProperty(GraphFig.SHARD_CACHE_TIMEOUT, cacheTimeout); final long minDelta = (long) (cacheTimeout * 2.5); ConfigurationManager.getConfigInstance().setProperty(GraphFig.SHARD_MIN_DELTA, minDelta); // get the system property of the UUID to use. If one is not set, use the defualt String uuidString = System.getProperty("org.id", "80a42760-b699-11e3-a5e2-0800200c9a66"); scope = new ApplicationScopeImpl(IdGenerator.createId(UUID.fromString(uuidString), "test")); reporter = Slf4jReporter.forRegistry(registry) .outputTo(logger) .convertRatesTo(TimeUnit.SECONDS) .convertDurationsTo(TimeUnit.MILLISECONDS) .build(); reporter.start(10, TimeUnit.SECONDS); }
public static void addApplicationContext(ConfigurableApplicationContext context) { AbstractConfiguration config = ConfigurationManager.getConfigInstance(); config.clearProperty(APPLICATION_CONTEXT); config.setProperty(APPLICATION_CONTEXT, context); }
public static <T> T getNamedInstance(Class<T> type, String name) { ApplicationContext context = (ApplicationContext) ConfigurationManager.getConfigInstance().getProperty(APPLICATION_CONTEXT); return context != null && context.containsBean(name) ? context.getBean(name, type) : null; }
@Test public void testZoneAffinityOverride() throws Exception { ConfigurationManager.getConfigInstance() .setProperty( "DefaultNIWSServerListFilterTest3.ribbon.DeploymentContextBasedVipAddresses", "l10nservicegeneral.cloud.netflix.net:7001"); ConfigurationManager.getConfigInstance() .setProperty( "DefaultNIWSServerListFilterTest3.ribbon.NFLoadBalancerClassName", DynamicServerListLoadBalancer.class.getName()); ConfigurationManager.getConfigInstance() .setProperty("DefaultNIWSServerListFilterTest3.ribbon.EnableZoneAffinity", "true"); ConfigurationManager.getConfigInstance() .setProperty( "DefaultNIWSServerListFilterTest3.ribbon.NIWSServerListClassName", DiscoveryEnabledNIWSServerList.class.getName()); ConfigurationManager.getConfigInstance() .setProperty( "DefaultNIWSServerListFilterTest3.ribbon.zoneAffinity.minAvailableServers", "3"); DynamicServerListLoadBalancer lb = (DynamicServerListLoadBalancer) ClientFactory.getNamedLoadBalancer("DefaultNIWSServerListFilterTest3"); ZoneAffinityServerListFilter filter = (ZoneAffinityServerListFilter) lb.getFilter(); LoadBalancerStats loadBalancerStats = lb.getLoadBalancerStats(); List<DiscoveryEnabledServer> servers = new ArrayList<DiscoveryEnabledServer>(); servers.add(createServer(1, "a")); servers.add(createServer(2, "a")); servers.add(createServer(3, "a")); servers.add(createServer(4, "a")); servers.add(createServer(1, "b")); servers.add(createServer(2, "b")); servers.add(createServer(3, "b")); servers.add(createServer(1, "c")); servers.add(createServer(2, "c")); List<DiscoveryEnabledServer> filtered = filter.getFilteredListOfServers(servers); List<DiscoveryEnabledServer> expected = new ArrayList<DiscoveryEnabledServer>(); /* expected.add(createServer(1, "c")); expected.add(createServer(2, "c")); expected.add(createServer(3, "c")); expected.add(createServer(4, "c")); expected.add(createServer(5, "c")); */ // less than 3 servers in zone c, will not honor zone affinity assertEquals(servers, filtered); lb.setServersList(filtered); servers.add(createServer(3, "c")); filtered = filter.getFilteredListOfServers(servers); expected.add(createServer(1, "c")); expected.add(createServer(2, "c")); expected.add(createServer(3, "c")); filtered = filter.getFilteredListOfServers(servers); // now we have enough servers in C assertEquals(expected, filtered); // make one server black out for (int i = 1; i <= 3; i++) { loadBalancerStats.incrementSuccessiveConnectionFailureCount(createServer(1, "c")); } filtered = filter.getFilteredListOfServers(servers); assertEquals(servers, filtered); // new server added in zone c, zone c should now have enough servers servers.add(createServer(4, "c")); filtered = filter.getFilteredListOfServers(servers); expected.add(createServer(4, "c")); assertEquals(expected, filtered); }
@Override public void contextInitialized(ServletContextEvent servletContextEvent) { super.contextInitialized(servletContextEvent); /* * -------------------------------------------------------------------- * Archaius Configuration Settings * -------------------------------------------------------------------- */ Env env = Env.getEnvironment(); if (env == Env.ALL) { ConfigurationManager.getDeploymentContext().setDeploymentEnvironment("CHOP"); LOG.info("Setting environment to: CHOP"); } else if (env == Env.UNIT) { LOG.info("Operating in UNIT environment"); } try { ConfigurationManager.loadCascadedPropertiesFromResources("project"); } catch (IOException e) { LOG.error("Failed to load project properties!", e); throw new RuntimeException("Cannot do much without properly loading our configuration.", e); } /* * -------------------------------------------------------------------- * Environment Based Configuration Property Adjustments * -------------------------------------------------------------------- */ servletFig = injector.getInstance(ServletFig.class); runner = injector.getInstance(Runner.class); project = injector.getInstance(Project.class); ServletContext context = servletContextEvent.getServletContext(); /* * -------------------------------------------------------------------- * Adjust Runner Settings to Environment * -------------------------------------------------------------------- */ if (env == Env.UNIT || env == Env.INTEG || env == Env.ALL) { runner.bypass(Runner.HOSTNAME_KEY, "localhost"); runner.bypass(Runner.IPV4_KEY, "127.0.0.1"); } else if (env == Env.CHOP) { Ec2Metadata.applyBypass(runner); } StringBuilder sb = new StringBuilder(); sb.append("https://") .append(runner.getHostname()) .append(':') .append(runner.getServerPort()) .append(context.getContextPath()); String baseUrl = sb.toString(); runner.bypass(Runner.URL_KEY, baseUrl); LOG.info("Setting url key {} to base url {}", Runner.URL_KEY, baseUrl); File tempDir = new File(System.getProperties().getProperty("java.io.tmpdir")); runner.bypass(Runner.RUNNER_TEMP_DIR_KEY, tempDir.getAbsolutePath()); LOG.info( "Setting runner temp directory key {} to context temp directory {}", Runner.RUNNER_TEMP_DIR_KEY, tempDir.getAbsolutePath()); /* * -------------------------------------------------------------------- * Adjust ServletFig Settings to Environment * -------------------------------------------------------------------- */ servletFig.bypass(ServletFig.SERVER_INFO_KEY, context.getServerInfo()); LOG.info( "Setting server info key {} to {}", ServletFig.SERVER_INFO_KEY, context.getServerInfo()); servletFig.bypass(ServletFig.CONTEXT_PATH, context.getContextPath()); LOG.info( "Setting server context path key {} to {}", ServletFig.CONTEXT_PATH, context.getContextPath()); // @todo Is this necessary? servletFig.bypass(ServletFig.CONTEXT_TEMPDIR_KEY, tempDir.getAbsolutePath()); LOG.info( "Setting runner context temp directory key {} to context temp directory {}", ServletFig.CONTEXT_TEMPDIR_KEY, tempDir.getAbsolutePath()); /* * -------------------------------------------------------------------- * Start Up The RunnerRegistry and Register * -------------------------------------------------------------------- */ if (isTestMode()) { runner.bypass(Runner.HOSTNAME_KEY, "localhost"); runner.bypass(Runner.IPV4_KEY, "127.0.0.1"); project.bypass(Project.LOAD_KEY, "bogus-load-key"); project.bypass(Project.ARTIFACT_ID_KEY, "bogus-artifact-id"); project.bypass(Project.GROUP_ID_KEY, "org.apache.usergrid.chop"); project.bypass(Project.CHOP_VERSION_KEY, "bogus-chop-version"); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss"); dateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); project.bypass(Project.CREATE_TIMESTAMP_KEY, dateFormat.format(new Date())); project.bypass( Project.GIT_URL_KEY, "http://stash.safehaus.org/projects/CHOP/repos/main/browse"); project.bypass(Project.GIT_UUID_KEY, "d637a8ce"); project.bypass(Project.LOAD_TIME_KEY, dateFormat.format(new Date())); project.bypass(Project.PROJECT_VERSION_KEY, "1.0.0-SNAPSHOT"); } if (runner.getHostname() != null && project.getLoadKey() != null) { final RunnerRegistry registry = getInjector().getInstance(RunnerRegistry.class); if (env != Env.TEST && env != Env.UNIT) { registry.register(runner); registered = true; Runtime.getRuntime() .addShutdownHook( new Thread( new Runnable() { @Override public void run() { if (registered) { System.err.println( "Premature shutdown, attempting to unregister this runner."); registry.unregister(runner); LOG.info("Unregistering runner on shutdownx: {}", runner.getHostname()); registered = false; } } })); LOG.info("Registered runner information in coordinator registry."); } else { LOG.warn("Env = {} so we are not registering this runner.", env); } } else { LOG.warn( "Runner registry not started, and not registered: insufficient configuration parameters."); } }
@BeforeClass public static void init() { ConfigurationManager.getDeploymentContext().setValue(ContextKey.zone, "us-eAst-1C"); }
public void loadDefaultValues() { putDefaultIntegerProperty( CommonClientConfigKey.MaxHttpConnectionsPerHost, getDefaultMaxHttpConnectionsPerHost()); putDefaultIntegerProperty( CommonClientConfigKey.MaxTotalHttpConnections, getDefaultMaxTotalHttpConnections()); putDefaultBooleanProperty( CommonClientConfigKey.EnableConnectionPool, getDefaultEnableConnectionPool()); putDefaultIntegerProperty( CommonClientConfigKey.MaxConnectionsPerHost, getDefaultMaxConnectionsPerHost()); putDefaultIntegerProperty( CommonClientConfigKey.MaxTotalConnections, getDefaultMaxTotalConnections()); putDefaultIntegerProperty(CommonClientConfigKey.ConnectTimeout, getDefaultConnectTimeout()); putDefaultIntegerProperty( CommonClientConfigKey.ConnectionManagerTimeout, getDefaultConnectionManagerTimeout()); putDefaultIntegerProperty(CommonClientConfigKey.ReadTimeout, getDefaultReadTimeout()); putDefaultIntegerProperty(CommonClientConfigKey.MaxAutoRetries, getDefaultMaxAutoRetries()); putDefaultIntegerProperty( CommonClientConfigKey.MaxAutoRetriesNextServer, getDefaultMaxAutoRetriesNextServer()); putDefaultBooleanProperty( CommonClientConfigKey.OkToRetryOnAllOperations, getDefaultOkToRetryOnAllOperations()); putDefaultBooleanProperty(CommonClientConfigKey.FollowRedirects, getDefaultFollowRedirects()); putDefaultBooleanProperty( CommonClientConfigKey.ConnectionPoolCleanerTaskEnabled, getDefaultConnectionPoolCleanerTaskEnabled()); putDefaultIntegerProperty( CommonClientConfigKey.ConnIdleEvictTimeMilliSeconds, getDefaultConnectionidleTimeInMsecs()); putDefaultIntegerProperty( CommonClientConfigKey.ConnectionCleanerRepeatInterval, getDefaultConnectionIdleTimertaskRepeatInMsecs()); putDefaultBooleanProperty( CommonClientConfigKey.EnableGZIPContentEncodingFilter, getDefaultEnableGzipContentEncodingFilter()); String proxyHost = ConfigurationManager.getConfigInstance() .getString(getDefaultPropName(CommonClientConfigKey.ProxyHost.key())); if (proxyHost != null && proxyHost.length() > 0) { setProperty(CommonClientConfigKey.ProxyHost, proxyHost); } Integer proxyPort = ConfigurationManager.getConfigInstance() .getInteger( getDefaultPropName(CommonClientConfigKey.ProxyPort), (Integer.MIN_VALUE + 1)); // + 1 just to avoid potential clash with user setting if (proxyPort != (Integer.MIN_VALUE + 1)) { setProperty(CommonClientConfigKey.ProxyPort, proxyPort); } putDefaultIntegerProperty(CommonClientConfigKey.Port, getDefaultPort()); putDefaultBooleanProperty( CommonClientConfigKey.EnablePrimeConnections, getDefaultEnablePrimeConnections()); putDefaultIntegerProperty( CommonClientConfigKey.MaxRetriesPerServerPrimeConnection, getDefaultMaxRetriesPerServerPrimeConnection()); putDefaultIntegerProperty( CommonClientConfigKey.MaxTotalTimeToPrimeConnections, getDefaultMaxTotalTimeToPrimeConnections()); putDefaultStringProperty( CommonClientConfigKey.PrimeConnectionsURI, getDefaultPrimeConnectionsUri()); putDefaultIntegerProperty(CommonClientConfigKey.PoolMinThreads, getDefaultPoolMinThreads()); putDefaultIntegerProperty(CommonClientConfigKey.PoolMaxThreads, getDefaultPoolMaxThreads()); putDefaultLongProperty(CommonClientConfigKey.PoolKeepAliveTime, getDefaultPoolKeepAliveTime()); putDefaultTimeUnitProperty( CommonClientConfigKey.PoolKeepAliveTimeUnits, getDefaultPoolKeepAliveTimeUnits()); putDefaultBooleanProperty( CommonClientConfigKey.EnableZoneAffinity, getDefaultEnableZoneAffinity()); putDefaultBooleanProperty( CommonClientConfigKey.EnableZoneExclusivity, getDefaultEnableZoneExclusivity()); putDefaultStringProperty(CommonClientConfigKey.ClientClassName, getDefaultClientClassname()); putDefaultStringProperty( CommonClientConfigKey.NFLoadBalancerClassName, getDefaultNfloadbalancerClassname()); putDefaultStringProperty( CommonClientConfigKey.NFLoadBalancerRuleClassName, getDefaultNfloadbalancerRuleClassname()); putDefaultStringProperty( CommonClientConfigKey.NFLoadBalancerPingClassName, getDefaultNfloadbalancerPingClassname()); putDefaultBooleanProperty( CommonClientConfigKey.PrioritizeVipAddressBasedServers, getDefaultPrioritizeVipAddressBasedServers()); putDefaultFloatProperty( CommonClientConfigKey.MinPrimeConnectionsRatio, getDefaultMinPrimeConnectionsRatio()); putDefaultStringProperty( CommonClientConfigKey.PrimeConnectionsClassName, getDefaultPrimeConnectionsClass()); putDefaultStringProperty( CommonClientConfigKey.NIWSServerListClassName, getDefaultSeverListClass()); putDefaultStringProperty( CommonClientConfigKey.VipAddressResolverClassName, getDefaultVipaddressResolverClassname()); putDefaultBooleanProperty( CommonClientConfigKey.IsClientAuthRequired, getDefaultIsClientAuthRequired()); // putDefaultStringProperty(CommonClientConfigKey.RequestIdHeaderName, // getDefaultRequestIdHeaderName()); putDefaultBooleanProperty( CommonClientConfigKey.UseIPAddrForServer, getDefaultUseIpAddressForServer()); putDefaultStringProperty(CommonClientConfigKey.ListOfServers, ""); }
// Helper methods which first check if a "default" (with rest client name) // property exists. If so, that value is used, else the default value // passed as argument is used to put into the properties member variable protected void putDefaultIntegerProperty(IClientConfigKey propName, Integer defaultValue) { Integer value = ConfigurationManager.getConfigInstance() .getInteger(getDefaultPropName(propName), defaultValue); setPropertyInternal(propName, value); }
protected void putDefaultBooleanProperty(IClientConfigKey propName, Boolean defaultValue) { Boolean value = ConfigurationManager.getConfigInstance() .getBoolean(getDefaultPropName(propName), defaultValue); setPropertyInternal(propName, value); }
protected void putDefaultStringProperty(IClientConfigKey propName, String defaultValue) { String value = ConfigurationManager.getConfigInstance() .getString(getDefaultPropName(propName), defaultValue); setPropertyInternal(propName, value); }
protected void putDefaultFloatProperty(IClientConfigKey propName, Float defaultValue) { Float value = ConfigurationManager.getConfigInstance() .getFloat(getDefaultPropName(propName), defaultValue); setPropertyInternal(propName, value); }