Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Java: be more verbose when cleaning the disk on exit fails
[simgrid.git] / examples / java / cloud / migration / Test.java
1 /* Copyright (c) 2014, 2016. 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 import java.util.ArrayList;
9 import java.util.List;
10
11
12 import org.simgrid.msg.*;
13 import org.simgrid.msg.Process;
14
15 public class Test extends Process{
16
17   Test(String hostname, String name) throws HostNotFoundException, NativeException  {
18     super(hostname, name);
19   }
20
21   public void main(String[] strings) throws MsgException {
22     double startTime = 0;
23     double endTime = 0;
24
25     /* get hosts 1 and 2*/
26     Host host0 = null;
27     Host host1 = null;
28
29     try {
30       host0 = Host.getByName("host0");
31       host1 = Host.getByName("host1");
32     }catch (HostNotFoundException e) {
33       e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
34     }
35
36     List<VM> vms = new ArrayList<VM>();
37
38     /* Create VM1 */
39     int dpRate = 70;
40     int load1 = 90;
41     int load2 = 80;
42
43     Msg.info("This example evaluates the migration time of a VM in presence of collocated VMs on the source and "
44              + "the dest nodes");
45     Msg.info("The migrated VM has a memory intensity rate of 70% of the network BW and a cpu load of 90% \" "
46              +"(see cloudcom 2013 paper \"Adding a Live Migration Model Into SimGrid\" for further information) ");
47
48     Msg.info("Load of collocated VMs fluctuate between 0 and 90% in order to create a starvation issue and see "
49              + "whether it impacts or not the migration time");
50     XVM vm1 = null;
51     vm1 = new XVM(host0, "vm0",
52         1, // Nb of vcpu
53         2048, // Ramsize,
54         125, // Net Bandwidth
55         null, //VM disk image
56         -1,   //size of disk image,
57         125, // Net bandwidth,
58         dpRate // Memory intensity
59         );
60     vms.add(vm1);
61     vm1.start();
62
63     /* Collocated VMs */
64     int collocatedSrc = 6;
65     int vmSrcLoad[] = {
66         80,
67         0,
68         90,
69         40,
70         30,
71         90,
72     };
73
74     XVM tmp = null;
75     for (int i=1 ; i<= collocatedSrc ; i++){
76       tmp = new XVM(host0, "vm"+i,
77           1, // Nb of vcpu
78           2048, // Ramsize,
79           125, // Net Bandwidth
80           null, //VM disk image
81           -1,   //size of disk image,
82           125, // Net bandwidth,
83           dpRate // Memory intensity
84           );
85       vms.add(tmp);
86       tmp.start();
87       tmp.setLoad(vmSrcLoad[i-1]);
88     }
89
90     int collocatedDst = 6;
91     int vmDstLoad[] = {
92         0,
93         40,
94         90,
95         100,
96         0,
97         80,
98     };
99
100     for (int i=1 ; i <= collocatedDst ; i++){
101       tmp = new XVM(host1, "vm"+(i+collocatedSrc),
102           1, // Nb of vcpu
103           2048, // Ramsize,
104           125, // Net Bandwidth
105           null, //VM disk image
106           -1,   //size of disk image,
107           125, // Net bandwidth,
108           dpRate // Memory intensity
109           );
110       vms.add(tmp);
111       tmp.start();
112       tmp.setLoad(vmDstLoad[i-1]);
113     }
114
115     Msg.info("Round trip of VM1 (load "+load1+"%)");
116     vm1.setLoad(load1);
117     Msg.info("     - Launch migration from host 0 to host 1");
118     startTime = Msg.getClock();
119     vm1.migrate(host1);
120     endTime = Msg.getClock();
121     Msg.info("     - End of Migration from host 0 to host 1 (duration:"+(endTime-startTime)+")");
122     Msg.info("     - Launch migration from host 1 to host 0");
123     startTime = Msg.getClock();
124     vm1.migrate(host0);
125     endTime = Msg.getClock();
126     Msg.info("     - End of Migration from host 1 to host 0 (duration:"+(endTime-startTime)+")");
127
128     Msg.info("");
129     Msg.info("");
130     Msg.info("Round trip of VM1 (load "+load2+"%)");
131     vm1.setLoad(load2);
132     Msg.info("     - Launch migration from host 0 to host 1");
133     startTime = Msg.getClock();
134     vm1.migrate(host1);
135     endTime = Msg.getClock();
136     Msg.info("     - End of Migration from host 0 to host 1 (duration:"+(endTime-startTime)+")");
137     Msg.info("     - Launch migration from host 1 to host 0");
138     startTime = Msg.getClock();
139     vm1.migrate(host0);
140     endTime = Msg.getClock();
141     Msg.info("     - End of Migration from host 1 to host 0 (duration:"+(endTime-startTime)+")");
142
143     Main.setEndOfTest();
144     Msg.info("Forcefully destroy VMs");
145     for (VM vm: vms)
146       vm.destroy();
147   }
148 }