Examples of AWSEC2Client


Examples of com.elastisys.scale.cloudadapters.aws.ec2.scalinggroup.client.AwsEc2Client

*
*/
public class Main {

  public static void main(String[] args) throws Exception {
    ScalingGroup scalingGroup = new Ec2ScalingGroup(new AwsEc2Client());
    CloudAdapterServer.main(new BaseCloudAdapter(scalingGroup), args);
  }
View Full Code Here

Examples of org.jclouds.aws.ec2.AWSEC2Client

   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

Examples of org.jclouds.aws.ec2.AWSEC2Client

   @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

Examples of org.jclouds.aws.ec2.AWSEC2Client

    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

Examples of org.jclouds.aws.ec2.AWSEC2Client

  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

Examples of org.jclouds.aws.ec2.AWSEC2Client

  @Override
  public synchronized void releaseAddress(IaasProvider iaasInfo, String ip) {

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

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

Examples of org.jclouds.aws.ec2.AWSEC2Client

   private static final KeyPair pairWithFingerprint = pair.toBuilder().fingerprint(fingerprintPublicKey(PUBLIC_KEY))
            .build();

   @Test
   public void testApply() {
      AWSEC2Client client = createMock(AWSEC2Client.class);
      AWSKeyPairClient keyClient = createMock(AWSKeyPairClient.class);

      expect(client.getKeyPairServices()).andReturn(keyClient).atLeastOnce();

      expect(keyClient.importKeyPairInRegion("region", "jclouds#group", PUBLIC_KEY)).andReturn(pair);

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

Examples of org.jclouds.aws.ec2.AWSEC2Client

      verify(keyClient);
   }

   @Test
   public void testApplyWithIllegalStateExceptionReturnsExistingKey() {
      AWSEC2Client client = createMock(AWSEC2Client.class);
      AWSKeyPairClient keyClient = createMock(AWSKeyPairClient.class);

      expect(client.getKeyPairServices()).andReturn(keyClient).atLeastOnce();

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

Examples of org.jclouds.aws.ec2.AWSEC2Client

   }

   @Test
   public void testApplyWithIllegalStateExceptionRetriesWhenExistingKeyNotFound() {
      AWSEC2Client client = createMock(AWSEC2Client.class);
      AWSKeyPairClient keyClient = createMock(AWSKeyPairClient.class);

      expect(client.getKeyPairServices()).andReturn(keyClient).atLeastOnce();

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

Examples of org.jclouds.aws.ec2.AWSEC2Client

      provider = "aws-ec2";
   }

   @Override
   protected Iterable<? extends Image> listImages() {
      AWSEC2Client client = view.utils().injector().getInstance(AWSEC2Client.class);
      String[] parts = AWSUtils.parseHandle(imageId);
      String region = parts[0];
      String imageId = parts[1];
      EC2ImageParser parser = view.utils().injector().getInstance(EC2ImageParser.class);
      return transform(
            client.getAMIServices().describeImagesInRegion(region, new DescribeImagesOptions().imageIds(imageId)),
            parser);
   }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.