com.amazonaws.services.s3.model.DeleteObjectsResult#com.amazonaws.SdkClientException源码实例Demo

下面列出了com.amazonaws.services.s3.model.DeleteObjectsResult#com.amazonaws.SdkClientException 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

public Request<DeleteApplicationRequest> marshall(DeleteApplicationRequest deleteApplicationRequest) {

        if (deleteApplicationRequest == null) {
            throw new SdkClientException("Invalid argument passed to marshall(...)");
        }

        try {
            final ProtocolRequestMarshaller<DeleteApplicationRequest> protocolMarshaller = protocolFactory.createProtocolMarshaller(SDK_OPERATION_BINDING,
                    deleteApplicationRequest);

            protocolMarshaller.startMarshalling();
            DeleteApplicationRequestMarshaller.getInstance().marshall(deleteApplicationRequest, protocolMarshaller);
            return protocolMarshaller.finishMarshalling();
        } catch (Exception e) {
            throw new SdkClientException("Unable to marshall request to JSON: " + e.getMessage(), e);
        }
    }
 
/**
 * Marshall the given parameter object.
 */
public void marshall(Application application, ProtocolMarshaller protocolMarshaller) {

    if (application == null) {
        throw new SdkClientException("Invalid argument passed to marshall(...)");
    }

    try {
        protocolMarshaller.marshall(application.getApplicationId(), APPLICATIONID_BINDING);
        protocolMarshaller.marshall(application.getAuthor(), AUTHOR_BINDING);
        protocolMarshaller.marshall(application.getCreationTime(), CREATIONTIME_BINDING);
        protocolMarshaller.marshall(application.getDescription(), DESCRIPTION_BINDING);
        protocolMarshaller.marshall(application.getHomePageUrl(), HOMEPAGEURL_BINDING);
    } catch (Exception e) {
        throw new SdkClientException("Unable to marshall request to JSON: " + e.getMessage(), e);
    }
}
 
public Request<UpdateApplicationRequest> marshall(UpdateApplicationRequest updateApplicationRequest) {

        if (updateApplicationRequest == null) {
            throw new SdkClientException("Invalid argument passed to marshall(...)");
        }

        try {
            final ProtocolRequestMarshaller<UpdateApplicationRequest> protocolMarshaller = protocolFactory.createProtocolMarshaller(SDK_OPERATION_BINDING,
                    updateApplicationRequest);

            protocolMarshaller.startMarshalling();
            UpdateApplicationRequestMarshaller.getInstance().marshall(updateApplicationRequest, protocolMarshaller);
            return protocolMarshaller.finishMarshalling();
        } catch (Exception e) {
            throw new SdkClientException("Unable to marshall request to JSON: " + e.getMessage(), e);
        }
    }
 
/**
 * Marshall the given parameter object.
 */
public void marshall(CreateApplicationInput createApplicationInput, ProtocolMarshaller protocolMarshaller) {

    if (createApplicationInput == null) {
        throw new SdkClientException("Invalid argument passed to marshall(...)");
    }

    try {
        protocolMarshaller.marshall(createApplicationInput.getApplicationId(), APPLICATIONID_BINDING);
        protocolMarshaller.marshall(createApplicationInput.getAuthor(), AUTHOR_BINDING);
        protocolMarshaller.marshall(createApplicationInput.getDescription(), DESCRIPTION_BINDING);
        protocolMarshaller.marshall(createApplicationInput.getHomePageUrl(), HOMEPAGEURL_BINDING);
    } catch (Exception e) {
        throw new SdkClientException("Unable to marshall request to JSON: " + e.getMessage(), e);
    }
}
 
@Test
public void testInitIncorrectRegion() throws Exception {
  String region = "us-west-2";
  String awsAccessKey = "access-key";
  String awsSecretKey = "secret-key";

  CredentialStore.Context context = Mockito.mock(CredentialStore.Context.class);
  Mockito.when(context.getConfig(AWSSecretsManagerCredentialStore.AWS_REGION_PROP)).thenReturn(region);
  Mockito.when(context.getConfig(AWSSecretsManagerCredentialStore.AWS_ACCESS_KEY_PROP)).thenReturn(awsAccessKey);
  Mockito.when(context.getConfig(AWSSecretsManagerCredentialStore.AWS_SECRET_KEY_PROP)).thenReturn(awsSecretKey);

  SecretCache secretCache = Mockito.mock(SecretCache.class);
  SdkClientException exception = new SdkClientException("message");
  AWSSecretsManagerCredentialStore secretManager = createAWSSecretsManagerCredentialStore(secretCache, exception);
  List<CredentialStore.ConfigIssue> issues = secretManager.init(context);
  Assert.assertEquals(1, issues.size());
  Mockito.verify(context, Mockito.times(1)).createConfigIssue(
      Errors.AWS_SECRETS_MANAGER_CRED_STORE_01,
      exception.getMessage(),
      exception
  );
}
 
public Request<UpdateApplicationRequest> marshall(UpdateApplicationRequest updateApplicationRequest) {

    if (updateApplicationRequest == null) {
      throw new SdkClientException("Invalid argument passed to marshall(...)");
    }

    try {
      final ProtocolRequestMarshaller<UpdateApplicationRequest> protocolMarshaller = protocolFactory.createProtocolMarshaller(SDK_OPERATION_BINDING,
              updateApplicationRequest);

      protocolMarshaller.startMarshalling();
      UpdateApplicationRequestMarshaller.getInstance().marshall(updateApplicationRequest, protocolMarshaller);
      return protocolMarshaller.finishMarshalling();
    } catch (Exception e) {
      throw new SdkClientException("Unable to marshall request to JSON: " + e.getMessage(), e);
    }
  }
 
源代码7 项目: cloudbreak   文件: AwsInstanceConnector.java
@Retryable(
        value = SdkClientException.class,
        maxAttempts = 15,
        backoff = @Backoff(delay = 1000, multiplier = 2, maxDelay = 10000)
)
@Override
public List<CloudVmInstanceStatus> reboot(AuthenticatedContext ac, List<CloudInstance> vms) {
    AmazonEC2Client amazonEC2Client = awsClient.createAccess(new AwsCredentialView(ac.getCloudCredential()),
            ac.getCloudContext().getLocation().getRegion().value());
    List<CloudInstance> affectedVms = new ArrayList<>();
    try {
        if (!vms.isEmpty()) {
            List<CloudVmInstanceStatus> statuses = check(ac, vms);
            doReboot(affectedVms, amazonEC2Client, getStarted(statuses));
            doStart(affectedVms, ac, getStopped(statuses));
            logInvalidStatuses(getNotStoppedOrStarted(statuses));
        }
    } catch (SdkClientException e) {
        LOGGER.warn("Failed to send reboot request to AWS: ", e);
        throw e;
    }
    return pollerUtil.waitFor(ac, affectedVms, Sets.newHashSet(InstanceStatus.STARTED, InstanceStatus.FAILED));
}
 
@Override
public AWSCredentials getCredentials() {
    String accessKey = environment.getProperty(ACCESS_KEY_ENV_VAR, String.class, environment.getProperty(ALTERNATE_ACCESS_KEY_ENV_VAR, String.class, (String) null));

    String secretKey = environment.getProperty(SECRET_KEY_ENV_VAR, String.class, environment.getProperty(ALTERNATE_SECRET_KEY_ENV_VAR, String.class, (String) null));
    accessKey = StringUtils.trim(accessKey);
    secretKey = StringUtils.trim(secretKey);
    String sessionToken = StringUtils.trim(environment.getProperty(AWS_SESSION_TOKEN_ENV_VAR, String.class, (String) null));

    if (StringUtils.isNullOrEmpty(accessKey) || StringUtils.isNullOrEmpty(secretKey)) {
        throw new SdkClientException(
            "Unable to load AWS credentials from environment " +
                "(" + ACCESS_KEY_ENV_VAR + " (or " + ALTERNATE_ACCESS_KEY_ENV_VAR + ") and " +
                SECRET_KEY_ENV_VAR + " (or " + ALTERNATE_SECRET_KEY_ENV_VAR + "))");
    }

    return sessionToken == null ?
        new BasicAWSCredentials(accessKey, secretKey)
        :
        new BasicSessionCredentials(accessKey, secretKey, sessionToken);
}
 
源代码9 项目: aws-codebuild-jenkins-plugin   文件: Validation.java
public static AWSCredentialsProvider getBasicCredentialsOrDefaultChain(String accessKey, String secretKey, String awsSessionToken) {
    AWSCredentialsProvider result;
    if (StringUtils.isNotEmpty(accessKey) && StringUtils.isNotEmpty(secretKey) && StringUtils.isNotEmpty(awsSessionToken)) {
        result = new AWSStaticCredentialsProvider(new BasicSessionCredentials(accessKey, secretKey, awsSessionToken));
    }
    else if (StringUtils.isNotEmpty(accessKey) && StringUtils.isNotEmpty(secretKey)) {
        result = new AWSStaticCredentialsProvider(new BasicAWSCredentials(accessKey, secretKey));
    } else {
        result = DefaultAWSCredentialsProviderChain.getInstance();
        try {
            result.getCredentials();
        } catch (SdkClientException e) {
            throw new InvalidInputException(invalidDefaultCredentialsError);
        }
    }
    return result;
}
 
源代码10 项目: nexus-public   文件: ParallelUploader.java
@Override
public void upload(final AmazonS3 s3, final String bucket, final String key, final InputStream contents) {
  try (InputStream input = new BufferedInputStream(contents, chunkSize)) {
    log.debug("Starting upload to key {} in bucket {}", key, bucket);

    input.mark(chunkSize);
    ChunkReader chunkReader = new ChunkReader(input);
    Chunk chunk = chunkReader.readChunk(chunkSize).orElse(EMPTY_CHUNK);
    input.reset();

    if (chunk.dataLength < chunkSize) {
      ObjectMetadata metadata = new ObjectMetadata();
      metadata.setContentLength(chunk.dataLength);
      s3.putObject(bucket, key, new ByteArrayInputStream(chunk.data, 0, chunk.dataLength), metadata);
    }
    else {
      ChunkReader parallelReader = new ChunkReader(input);
      parallelRequests(s3, bucket, key,
          () -> (uploadId -> uploadChunks(s3, bucket, key, uploadId, parallelReader)));
    }
    log.debug("Finished upload to key {} in bucket {}", key, bucket);
  }
  catch (IOException | SdkClientException e) { // NOSONAR
    throw new BlobStoreException(format("Error uploading blob to bucket:%s key:%s", bucket, key), e, null);
  }
}
 
源代码11 项目: cloudbreak   文件: AwsValidatorsTest.java
@Test
public void testStackValidatorStackUseRetryClient() {
    doReturn(amazonCloudFormationClient).when(awsClient).createCloudFormationClient(any(), anyString());
    when(amazonCloudFormationClient.describeStacks(any()))
            .thenThrow(new SdkClientException("repeat1 Rate exceeded"))
            .thenThrow(new SdkClientException("repeat2Request limit exceeded"))
            .thenReturn(null);
    Assertions.assertThrows(CloudConnectorException.class, () -> awsStackValidatorUnderTest.validate(authenticatedContext, null));
    verify(amazonCloudFormationClient, times(3)).describeStacks(any());
}
 
/**
 * Marshall the given parameter object.
 */
public void marshall(ApplicationList applicationList, ProtocolMarshaller protocolMarshaller) {

    if (applicationList == null) {
        throw new SdkClientException("Invalid argument passed to marshall(...)");
    }

    try {
        protocolMarshaller.marshall(applicationList.getApplications(), APPLICATIONS_BINDING);
        protocolMarshaller.marshall(applicationList.getNextToken(), NEXTTOKEN_BINDING);
    } catch (Exception e) {
        throw new SdkClientException("Unable to marshall request to JSON: " + e.getMessage(), e);
    }
}
 
/**
 * Marshall the given parameter object.
 */
public void marshall(UpdateApplicationInput updateApplicationInput, ProtocolMarshaller protocolMarshaller) {

    if (updateApplicationInput == null) {
        throw new SdkClientException("Invalid argument passed to marshall(...)");
    }

    try {
        protocolMarshaller.marshall(updateApplicationInput.getAuthor(), AUTHOR_BINDING);
        protocolMarshaller.marshall(updateApplicationInput.getDescription(), DESCRIPTION_BINDING);
        protocolMarshaller.marshall(updateApplicationInput.getHomePageUrl(), HOMEPAGEURL_BINDING);
    } catch (Exception e) {
        throw new SdkClientException("Unable to marshall request to JSON: " + e.getMessage(), e);
    }
}
 
/**
 * Marshall the given parameter object.
 */
public void marshall(CreateApplicationRequest createApplicationRequest, ProtocolMarshaller protocolMarshaller) {

    if (createApplicationRequest == null) {
        throw new SdkClientException("Invalid argument passed to marshall(...)");
    }

    try {
        protocolMarshaller.marshall(createApplicationRequest.getCreateApplicationInput(), CREATEAPPLICATIONINPUT_BINDING);
    } catch (Exception e) {
        throw new SdkClientException("Unable to marshall request to JSON: " + e.getMessage(), e);
    }
}
 
/**
 * Marshall the given parameter object.
 */
public void marshall(ApplicationSummary applicationSummary, ProtocolMarshaller protocolMarshaller) {

    if (applicationSummary == null) {
        throw new SdkClientException("Invalid argument passed to marshall(...)");
    }

    try {
        protocolMarshaller.marshall(applicationSummary.getApplicationId(), APPLICATIONID_BINDING);
        protocolMarshaller.marshall(applicationSummary.getCreationTime(), CREATIONTIME_BINDING);
        protocolMarshaller.marshall(applicationSummary.getDescription(), DESCRIPTION_BINDING);
    } catch (Exception e) {
        throw new SdkClientException("Unable to marshall request to JSON: " + e.getMessage(), e);
    }
}
 
/**
 * Marshall the given parameter object.
 */
public void marshall(ApplicationList applicationList, ProtocolMarshaller protocolMarshaller) {

  if (applicationList == null) {
    throw new SdkClientException("Invalid argument passed to marshall(...)");
  }

  try {
    protocolMarshaller.marshall(applicationList.getApplications(), APPLICATIONS_BINDING);
    protocolMarshaller.marshall(applicationList.getNextToken(), NEXTTOKEN_BINDING);
  } catch (Exception e) {
    throw new SdkClientException("Unable to marshall request to JSON: " + e.getMessage(), e);
  }
}
 
源代码17 项目: cloudbreak   文件: CloudFormationStackUtil.java
@Retryable(
        value = SdkClientException.class,
        maxAttempts = 15,
        backoff = @Backoff(delay = 1000, multiplier = 2, maxDelay = 10000)
)
public String getAutoscalingGroupName(AuthenticatedContext ac, AmazonCloudFormationRetryClient amazonCFClient, String instanceGroup) {
    String cFStackName = getCfStackName(ac);
    DescribeStackResourceResult asGroupResource = amazonCFClient.describeStackResource(new DescribeStackResourceRequest()
            .withStackName(cFStackName)
            .withLogicalResourceId(String.format("AmbariNodes%s", instanceGroup.replaceAll("_", ""))));
    return asGroupResource.getStackResourceDetail().getPhysicalResourceId();
}
 
/**
 * Marshall the given parameter object.
 */
public void marshall(UpdateApplicationInput updateApplicationInput, ProtocolMarshaller protocolMarshaller) {

  if (updateApplicationInput == null) {
    throw new SdkClientException("Invalid argument passed to marshall(...)");
  }

  try {
    protocolMarshaller.marshall(updateApplicationInput.getAuthor(), AUTHOR_BINDING);
    protocolMarshaller.marshall(updateApplicationInput.getDescription(), DESCRIPTION_BINDING);
    protocolMarshaller.marshall(updateApplicationInput.getHomePageUrl(), HOMEPAGEURL_BINDING);
  } catch (Exception e) {
    throw new SdkClientException("Unable to marshall request to JSON: " + e.getMessage(), e);
  }
}
 
/**
 * Marshall the given parameter object.
 */
public void marshall(ApplicationSummary applicationSummary, ProtocolMarshaller protocolMarshaller) {

  if (applicationSummary == null) {
    throw new SdkClientException("Invalid argument passed to marshall(...)");
  }

  try {
    protocolMarshaller.marshall(applicationSummary.getApplicationId(), APPLICATIONID_BINDING);
    protocolMarshaller.marshall(applicationSummary.getCreationTime(), CREATIONTIME_BINDING);
    protocolMarshaller.marshall(applicationSummary.getDescription(), DESCRIPTION_BINDING);
  } catch (Exception e) {
    throw new SdkClientException("Unable to marshall request to JSON: " + e.getMessage(), e);
  }
}
 
/**
 * Marshall the given parameter object.
 */
public void marshall(GetApplicationRequest getApplicationRequest, ProtocolMarshaller protocolMarshaller) {

  if (getApplicationRequest == null) {
    throw new SdkClientException("Invalid argument passed to marshall(...)");
  }

  try {
    protocolMarshaller.marshall(getApplicationRequest.getApplicationId(), APPLICATIONID_BINDING);
  } catch (Exception e) {
    throw new SdkClientException("Unable to marshall request to JSON: " + e.getMessage(), e);
  }
}
 
/**
 * Marshall the given parameter object.
 */
public void marshall(ListApplicationsRequest listApplicationsRequest, ProtocolMarshaller protocolMarshaller) {

  if (listApplicationsRequest == null) {
    throw new SdkClientException("Invalid argument passed to marshall(...)");
  }

  try {
    protocolMarshaller.marshall(listApplicationsRequest.getMaxItems(), MAXITEMS_BINDING);
    protocolMarshaller.marshall(listApplicationsRequest.getNextToken(), NEXTTOKEN_BINDING);
  } catch (Exception e) {
    throw new SdkClientException("Unable to marshall request to JSON: " + e.getMessage(), e);
  }
}
 
源代码22 项目: Flink-CEPplus   文件: KinesisProxy.java
/**
 * Determines whether the exception is recoverable using exponential-backoff.
 *
 * @param ex Exception to inspect
 * @return <code>true</code> if the exception can be recovered from, else
 *         <code>false</code>
 */
protected boolean isRecoverableSdkClientException(SdkClientException ex) {
	if (ex instanceof AmazonServiceException) {
		return KinesisProxy.isRecoverableException((AmazonServiceException) ex);
	}
	// customizations may decide to retry other errors, such as read timeouts
	return false;
}
 
/**
 * 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)
 * @throws SdkClientException If the aws sdk client could not be created
 */
AWSParameterStoreConfigClient(
        AWSClientConfiguration awsConfiguration,
        AWSParameterStoreConfiguration awsParameterStoreConfiguration,
        ApplicationConfiguration applicationConfiguration,
        @Nullable Route53ClientDiscoveryConfiguration route53ClientDiscoveryConfiguration) throws SdkClientException {
    this.awsConfiguration = awsConfiguration;
    this.awsParameterStoreConfiguration = awsParameterStoreConfiguration;
    this.client = AWSSimpleSystemsManagementAsyncClient.asyncBuilder().withClientConfiguration(awsConfiguration.getClientConfiguration()).build();
    this.serviceId = (route53ClientDiscoveryConfiguration != null ? route53ClientDiscoveryConfiguration.getServiceId() : applicationConfiguration.getName()).orElse(null);
}
 
private static Publisher<? extends GetParametersResult> onGetParametersError(Throwable throwable) {
    if (throwable instanceof SdkClientException) {
        return Flowable.error(throwable);
    } else {
        return Flowable.error(new ConfigurationException("Error reading distributed configuration from AWS Parameter Store: " + throwable.getMessage(), throwable));
    }
}
 
private static Publisher<? extends GetParametersByPathResult> onGetParametersByPathResult(Throwable throwable) {
    if (throwable instanceof SdkClientException) {
        return Flowable.error(throwable);
    } else {
        return Flowable.error(new ConfigurationException("Error reading distributed configuration from AWS Parameter Store: " + throwable.getMessage(), throwable));
    }
}
 
@Override
public AWSCredentials getCredentials() {
  try {
    return super.getCredentials();
  } catch (final SdkClientException exception) {

  }
  // fall back to anonymous credentials
  return new AnonymousAWSCredentials();
}
 
@Test(expectedExceptions = {SdkClientException.class})
public void exceptionSecretCacheConfigTest() {
    try (SecretCache sc = new SecretCache(new SecretCacheConfiguration()
            .withCacheItemTTL(SecretCacheConfiguration.DEFAULT_CACHE_ITEM_TTL)
            .withMaxCacheSize(SecretCacheConfiguration.DEFAULT_MAX_CACHE_SIZE)
            .withVersionStage(SecretCacheConfiguration.DEFAULT_VERSION_STAGE))) {
        sc.getSecretString("");
    }
}
 
private AmazonS3 createS3Client(AwsS3BuildCache config) {
  AmazonS3 s3;
  try {
    AmazonS3ClientBuilder s3Builder = AmazonS3ClientBuilder.standard();
    if (!isNullOrEmpty(config.getAwsAccessKeyId()) && !isNullOrEmpty(config.getAwsSecretKey()) &&
              !isNullOrEmpty(config.getSessionToken())) {
          s3Builder.withCredentials(new AWSStaticCredentialsProvider(
                  new BasicSessionCredentials(config.getAwsAccessKeyId(), config.getAwsSecretKey(),
                          config.getSessionToken())));
    } else if (!isNullOrEmpty(config.getAwsAccessKeyId()) && !isNullOrEmpty(config.getAwsSecretKey())) {
      s3Builder.withCredentials(new AWSStaticCredentialsProvider(
          new BasicAWSCredentials(config.getAwsAccessKeyId(), config.getAwsSecretKey())));
    }

    addHttpHeaders(s3Builder, config);

    if (isNullOrEmpty(config.getEndpoint())) {
      s3Builder.withRegion(config.getRegion());
    } else {
      s3Builder.withEndpointConfiguration(
          new AwsClientBuilder.EndpointConfiguration(config.getEndpoint(), config.getRegion()));
    }
    s3 = s3Builder.build();
  } catch (SdkClientException e) {
    logger.debug("Error while building AWS S3 client: {}", e.getMessage());
    throw new GradleException("Creation of S3 build cache failed; cannot create S3 client", e);
  }
  return s3;
}
 
源代码29 项目: aws-xray-sdk-java   文件: UnsignedXrayClient.java
/**
 * Parses the given date string returned by the AWS service into a Date
 * object.
 */
private static Date parseServiceSpecificDate(String dateString) {
    try {
        BigDecimal dateValue = new BigDecimal(dateString);
        return new Date(dateValue.scaleByPowerOfTen(AWS_DATE_MILLI_SECOND_PRECISION).longValue());
    } catch (NumberFormatException nfe) {
        throw new SdkClientException("Unable to parse date : " + dateString, nfe);
    }
}
 
源代码30 项目: strongbox   文件: CustomRegionProviderChain.java
private Optional<Region> getRegionFromMetadata() {
    try {
        Region resolvedRegion = null;
        if (EC2MetadataUtils.getInstanceInfo() != null) {
            if (EC2MetadataUtils.getInstanceInfo().getRegion() != null) {
                resolvedRegion = Region.fromName(EC2MetadataUtils.getInstanceInfo().getRegion());
            } else { // fallback to provider chain if region is not exposed
                resolvedRegion = Region.fromName(new DefaultAwsRegionProviderChain().getRegion());
            }
        }
        return Optional.ofNullable(resolvedRegion);
    } catch (SdkClientException e) {
        return Optional.empty();
    }
}