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.Random;
11 import org.simgrid.msg.*;
12 import org.simgrid.msg.Process;
14 // This test aims at validating that the migration process is robust in face of host turning off either on the SRC
15 // node or on the DST node.
16 public class TestHostOnOff extends Process{
18 public static Host host0 = null;
19 public static Host host1 = null;
20 public static Host host2 = null;
22 TestHostOnOff(Host host, String name, String[] args) throws NativeException {
23 super(host, name, args);
27 public void main(String[] strings) throws MsgException {
28 /* get hosts 1 and 2*/
30 host0 = Host.getByName("host0");
31 host1 = Host.getByName("host1");
32 host1 = Host.getByName("host2");
33 }catch (HostNotFoundException e) {
34 e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
37 // Robustness on the SRC node
38 //for (int i =0 ; i < 55000 ; i++)
39 // testVMMigrate(host1, i);
41 // Robustness on the DST node
42 //for (int i =0 ; i < 55000 ; i++)
43 // testVMMigrate(host2, i);
46 Msg.info("Nor more tests, Bye Bye !");
50 public static void testVMMigrate (Host hostToKill, long killAt) throws MsgException {
51 Msg.info("**** **** **** ***** ***** Test Migrate with host shutdown ***** ***** **** **** ****");
52 Msg.info("Turn on one host, assign a VM on this host, launch a process inside the VM, migrate the VM and "
53 + "turn off either the SRC or DST");
63 vm0 = new XVM(host1, "vm0",
68 -1, //size of disk image,
69 125, // Net bandwidth,
70 dpRate // Memory intensity
75 String[] args = new String[3];
80 new Process(host1, "Migrate-" + new Random().nextDouble(), args) {
81 public void main(String[] args) {
83 Host sourceHost = null;
86 sourceHost = Host.getByName(args[1]);
87 destHost = Host.getByName(args[2]);
88 } catch (Exception e) {
90 System.err.println("You are trying to migrate from/to a non existing node");
92 if (destHost != null) {
93 if (sourceHost.isOn() && destHost.isOn()) {
95 Msg.info("Migrate vm "+args[0]+" to node "+destHost.getName());
96 VM.getVMByName(args[0]).migrate(destHost);
97 } catch (HostFailureException e) {
99 Msg.info("Something occurs during the migration that cannot validate the operation");
106 // Wait killAt ms before killing thehost
107 Process.sleep(killAt);
110 Msg.info("The migration process should be stopped and we should catch an exception\n");
113 Process.sleep(50000);
114 Msg.info("Destroy VMs");
116 Process.sleep(20000);
119 public static void testVMShutdownDestroy () throws HostFailureException {
120 Msg.info("**** **** **** ***** ***** Test shutdown a VM ***** ***** **** **** ****");
121 Msg.info("Turn on host1, assign a VM on host1, launch a process inside the VM, and turn off the vm, " +
122 "and check whether you can reallocate the same VM");
126 XVM vm0 = new XVM(host1, "vm0",
129 125, // Net Bandwidth
130 null, //VM disk image
131 -1, //size of disk image,
132 125, // Net bandwidth,
133 dpRate // Memory intensity
135 Msg.info("Start VM0");
141 Msg.info("Shutdown VM0");
145 Msg.info("Restart VM0");
146 vm0 = new XVM(host1, "vm0",
149 125, // Net Bandwidth
150 null, //VM disk image
151 -1, //size of disk image,
152 125, // Net bandwidth,
153 dpRate // Memory intensity
158 Msg.info("You suceed to recreate and restart a VM without generating any exception ! Great the Test is ok");