Logo AND Algorithmique Numérique Distribuée

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