use of org.talend.components.api.exception.ComponentException in project components by Talend.
the class AzureStoragePutRuntime method upload.
private void upload(RuntimeContainer runtimeContainer) {
AzureStorageUtils utils = new AzureStorageUtils();
List<Map<String, String>> list = new ArrayList<>();
// process files list
if (useFileList && files != null && files.size() > 0) {
for (int idx = 0; idx < files.fileMask.getValue().size(); idx++) {
String fileMask = files.fileMask.getValue().get(idx);
String newName = files.newName.getValue().get(idx);
Map<String, String> map = new HashMap<>();
map.put(fileMask, newName);
list.add(map);
}
}
Map<String, String> fileMap;
if (useFileList) {
fileMap = utils.genFileFilterList(list, localFolder, remoteFolder);
} else {
fileMap = utils.genAzureObjectList(new File(localFolder), remoteFolder);
}
for (Map.Entry<String, String> entry : fileMap.entrySet()) {
File source = new File(entry.getKey());
try (FileInputStream stream = new FileInputStream(source)) {
// see try-with-resources concept
// TODO Any Action ??? if remoteFolder doesn't exist it will fail...
azureStorageBlobService.upload(containerName, entry.getValue(), stream, source.length());
} catch (StorageException | URISyntaxException | IOException | InvalidKeyException e) {
LOGGER.error(e.getLocalizedMessage());
if (dieOnError) {
throw new ComponentException(e);
}
}
}
}
use of org.talend.components.api.exception.ComponentException in project components by Talend.
the class AzureStorageSourceOrSink method getSchemaNames.
@Override
public List<NamedThing> getSchemaNames(RuntimeContainer container) throws IOException {
List<NamedThing> result = new ArrayList<>();
try {
CloudStorageAccount storageAccount = getAzureConnection(container).getCloudStorageAccount();
CloudBlobClient client = storageAccount.createCloudBlobClient();
for (CloudBlobContainer c : client.listContainers()) {
result.add(new SimpleNamedThing(c.getName(), c.getName()));
}
} catch (InvalidKeyException | URISyntaxException e) {
throw new ComponentException(e);
}
return result;
}
use of org.talend.components.api.exception.ComponentException 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;
}
use of org.talend.components.api.exception.ComponentException in project components by Talend.
the class AzureStorageBlobService method createContainerIfNotExist.
/**
* This method create an azure container if it doesn't exist and set it access policy
*
* @param containerName : the name of the container to be created
* @return true if the container was created, false otherwise
*/
public boolean createContainerIfNotExist(final String containerName) throws StorageException, URISyntaxException, InvalidKeyException {
CloudBlobClient cloudBlobClient = connection.getCloudStorageAccount().createCloudBlobClient();
CloudBlobContainer cloudBlobContainer = cloudBlobClient.getContainerReference(containerName);
boolean containerCreated;
try {
containerCreated = cloudBlobContainer.createIfNotExists();
} catch (StorageException e) {
if (!e.getErrorCode().equals(StorageErrorCodeStrings.CONTAINER_BEING_DELETED)) {
throw e;
}
LOGGER.warn(messages.getMessage("error.CONTAINER_BEING_DELETED", containerName));
// See https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/delete-container
try {
Thread.sleep(40000);
} catch (InterruptedException eint) {
LOGGER.error(messages.getMessage("error.InterruptedException"));
throw new ComponentException(eint);
}
containerCreated = cloudBlobContainer.createIfNotExists();
LOGGER.debug(messages.getMessage("debug.ContainerCreated", containerName));
}
return containerCreated;
}
use of org.talend.components.api.exception.ComponentException in project components by Talend.
the class HadoopCMClusterService method getConfFileContent.
@Override
public String getConfFileContent(String confFileName) {
Configuration conf = confs.get(confFileName);
if (conf == null) {
return null;
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
conf.writeXml(baos);
} catch (IOException e) {
throw new ComponentException(e);
}
try {
return baos.toString("UTF-8");
} catch (UnsupportedEncodingException e) {
throw new ComponentException(e);
}
}
Aggregations