static boolean isBlobAlreadyExistsConflict(StorageException e) { if (e.getHttpStatusCode() == HttpURLConnection.HTTP_CONFLICT && StorageErrorCodeStrings.BLOB_ALREADY_EXISTS.equals(e.getErrorCode())) { return true; } return false; }
@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()); } }
/** * Reserved for internal use. A static factory method that generates a {@link StorageException} for invalid MIME * responses. * * @return * The {@link StorageException} for the invalid MIME response. */ private static StorageException generateMimeParseException() { return new StorageException(StorageErrorCodeStrings.OUT_OF_RANGE_INPUT, SR.INVALID_MIME_RESPONSE, Constants.HeaderConstants.HTTP_UNUSED_306, null, null); }
/** * Returns an unexpected storage exception. * * @param cause * An <code>Exception</code> object that represents the initial exception that caused the unexpected * error. * * @return A {@link StorageException} object that represents the unexpected storage exception being thrown. */ public static StorageException generateNewUnexpectedStorageException(final Exception cause) { final StorageException exceptionRef = new StorageException(StorageErrorCode.NONE.toString(), "Unexpected internal storage client error.", 306, // unused null, null); exceptionRef.initCause(cause); return exceptionRef; }
/** * Create a container * * @throws StorageException * @throws URISyntaxException */ @Test @Category({ DevFabricTests.class, DevStoreTests.class }) public void testCloudBlobContainerCreate() throws StorageException { this.container.create(); try { this.container.create(); fail("Should not be able to create twice."); } catch (StorageException e) { assertEquals(e.getErrorCode(), "ContainerAlreadyExists"); assertEquals(e.getHttpStatusCode(), 409); assertEquals(e.getMessage(), "The specified container already exists."); } }
|| translatedException.getErrorCode().equals(StorageErrorCodeStrings.INVALID_BLOB_TYPE)) { throw translatedException; translatedException = new StorageException("NetworkOnMainThreadException", SR.NETWORK_ON_MAIN_THREAD_EXCEPTION, -1, null, e); task.getResult().setException(translatedException); task.getResult().setStatusCode(e.getHttpStatusCode()); task.getResult().setStatusMessage(e.getMessage()); task.getResult().setException(e); Logger.warn(opContext, LogConstants.RETRYABLE_EXCEPTION, e.getClass().getName(), e.getMessage()); translatedException = e; translatedException = StorageException.translateException(task, e, opContext); task.getResult().setException(translatedException); translatedException == null ? null : translatedException.getMessage()); : translatedException.getMessage()); throw translatedException; translatedException = new StorageException(StorageErrorCodeStrings.OPERATION_TIMED_OUT, SR.MAXIMUM_EXECUTION_TIMEOUT_EXCEPTION, Constants.HeaderConstants.HTTP_UNUSED_306, null, timeoutException); : translatedException.getMessage());
bld.append(ex.getHttpStatusCode()); bld.append(ex.getMessage()); bld.append(ex.getErrorCode()); StorageExtendedErrorInformation extendedError = ex.getExtendedErrorInformation(); if (extendedError != null) { bld.append(", ExtendedErrorInformation= {ErrorMessage= ");
private void doCreateAppendBlob(CloudAppendBlob client, BlobServiceRequestOptions opts, Exchange exchange) throws Exception { LOG.trace("Creating an append blob [{}] from exchange [{}]...", getConfiguration().getBlobName(), exchange); try { client.createOrReplace(opts.getAccessCond(), opts.getRequestOpts(), opts.getOpContext()); } catch (StorageException ex) { if (ex.getHttpStatusCode() != 409) { throw ex; } } ExchangeUtil.getMessageForResponse(exchange) .setHeader(BlobServiceConstants.APPEND_BLOCK_CREATED, Boolean.TRUE); }
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; }
/** * Acquires a lease on a blob. The lease ID is NULL initially. * @param leaseTimeInSec The time in seconds you want to acquire the lease for. * @param leaseId Proposed ID you want to acquire the lease with, null if not proposed. * @return String that represents lease ID. Null if acquireLease is unsuccessful because the blob is leased already. * @throws AzureException If a Azure storage service error occurred. This includes the case where the blob you're trying to lease does not exist. */ public String acquireLease(int leaseTimeInSec, String leaseId) { try { String id = leaseBlob.acquireLease(leaseTimeInSec, leaseId); LOG.info("Acquired lease with lease id = " + id); return id; } catch (StorageException storageException) { int httpStatusCode = storageException.getHttpStatusCode(); if (httpStatusCode == HttpStatus.CONFLICT_409) { LOG.info("The blob you're trying to acquire is leased already.", storageException.getMessage()); } else if (httpStatusCode == HttpStatus.NOT_FOUND_404) { LOG.error("The blob you're trying to lease does not exist.", storageException); throw new AzureException(storageException); } else { LOG.error("Error acquiring lease!", storageException); throw new AzureException(storageException); } } return null; }
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); } } }
/** * Writes b.length bytes from the specified byte array to this output * stream. The general contract for write(b) is that it should have exactly * the same effect as the call write(b, 0, b.length). * * @param b * Block of bytes to be written to the output stream. */ @Override public void write(byte[] b) throws IOException { try { out.write(b); } catch(IOException e) { if (e.getCause() instanceof StorageException) { StorageException storageExcp = (StorageException) e.getCause(); LOG.error("Encountered Storage Exception for write on Blob : {}" + " Exception details: {} Error Code : {}", key, e.getMessage(), storageExcp.getErrorCode()); } throw e; } }
private static void testMetadataFailures(CloudFileDirectory directory, String key, String value, boolean badKey) throws URISyntaxException { directory.getMetadata().put(key, value); try { directory.uploadMetadata(); fail(SR.METADATA_KEY_INVALID); } catch (StorageException e) { if (badKey) { assertEquals(SR.METADATA_KEY_INVALID, e.getMessage()); } else { assertEquals(SR.METADATA_VALUE_INVALID, e.getMessage()); } } directory.getMetadata().remove(key); }
assertEquals("InvalidUri", e.getErrorCode()); assertTrue(e.getExtendedErrorInformation().getErrorMessage() .startsWith("The requested URI does not represent any resource on the server."));
throw new StorageException("CredentialsNotSpecified", "Credentials must be specified in the TestHelper class in order to run tests.", Constants.HeaderConstants.HTTP_UNUSED_306, throw StorageException.translateException(null, e, 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); } }
/** * Returns either the held exception from the operation if it is set, otherwise the translated exception. * * @param opContext * an object used to track the execution of the operation * @return the exception to throw. */ protected final StorageException materializeException(final OperationContext opContext) { if (this.getException() != null) { return this.getException(); } return StorageException.translateException(this, null, opContext); }
/** * Try to create a share after it is created * * @throws StorageException */ @Test public void testCloudFileShareCreate() throws StorageException { this.share.create(); assertTrue(this.share.exists()); try { this.share.create(); fail("Share already existed but was created anyway."); } catch (StorageException e) { assertEquals(e.getErrorCode(), "ShareAlreadyExists"); assertEquals(e.getHttpStatusCode(), 409); assertEquals(e.getMessage(), "The specified share already exists."); } }
|| translatedException.getErrorCode().equals(StorageErrorCodeStrings.INVALID_BLOB_TYPE)) { throw translatedException; task.getResult().setStatusCode(e.getHttpStatusCode()); task.getResult().setStatusMessage(e.getMessage()); task.getResult().setException(e); Logger.warn(opContext, LogConstants.RETRYABLE_EXCEPTION, e.getClass().getName(), e.getMessage()); translatedException = e; translatedException = StorageException.translateException(task, e, opContext); task.getResult().setException(translatedException); translatedException == null ? null : translatedException.getMessage()); : translatedException.getMessage()); throw translatedException; translatedException = new StorageException(StorageErrorCodeStrings.OPERATION_TIMED_OUT, SR.MAXIMUM_EXECUTION_TIMEOUT_EXCEPTION, Constants.HeaderConstants.HTTP_UNUSED_306, null, timeoutException); : translatedException.getMessage());
bld.append(ex.getHttpStatusCode()); bld.append(ex.getMessage()); bld.append(ex.getErrorCode()); StorageExtendedErrorInformation extendedError = ex.getExtendedErrorInformation(); if (extendedError != null) { bld.append(", ExtendedErrorInformation= {ErrorMessage= ");