Logo AND Algorithmique Numérique Distribuée

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