diff --git a/apps/openchallenges/service-registry/.env.example b/apps/openchallenges/service-registry/.env.example index adfab6d35a..138a3412c4 100644 --- a/apps/openchallenges/service-registry/.env.example +++ b/apps/openchallenges/service-registry/.env.example @@ -1,2 +1,3 @@ SERVER_PORT=8081 -DEFAULT_ZONE=http://localhost:8081/eureka \ No newline at end of file +DEFAULT_ZONE=http://localhost:8081/eureka +OPENCHALLENGES_SERVICE_REGISTRY_IS_DEPLOYED_ON_AWS=false \ No newline at end of file diff --git a/apps/openchallenges/service-registry/build.gradle b/apps/openchallenges/service-registry/build.gradle index b3270d2ce6..157eacb0fb 100644 --- a/apps/openchallenges/service-registry/build.gradle +++ b/apps/openchallenges/service-registry/build.gradle @@ -5,6 +5,7 @@ buildscript { } plugins { + id 'com.diffplug.spotless' version "${spotlessVersion}" id 'java' id 'org.springframework.boot' version "${springBootVersion}" id "io.spring.dependency-management" version "${springDependencyManagementVersion}" @@ -41,3 +42,13 @@ tasks.withType(JavaCompile) { bootBuildImage { imageName = "ghcr.io/sage-bionetworks/${project.name}-base:local" } + +spotless { + java { + target 'src/*/java/**/*.java' + + importOrder() + removeUnusedImports() + googleJavaFormat() + } +} \ No newline at end of file diff --git a/apps/openchallenges/service-registry/config/application-local.yml b/apps/openchallenges/service-registry/config/application-local.yml index e69de29bb2..ab15347fd1 100644 --- a/apps/openchallenges/service-registry/config/application-local.yml +++ b/apps/openchallenges/service-registry/config/application-local.yml @@ -0,0 +1,3 @@ +openchallenges-service-registry: + welcome-message: 'Welcome to the service registry (local config).' + is-deployed-on-aws: false \ No newline at end of file diff --git a/apps/openchallenges/service-registry/gradle.properties b/apps/openchallenges/service-registry/gradle.properties index b120134921..2067da8e56 100644 --- a/apps/openchallenges/service-registry/gradle.properties +++ b/apps/openchallenges/service-registry/gradle.properties @@ -1,4 +1,5 @@ openchallengesVersion=0.0.1-SNAPSHOT +spotlessVersion=6.11.0 springBootVersion=2.7.8 springCloudVersion=3.1.4 springDependencyManagementVersion=1.0.14.RELEASE \ No newline at end of file diff --git a/apps/openchallenges/service-registry/project.json b/apps/openchallenges/service-registry/project.json index 616ff987ce..faa712ec27 100644 --- a/apps/openchallenges/service-registry/project.json +++ b/apps/openchallenges/service-registry/project.json @@ -97,6 +97,20 @@ "command": "trivy image ghcr.io/sage-bionetworks/openchallenges-service-registry:local --quiet", "color": true } + }, + "format": { + "executor": "nx:run-commands", + "options": { + "command": "./gradlew spotlessApply", + "cwd": "{projectRoot}" + } + }, + "format-check": { + "executor": "nx:run-commands", + "options": { + "command": "./gradlew spotlessCheck", + "cwd": "{projectRoot}" + } } }, "tags": ["type:service", "scope:backend", "language:java", "package-manager:gradle"], diff --git a/apps/openchallenges/service-registry/src/main/java/org/sagebionetworks/openchallenges/service/registry/ServiceRegistryApplication.java b/apps/openchallenges/service-registry/src/main/java/org/sagebionetworks/openchallenges/service/registry/ServiceRegistryApplication.java index 7cf8043568..56e0c0d5ed 100644 --- a/apps/openchallenges/service-registry/src/main/java/org/sagebionetworks/openchallenges/service/registry/ServiceRegistryApplication.java +++ b/apps/openchallenges/service-registry/src/main/java/org/sagebionetworks/openchallenges/service/registry/ServiceRegistryApplication.java @@ -30,5 +30,4 @@ public static void main(String[] args) { public void run(String... args) throws Exception { LOG.info(serviceRegistryConfigData.getWelcomeMessage()); } - } diff --git a/apps/openchallenges/service-registry/src/main/java/org/sagebionetworks/openchallenges/service/registry/configuration/EurekaInstanceConfiguration.java b/apps/openchallenges/service-registry/src/main/java/org/sagebionetworks/openchallenges/service/registry/configuration/EurekaInstanceConfiguration.java new file mode 100644 index 0000000000..beddeee506 --- /dev/null +++ b/apps/openchallenges/service-registry/src/main/java/org/sagebionetworks/openchallenges/service/registry/configuration/EurekaInstanceConfiguration.java @@ -0,0 +1,37 @@ +package org.sagebionetworks.openchallenges.service.registry.configuration; + +import com.netflix.appinfo.AmazonInfo; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +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); + + /** + * 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 Using + * Eureka on AWS + */ + @Bean + @ConditionalOnProperty( + value = "openchallenges-service-registry.is-deployed-on-aws", + havingValue = "true", + matchIfMissing = false) + public EurekaInstanceConfigBean eurekaInstanceConfig(InetUtils inetUtils) { + LOGGER.info("Configuring the Eureka instance to be AWS-aware."); + EurekaInstanceConfigBean bean = new EurekaInstanceConfigBean(inetUtils); + AmazonInfo info = AmazonInfo.Builder.newBuilder().autoBuild("eureka"); + bean.setDataCenterInfo(info); + return bean; + } +} diff --git a/apps/openchallenges/service-registry/src/test/java/org/sagebionetworks/openchallenges/service/registry/ServiceRegistryApplicationTests.java b/apps/openchallenges/service-registry/src/test/java/org/sagebionetworks/openchallenges/service/registry/ServiceRegistryApplicationTests.java index ed3d4f7ecc..cf113e976b 100644 --- a/apps/openchallenges/service-registry/src/test/java/org/sagebionetworks/openchallenges/service/registry/ServiceRegistryApplicationTests.java +++ b/apps/openchallenges/service-registry/src/test/java/org/sagebionetworks/openchallenges/service/registry/ServiceRegistryApplicationTests.java @@ -6,8 +6,6 @@ @SpringBootTest class ServiceRegistryApplicationTests { - @Test - void contextLoads() { - } - + @Test + void contextLoads() {} } diff --git a/libs/openchallenges/app-config-data/src/main/java/org/sagebionetworks/openchallenges/app/config/data/ServiceRegistryConfigData.java b/libs/openchallenges/app-config-data/src/main/java/org/sagebionetworks/openchallenges/app/config/data/ServiceRegistryConfigData.java index 13a112073c..90d9adeffa 100644 --- a/libs/openchallenges/app-config-data/src/main/java/org/sagebionetworks/openchallenges/app/config/data/ServiceRegistryConfigData.java +++ b/libs/openchallenges/app-config-data/src/main/java/org/sagebionetworks/openchallenges/app/config/data/ServiceRegistryConfigData.java @@ -10,4 +10,5 @@ public class ServiceRegistryConfigData { private String welcomeMessage; + private boolean isDeployedOnAws; }