Search in sources :

Example 6 with CloudTable

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

the class AzureTableStore method updateJob.

@Override
protected void updateJob(UUID jobId, PortabilityJob job, JobUpdateValidator validator) throws IOException {
    Preconditions.checkNotNull(jobId, "Job is null");
    Preconditions.checkNotNull(job, "Job is null");
    try {
        CloudTable table = tableClient.getTableReference(JOB_TABLE);
        String serializedJob = configuration.getMapper().writeValueAsString(job);
        DataWrapper wrapper = new DataWrapper(configuration.getPartitionKey(), jobId.toString(), job.jobAuthorization().state().name(), serializedJob);
        if (validator != null) {
            PortabilityJob previousJob = findJob(jobId);
            if (previousJob == null) {
                throw new IOException("Could not find record for jobId: " + jobId);
            }
            validator.validate(previousJob, job);
        }
        TableOperation insert = TableOperation.insertOrReplace(wrapper);
        table.execute(insert);
    } catch (JsonProcessingException | StorageException | URISyntaxException e) {
        throw new IOException("Error updating job: " + jobId, e);
    }
}
Also used : PortabilityJob(org.datatransferproject.spi.cloud.types.PortabilityJob) TableOperation(com.microsoft.azure.storage.table.TableOperation) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) CloudTable(com.microsoft.azure.storage.table.CloudTable) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) StorageException(com.microsoft.azure.storage.StorageException)

Example 7 with CloudTable

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

the class AzureTableStore method findFirst.

@Override
public UUID findFirst(JobAuthorization.State jobState) {
    try {
        String partitionFilter = generateFilterCondition("PartitionKey", TableQuery.QueryComparisons.EQUAL, configuration.getPartitionKey());
        String stateFilter = generateFilterCondition("State", TableQuery.QueryComparisons.EQUAL, // properties are converted to capitalized by the storage API
        jobState.name());
        String combinedFilter = TableQuery.combineFilters(partitionFilter, TableQuery.Operators.AND, stateFilter);
        TableQuery<DataWrapper> query = TableQuery.from(DataWrapper.class).where(combinedFilter).take(1);
        CloudTable table = tableClient.getTableReference(JOB_TABLE);
        Iterator<DataWrapper> iter = table.execute(query).iterator();
        if (!iter.hasNext()) {
            return null;
        }
        return UUID.fromString(iter.next().getRowKey());
    } catch (StorageException | URISyntaxException e) {
        throw new MicrosoftStorageException("Error finding first job", e);
    }
}
Also used : URISyntaxException(java.net.URISyntaxException) CloudTable(com.microsoft.azure.storage.table.CloudTable) StorageException(com.microsoft.azure.storage.StorageException)

Example 8 with CloudTable

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

the class AzureTableStore method find.

private <T> T find(Class<T> type, String rowKey, String tableName) {
    try {
        CloudTable table = tableClient.getTableReference(tableName);
        TableOperation retrieve = TableOperation.retrieve(configuration.getPartitionKey(), rowKey, DataWrapper.class);
        TableResult result = table.execute(retrieve);
        DataWrapper wrapper = result.getResultAsType();
        return configuration.getMapper().readValue(wrapper.getSerialized(), type);
    } catch (StorageException | IOException | URISyntaxException e) {
        throw new MicrosoftStorageException("Error finding data for rowKey: " + rowKey, e);
    }
}
Also used : TableResult(com.microsoft.azure.storage.table.TableResult) TableOperation(com.microsoft.azure.storage.table.TableOperation) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) 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