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, serializedJob); // job id used as key TableOperation insert = TableOperation.insert(wrapper); table.execute(insert); } catch (JsonProcessingException | StorageException | URISyntaxException e) { throw new IOException("Error creating data for rowKey: " + rowKey, e); } }
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); } }
@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); } }
cloudTable = tableClient.getTableReference(table); cloudTable.createIfNotExists(); } catch (Exception e) {
@Override public 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); } }
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); } }
@Override public UUID findFirst(JobAuthorization.State jobState) { try { String partitionFilter = generateFilterCondition( "PartitionKey", TableQuery.QueryComparisons.EQUAL, configuration.getPartitionKey()); String stateFilter = generateFilterCondition( "State", TableQuery.QueryComparisons.EQUAL, jobState.name()); // properties are converted to capitalized by the storage API 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); } }
public void init() { try { String endpoint = String.format(ENDPOINT_TEMPLATE, configuration.getAccountName()); CloudStorageAccount cosmosAccount = CloudStorageAccount.parse( String.format( COSMOS_CONNECTION_TEMPLATE, configuration.getAccountName(), configuration.getAccountKey(), endpoint)); tableClient = cosmosAccount.createCloudTableClient(); // Create the tables if the do not exist tableClient.getTableReference(JOB_TABLE).createIfNotExists(); tableClient.getTableReference(JOB_DATA_TABLE).createIfNotExists(); CloudStorageAccount blobAccount = CloudStorageAccount.parse( String.format( BLOB_CONNECTION_TEMPLATE, configuration.getAccountName(), configuration.getBlobKey())); blobClient = blobAccount.createCloudBlobClient(); blobClient.getContainerReference(BLOB_CONTAINER).createIfNotExists(); } catch (StorageException | URISyntaxException | InvalidKeyException e) { throw new MicrosoftStorageException(e); } }
/** * Gets the capacity metrics table for the blob service. * * @return * A {@link CloudTable} object. * @throws URISyntaxException * @throws StorageException */ public CloudTable getCapacityTable() throws URISyntaxException, StorageException { return this.tableClient.getTableReference(Constants.AnalyticsConstants.METRICS_CAPACITY_BLOB); }
/** * Gets the capacity metrics table for the blob service. * * @return * A {@link CloudTable} object. * @throws URISyntaxException * @throws StorageException */ public CloudTable getCapacityTable() throws URISyntaxException, StorageException { return this.tableClient.getTableReference(Constants.AnalyticsConstants.METRICS_CAPACITY_BLOB); }
private CloudTable tableRefrence(AzureTableName table) { try { return cloudTableClient.getTableReference(table.toString()); } catch (URISyntaxException e) { LOG.warn("URI exception creating table: {},", table, e); } catch (StorageException e) { LOG.warn("Error generating TableClient: {}", table, e); } throw new IllegalStateException("Could not create table: " + table); }
public AzureAccess(CloudTableClient client, String tableName) throws AzureAccessNotPossibleException { try { table = client.getTableReference(tableName); table.createIfNotExists(); } catch (URISyntaxException | StorageException e) { LOG.error("Azure communication failed", e); throw new AzureAccessNotPossibleException("Azure communication failed"); } }
public BlobDataIO(String tableName,String accessKey,String secretKey,String connectionProtocol) throws InvalidKeyException, URISyntaxException, StorageException { storageConnectionString="DefaultEndpointsProtocol=" + connectionProtocol + ";" + "AccountName=" + accessKey + ";" + "AccountKey=" + secretKey; CloudStorageAccount storageAccount = CloudStorageAccount.parse(storageConnectionString); tableClient = storageAccount.createCloudTableClient(); cloudTable = tableClient.getTableReference(tableName); cloudTable.createIfNotExists(); }
public TableResult executeOperation(String tableName, TableOperation ope) throws InvalidKeyException, URISyntaxException, StorageException { CloudTable cloudTable = connection.getCloudStorageAccount().createCloudTableClient().getTableReference(tableName); return cloudTable.execute(ope, null, AzureStorageUtils.getTalendOperationContext()); }
public TableResult executeOperation(String tableName, TableOperation ope) throws InvalidKeyException, URISyntaxException, StorageException { CloudTable cloudTable = connection.getCloudStorageAccount().createCloudTableClient().getTableReference(tableName); return cloudTable.execute(ope, null, AzureStorageUtils.getTalendOperationContext()); }
public ArrayList<TableResult> executeOperation(String tableName, TableBatchOperation batchOpe) throws InvalidKeyException, URISyntaxException, StorageException { CloudTable cloudTable = connection.getCloudStorageAccount().createCloudTableClient().getTableReference(tableName); return cloudTable.execute(batchOpe, null, AzureStorageUtils.getTalendOperationContext()); }
public Iterable<DynamicTableEntity> executeQuery(String tableName, TableQuery<DynamicTableEntity> partitionQuery) throws InvalidKeyException, URISyntaxException, StorageException { CloudTable cloudTable = connection.getCloudStorageAccount().createCloudTableClient().getTableReference(tableName); return cloudTable.execute(partitionQuery, null, AzureStorageUtils.getTalendOperationContext()); }
public ArrayList<TableResult> executeOperation(String tableName, TableBatchOperation batchOpe) throws InvalidKeyException, URISyntaxException, StorageException { CloudTable cloudTable = connection.getCloudStorageAccount().createCloudTableClient().getTableReference(tableName); return cloudTable.execute(batchOpe, null, AzureStorageUtils.getTalendOperationContext()); }
public static CloudTable getRandomTableReference() throws URISyntaxException, StorageException { String tableName = generateRandomTableName(); CloudTableClient tClient = createCloudTableClient(); CloudTable table = tClient.getTableReference(tableName); return table; }
@Test public void testTableDeleteIfExists() throws StorageException, URISyntaxException { CloudTableClient tClient = TableTestHelper.createCloudTableClient(); String tableName = TableTestHelper.generateRandomTableName(); CloudTable table = tClient.getTableReference(tableName); assertFalse(table.deleteIfExists()); table.create(); assertTrue(table.exists()); assertTrue(table.deleteIfExists()); assertFalse(table.deleteIfExists()); }