Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
tidy the exceptions that can be raised by our Java code
[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     daemon.start();
44     this.setLoad(0);
45   }
46
47   public Daemon getDaemon(){
48     return this.daemon;
49   }
50
51   public int getLoad(){
52     System.out.println("Remaining comp:" + this.daemon.getRemaining());
53     return this.currentLoad;
54   }
55
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 }