-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Add Google Storage support #2458
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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,55 @@ | ||
| --- | ||
| layout: doc_page | ||
| --- | ||
|
|
||
| # Google Cloud Storage | ||
|
|
||
| To use this extension, make sure to [include](../../operations/including-extensions.html) `druid-google-extensions` extension. | ||
|
|
||
| ## Deep Storage | ||
|
|
||
| [Google Cloud Storage](https://cloud.google.com/storage/) is another option for deep storage. This requires some additional druid configuration. | ||
|
|
||
| |Property|Description|Default|Required?| | ||
| |--------|-----------|-------|---------| | ||
| |bucket|Name of the Google Cloud bucket|N/A|yes| | ||
| |path|The path where data is located.|N/A|yes| | ||
|
|
||
| ## Firehose | ||
|
|
||
| #### StaticGoogleBlobStoreFirehose | ||
|
|
||
| This firehose ingests events, similar to the StaticS3Firehose, but from an Google Cloud Store. | ||
|
|
||
| As with the S3 blobstore, it is assumed to be gzipped if the extension ends in .gz | ||
|
|
||
| Sample spec: | ||
|
|
||
| ```json | ||
| "firehose" : { | ||
| "type" : "static-google-blobstore", | ||
| "blobs": [ | ||
| { | ||
| "bucket": "foo", | ||
| "path": "/path/to/your/file.json" | ||
| }, | ||
| { | ||
| "container": "bar", | ||
| "path": "/another/path.json" | ||
| } | ||
| ] | ||
| } | ||
| ``` | ||
|
|
||
| |property|description|default|required?| | ||
| |--------|-----------|-------|---------| | ||
| |type|This should be "static-google-blobstore".|N/A|yes| | ||
| |blobs|JSON array of Google Blobs.|N/A|yes| | ||
|
|
||
| Google Blobs: | ||
|
|
||
| |property|description|default|required?| | ||
| |--------|-----------|-------|---------| | ||
| |bucket|Name of the Google Cloud bucket|N/A|yes| | ||
| |path|The path where data is located.|N/A|yes| | ||
|
|
||
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,73 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <!-- | ||
| ~ Licensed to Metamarkets Group Inc. (Metamarkets) under one | ||
| ~ or more contributor license agreements. See the NOTICE file | ||
| ~ distributed with this work for additional information | ||
| ~ regarding copyright ownership. Metamarkets licenses this file | ||
| ~ to you under the Apache License, Version 2.0 (the | ||
| ~ "License"); you may not use this file except in compliance | ||
| ~ with the License. You may obtain a copy of the License at | ||
| ~ | ||
| ~ http://www.apache.org/licenses/LICENSE-2.0 | ||
| ~ | ||
| ~ Unless required by applicable law or agreed to in writing, | ||
| ~ software distributed under the License is distributed on an | ||
| ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| ~ KIND, either express or implied. See the License for the | ||
| ~ specific language governing permissions and limitations | ||
| ~ under the License. | ||
| --> | ||
|
|
||
| <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
| <modelVersion>4.0.0</modelVersion> | ||
|
|
||
| <groupId>io.druid.extensions.contrib</groupId> | ||
| <artifactId>druid-google-extensions</artifactId> | ||
| <name>druid-google-extensions</name> | ||
| <description>druid-google-extensions</description> | ||
|
|
||
| <parent> | ||
| <groupId>io.druid</groupId> | ||
| <artifactId>druid</artifactId> | ||
| <version>0.9.3-SNAPSHOT</version> | ||
| <relativePath>../../pom.xml</relativePath> | ||
| </parent> | ||
|
|
||
| <dependencies> | ||
| <dependency> | ||
| <groupId>io.druid</groupId> | ||
| <artifactId>druid-api</artifactId> | ||
| <version>${project.parent.version}</version> | ||
| <scope>provided</scope> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>com.google.apis</groupId> | ||
| <artifactId>google-api-services-storage</artifactId> | ||
| <version>v1-rev79-1.22.0</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>com.google.http-client</groupId> | ||
| <artifactId>google-http-client-jackson2</artifactId> | ||
| <version>1.22.0</version> | ||
| </dependency> | ||
|
|
||
| <!-- Tests --> | ||
| <dependency> | ||
| <groupId>junit</groupId> | ||
| <artifactId>junit</artifactId> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>io.druid</groupId> | ||
| <artifactId>druid-server</artifactId> | ||
| <version>${project.parent.version}</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.easymock</groupId> | ||
| <artifactId>easymock</artifactId> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| </dependencies> | ||
| </project> |
45 changes: 45 additions & 0 deletions
45
extensions-contrib/google-extensions/src/main/java/io/druid/firehose/google/GoogleBlob.java
This file contains hidden or 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,45 @@ | ||
| /* | ||
| * Licensed to Metamarkets Group Inc. (Metamarkets) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. Metamarkets licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package io.druid.firehose.google; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonCreator; | ||
| import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
|
||
| public class GoogleBlob { | ||
| private final String bucket; | ||
| private final String path; | ||
|
|
||
| @JsonCreator | ||
| public GoogleBlob(@JsonProperty("bucket") String bucket, @JsonProperty("path") String path) { | ||
| this.bucket = bucket; | ||
| this.path = path; | ||
| } | ||
|
|
||
| @JsonProperty | ||
| public String getBucket() { | ||
| return bucket; | ||
| } | ||
|
|
||
| @JsonProperty | ||
| public String getPath() { | ||
| return path; | ||
| } | ||
| } | ||
|
|
123 changes: 123 additions & 0 deletions
123
...tensions/src/main/java/io/druid/firehose/google/StaticGoogleBlobStoreFirehoseFactory.java
This file contains hidden or 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,123 @@ | ||
| /* | ||
| * Licensed to Metamarkets Group Inc. (Metamarkets) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. Metamarkets licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package io.druid.firehose.google; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JacksonInject; | ||
| import com.fasterxml.jackson.annotation.JsonCreator; | ||
| import com.fasterxml.jackson.annotation.JsonProperty; | ||
| import com.google.common.base.Charsets; | ||
| import com.google.common.base.Preconditions; | ||
| import com.google.common.base.Throwables; | ||
| import com.google.common.collect.ImmutableList; | ||
| import com.google.common.collect.Lists; | ||
| import io.druid.data.input.Firehose; | ||
| import io.druid.data.input.FirehoseFactory; | ||
| import io.druid.data.input.impl.FileIteratingFirehose; | ||
| import io.druid.data.input.impl.StringInputRowParser; | ||
| import io.druid.java.util.common.CompressionUtils; | ||
| import io.druid.java.util.common.logger.Logger; | ||
| import io.druid.storage.google.GoogleByteSource; | ||
| import io.druid.storage.google.GoogleStorage; | ||
| import org.apache.commons.io.IOUtils; | ||
| import org.apache.commons.io.LineIterator; | ||
|
|
||
| import java.io.BufferedReader; | ||
| import java.io.IOException; | ||
| import java.io.InputStream; | ||
| import java.io.InputStreamReader; | ||
| import java.util.Iterator; | ||
| import java.util.LinkedList; | ||
| import java.util.List; | ||
|
|
||
| public class StaticGoogleBlobStoreFirehoseFactory implements FirehoseFactory<StringInputRowParser> { | ||
| private static final Logger LOG = new Logger(StaticGoogleBlobStoreFirehoseFactory.class); | ||
|
|
||
| private final GoogleStorage storage; | ||
| private final List<GoogleBlob> blobs; | ||
|
|
||
| @JsonCreator | ||
| public StaticGoogleBlobStoreFirehoseFactory( | ||
| @JacksonInject GoogleStorage storage, | ||
| @JsonProperty("blobs") GoogleBlob[] blobs | ||
| ) { | ||
| this.storage = storage; | ||
| this.blobs = ImmutableList.copyOf(blobs); | ||
| } | ||
|
|
||
| @JsonProperty | ||
| public List<GoogleBlob> getBlobs() { | ||
| return blobs; | ||
| } | ||
|
|
||
| @Override | ||
| public Firehose connect(StringInputRowParser stringInputRowParser) throws IOException { | ||
| Preconditions.checkNotNull(storage, "null storage"); | ||
|
|
||
| final LinkedList<GoogleBlob> objectQueue = Lists.newLinkedList(blobs); | ||
|
|
||
| return new FileIteratingFirehose( | ||
| new Iterator<LineIterator>() { | ||
| @Override | ||
| public boolean hasNext() { | ||
| return !objectQueue.isEmpty(); | ||
| } | ||
|
|
||
| @Override | ||
| public LineIterator next() { | ||
| final GoogleBlob nextURI = objectQueue.poll(); | ||
|
|
||
| final String bucket = nextURI.getBucket(); | ||
| final String path = nextURI.getPath().startsWith("/") | ||
| ? nextURI.getPath().substring(1) | ||
| : nextURI.getPath(); | ||
|
|
||
| try { | ||
| final InputStream innerInputStream = new GoogleByteSource(storage, bucket, path).openStream(); | ||
|
|
||
| final InputStream outerInputStream = path.endsWith(".gz") | ||
| ? CompressionUtils.gzipInputStream(innerInputStream) | ||
| : innerInputStream; | ||
|
|
||
| return IOUtils.lineIterator( | ||
| new BufferedReader( | ||
| new InputStreamReader(outerInputStream, Charsets.UTF_8) | ||
| ) | ||
| ); | ||
| } catch (Exception e) { | ||
| LOG.error(e, | ||
| "Exception opening bucket[%s] blob[%s]", | ||
| bucket, | ||
| path | ||
| ); | ||
|
|
||
| throw Throwables.propagate(e); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void remove() { | ||
| throw new UnsupportedOperationException(); | ||
| } | ||
| }, | ||
| stringInputRowParser | ||
| ); | ||
| } | ||
| } | ||
|
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The correct property is
prefixinstead ofpath.https://github.com/druid-io/druid/blob/7d36f540e809198206238c93f253ce54e4deed03/extensions-contrib/google-extensions/src/main/java/io/druid/storage/google/GoogleAccountConfig.java#L33
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right. I'll make a pull request to fix this.