From 9ec5f4169d570e5f215ed12da8ba02b8e9c80fbd Mon Sep 17 00:00:00 2001 From: Jim Grace Date: Thu, 10 Oct 2024 17:12:01 -0400 Subject: [PATCH] fix: Catch JCloud exceptions again [DHIS2-18212] --- .../org/hisp/dhis/jclouds/JCloudsStore.java | 33 +++++++++++++++---- 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/jclouds/JCloudsStore.java b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/jclouds/JCloudsStore.java index 5da1be4a9e83..09b82e7e524e 100644 --- a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/jclouds/JCloudsStore.java +++ b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/jclouds/JCloudsStore.java @@ -51,7 +51,9 @@ import org.jclouds.domain.LocationBuilder; import org.jclouds.domain.LocationScope; import org.jclouds.filesystem.reference.FilesystemConstants; +import org.jclouds.http.HttpResponseException; import org.jclouds.logging.slf4j.config.SLF4JLoggingModule; +import org.jclouds.rest.AuthorizationException; import org.jclouds.s3.reference.S3Constants; import org.springframework.stereotype.Component; @@ -149,13 +151,32 @@ private Properties configureOverrides(String provider, String endpoint) { @PostConstruct public void init() { Location location = createLocation(fileStoreConfig.provider, fileStoreConfig.location); - blobStoreContext.getBlobStore().createContainerInLocation(location, fileStoreConfig.container); - log.info( - "File store configured with provider: '{}', container: '{}' and location: '{}'.", - fileStoreConfig.provider, - fileStoreConfig.container, - fileStoreConfig.location); + try { + blobStoreContext + .getBlobStore() + .createContainerInLocation(location, fileStoreConfig.container); + + log.info( + "File store configured with provider: '{}', container: '{}' and location: '{}'.", + fileStoreConfig.provider, + fileStoreConfig.container, + fileStoreConfig.location); + } catch (HttpResponseException ex) { + log.error( + String.format( + "Could not configure file store with provider '%s' and container '%s'.\n" + + "File storage will not be available.", + fileStoreConfig.provider, fileStoreConfig.container), + ex); + } catch (AuthorizationException ex) { + log.error( + String.format( + "Could not authenticate with file store provider '%s' and container '%s'. " + + "File storage will not be available.", + fileStoreConfig.provider, fileStoreConfig.location), + ex); + } } @PreDestroy