Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix smpi_execute_benched.
[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, int ramsize, int migNetBW, int dpIntensity){
23     super(host, name, ramsize, (int)(migNetBW*0.9), dpIntensity);
24     this.currentLoad = 0;
25     this.dpIntensity = dpIntensity ;
26     this.ramsize= ramsize;
27     this.daemon = new Daemon(this);
28   }
29
30   public void setLoad(int load){  
31     if (load >0) {
32       this.setBound(this.getSpeed()*load/100);
33       //    this.getDaemon().setLoad(load);
34       daemon.resume();
35     } else{
36       daemon.suspend();
37     }
38     currentLoad = load ;
39   }
40
41   public void start(){
42     super.start();
43     try {
44       daemon.start();
45     } catch (HostNotFoundException e) {
46       e.printStackTrace();
47     }
48     this.setLoad(0);
49   }
50
51   public Daemon getDaemon(){
52     return this.daemon;
53   }
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) throws HostFailureException {
61     Msg.info("Start migration of VM " + this.getName() + " to " + host.getName());
62     Msg.info("    currentLoad:" + this.currentLoad + "/ramSize:" + this.ramsize + "/dpIntensity:" + this.dpIntensity 
63         + "/remaining:" + String.format(java.util.Locale.US, "%.2E",this.daemon.getRemaining()));
64     try{
65       super.migrate(host);
66     } catch (Exception e){
67       Msg.info("Something wrong during the live migration of VM "+this.getName());
68       throw new HostFailureException(); 
69     }
70     this.setLoad(this.currentLoad); //Fixed the fact that setBound is not propagated to the new node.
71     Msg.info("End of migration of VM " + this.getName() + " to node " + host.getName());
72   }
73 }