Package org.jclouds.ec2.features

Examples of org.jclouds.ec2.features.ElasticIPAddressApi


            .providerId(instanceCreatedId).status(Status.RUNNING).build();
      // setup mocks
      EC2CreateNodesInGroupThenAddToSet strategy = setupStrategy(nodeMetadata);
      InputParams input = new InputParams(location);
      InstanceApi instanceClient = createMock(InstanceApi.class);
      ElasticIPAddressApi ipClient = createMock(ElasticIPAddressApi.class);
      RunInstancesOptions ec2Options = createMock(RunInstancesOptions.class);
      RunningInstance instance = createMock(RunningInstance.class);
      Reservation<? extends RunningInstance> reservation = new Reservation<RunningInstance>(region,
            ImmutableSet.<String> of(), ImmutableSet.<RunningInstance> of(instance), "ownerId", "requesterId",
            "reservationId");

      // enable auto-allocation
      strategy.autoAllocateElasticIps = true;

      // setup expectations
      expect(input.template.clone()).andReturn(input.template);
      expect(strategy.client.getInstanceApi()).andReturn((Optional) Optional.of(instanceClient)).atLeastOnce();
      expect(
            strategy.createKeyPairAndSecurityGroupsAsNeededAndReturncustomize
                  .execute(region, input.tag, input.template)).andReturn(ec2Options);
      expect(strategy.client.getElasticIPAddressApi()).andReturn((Optional) Optional.of(ipClient)).atLeastOnce();

      expect(input.template.getLocation()).andReturn(input.location).atLeastOnce();
      expect(input.template.getImage()).andReturn(input.image).atLeastOnce();
      expect(input.image.getProviderId()).andReturn(imageId).atLeastOnce();

      // differences when ip allocation
      expect(ipClient.allocateAddressInRegion(region)).andReturn("1.1.1.1");
      expect(strategy.runningInstanceToNodeMetadata.apply(instance)).andReturn(nodeMetadata).atLeastOnce();
      ipClient.associateAddressInRegion(region, "1.1.1.1", instanceCreatedId);
      strategy.elasticIpCache.put(new RegionAndName(region, instanceCreatedId), "1.1.1.1");

      expect(instanceClient.runInstancesInRegion(region, zone, imageId, 1, input.count, ec2Options)).andReturn(
            Reservation.class.cast(reservation));
      expect(instance.getId()).andReturn(instanceCreatedId).atLeastOnce();
View Full Code Here


    IaasProvider iaasInfo = getIaasProvider();
   
    ComputeServiceContext context = iaasInfo.getComputeService()
        .getContext();
   
    ElasticIPAddressApi elasticIPAddressApi = context.unwrapApi(AWSEC2Api.class).getElasticIPAddressApi().get();
    String region = ComputeServiceBuilderUtil.extractRegion(iaasInfo);
   
    String ip = null;

    // first try to find an unassigned IP.
    ArrayList<PublicIpInstanceIdPair> unassignedIps = Lists
        .newArrayList(Iterables.filter(elasticIPAddressApi.describeAddressesInRegion(region, new String[0]),
            new Predicate<PublicIpInstanceIdPair>() {

              @Override
              public boolean apply(PublicIpInstanceIdPair arg0) {
                return arg0.getInstanceId() == null;
              }

            }));

    if (!unassignedIps.isEmpty()) {
      // try to prevent multiple parallel launches from choosing the same
      // ip.
      Collections.shuffle(unassignedIps);
      ip = Iterables.getLast(unassignedIps).getPublicIp();
    }

    // if no unassigned IP is available, we'll try to allocate an IP.
    if (ip == null || ip.isEmpty()) {
      try {
        ip = elasticIPAddressApi
            .allocateAddressInRegion(region);
        log.info("Allocated ip [" + ip + "]");

      } catch (Exception e) {
        String msg = "Failed to allocate an IP address. All IP addresses are in use.";
View Full Code Here

    IaasProvider iaasInfo = getIaasProvider();
   
    ComputeServiceContext context = iaasInfo.getComputeService()
        .getContext();
    ElasticIPAddressApi elasticIPAddressApi = context.unwrapApi(AWSEC2Api.class).getElasticIPAddressApi().get();
    String region = ComputeServiceBuilderUtil.extractRegion(iaasInfo);

    elasticIPAddressApi.disassociateAddressInRegion(
        region, ip);
    elasticIPAddressApi.releaseAddressInRegion(region,
        ip);
  }
View Full Code Here

            .providerId(instanceCreatedId).status(Status.RUNNING).build();
      // setup mocks
      EC2CreateNodesInGroupThenAddToSet strategy = setupStrategy(nodeMetadata);
      InputParams input = new InputParams(location);
      InstanceApi instanceClient = createMock(InstanceApi.class);
      ElasticIPAddressApi ipClient = createMock(ElasticIPAddressApi.class);
      RunInstancesOptions ec2Options = createMock(RunInstancesOptions.class);
      RunningInstance instance = createMock(RunningInstance.class);
      Reservation<? extends RunningInstance> reservation = new Reservation<RunningInstance>(region,
            ImmutableSet.<String> of(), ImmutableSet.<RunningInstance> of(instance), "ownerId", "requesterId",
            "reservationId");

      // enable auto-allocation
      strategy.autoAllocateElasticIps = true;

      // setup expectations
      expect(input.template.clone()).andReturn(input.template);
      expect(strategy.client.getInstanceApi()).andReturn((Optional) Optional.of(instanceClient)).atLeastOnce();
      expect(
            strategy.createKeyPairAndSecurityGroupsAsNeededAndReturncustomize
                  .execute(region, input.tag, input.template)).andReturn(ec2Options);
      expect(strategy.client.getElasticIPAddressApi()).andReturn((Optional) Optional.of(ipClient)).atLeastOnce();

      expect(input.template.getLocation()).andReturn(input.location).atLeastOnce();
      expect(input.template.getImage()).andReturn(input.image).atLeastOnce();
      expect(input.image.getProviderId()).andReturn(imageId).atLeastOnce();

      // differences when ip allocation
      expect(ipClient.allocateAddressInRegion(region)).andReturn("1.1.1.1");
      expect(strategy.runningInstanceToNodeMetadata.apply(instance)).andReturn(nodeMetadata).atLeastOnce();
      ipClient.associateAddressInRegion(region, "1.1.1.1", instanceCreatedId);
      strategy.elasticIpCache.put(new RegionAndName(region, instanceCreatedId), "1.1.1.1");

      expect(instanceClient.runInstancesInRegion(region, zone, imageId, 1, input.count, ec2Options)).andReturn(
            Reservation.class.cast(reservation));
      expect(instance.getId()).andReturn(instanceCreatedId).atLeastOnce();
View Full Code Here

   public void testDestroyNodeDisassociatesAndReleasesIpThenTerminatesInstanceAndReturnsRefreshedNode()
            throws Exception {
      EC2Api client = createMock(EC2Api.class);
      GetNodeMetadataStrategy getNode = createMock(GetNodeMetadataStrategy.class);
      LoadingCache<RegionAndName, String> elasticIpCache = createMock(LoadingCache.class);
      ElasticIPAddressApi ipClient = createMock(ElasticIPAddressApi.class);
      InstanceApi instanceClient = createMock(InstanceApi.class);

      NodeMetadata node = createMock(NodeMetadata.class);

      expect(elasticIpCache.get(new RegionAndName("region", "i-blah"))).andReturn("1.1.1.1");

      expect(client.getElasticIPAddressApi()).andReturn((Optional) Optional.of(ipClient)).atLeastOnce();
      ipClient.disassociateAddressInRegion("region", "1.1.1.1");
      ipClient.releaseAddressInRegion("region", "1.1.1.1");
      elasticIpCache.invalidate(new RegionAndName("region", "i-blah"));


      expect(client.getInstanceApi()).andReturn((Optional) Optional.of(instanceClient)).atLeastOnce();
      expect(instanceClient.terminateInstancesInRegion("region", "i-blah")).andReturn(null);
View Full Code Here

   public void testDestroyNodeSafeOnCacheMissThenTerminatesInstanceAndReturnsRefreshedNode()
            throws Exception {
      EC2Api client = createMock(EC2Api.class);
      GetNodeMetadataStrategy getNode = createMock(GetNodeMetadataStrategy.class);
      LoadingCache<RegionAndName, String> elasticIpCache = createMock(LoadingCache.class);
      ElasticIPAddressApi ipClient = createMock(ElasticIPAddressApi.class);
      InstanceApi instanceClient = createMock(InstanceApi.class);

      NodeMetadata node = createMock(NodeMetadata.class);

      expect(elasticIpCache.get(new RegionAndName("region", "i-blah"))).andThrow(new CacheLoader.InvalidCacheLoadException(null));
View Full Code Here

   public void testDestroyNodeSafeOnCacheExecutionExceptionThenTerminatesInstanceAndReturnsRefreshedNode()
            throws Exception {
      EC2Api client = createMock(EC2Api.class);
      GetNodeMetadataStrategy getNode = createMock(GetNodeMetadataStrategy.class);
      LoadingCache<RegionAndName, String> elasticIpCache = createMock(LoadingCache.class);
      ElasticIPAddressApi ipClient = createMock(ElasticIPAddressApi.class);
      InstanceApi instanceClient = createMock(InstanceApi.class);

      NodeMetadata node = createMock(NodeMetadata.class);

      expect(elasticIpCache.get(new RegionAndName("region", "i-blah"))).andThrow(new ExecutionException(null));
View Full Code Here

public class LoadPublicIpForInstanceOrNullTest {

   @Test
   public void testReturnsPublicIpOnMatch() throws Exception {
      EC2Api client = createMock(EC2Api.class);
      ElasticIPAddressApi ipClient = createMock(ElasticIPAddressApi.class);

      expect(client.getElasticIPAddressApi()).andReturn((Optional) Optional.of(ipClient)).atLeastOnce();
      expect(ipClient.describeAddressesInRegion("region")).andReturn(
               ImmutableSet.<PublicIpInstanceIdPair> of(new PublicIpInstanceIdPair("region", "1.1.1.1", "i-blah")))
               .atLeastOnce();

      replay(client);
      replay(ipClient);
View Full Code Here

   }

   @Test
   public void testReturnsNullWhenNotFound() throws Exception {
      EC2Api client = createMock(EC2Api.class);
      ElasticIPAddressApi ipClient = createMock(ElasticIPAddressApi.class);

      expect(client.getElasticIPAddressApi()).andReturn((Optional) Optional.of(ipClient)).atLeastOnce();

      expect(ipClient.describeAddressesInRegion("region")).andReturn(ImmutableSet.<PublicIpInstanceIdPair> of())
               .atLeastOnce();

      replay(client);
      replay(ipClient);
View Full Code Here

   }

   @Test
   public void testReturnsNullWhenNotAssigned() throws Exception {
      EC2Api client = createMock(EC2Api.class);
      ElasticIPAddressApi ipClient = createMock(ElasticIPAddressApi.class);

      expect(client.getElasticIPAddressApi()).andReturn((Optional) Optional.of(ipClient)).atLeastOnce();

      expect(ipClient.describeAddressesInRegion("region")).andReturn(
               ImmutableSet.<PublicIpInstanceIdPair> of(new PublicIpInstanceIdPair("region", "1.1.1.1", null)))
               .atLeastOnce();

      replay(client);
      replay(ipClient);
View Full Code Here

TOP

Related Classes of org.jclouds.ec2.features.ElasticIPAddressApi

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.