Search in sources :

Example 1 with CloudTable

use of com.microsoft.azure.storage.table.CloudTable in project components by Talend.

the class AzureStorageTableService method handleActionOnTable.

public void handleActionOnTable(String tableName, ActionOnTable actionTable) throws IOException, StorageException, InvalidKeyException, URISyntaxException {
    // FIXME How does this will behave in a distributed runtime ? See where to place correctly this
    // instruction...
    CloudTable cloudTable = connection.getCloudStorageAccount().createCloudTableClient().getTableReference(tableName);
    switch(actionTable) {
        case Create_table:
            cloudTable.create();
            break;
        case Create_table_if_does_not_exist:
            cloudTable.createIfNotExists();
            break;
        case Drop_and_create_table:
            cloudTable.delete();
            createTableAfterDeletion(cloudTable);
            break;
        case Drop_table_if_exist_and_create:
            cloudTable.deleteIfExists();
            createTableAfterDeletion(cloudTable);
            break;
        case Default:
        default:
            return;
    }
}
Also used : CloudTable(com.microsoft.azure.storage.table.CloudTable)

Example 2 with CloudTable

use of com.microsoft.azure.storage.table.CloudTable in project stdlib by petergeneric.

the class ServiceManagerGuiceModule method getLogDataTable.

/**
 * For the Azure Log Store, the underlying table to use
 *
 * @param storageConnectionString
 *
 * @return
 *
 * @throws URISyntaxException
 * @throws StorageException
 * @throws InvalidKeyException
 */
@Provides
@Named("logdata")
public CloudTable getLogDataTable(@Named("azure.storage-connection-string") String storageConnectionString, @Named("azure.logging-table") String logTableName) throws URISyntaxException, StorageException, InvalidKeyException {
    // Retrieve storage account from connection-string.
    CloudStorageAccount storageAccount = CloudStorageAccount.parse(storageConnectionString);
    // Create the table client.
    CloudTableClient tableClient = storageAccount.createCloudTableClient();
    // Create the table if it doesn't exist.
    CloudTable table = tableClient.getTableReference(logTableName);
    table.createIfNotExists();
    return table;
}
Also used : CloudStorageAccount(com.microsoft.azure.storage.CloudStorageAccount) CloudTableClient(com.microsoft.azure.storage.table.CloudTableClient) CloudTable(com.microsoft.azure.storage.table.CloudTable) Named(com.google.inject.name.Named) Provides(com.google.inject.Provides)

Example 3 with CloudTable

use of com.microsoft.azure.storage.table.CloudTable in project data-transfer-project by google.

the class AzureTableStore method findJob.

@Override
public PortabilityJob findJob(UUID jobId) {
    Preconditions.checkNotNull(jobId, "Job id is null");
    try {
        CloudTable table = tableClient.getTableReference(JOB_TABLE);
        TableOperation retrieve = TableOperation.retrieve(configuration.getPartitionKey(), jobId.toString(), DataWrapper.class);
        TableResult result = table.execute(retrieve);
        DataWrapper wrapper = result.getResultAsType();
        return configuration.getMapper().readValue(wrapper.getSerialized(), PortabilityJob.class);
    } catch (StorageException | URISyntaxException | IOException e) {
        throw new MicrosoftStorageException("Error finding job: " + jobId, e);
    }
}
Also used : TableResult(com.microsoft.azure.storage.table.TableResult) TableOperation(com.microsoft.azure.storage.table.TableOperation) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) CloudTable(com.microsoft.azure.storage.table.CloudTable) StorageException(com.microsoft.azure.storage.StorageException)

Example 4 with CloudTable

use of com.microsoft.azure.storage.table.CloudTable in project data-transfer-project by google.

the class AzureTableStore method create.

private void create(String rowKey, String tableName, String state, Object type) throws IOException {
    try {
        CloudTable table = tableClient.getTableReference(tableName);
        String serializedJob = configuration.getMapper().writeValueAsString(type);
        DataWrapper wrapper = new DataWrapper(configuration.getPartitionKey(), rowKey, state, // job id used as key
        serializedJob);
        TableOperation insert = TableOperation.insert(wrapper);
        table.execute(insert);
    } catch (JsonProcessingException | StorageException | URISyntaxException e) {
        throw new IOException("Error creating data for rowKey: " + rowKey, e);
    }
}
Also used : TableOperation(com.microsoft.azure.storage.table.TableOperation) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) CloudTable(com.microsoft.azure.storage.table.CloudTable) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) StorageException(com.microsoft.azure.storage.StorageException)

Example 5 with CloudTable

use of com.microsoft.azure.storage.table.CloudTable in project data-transfer-project by google.

the class AzureTableStore method remove.

private void remove(UUID jobId, String tableName) throws IOException {
    try {
        CloudTable table = tableClient.getTableReference(tableName);
        TableOperation retrieve = TableOperation.retrieve(configuration.getPartitionKey(), jobId.toString(), DataWrapper.class);
        TableResult result = table.execute(retrieve);
        DataWrapper wrapper = result.getResultAsType();
        TableOperation delete = TableOperation.delete(wrapper);
        table.execute(delete);
    } catch (StorageException | URISyntaxException e) {
        throw new IOException("Error removing data for job: " + jobId, e);
    }
}
Also used : TableResult(com.microsoft.azure.storage.table.TableResult) TableOperation(com.microsoft.azure.storage.table.TableOperation) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) CloudTable(com.microsoft.azure.storage.table.CloudTable) StorageException(com.microsoft.azure.storage.StorageException)

Aggregations

CloudTable (com.microsoft.azure.storage.table.CloudTable)8 StorageException (com.microsoft.azure.storage.StorageException)6 URISyntaxException (java.net.URISyntaxException)6 TableOperation (com.microsoft.azure.storage.table.TableOperation)5 IOException (java.io.IOException)5 TableResult (com.microsoft.azure.storage.table.TableResult)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 Provides (com.google.inject.Provides)1 Named (com.google.inject.name.Named)1 CloudStorageAccount (com.microsoft.azure.storage.CloudStorageAccount)1 CloudTableClient (com.microsoft.azure.storage.table.CloudTableClient)1 PortabilityJob (org.datatransferproject.spi.cloud.types.PortabilityJob)1