Package org.jclouds.aws.ec2.compute.domain

Examples of org.jclouds.aws.ec2.compute.domain.RegionAndName


      checkNotNull(region, "region");
      checkNotNull(name, "name");
      logger.debug(">> creating securityGroup region(%s) name(%s)", region, name);
      try {
         securityClient.createSecurityGroupInRegion(region, name, name);
         boolean created = securityGroupEventualConsistencyDelay.apply(new RegionAndName(region, name));
         if (!created)
            throw new RuntimeException(String.format("security group %s/%s is not available after creating", region,
                  name));
         logger.debug("<< created securityGroup(%s)", name);
         for (int port : ports) {
View Full Code Here


   protected void releaseAnyPublicIpForInstanceInRegion(String instanceId, String region) {
      if (!autoAllocateElasticIps)
         return;
      try {
         String ip = elasticIpCache.get(new RegionAndName(region, instanceId));
         logger.debug(">> disassociating elastic IP %s", ip);
         client.getElasticIPAddressApi().get().disassociateAddressInRegion(region, ip);
         logger.trace("<< disassociated elastic IP %s", ip);
         elasticIpCache.invalidate(new RegionAndName(region, instanceId));
         logger.debug(">> releasing elastic IP %s", ip);
         client.getElasticIPAddressApi().get().releaseAddressInRegion(region, ip);
         logger.trace("<< released elastic IP %s", ip);
      } catch (CacheLoader.InvalidCacheLoadException e) {
         // no ip was found
View Full Code Here

   private void blockUntilRunningAndAssignElasticIpsToInstancesOrPutIntoBadMap(Set<RunningInstance> input,
         Map<NodeMetadata, Exception> badNodes) {
      Map<RegionAndName, RunningInstance> instancesById = Maps.uniqueIndex(input, instanceToRegionAndName);
      for (Map.Entry<RegionAndName, RunningInstance> entry : instancesById.entrySet()) {
         RegionAndName id = entry.getKey();
         RunningInstance instance = entry.getValue();
         try {
            logger.debug("<< allocating elastic IP instance(%s)", id);
            String ip = client.getElasticIPAddressApi().get().allocateAddressInRegion(id.getRegion());
            // block until instance is running
            logger.debug(">> awaiting status running instance(%s)", id);
            AtomicReference<NodeMetadata> node = newReference(runningInstanceToNodeMetadata
                  .apply(instance));
            nodeRunning.apply(node);
            logger.trace("<< running instance(%s)", id);
            logger.debug(">> associating elastic IP %s to instance %s", ip, id);
            client.getElasticIPAddressApi().get().associateAddressInRegion(id.getRegion(), ip, id.getName());
            logger.trace("<< associated elastic IP %s to instance %s", ip, id);
            // add mapping of instance to ip into the cache
            elasticIpCache.put(id, ip);
         } catch (RuntimeException e) {
            badNodes.put(runningInstanceToNodeMetadata.apply(instancesById.get(id)), e);
View Full Code Here

      } else if (keyPairName != null) {
         if (options.getLoginPrivateKey() != null) {
            String pem = options.getLoginPrivateKey();
            KeyPair keyPair = KeyPair.builder().region(region).keyName(keyPairName).fingerprint(
                     fingerprintPrivateKey(pem)).sha1OfPrivateKey(sha1PrivateKey(pem)).keyMaterial(pem).build();
            RegionAndName key = new RegionAndName(region, keyPairName);
            credentialsMap.put(key, keyPair);
         }
      }

      if (options.getRunScript() != null) {
         RegionAndName regionAndName = new RegionAndName(region, keyPairName);
         checkArgument(
                  credentialsMap.containsKey(regionAndName),
                  "no private key configured for: %s; please use options.overrideLoginCredentialWith(rsa_private_text)",
                  regionAndName);
      }
View Full Code Here

      return keyPairName;
   }

   // base EC2 driver currently does not support key import
   protected String createOrImportKeyPair(String region, String group, TemplateOptions options) {
      RegionAndName regionAndGroup = new RegionAndName(region, group);
      KeyPair keyPair;
      // make sure that we don't request multiple keys simultaneously
      synchronized (credentialsMap) {
         // if there is already a keypair for the group specified, use it
         if (credentialsMap.containsKey(regionAndGroup))
            return credentialsMap.get(regionAndGroup).getKeyName();

         // otherwise create a new keypair and key it under the group and also the regular keyname
         keyPair = makeKeyPair.apply(new RegionAndName(region, group));
         credentialsMap.put(regionAndGroup, keyPair);
      }
      credentialsMap.put(new RegionAndName(region, keyPair.getKeyName()), keyPair);
      return keyPair.getKeyName();
   }
View Full Code Here

               .operatingSystem(new OperatingSystem(OsFamily.UBUNTU, null, "1.0", "hvm", "ubuntu", true))
               .description("description").version("1.0").defaultCredentials(LoginCredentials.builder().user("root").build())
               .status(Image.Status.AVAILABLE)
               .build();
      Map<RegionAndName, Image> imageMap = ImmutableMap.of(
               new RegionAndName(image.getLocation().getId(), image.getProviderId()), image);
     
      // weird compilation error means have to declare extra generics for call to build() - see https://bugs.eclipse.org/bugs/show_bug.cgi?id=365818
      Supplier<LoadingCache<RegionAndName, ? extends Image>> imageCache = Suppliers.<LoadingCache<RegionAndName, ? extends Image>> ofInstance(
               CacheBuilder.newBuilder().<RegionAndName,Image>build(CacheLoader.from(Functions.forMap(imageMap))));
View Full Code Here

      // 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();
      // simulate a lazy credentials fetch
      LoginCredentials creds = LoginCredentials.builder().user("foo").privateKey("bar").build();
      expect(strategy.instanceToCredentials.apply(instance)).andReturn(Optional.of(creds));
      expect(instance.getRegion()).andReturn(region).atLeastOnce();
      expect(strategy.credentialStore.put("node#" + region + "/" + instanceCreatedId, creds)).andReturn(null);

      expect(strategy.presentInstances.apply(ImmutableSet.of(new RegionAndName(region, instanceCreatedId)))).andReturn(ImmutableSet.of(instance));
      expect(input.template.getOptions()).andReturn(input.options).atLeastOnce();
      expect(input.options.getLoginUser()).andReturn(null);
      expect(input.options.getLoginPassword()).andReturn(null);
      expect(input.options.getLoginPrivateKey()).andReturn(null);
      expect(input.options.shouldAuthenticateSudo()).andReturn(null);
View Full Code Here

      LoginCredentials creds = LoginCredentials.builder().user("foo").privateKey("bar").build();
      expect(strategy.instanceToCredentials.apply(instance)).andReturn(Optional.of(creds));
      expect(instance.getRegion()).andReturn(region).atLeastOnce();
      expect(strategy.credentialStore.put("node#" + region + "/" + instanceCreatedId, creds)).andReturn(null);

      expect(strategy.presentInstances.apply(ImmutableSet.of(new RegionAndName(region, instanceCreatedId)))).andReturn(ImmutableSet.of(instance));
      expect(input.template.getOptions()).andReturn(input.options).atLeastOnce();
      expect(input.options.getLoginUser()).andReturn(null);
      expect(input.options.getLoginPassword()).andReturn(null);
      expect(input.options.getLoginPrivateKey()).andReturn(null);
      expect(input.options.shouldAuthenticateSudo()).andReturn(null);
View Full Code Here

      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);
      expect(getNode.getNode("region/i-blah")).andReturn(node);
View Full Code Here

      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));

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

TOP

Related Classes of org.jclouds.aws.ec2.compute.domain.RegionAndName

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.