Search in sources :

Example 11 with AzureException

use of org.apache.samza.AzureException in project samza by apache.

the class BlobUtils method getBarrierState.

/**
 * Reads the current barrier state from the blob.
 * @return Barrier state published on the blob.
 * @throws AzureException If an Azure storage service error occurred.
 * @throws SamzaException If data retrieved from blob could not be parsed by SamzaObjectMapper.
 */
public String getBarrierState() {
    LOG.info("Reading the barrier state from blob.");
    byte[] data = new byte[(int) BARRIER_STATE_BLOCK_SIZE];
    try {
        blob.downloadRangeToByteArray(JOB_MODEL_BLOCK_SIZE, BARRIER_STATE_BLOCK_SIZE, data, 0);
    } catch (StorageException e) {
        LOG.error("Failed to read barrier state from blob.", e);
        throw new AzureException(e);
    }
    try {
        return SamzaObjectMapper.getObjectMapper().readValue(data, String.class);
    } catch (IOException e) {
        LOG.error("Failed to parse byte data: " + Arrays.toString(data) + " for barrier state retrieved from the blob.", e);
        throw new SamzaException(e);
    }
}
Also used : AzureException(org.apache.samza.AzureException) IOException(java.io.IOException) StorageException(com.microsoft.azure.storage.StorageException) SamzaException(org.apache.samza.SamzaException)

Example 12 with AzureException

use of org.apache.samza.AzureException in project samza by apache.

the class TableUtils method deleteProcessorEntity.

/**
 * 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);
    }
}
Also used : AzureException(org.apache.samza.AzureException) TableOperation(com.microsoft.azure.storage.table.TableOperation) ProcessorEntity(org.apache.samza.coordinator.data.ProcessorEntity) StorageException(com.microsoft.azure.storage.StorageException)

Aggregations

AzureException (org.apache.samza.AzureException)12 StorageException (com.microsoft.azure.storage.StorageException)9 TableOperation (com.microsoft.azure.storage.table.TableOperation)4 IOException (java.io.IOException)4 SamzaException (org.apache.samza.SamzaException)3 ProcessorEntity (org.apache.samza.coordinator.data.ProcessorEntity)3 ImmutableMap (com.google.common.collect.ImmutableMap)1 URISyntaxException (java.net.URISyntaxException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Random (java.util.Random)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 LinkedBlockingDeque (java.util.concurrent.LinkedBlockingDeque)1 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1 CheckpointV1 (org.apache.samza.checkpoint.CheckpointV1)1 SystemStreamPartition (org.apache.samza.system.SystemStreamPartition)1 BlobMetadataContext (org.apache.samza.system.azureblob.utils.BlobMetadataContext)1 BlobMetadataGenerator (org.apache.samza.system.azureblob.utils.BlobMetadataGenerator)1 Test (org.junit.Test)1