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 java.util.ArrayList;
10 import java.util.List;
11 import java.util.Random;
13 import org.simgrid.msg.*;
14 import org.simgrid.msg.Process;
16 // This test aims at validating that the migration process is robust in face of host turning off either on the SRC
17 // node or on the DST node.
18 public class TestHostOnOff extends Process{
20 public static Host host0 = null;
21 public static Host host1 = null;
22 public static Host host2 = null;
25 TestHostOnOff(Host host, String name, String[] args) throws HostNotFoundException, NativeException {
26 super(host, name, args);
29 public void main(String[] strings) throws MsgException {
33 /* get hosts 1 and 2*/
35 host0 = Host.getByName("host0");
36 host1 = Host.getByName("host1");
37 host1 = Host.getByName("host2");
38 }catch (HostNotFoundException e) {
39 e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
42 // Robustness on the SRC node
43 //for (int i =0 ; i < 55000 ; i++)
44 // test_vm_migrate(host1, i);
46 // Robustness on the DST node
47 //for (int i =0 ; i < 55000 ; i++)
48 // test_vm_migrate(host2, i);
51 Msg.info("Nor more tests, Bye Bye !");
55 public static void test_vm_migrate (Host hostToKill, long killAt) throws MsgException {
56 Msg.info("**** **** **** ***** ***** Test Migrate with host shutdown ***** ***** **** **** ****");
57 Msg.info("Turn on one host, assign a VM on this host, launch a process inside the VM, migrate the VM and "
58 + "turn off either the SRC or DST");
68 vm0 = new XVM(host1, "vm0",
73 -1, //size of disk image,
74 125, // Net bandwidth,
75 dpRate // Memory intensity
80 String[] args = new String[3];
85 new Process(host1, "Migrate-" + new Random().nextDouble(), args) {
86 public void main(String[] args) {
88 Host sourceHost = null;
91 sourceHost = Host.getByName(args[1]);
92 destHost = Host.getByName(args[2]);
93 } catch (Exception e) {
95 System.err.println("You are trying to migrate from/to a non existing node");
97 if (destHost != null) {
98 if (sourceHost.isOn() && destHost.isOn()) {
100 Msg.info("Migrate vm "+args[0]+" to node "+destHost.getName());
101 VM.getVMByName(args[0]).migrate(destHost);
102 } catch (HostFailureException e) {
104 Msg.info("Something occurs during the migration that cannot validate the operation");
111 // Wait killAt ms before killing thehost
112 Process.sleep(killAt);
115 Msg.info("The migration process should be stopped and we should catch an exception\n");
118 Process.sleep(50000);
119 Msg.info("Destroy VMs");
121 Process.sleep(20000);
124 public static void test_vm_shutdown_destroy () throws HostFailureException {
125 Msg.info("**** **** **** ***** ***** Test shutdown a VM ***** ***** **** **** ****");
126 Msg.info("Turn on host1, assign a VM on host1, launch a process inside the VM, and turn off the vm, " +
127 "and check whether you can reallocate the same VM");
132 vm0 = new XVM(host1, "vm0",
135 125, // Net Bandwidth
136 null, //VM disk image
137 -1, //size of disk image,
138 125, // Net bandwidth,
139 dpRate // Memory intensity
141 Msg.info("Start VM0");
147 Msg.info("Shutdown VM0");
151 Msg.info("Restart VM0");
152 vm0 = new XVM(host1, "vm0",
155 125, // Net Bandwidth
156 null, //VM disk image
157 -1, //size of disk image,
158 125, // Net bandwidth,
159 dpRate // Memory intensity
164 Msg.info("You suceed to recreate and restart a VM without generating any exception ! Great the Test is ok");