Search in sources :

Example 1 with TableResult

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);
    }
}
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 2 with TableResult

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);
    }
}
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 3 with TableResult

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());
    }
}
Also used : URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) InvalidKeyException(java.security.InvalidKeyException) ActionOnTable(org.talend.components.azurestorage.table.tazurestorageoutputtable.TAzureStorageOutputTableProperties.ActionOnTable) TableResult(com.microsoft.azure.storage.table.TableResult) InvocationOnMock(org.mockito.invocation.InvocationOnMock) TableOperation(com.microsoft.azure.storage.table.TableOperation) StorageException(com.microsoft.azure.storage.StorageException)

Example 4 with TableResult

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());
    }
}
Also used : URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) InvalidKeyException(java.security.InvalidKeyException) ActionOnTable(org.talend.components.azurestorage.table.tazurestorageoutputtable.TAzureStorageOutputTableProperties.ActionOnTable) TableResult(com.microsoft.azure.storage.table.TableResult) InvocationOnMock(org.mockito.invocation.InvocationOnMock) TableOperation(com.microsoft.azure.storage.table.TableOperation) StorageException(com.microsoft.azure.storage.StorageException)

Example 5 with TableResult

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

StorageException (com.microsoft.azure.storage.StorageException)5 TableOperation (com.microsoft.azure.storage.table.TableOperation)5 TableResult (com.microsoft.azure.storage.table.TableResult)5 IOException (java.io.IOException)5 URISyntaxException (java.net.URISyntaxException)5 CloudTable (com.microsoft.azure.storage.table.CloudTable)3 InvalidKeyException (java.security.InvalidKeyException)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 ActionOnTable (org.talend.components.azurestorage.table.tazurestorageoutputtable.TAzureStorageOutputTableProperties.ActionOnTable)2