Example usage for com.amazonaws.services.ec2.model AssociateAddressRequest AssociateAddressRequest

List of usage examples for com.amazonaws.services.ec2.model AssociateAddressRequest AssociateAddressRequest

Introduction

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

Prototype

public AssociateAddressRequest(String instanceId, String publicIp) 

Source Link

Document

Constructs a new AssociateAddressRequest object.

Usage

From source file:com.agilegroups.aws.services.AmazonEC2ServicesImpl.java

License:Apache License

@Override
public AssociateAddressResult associateAddress(InstanceModel model) {

    AssociateAddressRequest request = new AssociateAddressRequest(model.getInstanceId(), model.getIpAddress());

    return this.client.associateAddress(request);
}

From source file:com.appdynamics.connectors.AWSConnector.java

License:Apache License

private void setElasticIp(IMachine machine, String elasticIp, AmazonEC2 connector) throws ConnectorException {
    try {//  w  w w  . jav  a2 s.  c  om
        connector.associateAddress(new AssociateAddressRequest(machine.getName(), elasticIp));

        machine.setIpAddress(elasticIp);
    } catch (AmazonServiceException e) {
        throw new ConnectorException(e);
    } catch (AmazonClientException e) {
        throw new ConnectorException(e);
    }
}

From source file:fr.xebia.workshop.continuousdelivery.CreateNexusInstance.java

License:Apache License

@Override
public void execute(AmazonEC2 ec2, WorkshopInfrastructure workshopInfrastructure) throws Exception {
    logger.info("STARTING CREATE NEXUS SERVER");

    // TERMINATE EXISTING NEXUS SERVERS IF EXIST
    AmazonAwsUtils.terminateInstancesByRole(TeamInfrastructure.ROLE_NEXUS, ec2);

    // CREATE NEXUS INSTANCE
    String cloudConfigFilePath = "fr/xebia/workshop/continuousdelivery/cloud-config-amzn-linux-nexus.txt";
    String userData = CloudInitUserDataBuilder.start().addCloudConfigFromFilePath(cloudConfigFilePath)
            .buildBase64UserData();//w  w  w .java 2s.c o  m

    RunInstancesRequest runInstancesRequest = new RunInstancesRequest() //
            .withInstanceType(InstanceType.T1Micro.toString()) //
            .withImageId(AmazonAwsUtils.AMI_AMZN_LINUX_EU_WEST) //
            .withMinCount(1) //
            .withMaxCount(1) //
            .withSecurityGroupIds("accept-all") //
            .withKeyName(KEY_PAIR_NAME) //
            .withUserData(userData);

    // START NEXUS INSTANCE
    List<Instance> nexusInstances = AmazonAwsUtils.reliableEc2RunInstances(runInstancesRequest, ec2);
    Instance nexusInstance = Iterables.getOnlyElement(nexusInstances);

    // TAG NEXUS INSTANCES
    CreateTagsRequest createTagsRequest = new CreateTagsRequest();
    createTagsRequest.withResources(nexusInstance.getInstanceId()) //
            .withTags(//
                    new Tag("Name", "nexus"), //
                    new Tag("Workshop", "continuous-delivery-workshop"), //
                    new Tag("Role", TeamInfrastructure.ROLE_NEXUS));
    ec2.createTags(createTagsRequest);

    // first waits for Nexus availability, otherwise the following elastic IP assignment will break its installation
    waitForNexusAvailability(nexusInstance);

    final String publicIp = workshopInfrastructure.getNexusPublicIp();

    // ASSOCIATE NEXUS INSTANCE WITH PUBLIC IP
    Address address = Iterables.getOnlyElement(
            ec2.describeAddresses(new DescribeAddressesRequest().withPublicIps(publicIp)).getAddresses());
    String currentlyAssociatedId = address.getInstanceId();
    if (currentlyAssociatedId == null) {
        logger.debug("Public IP {} is not currently associated with an instance", publicIp);
    } else {
        logger.info("Public IP {} is currently associated instance '{}'. Disassociate it first.", publicIp,
                currentlyAssociatedId);
        ec2.disassociateAddress(new DisassociateAddressRequest(publicIp));
    }

    ec2.associateAddress(new AssociateAddressRequest(nexusInstance.getInstanceId(), publicIp));

    try {
        AmazonAwsUtils.awaitForHttpAvailability(workshopInfrastructure.getNexusUrlWithIp());
        AmazonAwsUtils.awaitForHttpAvailability(workshopInfrastructure.getNexusUrlWithDomainName());
    } catch (Exception e) {
        logger.warn("Silently skipped " + e, e);
    }

    logger.info("1 NEXUS SERVER {} SUCCESSFULLY CREATED AND ASSOCIATED WITH {}: {}",
            new Object[] { nexusInstance.getInstanceId(), publicIp, nexusInstance });
}

From source file:net.roboconf.target.ec2.internal.Ec2MachineConfigurator.java

License:Apache License

/**
 * Associates an elastic IP with the VM.
 * @return true if there is nothing more to do about elastic IP configuration, false otherwise
 *//*ww  w.j av a  2 s.com*/
private boolean associateElasticIp() {

    String elasticIp = this.targetProperties.get(Ec2Constants.ELASTIC_IP);
    if (!Utils.isEmptyOrWhitespaces(elasticIp)) {
        this.logger.fine("Associating an elastic IP with the instance. IP = " + elasticIp);
        AssociateAddressRequest associateAddressRequest = new AssociateAddressRequest(this.machineId,
                elasticIp);
        this.ec2Api.associateAddress(associateAddressRequest);
    }

    return true;
}

From source file:org.openinfinity.cloud.service.administrator.EC2Wrapper.java

License:Apache License

public boolean assignElasticIPToInstance(String instanceId, String ipAddress) {
    try {//from  w ww .j  a v  a2  s .  c o m
        AssociateAddressRequest associateAddressRequest = new AssociateAddressRequest(instanceId, ipAddress);
        ec2.associateAddress(associateAddressRequest);
    } catch (Exception e) {
        String message = e.getMessage();
        LOG.error("Error associating elastic IP address to instance " + instanceId + ": " + message);
        ExceptionUtil.throwSystemException(message, e);
    }
    return true;
}