public Builder fromResourceAllocationSettingData(ResourceAllocationSettingData in) { return fromManagedElement(in).address(in.getAddress()).addressOnParent(in.getAddressOnParent()) .allocationUnits(in.getAllocationUnits()).automaticAllocation(in.isAutomaticAllocation()) .automaticDeallocation(in.isAutomaticDeallocation()).consumerVisibility(in.getConsumerVisibility()) .limit(in.getLimit()).mappingBehavior(in.getMappingBehavior()) .otherResourceType(in.getOtherResourceType()).parent(in.getParent()).poolID(in.getPoolID()) .reservation(in.getReservation()).resourceSubType(in.getResourceSubType()) .resourceType(in.getResourceType()).virtualQuantity(in.getVirtualQuantity()) .virtualQuantityUnits(in.getVirtualQuantityUnits()).weight(in.getWeight()) .connections(in.getConnections()).hostResources(in.getHostResources()); }
/** * {@inheritDoc} */ @Override public Builder toBuilder() { return builder().fromResourceAllocationSettingData(this); }
public ResourceAllocationSettingData build() { return new ResourceAllocationSettingData(elementName, instanceID, caption, description, address, addressOnParent, allocationUnits, automaticAllocation, automaticDeallocation, consumerVisibility, limit, mappingBehavior, otherResourceType, parent, poolID, reservation, resourceSubType, resourceType, virtualQuantity, virtualQuantityUnits, weight, connections, hostResources); }
public Volume apply(ResourceAllocationSettingData from) { return new VolumeImpl(from.getAddressOnParent() + "", Volume.Type.LOCAL, from.getVirtualQuantity() == null ? null : from.getVirtualQuantity() / (float) (1024 * 1024), null, "0".equals(from.getAddressOnParent()) || ResourceType.BASE_PARTITIONABLE_UNIT.equals(from.getResourceType()), true); } }
public void testApplyInputStream() { InputStream is = getClass().getResourceAsStream("/item.xml"); ResourceAllocationSettingData result = factory.create( injector.getInstance(ResourceAllocationSettingDataHandler.class)).parse(is); assertEquals(result.getAddress(), "0"); assertEquals(result.getDescription(), "SCSI Controller"); assertEquals(result.getElementName(), "SCSI Controller 0"); assertEquals(result.getInstanceID(), "3"); assertEquals(result.getResourceSubType(), "lsilogic"); assertEquals(result.getResourceType(), ResourceType.PARALLEL_SCSI_HBA); } }
private XMLBuilder addDiskWithQuantity(XMLBuilder sectionBuilder, ResourceAllocationSettingData disk) { XMLBuilder itemBuilder = sectionBuilder.e("Item"); itemBuilder.e("AddressOnParent").a("xmlns", RESOURCE_ALLOCATION_NS).t(disk.getAddressOnParent() + ""); for (String hostResource : disk.getHostResources()) itemBuilder.e("HostResource").a("xmlns", RESOURCE_ALLOCATION_NS).t(hostResource); addCommonElements(itemBuilder, disk, disk.getVirtualQuantity()); return itemBuilder; }
private void addDiskItems(XMLBuilder sectionBuilder, VApp vApp, VAppConfiguration configuration) { for (ResourceAllocationSettingData disk : filter(vApp.getResourceAllocations(), CIMPredicates .resourceTypeIn(ResourceType.DISK_DRIVE))) { if (!configuration.getDisksToDelete().contains(Integer.valueOf(disk.getAddressOnParent()))) { addDiskWithQuantity(sectionBuilder, disk); } } for (Long quantity : configuration.getDisks()) { ResourceAllocationSettingData disk = ResourceAllocationSettingData.builder().instanceID("9").addressOnParent( "-1").elementName("").resourceType(ResourceType.DISK_DRIVE).virtualQuantity(quantity).build(); addDiskWithQuantity(sectionBuilder, disk); } }
public void testHosting() { InputStream is = getClass().getResourceAsStream("/resourceallocation-hosting.xml"); ResourceAllocationSettingData result = factory.create( injector.getInstance(ResourceAllocationSettingDataHandler.class)).parse(is); ResourceAllocationSettingData expects = ResourceAllocationSettingData.builder().elementName("1 virtual CPU(s)") .allocationUnits("hertz * 10^6").instanceID("1").resourceType(ResourceAllocationSettingData.ResourceType.PROCESSOR) .virtualQuantity(1l).description("Number of Virtual CPUs").virtualQuantityUnits("count").build(); assertEquals(result.toString(), expects.toString()); } }
assertEquals(result.getNetworkToAddresses().get("Internal"), ImmutableList.<String> of("10.114.34.132")); ResourceAllocationSettingData cpu = ResourceAllocationSettingData.builder().instanceID("1").elementName( "1 virtual CPU(s)").description("Number of Virtual CPUs").resourceType(ResourceType.PROCESSOR) .virtualQuantity(2l).virtualQuantityUnits("hertz * 10^6").build(); ResourceAllocationSettingData controller = ResourceAllocationSettingData.builder().instanceID("3").elementName( "SCSI Controller 0").description("SCSI Controller").resourceType(ResourceType.PARALLEL_SCSI_HBA) .resourceSubType("lsilogic").address("0").virtualQuantity(1l).build(); ResourceAllocationSettingData memory = ResourceAllocationSettingData.builder().instanceID("2").elementName( "512MB of memory").description("Memory Size").resourceType(ResourceType.MEMORY).virtualQuantity(512l) .virtualQuantityUnits("byte * 2^20").build(); ResourceAllocationSettingData disk = ResourceAllocationSettingData.builder().instanceID("9").elementName( "Hard Disk 1").resourceType(ResourceType.DISK_DRIVE).hostResource("10485760").addressOnParent("0") .virtualQuantity(10485760l).virtualQuantityUnits("byte * 2^20").build(); assertEquals(result.getResourceAllocations(), ImmutableSet.of(cpu, memory, controller, disk)); assertEquals(find(result.getResourceAllocations(), CIMPredicates.resourceTypeIn(ResourceType.PROCESSOR)) .getVirtualQuantity().intValue(), 1); find(result.getResourceAllocations(), CIMPredicates.resourceTypeIn(ResourceType.PARALLEL_SCSI_HBA)); .getVirtualQuantity().intValue(), 512); assertEquals(find(result.getResourceAllocations(), CIMPredicates.resourceTypeIn(ResourceType.DISK_DRIVE)) .getVirtualQuantity().longValue(), 10485760); assertEquals(result.getSize().longValue(), find(result.getResourceAllocations(), CIMPredicates.resourceTypeIn(ResourceType.DISK_DRIVE)).getVirtualQuantity().longValue());
@Override public Processor apply(ResourceAllocationSettingData arg0) { return new Processor(arg0.getVirtualQuantity(), 1); } }));
@Test(enabled = true, dependsOnMethods = "testLifeCycle") public void testConfigure() throws InterruptedException, ExecutionException, TimeoutException, IOException { vApp = api.getVApp(vApp.getHref()); Task task = api.configureVApp(vApp, changeNameTo("eduardo").changeMemoryTo(1536).changeProcessorCountTo(1) .addDisk(25 * 1048576).addDisk(25 * 1048576)); assert successTester.apply(task.getHref()); vApp = api.getVApp(vApp.getHref()); assertEquals(vApp.getName(), "eduardo"); assertEquals(find(vApp.getResourceAllocations(), CIMPredicates.resourceTypeIn(ResourceType.PROCESSOR)) .getVirtualQuantity().longValue(), 1); assertEquals(find(vApp.getResourceAllocations(), CIMPredicates.resourceTypeIn(ResourceType.MEMORY)) .getVirtualQuantity().longValue(), 1536); assertEquals(size(filter(vApp.getResourceAllocations(), CIMPredicates.resourceTypeIn(ResourceType.DISK_DRIVE))), 3); assert successTester.apply(api.powerOnVApp(vApp.getHref()).getHref()); loopAndCheckPass(); assert successTester.apply(api.powerOffVApp(vApp.getHref()).getHref()); // extract the disks on the vApp sorted by addressOnParent List<ResourceAllocationSettingData> disks = Lists.newArrayList(filter(vApp.getResourceAllocations(), CIMPredicates.resourceTypeIn(ResourceType.DISK_DRIVE))); // delete the second disk task = api.configureVApp(vApp, deleteDiskWithAddressOnParent(Integer.parseInt(disks.get(1).getAddressOnParent()))); assert successTester.apply(task.getHref()); assert successTester.apply(api.powerOnVApp(vApp.getHref()).getHref()); loopAndCheckPass(); }
@Override public Volume apply(ResourceAllocationSettingData from) { if (from instanceof VCloudHardDisk) { VCloudHardDisk vDisk = VCloudHardDisk.class.cast(from); return new VolumeImpl(from.getAddressOnParent() + "", Volume.Type.LOCAL, vDisk.getCapacity() / 1024f, null, "0".equals(from.getAddressOnParent()), true); } else { return super.apply(from); } } }
@Override public boolean apply(ResourceAllocationSettingData in) { return resourceTypes.contains(in.getResourceType()); }
private void addCommonElements(XMLBuilder itemBuilder, ResourceAllocationSettingData resource, long quantity) { itemBuilder.e("InstanceID").a("xmlns", RESOURCE_ALLOCATION_NS).t(resource.getInstanceID() + ""); itemBuilder.e("ResourceType").a("xmlns", RESOURCE_ALLOCATION_NS).t(resource.getResourceType().value()); itemBuilder.e("VirtualQuantity").a("xmlns", RESOURCE_ALLOCATION_NS).t(quantity + ""); }
public Volume apply(ResourceAllocationSettingData from) { return new VolumeImpl(from.getAddressOnParent() + "", Volume.Type.LOCAL, from.getVirtualQuantity() == null ? null : from.getVirtualQuantity() / (float) (1024 * 1024), null, "0".equals(from.getAddressOnParent()) || ResourceType.BASE_PARTITIONABLE_UNIT.equals(from.getResourceType()), true); } }
public void testNormal() { InputStream is = getClass().getResourceAsStream("/resourceallocation.xml"); ResourceAllocationSettingData result = factory.create( injector.getInstance(ResourceAllocationSettingDataHandler.class)).parse(is); ResourceAllocationSettingData expects = ResourceAllocationSettingData.builder().allocationUnits("Gigabytes") .caption("1234568").description("Hard Disk").elementName("D:\\").hostResource("data").instanceID("6") .resourceType(ResourceAllocationSettingData.ResourceType.PARTITIONABLE_UNIT).virtualQuantity(50l) .build(); assertEquals(result.toString(), expects.toString()); }
ResourceAllocationSettingData cpu = ResourceAllocationSettingData.builder().instanceID("1").elementName( "2 virtual CPU(s)").description("Number of Virtual CPUs").resourceType(ResourceType.PROCESSOR) .virtualQuantity(2l).virtualQuantityUnits("hertz * 10^6").build(); ResourceAllocationSettingData controller = ResourceAllocationSettingData.builder().instanceID("3").elementName( "SCSI Controller 0").description("SCSI Controller").resourceType(ResourceType.PARALLEL_SCSI_HBA) .resourceSubType("lsilogic").address("0").virtualQuantity(1l).build(); ResourceAllocationSettingData memory = ResourceAllocationSettingData.builder().instanceID("2").elementName( "1024MB of memory").description("Memory Size").resourceType(ResourceType.MEMORY).virtualQuantity(1024l) .virtualQuantityUnits("byte * 2^20").build(); ResourceAllocationSettingData disk = ResourceAllocationSettingData.builder().instanceID("9").elementName( "Hard Disk 1").resourceType(ResourceType.DISK_DRIVE).hostResource("4194304").addressOnParent("0") .virtualQuantity(4194304l).virtualQuantityUnits("byte * 2^20").build(); ResourceAllocationSettingData disk2 = ResourceAllocationSettingData.builder().instanceID("9").elementName( "Hard Disk 2").resourceType(ResourceType.DISK_DRIVE).hostResource("26214400").addressOnParent("1") .virtualQuantity(26214400l).virtualQuantityUnits("byte * 2^20").build(); .getVirtualQuantity().intValue(), 2); find(vApp.getResourceAllocations(), CIMPredicates.resourceTypeIn(ResourceType.PARALLEL_SCSI_HBA)); assertEquals(find(vApp.getResourceAllocations(), CIMPredicates.resourceTypeIn(ResourceType.MEMORY)) .getVirtualQuantity().longValue(), 1024); CIMPredicates.resourceTypeIn(ResourceType.DISK_DRIVE))); assertEquals(disks.get(0).getVirtualQuantity().longValue(), 4194304); assertEquals(disks.get(1).getVirtualQuantity().longValue(), 26214400);
@Override public Processor apply(ResourceAllocationSettingData arg0) { return new Processor(arg0.getVirtualQuantity(), 1); } }));
@Override public Volume apply(ResourceAllocationSettingData from) { if (from instanceof VCloudHardDisk) { VCloudHardDisk vDisk = VCloudHardDisk.class.cast(from); return new VolumeImpl(from.getAddressOnParent() + "", Volume.Type.LOCAL, vDisk.getCapacity() / 1024f, null, "0".equals(from.getAddressOnParent()), true); } else { return super.apply(from); } } }
@Override public boolean apply(ResourceAllocationSettingData in) { return resourceTypes.contains(in.getResourceType()); }