Java Code Examples for com.amazonaws.AmazonServiceException

The following examples show how to use com.amazonaws.AmazonServiceException. These examples are extracted from open source projects. 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 Project: hadoop   Source File: S3AFileSystem.java    License: Apache License 2.0 6 votes vote down vote up
private void createEmptyObject(final String bucketName, final String objectName)
    throws AmazonClientException, AmazonServiceException {
  final InputStream im = new InputStream() {
    @Override
    public int read() throws IOException {
      return -1;
    }
  };

  final ObjectMetadata om = new ObjectMetadata();
  om.setContentLength(0L);
  if (StringUtils.isNotBlank(serverSideEncryptionAlgorithm)) {
    om.setServerSideEncryption(serverSideEncryptionAlgorithm);
  }
  PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, objectName, im, om);
  putObjectRequest.setCannedAcl(cannedACL);
  s3.putObject(putObjectRequest);
  statistics.incrementWriteOps(1);
}
 
Example 2
Source Project: presto   Source File: GlueHiveMetastore.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public List<String> getAllDatabases()
{
    try {
        return stats.getGetAllDatabases().call(() -> {
            List<String> databaseNames = new ArrayList<>();
            String nextToken = null;

            do {
                GetDatabasesResult result = glueClient.getDatabases(new GetDatabasesRequest().withCatalogId(catalogId).withNextToken(nextToken));
                nextToken = result.getNextToken();
                result.getDatabaseList().forEach(database -> databaseNames.add(database.getName()));
            }
            while (nextToken != null);

            return databaseNames;
        });
    }
    catch (AmazonServiceException e) {
        throw new PrestoException(HIVE_METASTORE_ERROR, e);
    }
}
 
Example 3
Source Project: presto   Source File: GlueHiveMetastore.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void dropTable(HiveIdentity identity, String databaseName, String tableName, boolean deleteData)
{
    Table table = getExistingTable(identity, databaseName, tableName);

    try {
        stats.getDropTable().call(() ->
                glueClient.deleteTable(new DeleteTableRequest()
                        .withCatalogId(catalogId)
                        .withDatabaseName(databaseName)
                        .withName(tableName)));
    }
    catch (AmazonServiceException e) {
        throw new PrestoException(HIVE_METASTORE_ERROR, e);
    }

    String tableLocation = table.getStorage().getLocation();
    if (deleteData && isManagedTable(table) && !isNullOrEmpty(tableLocation)) {
        deleteDir(hdfsContext, hdfsEnvironment, new Path(tableLocation), true);
    }
}
 
Example 4
@Test
void testPotentiallyNoAccessToPerformGetQueueUrl() throws Exception {
	AmazonSQS amazonSqs = mock(AmazonSQS.class);
	AmazonServiceException exception = new QueueDoesNotExistException(
			"AWS.SimpleQueueService.NonExistentQueue");
	exception.setErrorCode("AWS.SimpleQueueService.NonExistentQueue");
	exception.setErrorMessage(
			"The specified queue does not exist or you do not have access to it.");
	String queueUrl = "noAccessGetQueueUrlName";
	when(amazonSqs.getQueueUrl(new GetQueueUrlRequest(queueUrl)))
			.thenThrow(exception);
	DynamicQueueUrlDestinationResolver dynamicQueueDestinationResolver = new DynamicQueueUrlDestinationResolver(
			amazonSqs);
	try {
		dynamicQueueDestinationResolver.resolveDestination(queueUrl);
	}
	catch (DestinationResolutionException e) {
		assertThat(e.getMessage()).startsWith(
				"The queue does not exist or no access to perform action sqs:GetQueueUrl.");
	}
}
 
Example 5
Source Project: athenz   Source File: MockCloudStore.java    License: Apache License 2.0 6 votes vote down vote up
@Override
AWSSecurityTokenServiceClient getTokenServiceClient() {
    if (exceptionStatusCode != 0) {
        if (amazonException) {
            AmazonServiceException ex = new AmazonServiceException("Error");
            ex.setStatusCode(exceptionStatusCode);
            throw ex;
        } else {
            throw new IllegalArgumentException("Error");
        }
    } else {
        AWSSecurityTokenServiceClient client = Mockito.mock(AWSSecurityTokenServiceClient.class);
        Mockito.when(client.assumeRole(Mockito.any(AssumeRoleRequest.class))).thenReturn(assumeRoleResult);
        Mockito.when(client.getCallerIdentity(Mockito.any(GetCallerIdentityRequest.class))).thenReturn(callerIdentityResult);
        return client;
    }
}
 
Example 6
Source Project: presto   Source File: GlueHiveMetastore.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void dropPartition(HiveIdentity identity, String databaseName, String tableName, List<String> parts, boolean deleteData)
{
    Table table = getExistingTable(identity, databaseName, tableName);
    Partition partition = getPartition(identity, table, parts)
            .orElseThrow(() -> new PartitionNotFoundException(new SchemaTableName(databaseName, tableName), parts));

    try {
        stats.getDropPartition().call(() ->
                glueClient.deletePartition(new DeletePartitionRequest()
                        .withCatalogId(catalogId)
                        .withDatabaseName(databaseName)
                        .withTableName(tableName)
                        .withPartitionValues(parts)));
    }
    catch (AmazonServiceException e) {
        throw new PrestoException(HIVE_METASTORE_ERROR, e);
    }

    String partLocation = partition.getStorage().getLocation();
    if (deleteData && isManagedTable(table) && !isNullOrEmpty(partLocation)) {
        deleteDir(hdfsContext, hdfsEnvironment, new Path(partLocation), true);
    }
}
 
Example 7
Source Project: aws-cf-templates   Source File: ACloudFormationTest.java    License: Apache License 2.0 6 votes vote down vote up
private List<StackEvent> getStackEvents(final String stackName) {
    final List<StackEvent> events = new ArrayList<>();
    String nextToken = null;
    do {
        try {
            final DescribeStackEventsResult res = this.cf.describeStackEvents(new DescribeStackEventsRequest().withStackName(stackName).withNextToken(nextToken));
            events.addAll(res.getStackEvents());
            nextToken = res.getNextToken();
        } catch (final AmazonServiceException e) {
            if (e.getErrorMessage().equals("Stack [" + stackName + "] does not exist")) {
                nextToken = null;
            } else {
                throw e;
            }
        }
    } while (nextToken != null);
    Collections.reverse(events);
    return events;
}
 
Example 8
Source Project: rdf-delta   Source File: S3.java    License: Apache License 2.0 6 votes vote down vote up
/** Test whether the bucket exists and is accessible. */
public static boolean bucketExists(AmazonS3 client, String bucketName) {
    try {
        HeadBucketRequest request = new HeadBucketRequest(bucketName);
        HeadBucketResult result = client.headBucket(request);
        return true;
    }
    catch (AmazonServiceException awsEx) {
        switch (awsEx.getStatusCode()) {
            case HttpSC.NOT_FOUND_404 :
                return false;
            case HttpSC.FORBIDDEN_403 :
                break;
            case HttpSC.MOVED_PERMANENTLY_301 : { // Moved permanently.
                System.err.println("301 Location: " + awsEx.getHttpHeaders().get(HttpNames.hLocation));
                break;
            }
        }
        throw awsEx;
    }
}
 
Example 9
Source Project: cassandra-backup   Source File: S3Backuper.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public FreshenResult freshenRemoteObject(final RemoteObjectReference object) throws InterruptedException {
    final String canonicalPath = ((S3RemoteObjectReference) object).canonicalPath;

    final CopyObjectRequest copyRequest = new CopyObjectRequest(request.storageLocation.bucket,
                                                                canonicalPath,
                                                                request.storageLocation.bucket,
                                                                canonicalPath).withStorageClass(StorageClass.Standard);

    try {
        // attempt to refresh existing object in the bucket via an inplace copy
        transferManager.copy(copyRequest).waitForCompletion();
        return FreshenResult.FRESHENED;

    } catch (final AmazonServiceException e) {
        // AWS S3 under certain access policies can't return NoSuchKey (404)
        // instead, it returns AccessDenied (403) — handle it the same way
        if (e.getStatusCode() != 404 && e.getStatusCode() != 403) {
            throw e;
        }

        // the freshen failed because the file/key didn't exist
        return FreshenResult.UPLOAD_REQUIRED;
    }
}
 
Example 10
public static void uploadDirWithSubprogress(
    String dir_path, String bucket_name, String key_prefix, boolean recursive, boolean pause) {
  System.out.println(
      "directory: " + dir_path + (recursive ? " (recursive)" : "") + (pause ? " (pause)" : ""));

  TransferManager xfer_mgr = new TransferManager();
  try {
    MultipleFileUpload multi_upload =
        xfer_mgr.uploadDirectory(bucket_name, key_prefix, new File(dir_path), recursive);
    // loop with Transfer.isDone()
    XferMgrProgress.showMultiUploadProgress(multi_upload);
    // or block with Transfer.waitForCompletion()
    XferMgrProgress.waitForCompletion(multi_upload);
  } catch (AmazonServiceException e) {
    System.err.println(e.getErrorMessage());
    System.exit(1);
  }
  xfer_mgr.shutdownNow();
}
 
Example 11
public void listingObjects(String bucketName, String key) throws AmazonServiceException {
  /**
   * List objects in your bucket by prefix - There are many options for
   * listing the objects in your bucket. Keep in mind that buckets with many
   * objects might truncate their results when listing their objects, so be
   * sure to check if the returned object listing is truncated, and use the
   * AmazonS3.listNextBatchOfObjects(...) operation to retrieve additional
   * results.
   */
  System.out.println("Listing objects");
  ListObjectsRequest request = new ListObjectsRequest().withBucketName(bucketName).withPrefix("My");
  ObjectListing objectListing = s3Client.listObjects(request);
  for (S3ObjectSummary objectSummary : objectListing.getObjectSummaries()) {
    System.out.println(" - " + objectSummary.getKey() + "  " + "(size = " + objectSummary.getSize() + ")");
  }
  System.out.println();
}
 
Example 12
Source Project: pacbot   Source File: InventoryUtilTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Fetch S 3 info test test exception.
 *
 * @throws Exception the exception
 */
@SuppressWarnings("static-access")
@Test
public void fetchS3InfoTestTest_Exception() throws Exception {
    
    mockStatic(AmazonS3ClientBuilder.class);
    AmazonS3 amazonS3Client = PowerMockito.mock(AmazonS3.class);
    AmazonS3ClientBuilder amazonRDSClientBuilder = PowerMockito.mock(AmazonS3ClientBuilder.class);
    AWSStaticCredentialsProvider awsStaticCredentialsProvider = PowerMockito.mock(AWSStaticCredentialsProvider.class);
    PowerMockito.whenNew(AWSStaticCredentialsProvider.class).withAnyArguments().thenReturn(awsStaticCredentialsProvider);
    when(amazonRDSClientBuilder.standard()).thenReturn(amazonRDSClientBuilder);
    when(amazonRDSClientBuilder.withCredentials(anyObject())).thenReturn(amazonRDSClientBuilder);
    when(amazonRDSClientBuilder.withRegion(anyString())).thenReturn(amazonRDSClientBuilder);
    when(amazonRDSClientBuilder.build()).thenReturn(amazonS3Client);
    
    List<Bucket> s3buckets = new ArrayList<>();
    Bucket bucket = new Bucket();
    bucket.setName("name");
    s3buckets.add(bucket);
    when(amazonS3Client.listBuckets()).thenReturn(s3buckets);
    
    when(amazonS3Client.getBucketLocation(anyString())).thenThrow(new AmazonServiceException("Error"));
    assertThat(inventoryUtil.fetchS3Info(new BasicSessionCredentials("awsAccessKey", "awsSecretKey", "sessionToken"), 
            "skipRegions", "account","accountName").size(), is(0));
}
 
Example 13
protected List<FlowFile> processServiceException(final ProcessSession session, List<FlowFile> flowFiles,
        AmazonServiceException exception) {
    List<FlowFile> failedFlowFiles = new ArrayList<>();
    for (FlowFile flowFile : flowFiles) {
        Map<String,String> attributes = new HashMap<>();
        attributes.put(DYNAMODB_ERROR_EXCEPTION_MESSAGE, exception.getMessage() );
        attributes.put(DYNAMODB_ERROR_CODE, exception.getErrorCode() );
        attributes.put(DYNAMODB_ERROR_MESSAGE, exception.getErrorMessage() );
        attributes.put(DYNAMODB_ERROR_TYPE, exception.getErrorType().name() );
        attributes.put(DYNAMODB_ERROR_SERVICE, exception.getServiceName() );
        attributes.put(DYNAMODB_ERROR_RETRYABLE, Boolean.toString(exception.isRetryable()));
        attributes.put(DYNAMODB_ERROR_REQUEST_ID, exception.getRequestId() );
        attributes.put(DYNAMODB_ERROR_STATUS_CODE, Integer.toString(exception.getStatusCode()) );
        attributes.put(DYNAMODB_ERROR_EXCEPTION_MESSAGE, exception.getMessage() );
        attributes.put(DYNAMODB_ERROR_RETRYABLE, Boolean.toString(exception.isRetryable()));
        flowFile = session.putAllAttributes(flowFile, attributes);
        failedFlowFiles.add(flowFile);
    }
    return failedFlowFiles;
}
 
Example 14
@Inject
public AmazonS3Storage (Configuration configuration) {
    bucketName = configuration.getString("storage.s3.bucket", "thunderbit");

    String accessKey = configuration.getString("storage.s3.accesskey");
    String secretKey = configuration.getString("storage.s3.secretkey");
    credentials = new BasicAWSCredentials(accessKey, secretKey);

    AmazonS3 amazonS3 = new AmazonS3Client(credentials);

    if (configuration.getBoolean("storage.s3.createBucket", true)) {
        try {
            if (!(amazonS3.doesBucketExist(bucketName))) {
                amazonS3.createBucket(new CreateBucketRequest(bucketName));
            }

            String bucketLocation = amazonS3.getBucketLocation(new GetBucketLocationRequest(bucketName));
            logger.info("Amazon S3 bucket created at " + bucketLocation);
        } catch (AmazonServiceException ase) {
            logAmazonServiceException (ase);
        } catch (AmazonClientException ace) {
            logAmazonClientException(ace);
        }
    }
}
 
Example 15
Source Project: aws-doc-sdk-examples   Source File: GetBucketPolicy.java    License: Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
    final String USAGE = "\n" +
            "Usage:\n" +
            "    GetBucketPolicy <bucket>\n\n" +
            "Where:\n" +
            "    bucket - the bucket to get the policy from.\n\n" +
            "Example:\n" +
            "    GetBucketPolicy testbucket\n\n";

    if (args.length < 1) {
        System.out.println(USAGE);
        System.exit(1);
    }

    String bucket_name = args[0];
    String policy_text = null;

    System.out.format("Getting policy for bucket: \"%s\"\n\n", bucket_name);

    final AmazonS3 s3 = AmazonS3ClientBuilder.standard().withRegion(Regions.DEFAULT_REGION).build();
    try {
        BucketPolicy bucket_policy = s3.getBucketPolicy(bucket_name);
        policy_text = bucket_policy.getPolicyText();
    } catch (AmazonServiceException e) {
        System.err.println(e.getErrorMessage());
        System.exit(1);
    }

    if (policy_text == null) {
        System.out.println("The specified bucket has no bucket policy.");
    } else {
        System.out.println("Returned policy:");
        System.out.println("----");
        System.out.println(policy_text);
        System.out.println("----\n");
    }

    System.out.println("Done!");
}
 
Example 16
private void renamePartitionInCatalog(String databaseName, String tableName,
                                      List<String> partitionValues, org.apache.hadoop.hive.metastore.api.Partition newPartition)
      throws InvalidOperationException, MetaException, TException {
  try {
    glueClient.updatePartition(
        new UpdatePartitionRequest()
        .withDatabaseName(databaseName)
        .withTableName(tableName)
        .withPartitionValueList(partitionValues)
        .withPartitionInput(GlueInputConverter.convertToPartitionInput(newPartition)));
  } catch (AmazonServiceException e) {
    throw CatalogToHiveConverter.wrapInHiveException(e);
  }
}
 
Example 17
/**
 * TODO: メソッドコメント
 * 
 * @param awsProcessClient
 * @return
 */
public AwsAddress createAddress(AwsProcessClient awsProcessClient) {
    // Elastic IPの確保
    AllocateAddressRequest request = new AllocateAddressRequest();
    if (BooleanUtils.isTrue(awsProcessClient.getPlatformAws().getVpc())) {
        request.withDomain(DomainType.Vpc);
    }

    String publicIp;
    try {
        AllocateAddressResult result = awsProcessClient.getEc2Client().allocateAddress(request);
        publicIp = result.getPublicIp();

    } catch (AutoException e) {
        // Elastic IPの上限オーバーの場合
        if (e.getCause() instanceof AmazonServiceException
                && "AddressLimitExceeded".equals(((AmazonServiceException) e.getCause()).getErrorCode())) {
            throw new AutoApplicationException("EPROCESS-000134");
        }

        throw e;
    }

    // イベントログ出力
    processLogger.debug(null, null, "AwsElasticIpAllocate",
            new Object[] { awsProcessClient.getPlatform().getPlatformName(), publicIp });

    // AWSアドレス情報を作成
    AwsAddress awsAddress = new AwsAddress();
    awsAddress.setUserNo(awsProcessClient.getUserNo());
    awsAddress.setPlatformNo(awsProcessClient.getPlatform().getPlatformNo());
    awsAddress.setPublicIp(publicIp);
    awsAddress.setComment("Allocate at " + DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
    awsAddressDao.create(awsAddress);

    return awsAddress;
}
 
Example 18
@Test
public void doGetTable()
        throws Exception
{
    when(glueClient.getTable(any())).thenThrow(new AmazonServiceException(""));

    GetTableRequest req = new GetTableRequest(TEST_IDENTITY, TEST_QUERY_ID, TEST_CATALOG_NAME, TEST_TABLE_NAME);
    GetTableResponse res = handler.doGetTable(allocator, req);

    logger.info("doGetTable - {}", res.getSchema());

    assertThat(res.getTableName().getSchemaName(), equalTo(DEFAULT_SCHEMA));
    assertThat(res.getTableName().getTableName(), equalTo(TEST_TABLE));
    assertThat(res.getSchema().getFields().size(), equalTo(10));
}
 
Example 19
Source Project: nifi   Source File: PutDynamoDBTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testStringHashStringRangePutThrowsServiceException() {
    final DynamoDB mockDynamoDB = new DynamoDB(Regions.AP_NORTHEAST_1) {
        @Override
        public BatchWriteItemOutcome batchWriteItem(TableWriteItems... tableWriteItems) {
            throw new AmazonServiceException("serviceException");
        }
    };

    putDynamoDB = new PutDynamoDB() {
        @Override
        protected DynamoDB getDynamoDB() {
            return mockDynamoDB;
        }
    };
    final TestRunner putRunner = TestRunners.newTestRunner(putDynamoDB);

    putRunner.setProperty(AbstractDynamoDBProcessor.ACCESS_KEY,"abcd");
    putRunner.setProperty(AbstractDynamoDBProcessor.SECRET_KEY, "cdef");
    putRunner.setProperty(AbstractDynamoDBProcessor.REGION, REGION);
    putRunner.setProperty(AbstractDynamoDBProcessor.TABLE, stringHashStringRangeTableName);
    putRunner.setProperty(AbstractDynamoDBProcessor.HASH_KEY_NAME, "hashS");
    putRunner.setProperty(AbstractDynamoDBProcessor.HASH_KEY_VALUE, "h1");
    putRunner.setProperty(AbstractDynamoDBProcessor.RANGE_KEY_NAME, "rangeS");
    putRunner.setProperty(AbstractDynamoDBProcessor.RANGE_KEY_VALUE, "r1");
    putRunner.setProperty(AbstractWriteDynamoDBProcessor.JSON_DOCUMENT, "document");
    String document = "{\"name\":\"john\"}";
    putRunner.enqueue(document.getBytes());

    putRunner.run(1);

    putRunner.assertAllFlowFilesTransferred(AbstractDynamoDBProcessor.REL_FAILURE, 1);
    List<MockFlowFile> flowFiles = putRunner.getFlowFilesForRelationship(AbstractDynamoDBProcessor.REL_FAILURE);
    for (MockFlowFile flowFile : flowFiles) {
        assertEquals("serviceException (Service: null; Status Code: 0; Error Code: null; Request ID: null)", flowFile.getAttribute(AbstractDynamoDBProcessor.DYNAMODB_ERROR_EXCEPTION_MESSAGE));
    }

}
 
Example 20
private static void createItems() {
    try {
        Map<String, AttributeValue> item1 = new HashMap<String, AttributeValue>();
        item1.put("Id", new AttributeValue().withN("120"));
        item1.put("Title", new AttributeValue().withS("Book 120 Title"));
        item1.put("ISBN", new AttributeValue().withS("120-1111111111"));
        item1.put("Authors", new AttributeValue().withSS(Arrays.asList("Author12", "Author22")));
        item1.put("Price", new AttributeValue().withN("20.00"));
        item1.put("Category", new AttributeValue().withS("Book"));
        item1.put("Dimensions", new AttributeValue().withS("8.5x11.0x.75"));
        item1.put("InPublication", new AttributeValue().withBOOL(false));

        PutItemRequest putItemRequest1 = new PutItemRequest().withTableName(tableName).withItem(item1);
        client.putItem(putItemRequest1);

        Map<String, AttributeValue> item2 = new HashMap<String, AttributeValue>();
        item2.put("Id", new AttributeValue().withN("121"));
        item2.put("Title", new AttributeValue().withS("Book 121 Title"));
        item2.put("ISBN", new AttributeValue().withS("121-1111111111"));
        item2.put("Price", new AttributeValue().withN("20.00"));
        item2.put("ProductCategory", new AttributeValue().withS("Book"));
        item2.put("Authors", new AttributeValue().withSS(Arrays.asList("Author21", "Author22")));
        item1.put("Dimensions", new AttributeValue().withS("8.5x11.0x.75"));
        item1.put("InPublication", new AttributeValue().withBOOL(true));

        PutItemRequest putItemRequest2 = new PutItemRequest().withTableName(tableName).withItem(item2);
        client.putItem(putItemRequest2);
    }
    catch (AmazonServiceException ase) {
        System.err.println("Create items failed.");
    }
}
 
Example 21
@Override
public UpdateItemResult updateItem(UpdateItemRequest request)
        throws AmazonServiceException, AmazonClientException {
    Map<String, ExpectedAttributeValue> expectedValues = request.getExpected();
    checkExpectedValues(request.getTableName(), request.getKey(), expectedValues);

    // conditional checks are handled by the above call
    request.setExpected(null);
    return txn.updateItem(request);
}
 
Example 22
@Test(expected = RuntimeException.class)
public void testRetryThrottleException() throws Exception {
  AmazonServiceException ase = new AmazonServiceException("Test");
  ase.setErrorCode("ProvisionedThroughputExceededException");
  ase.setStatusCode(400);
  when(call.call()).thenThrow(ase);
  DynamoDBFibonacciRetryer retryer = new DynamoDBFibonacciRetryer(Duration.standardSeconds(10));

  try {
    retryer.runWithRetry(call, null, null);
  } finally {
    verify(call, atLeast(2)).call();
    verify(call, atMost(15)).call();
  }
}
 
Example 23
Source Project: Cheddar   Source File: DynamoDbTemplateTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void shouldNotUpdateItem_withAmazonServiceException() throws Exception {
    // Given
    final ItemConfiguration itemConfiguration = new ItemConfiguration(StubItem.class, tableName);
    final Collection<ItemConfiguration> itemConfigurations = Arrays.asList(itemConfiguration);
    when(mockDatabaseSchemaHolder.itemConfigurations()).thenReturn(itemConfigurations);
    final DynamoDbTemplate dynamoDbTemplate = new DynamoDbTemplate(mockDatabaseSchemaHolder);
    final AmazonDynamoDB mockAmazonDynamoDbClient = mock(AmazonDynamoDB.class);
    dynamoDbTemplate.initialize(mockAmazonDynamoDbClient);
    final StubItem stubItem = new StubItem();
    stubItem.setId(randomId());
    final String stringPropertyValue = randomString(10);
    stubItem.setStringProperty(stringPropertyValue);
    final Long oldVersion = randomLong();
    stubItem.setVersion(oldVersion);
    when(mockAmazonDynamoDbClient.updateItem(any(UpdateItemRequest.class))).thenThrow(AmazonServiceException.class);

    // When
    PersistenceResourceFailureException actualException = null;
    try {
        dynamoDbTemplate.update(stubItem);
    } catch (final PersistenceResourceFailureException e) {
        actualException = e;
    }

    // Then
    assertNotNull(actualException);
}
 
Example 24
@Override
public CreateTableResult createTable(
        List<AttributeDefinition> attributeDefinitions, String tableName,
        List<KeySchemaElement> keySchema,
        ProvisionedThroughput provisionedThroughput)
        throws AmazonServiceException, AmazonClientException {
    throw new UnsupportedOperationException("Use the underlying client instance instead");
}
 
Example 25
@Override
public PutItemResult putItem(String tableName,
        Map<String, AttributeValue> item) throws AmazonServiceException,
        AmazonClientException {
    return putItem(new PutItemRequest()
            .withTableName(tableName)
            .withItem(item));
}
 
Example 26
Source Project: big-c   Source File: S3AFileSystem.java    License: Apache License 2.0 5 votes vote down vote up
private void deleteUnnecessaryFakeDirectories(Path f) throws IOException {
  while (true) {
    try {
      String key = pathToKey(f);
      if (key.isEmpty()) {
        break;
      }

      S3AFileStatus status = getFileStatus(f);

      if (status.isDirectory() && status.isEmptyDirectory()) {
        if (LOG.isDebugEnabled()) {
          LOG.debug("Deleting fake directory " + key + "/");
        }
        s3.deleteObject(bucket, key + "/");
        statistics.incrementWriteOps(1);
      }
    } catch (FileNotFoundException | AmazonServiceException e) {
    }

    if (f.isRoot()) {
      break;
    }

    f = f.getParent();
  }
}
 
Example 27
@Test(expected = JMSException.class)
public void testGetQueueUrlThrowAmazonServiceException() throws JMSException {

    GetQueueUrlRequest getQueueUrlRequest = new GetQueueUrlRequest(QUEUE_NAME);
    doThrow(new AmazonServiceException("ase"))
            .when(amazonSQSClient).getQueueUrl(eq(getQueueUrlRequest));

    wrapper.getQueueUrl(QUEUE_NAME);
}
 
Example 28
@Test
// Test that if a fallback subnet is specified, that the request for new nodes will fallback successfully and nodes will be spun up
public void testSubnetFallsBackSuccessfully() throws NodesCouldNotBeStartedException {
    MockAmazonEc2Client client = new MockAmazonEc2Client(null);
    AmazonServiceException exception = new AmazonServiceException("message");
    exception.setErrorCode("InsufficientInstanceCapacity");
    client.setThrowDescribeInstancesError(exception);
    RunInstancesResult runInstancesResult = new RunInstancesResult();
    Reservation reservation = new Reservation();
    reservation.setInstances(Arrays.asList(new Instance()));
    runInstancesResult.setReservation(reservation);
    client.setRunInstances(runInstancesResult);
    Properties properties = new Properties();
    String region = "east", uuid="uuid",browser="chrome",os="linux";
    Integer threadCount = 5,maxSessions=5;
    MockManageVm manageEC2 = new MockManageVm(client,properties,region);
    String userData = "userData";
    String securityGroup="securityGroup",subnetId="subnetId",keyName="keyName",windowsImage="windowsImage",fallBackSubnet="fallback";
    properties.setProperty(region + "_security_group",securityGroup);
    properties.setProperty(region + "_subnet_id", subnetId);
    properties.setProperty(region + "_subnet_fallback_id_1", fallBackSubnet);
    properties.setProperty(region + "_key_name", keyName);
    properties.setProperty(region + "_windows_node_ami", windowsImage);
    manageEC2.setUserData(userData);
    List<Instance> instances = manageEC2.launchNodes(uuid,os,browser,null,threadCount,maxSessions);
    System.out.print("");
}
 
Example 29
@Override
public void run() {
    logger.debug("Error storing object to dynamo, unprocessed items: {}. Retrying with exponential back-off",
            unprocessedItems);
    lastException = null;
    while (!unprocessedItems.isEmpty() && retry < WAIT_MILLIS_IN_RETRIES.length) {
        if (!sleep()) {
            // Interrupted
            return;
        }
        retry++;
        try {
            BatchWriteItemOutcome outcome = DynamoDBPersistenceService.this.db.getDynamoDB()
                    .batchWriteItemUnprocessed(unprocessedItems);
            unprocessedItems = outcome.getUnprocessedItems();
            lastException = null;
        } catch (AmazonServiceException e) {
            if (e instanceof ResourceNotFoundException) {
                logger.debug(
                        "DynamoDB query raised unexpected exception: {}. This might happen if table was recently created",
                        e.getMessage());
            } else {
                logger.debug("DynamoDB query raised unexpected exception: {}.", e.getMessage());
            }
            lastException = e;
            continue;
        }
    }
    if (unprocessedItems.isEmpty()) {
        logger.debug("After {} retries successfully wrote all unprocessed items", retry);
    } else {
        logger.warn(
                "Even after retries failed to write some items. Last exception: {} {}, unprocessed items: {}",
                lastException == null ? "null" : lastException.getClass().getName(),
                lastException == null ? "null" : lastException.getMessage(), unprocessedItems);
    }
}
 
Example 30
Source Project: pocket-etl   Source File: SqsExtractorTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void nextRetriesThreeTimesBeforeThrowingUnrecoverableStreamFailureExceptionInCaseOfServiceException() {
    when(mockAmazonSQS.receiveMessage(any(ReceiveMessageRequest.class))).thenThrow(new AmazonServiceException(SAMPLE_EXCEPTION));

    try {
        sqsExtractor.next();
    } catch (UnrecoverableStreamFailureException ignored) {}

    verify(mockAmazonSQS, times(3)).receiveMessage(any(ReceiveMessageRequest.class));
}