Skip to content

Commit

Permalink
Merge pull request #969 from dtrebbien/misc-fixes
Browse files Browse the repository at this point in the history
Misc. fixes
  • Loading branch information
qiangdavidliu authored Nov 14, 2017
2 parents 6de298e + 2e0c8d6 commit 47789f4
Show file tree
Hide file tree
Showing 34 changed files with 104 additions and 117 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ public String resolveDeploymentContextBasedVipAddresses(String vipAddressMacro)
String key = matcher.group(1);
String value = config.getString(key, "");

logger.debug("att:" + matcher.group());
logger.debug(", att key:" + key);
logger.debug(", att value:" + value);
logger.debug("att:{}", matcher.group());
logger.debug(", att key:{}", key);
logger.debug(", att value:{}", value);
logger.debug("");
result = result.replaceAll("\\$\\{" + key + "\\}", value);
matcher = VIP_ATTRIBUTES_PATTERN.matcher(result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public AmazonInfo autoBuild(String namespace) {
break;
} catch (Throwable e) {
if (config.shouldLogAmazonMetadataErrors()) {
logger.warn("Cannot get the value for the metadata key :" + key + " Reason :", e);
logger.warn("Cannot get the value for the metadata key: {} Reason :", key, e);
}
if (numOfRetries >= 0) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ public static InstanceStatus toEnum(String s) {
return InstanceStatus.valueOf(s.toUpperCase());
} catch (IllegalArgumentException e) {
// ignore and fall through to unknown
if (logger.isDebugEnabled()) logger.debug("illegal argument supplied to InstanceStatus.valueOf: {}, defaulting to {}", s, UNKNOWN);
logger.debug("illegal argument supplied to InstanceStatus.valueOf: {}, defaulting to {}", s, UNKNOWN);
}
}
return UNKNOWN;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private static AmazonInfo init(AmazonInfoConfig amazonInfoConfig, FallbackAddres
.newBuilder()
.withAmazonInfoConfig(amazonInfoConfig)
.autoBuild(amazonInfoConfig.getNamespace());
logger.info("Datacenter is: " + DataCenterInfo.Name.Amazon);
logger.info("Datacenter is: {}", DataCenterInfo.Name.Amazon);
} catch (Throwable e) {
logger.error("Cannot initialize amazon info :", e);
throw new RuntimeException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ public String resolveDeploymentContextBasedVipAddresses(String vipAddressMacro)
String key = matcher.group(1);
String value = DynamicPropertyFactory.getInstance().getStringProperty(key, "").get();

logger.debug("att:" + matcher.group());
logger.debug(", att key:" + key);
logger.debug(", att value:" + value);
logger.debug("att:{}", matcher.group());
logger.debug(", att key:{}", key);
logger.debug(", att value:{}", value);
logger.debug("");
result = result.replaceAll("\\$\\{" + key + "\\}", value);
matcher = VIP_ATTRIBUTES_PATTERN.matcher(result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public synchronized InstanceInfo get() {
// Start off with the STARTING state to avoid traffic
if (!config.isInstanceEnabledOnit()) {
InstanceStatus initialStatus = InstanceStatus.STARTING;
LOG.info("Setting initial instance status as: " + initialStatus);
LOG.info("Setting initial instance status as: {}", initialStatus);
builder.setStatus(initialStatus);
} else {
LOG.info("Setting initial instance status as: {}. This may be too early for the instance to advertise "
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.netflix.discovery;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -52,15 +51,15 @@ protected AbstractAzToRegionMapper(EurekaClientConfig clientConfig) {
public synchronized void setRegionsToFetch(String[] regionsToFetch) {
if (null != regionsToFetch) {
this.regionsToFetch = regionsToFetch;
logger.info("Fetching availability zone to region mapping for regions {}", Arrays.toString(regionsToFetch));
logger.info("Fetching availability zone to region mapping for regions {}", (Object) regionsToFetch);
availabilityZoneVsRegion.clear();
for (String remoteRegion : regionsToFetch) {
Set<String> availabilityZones = getZonesForARegion(remoteRegion);
if (null == availabilityZones
|| (availabilityZones.size() == 1 && availabilityZones.contains(DEFAULT_ZONE))
|| availabilityZones.isEmpty()) {
logger.info("No availability zone information available for remote region: " + remoteRegion
+ ". Now checking in the default mapping.");
logger.info("No availability zone information available for remote region: {}"
+ ". Now checking in the default mapping.", remoteRegion);
if (defaultRegionVsAzMap.containsKey(remoteRegion)) {
Collection<String> defaultAvailabilityZones = defaultRegionVsAzMap.get(remoteRegion);
for (String defaultAvailabilityZone : defaultAvailabilityZones) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ public synchronized BackupRegistry get() {
if (null != backupRegistryClassName) {
try {
backupRegistryInstance = (BackupRegistry) Class.forName(backupRegistryClassName).newInstance();
logger.info("Enabled backup registry of type " + backupRegistryInstance.getClass());
logger.info("Enabled backup registry of type {}", backupRegistryInstance.getClass());
} catch (InstantiationException e) {
logger.error("Error instantiating BackupRegistry.", e);
} catch (IllegalAccessException e) {
Expand Down Expand Up @@ -426,7 +426,7 @@ public synchronized BackupRegistry get() {
throw new IllegalStateException("Registration error at startup. Invalid server response.");
}
} catch (Throwable th) {
logger.error("Registration error at startup.", th.getMessage());
logger.error("Registration error at startup: {}", th.getMessage());
throw new IllegalStateException(th);
}
}
Expand Down Expand Up @@ -809,12 +809,12 @@ public Applications getApplications(String serviceUrl) {
? eurekaTransport.queryClient.getApplications()
: eurekaTransport.queryClient.getVip(clientConfig.getRegistryRefreshSingleVipAddress());
if (response.getStatusCode() == 200) {
logger.debug(PREFIX + appPathIdentifier + " - refresh status: " + response.getStatusCode());
logger.debug(PREFIX + "{} - refresh status: {}", appPathIdentifier, response.getStatusCode());
return response.getEntity();
}
logger.error(PREFIX + appPathIdentifier + " - was unable to refresh its cache! status = " + response.getStatusCode());
logger.error(PREFIX + "{} - was unable to refresh its cache! status = {}", appPathIdentifier, response.getStatusCode());
} catch (Throwable th) {
logger.error(PREFIX + appPathIdentifier + " - was unable to refresh its cache! status = " + th.getMessage(), th);
logger.error(PREFIX + "{} - was unable to refresh its cache! status = {}", appPathIdentifier, th.getMessage(), th);
}
return null;
}
Expand All @@ -823,16 +823,16 @@ public Applications getApplications(String serviceUrl) {
* Register with the eureka service by making the appropriate REST call.
*/
boolean register() throws Throwable {
logger.info(PREFIX + appPathIdentifier + ": registering service...");
logger.info(PREFIX + "{}: registering service...", appPathIdentifier);
EurekaHttpResponse<Void> httpResponse;
try {
httpResponse = eurekaTransport.registrationClient.register(instanceInfo);
} catch (Exception e) {
logger.warn("{} - registration failed {}", PREFIX + appPathIdentifier, e.getMessage(), e);
logger.warn(PREFIX + "{} - registration failed {}", appPathIdentifier, e.getMessage(), e);
throw e;
}
if (logger.isInfoEnabled()) {
logger.info("{} - registration status: {}", PREFIX + appPathIdentifier, httpResponse.getStatusCode());
logger.info(PREFIX + "{} - registration status: {}", appPathIdentifier, httpResponse.getStatusCode());
}
return httpResponse.getStatusCode() == 204;
}
Expand All @@ -844,10 +844,10 @@ boolean renew() {
EurekaHttpResponse<InstanceInfo> httpResponse;
try {
httpResponse = eurekaTransport.registrationClient.sendHeartBeat(instanceInfo.getAppName(), instanceInfo.getId(), instanceInfo, null);
logger.debug("{} - Heartbeat status: {}", PREFIX + appPathIdentifier, httpResponse.getStatusCode());
logger.debug(PREFIX + "{} - Heartbeat status: {}", appPathIdentifier, httpResponse.getStatusCode());
if (httpResponse.getStatusCode() == 404) {
REREGISTER_COUNTER.increment();
logger.info("{} - Re-registering apps/{}", PREFIX + appPathIdentifier, instanceInfo.getAppName());
logger.info(PREFIX + "{} - Re-registering apps/{}", appPathIdentifier, instanceInfo.getAppName());
long timestamp = instanceInfo.setIsDirtyWithTime();
boolean success = register();
if (success) {
Expand All @@ -857,7 +857,7 @@ boolean renew() {
}
return httpResponse.getStatusCode() == 200;
} catch (Throwable e) {
logger.error("{} - was unable to send heartbeat!", PREFIX + appPathIdentifier, e);
logger.error(PREFIX + "{} - was unable to send heartbeat!", appPathIdentifier, e);
return false;
}
}
Expand Down Expand Up @@ -921,9 +921,9 @@ void unregister() {
try {
logger.info("Unregistering ...");
EurekaHttpResponse<Void> httpResponse = eurekaTransport.registrationClient.cancel(instanceInfo.getAppName(), instanceInfo.getId());
logger.info(PREFIX + appPathIdentifier + " - deregister status: " + httpResponse.getStatusCode());
logger.info(PREFIX + "{} - deregister status: {}", appPathIdentifier, httpResponse.getStatusCode());
} catch (Exception e) {
logger.error(PREFIX + appPathIdentifier + " - de-registration failed" + e.getMessage(), e);
logger.error(PREFIX + "{} - de-registration failed{}", appPathIdentifier, e.getMessage(), e);
}
}
}
Expand Down Expand Up @@ -969,7 +969,7 @@ private boolean fetchRegistry(boolean forceFullRegistryFetch) {
applications.setAppsHashCode(applications.getReconcileHashCode());
logTotalInstances();
} catch (Throwable e) {
logger.error(PREFIX + appPathIdentifier + " - was unable to refresh its cache! status = " + e.getMessage(), e);
logger.error(PREFIX + "{} - was unable to refresh its cache! status = {}", appPathIdentifier, e.getMessage(), e);
return false;
} finally {
if (tracer != null) {
Expand Down Expand Up @@ -1261,7 +1261,7 @@ private void initScheduledTasks() {
if (clientConfig.shouldRegisterWithEureka()) {
int renewalIntervalInSecs = instanceInfo.getLeaseInfo().getRenewalIntervalInSecs();
int expBackOffBound = clientConfig.getHeartbeatExecutorExponentialBackOffBound();
logger.info("Starting heartbeat executor: " + "renew interval is: " + renewalIntervalInSecs);
logger.info("Starting heartbeat executor: " + "renew interval is: {}", renewalIntervalInSecs);

// Heartbeat timer
scheduler.schedule(
Expand Down Expand Up @@ -1487,7 +1487,7 @@ void refreshRegistry() {
allAppsHashCodes.append(entry.getValue().getAppsHashCode());
}
logger.debug("Completed cache refresh task for discovery. All Apps hash code is {} ",
allAppsHashCodes.toString());
allAppsHashCodes);
}
} catch (Throwable e) {
logger.error("Cannot fetch registry from server", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public EurekaUpStatusResolver(EurekaClient client, EventBus eventBus) {

@Subscribe
public void onStatusChange(StatusChangeEvent event) {
LOG.info("Eureka status changed from " + event.getPreviousStatus() + " to " + event.getStatus());
LOG.info("Eureka status changed from {} to {}", event.getPreviousStatus(), event.getStatus());
currentStatus = event.getStatus();
counter.incrementAndGet();
}
Expand All @@ -52,7 +52,7 @@ public void init() {
// Must set the initial status
currentStatus = client.getInstanceRemoteStatus();

LOG.info("Initial status set to " + currentStatus);
LOG.info("Initial status set to {}", currentStatus);
eventBus.registerSubscriber(this);
} catch (InvalidSubscriberException e) {
LOG.error("Error registring for discovery status change events.", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public static String resolve(String originalHost) {
} while (targetHost == null);
return targetHost;
} catch (NamingException e) {
logger.warn("Cannot resolve eureka server address " + currentHost + "; returning original value " + originalHost, e);
logger.warn("Cannot resolve eureka server address {}; returning original value {}", currentHost, originalHost, e);
return originalHost;
}
}
Expand Down Expand Up @@ -109,7 +109,7 @@ public static List<String> resolveARecord(String rootDomainName) {
return result;
}
} catch (Exception e) {
logger.warn("Cannot load A-record for eureka server address " + rootDomainName, e);
logger.warn("Cannot load A-record for eureka server address {}", rootDomainName, e);
return null;
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
Expand Down Expand Up @@ -117,15 +116,17 @@ public static List<String> getServiceUrlsFromDNS(EurekaClientConfig clientConfig
}
}
if (zoneFound) {
Object[] args = {zones, instanceZone, zoneIndex};
logger.debug("The zone index from the list {} that matches the instance zone {} is {}", args);
logger.debug("The zone index from the list {} that matches the instance zone {} is {}",
zones, instanceZone, zoneIndex);
break;
}
zoneIndex++;
}
if (zoneIndex >= zones.size()) {
logger.warn("No match for the zone {} in the list of available zones {}",
instanceZone, Arrays.toString(zones.toArray()));
if (logger.isWarnEnabled()) {
logger.warn("No match for the zone {} in the list of available zones {}",
instanceZone, zones.toArray());
}
} else {
// Rearrange the zones with the instance zone first
for (int i = 0; i < zoneIndex; i++) {
Expand Down Expand Up @@ -159,8 +160,10 @@ public static List<String> getServiceUrlsFromDNS(EurekaClientConfig clientConfig
randomizer.randomize(serviceUrls);
serviceUrls.add(0, primaryServiceUrl);

logger.debug("This client will talk to the following serviceUrls in order : {} ",
Arrays.toString(serviceUrls.toArray()));
if (logger.isDebugEnabled()) {
logger.debug("This client will talk to the following serviceUrls in order : {} ",
(Object) serviceUrls.toArray());
}
return serviceUrls;
}

Expand All @@ -180,7 +183,7 @@ public static List<String> getServiceUrlsFromConfig(EurekaClientConfig clientCon
availZones = new String[1];
availZones[0] = DEFAULT_ZONE;
}
logger.debug("The availability zone for the given region {} are {}", region, Arrays.toString(availZones));
logger.debug("The availability zone for the given region {} are {}", region, availZones);
int myZoneOffset = getZoneOffset(instanceZone, preferSameZone, availZones);

List<String> serviceUrls = clientConfig.getEurekaServerServiceUrls(availZones[myZoneOffset]);
Expand Down Expand Up @@ -222,7 +225,7 @@ public static Map<String, List<String>> getServiceUrlsMapFromConfig(EurekaClient
availZones = new String[1];
availZones[0] = DEFAULT_ZONE;
}
logger.debug("The availability zone for the given region {} are {}", region, Arrays.toString(availZones));
logger.debug("The availability zone for the given region {} are {}", region, availZones);
int myZoneOffset = getZoneOffset(instanceZone, preferSameZone, availZones);

String zone = availZones[myZoneOffset];
Expand Down Expand Up @@ -362,7 +365,7 @@ private static int getZoneOffset(String myZone, boolean preferSameZone, String[]
}
}
logger.warn("DISCOVERY: Could not pick a zone based on preferred zone settings. My zone - {}," +
" preferSameZone- {}. Defaulting to " + availZones[0], myZone, preferSameZone);
" preferSameZone - {}. Defaulting to {}", myZone, preferSameZone, availZones[0]);

return 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ public DnsClusterResolver(DnsService dnsService, String region, String rootClust
} else {
this.eurekaEndpoints = DefaultEndpoint.createForServerList(addresses, port, isSecure, relativeUri);
}
if (logger.isDebugEnabled()) {
logger.debug("Resolved {} to {}", rootClusterDNS, eurekaEndpoints);
}
logger.debug("Resolved {} to {}", rootClusterDNS, eurekaEndpoints);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public List<T> getClusterEndpoints() {
} catch (Exception e) {
this.currentReloadIntervalMs = Math.min(maxReloadIntervalMs, currentReloadIntervalMs * 2);
logger.warn("Cluster resolve error; keeping the current Eureka endpoints; next reload in "
+ currentReloadIntervalMs / 1000 + "[sec]", e);
+ "{}[sec]", currentReloadIntervalMs / 1000, e);
}
}
return delegateRef.get().getClusterEndpoints();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ public StaticClusterResolver(String region, T... eurekaEndpoints) {
public StaticClusterResolver(String region, List<T> eurekaEndpoints) {
this.eurekaEndpoints = eurekaEndpoints;
this.region = region;
if (logger.isDebugEnabled()) {
logger.debug("Fixed resolver configuration: {}", eurekaEndpoints);
}
logger.debug("Fixed resolver configuration: {}", eurekaEndpoints);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,7 @@ private List<AwsEndpoint> getClusterEndpointsFromConfig() {
}
}

if (logger.isDebugEnabled()) {
logger.debug("Config resolved to {}", endpoints);
}
logger.debug("Config resolved to {}", endpoints);

if (endpoints.isEmpty()) {
logger.error("Cannot resolve to any endpoints from provided configuration: {}", serviceUrls);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,7 @@ public String getRegion() {
@Override
public List<AwsEndpoint> getClusterEndpoints() {
List<AwsEndpoint> eurekaEndpoints = resolve(region, rootClusterDNS, extractZoneFromDNS, port, isSecure, relativeUri);
if (logger.isDebugEnabled()) {
logger.debug("Resolved {} to {}", rootClusterDNS, eurekaEndpoints);
}
logger.debug("Resolved {} to {}", rootClusterDNS, eurekaEndpoints);

return eurekaEndpoints;
}
Expand Down
Loading

0 comments on commit 47789f4

Please sign in to comment.