Optimize code of eureka (#3660)
* Optimize code of eureka * Merge newest code * fix checkstyle bug
This commit is contained in:
committed by
Olga Maciaszek-Sharma
parent
ac9f021b92
commit
bd6005e23d
@@ -64,12 +64,7 @@ public class EurekaHealthCheckTests {
|
||||
|
||||
@Bean
|
||||
public HealthIndicator healthIndicator() {
|
||||
return new HealthIndicator() {
|
||||
@Override
|
||||
public Health health() {
|
||||
return new Health.Builder().outOfService().build();
|
||||
}
|
||||
};
|
||||
return () -> new Health.Builder().outOfService().build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -131,10 +131,9 @@ public class EurekaServerMockApplication {
|
||||
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)
|
||||
|
||||
@@ -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("/")
|
||||
|
||||
@@ -66,7 +66,7 @@ public class DomainExtractingServerListTests {
|
||||
|
||||
@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(
|
||||
|
||||
@@ -66,12 +66,7 @@ public class RibbonEurekaAutoConfigurationTests {
|
||||
@Bean
|
||||
public CommandLineRunner commandLineRunner(
|
||||
final TestLoadbalancerClient testLoadbalancerClient) {
|
||||
return new CommandLineRunner() {
|
||||
@Override
|
||||
public void run(String... args) throws Exception {
|
||||
testLoadbalancerClient.doStuff();
|
||||
}
|
||||
};
|
||||
return args -> testLoadbalancerClient.doStuff();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ import java.net.URI;
|
||||
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;
|
||||
@@ -197,21 +196,16 @@ public class EurekaController {
|
||||
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<>();
|
||||
@@ -296,8 +290,8 @@ public class EurekaController {
|
||||
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(",");
|
||||
|
||||
@@ -64,23 +64,20 @@ public class EurekaServerInitializerConfiguration
|
||||
|
||||
@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");
|
||||
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);
|
||||
}
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ public class RefreshablePeerEurekaNodesTests {
|
||||
"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")
|
||||
@@ -97,7 +97,7 @@ public class RefreshablePeerEurekaNodesTests {
|
||||
"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")
|
||||
|
||||
Reference in New Issue
Block a user