Logo AND Algorithmique Numérique Distribuée

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