Search in sources :

Example 1 with RemoteBlob

use of org.talend.components.azurestorage.blob.helpers.RemoteBlob in project components by Talend.

the class RemoteBlobTest method setUp.

@Before
public void setUp() throws Exception {
    remoteBlob = new RemoteBlob("", true);
    remoteBlobGet = new RemoteBlobGet("", true, true);
    remoteBlobGet2 = new RemoteBlobGet("", true);
}
Also used : RemoteBlob(org.talend.components.azurestorage.blob.helpers.RemoteBlob) RemoteBlobGet(org.talend.components.azurestorage.blob.helpers.RemoteBlobGet) Before(org.junit.Before)

Example 2 with RemoteBlob

use of org.talend.components.azurestorage.blob.helpers.RemoteBlob in project components by Talend.

the class AzureStorageSource method getRemoteBlobs.

public List<RemoteBlob> getRemoteBlobs() {
    List<RemoteBlob> remoteBlobs = new ArrayList<RemoteBlob>();
    if (!(this.properties instanceof AzureStorageBlobProperties))
        return null;
    AzureStorageBlobProperties p = (AzureStorageBlobProperties) properties;
    ValidationResult vr = p.remoteBlobs.getValidationResult();
    if (vr.getStatus().equals(Result.ERROR)) {
        throw new IllegalArgumentException(vr.getMessage());
    }
    for (int idx = 0; idx < p.remoteBlobs.prefix.getValue().size(); idx++) {
        String prefix = (p.remoteBlobs.prefix.getValue().get(idx) != null) ? p.remoteBlobs.prefix.getValue().get(idx) : "";
        Boolean include = (p.remoteBlobs.include.getValue().get(idx) != null) ? p.remoteBlobs.include.getValue().get(idx) : false;
        remoteBlobs.add(new RemoteBlob(prefix, include));
    }
    return remoteBlobs;
}
Also used : AzureStorageBlobProperties(org.talend.components.azurestorage.blob.AzureStorageBlobProperties) ArrayList(java.util.ArrayList) RemoteBlob(org.talend.components.azurestorage.blob.helpers.RemoteBlob) ValidationResult(org.talend.daikon.properties.ValidationResult)

Example 3 with RemoteBlob

use of org.talend.components.azurestorage.blob.helpers.RemoteBlob in project components by Talend.

the class AzureStorageListReader method start.

@Override
public boolean start() throws IOException {
    String mycontainer = properties.container.getValue();
    List<CloudBlob> blobs = new ArrayList<>();
    // build a list with remote blobs to fetch
    List<RemoteBlob> remoteBlobs = ((AzureStorageSource) getCurrentSource()).getRemoteBlobs();
    try {
        for (RemoteBlob rmtb : remoteBlobs) {
            for (ListBlobItem blob : azureStorageBlobService.listBlobs(mycontainer, rmtb.prefix, rmtb.include)) {
                if (blob instanceof CloudBlob) {
                    blobs.add((CloudBlob) blob);
                }
            }
        }
        startable = !blobs.isEmpty();
        blobsIterator = blobs.iterator();
    } catch (StorageException | URISyntaxException | InvalidKeyException e) {
        LOGGER.error(e.getLocalizedMessage());
        if (properties.dieOnError.getValue()) {
            throw new ComponentException(e);
        }
    }
    if (startable) {
        dataCount++;
        currentBlob = blobsIterator.next();
        IndexedRecord dataRecord = new GenericData.Record(properties.schema.schema.getValue());
        dataRecord.put(0, currentBlob.getName());
        Schema rootSchema = RootSchemaUtils.createRootSchema(properties.schema.schema.getValue(), properties.outOfBandSchema);
        currentRecord = new GenericData.Record(rootSchema);
        currentRecord.put(0, dataRecord);
        currentRecord.put(1, dataRecord);
    }
    return startable;
}
Also used : ListBlobItem(com.microsoft.azure.storage.blob.ListBlobItem) IndexedRecord(org.apache.avro.generic.IndexedRecord) Schema(org.apache.avro.Schema) ArrayList(java.util.ArrayList) URISyntaxException(java.net.URISyntaxException) InvalidKeyException(java.security.InvalidKeyException) GenericData(org.apache.avro.generic.GenericData) CloudBlob(com.microsoft.azure.storage.blob.CloudBlob) ComponentException(org.talend.components.api.exception.ComponentException) RemoteBlob(org.talend.components.azurestorage.blob.helpers.RemoteBlob) IndexedRecord(org.apache.avro.generic.IndexedRecord) StorageException(com.microsoft.azure.storage.StorageException)

Example 4 with RemoteBlob

use of org.talend.components.azurestorage.blob.helpers.RemoteBlob in project components by Talend.

the class AzureStorageDeleteRuntime method createRemoteBlobFilter.

/**
 * Create remote blob table used in filtering remote blob
 */
private List<RemoteBlob> createRemoteBlobFilter() {
    List<RemoteBlob> remoteBlobs = new ArrayList<RemoteBlob>();
    for (int idx = 0; idx < this.remoteBlobsTable.prefix.getValue().size(); idx++) {
        String prefix = "";
        boolean include = false;
        if (this.remoteBlobsTable.prefix.getValue().get(idx) != null) {
            prefix = this.remoteBlobsTable.prefix.getValue().get(idx);
        }
        if (remoteBlobsTable.include.getValue().get(idx) != null) {
            include = remoteBlobsTable.include.getValue().get(idx);
        }
        remoteBlobs.add(new RemoteBlob(prefix, include));
    }
    return remoteBlobs;
}
Also used : ArrayList(java.util.ArrayList) RemoteBlob(org.talend.components.azurestorage.blob.helpers.RemoteBlob)

Aggregations

RemoteBlob (org.talend.components.azurestorage.blob.helpers.RemoteBlob)4 ArrayList (java.util.ArrayList)3 StorageException (com.microsoft.azure.storage.StorageException)1 CloudBlob (com.microsoft.azure.storage.blob.CloudBlob)1 ListBlobItem (com.microsoft.azure.storage.blob.ListBlobItem)1 URISyntaxException (java.net.URISyntaxException)1 InvalidKeyException (java.security.InvalidKeyException)1 Schema (org.apache.avro.Schema)1 GenericData (org.apache.avro.generic.GenericData)1 IndexedRecord (org.apache.avro.generic.IndexedRecord)1 Before (org.junit.Before)1 ComponentException (org.talend.components.api.exception.ComponentException)1 AzureStorageBlobProperties (org.talend.components.azurestorage.blob.AzureStorageBlobProperties)1 RemoteBlobGet (org.talend.components.azurestorage.blob.helpers.RemoteBlobGet)1 ValidationResult (org.talend.daikon.properties.ValidationResult)1