Package org.jclouds.aws.ec2

Examples of org.jclouds.aws.ec2.AWSEC2Api


   }

   @Test
   public void testApplyWithIllegalStateExceptionRetriesWhenExistingKeyNotFound() {
      AWSEC2Api client = createMock(AWSEC2Api.class);
      AWSKeyPairApi keyApi = createMock(AWSKeyPairApi.class);

      expect(client.getKeyPairApi()).andReturn((Optional) Optional.of(keyApi)).atLeastOnce();

      expect(keyApi.importKeyPairInRegion("region", "jclouds#group", PUBLIC_KEY)).andThrow(
               new IllegalStateException());
      expect(keyApi.describeKeyPairsInRegion("region", "jclouds#group")).andReturn(ImmutableSet.<KeyPair> of());
      expect(keyApi.importKeyPairInRegion("region", "jclouds#group", PUBLIC_KEY)).andThrow(
View Full Code Here


   public void testFilterWhenResponseIs2xx() {
      HttpResponse filterResponse = HttpResponse.builder().statusCode(200)
              .payload(payloadFromResourceWithContentType("/describe_spot_instance.xml", "text/xml")).build();

      AWSEC2Api apiWhenExist = requestsSendResponses(describeRegionsRequest, describeRegionsResponse, filter, filterResponse)
              .getContext().unwrapApi(AWSEC2Api.class);

      SpotInstanceRequest request = getOnlyElement(apiWhenExist.getSpotInstanceApi().get().describeSpotInstanceRequestsInRegionWithFilter("us-east-1",
              ImmutableMultimap.<String, String>builder()
                      .put("instance-id", "i-ef308e8e")
                      .build()));

      assertEquals(request.getId(), "sir-1ede0012");
View Full Code Here

   }

   public void testFilterWhenResponseIs404() {
      HttpResponse filterResponse = HttpResponse.builder().statusCode(404).build();

      AWSEC2Api apiWhenNotExist = requestsSendResponses(describeRegionsRequest, describeRegionsResponse, filter, filterResponse)
              .getContext().unwrapApi(AWSEC2Api.class);

      assertEquals(apiWhenNotExist.getSpotInstanceApi().get().describeSpotInstanceRequestsInRegionWithFilter("us-east-1",
              ImmutableMultimap.<String, String>builder()
                      .put("instance-id", "i-ef308e8e")
                      .build()),
              ImmutableSet.of());
   }
View Full Code Here

   public void testFilterWhenResponseIs2xx() {
      HttpResponse filterResponse = HttpResponse.builder().statusCode(200)
              .payload(payloadFromResourceWithContentType("/describe_placement_groups.xml", "text/xml")).build();

      AWSEC2Api apiWhenExist = requestsSendResponses(describeRegionsRequest, describeRegionsResponse, filter, filterResponse)
              .getContext().unwrapApi(AWSEC2Api.class);

      PlacementGroup group = getOnlyElement(apiWhenExist.getPlacementGroupApi().get().describePlacementGroupsInRegionWithFilter("us-east-1",
              ImmutableMultimap.<String, String>builder()
                      .put("strategy", "cluster")
                      .build()));

      assertEquals(group.getName(), "XYZ-cluster");
View Full Code Here

   }

   public void testFilterWhenResponseIs404() {
      HttpResponse filterResponse = HttpResponse.builder().statusCode(404).build();

      AWSEC2Api apiWhenNotExist = requestsSendResponses(describeRegionsRequest, describeRegionsResponse, filter, filterResponse)
              .getContext().unwrapApi(AWSEC2Api.class);

      assertEquals(apiWhenNotExist.getPlacementGroupApi().get().describePlacementGroupsInRegionWithFilter("us-east-1",
              ImmutableMultimap.<String, String>builder()
                      .put("strategy", "cluster")
                      .build()),
              ImmutableSet.of());
   }
View Full Code Here

     
      GroupNamingConvention.Factory namingConvention = Guice.createInjector(new AbstractModule() {

         @Override
         protected void configure() {
            Names.bindProperties(binder(),new AWSEC2ApiMetadata().getDefaultProperties());
         }

      }).getInstance(GroupNamingConvention.Factory.class);

      AWSRunningInstanceToNodeMetadata parser = new AWSRunningInstanceToNodeMetadata(instanceToNodeStatus,
View Full Code Here

   public void testWhenSpotsPresentSingleCall() {

      Function<SpotInstanceRequest, AWSRunningInstance> converter = Functions.forMap(ImmutableMap.of(spot1, instance1,
            spot2, instance2));

      AWSEC2Client client = createMock(AWSEC2Client.class);
      SpotInstanceClient spotClient = createMock(SpotInstanceClient.class);

      expect(client.getSpotInstanceServices()).andReturn(spotClient);
      expect(spotClient.describeSpotInstanceRequestsInRegion("us-east-1", "sir-aaaa", "sir-bbbb")).andReturn(
            ImmutableSet.of(spot1, spot2));

      replay(client, spotClient);
View Full Code Here

   @SuppressWarnings("unchecked")
   @Test
   public void testWhenInstancesPresentSingleCall() {

      AWSEC2Client client = createMock(AWSEC2Client.class);
      AWSInstanceClient instanceClient = createMock(AWSInstanceClient.class);
      Function<SpotInstanceRequest, AWSRunningInstance> converter = createMock(Function.class);

      expect(client.getInstanceServices()).andReturn(instanceClient);
     
      // avoid imatcher fail.  if you change this, be sure to check multiple jres
      expect(instanceClient.describeInstancesInRegion("us-east-1", "i-aaaa", "i-bbbb")).andReturn(
            Set.class.cast(ImmutableSet.of(Reservation.<AWSRunningInstance> builder().region("us-east-1")
                  .instances(ImmutableSet.of(instance1, instance2)).build())));
View Full Code Here

    String ec2Msg = " ec2. Region: " + region + " - Key Pair Name: ";

    ComputeServiceContext context = iaasInfo.getComputeService()
        .getContext();
    AWSEC2Client ec2Client = context.unwrap(AWSEC2ApiMetadata.CONTEXT_TOKEN).getApi();

    ImportOrReturnExistingKeypair importer = new ImportOrReturnExistingKeypair(
        ec2Client);

    RegionNameAndPublicKeyMaterial regionNameAndKey = new RegionNameAndPublicKeyMaterial(
View Full Code Here

  public synchronized String associateAddress(IaasProvider iaasInfo,
      NodeMetadata node) {

    ComputeServiceContext context = iaasInfo.getComputeService()
        .getContext();
    AWSEC2Client ec2Client = context.unwrap(AWSEC2ApiMetadata.CONTEXT_TOKEN).getApi();
    String region = ComputeServiceBuilderUtil.extractRegion(iaasInfo);
   
    String ip = null;

    // first try to find an unassigned IP.
    ArrayList<PublicIpInstanceIdPair> unassignedIps = Lists
        .newArrayList(Iterables.filter(ec2Client
            .getElasticIPAddressServices()
            .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 = ec2Client.getElasticIPAddressServices()
            .allocateAddressInRegion(region);
        log.info("Assigned ip [" + ip + "]");

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

TOP

Related Classes of org.jclouds.aws.ec2.AWSEC2Api

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.