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.*;
10 import org.simgrid.msg.Process;
11 import java.util.ArrayList;
12 import java.util.List;
13 import java.util.Random;
15 // This test aims at validating that the migration process is robust in face of host turning off either on the SRC node or on the DST node.
17 public class TestHostOnOff extends Process{
19 public static Host host0 = null;
20 public static Host host1 = null;
21 public static Host host2 = null;
24 TestHostOnOff(Host host, String name, String[] args) throws HostNotFoundException, NativeException {
25 super(host, name, args);
28 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 turn off either the SRC or DST");
74 -1, //size of disk image,
75 125, // Net bandwidth,
76 dpRate // Memory intensity
81 String[] args = new String[3];
86 new Process(host1, "Migrate-" + new Random().nextDouble(), args) {
87 public void main(String[] args) {
89 Host sourceHost = null;
92 sourceHost = Host.getByName(args[1]);
93 destHost = Host.getByName(args[2]);
94 } catch (Exception e) {
96 System.err.println("You are trying to migrate from/to a non existing node");
98 if (destHost != null) {
99 if (sourceHost.isOn() && destHost.isOn()) {
102 Msg.info("Migrate vm "+args[0]+" to node "+destHost.getName());
103 VM.getVMByName(args[0]).migrate(destHost);
104 } catch (HostFailureException e) {
106 Msg.info("Something occurs during the migration that cannot validate the operation");
114 // Wait killAt ms before killing thehost
115 Process.sleep(killAt);
118 Msg.info("The migration process should be stopped and we should catch an exception\n");
121 Process.sleep(50000);
122 Msg.info("Destroy VMs");
124 Process.sleep(20000);
128 public static void test_vm_shutdown_destroy () throws HostFailureException {
130 Msg.info("**** **** **** ***** ***** Test shutdown a VM ***** ***** **** **** ****");
131 Msg.info("Turn on host1, assign a VM on host1, launch a process inside the VM, and turn off the vm, " +
132 "and check whether you can reallocate the same VM");
143 125, // Net Bandwidth
144 null, //VM disk image
145 -1, //size of disk image,
146 125, // Net bandwidth,
147 dpRate // Memory intensity
149 Msg.info("Start VM0");
155 Msg.info("Shutdown VM0");
159 Msg.info("Restart VM0");
165 125, // Net Bandwidth
166 null, //VM disk image
167 -1, //size of disk image,
168 125, // Net bandwidth,
169 dpRate // Memory intensity
174 Msg.info("You suceed to recreate and restart a VM without generating any exception ! Great the Test is ok");