Package org.jclouds.openstack.trove.v1.features

Examples of org.jclouds.openstack.trove.v1.features.InstanceApi


      NodeMetadata nodeMetadata = new NodeMetadataBuilder().id(region + "/" + instanceCreatedId)
            .providerId(instanceCreatedId).status(Status.RUNNING).build();
      // setup mocks
      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));
View Full Code Here


            .providerId(instanceCreatedId).status(Status.RUNNING).build();

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

               .getSecurityGroupApi().get();

      KeyPairApi keyPairClient = view.unwrapApi(EC2Api.class)
               .getKeyPairApi().get();

      InstanceApi instanceClient = view.unwrapApi(EC2Api.class)
               .getInstanceApi().get();

      String group = this.group + "o";

      TemplateOptions options = client.templateOptions();
View Full Code Here

   public void testMapEBS() throws Exception {
      if (ebsTemplate == null) {
         throw new SkipException("Test cannot run without the parameter test." + provider
               + ".ebs-template; this property should be in the format defined in TemplateBuilderSpec");
      }
      InstanceApi instanceClient = view.unwrapApi(EC2Api.class)
               .getInstanceApi().get();

      ElasticBlockStoreApi ebsClient = view.unwrapApi(EC2Api.class)
               .getElasticBlockStoreApi().get();

      String group = this.group + "e";
      int volumeSize = 8;
     
      final Template template = view.getComputeService().templateBuilder().from(ebsTemplate).build();

      Location zone = Iterables.find(view.getComputeService().listAssignableLocations(), new Predicate<Location>() {

         @Override
         public boolean apply(Location arg0) {
            return arg0.getScope() == LocationScope.ZONE
                     && arg0.getParent().getId().equals(template.getLocation().getId());
         }

      });

      // create volume only to make a snapshot
      Volume volume = ebsClient.createVolumeInAvailabilityZone(zone.getId(), 4);
      // Sleep for 5 seconds to make sure the volume creation finishes.
      Thread.sleep(5000);

      Snapshot snapshot = ebsClient.createSnapshotInRegion(volume.getRegion(), volume.getId());
      ebsClient.deleteVolumeInRegion(volume.getRegion(), volume.getId());

      template.getOptions().as(EC2TemplateOptions.class)//
               // .unmapDeviceNamed("/dev/foo)
               .mapEphemeralDeviceToDeviceName("/dev/sdm", "ephemeral0")//
               .mapNewVolumeToDeviceName("/dev/sdn", volumeSize, true)//
               .mapEBSSnapshotToDeviceName("/dev/sdo", snapshot.getId(), volumeSize, true);

      try {
         NodeMetadata node = Iterables.getOnlyElement(client.createNodesInGroup(group, 1, template));

         // TODO figure out how to validate the ephemeral drive. perhaps with df -k?

         Map<String, BlockDevice> devices = instanceClient.getBlockDeviceMappingForInstanceInRegion(node.getLocation()
                  .getParent().getId(), node.getProviderId());

         BlockDevice device = devices.get("/dev/sdn");
         // check delete on termination
         assertTrue(device.isDeleteOnTermination());
View Full Code Here

               .getSecurityGroupApi().get();

      KeyPairApi keyPairClient = view.unwrapApi(EC2Api.class)
               .getKeyPairApi().get();

      InstanceApi instanceClient = view.unwrapApi(EC2Api.class)
               .getInstanceApi().get();

      String group = this.group + "o";

      TemplateOptions options = client.templateOptions();
View Full Code Here

   public void testMapEBS() throws Exception {
      if (ebsTemplate == null) {
         throw new SkipException("Test cannot run without the parameter test." + provider
               + ".ebs-template; this property should be in the format defined in TemplateBuilderSpec");
      }
      InstanceApi instanceClient = view.unwrapApi(EC2Api.class)
               .getInstanceApi().get();

      ElasticBlockStoreApi ebsClient = view.unwrapApi(EC2Api.class)
               .getElasticBlockStoreApi().get();

      String group = this.group + "e";
      int volumeSize = 8;
     
      final Template template = view.getComputeService().templateBuilder().from(ebsTemplate).build();

      Location zone = Iterables.find(view.getComputeService().listAssignableLocations(), new Predicate<Location>() {

         @Override
         public boolean apply(Location arg0) {
            return arg0.getScope() == LocationScope.ZONE
                     && arg0.getParent().getId().equals(template.getLocation().getId());
         }

      });

      // create volume only to make a snapshot
      Volume volume = ebsClient.createVolumeInAvailabilityZone(zone.getId(), 4);
      // Sleep for 5 seconds to make sure the volume creation finishes.
      Thread.sleep(5000);

      Snapshot snapshot = ebsClient.createSnapshotInRegion(volume.getRegion(), volume.getId());
      ebsClient.deleteVolumeInRegion(volume.getRegion(), volume.getId());

      template.getOptions().as(EC2TemplateOptions.class)//
               // .unmapDeviceNamed("/dev/foo)
               .mapEphemeralDeviceToDeviceName("/dev/sdm", "ephemeral0")//
               .mapNewVolumeToDeviceName("/dev/sdn", volumeSize, true)//
               .mapEBSSnapshotToDeviceName("/dev/sdo", snapshot.getId(), volumeSize, true);

      try {
         NodeMetadata node = Iterables.getOnlyElement(client.createNodesInGroup(group, 1, template));

         // TODO figure out how to validate the ephemeral drive. perhaps with df -k?

         Map<String, BlockDevice> devices = instanceClient.getBlockDeviceMappingForInstanceInRegion(node.getLocation()
                  .getParent().getId(), node.getProviderId());

         BlockDevice device = devices.get("/dev/sdn");
         // check delete on termination
         assertTrue(device.isDeleteOnTermination());
View Full Code Here

      NodeMetadata nodeMetadata = new NodeMetadataBuilder().id(region + "/" + instanceCreatedId)
            .providerId(instanceCreatedId).status(Status.RUNNING).build();
      // setup mocks
      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));
View Full Code Here

            .providerId(instanceCreatedId).status(Status.RUNNING).build();

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

   @SuppressWarnings("unchecked")
   @Test
   public void testDestroyNodeTerminatesInstanceAndReturnsRefreshedNode() throws Exception {
      EC2Api client = createMock(EC2Api.class);
      InstanceApi instanceClient = createMock(InstanceApi.class);
      GetNodeMetadataStrategy getNode = createMock(GetNodeMetadataStrategy.class);
      LoadingCache<RegionAndName, String> elasticIpCache = createMock(LoadingCache.class);

      NodeMetadata node = createMock(NodeMetadata.class);

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

      replay(client);
      replay(getNode);
      replay(instanceClient);
View Full Code Here

            throws Exception {
      EC2Api client = createMock(EC2Api.class);
      GetNodeMetadataStrategy getNode = createMock(GetNodeMetadataStrategy.class);
      LoadingCache<RegionAndName, String> elasticIpCache = createMock(LoadingCache.class);
      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);

      replay(client);
      replay(getNode);
      replay(elasticIpCache);
View Full Code Here

TOP

Related Classes of org.jclouds.openstack.trove.v1.features.InstanceApi

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.