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 Msg.error("You are trying to use a non existing node:" + e.getMessage());
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",
62 125, // Net bandwidth,
63 dpRate // Memory intensity
68 String[] args = new String[3];
73 new Process(host1, "Migrate-" + killAt, args) {
74 public void main(String[] args) {
76 Host sourceHost = null;
79 sourceHost = Host.getByName(args[1]);
80 destHost = Host.getByName(args[2]);
81 } catch (HostNotFoundException e) {
82 Msg.error("You are trying to migrate from/to a non existing node: " + e.getMessage());
85 if (destHost != null && sourceHost.isOn() && destHost.isOn()) {
87 Msg.info("Migrate vm "+args[0]+" to node "+destHost.getName());
88 VM.getVMByName(args[0]).migrate(destHost);
89 } catch (HostFailureException e) {
90 Msg.error("Something occurs during the migration that cannot validate the operation: " + e.getMessage());
97 // Wait killAt ms before killing thehost
98 Process.sleep(killAt);
99 Msg.info("The migration process should be stopped and we should catch an exception");
102 Process.sleep(50000);
103 Msg.info("Destroy VMs");
105 Process.sleep(20000);
108 public void testVMShutdownDestroy () throws HostFailureException {
109 Msg.info("**** **** **** ***** ***** Test shutdown a VM ***** ***** **** **** ****");
110 Msg.info("Turn on host1, assign a VM on host1, launch a process inside the VM, and turn off the vm, " +
111 "and check whether you can reallocate the same VM");
115 XVM vm0 = new XVM(host1, "vm0",
117 125, // Net bandwidth,
118 dpRate // Memory intensity
120 Msg.info("Start VM0");
126 Msg.info("Shutdown VM0");
130 Msg.info("Restart VM0");
131 vm0 = new XVM(host1, "vm0",
133 125, // Net bandwidth,
134 dpRate // Memory intensity
139 Msg.info("You suceed to recreate and restart a VM without generating any exception ! Great the Test is ok");