Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix java cloud
[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
7 package cloud.migration;
8
9 import org.simgrid.msg.*;
10 import org.simgrid.msg.Process;
11 import java.util.ArrayList;
12 import java.util.List;
13
14 public class Test extends Process{
15
16     Test(Host host, String name, String[] args) throws HostNotFoundException, NativeException  {
17         super(host, name, args);
18     }
19
20     public void main(String[] strings) throws MsgException {
21
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         XVM vm1 = null;
44         vm1 = new XVM(
45                 host0,
46                 "vm0",
47                 1, // Nb of vcpu
48                 2048, // Ramsize,
49                 125, // Net Bandwidth
50                 null, //VM disk image
51                 -1,   //size of disk image,
52                 125, // Net bandwidth,
53                 dpRate // Memory intensity
54         );
55         vms.add(vm1);
56         vm1.start();
57
58         /* Collocated VMs */
59         int collocatedSrc = 6;
60         int vmSrcLoad[] = {
61                 80,
62                 0,
63                 90,
64                 40,
65                 30,
66                 90,
67         };
68
69         XVM tmp = null;
70         for (int i=1 ; i<= collocatedSrc ; i++){
71             tmp = new XVM(
72                     host0,
73                     "vm"+i,
74                     1, // Nb of vcpu
75                     2048, // Ramsize,
76                     125, // Net Bandwidth
77                     null, //VM disk image
78                     -1,   //size of disk image,
79                     125, // Net bandwidth,
80                     dpRate // Memory intensity
81             );
82             vms.add(tmp);
83             tmp.start();
84             tmp.setLoad(vmSrcLoad[i-1]);
85         }
86
87         int collocatedDst = 6;
88         int vmDstLoad[] = {
89                 0,
90                 40,
91                 90,
92                 100,
93                 0,
94                 80,
95         };
96
97         for (int i=1 ; i <= collocatedDst ; i++){
98             tmp = new XVM(
99                     host1,
100                     "vm"+i+collocatedSrc,
101                     1, // Nb of vcpu
102                     2048, // Ramsize,
103                     125, // Net Bandwidth
104                     null, //VM disk image
105                     -1,   //size of disk image,
106                     125, // Net bandwidth,
107                     dpRate // Memory intensity
108             );
109             vms.add(tmp);
110             tmp.start();
111             tmp.setLoad(vmDstLoad[i-1]);
112         }
113
114         Msg.info("Round trip of VM1 (load "+load1+"%)");
115         vm1.setLoad(load1);
116         Msg.info("     - Launch migration from host 0 to host 1");
117         startTime = Msg.getClock();
118         vm1.migrate(host1);
119         endTime = Msg.getClock();
120         Msg.info("     - End of Migration from host 0 to host 1 (duration:"+(endTime-startTime)+")");
121         Msg.info("     - Launch migration from host 1 to host 0");
122         startTime = Msg.getClock();
123         vm1.migrate(host0);
124         endTime = Msg.getClock();
125         Msg.info("     - End of Migration from host 1 to host 0 (duration:"+(endTime-startTime)+")");
126
127         Msg.info("\n \n \nRound trip of VM1 (load "+load2+"%)");
128         vm1.setLoad(load2);
129         Msg.info("     - Launch migration from host 0 to host 1");
130         startTime = Msg.getClock();
131         vm1.migrate(host1);
132         endTime = Msg.getClock();
133         Msg.info("     - End of Migration from host 0 to host 1 (duration:"+(endTime-startTime)+")");
134         Msg.info("     - Launch migration from host 1 to host 0");
135         startTime = Msg.getClock();
136         vm1.migrate(host0);
137         endTime = Msg.getClock();
138         Msg.info("     - End of Migration from host 1 to host 0 (duration:"+(endTime-startTime)+")");
139
140         waitFor(100000);
141         Main.setEndOfTest();
142         Msg.info("Destroy VMs");
143         for (VM vm: vms)
144           vm.destroy();
145     }
146 }