/** * Build the {@link StatusInfo}. General information are automatically * built here too. */ public StatusInfo build() { if (result.instanceInfo == null) { throw new IllegalStateException("instanceInfo can not be null"); } result.generalStats.put("server-uptime", getUpTime()); result.generalStats.put("environment", ConfigurationManager .getDeploymentContext().getDeploymentEnvironment()); Runtime runtime = Runtime.getRuntime(); int totalMem = (int) (runtime.totalMemory() / 1048576); int freeMem = (int) (runtime.freeMemory() / 1048576); int usedPercent = (int) (((float) totalMem - freeMem) / (totalMem) * 100.0); result.generalStats.put("num-of-cpus", String.valueOf(runtime.availableProcessors())); result.generalStats.put("total-avail-memory", String.valueOf(totalMem) + "mb"); result.generalStats.put("current-memory-usage", String.valueOf(totalMem - freeMem) + "mb" + " (" + usedPercent + "%)"); return result; } }
ConfigurationManager.getDeploymentContext().setDeploymentEnvironment( "CHOP" ); LOG.info( "Setting environment to: CHOP" );
EurekaInstanceConfig instanceConfig = isCloud(ConfigurationManager.getDeploymentContext()) ? new CloudInstanceConfig() : new MyDataCenterInstanceConfig();
@Override public void initWithNiwsConfig(IClientConfig niwsClientConfig) { super.initWithNiwsConfig(niwsClientConfig); if (ConfigurationManager.getDeploymentContext() != null) { this.zone = ConfigurationManager.getDeploymentContext().getValue( ContextKey.zone); } }
@Override public void load() { String appNameToUse = appName; if (null == appNameToUse) { appNameToUse = ConfigurationManager.getDeploymentContext().getApplicationId(); } try { logger.info(String.format("Loading application properties with app id: %s and environment: %s", appNameToUse, ConfigurationManager.getDeploymentContext().getDeploymentEnvironment())); /** * This loads a property file with the name "appName".properties and "appName"-"env".properties, if found. */ ConfigurationManager.loadCascadedPropertiesFromResources(appNameToUse); } catch (IOException e) { logger.error(String.format( "Failed to load properties for application id: %s and environment: %s. This is ok, if you do not have application level properties.", appNameToUse, ConfigurationManager.getDeploymentContext().getDeploymentEnvironment()), e); } } }
@Override public void load() { String appNameToUse = appName; if (null == appNameToUse) { appNameToUse = ConfigurationManager.getDeploymentContext().getApplicationId(); } try { logger.info(String.format("Loading application properties with app id: %s and environment: %s", appNameToUse, ConfigurationManager.getDeploymentContext().getDeploymentEnvironment())); /** * This loads a property file with the name "appName".properties and "appName"-"env".properties, if found. */ ConfigurationManager.loadCascadedPropertiesFromResources(appNameToUse); } catch (IOException e) { logger.error(String.format( "Failed to load properties for application id: %s and environment: %s. This is ok, if you do not have application level properties.", appNameToUse, ConfigurationManager.getDeploymentContext().getDeploymentEnvironment()), e); } } }
/** * Build the {@link StatusInfo}. General information are automatically * built here too. */ public StatusInfo build() { if (result.instanceInfo == null) { throw new IllegalStateException("instanceInfo can not be null"); } result.generalStats.put("server-uptime", getUpTime()); result.generalStats.put("environment", ConfigurationManager .getDeploymentContext().getDeploymentEnvironment()); Runtime runtime = Runtime.getRuntime(); int totalMem = (int) (runtime.totalMemory() / 1048576); int freeMem = (int) (runtime.freeMemory() / 1048576); int usedPercent = (int) (((float) totalMem - freeMem) / (totalMem) * 100.0); result.generalStats.put("num-of-cpus", String.valueOf(runtime.availableProcessors())); result.generalStats.put("total-avail-memory", String.valueOf(totalMem) + "mb"); result.generalStats.put("current-memory-usage", String.valueOf(totalMem - freeMem) + "mb" + " (" + usedPercent + "%)"); return result; } }
@Override public void load() { String appNameToUse = appName; if (null == appNameToUse) { appNameToUse = ConfigurationManager.getDeploymentContext().getApplicationId(); } try { logger.info(String.format("Loading application properties with app id: %s and environment: %s", appNameToUse, ConfigurationManager.getDeploymentContext().getDeploymentEnvironment())); /** * This loads a property file with the name "appName".properties and "appName"-"env".properties, if found. */ ConfigurationManager.loadCascadedPropertiesFromResources(appNameToUse); } catch (IOException e) { logger.error(String.format( "Failed to load properties for application id: %s and environment: %s. This is ok, if you do not have application level properties.", appNameToUse, ConfigurationManager.getDeploymentContext().getDeploymentEnvironment()), e); } } }
private static Properties loadCascadedProperties(String configName) throws IOException { String defaultConfigFileName = configName + ".properties"; if (instance == null) { instance = getConfigInstance(); } ClassLoader loader = Thread.currentThread().getContextClassLoader(); URL url = loader.getResource(defaultConfigFileName); if (url == null) { throw new IOException("Cannot locate " + defaultConfigFileName + " as a classpath resource."); } Properties props = getPropertiesFromFile(url); String environment = getDeploymentContext().getDeploymentEnvironment(); if (environment != null && environment.length() > 0) { String envConfigFileName = configName + "-" + environment + ".properties"; url = loader.getResource(envConfigFileName); if (url != null) { Properties envProps = getPropertiesFromFile(url); if (envProps != null) { props.putAll(envProps); } } } return props; }
private static Properties loadCascadedProperties(String configName) throws IOException { String defaultConfigFileName = configName + ".properties"; if (instance == null) { instance = getConfigInstance(); } ClassLoader loader = Thread.currentThread().getContextClassLoader(); URL url = loader.getResource(defaultConfigFileName); if (url == null) { throw new IOException("Cannot locate " + defaultConfigFileName + " as a classpath resource."); } Properties props = getPropertiesFromFile(url); String environment = getDeploymentContext().getDeploymentEnvironment(); if (environment != null && environment.length() > 0) { String envConfigFileName = configName + "-" + environment + ".properties"; url = loader.getResource(envConfigFileName); if (url != null) { Properties envProps = getPropertiesFromFile(url); if (envProps != null) { props.putAll(envProps); } } } return props; }
private void populateHeader(Map<String, Object> model) { model.put("currentTime", StatusResource.getCurrentTimeAsString()); model.put("upTime", StatusInfo.getUpTime()); model.put("environment", ConfigurationManager.getDeploymentContext() .getDeploymentEnvironment()); model.put("datacenter", ConfigurationManager.getDeploymentContext() .getDeploymentDatacenter()); PeerAwareInstanceRegistry registry = getRegistry(); model.put("registry", registry); model.put("isBelowRenewThresold", registry.isBelowRenewThresold() == 1); DataCenterInfo info = applicationInfoManager.getInfo().getDataCenterInfo(); if (info.getName() == DataCenterInfo.Name.Amazon) { AmazonInfo amazonInfo = (AmazonInfo) info; model.put("amazonInfo", amazonInfo); model.put("amiId", amazonInfo.get(AmazonInfo.MetaDataKey.amiId)); model.put("availabilityZone", amazonInfo.get(AmazonInfo.MetaDataKey.availabilityZone)); model.put("instanceId", amazonInfo.get(AmazonInfo.MetaDataKey.instanceId)); } }
private void populateHeader(Map<String, Object> model) { model.put("currentTime", StatusResource.getCurrentTimeAsString()); model.put("upTime", StatusInfo.getUpTime()); model.put("environment", ConfigurationManager.getDeploymentContext() .getDeploymentEnvironment()); model.put("datacenter", ConfigurationManager.getDeploymentContext() .getDeploymentDatacenter()); PeerAwareInstanceRegistry registry = getRegistry(); model.put("registry", registry); model.put("isBelowRenewThresold", registry.isBelowRenewThresold() == 1); DataCenterInfo info = applicationInfoManager.getInfo().getDataCenterInfo(); if (info.getName() == DataCenterInfo.Name.Amazon) { AmazonInfo amazonInfo = (AmazonInfo) info; model.put("amazonInfo", amazonInfo); model.put("amiId", amazonInfo.get(AmazonInfo.MetaDataKey.amiId)); model.put("availabilityZone", amazonInfo.get(AmazonInfo.MetaDataKey.availabilityZone)); model.put("instanceId", amazonInfo.get(AmazonInfo.MetaDataKey.instanceId)); } }
@PostConstruct public void preprocess() { String zone = ConfigurationManager.getDeploymentContext() .getValue(ContextKey.zone); if (this.clientConfig != null && StringUtils.isEmpty(zone)) { .extractApproximateZone(this.eurekaConfig.getHostName(false)); log.debug("Setting Zone To " + approxZone); ConfigurationManager.getDeploymentContext().setValue(ContextKey.zone, approxZone); ConfigurationManager.getDeploymentContext().setValue(ContextKey.zone, availabilityZone);
@Override public void initWithNiwsConfig(IClientConfig niwsClientConfig) { String sZoneAffinity = "" + niwsClientConfig.getProperty(CommonClientConfigKey.EnableZoneAffinity, false); if (sZoneAffinity != null){ zoneAffinity = Boolean.parseBoolean(sZoneAffinity); logger.debug("ZoneAffinity is set to {}", zoneAffinity); } String sZoneExclusive = "" + niwsClientConfig.getProperty(CommonClientConfigKey.EnableZoneExclusivity, false); if (sZoneExclusive != null){ zoneExclusive = Boolean.parseBoolean(sZoneExclusive); } if (ConfigurationManager.getDeploymentContext() != null) { zone = ConfigurationManager.getDeploymentContext().getValue(ContextKey.zone); } activeReqeustsPerServerThreshold = DynamicPropertyFactory.getInstance().getDoubleProperty(niwsClientConfig.getClientName() + "." + niwsClientConfig.getNameSpace() + ".zoneAffinity.maxLoadPerServer", 0.6d); logger.debug("activeReqeustsPerServerThreshold: {}", activeReqeustsPerServerThreshold.get()); blackOutServerPercentageThreshold = DynamicPropertyFactory.getInstance().getDoubleProperty(niwsClientConfig.getClientName() + "." + niwsClientConfig.getNameSpace() + ".zoneAffinity.maxBlackOutServesrPercentage", 0.8d); logger.debug("blackOutServerPercentageThreshold: {}", blackOutServerPercentageThreshold.get()); availableServersThreshold = DynamicPropertyFactory.getInstance().getIntProperty(niwsClientConfig.getClientName() + "." + niwsClientConfig.getNameSpace() + ".zoneAffinity.minAvailableServers", 2); logger.debug("availableServersThreshold: {}", availableServersThreshold.get()); overrideCounter = Monitors.newCounter("ZoneAffinity_OverrideCounter"); Monitors.registerObject("NIWSServerListFilter_" + niwsClientConfig.getClientName()); }
datacenter = ConfigurationManager.getDeploymentContext().getDeploymentDatacenter(); targetRegion = (String) clientConfig.getProperty(CommonClientConfigKey.TargetRegion);
@Override protected AbstractConfiguration getConfiguration() { AbstractConfiguration config = ConfigurationManager.getConfigInstance(); boolean dynamic = config.getBoolean(DYNAMIC_CONFIG, true); if (!dynamic) { return new DynamicConfiguration(); } else { String appId = null; DeploymentContext context = ConfigurationManager.getDeploymentContext(); appId = context.getApplicationId(); if (appId == null) { throw new RuntimeException( "Archaius deployment context's applicationId not set (archaius.deployment.applicationId)"); } String consulHost = config.getString(CONSUL_HOST, CONSUL_DEFAULT_HOST); int consulPort = config.getInt(CONSUL_PORT, 8500); String consulAclToken = config.getString(CONSUL_TOKEN); ConsulWatchedConfigurationSource configSource = new ConsulWatchedConfigurationSource(appId, new ConsulClient(consulHost, consulPort), 30, TimeUnit.SECONDS, consulAclToken); // do the first update synchronously try { configSource.runOnce(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } configSource.startAsync(); return new DynamicWatchedConfiguration(configSource); } }
@WarmUp public void initialize() { try { RibbonConfig.setupAppInfo(); String stack = ConfigurationManager.getDeploymentContext().getDeploymentStack(); // Setup the default origin. String defaultClientName; if (stack != null && !stack.trim().isEmpty() && RibbonConfig.isAutodetectingBackendVips()) { defaultClientName = RibbonConfig.setupDefaultRibbonConfig(); } else { DynamicStringProperty DEFAULT_CLIENT = DynamicPropertyFactory.getInstance().getStringProperty(ZUUL_NIWS_DEFAULTCLIENT, null); defaultClientName = DEFAULT_CLIENT.get(); if (defaultClientName == null) { defaultClientName = stack; } ZuulApplicationInfo.setApplicationName(defaultClientName); } origins.put(defaultClientName, new RibbonOrigin(defaultClientName)); // Setup the other configured origins. String clientPropertyList = DynamicPropertyFactory.getInstance().getStringProperty(ZUUL_NIWS_CLIENTLIST, "").get(); String[] aClientList = clientPropertyList.split("\\|"); for (String client : aClientList) { initOrigin(RIBBON_NAMESPACE.get(), client); } } catch (ClientException e) { throw new ZuulException(e, "Error initializing Ribbon clients."); } }
private void populateHeader(NutMap result) { result.put("currentTime", StatusResource.getCurrentTimeAsString()); result.put("upTime", StatusInfo.getUpTime()); result.put("environment", ConfigurationManager.getDeploymentContext().getDeploymentEnvironment()); result.put("datacenter", ConfigurationManager.getDeploymentContext().getDeploymentDatacenter()); PeerAwareInstanceRegistry registry = getRegistry(); NutMap registryMap = NutMap.NEW() .setv("leaseExpirationEnabled", registry.isLeaseExpirationEnabled()) .setv("numOfRenewsPerMinThreshold", registry.getNumOfRenewsPerMinThreshold()) .setv("numOfRenewsInLastMin", registry.getNumOfRenewsInLastMin()) .setv("selfPreservationModeEnabled", registry.isSelfPreservationModeEnabled()); result.put("registry", registryMap); result.put("isBelowRenewThresold", registry.isBelowRenewThresold() == 1); DataCenterInfo info = getServerContext().getApplicationInfoManager() .getInfo() .getDataCenterInfo(); result.put("amazonInfo", false); if (info.getName() == DataCenterInfo.Name.Amazon) { AmazonInfo amazonInfo = (AmazonInfo) info; result.put("amazonInfo", true); result.put("amiId", amazonInfo.get(AmazonInfo.MetaDataKey.amiId)); result.put("availabilityZone", amazonInfo.get(AmazonInfo.MetaDataKey.availabilityZone)); result.put("instanceId", amazonInfo.get(AmazonInfo.MetaDataKey.instanceId)); } }
EurekaInstanceConfig instanceConfig = isCloud(ConfigurationManager.getDeploymentContext()) ? new CloudInstanceConfig() : new MyDataCenterInstanceConfig();
final DeploymentContext config = ConfigurationManager.getDeploymentContext();