Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
03dd601009d0b7d98990be1d8b0f297a5a5c8a9d
[simgrid.git] / examples / java / cloud / migration / XVM.java
1 /* Copyright (c) 2014. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6 package cloud.migration;
7
8 import org.simgrid.msg.Host;
9 import org.simgrid.msg.HostNotFoundException;
10 import org.simgrid.msg.Msg;
11 import org.simgrid.msg.VM;
12
13 /**
14  * A stupid VM extension to associate a daemon to the VM
15  */
16 public class XVM extends VM {
17
18
19     private int dpIntensity;
20     private int netBW;
21     private int ramsize;
22     private int currentLoad;
23
24     private Daemon daemon;
25
26     public XVM(Host host, String name,
27                int nbCores, int ramsize, int netBW, String diskPath, int diskSize, int migNetBW, int dpIntensity){
28         super(host, name, nbCores, ramsize, netBW, diskPath, diskSize, (int)(migNetBW*0.9), dpIntensity);
29         this.currentLoad = 0;
30         this.netBW = netBW ;
31         this. dpIntensity = dpIntensity ;
32         this.ramsize= ramsize;
33         this.daemon = new Daemon(this, 100);
34
35     }
36
37     public void setLoad(int load){  
38         if (load >0) {
39             this.setBound(load);
40         //    this.getDaemon().setLoad(load);
41             daemon.resume();
42         }
43         else{
44             daemon.suspend();
45         }
46         currentLoad = load ;
47     }
48
49     public void start(){
50         super.start();
51          try {
52             daemon.start();
53         } catch (HostNotFoundException e) {
54             e.printStackTrace();
55         }
56         this.setLoad(0);
57
58     }
59     public Daemon getDaemon(){
60         return this.daemon;
61     }
62     public int getLoad(){
63        System.out.println("Remaining comp:" + this.daemon.getRemaining());
64         return this.currentLoad;
65     }
66
67     public void migrate(Host host){
68         Msg.info("Start migration of VM " + this.getName() + " to " + host.getName());
69         Msg.info("    currentLoad:" + this.currentLoad + "/ramSize:" + this.ramsize + "/dpIntensity:" + this.dpIntensity + "/remaining:" + this.daemon.getRemaining());
70         super.migrate(host);
71         this.setLoad(this.currentLoad); //Fixed the fact that setBound is not propagated to the new node.
72         Msg.info("End of migration of VM " + this.getName() + " to node " + host.getName());
73     }
74 }