Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
update a teshfile that was affected by #123, which Fabien just fixed
[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
7 package cloud.migration;
8
9 import org.simgrid.msg.Msg;
10 import org.simgrid.msg.VM;
11 import org.simgrid.msg.Host;
12 import org.simgrid.msg.HostNotFoundException;
13 import org.simgrid.msg.HostFailureException;
14
15 public class XVM extends VM {
16   private int dpIntensity;
17   private int ramsize;
18   private int currentLoad;
19
20   private Daemon daemon;
21
22   public XVM(Host host, String name,
23     int nbCores, int ramsize, int netBW, String diskPath, int diskSize, int migNetBW, int dpIntensity){
24     super(host, name, nbCores, ramsize, netBW, diskPath, diskSize, (int)(migNetBW*0.9), dpIntensity);
25     this.currentLoad = 0;
26     this. dpIntensity = dpIntensity ;
27     this.ramsize= ramsize;
28     this.daemon = new Daemon(this, 100);
29   }
30
31   public void setLoad(int load){  
32     if (load >0) {
33       this.setBound(this.getSpeed()*load/100);
34       //    this.getDaemon().setLoad(load);
35       daemon.resume();
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
56   public int getLoad(){
57     System.out.println("Remaining comp:" + this.daemon.getRemaining());
58     return this.currentLoad;
59   }
60
61   public void migrate(Host host) throws HostFailureException {
62     Msg.info("Start migration of VM " + this.getName() + " to " + host.getName());
63     Msg.info("    currentLoad:" + this.currentLoad + "/ramSize:" + this.ramsize + "/dpIntensity:" + this.dpIntensity 
64         + "/remaining:" + String.format(java.util.Locale.US, "%.2E",this.daemon.getRemaining()));
65     try{
66       super.migrate(host);
67     } catch (Exception e){
68       Msg.info("Something wrong during the live migration of VM "+this.getName());
69       throw new HostFailureException(); 
70     }
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 }