List of usage examples for com.amazonaws.services.ec2.model DisassociateAddressRequest DisassociateAddressRequest
public DisassociateAddressRequest(String publicIp)
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();//from w w w . j av a2 s .co 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:org.openinfinity.cloud.service.administrator.EC2Wrapper.java
License:Apache License
public boolean removeElasticIPFromInstance(String ipAddress) { try {//from w w w . j a v a2 s . c om DisassociateAddressRequest req = new DisassociateAddressRequest(ipAddress); ec2.disassociateAddress(req); } catch (Exception e) { String message = e.getMessage(); LOG.error("Error removing elastic IP address (" + ipAddress + ") from instance"); ExceptionUtil.throwSystemException(message, e); } return true; }