-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add more support for Azure Blob Store
Azure Blob Store support for Task Logs and a firehose for data ingestion
- Loading branch information
1 parent
3ce32f9
commit 0bda7af
Showing
12 changed files
with
555 additions
and
12 deletions.
There are no files selected for viewing
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
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
49 changes: 49 additions & 0 deletions
49
extensions/azure-extensions/src/main/java/io/druid/firehose/azure/AzureBlob.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,49 @@ | ||
/* | ||
* Druid - a distributed column store. | ||
* Copyright 2012 - 2015 Metamarkets Group Inc. | ||
* | ||
* Licensed 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.azure; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
import javax.validation.constraints.NotNull; | ||
|
||
|
||
public class AzureBlob { | ||
@JsonProperty | ||
@NotNull | ||
private String container = null; | ||
|
||
@JsonProperty | ||
@NotNull | ||
private String path = null; | ||
|
||
public AzureBlob() { | ||
} | ||
|
||
public AzureBlob(String container, String path) { | ||
this.container = container; | ||
this.path = path; | ||
} | ||
|
||
public String getContainer() { | ||
return container; | ||
} | ||
|
||
public String getPath() { | ||
return path; | ||
} | ||
} |
124 changes: 124 additions & 0 deletions
124
...extensions/src/main/java/io/druid/firehose/azure/StaticAzureBlobStoreFirehoseFactory.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,124 @@ | ||
/* | ||
* Druid - a distributed column store. | ||
* Copyright 2012 - 2015 Metamarkets Group Inc. | ||
* | ||
* Licensed 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.azure; | ||
|
||
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 com.metamx.common.CompressionUtils; | ||
import com.metamx.common.logger.Logger; | ||
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.storage.azure.AzureByteSource; | ||
import io.druid.storage.azure.AzureStorage; | ||
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; | ||
|
||
/** | ||
* This class is heavily inspired by the StaticS3FirehoseFactory class in the io.druid.firehose.s3 package | ||
*/ | ||
public class StaticAzureBlobStoreFirehoseFactory implements FirehoseFactory<StringInputRowParser> { | ||
private static final Logger log = new Logger(StaticAzureBlobStoreFirehoseFactory.class); | ||
|
||
private final AzureStorage azureStorage; | ||
private final List<AzureBlob> blobs; | ||
|
||
@JsonCreator | ||
public StaticAzureBlobStoreFirehoseFactory( | ||
@JacksonInject("azureStorage") AzureStorage azureStorage, | ||
@JsonProperty("blobs") AzureBlob[] blobs | ||
) { | ||
this.azureStorage = azureStorage; | ||
this.blobs = ImmutableList.copyOf(blobs); | ||
} | ||
|
||
@JsonProperty | ||
public List<AzureBlob> getBlobs() { | ||
return blobs; | ||
} | ||
|
||
@Override | ||
public Firehose connect(StringInputRowParser stringInputRowParser) throws IOException { | ||
Preconditions.checkNotNull(azureStorage, "null azureStorage"); | ||
|
||
final LinkedList<AzureBlob> objectQueue = Lists.newLinkedList(blobs); | ||
|
||
return new FileIteratingFirehose( | ||
new Iterator<LineIterator>() { | ||
@Override | ||
public boolean hasNext() { | ||
return !objectQueue.isEmpty(); | ||
} | ||
|
||
@Override | ||
public LineIterator next() { | ||
final AzureBlob nextURI = objectQueue.poll(); | ||
|
||
final String container = nextURI.getContainer(); | ||
final String path = nextURI.getPath().startsWith("/") | ||
? nextURI.getPath().substring(1) | ||
: nextURI.getPath(); | ||
|
||
try { | ||
final InputStream innerInputStream = new AzureByteSource(azureStorage, container, 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 container[%s] blob[%s]", | ||
container, | ||
path | ||
); | ||
|
||
throw Throwables.propagate(e); | ||
} | ||
} | ||
|
||
@Override | ||
public void remove() { | ||
throw new UnsupportedOperationException(); | ||
} | ||
}, | ||
stringInputRowParser | ||
); | ||
} | ||
} |
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
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
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
Oops, something went wrong.