Polish
This commit is contained in:
@@ -57,14 +57,10 @@ public class EurekaController {
|
||||
@RequestMapping(method = RequestMethod.GET)
|
||||
public String status(HttpServletRequest request, Map<String, Object> model) {
|
||||
populateBase(request, model);
|
||||
|
||||
populateApps(model);
|
||||
|
||||
StatusInfo statusInfo = new StatusResource().getStatusInfo();
|
||||
model.put("statusInfo", statusInfo);
|
||||
|
||||
populateInstanceInfo(model, statusInfo);
|
||||
|
||||
return "eureka/status";
|
||||
}
|
||||
|
||||
@@ -72,7 +68,6 @@ public class EurekaController {
|
||||
public String lastn(HttpServletRequest request, Map<String, Object> model) {
|
||||
populateBase(request, model);
|
||||
PeerAwareInstanceRegistry registery = PeerAwareInstanceRegistry.getInstance();
|
||||
|
||||
ArrayList<Map<String, Object>> lastNCanceled = new ArrayList<>();
|
||||
List<Pair<Long, String>> list = registery.getLastNCanceledInstances();
|
||||
for (Pair<Long, String> entry : list) {
|
||||
@@ -80,7 +75,6 @@ public class EurekaController {
|
||||
.longValue()));
|
||||
}
|
||||
model.put("lastNCanceled", lastNCanceled);
|
||||
|
||||
list = registery.getLastNRegisteredInstances();
|
||||
ArrayList<Map<String, Object>> lastNRegistered = new ArrayList<>();
|
||||
for (Pair<Long, String> entry : list) {
|
||||
@@ -88,7 +82,6 @@ public class EurekaController {
|
||||
.longValue()));
|
||||
}
|
||||
model.put("lastNRegistered", lastNRegistered);
|
||||
|
||||
return "eureka/lastn";
|
||||
}
|
||||
|
||||
@@ -104,9 +97,7 @@ public class EurekaController {
|
||||
model.put("basePath", "/");
|
||||
model.put("dashboardPath", this.dashboardPath.equals("/") ? ""
|
||||
: this.dashboardPath);
|
||||
|
||||
populateHeader(model);
|
||||
|
||||
populateNavbar(request, model);
|
||||
}
|
||||
|
||||
@@ -120,7 +111,6 @@ public class EurekaController {
|
||||
model.put("registry", PeerAwareInstanceRegistry.getInstance());
|
||||
model.put("isBelowRenewThresold", PeerAwareInstanceRegistry.getInstance()
|
||||
.isBelowRenewThresold() == 1);
|
||||
|
||||
DataCenterInfo info = ApplicationInfoManager.getInstance().getInfo()
|
||||
.getDataCenterInfo();
|
||||
if (info.getName() == DataCenterInfo.Name.Amazon) {
|
||||
@@ -143,7 +133,7 @@ public class EurekaController {
|
||||
String href = node.getServiceUrl();
|
||||
replicas.put(uri.getHost(), href);
|
||||
}
|
||||
catch (Exception e) {
|
||||
catch (Exception ex) {
|
||||
// ignore?
|
||||
}
|
||||
}
|
||||
@@ -153,18 +143,14 @@ public class EurekaController {
|
||||
private void populateApps(Map<String, Object> model) {
|
||||
List<com.netflix.discovery.shared.Application> sortedApplications = PeerAwareInstanceRegistry
|
||||
.getInstance().getSortedApplications();
|
||||
|
||||
ArrayList<Map<String, Object>> apps = new ArrayList<>();
|
||||
|
||||
for (Application app : sortedApplications) {
|
||||
LinkedHashMap<String, Object> appData = new LinkedHashMap<>();
|
||||
apps.add(appData);
|
||||
|
||||
appData.put("name", app.getName());
|
||||
Map<String, Integer> amiCounts = new HashMap<>();
|
||||
Map<InstanceInfo.InstanceStatus, List<Pair<String, String>>> instancesByStatus = new HashMap<>();
|
||||
Map<String, Integer> zoneCounts = new HashMap<>();
|
||||
|
||||
for (InstanceInfo info : app.getInstances()) {
|
||||
String id = info.getId();
|
||||
String url = info.getStatusPageUrl();
|
||||
@@ -176,7 +162,6 @@ public class EurekaController {
|
||||
ami = dcInfo.get(AmazonInfo.MetaDataKey.amiId);
|
||||
zone = dcInfo.get(AmazonInfo.MetaDataKey.availabilityZone);
|
||||
}
|
||||
|
||||
Integer count = amiCounts.get(ami);
|
||||
if (count != null) {
|
||||
amiCounts.put(ami, Integer.valueOf(count.intValue() + 1));
|
||||
@@ -184,7 +169,6 @@ public class EurekaController {
|
||||
else {
|
||||
amiCounts.put(ami, Integer.valueOf(1));
|
||||
}
|
||||
|
||||
count = zoneCounts.get(zone);
|
||||
if (count != null) {
|
||||
zoneCounts.put(zone, Integer.valueOf(count.intValue() + 1));
|
||||
@@ -193,35 +177,31 @@ public class EurekaController {
|
||||
zoneCounts.put(zone, Integer.valueOf(1));
|
||||
}
|
||||
List<Pair<String, String>> list = instancesByStatus.get(status);
|
||||
|
||||
if (list == null) {
|
||||
list = new ArrayList<>();
|
||||
instancesByStatus.put(status, list);
|
||||
}
|
||||
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();
|
||||
List<Pair<String, String>> value = entry.getValue();
|
||||
InstanceInfo.InstanceStatus status = entry.getKey();
|
||||
|
||||
LinkedHashMap<String, Object> instanceData = new LinkedHashMap<>();
|
||||
instanceInfos.add(instanceData);
|
||||
|
||||
instanceData.put("status", entry.getKey());
|
||||
ArrayList<Map<String, Object>> instances = new ArrayList<>();
|
||||
instanceData.put("instances", instances);
|
||||
instanceData.put("isNotUp", status != InstanceInfo.InstanceStatus.UP);
|
||||
|
||||
// TODO
|
||||
|
||||
/*
|
||||
* if(status != InstanceInfo.InstanceStatus.UP){
|
||||
* buf.append("<font color=red size=+1><b>"); }
|
||||
@@ -248,13 +228,11 @@ public class EurekaController {
|
||||
}
|
||||
// out.println("<td>" + buf.toString() + "</td></tr>");
|
||||
}
|
||||
|
||||
model.put("apps", apps);
|
||||
}
|
||||
|
||||
private void populateInstanceInfo(Map<String, Object> model, StatusInfo statusInfo) {
|
||||
InstanceInfo instanceInfo = statusInfo.getInstanceInfo();
|
||||
|
||||
Map<String, String> instanceMap = new HashMap<>();
|
||||
instanceMap.put("ipAddr", instanceInfo.getIPAddr());
|
||||
instanceMap.put("status", instanceInfo.getStatus().toString());
|
||||
@@ -270,7 +248,6 @@ public class EurekaController {
|
||||
instanceMap.put("instance-type",
|
||||
info.get(AmazonInfo.MetaDataKey.instanceType));
|
||||
}
|
||||
|
||||
model.put("instanceInfo", instanceMap);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,8 +22,8 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
/**
|
||||
* Configuration properties for the Eureka dashboard (UI).
|
||||
* @author Dave Syer
|
||||
*
|
||||
* @author Dave Syer
|
||||
*/
|
||||
@ConfigurationProperties("eureka.dashboard")
|
||||
@Data
|
||||
@@ -35,7 +35,7 @@ public class EurekaDashboardProperties {
|
||||
private String path = "/";
|
||||
|
||||
/**
|
||||
* FLag to enable the Eureka dashboard. Default true.
|
||||
* Flag to enable the Eureka dashboard. Default true.
|
||||
*/
|
||||
private boolean enabled = true;
|
||||
|
||||
|
||||
@@ -34,9 +34,7 @@ import com.google.common.collect.Lists;
|
||||
import com.sun.jersey.spi.container.servlet.ServletContainer;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Gunnar Hillert
|
||||
*
|
||||
*/
|
||||
@Configuration
|
||||
@Import(EurekaServerInitializerConfiguration.class)
|
||||
@@ -72,4 +70,5 @@ public class EurekaServerConfiguration extends WebMvcConfigurerAdapter {
|
||||
bean.setOrder(Ordered.LOWEST_PRECEDENCE - 10);
|
||||
return bean;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -63,7 +63,6 @@ import com.netflix.eureka.PeerAwareInstanceRegistry;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
@Configuration
|
||||
@EnableConfigurationProperties(EurekaServerConfigBean.class)
|
||||
@@ -114,7 +113,7 @@ public class EurekaServerInitializerConfiguration implements ServletContextAware
|
||||
.toString());
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
catch (IOException ex) {
|
||||
// ignore
|
||||
}
|
||||
LoggingConfiguration.getInstance().configure();
|
||||
@@ -145,9 +144,9 @@ public class EurekaServerInitializerConfiguration implements ServletContextAware
|
||||
.publishEvent(new EurekaServerStartedEvent(
|
||||
EurekaServerInitializerConfiguration.this.eurekaServerConfig));
|
||||
}
|
||||
catch (Exception e) {
|
||||
catch (Exception ex) {
|
||||
// Help!
|
||||
logger.error("Could not initialize Eureka servlet context", e);
|
||||
logger.error("Could not initialize Eureka servlet context", ex);
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
@@ -226,8 +225,8 @@ public class EurekaServerInitializerConfiguration implements ServletContextAware
|
||||
modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
|
||||
ReflectionUtils.setField(field, null, proxy);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new IllegalStateException("Cannot modify instance registry", e);
|
||||
catch (Exception ex) {
|
||||
throw new IllegalStateException("Cannot modify instance registry", ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -260,9 +259,9 @@ public class EurekaServerInitializerConfiguration implements ServletContextAware
|
||||
ReflectionUtils.setField(field, this.instance, count);
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
catch (Exception ex) {
|
||||
throw new IllegalStateException(
|
||||
"Cannot modify instance registry expected renews", e);
|
||||
"Cannot modify instance registry expected renews", ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -274,9 +273,6 @@ public class EurekaServerInitializerConfiguration implements ServletContextAware
|
||||
* hasn't sent any renewals recently. This happens for a standalone server. It
|
||||
* seems like a bad default, so we set it to the smallest non-zero value we can,
|
||||
* so that any instances that subsequently register can bump up the threshold.
|
||||
*
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
private class TrafficOpener implements MethodInterceptor {
|
||||
|
||||
@@ -290,6 +286,7 @@ public class EurekaServerInitializerConfiguration implements ServletContextAware
|
||||
}
|
||||
return invocation.proceed();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@ import com.netflix.eureka.lease.LeaseManager;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public interface LeaseManagerLite<T> extends LeaseManager<T> {
|
||||
|
||||
|
||||
@@ -24,11 +24,11 @@ import org.springframework.util.ReflectionUtils;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public class PiggybackMethodInterceptor implements MethodInterceptor {
|
||||
|
||||
private Object delegate;
|
||||
|
||||
private Class<?>[] types;
|
||||
|
||||
public PiggybackMethodInterceptor(Object delegate, Class<?>... types) {
|
||||
|
||||
@@ -28,8 +28,11 @@ import org.springframework.context.ApplicationEvent;
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@SuppressWarnings("serial")
|
||||
public class EurekaInstanceCanceledEvent extends ApplicationEvent {
|
||||
|
||||
private String appName;
|
||||
|
||||
private String serverId;
|
||||
|
||||
boolean replication;
|
||||
|
||||
public EurekaInstanceCanceledEvent(Object source, String appName, String serverId,
|
||||
@@ -39,4 +42,5 @@ public class EurekaInstanceCanceledEvent extends ApplicationEvent {
|
||||
this.serverId = serverId;
|
||||
this.replication = replication;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -30,8 +30,11 @@ import com.netflix.appinfo.InstanceInfo;
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@SuppressWarnings("serial")
|
||||
public class EurekaInstanceRegisteredEvent extends ApplicationEvent {
|
||||
|
||||
private InstanceInfo instanceInfo;
|
||||
|
||||
private int leaseDuration;
|
||||
|
||||
boolean replication;
|
||||
|
||||
public EurekaInstanceRegisteredEvent(Object source, InstanceInfo instanceInfo,
|
||||
@@ -41,4 +44,5 @@ public class EurekaInstanceRegisteredEvent extends ApplicationEvent {
|
||||
this.leaseDuration = leaseDuration;
|
||||
this.replication = replication;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -30,9 +30,13 @@ import com.netflix.appinfo.InstanceInfo;
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@SuppressWarnings("serial")
|
||||
public class EurekaInstanceRenewedEvent extends ApplicationEvent {
|
||||
|
||||
private String appName;
|
||||
|
||||
private String serverId;
|
||||
|
||||
private InstanceInfo instanceInfo;
|
||||
|
||||
boolean replication;
|
||||
|
||||
public EurekaInstanceRenewedEvent(Object source, String appName, String serverId,
|
||||
@@ -43,4 +47,5 @@ public class EurekaInstanceRenewedEvent extends ApplicationEvent {
|
||||
this.instanceInfo = instanceInfo;
|
||||
this.replication = replication;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,7 +22,6 @@ import com.netflix.eureka.EurekaServerConfig;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class EurekaRegistryAvailableEvent extends ApplicationEvent {
|
||||
|
||||
@@ -22,7 +22,6 @@ import com.netflix.eureka.EurekaServerConfig;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class EurekaServerStartedEvent extends ApplicationEvent {
|
||||
|
||||
@@ -81,7 +81,6 @@ public class LeaseManagerMessageBroker implements LeaseManagerLite<InstanceInfo>
|
||||
return input.getName().equals(appName);
|
||||
}
|
||||
});
|
||||
|
||||
if (app.isPresent()) {
|
||||
Optional<InstanceInfo> info = tryFind(app.get().getInstances(),
|
||||
new Predicate<InstanceInfo>() {
|
||||
@@ -99,4 +98,5 @@ public class LeaseManagerMessageBroker implements LeaseManagerLite<InstanceInfo>
|
||||
@Override
|
||||
public void evict() {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -46,17 +46,6 @@ public class ApplicationContextTests {
|
||||
@Value("${local.server.port}")
|
||||
private int port = 0;
|
||||
|
||||
@Configuration
|
||||
@EnableAutoConfiguration
|
||||
@EnableEurekaServer
|
||||
protected static class Application {
|
||||
public static void main(String[] args) {
|
||||
new SpringApplicationBuilder(Application.class).properties(
|
||||
"spring.application.name=eureka", "server.contextPath=/context").run(
|
||||
args);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void catalogLoads() {
|
||||
@SuppressWarnings("rawtypes")
|
||||
@@ -103,4 +92,16 @@ public class ApplicationContextTests {
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@EnableAutoConfiguration
|
||||
@EnableEurekaServer
|
||||
protected static class Application {
|
||||
|
||||
public static void main(String[] args) {
|
||||
new SpringApplicationBuilder(Application.class).properties(
|
||||
"spring.application.name=eureka", "server.contextPath=/context").run(
|
||||
args);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,7 +81,6 @@ public class ApplicationTests {
|
||||
String body = entity.getBody();
|
||||
assertNotNull(body);
|
||||
assertFalse("basePath contains double slashes", body.contains(basePath + "/"));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user