List of usage examples for com.amazonaws AmazonServiceException AmazonServiceException
public AmazonServiceException(String errorMessage)
From source file:org.finra.dm.dao.impl.MockEc2OperationsImpl.java
License:Apache License
@Override public void modifyInstanceAttribute(AmazonEC2Client ec2Client, ModifyInstanceAttributeRequest modifyInstanceAttributeRequest) { if (modifyInstanceAttributeRequest.getGroups() != null && modifyInstanceAttributeRequest.getGroups().get(0) .equals(MockAwsOperationsHelper.AMAZON_SERVICE_EXCEPTION)) { throw new AmazonServiceException(MockAwsOperationsHelper.AMAZON_SERVICE_EXCEPTION); }/* w ww.j ava 2 s.c o m*/ if (modifyInstanceAttributeRequest.getGroups() != null && modifyInstanceAttributeRequest.getGroups().get(0) .equals(MockAwsOperationsHelper.AMAZON_THROTTLING_EXCEPTION)) { AmazonServiceException throttlingException = new AmazonServiceException("test throttling exception"); throttlingException.setErrorCode("ThrottlingException"); throw throttlingException; } }
From source file:org.finra.dm.dao.impl.MockEc2OperationsImpl.java
License:Apache License
/** * In-memory implementation of describeSubnets. Returns the subnets from the pre-configured subnets. * The method can be ordered to throw an AmazonServiceException with a specified error code by specifying a subnet ID with prefix "throw." followed by a * string indicating the error code to throw. The exception thrown in this manner will always set the status code to 500. *//* ww w .j ava2s . com*/ @Override public DescribeSubnetsResult describeSubnets(AmazonEC2Client ec2Client, DescribeSubnetsRequest describeSubnetsRequest) { List<Subnet> subnets = new ArrayList<>(); List<String> requestedSubnetIds = describeSubnetsRequest.getSubnetIds(); // add all subnets if request is empty (this is AWS behavior) if (requestedSubnetIds.isEmpty()) { requestedSubnetIds.addAll(mockSubnets.keySet()); } for (String requestedSubnetId : requestedSubnetIds) { MockSubnet mockSubnet = mockSubnets.get(requestedSubnetId); // Throw exception if any of the subnet ID do not exist if (mockSubnet == null) { AmazonServiceException amazonServiceException; if (requestedSubnetId.startsWith("throw.")) { String errorCode = requestedSubnetId.substring("throw.".length()); amazonServiceException = new AmazonServiceException(errorCode); amazonServiceException.setErrorCode(errorCode); amazonServiceException.setStatusCode(500); } else { amazonServiceException = new AmazonServiceException( "The subnet ID '" + requestedSubnetId + "' does not exist"); amazonServiceException.setErrorCode(Ec2DaoImpl.ERROR_CODE_SUBNET_ID_NOT_FOUND); amazonServiceException.setStatusCode(400); } throw amazonServiceException; } subnets.add(mockSubnet.toAwsObject()); } DescribeSubnetsResult describeSubnetsResult = new DescribeSubnetsResult(); describeSubnetsResult.setSubnets(subnets); return describeSubnetsResult; }
From source file:org.finra.dm.dao.impl.MockEmrOperationsImpl.java
License:Apache License
@Override public String runEmrJobFlow(AmazonElasticMapReduceClient emrClient, RunJobFlowRequest jobFlowRequest) { String clusterStatus = ClusterState.BOOTSTRAPPING.toString(); 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 ww w . jav a2s. co m } return createNewCluster(jobFlowRequest, clusterStatus).getJobFlowId(); }
From source file:org.finra.dm.dao.impl.MockEmrOperationsImpl.java
License:Apache License
/** * Add Job Flow Step to AmazonElasticMapReduceClient *//*from w w w . j ava 2 s . c om*/ @Override public List<String> addJobFlowStepsRequest(AmazonElasticMapReduceClient emrClient, AddJobFlowStepsRequest addJobFlowStepsRequest) { if (addJobFlowStepsRequest.getSteps() != null && addJobFlowStepsRequest.getSteps().get(0) != null) { StepConfig firstStep = addJobFlowStepsRequest.getSteps().get(0); if (firstStep.getName().equals(MockAwsOperationsHelper.AMAZON_BAD_REQUEST)) { AmazonServiceException badRequestException = new AmazonServiceException( MockAwsOperationsHelper.AMAZON_BAD_REQUEST); badRequestException.setStatusCode(HttpStatus.SC_BAD_REQUEST); throw badRequestException; } else if (firstStep.getName().equals(MockAwsOperationsHelper.AMAZON_NOT_FOUND)) { AmazonServiceException notFoundException = new AmazonServiceException( MockAwsOperationsHelper.AMAZON_NOT_FOUND); notFoundException.setStatusCode(HttpStatus.SC_NOT_FOUND); throw notFoundException; } else if (firstStep.getName().equals(MockAwsOperationsHelper.AMAZON_SERVICE_EXCEPTION)) { throw new AmazonServiceException(MockAwsOperationsHelper.AMAZON_SERVICE_EXCEPTION); } } MockEmrJobFlow cluster = getClusterById(addJobFlowStepsRequest.getJobFlowId()); if (cluster == null) { throw new AmazonServiceException( "No Cluster exists with jobFlowId: " + addJobFlowStepsRequest.getJobFlowId()); } List<String> jobIds = new ArrayList<>(); for (StepConfig step : addJobFlowStepsRequest.getSteps()) { jobIds.add(addClusterStep(cluster.getJobFlowId(), step).getJobFlowId()); } return jobIds; }
From source file:org.finra.dm.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 w w . ja 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()))); } else { return null; } }
From source file:org.finra.dm.dao.impl.MockEmrOperationsImpl.java
License:Apache License
@Override public void terminateEmrCluster(AmazonElasticMapReduceClient emrClient, String clusterId, boolean overrideTerminationProtection) { MockEmrJobFlow cluster = getClusterById(clusterId); if (cluster.getJobFlowName().endsWith(MockAwsOperationsHelper.AMAZON_SERVICE_EXCEPTION)) { throw new AmazonServiceException(MockAwsOperationsHelper.AMAZON_SERVICE_EXCEPTION); }// w w w . j ava2 s .c o m cluster.setStatus(ClusterState.TERMINATED.toString()); }
From source file:org.finra.dm.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()); }/* w w w . j a va 2 s . c om*/ 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())); steps.add(stepSummary); } } return new ListStepsResult().withSteps(steps); }
From source file:org.finra.dm.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()); }/* www . j ava 2 s .c o 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); break; } } return new DescribeStepResult().withStep(stepResult); }
From source file:org.finra.dm.dao.impl.MockS3OperationsImpl.java
License:Apache License
/** * <p>//from ww w.j a v a2 s . c om * Creates and returns a new {@link ObjectMetadata} with the given parameters. Content length is defaulted to 1 bytes unless a hint is provided. * </p> * <p> * Takes the following hints when filePath is suffixed: * </p> * <dl> * <p/> * <dt>AMAZON_THROTTLING_EXCEPTION</dt> * <dd>Throws AmazonServiceException with the error code "ThrottlingException"</dd> * <p/> * <dt>MOCK_S3_FILE_NAME_SERVICE_EXCEPTION</dt> * <dd>Throws AmazonServiceException</dd> * <p/> * <dt>MOCK_S3_FILE_NAME_NOT_FOUND</dt> * <dd>Throws AmazonServiceException with status code SC_NOT_FOUND</dd> * <p/> * <dt>MOCK_S3_FILE_NAME_0_BYTE_SIZE</dt> * <dd>Sets content length to 0 bytes</dd> * <p/> * </dl> */ @Override public ObjectMetadata getObjectMetadata(String sourceBucketName, String filePath, AmazonS3Client s3Client) { ObjectMetadata objectMetadata = new ObjectMetadata(); if (filePath.endsWith(MockAwsOperationsHelper.AMAZON_THROTTLING_EXCEPTION)) { AmazonServiceException throttlingException = new AmazonServiceException("test throttling exception"); throttlingException.setErrorCode("ThrottlingException"); throw throttlingException; } else if (filePath.endsWith(MOCK_S3_FILE_NAME_SERVICE_EXCEPTION)) { throw new AmazonServiceException(null); } else if (filePath.endsWith(MOCK_S3_FILE_NAME_NOT_FOUND)) { AmazonServiceException exception = new AmazonServiceException(null); exception.setStatusCode(HttpStatus.SC_NOT_FOUND); throw exception; } else if (filePath.endsWith(MOCK_S3_FILE_NAME_0_BYTE_SIZE)) { objectMetadata.setContentLength(AbstractCoreTest.FILE_SIZE_0_BYTE); } else { objectMetadata.setContentLength(AbstractCoreTest.FILE_SIZE_1_KB); } return objectMetadata; }
From source file:org.finra.dm.dao.impl.MockS3OperationsImpl.java
License:Apache License
/** * <p>/*from w w w. j av a2 s . c o m*/ * Simulates a copyFile operation. * </p> * <p> * This method does not actually copy files in-memory, but always returns a pre-defined result. * </p> * <p> * The result {@link Copy} has the following properties: * <dl> * <p/> * <dt>description</dt> * <dd>"MockTransfer"</dd> * <p/> * <dt>state</dt> * <dd>{@link TransferState#Completed}</dd> * <p/> * <dt>transferProgress.totalBytesToTransfer</dt> * <dd>1024</dd> * <p/> * <dt>transferProgress.updateProgress</dt> * <dd>1024</dd> * <p/> * </dl> * <p/> * All other properties are set as default. * </p> * <p> * This operation takes the following hints when suffixed in copyObjectRequest.sourceKey: * <dl> * <p/> * <dt>MOCK_S3_FILE_NAME_NOT_FOUND</dt> * <dd>Throws a AmazonServiceException</dd> * <p/> * </dl> * </p> */ @Override public Copy copyFile(final CopyObjectRequest copyObjectRequest, TransferManager transferManager) { LOGGER.debug("copyFile(): copyObjectRequest.getSourceBucketName() = " + copyObjectRequest.getSourceBucketName() + ", copyObjectRequest.getSourceKey() = " + copyObjectRequest.getSourceKey() + ", copyObjectRequest.getDestinationBucketName() = " + copyObjectRequest.getDestinationBucketName() + ", copyObjectRequest.getDestinationKey() = " + copyObjectRequest.getDestinationKey()); if (copyObjectRequest.getSourceKey().endsWith(MOCK_S3_FILE_NAME_NOT_FOUND)) { throw new AmazonServiceException(null); } /* * Does not actually copy files in memory. There is a test case S3ServiceTest.testCopyFile() which is expecting a result without staging any data. * Below is implementation when needed. */ /* * String sourceBucketName = copyObjectRequest.getSourceBucketName(); * String sourceKey = copyObjectRequest.getSourceKey(); * MockS3Bucket mockSourceS3Bucket = mockS3Buckets.get(sourceBucketName); * MockS3Object mockSourceS3Object = mockSourceS3Bucket.getObjects().get(sourceKey); * String destinationBucketName = copyObjectRequest.getDestinationBucketName(); * String destinationKey = copyObjectRequest.getDestinationKey(); * ObjectMetadata objectMetadata = copyObjectRequest.getNewObjectMetadata(); * MockS3Object mockDestinationS3Object = new MockS3Object(); * mockDestinationS3Object.setKey(destinationKey); * mockDestinationS3Object.setData(Arrays.copyOf(mockSourceS3Object.getData(), mockSourceS3Object.getData().length)); * mockDestinationS3Object.setObjectMetadata(objectMetadata); * MockS3Bucket mockDestinationS3Bucket = getOrCreateBucket(destinationBucketName); * mockDestinationS3Bucket.getObjects().put(destinationKey, mockDestinationS3Object); */ // Set the result CopyImpl and TransferProgress. TransferProgress transferProgress = new TransferProgress(); transferProgress.setTotalBytesToTransfer(AbstractCoreTest.FILE_SIZE_1_KB); transferProgress.updateProgress(AbstractCoreTest.FILE_SIZE_1_KB); CopyImpl copy = new CopyImpl(MOCK_TRANSFER_DESCRIPTION, transferProgress, null, null); copy.setState(TransferState.Completed); // If an invalid KMS Id was passed in, mark the transfer as failed and return an exception via the transfer monitor. final String kmsId = copyObjectRequest.getSSEAwsKeyManagementParams().getAwsKmsKeyId(); if (kmsId.startsWith(MOCK_KMS_ID_FAILED_TRANSFER)) { copy.setState(TransferState.Failed); copy.setMonitor(new TransferMonitor() { @Override public Future<?> getFuture() { if (!kmsId.equals(MOCK_KMS_ID_FAILED_TRANSFER_NO_EXCEPTION)) { throw new AmazonServiceException("Key '" + copyObjectRequest.getSSEAwsKeyManagementParams().getAwsKmsKeyId() + "' does not exist (Service: Amazon S3; Status Code: 400; Error Code: KMS.NotFoundException; Request ID: 1234567890123456)"); } // We don't want an exception to be thrown so return a basic future that won't throw an exception. BasicFuture<?> future = new BasicFuture<Void>(null); future.completed(null); return future; } @Override public boolean isDone() { return true; } }); } else if (kmsId.startsWith(MOCK_KMS_ID_CANCELED_TRANSFER)) { // If the KMS indicates a cancelled transfer, just update the state to canceled. copy.setState(TransferState.Canceled); } return copy; }