Search in sources :

Example 51 with ComponentException

use of org.talend.components.api.exception.ComponentException in project components by Talend.

the class AzureStorageGetRuntime method download.

private void download(RuntimeContainer runtimeContainer) {
    FileOutputStream fos = null;
    try {
        List<RemoteBlobGet> remoteBlobs = createRemoteBlobsGet();
        for (RemoteBlobGet rmtb : remoteBlobs) {
            for (ListBlobItem blob : azureStorageBlobService.listBlobs(containerName, rmtb.prefix, rmtb.include)) {
                if (blob instanceof CloudBlob) {
                    // TODO - Action when create is false and include is true ???
                    if (rmtb.create) {
                        new File(localFolder + "/" + ((CloudBlob) blob).getName()).getParentFile().mkdirs();
                    }
                    fos = new FileOutputStream(localFolder + "/" + ((CloudBlob) blob).getName());
                    azureStorageBlobService.download((CloudBlob) blob, fos);
                }
            }
        }
    } catch (StorageException | URISyntaxException | FileNotFoundException | InvalidKeyException e) {
        LOGGER.error(e.getLocalizedMessage());
        if (dieOnError) {
            throw new ComponentException(e);
        }
    } finally {
        try {
            fos.close();
        } catch (Exception e) {
        // ignore
        }
    }
}
Also used : ListBlobItem(com.microsoft.azure.storage.blob.ListBlobItem) FileNotFoundException(java.io.FileNotFoundException) URISyntaxException(java.net.URISyntaxException) InvalidKeyException(java.security.InvalidKeyException) URISyntaxException(java.net.URISyntaxException) StorageException(com.microsoft.azure.storage.StorageException) ComponentException(org.talend.components.api.exception.ComponentException) FileNotFoundException(java.io.FileNotFoundException) InvalidKeyException(java.security.InvalidKeyException) CloudBlob(com.microsoft.azure.storage.blob.CloudBlob) FileOutputStream(java.io.FileOutputStream) ComponentException(org.talend.components.api.exception.ComponentException) RemoteBlobGet(org.talend.components.azurestorage.blob.helpers.RemoteBlobGet) File(java.io.File) StorageException(com.microsoft.azure.storage.StorageException)

Example 52 with ComponentException

use of org.talend.components.api.exception.ComponentException in project components by Talend.

the class AzureStorageQueueCreateRuntime method createAzureQueue.

private boolean createAzureQueue(RuntimeContainer container) {
    Boolean createResult = false;
    try {
        LOGGER.debug(messages.getMessage("debug.QueuePrecreate", queueName));
        createResult = queueService.createQueueIfNotExists(queueName);
        if (!createResult) {
            LOGGER.warn(messages.getMessage("warn.QueueExist", queueName));
        }
    } catch (InvalidKeyException | URISyntaxException | StorageException e) {
        LOGGER.error(e.getLocalizedMessage());
        if (dieOnError) {
            throw new ComponentException(e);
        }
    }
    return createResult;
}
Also used : ComponentException(org.talend.components.api.exception.ComponentException) URISyntaxException(java.net.URISyntaxException) InvalidKeyException(java.security.InvalidKeyException) StorageException(com.microsoft.azure.storage.StorageException)

Example 53 with ComponentException

use of org.talend.components.api.exception.ComponentException in project components by Talend.

the class AzureStorageQueueListReader method start.

@Override
public boolean start() throws IOException {
    try {
        queues = queueService.listQueues().iterator();
        startable = queues.hasNext();
        if (startable) {
            current = queues.next();
            dataCount++;
        }
    } catch (InvalidKeyException | URISyntaxException e) {
        LOGGER.error(e.getLocalizedMessage());
        if (dieOnError) {
            throw new ComponentException(e);
        }
    }
    return startable;
}
Also used : ComponentException(org.talend.components.api.exception.ComponentException) URISyntaxException(java.net.URISyntaxException) InvalidKeyException(java.security.InvalidKeyException)

Example 54 with ComponentException

use of org.talend.components.api.exception.ComponentException in project components by Talend.

the class AzureStorageQueuePurgeRuntime method purgeAzureQueue.

private boolean purgeAzureQueue(RuntimeContainer container) {
    Boolean purgeResult = false;
    try {
        int dataCount = (int) queueService.getApproximateMessageCount(queueName);
        LOGGER.debug(messages.getMessage("debug.Purgeing", dataCount, queueName));
        queueService.clear(queueName);
        purgeResult = true;
    } catch (InvalidKeyException | URISyntaxException | StorageException e) {
        LOGGER.error(e.getLocalizedMessage());
        if (dieOnError) {
            throw new ComponentException(e);
        }
    }
    return purgeResult;
}
Also used : ComponentException(org.talend.components.api.exception.ComponentException) URISyntaxException(java.net.URISyntaxException) InvalidKeyException(java.security.InvalidKeyException) StorageException(com.microsoft.azure.storage.StorageException)

Example 55 with ComponentException

use of org.talend.components.api.exception.ComponentException in project components by Talend.

the class BigQueryDatasetProperties method beforeBqDataset.

public ValidationResult beforeBqDataset() {
    BigQueryDatasetDefinition definition = new BigQueryDatasetDefinition();
    RuntimeInfo runtimeInfo = definition.getRuntimeInfo(this);
    try (SandboxedInstance sandboxedInstance = RuntimeUtil.createRuntimeClass(runtimeInfo, getClass().getClassLoader())) {
        IBigQueryDatasetRuntime runtime = (IBigQueryDatasetRuntime) sandboxedInstance.getInstance();
        runtime.initialize(null, this);
        List<NamedThing> datasets = new ArrayList<>();
        for (String dataset : runtime.listDatasets()) {
            datasets.add(new SimpleNamedThing(dataset, dataset));
        }
        bqDataset.setPossibleValues(datasets);
        return ValidationResult.OK;
    } catch (Exception e) {
        return new ValidationResult(new ComponentException(e));
    }
}
Also used : SandboxedInstance(org.talend.daikon.sandbox.SandboxedInstance) IBigQueryDatasetRuntime(org.talend.components.bigquery.runtime.IBigQueryDatasetRuntime) RuntimeInfo(org.talend.daikon.runtime.RuntimeInfo) SimpleNamedThing(org.talend.daikon.SimpleNamedThing) ArrayList(java.util.ArrayList) ComponentException(org.talend.components.api.exception.ComponentException) NamedThing(org.talend.daikon.NamedThing) SimpleNamedThing(org.talend.daikon.SimpleNamedThing) ValidationResult(org.talend.daikon.properties.ValidationResult) ComponentException(org.talend.components.api.exception.ComponentException) TalendRuntimeException(org.talend.daikon.exception.TalendRuntimeException)

Aggregations

ComponentException (org.talend.components.api.exception.ComponentException)101 URL (java.net.URL)32 MalformedURLException (java.net.MalformedURLException)30 JarRuntimeInfo (org.talend.components.api.component.runtime.JarRuntimeInfo)27 IOException (java.io.IOException)18 ArrayList (java.util.ArrayList)17 InvalidKeyException (java.security.InvalidKeyException)14 Schema (org.apache.avro.Schema)14 URISyntaxException (java.net.URISyntaxException)12 StorageException (com.microsoft.azure.storage.StorageException)11 NamedThing (org.talend.daikon.NamedThing)11 ValidationResult (org.talend.daikon.properties.ValidationResult)10 SandboxedInstance (org.talend.daikon.sandbox.SandboxedInstance)10 IndexedRecord (org.apache.avro.generic.IndexedRecord)8 Test (org.junit.Test)8 SimpleNamedThing (org.talend.daikon.SimpleNamedThing)8 NetSuiteException (org.talend.components.netsuite.client.NetSuiteException)6 GeneralSecurityException (java.security.GeneralSecurityException)5 JDBCSource (org.talend.components.jdbc.runtime.JDBCSource)5 TJDBCInputDefinition (org.talend.components.jdbc.tjdbcinput.TJDBCInputDefinition)5