Example usage for com.amazonaws AmazonServiceException getMessage

List of usage examples for com.amazonaws AmazonServiceException getMessage

Introduction

In this page you can find the example usage for com.amazonaws AmazonServiceException getMessage.

Prototype

@Override
    public String getMessage() 

Source Link

Usage

From source file:io.relution.jenkins.awssqs.threading.SQSQueueMonitorSchedulerImpl.java

License:Apache License

private boolean hasQueueChanged(final SQSQueueMonitor monitor, final SQSQueue queue) {
    try {//from  www  .j  av a2  s . c  om
        final SQSQueue current = monitor.getQueue();

        if (!StringUtils.equals(current.getUrl(), queue.getUrl())) {
            return true;
        }

        if (!StringUtils.equals(current.getAWSAccessKeyId(), queue.getAWSAccessKeyId())) {
            return true;
        }

        if (!StringUtils.equals(current.getAWSSecretKey(), queue.getAWSSecretKey())) {
            return true;
        }

        if (current.getMaxNumberOfMessages() != queue.getMaxNumberOfMessages()) {
            return true;
        }

        if (current.getMaxNumberOfJobQueue() != queue.getMaxNumberOfJobQueue()) {
            return true;
        }

        if (current.isKeepQueueMessages() != queue.isKeepQueueMessages()) {
            return true;
        }

        if (current.getWaitTimeSeconds() != queue.getWaitTimeSeconds()) {
            return true;
        }

        return false;
    } catch (final com.amazonaws.AmazonServiceException e) {
        Log.warning("Cannot compare queues: %s", e.getMessage());
    } catch (final Exception e) {
        Log.severe(e, "Cannot compare queues, unknown error");
    }
    return true;
}

From source file:io.relution.jenkins.scmsqs.threading.SQSQueueMonitorSchedulerImpl.java

License:Apache License

private boolean hasQueueChanged(final SQSQueueMonitor monitor, final SQSQueue queue) {
    try {/*from   w w w .j  av  a  2 s  .  co  m*/
        final SQSQueue current = monitor.getQueue();

        if (!StringUtils.equals(current.getUrl(), queue.getUrl())) {
            return true;
        }

        if (!StringUtils.equals(current.getAWSAccessKeyId(), queue.getAWSAccessKeyId())) {
            return true;
        }

        if (!StringUtils.equals(current.getAWSSecretKey(), queue.getAWSSecretKey())) {
            return true;
        }

        if (current.getMaxNumberOfMessages() != queue.getMaxNumberOfMessages()) {
            return true;
        }

        if (current.getWaitTimeSeconds() != queue.getWaitTimeSeconds()) {
            return true;
        }

        return false;
    } catch (final com.amazonaws.AmazonServiceException e) {
        Log.warning("Cannot compare queues: %s", e.getMessage());
    } catch (final Exception e) {
        Log.severe(e, "Cannot compare queues, unknown error");
    }
    return true;
}

From source file:io.robrose.hop.watermap.aws.DynamoGeoClient.java

License:Open Source License

public static void main(String[] args) {
    init();/*from  w ww.j a v  a2s.c  o m*/

    try {
        String tableName = "water-safe-locations-table";
        config = new GeoDataManagerConfiguration(dynamoDB, tableName);
        geoDataManager = new GeoDataManager(config);
        // Create table if it does not exist yet
        if (Tables.doesTableExist(dynamoDB, tableName)) {
            System.out.println("Table " + tableName + " is already ACTIVE");
        } else {
            // Create a table with a primary hash key named 'name', which holds a string

            /*
             CreateTableRequest createTableRequest = new CreateTableRequest().withTableName(tableName)
            .withKeySchema(new KeySchemaElement().withAttributeName("name").withKeyType(KeyType.HASH))
            .withAttributeDefinitions(new AttributeDefinition().withAttributeName("name").withAttributeType(ScalarAttributeType.S))
            .withProvisionedThroughput(new ProvisionedThroughput().withReadCapacityUnits(1L).withWriteCapacityUnits(1L));
            TableDescription createdTableDescription = dynamoDB.createTable(createTableRequest).getTableDescription();
             */
            //AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);

            CreateTableRequest createTableRequest = GeoTableUtil.getCreateTableRequest(config);
            CreateTableResult createTableResult = dynamoDB.createTable(createTableRequest);
            System.out.println("Created Table: " + tableName);

            // Wait for it to become active
            System.out.println("Waiting for " + tableName + " to become ACTIVE...");
            Tables.waitForTableToBecomeActive(dynamoDB, tableName);
        }

        // Describe our new table
        DescribeTableRequest describeTableRequest = new DescribeTableRequest().withTableName(tableName);
        TableDescription tableDescription = dynamoDB.describeTable(describeTableRequest).getTable();
        System.out.println("Table Description: " + tableDescription);

        Map<String, String> m = new HashMap<>();
        m.put("lat", "51.5034070");
        m.put("lng", "-0.1275920");
        m.put("violationCode", "47");

        // request = new JSONObject(m);
        //try {
        //    putPoint(request);
        //}catch(JSONException f){
        //    System.out.println("Bad JSON");
        //}
        // Scan items for movies with a year attribute greater than 1985
        HashMap<String, Condition> scanFilter = new HashMap<>();
        Condition condition = new Condition().withComparisonOperator(ComparisonOperator.GT.toString())
                .withAttributeValueList(new AttributeValue().withN("1985"));
        scanFilter.put("year", condition);
        ScanRequest scanRequest = new ScanRequest(tableName);//.withScanFilter(scanFilter);
        ScanResult scanResult = dynamoDB.scan(scanRequest);
        System.out.println("Result: " + scanResult);

    } catch (AmazonServiceException ase) {
        System.out.println("Caught an AmazonServiceException, which means your request made it "
                + "to AWS, but was rejected with an error response for some reason.");
        System.out.println("Error Message:    " + ase.getMessage());
        System.out.println("HTTP Status Code: " + ase.getStatusCode());
        System.out.println("AWS Error Code:   " + ase.getErrorCode());
        System.out.println("Error Type:       " + ase.getErrorType());
        System.out.println("Request ID:       " + ase.getRequestId());
    } catch (AmazonClientException ace) {
        System.out.println("Caught an AmazonClientException, which means the client encountered "
                + "a serious internal problem while trying to communicate with AWS, "
                + "such as not being able to access the network.");
        System.out.println("Error Message: " + ace.getMessage());
    }
}

From source file:io.starter.messaging.SNSMobilePush.java

License:Open Source License

public static void main(String[] args) throws IOException {
    /*/*from   w w w . ja  va 2  s .  c  o m*/
     * TODO: Be sure to fill in your AWS access credentials in the
     * AwsCredentials.properties file before you try to run this sample.
     * http://aws.amazon.com/security-credentials
     */

    String awsAccessKey = System.getProperty("AWS_ACCESS_KEY_ID"); // "YOUR_AWS_ACCESS_KEY";
    String awsSecretKey = System.getProperty("AWS_SECRET_KEY"); // "YOUR_AWS_SECRET_KEY";

    if (awsAccessKey == null)
        awsAccessKey = AWS_ACCESS_KEY;
    if (awsSecretKey == null)
        awsSecretKey = AWS_SECRET_KEY;

    AWSCredentials credentials = new BasicAWSCredentials(awsAccessKey, awsSecretKey);

    AmazonSNS sns = new AmazonSNSClient(
            new PropertiesCredentials(SNSMobilePush.class.getResourceAsStream("AwsCredentials.properties")));

    // AmazonSNS sns = new AmazonSNSClient(credentials);

    sns.setEndpoint("https://sns.us-west-2.amazonaws.com");
    System.out.println("===========================================\n");
    System.out.println("Initializing Communication with Amazon SNS");
    System.out.println("===========================================\n");
    try {
        SNSMobilePush sample = new SNSMobilePush(sns);
        /* TODO: Uncomment the services you wish to use. */
        // sample.starterAndroidAppNotification();
        // sample.starterKindleAppNotification();
        sample.starterAppleAppNotification();
        // sample.starterAppleSandboxAppNotification();
        // sample.starterBaiduAppNotification();
        // sample.starterWNSAppNotification();
        // sample.starterMPNSAppNotification();
    } catch (AmazonServiceException ase) {
        System.out.println("Caught an AmazonServiceException, which means your request made it "
                + "to Amazon SNS, but was rejected with an error response for some reason.");
        System.out.println("Error Message:    " + ase.getMessage());
        System.out.println("HTTP Status Code: " + ase.getStatusCode());
        System.out.println("AWS Error Code:   " + ase.getErrorCode());
        System.out.println("Error Type:       " + ase.getErrorType());
        System.out.println("Request ID:       " + ase.getRequestId());
    } catch (AmazonClientException ace) {
        System.out.println("Caught an AmazonClientException, which means the client encountered "
                + "a serious internal problem while trying to communicate with SNS, such as not "
                + "being able to access the network.");
        System.out.println("Error Message: " + ace.getMessage());
    }
}

From source file:jenkins.plugins.ec2slave.EC2ImageLaunchWrapper.java

License:Open Source License

@Override
public void launch(SlaveComputer computer, TaskListener listener) throws IOException, InterruptedException {
    try {//  ww w .  j  av a  2s  .  c  o  m
        if (instanceId != null && getInstanceState(instanceId) == Pending) {
            throw new IllegalStateException("EC2 Instance " + instanceId
                    + " is in Pending state.  Not sure what to do here, try again?");
        }

        if (instanceId == null || getInstanceState(instanceId) == Stopped
                || getInstanceState(instanceId) == ShuttingDown) {
            // only start the EC2 instance if we haven't tried before or the instance was stopped externally
            preLaunch(listener.getLogger());
            preLaunchOk = true;
        } else {
            LOGGER.info("Skipping EC2 part of launch, since the instance is already running");
        }
    } catch (IllegalStateException ise) {
        listener.error(ise.getMessage());
        return;
    } catch (AmazonServiceException ase) {
        listener.error(ase.getMessage());
        return;
    } catch (AmazonClientException ace) {
        listener.error(ace.getMessage());
        return;
    }

    LOGGER.info("EC2 instance [" + instanceId
            + "] has been started to serve as a Jenkins slave.  Passing control to computer launcher.");
    try {
        computerLauncher = computerConnector.launch(getInstancePublicHostName(), listener);
    } catch (IOException ioException) {
        LOGGER.warning("IOException Error1: " + ioException.toString());
    } catch (InterruptedException interruptedException) {
        LOGGER.warning("InterruptedException Error1: " + interruptedException.toString());
    } catch (Exception exception) {
        LOGGER.warning("Exception Error1: " + exception.toString());
    }

    try {
        computerLauncher.launch(computer, listener);
    } catch (IOException ioException) {
        LOGGER.warning("IOException Error2: " + ioException.toString());
    } catch (InterruptedException interruptedException) {
        LOGGER.warning("InterruptedException Error2: " + interruptedException.toString());
    } catch (Exception exception) {
        LOGGER.warning("Exception Error2: " + exception.toString());
    }
}

From source file:jp.classmethod.aws.gradle.cloudformation.AmazonCloudFormationExecuteChangeSetTask.java

License:Apache License

@TaskAction
public void executeChangeSet() throws InterruptedException, IOException {
    // to enable conventionMappings feature
    String stackName = getStackName();

    if (stackName == null) {
        throw new GradleException("stackName is not specified");
    }//from ww w .ja v a 2 s . co  m

    AmazonCloudFormationPluginExtension ext = getProject().getExtensions()
            .getByType(AmazonCloudFormationPluginExtension.class);
    AmazonCloudFormation cfn = ext.getClient();

    try {
        DescribeStacksResult describeStackResult = cfn
                .describeStacks(new DescribeStacksRequest().withStackName(stackName));
        Stack stack = describeStackResult.getStacks().get(0);

        if (stableStatuses.contains(stack.getStackStatus())) {
            Optional<ChangeSetSummary> summary = getLatestChangeSetSummary(cfn);
            String changeSetName = summary
                    .orElseThrow(
                            () -> new GradleException("ChangeSet for stack " + stackName + " was not found."))
                    .getChangeSetName();
            ExecuteChangeSetRequest req = new ExecuteChangeSetRequest().withStackName(stackName)
                    .withChangeSetName(changeSetName);
            cfn.executeChangeSet(req);
            getLogger().info("ChangeSet is executed : {}, {}", stackName, changeSetName);
        } else {
            throw new GradleException("invalid status for update: " + stack.getStackStatus());
        }
    } catch (AmazonServiceException e) {
        if (e.getMessage().contains("does not exist")) {
            getLogger().warn("stack {} not found", stackName);
        } else if (e.getMessage().contains("No updates are to be performed.")) {
            getLogger().trace(e.getMessage());
        } else {
            throw e;
        }
    }

}

From source file:jp.classmethod.aws.gradle.cloudformation.AmazonCloudFormationMigrateStackTask.java

License:Apache License

@TaskAction
public void createOrUpdateStack() throws InterruptedException, IOException {
    // to enable conventionMappings feature
    String stackName = getStackName();
    String cfnTemplateUrl = getCfnTemplateUrl();
    File cfnTemplateFile = getCfnTemplateFile();
    List<String> stableStatuses = getStableStatuses();

    if (stackName == null) {
        throw new GradleException("stackName is not specified");
    }//from   ww w . jav a 2 s  .  c  om
    if (cfnTemplateUrl == null && cfnTemplateFile == null) {
        throw new GradleException("cfnTemplateUrl or cfnTemplateFile must be provided");
    }

    AmazonCloudFormationPluginExtension ext = getProject().getExtensions()
            .getByType(AmazonCloudFormationPluginExtension.class);
    AmazonCloudFormation cfn = ext.getClient();

    try {
        DescribeStacksResult describeStackResult = cfn
                .describeStacks(new DescribeStacksRequest().withStackName(stackName));
        Stack stack = describeStackResult.getStacks().get(0);
        if (stack.getStackStatus().equals("DELETE_COMPLETE")) {
            getLogger().warn("deleted stack {} already exists", stackName);
            deleteStack(cfn);
            createStack(cfn);
        } else if (stableStatuses.contains(stack.getStackStatus())) {
            updateStack(cfn);
        } else {
            throw new GradleException("invalid status for update: " + stack.getStackStatus());
        }
    } catch (AmazonServiceException e) {
        if (e.getMessage().contains("does not exist")) {
            getLogger().warn("stack {} not found", stackName);
            createStack(cfn);
        } else if (e.getMessage().contains("No updates are to be performed.")) {
            getLogger().trace(e.getMessage());
        } else {
            throw e;
        }
    }
}

From source file:jp.classmethod.aws.gradle.ec2.AmazonEC2AuthorizeSecurityGroupEgressTask.java

License:Apache License

@TaskAction
public void authorizeEgress() {
    // to enable conventionMappings feature
    String groupId = getGroupId();
    Object ipPermissions = getIpPermissions();

    if (groupId == null) {
        throw new GradleException("groupId is not specified");
    }/* www .  j  ava  2 s  .  co  m*/
    if (ipPermissions == null) {
        throw new GradleException("ipPermissions is not specified");
    }

    AmazonEC2PluginExtension ext = getProject().getExtensions().getByType(AmazonEC2PluginExtension.class);
    AmazonEC2 ec2 = ext.getClient();

    try {
        ec2.authorizeSecurityGroupEgress(new AuthorizeSecurityGroupEgressRequest().withGroupId(groupId)
                .withIpPermissions(parse(ipPermissions)));
    } catch (AmazonServiceException e) {
        if (e.getErrorCode().equals("InvalidPermission.Duplicate")) {
            getLogger().warn(e.getMessage());
        } else {
            throw e;
        }
    }
}

From source file:jp.classmethod.aws.gradle.ec2.AmazonEC2AuthorizeSecurityGroupIngressTask.java

License:Apache License

@TaskAction
public void authorizeIngress() {
    // to enable conventionMappings feature
    String groupId = getGroupId();
    Object ipPermissions = getIpPermissions();

    if (groupId == null) {
        throw new GradleException("groupId is not specified");
    }//from w  w w  .j  a va  2 s.c  om
    if (ipPermissions == null) {
        throw new GradleException("ipPermissions is not specified");
    }

    AmazonEC2PluginExtension ext = getProject().getExtensions().getByType(AmazonEC2PluginExtension.class);
    AmazonEC2 ec2 = ext.getClient();

    try {
        ec2.authorizeSecurityGroupIngress(new AuthorizeSecurityGroupIngressRequest().withGroupId(groupId)
                .withIpPermissions(parse(ipPermissions)));
    } catch (AmazonServiceException e) {
        if (e.getErrorCode().equals("InvalidPermission.Duplicate")) {
            getLogger().warn(e.getMessage());
        } else {
            throw e;
        }
    }
}

From source file:jp.classmethod.aws.gradle.ec2.AmazonEC2CreateSecurityGroupTask.java

License:Apache License

@TaskAction
public void authorizeIngress() {
    // to enable conventionMappings feature
    String groupName = getGroupName();
    String groupDescription = getGroupDescription();

    if (groupName == null) {
        throw new GradleException("groupName is not specified");
    }//from   w  w w  .j a  v  a2  s.  com

    AmazonEC2PluginExtension ext = getProject().getExtensions().getByType(AmazonEC2PluginExtension.class);
    AmazonEC2 ec2 = ext.getClient();

    try {
        createSecurityGroupResult = ec2.createSecurityGroup(
                new CreateSecurityGroupRequest().withGroupName(groupName).withDescription(groupDescription));
    } catch (AmazonServiceException e) {
        if (e.getErrorCode().equals("InvalidPermission.Duplicate")) {
            getLogger().warn(e.getMessage());
        } else {
            throw e;
        }
    }
}