Skip to content

Commit

Permalink
Add Google Storage as a storage backend
Browse files Browse the repository at this point in the history
This works with a Google Storage project configured with S3
interoperability.

Signed-off-by: Andy Doan <andy@foundries.io>
  • Loading branch information
doanac committed Apr 4, 2019
1 parent 7d831f4 commit b6917a9
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/main/resources/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ server = {

treehub {
storage {
type = "s3" // or local
type = "s3" // or local or gs
type = ${?TREEHUB_STORAGE}

staleObjectsExpireAfter = 1 hour
Expand Down
10 changes: 8 additions & 2 deletions src/main/scala/com/advancedtelematic/treehub/Boot.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import com.advancedtelematic.libats.slick.db.{BootMigrations, DatabaseConfig}
import com.advancedtelematic.libats.slick.monitoring.DatabaseMetrics
import com.advancedtelematic.treehub.client._
import com.advancedtelematic.treehub.http.{TreeHubRoutes, Http => TreeHubHttp}
import com.advancedtelematic.treehub.object_store.{LocalFsBlobStore, ObjectStore, S3BlobStore, S3Credentials}
import com.advancedtelematic.treehub.object_store.{GSBlobStore, LocalFsBlobStore, ObjectStore, S3BlobStore, S3Credentials}
import com.advancedtelematic.treehub.repo_metrics.UsageMetricsRouter
import com.amazonaws.regions.Regions
import com.typesafe.config.ConfigFactory
Expand All @@ -22,7 +22,7 @@ import com.advancedtelematic.libats.http.monitoring.MetricsSupport
import com.advancedtelematic.metrics.{AkkaHttpRequestMetrics, InfluxdbMetricsReporterSupport}
import com.advancedtelematic.metrics.prometheus.PrometheusMetricsSupport
import com.advancedtelematic.treehub.daemon.StaleObjectArchiveActor
import com.advancedtelematic.treehub.delta_store.{LocalDeltaStorage, S3DeltaStorage}
import com.advancedtelematic.treehub.delta_store.{GSDeltaStorage, LocalDeltaStorage, S3DeltaStorage}


object Boot extends BootApp with Directives with Settings with VersionInfo
Expand All @@ -48,6 +48,9 @@ object Boot extends BootApp with Directives with Settings with VersionInfo
if(useS3) {
log.info("Using s3 storage for object blobs")
new S3BlobStore(s3Credentials, allowRedirectsToS3)
} else if (useGoogleStorage) {
log.info("Using GS storage for object blobs")
new GSBlobStore(s3Credentials, allowRedirectsToS3)
} else {
log.info(s"Using local storage a t$localStorePath for object blobs")
LocalFsBlobStore(localStorePath.resolve("object-storage"))
Expand All @@ -58,6 +61,9 @@ object Boot extends BootApp with Directives with Settings with VersionInfo
if(useS3) {
log.info("Using s3 storage for object blobs")
new S3DeltaStorage(s3Credentials)
} else if (useGoogleStorage) {
log.info("Using GS storage for object blobs")
new GSDeltaStorage(s3Credentials)
} else {
log.info(s"Using local storage at $localStorePath for object blobs")
new LocalDeltaStorage(localStorePath.resolve("delta-storage"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ trait Settings {
}

lazy val useS3 = _config.getString("treehub.storage.type").equals("s3")
lazy val useGoogleStorage = _config.getString("treehub.storage.type").equals("gs")

lazy val staleObjectExpireAfter = _config.getDuration("treehub.storage.staleObjectsExpireAfter")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import com.advancedtelematic.libats.data.DataType.Namespace
import com.advancedtelematic.treehub.delta_store.StaticDeltaStorage.{StaticDeltaContent, StaticDeltaRedirectResponse, StaticDeltaResponse}
import com.advancedtelematic.treehub.http.Errors
import com.advancedtelematic.treehub.object_store.S3Credentials
import com.amazonaws.client.builder.AwsClientBuilder
import com.amazonaws.services.s3.AmazonS3ClientBuilder
import org.apache.commons.codec.binary.Hex
import org.apache.commons.codec.digest.DigestUtils
Expand Down Expand Up @@ -51,7 +52,7 @@ object StaticDeltaStorage {
class S3DeltaStorage(s3Credentials: S3Credentials)(implicit ec: ExecutionContext) extends StaticDeltaStorage {
private val _log = LoggerFactory.getLogger(this.getClass)

private lazy val s3client = AmazonS3ClientBuilder.standard()
protected lazy val s3client = AmazonS3ClientBuilder.standard()
.withCredentials(s3Credentials)
.withRegion(s3Credentials.region)
.build()
Expand Down Expand Up @@ -111,6 +112,13 @@ class S3DeltaStorage(s3Credentials: S3Credentials)(implicit ec: ExecutionContext
}
}

class GSDeltaStorage(s3Credentials: S3Credentials)(implicit ec: ExecutionContext) extends S3DeltaStorage(s3Credentials) {
override lazy val s3client = AmazonS3ClientBuilder.standard()
.withCredentials(s3Credentials)
.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration("https://storage.googleapis.com", "Multi-Regional"))
.build()
}

class LocalDeltaStorage(root: Path) extends StaticDeltaStorage {
private val _log = LoggerFactory.getLogger(this.getClass)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import com.advancedtelematic.libats.data.DataType.Namespace
import com.advancedtelematic.treehub.object_store.BlobStore.UploadAt
import com.amazonaws.HttpMethod
import com.amazonaws.auth.{AWSCredentials, AWSCredentialsProvider}
import com.amazonaws.client.builder.AwsClientBuilder
import com.amazonaws.regions.Regions
import com.amazonaws.services.s3.AmazonS3ClientBuilder
import com.amazonaws.services.s3.model._
Expand All @@ -32,7 +33,7 @@ class S3BlobStore(s3Credentials: S3Credentials, allowRedirects: Boolean)

private val bucketId = s3Credentials.blobBucketId

private lazy val s3client = AmazonS3ClientBuilder.standard()
protected lazy val s3client = AmazonS3ClientBuilder.standard()
.withCredentials(s3Credentials)
.withRegion(s3Credentials.region)
.build()
Expand Down Expand Up @@ -144,6 +145,14 @@ class S3BlobStore(s3Credentials: S3Credentials, allowRedirects: Boolean)
override val supportsOutOfBandStorage: Boolean = true
}

class GSBlobStore(s3Credentials: S3Credentials, allowRedirects: Boolean)
(implicit ec: ExecutionContext, mat: Materializer) extends S3BlobStore(s3Credentials, allowRedirects) {
override lazy val s3client = AmazonS3ClientBuilder.standard()
.withCredentials(s3Credentials)
.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration("https://storage.googleapis.com", "Multi-Regional"))
.build()
}

class S3Credentials(accessKey: String, secretKey: String,
val blobBucketId: String,
val deltasBucketId: String,
Expand Down

0 comments on commit b6917a9

Please sign in to comment.