@Override public void kill(DataSegment segment) throws SegmentLoadingException { log.info("Killing segment [%s]", segment); Map<String, Object> loadSpec = segment.getLoadSpec(); final String containerName = MapUtils.getString(loadSpec, "containerName"); final String blobPath = MapUtils.getString(loadSpec, "blobPath"); final String dirPath = Paths.get(blobPath).getParent().toString(); try { azureStorage.emptyCloudBlobDirectory(containerName, dirPath); } catch (StorageException e) { Object extendedInfo = e.getExtendedErrorInformation() == null ? null : e.getExtendedErrorInformation().getErrorMessage(); throw new SegmentLoadingException(e, "Couldn't kill segment[%s]: [%s]", segment.getId(), extendedInfo); } catch (URISyntaxException e) { throw new SegmentLoadingException(e, "Couldn't kill segment[%s]: [%s]", segment.getId(), e.getReason()); } }
bld.append(ex.getErrorCode()); StorageExtendedErrorInformation extendedError = ex.getExtendedErrorInformation(); if (extendedError != null) { bld.append(", ExtendedErrorInformation= {ErrorMessage= ");
private boolean wasLeaseLost(StorageException se, String partitionId) { boolean retval = false; TRACE_LOGGER.debug(this.hostContext.withHostAndPartition(partitionId, "WAS LEASE LOST? Http " + se.getHttpStatusCode())); if (se.getExtendedErrorInformation() != null) { TRACE_LOGGER.debug(this.hostContext.withHostAndPartition(partitionId, "Http " + se.getExtendedErrorInformation().getErrorCode() + " :: " + se.getExtendedErrorInformation().getErrorMessage())); } if ((se.getHttpStatusCode() == 409) || // conflict (se.getHttpStatusCode() == 412)) // precondition failed { StorageExtendedErrorInformation extendedErrorInfo = se.getExtendedErrorInformation(); if (extendedErrorInfo != null) { String errorCode = extendedErrorInfo.getErrorCode(); TRACE_LOGGER.debug(this.hostContext.withHostAndPartition(partitionId, "Error code: " + errorCode)); TRACE_LOGGER.debug(this.hostContext.withHostAndPartition(partitionId, "Error message: " + extendedErrorInfo.getErrorMessage())); if ((errorCode.compareTo(StorageErrorCodeStrings.LEASE_LOST) == 0) || (errorCode.compareTo(StorageErrorCodeStrings.LEASE_ID_MISMATCH_WITH_LEASE_OPERATION) == 0) || (errorCode.compareTo(StorageErrorCodeStrings.LEASE_ID_MISMATCH_WITH_BLOB_OPERATION) == 0) || (errorCode.compareTo(StorageErrorCodeStrings.LEASE_ALREADY_PRESENT) == 0)) { retval = true; } } } return retval; }
bld.append(ex.getErrorCode()); StorageExtendedErrorInformation extendedError = ex.getExtendedErrorInformation(); if (extendedError != null) { bld.append(", ExtendedErrorInformation= {ErrorMessage= ");
private void appendBlock(ByteArrayInputStream blockData, long offset, long writeLength) { final CloudAppendBlob blobRef = (CloudAppendBlob) this.parentBlobRef; this.accessCondition.setIfAppendPositionEqual(offset); int previousResultsCount = this.opContext.getRequestResults().size(); try { blobRef.appendBlock(blockData, writeLength, this.accessCondition, this.options, this.opContext); } catch (final IOException e) { this.lastError = e; } catch (final StorageException e) { if (this.options.getAbsorbConditionalErrorsOnRetry() && e.getHttpStatusCode() == HttpURLConnection.HTTP_PRECON_FAILED && e.getExtendedErrorInformation() != null && e.getExtendedErrorInformation().getErrorCode() != null && (e.getExtendedErrorInformation().getErrorCode() .equals(StorageErrorCodeStrings.INVALID_APPEND_POSITION) || e.getExtendedErrorInformation() .getErrorCode().equals(StorageErrorCodeStrings.INVALID_MAX_BLOB_SIZE_CONDITION)) && (this.opContext.getRequestResults().size() - previousResultsCount > 1)) { // Pre-condition failure on a retry should be ignored in a single writer scenario since // the request succeeded in the first attempt. Logger.info(this.opContext, SR.PRECONDITION_FAILURE_IGNORED); } else { this.lastError = Utility.initIOException(e); } } }
private static void assertMessagesMatch(String expectedMessage, StorageException ex) { final String message = ex.getExtendedErrorInformation().getErrorMessage().split("\n")[0]; assertEquals(expectedMessage, message); }
@Override public void kill(DataSegment segment) throws SegmentLoadingException { log.info("Killing segment [%s]", segment); Map<String, Object> loadSpec = segment.getLoadSpec(); final String containerName = MapUtils.getString(loadSpec, "containerName"); final String blobPath = MapUtils.getString(loadSpec, "blobPath"); final String dirPath = Paths.get(blobPath).getParent().toString(); try { azureStorage.emptyCloudBlobDirectory(containerName, dirPath); } catch(StorageException e){ throw new SegmentLoadingException(e, "Couldn't kill segment[%s]: [%s]", segment.getIdentifier(), e.getExtendedErrorInformation() == null ? null : e.getExtendedErrorInformation().getErrorMessage()); } catch (URISyntaxException e) { throw new SegmentLoadingException(e, "Couldn't kill segment[%s]: [%s]", segment.getIdentifier(), e.getReason()); } }
private AzureBlobLease createLeaseIfNotExistsInternal(String partitionId, BlobRequestOptions options) throws URISyntaxException, IOException, StorageException { AzureBlobLease returnLease = null; try { CloudBlockBlob leaseBlob = this.consumerGroupDirectory.getBlockBlobReference(partitionId); // getBlockBlobReference does not take options returnLease = new AzureBlobLease(partitionId, leaseBlob, this.leaseOperationOptions); uploadLease(returnLease, leaseBlob, AccessCondition.generateIfNoneMatchCondition("*"), UploadActivity.Create, options); // Do not set metadata on creation. No metadata/no owner value indicates that the lease is unowned. TRACE_LOGGER.info(this.hostContext.withHostAndPartition(partitionId, "CreateLeaseIfNotExist OK - leaseContainerName: " + this.storageContainerName + " consumerGroupName: " + this.hostContext.getConsumerGroupName() + " storageBlobPrefix: " + this.storageBlobPrefix)); } catch (StorageException se) { StorageExtendedErrorInformation extendedErrorInfo = se.getExtendedErrorInformation(); if ((extendedErrorInfo != null) && ((extendedErrorInfo.getErrorCode().compareTo(StorageErrorCodeStrings.BLOB_ALREADY_EXISTS) == 0) || (extendedErrorInfo.getErrorCode().compareTo(StorageErrorCodeStrings.LEASE_ID_MISSING) == 0))) // occurs when somebody else already has leased the blob { // The blob already exists. TRACE_LOGGER.info(this.hostContext.withHostAndPartition(partitionId, "Lease already exists")); returnLease = getLeaseInternal(partitionId, options); } else { throw se; } } return returnLease; }
private void appendBlock(ByteArrayInputStream blockData, long offset, long writeLength) { final CloudAppendBlob blobRef = (CloudAppendBlob) this.parentBlobRef; this.accessCondition.setIfAppendPositionEqual(offset); int previousResultsCount = this.opContext.getRequestResults().size(); try { blobRef.appendBlock(blockData, writeLength, this.accessCondition, this.options, this.opContext); } catch (final IOException e) { this.lastError = e; } catch (final StorageException e) { if (this.options.getAbsorbConditionalErrorsOnRetry() && e.getHttpStatusCode() == HttpURLConnection.HTTP_PRECON_FAILED && e.getExtendedErrorInformation() != null && e.getErrorCode() != null && (e.getErrorCode() .equals(StorageErrorCodeStrings.INVALID_APPEND_POSITION) || e.getErrorCode().equals(StorageErrorCodeStrings.INVALID_MAX_BLOB_SIZE_CONDITION)) && (this.opContext.getRequestResults().size() - previousResultsCount > 1)) { // Pre-condition failure on a retry should be ignored in a single writer scenario since // the request succeeded in the first attempt. Logger.info(this.opContext, SR.PRECONDITION_FAILURE_IGNORED); } else { this.lastError = Utility.initIOException(e); } } }
assertTrue(e.getExtendedErrorInformation().getErrorMessage() .startsWith("The requested URI does not represent any resource on the server."));
assertEquals("AuthorizationFailure", e.getExtendedErrorInformation().getErrorCode()); assertEquals("AuthorizationFailure", e.getExtendedErrorInformation().getErrorCode());
@Test @Category({ DevFabricTests.class, DevStoreTests.class }) public void testDeleteQueueIfExists() throws URISyntaxException, StorageException { final CloudQueue queue = QueueTestHelper.getRandomQueueReference(); assertFalse(queue.deleteIfExists()); try { final OperationContext createQueueContext = new OperationContext(); queue.create(null, createQueueContext); assertEquals(createQueueContext.getLastResult().getStatusCode(), HttpURLConnection.HTTP_CREATED); assertTrue(queue.deleteIfExists()); assertFalse(queue.deleteIfExists()); try { queue.create(); fail("Queue CreateIfNotExists did not throw exception while trying to create a queue in BeingDeleted State"); } catch (StorageException ex) { assertEquals("Expected 409 Exception, QueueBeingDeleted not thrown", ex.getHttpStatusCode(), HttpURLConnection.HTTP_CONFLICT); assertEquals("Expected 409 Exception, QueueBeingDeleted not thrown", ex.getExtendedErrorInformation() .getErrorCode(), StorageErrorCodeStrings.QUEUE_BEING_DELETED); } } finally { queue.delete(); } }
@Test @Category({ DevFabricTests.class, DevStoreTests.class }) public void testQueueCreateAfterDelete() throws URISyntaxException, StorageException { final CloudQueueClient qClient = TestHelper.createCloudQueueClient(); final String queueName = QueueTestHelper.generateRandomQueueName(); CloudQueue queue = qClient.getQueueReference(queueName); assertEquals(queueName, queue.getName()); try { OperationContext createQueueContext1 = new OperationContext(); assertTrue(queue.createIfNotExists(null, createQueueContext1)); assertEquals(createQueueContext1.getLastResult().getStatusCode(), HttpURLConnection.HTTP_CREATED); assertTrue(queue.deleteIfExists()); try { queue.create(); fail("Queue CreateIfNotExists did not throw exception while trying to create a queue in BeingDeleted State"); } catch (StorageException ex) { assertEquals("Expected 409 Exception, QueueBeingDeleted not thrown", ex.getHttpStatusCode(), HttpURLConnection.HTTP_CONFLICT); assertEquals("Expected 409 Exception, QueueBeingDeleted not thrown", ex.getExtendedErrorInformation() .getErrorCode(), StorageErrorCodeStrings.QUEUE_BEING_DELETED); } } finally { queue.deleteIfExists(); } }
@Test @Category({ DevFabricTests.class, DevStoreTests.class }) public void testQueueCreateIfNotExistsAfterDelete() throws URISyntaxException, StorageException { final CloudQueueClient qClient = TestHelper.createCloudQueueClient(); final String queueName = QueueTestHelper.generateRandomQueueName(); CloudQueue queue = qClient.getQueueReference(queueName); assertEquals(queueName, queue.getName()); try { OperationContext createQueueContext1 = new OperationContext(); assertTrue(queue.createIfNotExists(null, createQueueContext1)); assertEquals(createQueueContext1.getLastResult().getStatusCode(), HttpURLConnection.HTTP_CREATED); assertTrue(queue.deleteIfExists()); try { queue.createIfNotExists(); fail("Queue CreateIfNotExists did not throw exception while trying to create a queue in BeingDeleted State"); } catch (StorageException ex) { assertEquals("Expected 409 Exception, QueueBeingDeleted not thrown", ex.getHttpStatusCode(), HttpURLConnection.HTTP_CONFLICT); assertEquals("Expected 409 Exception, QueueBeingDeleted not thrown", ex.getExtendedErrorInformation() .getErrorCode(), StorageErrorCodeStrings.QUEUE_BEING_DELETED); } } finally { queue.deleteIfExists(); } }