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 protected Host host0 = null;
19 protected Host host1 = null;
20 protected Host host2 = null;
22 TestHostOnOff(String hostname, String name) throws HostNotFoundException, NativeException {
23 super(hostname, name);
26 public void main(String[] strings) throws MsgException {
27 /* get hosts 1 and 2*/
29 host0 = Host.getByName("PM0");
30 host1 = Host.getByName("PM1");
31 host2 = Host.getByName("PM2");
32 }catch (HostNotFoundException e) {
33 e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
36 // Robustness on the SRC node
37 for (int i =100 ; i < 55000 ; i+=100)
38 testVMMigrate(host1, i);
40 // Robustness on the DST node
41 for (int i =0 ; i < 55000 ; i++)
42 testVMMigrate(host2, i);
45 Msg.info("Nor more tests, Bye Bye !");
49 public void testVMMigrate (Host hostToKill, long killAt) throws MsgException {
50 Msg.info("**** **** **** ***** ***** Test Migrate with host shutdown ***** ***** **** **** ****");
51 Msg.info("Turn on one host, assign a VM on this host, launch a process inside the VM, migrate the VM and "
52 + "turn off either the SRC or DST");
62 vm0 = new XVM(host1, "vm0",
67 -1, //size of disk image,
68 125, // Net bandwidth,
69 dpRate // Memory intensity
74 String[] args = new String[3];
79 new Process(host1, "Migrate-" + killAt, args) {
80 public void main(String[] args) {
82 Host sourceHost = null;
85 sourceHost = Host.getByName(args[1]);
86 destHost = Host.getByName(args[2]);
87 } catch (Exception e) {
89 System.err.println("You are trying to migrate from/to a non existing node");
91 if (destHost != null) {
92 if (sourceHost.isOn() && destHost.isOn()) {
94 Msg.info("Migrate vm "+args[0]+" to node "+destHost.getName());
95 VM.getVMByName(args[0]).migrate(destHost);
96 } catch (HostFailureException e) {
97 Msg.info("Something occurs during the migration that cannot validate the operation");
105 // Wait killAt ms before killing thehost
106 Process.sleep(killAt);
107 Msg.info("The migration process should be stopped and we should catch an exception");
110 Process.sleep(50000);
111 Msg.info("Destroy VMs");
113 Process.sleep(20000);
116 public void testVMShutdownDestroy () throws HostFailureException {
117 Msg.info("**** **** **** ***** ***** Test shutdown a VM ***** ***** **** **** ****");
118 Msg.info("Turn on host1, assign a VM on host1, launch a process inside the VM, and turn off the vm, " +
119 "and check whether you can reallocate the same VM");
123 XVM vm0 = new XVM(host1, "vm0",
126 125, // Net Bandwidth
127 null, //VM disk image
128 -1, //size of disk image,
129 125, // Net bandwidth,
130 dpRate // Memory intensity
132 Msg.info("Start VM0");
138 Msg.info("Shutdown VM0");
142 Msg.info("Restart VM0");
143 vm0 = new XVM(host1, "vm0",
146 125, // Net Bandwidth
147 null, //VM disk image
148 -1, //size of disk image,
149 125, // Net bandwidth,
150 dpRate // Memory intensity
155 Msg.info("You suceed to recreate and restart a VM without generating any exception ! Great the Test is ok");