Examples of RunningInstance


Examples of org.jclouds.ec2.domain.RunningInstance

      }
   }

   @Test(enabled = false, dependsOnMethods = "testCreateRunningInstance")
   void testReboot() throws InterruptedException, ExecutionException, TimeoutException, IOException {
      RunningInstance instance = getInstance(instanceId);
      System.out.printf("%d: %s rebooting instance %n", System.currentTimeMillis(), instanceId);
      client.getInstanceServices().rebootInstancesInRegion(null, instanceId);
      Thread.sleep(1000);
      instance = getInstance(instanceId);
      blockUntilWeCanSshIntoInstance(instance);
      SshClient ssh = sshFactory.create(HostAndPort.fromParts(instance.getIpAddress(), 22),
            LoginCredentials.builder().user("root").privateKey(keyPair.getKeyMaterial()).build());
      try {
         ssh.connect();
         ExecResponse uptime = ssh.exec("uptime");
         assert uptime.getOutput().indexOf("0 min") != -1 : "reboot didn't work: " + uptime;
View Full Code Here

Examples of org.jclouds.ec2.domain.RunningInstance

         assert first.getCredentials() != null : first;
         assert first.getCredentials().identity != null : first;

         startedId = Iterables.getOnlyElement(nodes).getProviderId();

         RunningInstance instance = getInstance(instanceClient, startedId);

         assertEquals(instance.getKeyName(), group);

         // make sure we made our dummy group and also let in the user's group
         assertEquals(Sets.newTreeSet(instance.getGroupNames()), ImmutableSortedSet.<String> of("jclouds#" + group + "#"
                  + instance.getRegion(), group));

         // make sure our dummy group has no rules
         SecurityGroup secgroup = Iterables.getOnlyElement(securityGroupClient.describeSecurityGroupsInRegion(null,
                  "jclouds#" + group + "#" + instance.getRegion()));
         assert secgroup.size() == 0 : secgroup;

         // try to run a script with the original keyPair
         runScriptWithCreds(group, first.getOperatingSystem(),
               LoginCredentials.builder().user(first.getCredentials().identity).privateKey(result.getKeyMaterial())
View Full Code Here

Examples of org.jclouds.ec2.domain.RunningInstance

    * Gets the instance with the given ID from the default region
    *
    * @throws NoSuchElementException If no instance with that id exists, or the instance is in a different region
    */
   public static RunningInstance getInstance(InstanceClient instanceClient, String id) {
      RunningInstance instance = Iterables.getOnlyElement(Iterables.getOnlyElement(instanceClient
               .describeInstancesInRegion(null, id)));
      return instance;
   }
View Full Code Here

Examples of org.jclouds.ec2.domain.RunningInstance

   public void testCreateRunningInstance() throws Exception {
      instance = createInstance(IMAGE_ID);
   }

   private RunningInstance createInstance(String imageId) throws UnknownHostException {
      RunningInstance instance = null;
      while (instance == null) {
         try {
            System.out.printf("%d: running instance%n", System.currentTimeMillis());
            Reservation<? extends RunningInstance> reservation = client.getInstanceServices().runInstancesInRegion(
                  null, null, // allow
                  // ec2
                  // to
                  // chose
                  // an
                  // availability
                  // zone
                  imageId, 1, // minimum instances
                  1, // maximum instances
                  withKeyName(keyPair.getKeyName())// key I created above
                        .asType(InstanceType.M1_SMALL)// smallest instance
                        // size
                        .withSecurityGroup(securityGroupName));// group I
            // created
            // above
            instance = Iterables.getOnlyElement(reservation);
         } catch (HttpResponseException htpe) {
            if (htpe.getResponse().getStatusCode() == 400)
               continue;
            throw htpe;
         }
      }
      assertNotNull(instance.getId());
      assertEquals(instance.getInstanceState(), InstanceState.PENDING);
      instance = blockUntilWeCanSshIntoInstance(instance);
      return instance;
   }
View Full Code Here

Examples of org.jclouds.ec2.domain.RunningInstance

      EC2CreateNodesInGroupThenAddToSet strategy = setupStrategy(nodeMetadata);
      InputParams input = new InputParams(location);
      InstanceClient instanceClient = createMock(InstanceClient.class);
      ElasticIPAddressClient ipClient = createMock(ElasticIPAddressClient.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.getInstanceServices()).andReturn(instanceClient).atLeastOnce();
      expect(
            strategy.createKeyPairAndSecurityGroupsAsNeededAndReturncustomize
                  .execute(region, input.tag, input.template)).andReturn(ec2Options);
      expect(strategy.client.getElasticIPAddressServices()).andReturn(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();
      // 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);
View Full Code Here

Examples of org.jclouds.ec2.domain.RunningInstance

      // setup mocks
      EC2CreateNodesInGroupThenAddToSet strategy = setupStrategy(nodeMetadata);
      InputParams input = new InputParams(location);
      InstanceClient instanceClient = createMock(InstanceClient.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");

      // setup expectations
      expect(input.template.clone()).andReturn(input.template);
      expect(strategy.client.getInstanceServices()).andReturn(instanceClient).atLeastOnce();
      expect(
            strategy.createKeyPairAndSecurityGroupsAsNeededAndReturncustomize
                  .execute(region, input.tag, input.template)).andReturn(ec2Options);
      expect(input.template.getLocation()).andReturn(input.location).atLeastOnce();
      expect(input.template.getImage()).andReturn(input.image).atLeastOnce();
      expect(input.image.getProviderId()).andReturn(imageId).atLeastOnce();
      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);
View Full Code Here

Examples of org.jclouds.ec2.domain.RunningInstance

      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();
      // 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);
View Full Code Here

Examples of org.jclouds.ec2.domain.RunningInstance

      // setup mocks
      EC2CreateNodesInGroupThenAddToSet strategy = setupStrategy(nodeMetadata);
      InputParams input = new InputParams(location);
      InstanceApi instanceClient = createMock(InstanceApi.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");

      // 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(input.template.getLocation()).andReturn(input.location).atLeastOnce();
      expect(input.template.getImage()).andReturn(input.image).atLeastOnce();
      expect(input.image.getProviderId()).andReturn(imageId).atLeastOnce();
      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);
View Full Code Here

Examples of org.jclouds.ec2.domain.RunningInstance

   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);
View Full Code Here

Examples of org.jclouds.ec2.domain.RunningInstance

         // Verify that the output of createNodesInGroup is the same.
         assertEquals(client.createNodesInGroup(group, 1, options), nodes, "Idempotency failing - got different instances");
        
         startedId = Iterables.getOnlyElement(nodes).getProviderId();

         RunningInstance instance = getInstance(instanceClient, startedId);

         assertEquals(instance.getKeyName(), group);

         // make sure we made our dummy group and also let in the user's group
         assertEquals(ImmutableSortedSet.copyOf(instance.getGroupNames()), ImmutableSortedSet.<String> of("jclouds#" + group, group));

         // make sure our dummy group has no rules
         SecurityGroup secgroup = Iterables.getOnlyElement(securityGroupClient.describeSecurityGroupsInRegion(null,
                  "jclouds#" + group));
         assert secgroup.size() == 0 : secgroup;
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.