Merge remote-tracking branch 'origin/3.1.x'
This commit is contained in:
@@ -47,6 +47,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
* @author Gang Li
|
||||
* @author Weix Sun
|
||||
*/
|
||||
@Controller
|
||||
@RequestMapping("${eureka.dashboard.path:/}")
|
||||
@@ -57,8 +58,20 @@ public class EurekaController {
|
||||
|
||||
private ApplicationInfoManager applicationInfoManager;
|
||||
|
||||
private final EurekaProperties eurekaProperties;
|
||||
|
||||
/**
|
||||
* @deprecated in favour of
|
||||
* {@link EurekaController#EurekaController(ApplicationInfoManager, EurekaProperties)}
|
||||
*/
|
||||
@Deprecated
|
||||
public EurekaController(ApplicationInfoManager applicationInfoManager) {
|
||||
this(applicationInfoManager, null);
|
||||
}
|
||||
|
||||
public EurekaController(ApplicationInfoManager applicationInfoManager, EurekaProperties eurekaProperties) {
|
||||
this.applicationInfoManager = applicationInfoManager;
|
||||
this.eurekaProperties = eurekaProperties;
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.GET)
|
||||
@@ -115,8 +128,14 @@ public class EurekaController {
|
||||
private void populateHeader(Map<String, Object> model) {
|
||||
model.put("currentTime", StatusResource.getCurrentTimeAsString());
|
||||
model.put("upTime", StatusInfo.getUpTime());
|
||||
model.put("environment", "N/A"); // FIXME:
|
||||
model.put("datacenter", "N/A"); // FIXME:
|
||||
if (eurekaProperties != null) {
|
||||
model.put("environment", eurekaProperties.getEnvironment());
|
||||
model.put("datacenter", eurekaProperties.getDatacenter());
|
||||
}
|
||||
else {
|
||||
model.put("environment", "N/A");
|
||||
model.put("datacenter", "N/A");
|
||||
}
|
||||
PeerAwareInstanceRegistry registry = getRegistry();
|
||||
model.put("registry", registry);
|
||||
model.put("isBelowRenewThreshold", registry.isBelowRenewThresold() == 1);
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Copyright 2013-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.netflix.eureka.server;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
/**
|
||||
* Configuration properties for the Eureka deployment.
|
||||
*
|
||||
* @author Weix Sun
|
||||
*/
|
||||
@ConfigurationProperties("eureka")
|
||||
public class EurekaProperties {
|
||||
|
||||
/**
|
||||
* Eureka environment. Defaults to "test".
|
||||
*/
|
||||
private String environment = "test";
|
||||
|
||||
/**
|
||||
* Eureka datacenter. Defaults to "default".
|
||||
*/
|
||||
private String datacenter = "default";
|
||||
|
||||
public String getEnvironment() {
|
||||
return environment;
|
||||
}
|
||||
|
||||
public void setEnvironment(String environment) {
|
||||
this.environment = environment;
|
||||
}
|
||||
|
||||
public String getDatacenter() {
|
||||
return datacenter;
|
||||
}
|
||||
|
||||
public void setDatacenter(String datacenter) {
|
||||
this.datacenter = datacenter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
EurekaProperties that = (EurekaProperties) o;
|
||||
return Objects.equals(datacenter, that.datacenter) && Objects.equals(environment, that.environment);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(environment, datacenter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuilder sb = new StringBuilder("EurekaProperties{");
|
||||
sb.append("environment='").append(environment).append('\'');
|
||||
sb.append(", datacenter=").append(datacenter);
|
||||
sb.append('}');
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -73,11 +73,13 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
* @author Gunnar Hillert
|
||||
* @author Biju Kunjummen
|
||||
* @author Fahim Farook
|
||||
* @author Weix Sun
|
||||
*/
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@Import(EurekaServerInitializerConfiguration.class)
|
||||
@ConditionalOnBean(EurekaServerMarkerConfiguration.Marker.class)
|
||||
@EnableConfigurationProperties({ EurekaDashboardProperties.class, InstanceRegistryProperties.class })
|
||||
@EnableConfigurationProperties({ EurekaDashboardProperties.class, InstanceRegistryProperties.class,
|
||||
EurekaProperties.class })
|
||||
@PropertySource("classpath:/eureka/server.properties")
|
||||
public class EurekaServerAutoConfiguration implements WebMvcConfigurer {
|
||||
|
||||
@@ -113,8 +115,8 @@ public class EurekaServerAutoConfiguration implements WebMvcConfigurer {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnProperty(prefix = "eureka.dashboard", name = "enabled", matchIfMissing = true)
|
||||
public EurekaController eurekaController() {
|
||||
return new EurekaController(this.applicationInfoManager);
|
||||
public EurekaController eurekaController(EurekaProperties eurekaProperties) {
|
||||
return new EurekaController(this.applicationInfoManager, eurekaProperties);
|
||||
}
|
||||
|
||||
static {
|
||||
|
||||
@@ -37,6 +37,7 @@ import org.apache.commons.logging.LogFactory;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
* @author Weix Sun
|
||||
*/
|
||||
public class EurekaServerBootstrap {
|
||||
|
||||
@@ -66,7 +67,6 @@ public class EurekaServerBootstrap {
|
||||
|
||||
public void contextInitialized(ServletContext context) {
|
||||
try {
|
||||
initEurekaEnvironment();
|
||||
initEurekaServerContext();
|
||||
|
||||
context.setAttribute(EurekaServerContext.class.getName(), this.serverContext);
|
||||
@@ -92,11 +92,6 @@ public class EurekaServerBootstrap {
|
||||
log.info("Eureka Service is now shutdown...");
|
||||
}
|
||||
|
||||
protected void initEurekaEnvironment() throws Exception {
|
||||
log.info("Setting the eureka configuration..");
|
||||
|
||||
}
|
||||
|
||||
protected void initEurekaServerContext() throws Exception {
|
||||
// For backward compatibility
|
||||
JsonXStream.getInstance().registerConverter(new V1AwareInstanceInfoConverter(), XStream.PRIORITY_VERY_HIGH);
|
||||
|
||||
@@ -96,10 +96,13 @@ class EurekaControllerTests {
|
||||
void testStatus() throws Exception {
|
||||
Map<String, Object> model = new HashMap<>();
|
||||
|
||||
EurekaController controller = new EurekaController(infoManager);
|
||||
EurekaController controller = new EurekaController(infoManager, new EurekaProperties());
|
||||
|
||||
controller.status(new MockHttpServletRequest("GET", "/"), model);
|
||||
|
||||
assertThat((String) model.get("environment")).isEqualTo("test");
|
||||
assertThat((String) model.get("datacenter")).isEqualTo("default");
|
||||
|
||||
Map<String, Object> app = getFirst(model, "apps");
|
||||
Map<String, Object> instanceInfo = getFirst(app, "instanceInfos");
|
||||
Map<String, Object> instance = getFirst(instanceInfo, "instances");
|
||||
|
||||
Reference in New Issue
Block a user