Host. Java

Source: Internet
Author: User
/** Title: cloudsim toolkit * Description: cloudsim (cloud simulation) Toolkit for modeling and simulation of clouds * Licence: GPL-http://www.gnu.org/copyleft/gpl.html ** copyright (c) 2009-2010, the University of Melbourne, Australia */package Org. cloudid. cloudsim; import Java. util. arraylist; import Java. util. list; import Org. cloudid. cloudsim. lists. pelist; import Org. cloudid. cloudsim. provision ERS. bwprovisioner; import org. cloudid. cloudsim. provisioners. ramprovisioner;/*** host class * method: * Create, destroy Vm, and call the processing functions in VM to update cloud tasks. Migrate VM. * Host class extends a machine to include other hostlist beside PES * To Support Simulation of receivalized grids. it executes actions related * to management of virtual machines (e.g ., creation and destruction ). A host has * a defined policy for provisioning memory and BW, as well as an allocation policy * for PE's to virtual machines. ** a host is associated to a datacenter. it can host Vir Tual machines. ** @ authorrodrigo n. calheiros * @ authoranton beloglazov * @ sincecloudsim toolkit 1.0 */public class host {/** the ID. */private int ID;/** the storage. */private long storage;/** the ram provisioner. */private ramprovisioner;/** the BW provisioner. */private bwprovisioner;/** the allocation policy. it is mainly a PE list for pe vm allocation */private vmscheduler ;/** The VM list. */private list <? Extends VM> vmlist;/** the PE list. */private list <? Extends PE> pelist;/** tells whether this machine is working properly or has failed. */private Boolean failed;/** the VMS migrating in. */private list <VM> vmsmigratingin;/** the datacenter where the host is placed * The data center placed by the host **/private datacenter; /*** instantiates a new host. ** @ Param ID the ID * @ Param storage the storage * @ Param ramprovisioner the ram provisioner * @ Param B Wprovisioner the BW provisioner * @ Param pelist the PE list * @ Param vmscheduler the VM scheduler */public host (int id, ramprovisioner, describwprovisioner, long storage, list <? Extends PE> pelist, vmscheduler) {setid (ID); setramprovisioner (ramprovisioner); reverse (reverse); setstorage (storage); reverse (vmschedist); setpelist (pelist ); setvmlist (New arraylist <VM> (); setfailed (false );} /*** VM requests cloudlets to process updates * requests updating of processing of cloudlets In the VMS running in this host. ** @ Param currenttime the current time ** @ return expecte D time of completion of the next cloudlet in all VMS in this host. double. max_value * if there is no future events expected in this host ** @ pre currenttime >=0.0 * @ post $ none */Public double updatevmsprocessing (double currenttime) {double smallertime = double. max_value; For (Vm VM: getvmlist () {// For each VM on this host // If (VM. isinmigration () {// continue; //} // VM processes cloudlets with double time = VM. updatev Mprocessing (currenttime, getvmscheduler (). getallocatedmipsforvm (VM); If (Time> 0.0 & time <smallertime) {smallertime = Time ;}} return smallertime ;} /*** VM move to this host * @ Param VM */Public void addmigratinginvm (Vm VM) {If (! Getvmsmigratingin (). contains (VM) {// obtain the list vmsmigratingin to check whether this vmgetramprovisioner () exists (). allocateramforvm (Vm, VM. getcurrentrequestedram (); // allocate the memory getbwprovisioner (). allocatebwforvm (Vm, VM. getcurrentrequestedbw (); // allocate the bandwidth getvmsmigratingin (). add (VM) ;}}/*** VM removed from the host * @ Param VM */Public void removemigratinginvm (Vm VM) {getramprovisioner (). deallocateramforvm (VM); getbwprovisioner (). deallocatebwforvm (VM); GE Tvmsmigratingin (). Remove (VM );}/***?? */Public void reallocatemigratingvms () {for (Vm VM: getvmsmigratingin () {getramprovisioner (). allocateramforvm (Vm, VM. getcurrentrequestedram (); getbwprovisioner (). allocatebwforvm (Vm, VM. getcurrentrequestedbw () ;}}/*** checks if is suitable for VM. * check whether the VM is suitable for moving to the host, such as MIPS, ram, and BW * @ Param vm The VM ** @ return true, if is suitable for VM */Public Boolean issuitableforvm (Vm VM) {return (getvmsche DNT (). getavailablemips ()> = VM. getcurrentrequestedtotalmips () & getramprovisioner (). issuitableforvm (Vm, VM. getcurrentrequestedram () & getbwprovisioner (). issuitableforvm (Vm, VM. getcurrentrequestedbw ();}/*** allocates PES and memory to a new VM in the host. * Create a VM and check whether Ram, BW, and PES are sufficient. * @ Param VM being started ** @ return $ true if the VM cocould be started in the host; $ false otherwise ** @ pre $ None * @ post $ none */Public Boolean vmcreate (Vm VM) {If (! Getramprovisioner (). allocateramforvm (Vm, VM. getcurrentrequestedram () {log. printline ("Allocation of VM #" + VM. GETID () + "to host #" + GETID () + "failed by Ram"); Return false;} If (! Getbwprovisioner (). allocatebwforvm (Vm, VM. getcurrentrequestedbw () {log. printline ("Allocation of VM #" + VM. GETID () + "to host #" + GETID () + "failed by BW"); getramprovisioner (). deallocateramforvm (VM); Return false;} If (! Getvmscheduler (). allocatepesforvm (Vm, VM. getcurrentrequestedmips () {log. printline ("[vmscheduler. vmcreate] allocation of VM # "+ VM. GETID () + "to host #" + GETID () + "failed by MIPS"); getramprovisioner (). deallocateramforvm (VM); getbwprovisioner (). deallocatebwforvm (VM); Return false;} getvmlist (). add (VM); VM. sethost (this); Return true;}/*** destroy a VM * destroys a VM running in the host. ** @ Param VM th E vm ** @ pre $ none * @ post $ none */Public void vmdestroy (Vm VM) {If (Vm! = NULL) {vmdeallocate (VM); getvmlist (). remove (VM); VM. sethost (null) ;}}/*** destroy all VMS * destroys all VMS running in the host. ** @ pre $ none * @ post $ none */Public void vmdestroyall () {vmdeallocateall (); For (Vm VM: getvmlist () {VM. sethost (null);} getvmlist (). clear ();}/*** reclaim the memory, bandwidth, and PES * deallocate all hostlist for the VM. ** @ Param vm The VM */protected void vmdeallocate (Vm VM) {getramprovisio NER (). deallocateramforvm (VM); getbwprovisioner (). deallocatebwforvm (VM); getvmscheduler (). deallocatepesforvm (VM);}/*** reclaim the memory, bandwidth, and PES * deallocate all hostlist for the VM. ** @ Param vm The VM */protected void vmdeallocateall () {getramprovisioner (). deallocateramforallvms (); getbwprovisioner (). deallocatebwforallvms (); getvmscheduler (). deallocatepesforallvms ();}/*** returns a VM object. ** @ para M vmid the vm id * @ Param userid of VM's owner ** @ return the virtual machine object, $ null if not found ** @ pre $ none * @ post $ none */Public VM getvm (INT vmid, int userid) {for (Vm VM: getvmlist ()) {If (VM. GETID () = vmid & VM. getuserid () = userid) {return VM;} return NULL;}/*** gets the PES number. ** @ return the PES Number */Public int getpesnumber () {return getpelist (). size ();}/*** g ETS the free PES number. ** @ return the free PES Number */@ suppresswarnings ("unchecked") Public int getfreepesnumber () {return pelist. getfreepesnumber (list <PE>) getpelist ();}/*** gets the total MIPS. ** @ return the total MIPS */@ suppresswarnings ("unchecked") Public int gettotalmips () {return pelist. gettotalmips (list <PE>) getpelist ();}/*** a VM * allocates PES for a VM is not configured with PES. ** @ Param VM th E vm * @ Param mipsshare the MIPs share ** @ return $ true if this policy allows a new VM in the host, $ false otherwise ** @ pre $ none * @ post $ none */Public Boolean allocatepesforvm (Vm, list <double> mipsshare) {return getvmscheduler (). allocatepesforvm (Vm, mipsshare);}/*** releases PES allocated to a VM. * release a VM's PES * @ Param vm The VM ** @ pre $ none * @ post $ none */Public void deallocatepesforv M (Vm VM) {getvmscheduler (). deallocatepesforvm (VM);}/*** returns the MIPs share of each PE that is allocated to a given VM. * obtain MIPS * @ Param vm The VM ** @ return an array containing the amount of MIPs of each PE that is available to the VM ** @ pre $ none * @ post $ none */public list <double> getallocatedmipsforvm (Vm VM) {return getvmscheduler (). getallocatedmipsforvm (VM);}/*** gets the total alloc Ated MIPS for a VM over all the PES. ** @ Param vm The VM ** @ return the allocated MIPS for VM */Public double gettotalallocatedmipsforvm (Vm VM) {return getvmscheduler (). gettotalallocatedmipsforvm (VM);}/*** returns maximum available MIPS among all the PES. ** @ return Max MIPS */Public double getmaxavailablemips () {return getvmscheduler (). getmaxavailablemips ();}/*** gets the free MIPS. ** @ RET Urn the free MIPS */Public double getavailablemips () {return getvmscheduler (). getavailablemips ();}/*** gets the machine BW. ** @ return the machine BW ** @ pre $ none * @ post $ result> 0 */public long getbw () {return getbwprovisioner (). getbw ();}/*** gets the machine memory. ** @ return the machine memory ** @ pre $ none * @ post $ result> 0 */Public int getram () {return getramprovisioner (). getram () ;}/*** Gets the machine storage. ** @ return the machine storage ** @ pre $ none * @ post $ result> 0 */public long getstorage () {return storage;}/*** gets the ID. ** @ return the ID */Public int GETID () {return ID;}/*** sets the ID. ** @ Param ID the new ID */protected void setid (int id) {This. id = ID;}/*** gets the ram provisioner. ** @ return the ram provisioner */Public ramprovisioner getram Provisioner () {return ramprovisioner;}/*** sets the ram provisioner. ** @ Param ramprovisioner the new RAM provisioner */protected void setramprovisioner (ramprovisioner) {This. ramprovisioner = ramprovisioner;}/*** gets the BW provisioner. ** @ return the BW provisioner */Public bwprovisioner getbwprovisioner () {return bwprovisioner;}/*** sets the BW provisioner. ** @ Param bwprov Isioner the new BW provisioner */protected void setbwprovisioner (bwprovisioner) {This. bwprovisioner = bwprovisioner;}/*** gets the VM scheduler. ** @ return the VM scheduler */protected vmscheduler getvmscheduler () {return vmschedsets;}/*** sets the VM schedsets. ** @ Param vmscheduler the VM scheduler */protected void setvmscheduler (vmscheduler) {This. vmscheduler = VMS Cheduler;}/*** gets the PE list. ** @ return the PE list */public list <? Extends PE> getpelist () {return this. pelist;}/*** sets the PE list. ** @ Param pelist the new PE list */protected void setpelist (list <? Extends PE> pelist) {This. pelist = pelist;}/*** gets the VM list. ** @ return the VM list */@ suppresswarnings ("unchecked") Public <t extends VM> List <t> getvmlist () {return (list <t>) vmlist ;} /*** sets the VM list. ** @ Param vmlist the new VM list */protected <t extends VM> void setvmlist (list <t> vmlist) {This. vmlist = vmlist;}/*** sets the storage. ** @ Param storage the new storage */protected void setstorage (long storage) {This. storage = storage;}/*** checks if is failed. ** @ return true, if is failed */Public Boolean isfailed () {return failed ;} /*** set the status of all PES on this machine to failed * sets the PES of this machine to a failed status. * Note: <tt> resname </tt> is used for debugging purposes, * which is <B> On </B> by default. * use {@ link # setfailed (Boolean)} If you do not want * this information. ** @ Param resname The Name Of The resource * @ Param failed the failed ** @ return <tt> true </tt> If successful, <tt> false </tt> otherwise */@ suppresswarnings ("unchecked") Public Boolean setfailed (string resname, Boolean failed) {// all the PES are failed (or recovered, depending on fail) This. failed = failed; pelist. setstatusfailed (list <PE>) getpelist (), resname, GETID (), failed); Return true ;} /*** set PES to failed * sets the PES of this machine to a failed status. ** @ Param failed the failed ** @ return <tt> true </tt> If successful, <tt> false </tt> otherwise */@ suppresswarnings ("unchecked ") public Boolean setfailed (Boolean failed) {// all the PES are failed (or recovered, depending on fail) This. failed = failed; pelist. setstatusfailed (list <PE>) getpelist (), failed); Return true;}/*** sets the participating PE status on this machine. ** @ Param status PE status, either <tt> PE. free </tt> or <tt> PE. busy </tt> * @ Param peid the pe id ** @ return <tt> true </tt> If the PE status has changed, <tt> false </tt> * otherwise (pe id might not be exist) ** @ pre peid> = 0 * @ post $ none */@ suppresswarnings ("unchecked ") public Boolean setpestatus (INT peid, int status) {return pelist. setpestatus (list <PE>) getpelist (), peid, status);}/*** gets the VMS migrating in. * obtain the list of VMS to be migrated * @ return the VMS migrating in */public list <VM> getvmsmigratingin () {return vmsmigratingin;}/*** sets the VMS migrating in. ** @ Param vmsmigratingin the new VMS migrating in */protected void setvmsmigratingin (list <VM> vmsmigratingin) {This. vmsmigratingin = vmsmigratingin;}/*** gets the data center. * @ return the data center where the host runs */Public datacenter getdatacenter () {return this. datacenter;}/*** sets the data center. ** @ Param datacenter the data center from this host */Public void setdatacenter (datacenter) {This. datacenter = datacenter ;}}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.