Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/3.1.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
OlgaMaciaszek committed Apr 13, 2022
2 parents 2a31d0e + a1a6ee2 commit e38cd1e
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
/**
* @author Spencer Gibb
* @author Gang Li
* @author Weix Sun
*/
@Controller
@RequestMapping("${eureka.dashboard.path:/}")
Expand All @@ -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)
Expand Down Expand Up @@ -115,8 +128,14 @@ protected void populateBase(HttpServletRequest request, Map<String, Object> mode
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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,13 @@
* @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 {

Expand Down Expand Up @@ -113,8 +115,8 @@ public HasFeatures eurekaServerFeature() {

@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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

/**
* @author Spencer Gibb
* @author Weix Sun
*/
public class EurekaServerBootstrap {

Expand Down Expand Up @@ -66,7 +67,6 @@ public EurekaServerBootstrap(ApplicationInfoManager applicationInfoManager, Eure

public void contextInitialized(ServletContext context) {
try {
initEurekaEnvironment();
initEurekaServerContext();

context.setAttribute(EurekaServerContext.class.getName(), this.serverContext);
Expand All @@ -92,11 +92,6 @@ public void contextDestroyed(ServletContext context) {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,13 @@ static void setInstance(ApplicationInfoManager infoManager) throws IllegalAccess
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");
Expand Down

0 comments on commit e38cd1e

Please sign in to comment.