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);
}
}
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);
}
}
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);
}
}
Aggregations