Logo AND Algorithmique Numérique Distribuée

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