Example usage for com.amazonaws.services.ec2.model AllocateAddressRequest withDomain

List of usage examples for com.amazonaws.services.ec2.model AllocateAddressRequest withDomain

Introduction

In this page you can find the example usage for com.amazonaws.services.ec2.model AllocateAddressRequest withDomain.

Prototype


public AllocateAddressRequest withDomain(DomainType domain) 

Source Link

Document

Set to vpc to allocate the address for use with instances in a VPC.

Usage

From source file:jp.primecloud.auto.process.aws.AwsAddressProcess.java

License:Open Source License

/**
 * TODO: /*  w w  w.j  av  a2  s. c om*/
 * 
 * @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;
}