Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
VM: don't take ignored parameter that may fool the users
[simgrid.git] / examples / java / cloud / migration / TestHostOnOff.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
12 // This test aims at validating that the migration process is robust in face of host turning off either on the SRC 
13 // node or on the DST node. 
14 public class TestHostOnOff extends Process{
15
16   protected Host host0 = null;
17   protected Host host1 = null;
18   protected Host host2 = null;
19
20   TestHostOnOff(String hostname, String name) throws  HostNotFoundException, NativeException {
21     super(hostname, name);
22   }
23
24   public void main(String[] strings) throws MsgException {
25     /* get hosts 1 and 2*/
26     try {
27       host0 = Host.getByName("PM0");
28       host1 = Host.getByName("PM1");
29       host2 = Host.getByName("PM2");
30     }catch (HostNotFoundException e) {
31       Msg.error("You are trying to use a non existing node:" + e.getMessage());
32     }
33
34     // Robustness on the SRC node
35     for (int i =100 ; i < 55000 ; i+=100)
36      testVMMigrate(host1, i);
37
38     // Robustness on the DST node
39     for (int i =0 ; i < 55000 ; i++)
40       testVMMigrate(host2, i);
41
42     /* End of Tests */
43     Msg.info("Nor more tests, Bye Bye !");
44     Main.setEndOfTest();
45   }
46
47   public void testVMMigrate (Host hostToKill, long killAt) throws MsgException {
48     Msg.info("**** **** **** ***** ***** Test Migrate with host shutdown ***** ***** **** **** ****");
49     Msg.info("Turn on one host, assign a VM on this host, launch a process inside the VM, migrate the VM and "
50              + "turn off either the SRC or DST");
51
52     host1.off();
53     host2.off();
54     host1.on();
55     host2.on();
56
57     // Create VM0
58     int dpRate = 70;
59     XVM vm0 = null;
60     vm0 = new XVM(host1, "vm0",
61         2048, // Ramsize,
62         125, // Net bandwidth,
63         dpRate // Memory intensity
64         );
65     vm0.start();
66     vm0.setLoad(90);
67
68     String[] args = new String[3];
69
70     args[0] = "vm0";
71     args[1] = "PM1";
72     args[2] = "PM2";
73     new Process(host1, "Migrate-" + killAt, args) {
74       public void main(String[] args) {
75         Host destHost = null;
76         Host sourceHost = null;
77
78         try {
79           sourceHost = Host.getByName(args[1]);
80           destHost = Host.getByName(args[2]);
81         } catch (HostNotFoundException e) {
82           Msg.error("You are trying to migrate from/to a non existing node: " + e.getMessage());
83           e.printStackTrace();
84         }
85         if (destHost != null && sourceHost.isOn() && destHost.isOn()) {
86           try {
87             Msg.info("Migrate vm "+args[0]+" to node "+destHost.getName());
88             VM.getVMByName(args[0]).migrate(destHost);
89           } catch (HostFailureException e) {
90             Msg.error("Something occurs during the migration that cannot validate the operation: " + e.getMessage());
91             e.printStackTrace();
92           }
93         }
94       }
95     }.start();
96
97     // Wait killAt ms before killing thehost
98     Process.sleep(killAt);
99     Msg.info("The migration process should be stopped and we should catch an exception");
100     hostToKill.off();
101
102     Process.sleep(50000);
103     Msg.info("Destroy VMs");
104     vm0.shutdown();
105     Process.sleep(20000);
106   }
107
108   public void testVMShutdownDestroy () throws HostFailureException {
109     Msg.info("**** **** **** ***** ***** Test shutdown a VM ***** ***** **** **** ****");
110     Msg.info("Turn on host1, assign a VM on host1, launch a process inside the VM, and turn off the vm, " +
111         "and check whether you can reallocate the same VM");
112
113     // Create VM0
114     int dpRate = 70;
115     XVM vm0 = new XVM(host1, "vm0",
116         2048, // Ramsize,
117         125, // Net bandwidth,
118         dpRate // Memory intensity
119         );
120     Msg.info("Start VM0");
121     vm0.start();
122     vm0.setLoad(90);
123
124     Process.sleep(5000);
125
126     Msg.info("Shutdown VM0");
127     vm0.shutdown();
128     Process.sleep(5000);
129
130     Msg.info("Restart VM0");
131     vm0 = new XVM(host1, "vm0",
132         2048, // Ramsize,
133         125, // Net bandwidth,
134         dpRate // Memory intensity
135         );
136     vm0.start();
137     vm0.setLoad(90);
138
139     Msg.info("You suceed to recreate and restart a VM without generating any exception ! Great the Test is ok");
140
141     Process.sleep(5000);
142     vm0.shutdown();
143   }
144 }