com.amazonaws.SdkBaseException Java Examples

The following examples show how to use com.amazonaws.SdkBaseException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AWSServerlessApplicationRepositoryClient.java    From realworld-serverless-application with Apache License 2.0 6 votes vote down vote up
/**
 * @param deleteApplicationRequest
 * @return Result of the DeleteApplication operation returned by the service.
 * @throws NotFoundException
 * @throws TooManyRequestsException
 * @throws BadRequestException
 * @throws UnauthorizedException
 * @throws InternalServerErrorException
 * @sample AWSServerlessApplicationRepository.DeleteApplication
 * @see <a href="http://docs.aws.amazon.com/goto/WebAPI/k9zlvhl83e-1570924800000/DeleteApplication"
 *      target="_top">AWS API Documentation</a>
 */
@Override
public DeleteApplicationResult deleteApplication(DeleteApplicationRequest deleteApplicationRequest) {
    HttpResponseHandler<DeleteApplicationResult> responseHandler = protocolFactory.createResponseHandler(new JsonOperationMetadata().withPayloadJson(true)
            .withHasStreamingSuccessResponse(false), new DeleteApplicationResultJsonUnmarshaller());

    HttpResponseHandler<SdkBaseException> errorResponseHandler = createErrorResponseHandler(
            new JsonErrorShapeMetadata().withModeledClass(NotFoundException.class).withHttpStatusCode(404),
            new JsonErrorShapeMetadata().withModeledClass(TooManyRequestsException.class).withHttpStatusCode(429), new JsonErrorShapeMetadata()
                    .withModeledClass(BadRequestException.class).withHttpStatusCode(400),
            new JsonErrorShapeMetadata().withModeledClass(UnauthorizedException.class).withHttpStatusCode(401), new JsonErrorShapeMetadata()
                    .withModeledClass(InternalServerErrorException.class).withHttpStatusCode(500));

    return clientHandler.execute(new ClientExecutionParams<DeleteApplicationRequest, DeleteApplicationResult>()
            .withMarshaller(new DeleteApplicationRequestProtocolMarshaller(protocolFactory)).withResponseHandler(responseHandler)
            .withErrorResponseHandler(errorResponseHandler).withInput(deleteApplicationRequest));
}
 
Example #2
Source File: AwsCredentialConnectorTest.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
@Test
public void testVerifyIfRoleBasedCredentialVerificationThrowsSdkBaseExceptionThenFailedStatusShouldReturn() throws AwsPermissionMissingException {
    String roleArn = "someRoleArn";
    when(credentialView.getRoleArn()).thenReturn(roleArn);

    String exceptionMessageComesFromSdk = "SomethingTerribleHappened!";
    Exception sdkException = new SdkBaseException(exceptionMessageComesFromSdk);

    doThrow(sdkException).when(awsCredentialVerifier).validateAws(credentialView);
    CloudCredentialStatus result = underTest.verify(authenticatedContext);

    assertNotNull(result);
    assertEquals(CredentialStatus.FAILED, result.getStatus());
    assertEquals(exceptionMessageComesFromSdk, result.getStatusReason());
    assertEquals(sdkException, result.getException());

    verify(awsCredentialVerifier, times(1)).validateAws(any());
    verify(awsCredentialVerifier, times(1)).validateAws(credentialView);
}
 
Example #3
Source File: AWSServerlessApplicationRepositoryClient.java    From realworld-serverless-application with Apache License 2.0 6 votes vote down vote up
/**
 * @param updateApplicationRequest
 * @return Result of the UpdateApplication operation returned by the service.
 * @throws NotFoundException
 * @throws TooManyRequestsException
 * @throws BadRequestException
 * @throws UnauthorizedException
 * @throws InternalServerErrorException
 * @sample AWSServerlessApplicationRepository.UpdateApplication
 * @see <a href="http://docs.aws.amazon.com/goto/WebAPI/xxx-2019-10-13/UpdateApplication"
 *      target="_top">AWS API Documentation</a>
 */
@Override
public UpdateApplicationResult updateApplication(UpdateApplicationRequest updateApplicationRequest) {
  HttpResponseHandler<UpdateApplicationResult> responseHandler = protocolFactory.createResponseHandler(new JsonOperationMetadata().withPayloadJson(true)
          .withHasStreamingSuccessResponse(false), new UpdateApplicationResultJsonUnmarshaller());

  HttpResponseHandler<SdkBaseException> errorResponseHandler = createErrorResponseHandler(
          new JsonErrorShapeMetadata().withModeledClass(NotFoundException.class).withHttpStatusCode(404),
          new JsonErrorShapeMetadata().withModeledClass(TooManyRequestsException.class).withHttpStatusCode(429), new JsonErrorShapeMetadata()
                  .withModeledClass(BadRequestException.class).withHttpStatusCode(400),
          new JsonErrorShapeMetadata().withModeledClass(UnauthorizedException.class).withHttpStatusCode(401), new JsonErrorShapeMetadata()
                  .withModeledClass(InternalServerErrorException.class).withHttpStatusCode(500));

  return clientHandler.execute(new ClientExecutionParams<UpdateApplicationRequest, UpdateApplicationResult>()
          .withMarshaller(new UpdateApplicationRequestProtocolMarshaller(protocolFactory)).withResponseHandler(responseHandler)
          .withErrorResponseHandler(errorResponseHandler).withInput(updateApplicationRequest));
}
 
Example #4
Source File: AWSServerlessApplicationRepositoryClient.java    From realworld-serverless-application with Apache License 2.0 6 votes vote down vote up
/**
 * @param listApplicationsRequest
 * @return Result of the ListApplications operation returned by the service.
 * @throws TooManyRequestsException
 * @throws BadRequestException
 * @throws UnauthorizedException
 * @throws InternalServerErrorException
 * @sample AWSServerlessApplicationRepository.ListApplications
 * @see <a href="http://docs.aws.amazon.com/goto/WebAPI/xxx-2019-10-13/ListApplications" target="_top">AWS
 *      API Documentation</a>
 */
@Override
public ListApplicationsResult listApplications(ListApplicationsRequest listApplicationsRequest) {
  HttpResponseHandler<ListApplicationsResult> responseHandler = protocolFactory.createResponseHandler(new JsonOperationMetadata().withPayloadJson(true)
          .withHasStreamingSuccessResponse(false), new ListApplicationsResultJsonUnmarshaller());

  HttpResponseHandler<SdkBaseException> errorResponseHandler = createErrorResponseHandler(
          new JsonErrorShapeMetadata().withModeledClass(TooManyRequestsException.class).withHttpStatusCode(429), new JsonErrorShapeMetadata()
                  .withModeledClass(BadRequestException.class).withHttpStatusCode(400),
          new JsonErrorShapeMetadata().withModeledClass(UnauthorizedException.class).withHttpStatusCode(401), new JsonErrorShapeMetadata()
                  .withModeledClass(InternalServerErrorException.class).withHttpStatusCode(500));

  return clientHandler.execute(new ClientExecutionParams<ListApplicationsRequest, ListApplicationsResult>()
          .withMarshaller(new ListApplicationsRequestProtocolMarshaller(protocolFactory)).withResponseHandler(responseHandler)
          .withErrorResponseHandler(errorResponseHandler).withInput(listApplicationsRequest));
}
 
Example #5
Source File: AWSServerlessApplicationRepositoryClient.java    From realworld-serverless-application with Apache License 2.0 6 votes vote down vote up
/**
 * @param getApplicationRequest
 * @return Result of the GetApplication operation returned by the service.
 * @throws NotFoundException
 * @throws TooManyRequestsException
 * @throws BadRequestException
 * @throws UnauthorizedException
 * @throws InternalServerErrorException
 * @sample AWSServerlessApplicationRepository.GetApplication
 * @see <a href="http://docs.aws.amazon.com/goto/WebAPI/xxx-2019-10-13/GetApplication" target="_top">AWS
 *      API Documentation</a>
 */
@Override
public GetApplicationResult getApplication(GetApplicationRequest getApplicationRequest) {
  HttpResponseHandler<GetApplicationResult> responseHandler = protocolFactory.createResponseHandler(new JsonOperationMetadata().withPayloadJson(true)
          .withHasStreamingSuccessResponse(false), new GetApplicationResultJsonUnmarshaller());

  HttpResponseHandler<SdkBaseException> errorResponseHandler = createErrorResponseHandler(
          new JsonErrorShapeMetadata().withModeledClass(NotFoundException.class).withHttpStatusCode(404),
          new JsonErrorShapeMetadata().withModeledClass(TooManyRequestsException.class).withHttpStatusCode(429), new JsonErrorShapeMetadata()
                  .withModeledClass(BadRequestException.class).withHttpStatusCode(400),
          new JsonErrorShapeMetadata().withModeledClass(UnauthorizedException.class).withHttpStatusCode(401), new JsonErrorShapeMetadata()
                  .withModeledClass(InternalServerErrorException.class).withHttpStatusCode(500));

  return clientHandler.execute(new ClientExecutionParams<GetApplicationRequest, GetApplicationResult>()
          .withMarshaller(new GetApplicationRequestProtocolMarshaller(protocolFactory)).withResponseHandler(responseHandler)
          .withErrorResponseHandler(errorResponseHandler).withInput(getApplicationRequest));
}
 
Example #6
Source File: AWSServerlessApplicationRepositoryClient.java    From realworld-serverless-application with Apache License 2.0 6 votes vote down vote up
/**
 * @param deleteApplicationRequest
 * @return Result of the DeleteApplication operation returned by the service.
 * @throws NotFoundException
 * @throws TooManyRequestsException
 * @throws BadRequestException
 * @throws UnauthorizedException
 * @throws InternalServerErrorException
 * @sample AWSServerlessApplicationRepository.DeleteApplication
 * @see <a href="http://docs.aws.amazon.com/goto/WebAPI/xxx-2019-10-13/DeleteApplication"
 *      target="_top">AWS API Documentation</a>
 */
@Override
public DeleteApplicationResult deleteApplication(DeleteApplicationRequest deleteApplicationRequest) {
  HttpResponseHandler<DeleteApplicationResult> responseHandler = protocolFactory.createResponseHandler(new JsonOperationMetadata().withPayloadJson(true)
          .withHasStreamingSuccessResponse(false), new DeleteApplicationResultJsonUnmarshaller());

  HttpResponseHandler<SdkBaseException> errorResponseHandler = createErrorResponseHandler(
          new JsonErrorShapeMetadata().withModeledClass(NotFoundException.class).withHttpStatusCode(404),
          new JsonErrorShapeMetadata().withModeledClass(TooManyRequestsException.class).withHttpStatusCode(429), new JsonErrorShapeMetadata()
                  .withModeledClass(BadRequestException.class).withHttpStatusCode(400),
          new JsonErrorShapeMetadata().withModeledClass(UnauthorizedException.class).withHttpStatusCode(401), new JsonErrorShapeMetadata()
                  .withModeledClass(InternalServerErrorException.class).withHttpStatusCode(500));

  return clientHandler.execute(new ClientExecutionParams<DeleteApplicationRequest, DeleteApplicationResult>()
          .withMarshaller(new DeleteApplicationRequestProtocolMarshaller(protocolFactory)).withResponseHandler(responseHandler)
          .withErrorResponseHandler(errorResponseHandler).withInput(deleteApplicationRequest));
}
 
Example #7
Source File: AWSServerlessApplicationRepositoryClient.java    From realworld-serverless-application with Apache License 2.0 6 votes vote down vote up
/**
 * @param createApplicationRequest
 * @return Result of the CreateApplication operation returned by the service.
 * @throws TooManyRequestsException
 * @throws BadRequestException
 * @throws UnauthorizedException
 * @throws InternalServerErrorException
 * @throws ConflictException
 * @sample AWSServerlessApplicationRepository.CreateApplication
 * @see <a href="http://docs.aws.amazon.com/goto/WebAPI/xxx-2019-10-13/CreateApplication"
 *      target="_top">AWS API Documentation</a>
 */
@Override
public CreateApplicationResult createApplication(CreateApplicationRequest createApplicationRequest) {
  HttpResponseHandler<CreateApplicationResult> responseHandler = protocolFactory.createResponseHandler(new JsonOperationMetadata().withPayloadJson(true)
          .withHasStreamingSuccessResponse(false), new CreateApplicationResultJsonUnmarshaller());

  HttpResponseHandler<SdkBaseException> errorResponseHandler = createErrorResponseHandler(
          new JsonErrorShapeMetadata().withModeledClass(TooManyRequestsException.class).withHttpStatusCode(429), new JsonErrorShapeMetadata()
                  .withModeledClass(BadRequestException.class).withHttpStatusCode(400),
          new JsonErrorShapeMetadata().withModeledClass(UnauthorizedException.class).withHttpStatusCode(401), new JsonErrorShapeMetadata()
                  .withModeledClass(InternalServerErrorException.class).withHttpStatusCode(500),
          new JsonErrorShapeMetadata().withModeledClass(ConflictException.class).withHttpStatusCode(409));

  return clientHandler.execute(new ClientExecutionParams<CreateApplicationRequest, CreateApplicationResult>()
          .withMarshaller(new CreateApplicationRequestProtocolMarshaller(protocolFactory)).withResponseHandler(responseHandler)
          .withErrorResponseHandler(errorResponseHandler).withInput(createApplicationRequest));
}
 
Example #8
Source File: AWSServerlessApplicationRepositoryClient.java    From realworld-serverless-application with Apache License 2.0 6 votes vote down vote up
/**
 * @param updateApplicationRequest
 * @return Result of the UpdateApplication operation returned by the service.
 * @throws NotFoundException
 * @throws TooManyRequestsException
 * @throws BadRequestException
 * @throws UnauthorizedException
 * @throws InternalServerErrorException
 * @sample AWSServerlessApplicationRepository.UpdateApplication
 * @see <a href="http://docs.aws.amazon.com/goto/WebAPI/k9zlvhl83e-1570924800000/UpdateApplication"
 *      target="_top">AWS API Documentation</a>
 */
@Override
public UpdateApplicationResult updateApplication(UpdateApplicationRequest updateApplicationRequest) {
    HttpResponseHandler<UpdateApplicationResult> responseHandler = protocolFactory.createResponseHandler(new JsonOperationMetadata().withPayloadJson(true)
            .withHasStreamingSuccessResponse(false), new UpdateApplicationResultJsonUnmarshaller());

    HttpResponseHandler<SdkBaseException> errorResponseHandler = createErrorResponseHandler(
            new JsonErrorShapeMetadata().withModeledClass(NotFoundException.class).withHttpStatusCode(404),
            new JsonErrorShapeMetadata().withModeledClass(TooManyRequestsException.class).withHttpStatusCode(429), new JsonErrorShapeMetadata()
                    .withModeledClass(BadRequestException.class).withHttpStatusCode(400),
            new JsonErrorShapeMetadata().withModeledClass(UnauthorizedException.class).withHttpStatusCode(401), new JsonErrorShapeMetadata()
                    .withModeledClass(InternalServerErrorException.class).withHttpStatusCode(500));

    return clientHandler.execute(new ClientExecutionParams<UpdateApplicationRequest, UpdateApplicationResult>()
            .withMarshaller(new UpdateApplicationRequestProtocolMarshaller(protocolFactory)).withResponseHandler(responseHandler)
            .withErrorResponseHandler(errorResponseHandler).withInput(updateApplicationRequest));
}
 
Example #9
Source File: AWSServerlessApplicationRepositoryClient.java    From realworld-serverless-application with Apache License 2.0 6 votes vote down vote up
/**
 * @param listApplicationsRequest
 * @return Result of the ListApplications operation returned by the service.
 * @throws TooManyRequestsException
 * @throws BadRequestException
 * @throws UnauthorizedException
 * @throws InternalServerErrorException
 * @sample AWSServerlessApplicationRepository.ListApplications
 * @see <a href="http://docs.aws.amazon.com/goto/WebAPI/k9zlvhl83e-1570924800000/ListApplications" target="_top">AWS
 *      API Documentation</a>
 */
@Override
public ListApplicationsResult listApplications(ListApplicationsRequest listApplicationsRequest) {
    HttpResponseHandler<ListApplicationsResult> responseHandler = protocolFactory.createResponseHandler(new JsonOperationMetadata().withPayloadJson(true)
            .withHasStreamingSuccessResponse(false), new ListApplicationsResultJsonUnmarshaller());

    HttpResponseHandler<SdkBaseException> errorResponseHandler = createErrorResponseHandler(
            new JsonErrorShapeMetadata().withModeledClass(TooManyRequestsException.class).withHttpStatusCode(429), new JsonErrorShapeMetadata()
                    .withModeledClass(BadRequestException.class).withHttpStatusCode(400),
            new JsonErrorShapeMetadata().withModeledClass(UnauthorizedException.class).withHttpStatusCode(401), new JsonErrorShapeMetadata()
                    .withModeledClass(InternalServerErrorException.class).withHttpStatusCode(500));

    return clientHandler.execute(new ClientExecutionParams<ListApplicationsRequest, ListApplicationsResult>()
            .withMarshaller(new ListApplicationsRequestProtocolMarshaller(protocolFactory)).withResponseHandler(responseHandler)
            .withErrorResponseHandler(errorResponseHandler).withInput(listApplicationsRequest));
}
 
Example #10
Source File: AWSServerlessApplicationRepositoryClient.java    From realworld-serverless-application with Apache License 2.0 6 votes vote down vote up
/**
 * @param getApplicationRequest
 * @return Result of the GetApplication operation returned by the service.
 * @throws NotFoundException
 * @throws TooManyRequestsException
 * @throws BadRequestException
 * @throws UnauthorizedException
 * @throws InternalServerErrorException
 * @sample AWSServerlessApplicationRepository.GetApplication
 * @see <a href="http://docs.aws.amazon.com/goto/WebAPI/k9zlvhl83e-1570924800000/GetApplication" target="_top">AWS
 *      API Documentation</a>
 */
@Override
public GetApplicationResult getApplication(GetApplicationRequest getApplicationRequest) {
    HttpResponseHandler<GetApplicationResult> responseHandler = protocolFactory.createResponseHandler(new JsonOperationMetadata().withPayloadJson(true)
            .withHasStreamingSuccessResponse(false), new GetApplicationResultJsonUnmarshaller());

    HttpResponseHandler<SdkBaseException> errorResponseHandler = createErrorResponseHandler(
            new JsonErrorShapeMetadata().withModeledClass(NotFoundException.class).withHttpStatusCode(404),
            new JsonErrorShapeMetadata().withModeledClass(TooManyRequestsException.class).withHttpStatusCode(429), new JsonErrorShapeMetadata()
                    .withModeledClass(BadRequestException.class).withHttpStatusCode(400),
            new JsonErrorShapeMetadata().withModeledClass(UnauthorizedException.class).withHttpStatusCode(401), new JsonErrorShapeMetadata()
                    .withModeledClass(InternalServerErrorException.class).withHttpStatusCode(500));

    return clientHandler.execute(new ClientExecutionParams<GetApplicationRequest, GetApplicationResult>()
            .withMarshaller(new GetApplicationRequestProtocolMarshaller(protocolFactory)).withResponseHandler(responseHandler)
            .withErrorResponseHandler(errorResponseHandler).withInput(getApplicationRequest));
}
 
Example #11
Source File: AWSServerlessApplicationRepositoryClient.java    From realworld-serverless-application with Apache License 2.0 6 votes vote down vote up
/**
 * @param createApplicationRequest
 * @return Result of the CreateApplication operation returned by the service.
 * @throws TooManyRequestsException
 * @throws BadRequestException
 * @throws UnauthorizedException
 * @throws InternalServerErrorException
 * @throws ConflictException
 * @sample AWSServerlessApplicationRepository.CreateApplication
 * @see <a href="http://docs.aws.amazon.com/goto/WebAPI/k9zlvhl83e-1570924800000/CreateApplication"
 *      target="_top">AWS API Documentation</a>
 */
@Override
public CreateApplicationResult createApplication(CreateApplicationRequest createApplicationRequest) {
    HttpResponseHandler<CreateApplicationResult> responseHandler = protocolFactory.createResponseHandler(new JsonOperationMetadata().withPayloadJson(true)
            .withHasStreamingSuccessResponse(false), new CreateApplicationResultJsonUnmarshaller());

    HttpResponseHandler<SdkBaseException> errorResponseHandler = createErrorResponseHandler(
            new JsonErrorShapeMetadata().withModeledClass(TooManyRequestsException.class).withHttpStatusCode(429), new JsonErrorShapeMetadata()
                    .withModeledClass(BadRequestException.class).withHttpStatusCode(400),
            new JsonErrorShapeMetadata().withModeledClass(UnauthorizedException.class).withHttpStatusCode(401), new JsonErrorShapeMetadata()
                    .withModeledClass(InternalServerErrorException.class).withHttpStatusCode(500),
            new JsonErrorShapeMetadata().withModeledClass(ConflictException.class).withHttpStatusCode(409));

    return clientHandler.execute(new ClientExecutionParams<CreateApplicationRequest, CreateApplicationResult>()
            .withMarshaller(new CreateApplicationRequestProtocolMarshaller(protocolFactory)).withResponseHandler(responseHandler)
            .withErrorResponseHandler(errorResponseHandler).withInput(createApplicationRequest));
}
 
Example #12
Source File: HadoopS3AccessHelper.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public ObjectMetadata getObjectMetadata(String key) throws IOException {
	try {
		return s3a.getObjectMetadata(new Path('/' + key));
	}
	catch (SdkBaseException e) {
		throw S3AUtils.translateException("getObjectMetadata", key, e);
	}
}
 
Example #13
Source File: HadoopS3AccessHelper.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public ObjectMetadata getObjectMetadata(String key) throws IOException {
	try {
		return s3a.getObjectMetadata(new Path('/' + key));
	}
	catch (SdkBaseException e) {
		throw S3AUtils.translateException("getObjectMetadata", key, e);
	}
}
 
Example #14
Source File: AuthenticationService.java    From CognitoDemo with Apache License 2.0 5 votes vote down vote up
/**
 * <p>
 * Determine whether a user with userName exists in the login database.
 * </p>
 * 
 * @param userName
 * @return true if the user exists, false otherwise.
 */
@Override
public boolean hasUser(final String userName) {
    boolean userExists = false;
    try {
        UserInfo info = getUserInfo( userName );
        if (info != null && info.getUserName() != null && info.getUserName().length() > 0 && info.getUserName().equals(userName)) {
            userExists = true;
        }
    }
    catch (SdkBaseException ex) {}
    return userExists;
}
 
Example #15
Source File: S3BlobRetriever.java    From hollow-reference-implementation with Apache License 2.0 5 votes vote down vote up
private File downloadFile(String objectName) throws IOException {
	File tempFile = new File(System.getProperty("java.io.tmpdir"), objectName.replace('/', '-'));
	
	Download download = s3TransferManager.download(bucketName, objectName, tempFile);
	
	try {
	    download.waitForCompletion();
	} catch(SdkBaseException | InterruptedException e) {
	    throw new RuntimeException(e);
	}
	
	return tempFile;
}
 
Example #16
Source File: S3AsyncByteReaderUsingSyncClient.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
<T> T invoke(Callable<T> operation) throws Exception {
  int retryCount = 0;
  while (true) {
    try {
      return operation.call();
    } catch (SdkBaseException | IOException | RetryableException e) {
      if (retryCount >= maxRetries) {
        throw e;
      }

      logger.warn("Retrying S3Async operation, exception was: {}", e.getLocalizedMessage());
      ++retryCount;
    }
  }
}
 
Example #17
Source File: TestRetryableInvoker.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
private void testRetry(int numRetries) throws Exception {
  final S3AsyncByteReaderUsingSyncClient.RetryableInvoker invoker =
    new S3AsyncByteReaderUsingSyncClient.RetryableInvoker(numRetries);
  final AtomicInteger counter = new AtomicInteger(0);
  try {
    invoker.invoke(() -> {
      counter.incrementAndGet();
      throw new SdkBaseException("test exception");
    });
    Assert.fail();
  } catch (SdkBaseException e) {
    Assert.assertEquals(numRetries + 1, counter.get());
  }
}
 
Example #18
Source File: S3BlobStore.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public boolean isStorageAvailable() {
  try {
    return s3.doesBucketExistV2(getConfiguredBucket());
  } catch (SdkBaseException e) {
    log.warn("S3 bucket '{}' is not writable.", getConfiguredBucket(), e);
    return false;
  }
}
 
Example #19
Source File: S3Manager.java    From datacollector with Apache License 2.0 5 votes vote down vote up
String uploadToS3(String name, File file) throws IOException {
  long start = System.currentTimeMillis();
  long fileLength = file.length() / (1000 * 1000);
  String bucket = getBucket(pipelineEmrConfigs.getS3StagingUri());
  String path = getPath(pipelineEmrConfigs.getS3StagingUri()) + "/" + pipelineId + "/" + uniquePrefix;
  String s3Uri =  "s3://" + bucket + "/" +  path + "/" + name;
  try {

    // Upload
    PutObjectRequest putObjectRequest = new PutObjectRequest(bucket, path + "/" + name, file);
    putObjectRequest.setGeneralProgressListener(new ProgressListener() {
      long counter;
      long tick = -1;
      @Override
      public void progressChanged(ProgressEvent progressEvent) {
        counter += progressEvent.getBytesTransferred();
        if (counter / (100 * 1000000) > tick) {
          tick++;
          LOG.debug(
              "Uploading '{}' {}/{} MB, {} secs",
              s3Uri,
              counter / (1000 * 1000),
              fileLength,
              (System.currentTimeMillis() - start) / 1000
          );
        }
      }
    });

    getS3TransferManager().upload(putObjectRequest).waitForCompletion();

    LOG.info("Uploaded file at: {}", s3Uri);
    return s3Uri;
  } catch (SdkBaseException|InterruptedException ex) {
    throw new IOException(ex);
  }
}
 
Example #20
Source File: HadoopS3AccessHelper.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public ObjectMetadata getObjectMetadata(String key) throws IOException {
	try {
		return s3a.getObjectMetadata(new Path('/' + key));
	}
	catch (SdkBaseException e) {
		throw S3AUtils.translateException("getObjectMetadata", key, e);
	}
}
 
Example #21
Source File: AWSServerlessApplicationRepositoryClient.java    From realworld-serverless-application with Apache License 2.0 2 votes vote down vote up
/**
 * Create the error response handler for the operation.
 * 
 * @param errorShapeMetadata
 *        Error metadata for the given operation
 * @return Configured error response handler to pass to HTTP layer
 */
private HttpResponseHandler<SdkBaseException> createErrorResponseHandler(JsonErrorShapeMetadata... errorShapeMetadata) {
    return protocolFactory.createErrorResponseHandler(new JsonErrorResponseMetadata().withErrorShapes(Arrays.asList(errorShapeMetadata)));
}
 
Example #22
Source File: AWSServerlessApplicationRepositoryClient.java    From realworld-serverless-application with Apache License 2.0 2 votes vote down vote up
/**
 * Create the error response handler for the operation.
 *
 * @param errorShapeMetadata
 *        Error metadata for the given operation
 * @return Configured error response handler to pass to HTTP layer
 */
private HttpResponseHandler<SdkBaseException> createErrorResponseHandler(JsonErrorShapeMetadata... errorShapeMetadata) {
  return protocolFactory.createErrorResponseHandler(new JsonErrorResponseMetadata().withErrorShapes(Arrays.asList(errorShapeMetadata)));
}