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;
12 // This test aims at validating that the migration process is robust in face of host turning off either on the SRC
13 // node or on the DST node.
14 public class TestHostOnOff extends Process{
16 protected Host host0 = null;
17 protected Host host1 = null;
18 protected Host host2 = null;
20 TestHostOnOff(String hostname, String name) throws HostNotFoundException, NativeException {
21 super(hostname, name);
24 public void main(String[] strings) throws MsgException {
25 /* get hosts 1 and 2*/
27 host0 = Host.getByName("PM0");
28 host1 = Host.getByName("PM1");
29 host2 = Host.getByName("PM2");
30 }catch (HostNotFoundException e) {
31 e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
34 // Robustness on the SRC node
35 for (int i =100 ; i < 55000 ; i+=100)
36 testVMMigrate(host1, i);
38 // Robustness on the DST node
39 for (int i =0 ; i < 55000 ; i++)
40 testVMMigrate(host2, i);
43 Msg.info("Nor more tests, Bye Bye !");
47 public void testVMMigrate (Host hostToKill, long killAt) throws MsgException {
48 Msg.info("**** **** **** ***** ***** Test Migrate with host shutdown ***** ***** **** **** ****");
49 Msg.info("Turn on one host, assign a VM on this host, launch a process inside the VM, migrate the VM and "
50 + "turn off either the SRC or DST");
60 vm0 = new XVM(host1, "vm0",
65 -1, //size of disk image,
66 125, // Net bandwidth,
67 dpRate // Memory intensity
72 String[] args = new String[3];
77 new Process(host1, "Migrate-" + killAt, args) {
78 public void main(String[] args) {
80 Host sourceHost = null;
83 sourceHost = Host.getByName(args[1]);
84 destHost = Host.getByName(args[2]);
85 } catch (Exception e) {
87 System.err.println("You are trying to migrate from/to a non existing node");
89 if (destHost != null) {
90 if (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.info("Something occurs during the migration that cannot validate the operation");
103 // Wait killAt ms before killing thehost
104 Process.sleep(killAt);
105 Msg.info("The migration process should be stopped and we should catch an exception");
108 Process.sleep(50000);
109 Msg.info("Destroy VMs");
111 Process.sleep(20000);
114 public void testVMShutdownDestroy () throws HostFailureException {
115 Msg.info("**** **** **** ***** ***** Test shutdown a VM ***** ***** **** **** ****");
116 Msg.info("Turn on host1, assign a VM on host1, launch a process inside the VM, and turn off the vm, " +
117 "and check whether you can reallocate the same VM");
121 XVM vm0 = new XVM(host1, "vm0",
124 125, // Net Bandwidth
125 null, //VM disk image
126 -1, //size of disk image,
127 125, // Net bandwidth,
128 dpRate // Memory intensity
130 Msg.info("Start VM0");
136 Msg.info("Shutdown VM0");
140 Msg.info("Restart VM0");
141 vm0 = new XVM(host1, "vm0",
144 125, // Net Bandwidth
145 null, //VM disk image
146 -1, //size of disk image,
147 125, // Net bandwidth,
148 dpRate // Memory intensity
153 Msg.info("You suceed to recreate and restart a VM without generating any exception ! Great the Test is ok");