public void createBufferCommodities(PhysicalMachine pm) { // The pm sells buffer to all the vms that it hosts BufferCommodity pmBufferSold = (BufferCommodity) createObject( AbstractionPackage.eINSTANCE.getBufferCommodity(), "Buffer/" + pm.getName()); if (!pmBufferSold.eIsSet(AnalysisPackage.eINSTANCE.getCommodity_Capacity())) pmBufferSold.setCapacity(100000); pm.getCommodities().add(pmBufferSold); for (VMTManagedEntity managedEntity : pm.getHosts()) { if (managedEntity instanceof ServiceEntity) { ServiceEntity vm = (ServiceEntity) managedEntity; BufferCommodity vmBufferBought = (BufferCommodity) createObject( AbstractionPackage.eINSTANCE.getBufferCommodity(), "Buffer/" + managedEntity.getName()); vm.getCommoditiesBought().add(vmBufferBought); vmBufferBought.getConsumes().add(pmBufferSold); } } }
/** * * <!-- begin-user-doc --> * The capacity of the ballooning commodity sold by a PM is the sum of configured memory on all * powered-on VMs hosted by this PM times 65%. It is capped below by the size of physical memory. * <!-- end-user-doc --> * * @generated NOT */ @Override public float getCapacity() { if (capacity != CAPACITY_EDEFAULT) { return capacity; } ServiceEntity host = getSoldBy(); if (host == null) { return super.getCapacity(); } if (host instanceof PhysicalMachine) { PhysicalMachine pm = (PhysicalMachine) host; if (pm.isRecalculateBallooning() || cachedCapacity == 0) { float sum_vm_mem_size = 0.0F; float pm_mem_size = 0; List<VMTRootObject> mems = host.getRef( AnalysisPackage.eINSTANCE.getServiceEntity_Commodities(), AbstractionPackage.eINSTANCE.getMem()); if (mems.size() > 0) { Mem mem = (Mem) mems.get(0); pm_mem_size = mem.getCapacity(); } for (VMTManagedEntity me : host.getHosts()) { if (me instanceof VirtualMachine) { VirtualMachine vm = (VirtualMachine) me; ServiceEntityState state = vm.getState(); if (state.equals(ServiceEntityState.ACTIVE) || state.equals(ServiceEntityState.SUSPEND_PENDING) || state.equals(ServiceEntityState.TERMINATE_PENDING)) { List<VMTRootObject> vmems = vm.getRef( ManagedEntitiesPackage.eINSTANCE.getVMTManagedEntity_ComposedOf(), AbstractionPackage.eINSTANCE.getVMemory()); for (VMTRootObject vmt : vmems) { // there should be only one VMemory vmem = (VMemory) vmt; sum_vm_mem_size += vmem.getCapacity(); } } } } cachedCapacity = (float) Math.max(pm_mem_size, sum_vm_mem_size * 1024.0 * FACTOR); pm.setRecalculateBallooning(false); } } return cachedCapacity; }