Java Code Examples for com.microsoft.azure.storage.table.TableOperation#retrieve()

The following examples show how to use com.microsoft.azure.storage.table.TableOperation#retrieve() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AzureTableStore.java    From data-transfer-project with Apache License 2.0 6 votes vote down vote up
@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);
  }
}
 
Example 2
Source File: AzureTableStore.java    From data-transfer-project with Apache License 2.0 6 votes vote down vote up
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);
  }
}
 
Example 3
Source File: AzureTableStore.java    From data-transfer-project with Apache License 2.0 5 votes vote down vote up
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);
  }
}
 
Example 4
Source File: TableReportIngestionResult.java    From azure-kusto-java with MIT License 5 votes vote down vote up
@Override
public List<IngestionStatus> getIngestionStatusCollection() throws StorageException, URISyntaxException {
    List<IngestionStatus> results = new LinkedList<>();
    for (IngestionStatusInTableDescription descriptor : descriptors) {
        CloudTable table = new CloudTable(new URI(descriptor.TableConnectionString));
        TableOperation operation = TableOperation.retrieve(descriptor.PartitionKey, descriptor.RowKey,
                IngestionStatus.class);
        results.add(table.execute(operation).getResultAsType());
    }

    return results;
}
 
Example 5
Source File: TableUtils.java    From samza with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
  }
}
 
Example 6
Source File: TableUtils.java    From samza with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
  }
}
 
Example 7
Source File: TableUtils.java    From samza with Apache License 2.0 5 votes vote down vote up
/**
 * Updates the isLeader value when the processor starts or stops being a leader.
 * @param jmVersion Job model version of the processor row to be updated.
 * @param pid Unique processor ID of the processor row to be updated.
 * @param isLeader Denotes whether the processor is a leader or not.
 * @throws AzureException If an Azure storage service error occurred.
 */
public void updateIsLeader(String jmVersion, String pid, boolean isLeader) {
  try {
    TableOperation retrieveEntity = TableOperation.retrieve(jmVersion, pid, ProcessorEntity.class);
    ProcessorEntity entity = table.execute(retrieveEntity).getResultAsType();
    entity.setIsLeader(isLeader);
    TableOperation update = TableOperation.replace(entity);
    table.execute(update);
  } catch (StorageException e) {
    LOG.error("Azure storage exception while updating isLeader value for job model version: " + jmVersion + "and pid: " + pid, e);
    throw new AzureException(e);
  }
}
 
Example 8
Source File: TableUtils.java    From samza with Apache License 2.0 5 votes vote down vote up
/**
 * Deletes a specified row in the processor table.
 *
 * Note: Table service uses optimistic locking by default. Hence, if there is an update after retrieving the entity,
 * then the delete operation will fail.
 *
 * @param jmVersion Job model version of the processor row to be deleted.
 * @param pid Unique processor ID of the processor row to be deleted.
 * @param force True, to disable optimistic locking on the table. False, otherwise. Setting to false may result in
 *              AzureException when there is concurrent access to the table.
 *
 * @throws AzureException If an Azure storage service error occurred.
 */
public void deleteProcessorEntity(String jmVersion, String pid, boolean force) {
  try {
    TableOperation retrieveEntity = TableOperation.retrieve(jmVersion, pid, ProcessorEntity.class);
    ProcessorEntity entity = table.execute(retrieveEntity).getResultAsType();
    if (force) {
      entity.setEtag("*");
    }
    TableOperation remove = TableOperation.delete(entity);
    table.execute(remove);
  } catch (StorageException e) {
    LOG.error("Azure storage exception while deleting processor entity with job model version: " + jmVersion + "and pid: " + pid, e);
    throw new AzureException(e);
  }
}