Package org.jclouds.ibm.smartcloud.domain

Examples of org.jclouds.ibm.smartcloud.domain.Instance


      } catch (IllegalStateException e) {
         // must have been found
         connection.updatePublicKey(GROUP, keyPair.get("public"));
         key = connection.getKey(GROUP);
         for (String instanceId : key.getInstanceIds()) {
            Instance instance = connection.getInstance(instanceId);
            if (instance.getStatus() == Instance.Status.FAILED || instance.getStatus() == Instance.Status.ACTIVE) {
               killInstance(instance.getId());
            }
         }
      }
      assertEquals(key.getName(), GROUP);
      assert keyPair.get("public").indexOf(key.getKeyMaterial()) > 0;
View Full Code Here


   }

   private void killInstance(final String nameToKill) {
      Set<? extends Instance> instances = connection.listInstances();
      try {
         Instance instance = Iterables.find(instances, new Predicate<Instance>() {

            @Override
            public boolean apply(Instance input) {
               return input.getName().equals(nameToKill);
            }

         });
         if (instance.getStatus() != Instance.Status.DEPROVISIONING
                  && instance.getStatus() != Instance.Status.DEPROVISION_PENDING) {
            System.out.println("deleting instance: " + instance);
            int timeout = (instance.getStatus() == Instance.Status.NEW || instance.getStatus() == Instance.Status.PROVISIONING) ? 300
                     : 30;
            assert new RetryablePredicate<Instance>(new InstanceActiveOrFailed(connection), timeout, 2,
                     TimeUnit.SECONDS).apply(instance) : instance;
            connection.deleteInstance(instance.getId());
         }
         assert new RetryablePredicate<Instance>(new InstanceRemovedOrNotFound(connection), 120, 2, TimeUnit.SECONDS)
                  .apply(instance) : instance;
      } catch (NoSuchElementException ex) {
      }
View Full Code Here

   @Test
   public void testGetInstance() throws Exception {
      Set<? extends Instance> response = connection.listInstances();
      assertNotNull(response);
      if (response.size() > 0) {
         Instance instance = Iterables.get(response, 0);
         assertEquals(connection.getInstance(instance.getId()).getId(), instance.getId());
      }
   }
View Full Code Here

      this.instanceToNodeMetadata = instanceToNodeMetadata;
   }

   @Override
   public NodeMetadata getNode(String id) {
      Instance instance = client.getInstance(checkNotNull(id, "id"));
      return instance == null ? null : instanceToNodeMetadata.apply(instance);
   }
View Full Code Here

      this.getNode = checkNotNull(getNode, "getNode");
   }

   @Override
   public NodeMetadata destroyNode(String id) {
      Instance instance = client.getInstance(id);
      if (instance != null && instance.getStatus() != Instance.Status.DEPROVISIONING
               && instance.getStatus() != Instance.Status.DEPROVISION_PENDING) {
         // often it takes 8 minutes to finish provisioning a suse host
         int timeout = (instance.getStatus() == Instance.Status.NEW || instance.getStatus() == Instance.Status.PROVISIONING) ? 600
                  : 30;
         logger.debug(">> awaiting up to %s seconds for instance %s to be ready for delete", timeout, id);
         boolean ready = new RetryablePredicate<Instance>(new InstanceActiveOrFailed(client), timeout, 2,
                  TimeUnit.SECONDS).apply(instance);
         logger.debug(">> instance state is %sready, deleting", ready ? "" : "not ", id);
         client.deleteInstance(instance.getId());
      }
      return instance != null ? getNode.getNode(id) : null;
   }
View Full Code Here

   @Override
   public NodeMetadata createNodeWithGroupEncodedIntoName(String group, String name, Template template) {
      IBMSmartCloudTemplateOptions templateOptions = template.getOptions().as(IBMSmartCloudTemplateOptions.class);
      CreateInstanceOptions options = authorizePublicKey(templateOptions.getKeyPair()).isMiniEphemeral(
               IBMSmartCloudTemplateOptions.class.cast(template.getOptions()).isMiniEphemeral());
      Instance instance = client.createInstanceInLocation(template.getLocation().getId(), name, template.getImage()
               .getProviderId(), template.getHardware().getProviderId(), options);
      return instanceToNodeMetadata.apply(instance);
   }
View Full Code Here

TOP

Related Classes of org.jclouds.ibm.smartcloud.domain.Instance

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.