Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pavel pubdev 5688 gcs env check master (#2609)
* PUBDEV-5688- GCS started in unauthorized regime when there is no connection available. (cherry picked from commit b481e14) * GCS Storage instance lazily initialized in PersistGcs class (cherry picked from commit df771bc) * GCS Storage lazy initialization moved to a provider class (cherry picked from commit eea73ba)
- Loading branch information
Pavel Pscheidl
committed
Jul 7, 2018
1 parent
cca6c1a
commit 7c1124c
Showing
2 changed files
with
51 additions
and
20 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
h2o-persist-gcs/src/main/java/water/persist/GcsStorageProvider.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,28 @@ | ||
package water.persist; | ||
|
||
import com.google.cloud.storage.Storage; | ||
import com.google.cloud.storage.StorageOptions; | ||
|
||
/** | ||
* A class wrapping {@link Storage}, enabling safe lazy initialization by only providing getStorage method, not risking for | ||
* developers to access storage field directly. | ||
*/ | ||
final class GcsStorageProvider { | ||
|
||
private Storage storage; | ||
|
||
/** | ||
* Returns an existing instance of {@link Storage} or creates a new one, if not initialized. | ||
* Lazy-initialization of storage does not slow down startup of H2O (attempts are made to connect to GCS). | ||
* The connection status and {@link com.google.auth.Credentials} are checked at actual request-time. | ||
* | ||
* @return An instance of {@link Storage}, if initialized | ||
*/ | ||
protected Storage getStorage() { | ||
if (storage == null) { | ||
storage = StorageOptions.getDefaultInstance().getService(); | ||
} | ||
|
||
return storage; | ||
} | ||
} |
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