-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(openchallenges): update the Eureka config of the challenge and i…
…mage services (#2768)
- Loading branch information
1 parent
2199038
commit 14b1889
Showing
3 changed files
with
70 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
...gebionetworks/openchallenges/image/service/configuration/EurekaInstanceConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package org.sagebionetworks.openchallenges.image.service.configuration; | ||
|
||
import java.net.InetAddress; | ||
import java.net.UnknownHostException; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.cloud.commons.util.InetUtils; | ||
import org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
public class EurekaInstanceConfiguration { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(EurekaInstanceConfiguration.class); | ||
|
||
@Value("${server.port}") | ||
private String port; | ||
|
||
/** | ||
* If the application is planned to be deployed to an AWS cloud, the Eureka instance must be | ||
* configured to be AWS-aware. This can be done by customizing the EurekaInstanceConfigBean. | ||
* | ||
* @see <a | ||
* href="https://medium.com/@harsugangwar/microservices-with-eureka-on-aws-ecs-a-guide-to-service-discovery-and-ci-with-aws-codebuild-0478a4a71ba2">Microservices | ||
* with Eureka on AWS ECS: A Guide to Service Discovery and CI with AWS CodeBuild</a> | ||
*/ | ||
@Bean | ||
@ConditionalOnProperty( | ||
value = "openchallenges-image-service.is-deployed-on-aws", | ||
havingValue = "true", | ||
matchIfMissing = false) | ||
public EurekaInstanceConfigBean eurekaInstanceConfig(InetUtils inetUtils) { | ||
LOGGER.info("Configuring the Eureka instance for AWS."); | ||
EurekaInstanceConfigBean bean = new EurekaInstanceConfigBean(inetUtils); | ||
String ip = null; | ||
try { | ||
ip = InetAddress.getLocalHost().getHostAddress(); | ||
} catch (UnknownHostException e) { | ||
LOGGER.error("Unable to get the host address.", e); | ||
} | ||
bean.setIpAddress(ip); | ||
bean.setPreferIpAddress(true); | ||
bean.setNonSecurePortEnabled(true); | ||
bean.setNonSecurePort(Integer.parseInt(port)); | ||
return bean; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters