public Volume apply(ResourceAllocationSettingData from) {
   return new VolumeImpl(
       from.getAddressOnParent() + "",
       Volume.Type.LOCAL,
       from.getVirtualQuantity() == null
           ? null
           : from.getVirtualQuantity().longValue() / 1024 / 1024f,
       null,
       "0".equals(from.getAddressOnParent())
           || ResourceType.BASE_PARTITIONABLE_UNIT.equals(from.getResourceType()),
       true);
 }
예제 #2
0
  @Test(
      description = "PUT /vApp/{id}/virtualHardwareSection",
      dependsOnMethods = {"testGetVirtualHardwareSection"})
  public void testEditVirtualHardwareSection() {
    // Power off Vm
    vm = powerOffVm(vmUrn);

    // Copy existing section and edit fields
    VirtualHardwareSection oldSection = vmApi.getVirtualHardwareSection(vmUrn);
    Set<? extends ResourceAllocationSettingData> oldItems = oldSection.getItems();
    Set<ResourceAllocationSettingData> newItems = Sets.newLinkedHashSet(oldItems);
    ResourceAllocationSettingData oldMemory =
        Iterables.find(
            oldItems,
            new Predicate<ResourceAllocationSettingData>() {
              @Override
              public boolean apply(ResourceAllocationSettingData rasd) {
                return rasd.getResourceType() == ResourceAllocationSettingData.ResourceType.MEMORY;
              }
            });
    ResourceAllocationSettingData newMemory =
        oldMemory
            .toBuilder()
            .elementName("1024 MB of memory")
            .virtualQuantity(new BigInteger("1024"))
            .build();
    newItems.remove(oldMemory);
    newItems.add(newMemory);
    VirtualHardwareSection newSection = oldSection.toBuilder().items(newItems).build();

    // The method under test
    Task editVirtualHardwareSection = vmApi.editVirtualHardwareSection(vmUrn, newSection);
    assertTrue(
        retryTaskSuccess.apply(editVirtualHardwareSection),
        String.format(TASK_COMPLETE_TIMELY, "editVirtualHardwareSection"));

    // Retrieve the modified section
    VirtualHardwareSection modifiedSection = vmApi.getVirtualHardwareSection(vmUrn);

    // Check the retrieved object is well formed
    checkVirtualHardwareSection(modifiedSection);

    // Check the modified section fields are set correctly
    ResourceAllocationSettingData modifiedMemory =
        Iterables.find(
            modifiedSection.getItems(),
            new Predicate<ResourceAllocationSettingData>() {
              @Override
              public boolean apply(ResourceAllocationSettingData rasd) {
                return rasd.getResourceType() == ResourceAllocationSettingData.ResourceType.MEMORY;
              }
            });
    assertEquals(modifiedMemory.getVirtualQuantity(), new BigInteger("1024"));
    assertEquals(modifiedMemory, newMemory);
    assertEquals(modifiedSection, newSection);
  }