@Override public String getMessage() { String msg = super.getMessage(); return extraInfo == null ? msg : msg + "; " + extraInfo; }
/** * Retrieve a summary of the reason for the exception, including the {@link #getErrorCode()} and {@link #getErrorMessage()}, * if the error was raised by the service. */ @Override public String getMessage() { return super.getMessage(); }
@Override public CsmConfiguration getConfiguration() { for (CsmConfigurationProvider p : providers) { try { return p.getConfiguration(); } catch (SdkClientException e) { if (log.isDebugEnabled()) { log.debug("Unable to load configuration from " + p.toString() + ": " + e.getMessage()); } } } throw new SdkClientException("Could not resolve client side monitoring configuration from" + " the configured providers in the chain"); } }
private void handleRetryableException(ExecOneRequestParams execOneParams, Exception e) { captureExceptionMetrics(e); awsRequestMetrics.addProperty(Field.AWSRequestID, null); SdkClientException sdkClientException; if (!(e instanceof SdkClientException)) { sdkClientException = new SdkClientException( "Unable to execute HTTP request: " + e.getMessage(), e); } else { sdkClientException = (SdkClientException) e; } boolean willRetry = shouldRetry(execOneParams, sdkClientException); if (log.isTraceEnabled()) { log.trace(sdkClientException.getMessage() + (willRetry ? " Request will be retried." : ""), e); } else if (log.isDebugEnabled()) { log.trace(sdkClientException.getMessage() + (willRetry ? " Request will be retried." : "")); } if (!willRetry) { throw lastReset(sdkClientException); } // Cache the retryable exception execOneParams.retriedException = sdkClientException; }
/** * Initialize @Singleton. * @param awsConfiguration your aws configuration credentials * @param awsParameterStoreConfiguration configuration for the parameter store * @param applicationConfiguration the application configuration * @param route53ClientDiscoveryConfiguration configuration for route53 service discovery, if you are using this (not required) */ AWSParameterStoreConfigClient( AWSClientConfiguration awsConfiguration, AWSParameterStoreConfiguration awsParameterStoreConfiguration, ApplicationConfiguration applicationConfiguration, @Nullable Route53ClientDiscoveryConfiguration route53ClientDiscoveryConfiguration) { this.awsConfiguration = awsConfiguration; this.awsParameterStoreConfiguration = awsParameterStoreConfiguration; try { this.client = AWSSimpleSystemsManagementAsyncClient.asyncBuilder().withClientConfiguration(awsConfiguration.getClientConfiguration()).build(); } catch (SdkClientException sce) { LOG.warn("Error creating Simple Systems Management client - check your credentials: " + sce.getMessage(), sce); } this.serviceId = (route53ClientDiscoveryConfiguration != null ? route53ClientDiscoveryConfiguration.getServiceId() : applicationConfiguration.getName()).orElse(null); }
@Override public String getMessage() { String msg = super.getMessage(); return extraInfo == null ? msg : msg + "; " + extraInfo; }
@Override public CsmConfiguration getConfiguration() { for (CsmConfigurationProvider p : providers) { try { return p.getConfiguration(); } catch (SdkClientException e) { if (log.isDebugEnabled()) { log.debug("Unable to load configuration from " + p.toString() + ": " + e.getMessage()); } } } throw new SdkClientException("Could not resolve client side monitoring configuration from" + " the configured providers in the chain"); } }
private void handleRetryableException(ExecOneRequestParams execOneParams, Exception e) { captureExceptionMetrics(e); awsRequestMetrics.addProperty(Field.AWSRequestID, null); SdkClientException sdkClientException; if (!(e instanceof SdkClientException)) { sdkClientException = new SdkClientException( "Unable to execute HTTP request: " + e.getMessage(), e); } else { sdkClientException = (SdkClientException) e; } boolean willRetry = shouldRetry(execOneParams, sdkClientException); if (log.isTraceEnabled()) { log.trace(sdkClientException.getMessage() + (willRetry ? " Request will be retried." : ""), e); } else if (log.isDebugEnabled()) { log.trace(sdkClientException.getMessage() + (willRetry ? " Request will be retried." : "")); } if (!willRetry) { throw lastReset(sdkClientException); } // Cache the retryable exception execOneParams.retriedException = sdkClientException; }
@Override public String getMessage() { String msg = super.getMessage(); return extraInfo == null ? msg : msg + "; " + extraInfo; }
private void handleRetryableException(ExecOneRequestParams execOneParams, Exception e) { captureExceptionMetrics(e); awsRequestMetrics.addProperty(Field.AWSRequestID, null); SdkClientException sdkClientException; if (!(e instanceof SdkClientException)) { sdkClientException = new SdkClientException( "Unable to execute HTTP request: " + e.getMessage(), e); } else { sdkClientException = (SdkClientException) e; } boolean willRetry = shouldRetry(execOneParams, sdkClientException); if (log.isTraceEnabled()) { log.trace(sdkClientException.getMessage() + (willRetry ? " Request will be retried." : ""), e); } else if (log.isDebugEnabled()) { log.trace(sdkClientException.getMessage() + (willRetry ? " Request will be retried." : "")); } if (!willRetry) { throw lastReset(sdkClientException); } // Cache the retryable exception execOneParams.retriedException = sdkClientException; }
@Override public boolean delete(FileData data) { try { s3.deleteObject(bucketName, data.getName()); onModified(); return true; } catch (SdkClientException e) { log.error(e.getMessage(), e); return false; } }
log.warn( "Attempted to validate AWS credentials and failed due to {}. Falling back to no op implementation", sdkClientException.getMessage(), sdkClientException );
@Override public void savePath(Path fileSystemPath) throws IOException { long newFileSize = -1; if (!this.canWrite()) { open(DataAccessOption.WRITE_ACCESS); } try { File inputFile = fileSystemPath.toFile(); if (dvObject instanceof DataFile) { s3.putObject(new PutObjectRequest(bucketName, key, inputFile)); newFileSize = inputFile.length(); } else { throw new IOException("DvObject type other than datafile is not yet supported"); } } catch (SdkClientException ioex) { String failureMsg = ioex.getMessage(); if (failureMsg == null) { failureMsg = "S3AccessIO: Unknown exception occured while uploading a local file into S3Object "+key; } throw new IOException(failureMsg); } // if it has uploaded successfully, we can reset the size // of the object: setSize(newFileSize); }
@Override public void saveInputStream(InputStream inputStream) throws IOException { if (!this.canWrite()) { open(DataAccessOption.WRITE_ACCESS); } String directoryString = FileUtil.getFilesTempDirectory(); Random rand = new Random(); Path tempPath = Paths.get(directoryString, Integer.toString(rand.nextInt(Integer.MAX_VALUE))); File tempFile = createTempFile(tempPath, inputStream); try { s3.putObject(bucketName, key, tempFile); } catch (SdkClientException ioex) { String failureMsg = ioex.getMessage(); if (failureMsg == null) { failureMsg = "S3AccessIO: Unknown exception occured while uploading a local file into S3 Storage."; } tempFile.delete(); throw new IOException(failureMsg); } tempFile.delete(); ObjectMetadata objectMetadata = s3.getObjectMetadata(bucketName, key); if (objectMetadata != null) { setSize(objectMetadata.getContentLength()); } }
@Override public InputStream getInputStream() throws IOException { if(super.getInputStream()==null) { try { setInputStream(s3.getObject(new GetObjectRequest(bucketName, key)).getObjectContent()); } catch (SdkClientException sce) { throw new IOException("Cannot get S3 object " + key + " ("+sce.getMessage()+")"); } } if (super.getInputStream() == null) { throw new IOException("Cannot get InputStream for S3 Object" + key); } setChannel(Channels.newChannel(super.getInputStream())); return super.getInputStream(); }
@Override public boolean deleteHistory(FileData data) { String name = data.getName(); String version = data.getVersion(); try { if (version == null) { deleteAllVersions(name); onModified(); return true; } else { s3.deleteVersion(bucketName, name, version); onModified(); return true; } } catch (SdkClientException e) { log.error(e.getMessage(), e); return false; } }
@Override public void saveInputStreamAsAux(InputStream inputStream, String auxItemTag, Long filesize) throws IOException { if (filesize == null || filesize < 0) { saveInputStreamAsAux(inputStream, auxItemTag); } else { if (!this.canWrite()) { open(DataAccessOption.WRITE_ACCESS); } String destinationKey = getDestinationKey(auxItemTag); ObjectMetadata metadata = new ObjectMetadata(); metadata.setContentLength(filesize); try { s3.putObject(bucketName, destinationKey, inputStream, metadata); } catch (SdkClientException ioex) { String failureMsg = ioex.getMessage(); if (failureMsg == null) { failureMsg = "S3AccessIO: SdkClientException occured while saving a local InputStream as S3Object"; } throw new IOException(failureMsg); } } }
@Override protected Result verifyConnectivity(Map<String, Object> parameters) { ResultBuilder builder = ResultBuilder.withStatusAndScope(Result.Status.OK, Scope.CONNECTIVITY); try { S3Configuration configuration = setProperties(new S3Configuration(), parameters); AWSCredentials credentials = new BasicAWSCredentials(configuration.getAccessKey(), configuration.getSecretKey()); AWSCredentialsProvider credentialsProvider = new AWSStaticCredentialsProvider(credentials); AmazonS3 client = AmazonS3ClientBuilder.standard().withCredentials(credentialsProvider).withRegion(Regions.valueOf(configuration.getRegion())).build(); client.listBuckets(); } catch (SdkClientException e) { ResultErrorBuilder errorBuilder = ResultErrorBuilder.withCodeAndDescription(VerificationError.StandardCode.AUTHENTICATION, e.getMessage()) .detail("aws_s3_exception_message", e.getMessage()).detail(VerificationError.ExceptionAttribute.EXCEPTION_CLASS, e.getClass().getName()) .detail(VerificationError.ExceptionAttribute.EXCEPTION_INSTANCE, e); builder.error(errorBuilder.build()); } catch (Exception e) { builder.error(ResultErrorBuilder.withException(e).build()); } return builder.build(); } }
@Override @SuppressWarnings("PMD.AvoidCatchingGenericException") protected Result verifyConnectivity(Map<String, Object> parameters) { ResultBuilder builder = ResultBuilder.withStatusAndScope(Result.Status.OK, Scope.CONNECTIVITY); try { S3Configuration configuration = setProperties(new S3Configuration(), parameters); AWSCredentials credentials = new BasicAWSCredentials(configuration.getAccessKey(), configuration.getSecretKey()); AWSCredentialsProvider credentialsProvider = new AWSStaticCredentialsProvider(credentials); AmazonS3 client = AmazonS3ClientBuilder.standard().withCredentials(credentialsProvider).withRegion(Regions.valueOf(configuration.getRegion())).build(); client.listBuckets(); } catch (SdkClientException e) { ResultErrorBuilder errorBuilder = ResultErrorBuilder.withCodeAndDescription(VerificationError.StandardCode.AUTHENTICATION, e.getMessage()) .detail("aws_s3_exception_message", e.getMessage()).detail(VerificationError.ExceptionAttribute.EXCEPTION_CLASS, e.getClass().getName()) .detail(VerificationError.ExceptionAttribute.EXCEPTION_INSTANCE, e); builder.error(errorBuilder.build()); } catch (@SuppressWarnings("PMD.AvoidCatchingGenericException") Exception e) { builder.error(ResultErrorBuilder.withException(e).build()); } return builder.build(); } }
@Override protected Result verifyConnectivity(Map<String, Object> parameters) { ResultBuilder builder = ResultBuilder.withStatusAndScope(Result.Status.OK, Scope.CONNECTIVITY); try { S3Configuration configuration = setProperties(new S3Configuration(), parameters); AWSCredentials credentials = new BasicAWSCredentials(configuration.getAccessKey(), configuration.getSecretKey()); AWSCredentialsProvider credentialsProvider = new AWSStaticCredentialsProvider(credentials); AmazonS3 client = AmazonS3ClientBuilder.standard().withCredentials(credentialsProvider).withRegion(Regions.valueOf(configuration.getRegion())).build(); client.listBuckets(); } catch (SdkClientException e) { ResultErrorBuilder errorBuilder = ResultErrorBuilder.withCodeAndDescription(VerificationError.StandardCode.AUTHENTICATION, e.getMessage()) .detail("aws_s3_exception_message", e.getMessage()).detail(VerificationError.ExceptionAttribute.EXCEPTION_CLASS, e.getClass().getName()) .detail(VerificationError.ExceptionAttribute.EXCEPTION_INSTANCE, e); builder.error(errorBuilder.build()); } catch (Exception e) { builder.error(ResultErrorBuilder.withException(e).build()); } return builder.build(); } }