Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Make example java/cloud/migration build, and add dummy tesh file.
[simgrid.git] / examples / java / cloud / migration / Test.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 package cloud.migration;
7
8 import org.simgrid.msg.*;
9 import org.simgrid.msg.Process;
10
11 public class Test extends Process{
12
13     Test(Host host, String name, String[] args) throws HostNotFoundException, NativeException  {
14         super(host, name, args);
15     }
16
17     public void main(String[] strings) throws MsgException {
18
19        double startTime = 0;
20        double endTime = 0;
21
22        /* get hosts 1 and 2*/
23         Host host0 = null;
24         Host host1 = null;
25
26         try {
27             host0 = Host.getByName("host0");
28             host1 = Host.getByName("host1");
29         }catch (HostNotFoundException e) {
30             e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
31         }
32
33       /* Create VM1 */
34         int dpRate = 70;
35         int load1 = 90;
36         int load2 = 80;
37
38         XVM vm1 = null;
39         vm1 = new XVM(
40                 host0,
41                 "vm0",
42                 1, // Nb of vcpu
43                 2048, // Ramsize,
44                 125, // Net Bandwidth
45                 null, //VM disk image
46                 -1,   //size of disk image,
47                 125, // Net bandwidth,
48                 dpRate // Memory intensity
49         );
50
51
52         vm1.start();
53
54         /* Collocated VMs */
55         int collocatedSrc = 6;
56         int vmSrcLoad[] = {
57                 80,
58                 0,
59                 90,
60                 40,
61                 30,
62                 90,
63         };
64
65         XVM tmp = null;
66         for (int i=1 ; i<= collocatedSrc ; i++){
67             tmp = new XVM(
68                     host0,
69                     "vm"+i,
70                     1, // Nb of vcpu
71                     2048, // Ramsize,
72                     125, // Net Bandwidth
73                     null, //VM disk image
74                     -1,   //size of disk image,
75                     125, // Net bandwidth,
76                     dpRate // Memory intensity
77             );
78             tmp.start();
79             tmp.setLoad(vmSrcLoad[i-1]);
80         }
81
82         int collocatedDst = 6;
83         int vmDstLoad[] = {
84                 0,
85                 40,
86                 90,
87                 100,
88                 0,
89                 80,
90         };
91
92         for (int i=1 ; i <= collocatedDst ; i++){
93             tmp = new XVM(
94                     host1,
95                     "vm"+i+collocatedSrc,
96                     1, // Nb of vcpu
97                     2048, // Ramsize,
98                     125, // Net Bandwidth
99                     null, //VM disk image
100                     -1,   //size of disk image,
101                     125, // Net bandwidth,
102                     dpRate // Memory intensity
103             );
104             tmp.start();
105             tmp.setLoad(vmDstLoad[i-1]);
106         }
107
108
109
110
111
112         Msg.info("Round trip of VM1 (load "+load1+"%)");
113         vm1.setLoad(load1);
114         Msg.info("     - Launch migration from host 0 to host 1");
115         startTime = Msg.getClock();
116         vm1.migrate(host1);
117         endTime = Msg.getClock();
118         Msg.info("     - End of Migration from host 0 to host 1 (duration:"+(endTime-startTime)+")");
119         Msg.info("     - Launch migration from host 1 to host 0");
120         startTime = Msg.getClock();
121         vm1.migrate(host0);
122         endTime = Msg.getClock();
123         Msg.info("     - End of Migration from host 1 to host 0 (duration:"+(endTime-startTime)+")");
124
125         Msg.info("\n \n \nRound trip of VM1 (load "+load2+"%)");
126         vm1.setLoad(load2);
127         Msg.info("     - Launch migration from host 0 to host 1");
128         startTime = Msg.getClock();
129         vm1.migrate(host1);
130         endTime = Msg.getClock();
131         Msg.info("     - End of Migration from host 0 to host 1 (duration:"+(endTime-startTime)+")");
132         Msg.info("     - Launch migration from host 1 to host 0");
133         startTime = Msg.getClock();
134         vm1.migrate(host0);
135         endTime = Msg.getClock();
136         Msg.info("     - End of Migration from host 1 to host 0 (duration:"+(endTime-startTime)+")");
137
138         waitFor(100000);
139         Main.setEndOfTest();
140     }
141 }