List of usage examples for com.amazonaws AmazonServiceException AmazonServiceException
public AmazonServiceException(String errorMessage)
From source file:org.finra.dm.dao.impl.MockS3OperationsImpl.java
License:Apache License
/** * <p>// ww w . jav a 2 s . c o m * Deletes an object specified by the given bucket name and key. This method does nothing if the bucket does not exist. * </p> * <p> * This operation takes the following hints when suffixed in filePath: * <dl> * <p/> * <dt>MOCK_S3_FILE_NAME_NOT_FOUND</dt> * <dd>Throws a AmazonServiceException</dd> * <p/> * </dl> * </p> */ @Override public void deleteFile(String bucketName, String key, AmazonS3Client s3Client) { LOGGER.debug("deleteFile(): bucketName = " + bucketName + ", key = " + key); if (key.endsWith(MOCK_S3_FILE_NAME_NOT_FOUND)) { throw new AmazonServiceException(null); } MockS3Bucket mockS3Bucket = mockS3Buckets.get(bucketName); if (mockS3Bucket != null) { mockS3Bucket.getObjects().remove(key); } }
From source file:org.finra.dm.dao.impl.MockS3OperationsImpl.java
License:Apache License
/** * <p>/*from w w w . ja v a2 s.c o m*/ * Returns a mock list of multipart uploads. Since a multipart upload in progress does not exist when in-memory, this method simply returns a preconfigured * list. * </p> * <p> * Returns a mock {@link MultipartUploadListing} based on the parameters and hints provided. By default returns a mock listing as defiend by * {@link #getMultipartUploadListing()}. * </p> * <p> * This operation takes the following hints when suffixed in listMultipartUploadsRequest.bucketName: * <dl> * <p/> * <dt>MOCK_S3_BUCKET_NAME_SERVICE_EXCEPTION</dt> * <dd>Throws a AmazonServiceException</dd> * <p/> * <dt>MOCK_S3_BUCKET_NAME_TRUNCATED_MULTIPART_LISTING</dt> * <dd>Returns the listing as if it is truncated. See below for details.</dd> * <p/> * </dl> * </p> */ @Override public MultipartUploadListing listMultipartUploads(ListMultipartUploadsRequest listMultipartUploadsRequest, AmazonS3Client s3Client) { if (listMultipartUploadsRequest.getBucketName().equals(MOCK_S3_BUCKET_NAME_SERVICE_EXCEPTION)) { throw new AmazonServiceException(null); } else if (listMultipartUploadsRequest.getBucketName() .equals(MOCK_S3_BUCKET_NAME_TRUNCATED_MULTIPART_LISTING)) { MultipartUploadListing multipartUploadListing = getMultipartUploadListing(); // If listing request does not have upload ID marker set, mark the listing as truncated - this is done to truncate the multipart listing just once. if (listMultipartUploadsRequest.getUploadIdMarker() == null) { multipartUploadListing.setUploadIdMarker("TEST_UPLOAD_MARKER_ID"); multipartUploadListing.setTruncated(true); } return multipartUploadListing; } else { return getMultipartUploadListing(); } }
From source file:org.finra.dm.dao.impl.MockS3OperationsImpl.java
License:Apache License
@Override public S3Object getS3Object(GetObjectRequest getObjectRequest, AmazonS3 s3) { String bucketName = getObjectRequest.getBucketName(); String key = getObjectRequest.getKey(); if (MOCK_S3_BUCKET_NAME_NO_SUCH_BUCKET_EXCEPTION.equals(bucketName)) { AmazonServiceException amazonServiceException = new AmazonServiceException( S3Operations.ERROR_CODE_NO_SUCH_BUCKET); amazonServiceException.setErrorCode(S3Operations.ERROR_CODE_NO_SUCH_BUCKET); throw amazonServiceException; }/*from ww w . jav a2 s .c o m*/ if (MOCK_S3_BUCKET_NAME_ACCESS_DENIED.equals(bucketName)) { AmazonServiceException amazonServiceException = new AmazonServiceException( S3Operations.ERROR_CODE_ACCESS_DENIED); amazonServiceException.setErrorCode(S3Operations.ERROR_CODE_ACCESS_DENIED); throw amazonServiceException; } if (MOCK_S3_BUCKET_NAME_INTERNAL_ERROR.equals(bucketName)) { AmazonServiceException amazonServiceException = new AmazonServiceException( S3Operations.ERROR_CODE_INTERNAL_ERROR); amazonServiceException.setErrorCode(S3Operations.ERROR_CODE_INTERNAL_ERROR); throw amazonServiceException; } MockS3Bucket mockS3Bucket = getOrCreateBucket(bucketName); MockS3Object mockS3Object = mockS3Bucket.getObjects().get(key); if (mockS3Object == null) { AmazonServiceException amazonServiceException = new AmazonServiceException( S3Operations.ERROR_CODE_NO_SUCH_KEY); amazonServiceException.setErrorCode(S3Operations.ERROR_CODE_NO_SUCH_KEY); throw amazonServiceException; } S3Object s3Object = new S3Object(); s3Object.setBucketName(bucketName); s3Object.setKey(key); s3Object.setObjectContent(new ByteArrayInputStream(mockS3Object.getData())); s3Object.setObjectMetadata(mockS3Object.getObjectMetadata()); return s3Object; }
From source file:org.finra.dm.dao.impl.MockSqsOperationsImpl.java
License:Apache License
@Override public void sendSqsTextMessage(ClientConfiguration client, String queueName, String messageText) { // Throw a throttling exception for a specific queue name for testing purposes. if (queueName.equals(MockAwsOperationsHelper.AMAZON_THROTTLING_EXCEPTION)) { AmazonServiceException throttlingException = new AmazonServiceException("test throttling exception"); throttlingException.setErrorCode("ThrottlingException"); throw throttlingException; }/*from w w w . jav a 2 s . c o m*/ // Throw an illegal state exception for a specific queue name for testing purposes. if (queueName.equals(MOCK_SQS_QUEUE_NOT_FOUND_NAME)) { throw new IllegalStateException(String.format("AWS SQS queue with \"%s\" name not found.", queueName)); } // Nothing else to do in the normal case since our unit tests aren't reading messages once they have been published. }
From source file:org.finra.dm.dao.impl.MockStsOperationsImpl.java
License:Apache License
@Override public AssumeRoleResult assumeRole(AWSSecurityTokenServiceClient awsSecurityTokenServiceClient, AssumeRoleRequest assumeRoleRequest) { assertNotNull(assumeRoleRequest);//from w w w .j a v a 2s. c o m if (assumeRoleRequest.getPolicy() != null && assumeRoleRequest.getPolicy().equals(MockAwsOperationsHelper.AMAZON_THROTTLING_EXCEPTION)) { AmazonServiceException throttlingException = new AmazonServiceException("test throttling exception"); throttlingException.setErrorCode("ThrottlingException"); throw throttlingException; } AssumeRoleResult assumeRoleResult = new AssumeRoleResult(); assumeRoleResult.setCredentials(new Credentials(MOCK_AWS_ASSUMED_ROLE_ACCESS_KEY, MOCK_AWS_ASSUMED_ROLE_SECRET_KEY, MOCK_AWS_ASSUMED_ROLE_SESSION_TOKEN, new Date(System.currentTimeMillis() + 1000 * assumeRoleRequest.getDurationSeconds()))); return assumeRoleResult; }
From source file:org.finra.herd.dao.impl.MockEmrOperationsImpl.java
License:Apache License
@Override public String runEmrJobFlow(AmazonElasticMapReduceClient emrClient, RunJobFlowRequest jobFlowRequest) { String clusterStatus = ClusterState.BOOTSTRAPPING.toString(); StatusChangeReason reason = new StatusChangeReason(ClusterStateChangeReasonCode.USER_REQUEST.toString(), "Started " + clusterStatus); StatusTimeline timeline = new StatusTimeline(); timeline.setCreationTime(HerdDateUtils.getXMLGregorianCalendarValue(new Date())); if (StringUtils.isNotBlank(jobFlowRequest.getAmiVersion())) { if (jobFlowRequest.getAmiVersion().equals(MockAwsOperationsHelper.AMAZON_THROTTLING_EXCEPTION)) { AmazonServiceException throttlingException = new AmazonServiceException( "test throttling exception"); throttlingException.setErrorCode("ThrottlingException"); throw throttlingException; } else if (jobFlowRequest.getAmiVersion().equals(MockAwsOperationsHelper.AMAZON_BAD_REQUEST)) { AmazonServiceException badRequestException = new AmazonServiceException( MockAwsOperationsHelper.AMAZON_BAD_REQUEST); badRequestException.setStatusCode(HttpStatus.SC_BAD_REQUEST); throw badRequestException; } else if (jobFlowRequest.getAmiVersion().equals(MockAwsOperationsHelper.AMAZON_NOT_FOUND)) { AmazonServiceException notFoundException = new AmazonServiceException( MockAwsOperationsHelper.AMAZON_NOT_FOUND); notFoundException.setStatusCode(HttpStatus.SC_NOT_FOUND); throw notFoundException; } else if (jobFlowRequest.getAmiVersion().equals(MockAwsOperationsHelper.AMAZON_SERVICE_EXCEPTION)) { throw new AmazonServiceException(MockAwsOperationsHelper.AMAZON_SERVICE_EXCEPTION); } else if (jobFlowRequest.getAmiVersion() .equals(MockAwsOperationsHelper.AMAZON_CLUSTER_STATUS_WAITING)) { clusterStatus = ClusterState.WAITING.toString(); } else if (jobFlowRequest.getAmiVersion() .equals(MockAwsOperationsHelper.AMAZON_CLUSTER_STATUS_RUNNING)) { clusterStatus = ClusterState.RUNNING.toString(); }/*from w w w . ja v a 2 s .co m*/ } return createNewCluster(jobFlowRequest, clusterStatus, reason, timeline).getJobFlowId(); }
From source file:org.finra.herd.dao.impl.MockEmrOperationsImpl.java
License:Apache License
@Override public DescribeClusterResult describeClusterRequest(AmazonElasticMapReduceClient emrClient, DescribeClusterRequest describeClusterRequest) { if (describeClusterRequest.getClusterId() .equalsIgnoreCase(MockAwsOperationsHelper.AMAZON_SERVICE_EXCEPTION)) { throw new AmazonServiceException(MockAwsOperationsHelper.AMAZON_SERVICE_EXCEPTION); }// w ww . j a v a2 s .c o m MockEmrJobFlow cluster = getClusterById(describeClusterRequest.getClusterId()); if (cluster != null) { return new DescribeClusterResult().withCluster(new Cluster().withId(cluster.getJobFlowId()) .withName(cluster.getJobFlowName()) .withStatus(new ClusterStatus().withState(cluster.getStatus()) .withStateChangeReason(new ClusterStateChangeReason() .withCode(cluster.getStatusChangeReason().getCode()) .withMessage(cluster.getStatusChangeReason().getMessage())) .withTimeline(new ClusterTimeline() .withCreationDateTime(cluster.getStatusTimeline().getCreationTime() != null ? cluster.getStatusTimeline().getCreationTime().toGregorianCalendar() .getTime() : null) .withEndDateTime(cluster.getStatusTimeline().getEndTime() != null ? cluster .getStatusTimeline().getEndTime().toGregorianCalendar().getTime() : null) .withReadyDateTime(cluster.getStatusTimeline().getReadyTime() != null ? cluster .getStatusTimeline().getReadyTime().toGregorianCalendar().getTime() : null)))); } else { return null; } }
From source file:org.finra.herd.dao.impl.MockEmrOperationsImpl.java
License:Apache License
@Override public ListStepsResult listStepsRequest(AmazonElasticMapReduceClient emrClient, ListStepsRequest listStepsRequest) { MockEmrJobFlow cluster = getClusterById(listStepsRequest.getClusterId()); if (cluster == null) { throw new AmazonServiceException("No cluster found with jobFlowId: " + listStepsRequest.getClusterId()); }//from w w w . ja va 2s .c o m List<StepSummary> steps = new ArrayList<>(); // Add steps that are in these states for (MockEmrJobFlow step : cluster.getSteps()) { if ((listStepsRequest.getStepStates() == null || listStepsRequest.getStepStates().isEmpty()) || listStepsRequest.getStepStates().contains(step.getStatus())) { StepSummary stepSummary = new StepSummary().withId(step.getJobFlowId()) .withName(step.getJobFlowName()).withStatus(new StepStatus().withState(step.getStatus())) .withConfig(new HadoopStepConfig().withJar(step.getJarLocation())); steps.add(stepSummary); } } return new ListStepsResult().withSteps(steps); }
From source file:org.finra.herd.dao.impl.MockEmrOperationsImpl.java
License:Apache License
@Override public DescribeStepResult describeStepRequest(AmazonElasticMapReduceClient emrClient, DescribeStepRequest describeStepRequest) { MockEmrJobFlow cluster = getClusterById(describeStepRequest.getClusterId()); if (cluster == null) { throw new AmazonServiceException( "No cluster found with jobFlowId: " + describeStepRequest.getClusterId()); }/* w ww . j a v a2 s . co m*/ Step stepResult = null; // Add steps that are in these states for (MockEmrJobFlow step : cluster.getSteps()) { if (describeStepRequest.getStepId().equalsIgnoreCase(step.getJobFlowId())) { HadoopStepConfig hadoopStepConfig = new HadoopStepConfig().withJar(step.getJarLocation()); stepResult = new Step().withId(step.getJobFlowId()).withName(step.getJobFlowName()) .withStatus(new StepStatus().withState(step.getStatus())).withConfig(hadoopStepConfig); if (stepResult.getName().equalsIgnoreCase(MOCK_STEP_WITHOUT_ID_NAME)) { stepResult.setId(null); } break; } } return new DescribeStepResult().withStep(stepResult); }
From source file:org.finra.herd.dao.impl.MockGlacierOperationsImpl.java
License:Apache License
@Override public UploadResult upload(String vaultName, String archiveDescription, File file, ArchiveTransferManager archiveTransferManager) throws AmazonClientException, FileNotFoundException { if (vaultName.equals(MOCK_GLACIER_VAULT_NAME_SERVICE_EXCEPTION)) { throw new AmazonServiceException(null); }/* w ww . ja v a2 s .c om*/ return new UploadResult(MOCK_GLACIER_ARCHIVE_ID); }