private Status readEntity(String key, Map<String, ByteIterator> result) { try { // firstly, retrieve the entity to be deleted TableOperation retrieveOp = TableOperation.retrieve(partitionKey, key, DynamicTableEntity.class); DynamicTableEntity entity = cloudTable.execute(retrieveOp).getResultAsType(); HashMap<String, EntityProperty> properties = entity.getProperties(); for (Entry<String, EntityProperty> entry: properties.entrySet()) { String fieldName = entry.getKey(); ByteIterator fieldVal = new ByteArrayByteIterator(entry.getValue().getValueAsByteArray()); result.put(fieldName, fieldVal); } return Status.OK; } catch (Exception e) { return Status.ERROR; } }
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); } }
@Override public Status delete(String table, String key) { try { // firstly, retrieve the entity to be deleted TableOperation retrieveOp = TableOperation.retrieve(partitionKey, key, TableServiceEntity.class); TableServiceEntity entity = cloudTable.execute(retrieveOp).getResultAsType(); // secondly, delete the entity TableOperation deleteOp = TableOperation.delete(entity); cloudTable.execute(deleteOp); return Status.OK; } catch (Exception e) { return Status.ERROR; } }
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); } }
protected Optional<DynamicTableEntity> retrieve(String partitionKey, String rowKey) throws StorageException { DynamicTableEntity data = table .execute(TableOperation.retrieve(partitionKey, rowKey, DynamicTableEntity.class)) .getResultAsType(); return Optional.ofNullable(data); }
public Date getBlobDataTracker(long id,String volid) throws StorageException { TableOperation tro = TableOperation.retrieve(volid, Long.toString(id), BlobDataTracker.class); BlobDataTracker btr = cloudTable.execute(tro).getResultAsType(); return btr.getTimestamp(); }
/** * Adds a table operation to retrieve an entity of the specified class type with the specified PartitionKey and * RowKey to the batch operation. * * @param partitionKey * A <code>String</code> containing the PartitionKey of the entity to retrieve. * @param rowKey * A <code>String</code> containing the RowKey of the entity to retrieve. * @param clazzType * The class of the {@link TableEntity} type for the entity to retrieve. */ public void retrieve(final String partitionKey, final String rowKey, final Class<? extends TableEntity> clazzType) { this.lockToPartitionKey(partitionKey); this.add(TableOperation.retrieve(partitionKey, rowKey, clazzType)); }
/** * Adds a table operation to retrieve an entity of the specified class type with the specified PartitionKey and * RowKey to the batch operation. * * @param partitionKey * A <code>String</code> containing the PartitionKey of the entity to retrieve. * @param rowKey * A <code>String</code> containing the RowKey of the entity to retrieve. * @param clazzType * The class of the {@link TableEntity} type for the entity to retrieve. */ public void retrieve(final String partitionKey, final String rowKey, final Class<? extends TableEntity> clazzType) { this.lockToPartitionKey(partitionKey); this.add(TableOperation.retrieve(partitionKey, rowKey, clazzType)); }
/** * Adds a table operation to retrieve an entity of the specified class type with the specified PartitionKey and * RowKey to the batch operation. * * @param partitionKey * A <code>String</code> containing the PartitionKey of the entity to retrieve. * @param rowKey * A <code>String</code> containing the RowKey of the entity to retrieve. * @param resolver * The {@link EntityResolver} implementation to project the entity to retrieve as a particular type in * the result. */ public void retrieve(final String partitionKey, final String rowKey, final EntityResolver<?> resolver) { this.lockToPartitionKey(partitionKey); this.add(TableOperation.retrieve(partitionKey, rowKey, resolver)); }
/** * Retrieve a particular row in the processor table, given the partition key and the row key. * @param jmVersion Job model version of the processor row to be retrieved. * @param pid Unique processor ID of the processor row to be retrieved. * @return An instance of required processor entity. Null if does not exist. * @throws AzureException If an Azure storage service error occurred. */ public ProcessorEntity getEntity(String jmVersion, String pid) { try { TableOperation retrieveEntity = TableOperation.retrieve(jmVersion, pid, ProcessorEntity.class); return table.execute(retrieveEntity).getResultAsType(); } catch (StorageException e) { LOG.error("Azure storage exception while retrieving processor entity with job model version: " + jmVersion + "and pid: " + pid, e); throw new AzureException(e); } }
public void removeBlobDataTracker(long id,String volid) throws StorageException { TableOperation to = TableOperation.retrieve(volid, Long.toString(id), BlobDataTracker.class); BlobDataTracker btr = cloudTable.execute(to).getResultAsType(); if(btr != null) { TableOperation deleteBtr = TableOperation.delete(btr); // Submit the delete operation to the table service. cloudTable.execute(deleteBtr); } }
public <EntityType extends TableServiceEntity> Optional<EntityType> retrieve(TableKey tableKey) { try { return Optional.ofNullable(tableRefrence(tableKey.getTable()) .execute(TableOperation.retrieve(tableKey.getPartitionKey(), tableKey.getRowKey(), tableKey.getEntityClass())) .getResultAsType()); } catch (StorageException e) { LOG.warn("Error retrieving entity from table: {}", tableKey.getTable(), e); } return Optional.empty(); }
/** * Updates the liveness value of a particular processor with a randomly generated integer, which in turn updates the last modified since timestamp of the row. * @param jmVersion Job model version of the processor row to be updated. * @param pid Unique processor ID of the processor row to be updated. */ public void updateHeartbeat(String jmVersion, String pid) { try { TableOperation retrieveEntity = TableOperation.retrieve(jmVersion, pid, ProcessorEntity.class); ProcessorEntity entity = table.execute(retrieveEntity).getResultAsType(); entity.updateLiveness(); TableOperation update = TableOperation.replace(entity); table.execute(update); } catch (StorageException e) { LOG.error("Azure storage exception while updating heartbeat for job model version: " + jmVersion + "and pid: " + pid, e); } }
@Test public void testRetrieveWithNullResolver() { try { TableOperation.retrieve("foo", "blah", (EntityResolver<?>) null); } catch (IllegalArgumentException ex) { assertEquals(ex.getMessage(), String.format(SR.ARGUMENT_NULL_OR_EMPTY, SR.QUERY_REQUIRES_VALID_CLASSTYPE_OR_RESOLVER)); } }
private void testComplexEntityInsert(TableRequestOptions options, boolean usePropertyResolver) throws StorageException { ComplexEntity ref = new ComplexEntity(); ref.setPartitionKey("jxscl_odata"); ref.setRowKey(UUID.randomUUID().toString()); ref.populateEntity(); if (usePropertyResolver) { options.setPropertyResolver(ref); } this.table.execute(TableOperation.insert(ref), options, null); TableResult res = this.table.execute( TableOperation.retrieve(ref.getPartitionKey(), ref.getRowKey(), ComplexEntity.class), options, null); ComplexEntity retrievedComplexRef = res.getResultAsType(); ref.assertEquality(retrievedComplexRef); }
private void testDoubles(TableRequestOptions options, boolean usePropertyResolver) throws StorageException { StrangeDoubles ref = new StrangeDoubles(); ref.setPartitionKey("jxscl_odata"); ref.setRowKey(UUID.randomUUID().toString()); ref.populateEntity(); if (usePropertyResolver) { options.setPropertyResolver(ref); } // try with pojo this.table.execute(TableOperation.insert(ref), options, null); TableResult res = this.table.execute( TableOperation.retrieve(ref.getPartitionKey(), ref.getRowKey(), StrangeDoubles.class), options, null); StrangeDoubles retrievedComplexRef = res.getResultAsType(); ref.assertEquality(retrievedComplexRef); }
@Test public void testInvalidStoreAsAnnotation() throws StorageException { InvalidStoreAsEntity ref = new InvalidStoreAsEntity(); ref.setPartitionKey("jxscl_odata"); ref.setRowKey(UUID.randomUUID().toString()); ref.setStoreAsString("StoreAsOverride Data"); ref.populateEntity(); this.table.execute(TableOperation.insert(ref)); TableResult res = this.table.execute(TableOperation.retrieve(ref.getPartitionKey(), ref.getRowKey(), InvalidStoreAsEntity.class)); InvalidStoreAsEntity retrievedStoreAsRef = res.getResultAsType(); assertEquals(retrievedStoreAsRef.getStoreAsString(), null); }
@Test public void testTableOperationRetrieveJsonNoMetadataResolverFail() { // set custom property resolver which throws this.options.setPropertyResolver(new ThrowingPropertyResolver()); try { this.table.execute(TableOperation.retrieve(this.ent.getPartitionKey(), this.ent.getRowKey(), Class1.class), this.options, null); fail("Invalid property resolver should throw"); } catch (StorageException e) { assertEquals( "The custom property resolver delegate threw an exception. Check the inner exception for more details.", e.getMessage()); assertTrue(e.getCause().getClass() == IllegalArgumentException.class); } }
@Test public void testTableOperationRetrieveJsonNoMetadataFail() { // set custom property resolver this.options.setPropertyResolver(new CustomPropertyResolver()); try { this.table.execute(TableOperation.retrieve(this.ent.getPartitionKey(), this.ent.getRowKey(), Class1.class), this.options, null); fail("Invalid property resolver should throw"); } catch (StorageException e) { assertEquals("Failed to parse property 'fooint' with value '1234' as type 'Edm.Guid'", e.getMessage()); } }