Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize code of eureka #3660

Merged
merged 4 commits into from
Sep 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,7 @@ protected static class EurekaHealthCheckApplication {

@Bean
public HealthIndicator healthIndicator() {
return new HealthIndicator() {
@Override
public Health health() {
return new Health.Builder().outOfService().build();
}
};
return () -> new Health.Builder().outOfService().build();
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,9 @@ public ResponseEntity sendHeartBeat(@PathVariable String appName,
if ("fourOFour".equals(appName)) {
return new ResponseEntity(HttpStatus.NOT_FOUND);
}
return new ResponseEntity<InstanceInfo>(new InstanceInfo(null, null, null, null,
null, null, null, null, null, null, null, null, null, 0, null, null, null,
null, null, null, null, new HashMap<>(), 0L, 0L, null, null),
HttpStatus.OK);
return new ResponseEntity<>(new InstanceInfo(null, null, null, null, null, null,
null, null, null, null, null, null, null, 0, null, null, null, null, null,
null, null, new HashMap<>(), 0L, 0L, null, null), HttpStatus.OK);
}

@ResponseStatus(HttpStatus.OK)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,7 @@ public class EurekaSampleApplication implements ApplicationContextAware, Closeab

@Bean
public HealthCheckHandler healthCheckHandler() {
return new HealthCheckHandler() {
@Override
public InstanceInfo.InstanceStatus getStatus(
InstanceInfo.InstanceStatus currentStatus) {
return InstanceInfo.InstanceStatus.UP;
}
};
return currentStatus -> InstanceInfo.InstanceStatus.UP;
}

@RequestMapping("/")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void testDomainExtractingServer() {

@Test
public void testZoneInMetaData() {
this.metadata = new HashMap<String, String>();
this.metadata = new HashMap<>();
this.metadata.put("zone", "us-west-1");
this.metadata.put("instanceId", INSTANCE_ID);
DomainExtractingServerList serverList = getDomainExtractingServerList(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,7 @@ public TestLoadbalancerClient testLoadbalanceClient(
@Bean
public CommandLineRunner commandLineRunner(
final TestLoadbalancerClient testLoadbalancerClient) {
return new CommandLineRunner() {
@Override
public void run(String... args) throws Exception {
testLoadbalancerClient.doStuff();
}
};
return args -> testLoadbalancerClient.doStuff();
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -197,21 +196,16 @@ private void populateApps(Map<String, Object> model) {
else {
zoneCounts.put(zone, 1);
}
List<Pair<String, String>> list = instancesByStatus.get(status);
if (list == null) {
list = new ArrayList<>();
instancesByStatus.put(status, list);
}
List<Pair<String, String>> list = instancesByStatus
.computeIfAbsent(status, k -> new ArrayList<>());
list.add(new Pair<>(id, url));
}
appData.put("amiCounts", amiCounts.entrySet());
appData.put("zoneCounts", zoneCounts.entrySet());
ArrayList<Map<String, Object>> instanceInfos = new ArrayList<>();
appData.put("instanceInfos", instanceInfos);
for (Iterator<Map.Entry<InstanceInfo.InstanceStatus, List<Pair<String, String>>>> iter = instancesByStatus
.entrySet().iterator(); iter.hasNext();) {
Map.Entry<InstanceInfo.InstanceStatus, List<Pair<String, String>>> entry = iter
.next();
for (Map.Entry<InstanceInfo.InstanceStatus, List<Pair<String, String>>> entry : instancesByStatus
.entrySet()) {
List<Pair<String, String>> value = entry.getValue();
InstanceInfo.InstanceStatus status = entry.getKey();
LinkedHashMap<String, Object> instanceData = new LinkedHashMap<>();
Expand Down Expand Up @@ -296,8 +290,8 @@ private String scrubBasicAuth(String urlList) {
StringBuilder filteredUrls = new StringBuilder();
for (String u : urls) {
if (u.contains("@")) {
filteredUrls.append(u.substring(0, u.indexOf("//") + 2))
.append(u.substring(u.indexOf("@") + 1, u.length())).append(",");
filteredUrls.append(u, 0, u.indexOf("//") + 2)
.append(u.substring(u.indexOf("@") + 1)).append(",");
}
else {
filteredUrls.append(u).append(",");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,23 +64,20 @@ public void setServletContext(ServletContext servletContext) {

@Override
public void start() {
new Thread(new Runnable() {
@Override
public void run() {
try {
// TODO: is this class even needed now?
eurekaServerBootstrap.contextInitialized(
EurekaServerInitializerConfiguration.this.servletContext);
log.info("Started Eureka Server");

publish(new EurekaRegistryAvailableEvent(getEurekaServerConfig()));
EurekaServerInitializerConfiguration.this.running = true;
publish(new EurekaServerStartedEvent(getEurekaServerConfig()));
}
catch (Exception ex) {
// Help!
log.error("Could not initialize Eureka servlet context", ex);
}
new Thread(() -> {
try {
// TODO: is this class even needed now?
eurekaServerBootstrap.contextInitialized(
EurekaServerInitializerConfiguration.this.servletContext);
log.info("Started Eureka Server");

publish(new EurekaRegistryAvailableEvent(getEurekaServerConfig()));
EurekaServerInitializerConfiguration.this.running = true;
publish(new EurekaServerStartedEvent(getEurekaServerConfig()));
}
catch (Exception ex) {
// Help!
log.error("Could not initialize Eureka servlet context", ex);
}
}).start();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void notUpdatedWhenDnsIsTrue() {
"eureka.client.region=unavailable-region", // to force defaultZone
"eureka.client.service-url.defaultZone=http://default-host1:8678/eureka/");
this.context.publishEvent(new EnvironmentChangeEvent(
new HashSet<String>(Arrays.asList(USE_DNS, DEFAULT_ZONE))));
new HashSet<>(Arrays.asList(USE_DNS, DEFAULT_ZONE))));

assertThat(serviceUrlMatches("http://default-host1:8678/eureka/")).as(
"PeerEurekaNodes' are updated when eureka.client.use-dns-for-fetching-service-urls is true")
Expand All @@ -97,7 +97,7 @@ public void updatedWhenDnsIsFalse() {
"eureka.client.region=unavailable-region", // to force defaultZone
"eureka.client.service-url.defaultZone=http://default-host2:8678/eureka/");
this.context.publishEvent(new EnvironmentChangeEvent(
new HashSet<String>(Arrays.asList(USE_DNS, DEFAULT_ZONE))));
new HashSet<>(Arrays.asList(USE_DNS, DEFAULT_ZONE))));

assertThat(serviceUrlMatches("http://default-host2:8678/eureka/")).as(
"PeerEurekaNodes' are not updated when eureka.client.use-dns-for-fetching-service-urls is false")
Expand Down