Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add simcalls.{in,py} to EXTRA_DIST.
[simgrid.git] / examples / java / cloud / migration-test / src / XVM.java
1 import org.simgrid.msg.Host;
2 import org.simgrid.msg.HostNotFoundException;
3 import org.simgrid.msg.Msg;
4 import org.simgrid.msg.VM;
5
6 /**
7  * A stupid VM extension to associate a daemon to the VM
8  */
9 public class XVM extends VM {
10
11
12     private int dpIntensity;
13     private int netBW;
14     private int ramsize;
15     private int currentLoad;
16
17     private Daemon daemon;
18
19     public XVM(Host host, String name,
20                int nbCores, int ramsize, int netBW, String diskPath, int diskSize, int migNetBW, int dpIntensity){
21         super(host, name, nbCores, ramsize, netBW, diskPath, diskSize, (int)(migNetBW*0.9), dpIntensity);
22         this.currentLoad = 0;
23         this.netBW = netBW ;
24         this. dpIntensity = dpIntensity ;
25         this.ramsize= ramsize;
26         this.daemon = new Daemon(this, 100);
27
28     }
29
30     public void setLoad(int load){  
31         if (load >0) {
32             this.setBound(load);
33         //    this.getDaemon().setLoad(load);
34             daemon.resume();
35         }
36         else{
37             daemon.suspend();
38         }
39         currentLoad = load ;
40     }
41
42     public void start(){
43         super.start();
44          try {
45             daemon.start();
46         } catch (HostNotFoundException e) {
47             e.printStackTrace();
48         }
49         this.setLoad(0);
50
51     }
52     public Daemon getDaemon(){
53         return this.daemon;
54     }
55     public int getLoad(){
56        System.out.println("Remaining comp:" + this.daemon.getRemaining());
57         return this.currentLoad;
58     }
59
60     public void migrate(Host host){
61         Msg.info("Start migration of VM " + this.getName() + " to " + host.getName());
62         Msg.info("    currentLoad:" + this.currentLoad + "/ramSize:" + this.ramsize + "/dpIntensity:" + this.dpIntensity + "/remaining:" + this.daemon.getRemaining());
63         super.migrate(host);
64         this.setLoad(this.currentLoad); //Fixed the fact that setBound is not propagated to the new node.
65         Msg.info("End of migration of VM " + this.getName() + " to node " + host.getName());
66     }
67 }