diff --git a/aspire4j/aspire4j-extensions-spring/src/main/resources/templates/eureka/application.yaml b/aspire4j/aspire4j-extensions-spring/src/main/resources/templates/eureka/application.yaml index fa74881..fc68e5e 100644 --- a/aspire4j/aspire4j-extensions-spring/src/main/resources/templates/eureka/application.yaml +++ b/aspire4j/aspire4j-extensions-spring/src/main/resources/templates/eureka/application.yaml @@ -4,6 +4,8 @@ spring: server: port: ${targetPort?c} eureka: + instance: + hostname: localhost client: register-with-eureka: ${registerWithEureka?string("true", "false")} fetch-registry: ${fetchRegistry?string("true", "false")} \ No newline at end of file diff --git a/aspire4j/aspire4j-extensions-spring/src/main/resources/templates/eureka/pom.xml b/aspire4j/aspire4j-extensions-spring/src/main/resources/templates/eureka/pom.xml index 960b98c..f07f922 100644 --- a/aspire4j/aspire4j-extensions-spring/src/main/resources/templates/eureka/pom.xml +++ b/aspire4j/aspire4j-extensions-spring/src/main/resources/templates/eureka/pom.xml @@ -14,7 +14,7 @@ 0.0.1-SNAPSHOT - 17 + 21 2023.0.2 @@ -23,6 +23,10 @@ org.springframework.cloud spring-cloud-starter-netflix-eureka-server + + org.springframework.boot + spring-boot-starter-web + org.springframework.boot diff --git a/samples/storage-explorer/date-service/pom.xml b/samples/storage-explorer/date-service/pom.xml index 417dc0e..3fe5eec 100644 --- a/samples/storage-explorer/date-service/pom.xml +++ b/samples/storage-explorer/date-service/pom.xml @@ -28,6 +28,7 @@ 21 + 2023.0.2 @@ -49,6 +50,14 @@ runtime true + + + + org.springframework.cloud + spring-cloud-starter-netflix-eureka-client + + + org.springframework.boot spring-boot-starter-test @@ -56,6 +65,18 @@ + + + + org.springframework.cloud + spring-cloud-dependencies + ${spring-cloud.version} + pom + import + + + + diff --git a/samples/storage-explorer/date-service/src/main/resources/application.yml b/samples/storage-explorer/date-service/src/main/resources/application.yml new file mode 100644 index 0000000..e2977af --- /dev/null +++ b/samples/storage-explorer/date-service/src/main/resources/application.yml @@ -0,0 +1,9 @@ +spring: + application: + name: date-service-spring +eureka: + client: + serviceUrl: + defaultZone: ${services__eureka__https__0}/eureka/ + instance: + preferIpAddress: true \ No newline at end of file diff --git a/samples/storage-explorer/storage-explorer-apphost/src/main/java/com/microsoft/aspire/storageexplorer/StorageExplorerAppHost.java b/samples/storage-explorer/storage-explorer-apphost/src/main/java/com/microsoft/aspire/storageexplorer/StorageExplorerAppHost.java index a2f85f1..5df53e4 100644 --- a/samples/storage-explorer/storage-explorer-apphost/src/main/java/com/microsoft/aspire/storageexplorer/StorageExplorerAppHost.java +++ b/samples/storage-explorer/storage-explorer-apphost/src/main/java/com/microsoft/aspire/storageexplorer/StorageExplorerAppHost.java @@ -29,16 +29,16 @@ public class StorageExplorerAppHost implements AppHost { .addEurekaServiceDiscovery("eureka"); var dateService = app.withExtension(SpringExtension.class) - .addSpringProject("date-service-spring") - .withPath("date-service") - .withExternalHttpEndpoints(); + .addSpringProject("date-service-spring") + .withPath("date-service") + .withReference(eurekaServiceDiscovery) + .withExternalHttpEndpoints(); var storageExplorer = app.withExtension(SpringExtension.class) .addSpringProject("storage-explorer-spring") .withPath("storage-explorer") .withExternalHttpEndpoints() .withReference(blobStorage) - .withReference(dateService) .withReference(eurekaServiceDiscovery); // .withReference(openAI); diff --git a/samples/storage-explorer/storage-explorer/pom.xml b/samples/storage-explorer/storage-explorer/pom.xml index 1fe1043..81129a1 100644 --- a/samples/storage-explorer/storage-explorer/pom.xml +++ b/samples/storage-explorer/storage-explorer/pom.xml @@ -28,6 +28,7 @@ 21 + 2023.0.2 @@ -39,6 +40,13 @@ pom import + + org.springframework.cloud + spring-cloud-dependencies + ${spring-cloud.version} + pom + import + @@ -77,6 +85,11 @@ org.springframework.boot spring-boot-starter + + + org.springframework.cloud + spring-cloud-starter-netflix-eureka-client + org.springframework.boot spring-boot-docker-compose diff --git a/samples/storage-explorer/storage-explorer/src/main/java/com/microsoft/aspire/storageexplorer/StorageServiceController.java b/samples/storage-explorer/storage-explorer/src/main/java/com/microsoft/aspire/storageexplorer/StorageServiceController.java index bc1e106..fadf752 100644 --- a/samples/storage-explorer/storage-explorer/src/main/java/com/microsoft/aspire/storageexplorer/StorageServiceController.java +++ b/samples/storage-explorer/storage-explorer/src/main/java/com/microsoft/aspire/storageexplorer/StorageServiceController.java @@ -2,6 +2,7 @@ import com.microsoft.aspire.storageexplorer.service.StorageItem; import com.microsoft.aspire.storageexplorer.service.StorageService; +import com.netflix.discovery.EurekaClient; import jakarta.servlet.http.HttpServletResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -32,13 +33,13 @@ public class StorageServiceController { private static final Logger LOGGER = LoggerFactory.getLogger(StorageServiceController.class); private final StorageService storageService; - - @Value("${services__dateservice__https__0}") - private String dateServiceEndpoint; + private final String dateServiceUrl; @Autowired - public StorageServiceController(final StorageService storageService) { + public StorageServiceController(final StorageService storageService, final EurekaClient discoveryClient) { this.storageService = storageService; + this.dateServiceUrl = discoveryClient.getNextServerFromEureka("date-service-spring", false).getHomePageUrl(); + LOGGER.info("The discovered date service URL is " + dateServiceUrl); } @GetMapping("/") @@ -51,12 +52,12 @@ public String listUploadedFiles(final Model model, } private void updateTime(Model model) { - LOGGER.info("The datetime service endpoint is " + dateServiceEndpoint); String lastUpdated = ""; try { RestTemplate restTemplate = new RestTemplate(); - OffsetDateTime time = restTemplate.getForObject(dateServiceEndpoint + "/time", OffsetDateTime.class); + OffsetDateTime time = restTemplate.getForObject(dateServiceUrl + "/time", OffsetDateTime.class); if (time != null) { + LOGGER.info("The date service time is " + time.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))); lastUpdated = time.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); } } catch (Exception exception) { diff --git a/samples/storage-explorer/storage-explorer/src/main/java/com/microsoft/aspire/storageexplorer/service/AzureBlobStorageService.java b/samples/storage-explorer/storage-explorer/src/main/java/com/microsoft/aspire/storageexplorer/service/AzureBlobStorageService.java index bc1e516..d7e7659 100644 --- a/samples/storage-explorer/storage-explorer/src/main/java/com/microsoft/aspire/storageexplorer/service/AzureBlobStorageService.java +++ b/samples/storage-explorer/storage-explorer/src/main/java/com/microsoft/aspire/storageexplorer/service/AzureBlobStorageService.java @@ -8,6 +8,8 @@ import com.azure.storage.blob.BlobServiceClient; import com.azure.storage.blob.BlobServiceClientBuilder; import com.azure.storage.blob.models.BlobHttpHeaders; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; @@ -21,15 +23,18 @@ */ @Service public class AzureBlobStorageService implements StorageService { + private static final Logger LOGGER = LoggerFactory.getLogger(AzureBlobStorageService.class); + private String blobStorageContainerName = "mycontainer"; - @Value("${ENDPOINT}") + @Value("${ConnectionStrings__storage-explorer-blobs}") private String storageEndpoint; private BlobContainerClient blobContainerClient; @Override public void init() { + LOGGER.info("Using Azure Blob Storage endpoint {}", storageEndpoint); if (blobContainerClient != null) { return; } @@ -37,7 +42,7 @@ public void init() { boolean doInit = true; if ((storageEndpoint == null || storageEndpoint.isEmpty())) { - System.err.println("Error: Please set the ENDPOINT property"); + System.err.println("Error: Please set the ConnectionStrings__storage-explorer-blobs property"); doInit = false; } @@ -64,7 +69,7 @@ public void store(final String filename, final InputStream inputStream, final lo final String mimeType = URLConnection.guessContentTypeFromName(filename); blobClient.setHttpHeaders(new BlobHttpHeaders() - .setContentType(mimeType)); + .setContentType(mimeType)); } @Override diff --git a/samples/storage-explorer/storage-explorer/src/main/resources/application.yml b/samples/storage-explorer/storage-explorer/src/main/resources/application.yml new file mode 100644 index 0000000..b97be26 --- /dev/null +++ b/samples/storage-explorer/storage-explorer/src/main/resources/application.yml @@ -0,0 +1,9 @@ +spring: + application: + name: storage-explorer-spring +eureka: + client: + serviceUrl: + defaultZone: ${services__eureka__https__0}/eureka/ + instance: + preferIpAddress: true \ No newline at end of file