use of com.microsoft.azure.storage.table.TableResult 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);
}
}
use of com.microsoft.azure.storage.table.TableResult 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);
}
}
use of com.microsoft.azure.storage.table.TableResult in project components by Talend.
the class AzureStorageTableWriterTest method testWriteRecordWithDynamicSchemaToAvailableSink.
@Test
public void testWriteRecordWithDynamicSchemaToAvailableSink() {
// setup
properties.schema.schema.setValue(TableHelper.getDynamicWriteSchema());
assertEquals(ValidationResult.Result.OK, sink.initialize(container, properties).getStatus());
assertEquals(ValidationResult.Result.OK, sink.validate(container).getStatus());
WriteOperation<?> writeOperation = sink.createWriteOperation();
writeOperation.initialize(container);
writer = (AzureStorageTableWriter) writeOperation.createWriter(container);
// mock
writer.tableservice = tableService;
try {
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
return null;
}
}).when(tableService).handleActionOnTable(anyString(), any(ActionOnTable.class));
when(tableService.executeOperation(anyString(), any(TableOperation.class))).thenReturn(new TableResult(200));
// assert
writer.open(RandomStringUtils.random(12));
writer.write(TableHelper.getRecord(0));
writer.close();
} catch (InvalidKeyException | URISyntaxException | StorageException | IOException e) {
fail("should not throw " + e.getMessage());
}
}
use of com.microsoft.azure.storage.table.TableResult in project components by Talend.
the class AzureStorageTableWriterTest method testWriteValidRecordsToAvailableSink.
@Test
public void testWriteValidRecordsToAvailableSink() {
// setup
assertEquals(ValidationResult.Result.OK, sink.initialize(container, properties).getStatus());
assertEquals(ValidationResult.Result.OK, sink.validate(container).getStatus());
WriteOperation<?> writeOperation = sink.createWriteOperation();
writeOperation.initialize(container);
writer = (AzureStorageTableWriter) writeOperation.createWriter(container);
// mock
writer.tableservice = tableService;
try {
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
return null;
}
}).when(tableService).handleActionOnTable(anyString(), any(ActionOnTable.class));
when(tableService.executeOperation(anyString(), any(TableOperation.class))).thenReturn(new TableResult(200));
// assert
writer.open(RandomStringUtils.random(12));
for (int i = 0; i < 500; i++) {
writer.write(TableHelper.getRecord(i));
}
writer.close();
} catch (InvalidKeyException | URISyntaxException | StorageException | IOException e) {
fail("should not throw " + e.getMessage());
}
}
use of com.microsoft.azure.storage.table.TableResult 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