1 /* Copyright (c) 2014. The SimGrid Team.
2 * All rights reserved. */
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. */
7 package cloud.migration;
9 import org.simgrid.msg.Host;
10 import org.simgrid.msg.HostFailureException;
11 import org.simgrid.msg.HostNotFoundException;
12 import org.simgrid.msg.Msg;
13 import org.simgrid.msg.MsgException;
14 import org.simgrid.msg.Process;
15 import org.simgrid.msg.VM;
17 // This test aims at validating that the migration process is robust in face of host turning off either on the SRC
18 // node or on the DST node.
19 public class TestHostOnOff extends Process{
21 protected Host host0 = null;
22 protected Host host1 = null;
23 protected Host host2 = null;
25 TestHostOnOff(String hostname, String name) throws HostNotFoundException {
26 super(hostname, name);
29 public void main(String[] strings) throws MsgException {
30 /* get hosts 1 and 2*/
32 host0 = Host.getByName("PM0");
33 host1 = Host.getByName("PM1");
34 host2 = Host.getByName("PM2");
35 }catch (HostNotFoundException e) {
36 Msg.error("You are trying to use a non existing node:" + e.getMessage());
39 // Robustness on the SRC node
40 for (int i =100 ; i < 55000 ; i+=100)
41 testVMMigrate(host1, i);
43 // Robustness on the DST node
44 for (int i =0 ; i < 55000 ; i++)
45 testVMMigrate(host2, i);
48 Msg.info("Nor more tests, Bye Bye !");
52 public void testVMMigrate (Host hostToKill, long killAt) throws MsgException {
53 Msg.info("**** **** **** ***** ***** Test Migrate with host shutdown ***** ***** **** **** ****");
54 Msg.info("Turn on one host, assign a VM on this host, launch a process inside the VM, migrate the VM and "
55 + "turn off either the SRC or DST");
65 vm0 = new XVM(host1, "vm0",
67 125, // Net bandwidth,
68 dpRate // Memory intensity
73 String[] args = new String[3];
78 new Process(host1, "Migrate-" + killAt, args) {
79 public void main(String[] args) {
81 Host sourceHost = null;
84 sourceHost = Host.getByName(args[1]);
85 destHost = Host.getByName(args[2]);
86 } catch (HostNotFoundException e) {
87 Msg.error("You are trying to migrate from/to a non existing node: " + e.getMessage());
90 if (destHost != null && sourceHost.isOn() && destHost.isOn()) {
92 Msg.info("Migrate vm "+args[0]+" to node "+destHost.getName());
93 VM.getVMByName(args[0]).migrate(destHost);
94 } catch (HostFailureException e) {
95 Msg.error("Something occurs during the migration that cannot validate the operation: " + e.getMessage());
102 // Wait killAt ms before killing thehost
103 Process.sleep(killAt);
104 Msg.info("The migration process should be stopped and we should catch an exception");
107 Process.sleep(50000);
108 Msg.info("Destroy VMs");
110 Process.sleep(20000);
113 public void testVMShutdownDestroy () throws HostFailureException {
114 Msg.info("**** **** **** ***** ***** Test shutdown a VM ***** ***** **** **** ****");
115 Msg.info("Turn on host1, assign a VM on host1, launch a process inside the VM, and turn off the vm, " +
116 "and check whether you can reallocate the same VM");
120 XVM vm0 = new XVM(host1, "vm0",
122 125, // Net bandwidth,
123 dpRate // Memory intensity
125 Msg.info("Start VM0");
131 Msg.info("Shutdown VM0");
135 Msg.info("Restart VM0");
136 vm0 = new XVM(host1, "vm0",
138 125, // Net bandwidth,
139 dpRate // Memory intensity
144 Msg.info("You suceed to recreate and restart a VM without generating any exception ! Great the Test is ok");