File: TestHostOnOff.java

package info (click to toggle)
simgrid 3.21%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 21,972 kB
  • sloc: cpp: 88,193; ansic: 69,244; fortran: 6,089; f90: 5,162; xml: 4,861; java: 4,250; perl: 2,056; python: 1,193; sh: 1,159; makefile: 57; sed: 6
file content (149 lines) | stat: -rw-r--r-- 4,570 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/* Copyright (c) 2014-2018. The SimGrid Team.
 * All rights reserved.                                                     */

/* This program is free software; you can redistribute it and/or modify it
 * under the terms of the license (GNU LGPL) which comes with this package. */

package cloud.migration;

import org.simgrid.msg.Host;
import org.simgrid.msg.HostFailureException;
import org.simgrid.msg.HostNotFoundException;
import org.simgrid.msg.Msg;
import org.simgrid.msg.MsgException;
import org.simgrid.msg.Process;
import org.simgrid.msg.VM;

// 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. 
public class TestHostOnOff extends Process{

  protected Host host0 = null;
  protected Host host1 = null;
  protected Host host2 = null;

  TestHostOnOff(String hostname, String name) throws  HostNotFoundException {
    super(hostname, name);
  }

  public void main(String[] strings) throws MsgException {
    /* get hosts 1 and 2*/
    try {
      host0 = Host.getByName("PM0");
      host1 = Host.getByName("PM1");
      host2 = Host.getByName("PM2");
    }catch (HostNotFoundException e) {
      Msg.error("You are trying to use a non existing node:" + e.getMessage());
    }

    // Robustness on the SRC node
    for (int i =100 ; i < 55000 ; i+=100)
     testVMMigrate(host1, i);

    // Robustness on the DST node
    for (int i =0 ; i < 55000 ; i++)
      testVMMigrate(host2, i);

    /* End of Tests */
    Msg.info("Nor more tests, Bye Bye !");
    Main.setEndOfTest();
  }

  public void testVMMigrate (Host hostToKill, long killAt) throws MsgException {
    Msg.info("**** **** **** ***** ***** Test Migrate with host shutdown ***** ***** **** **** ****");
    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");

    host1.off();
    host2.off();
    host1.on();
    host2.on();

    // Create VM0
    int dpRate = 70;
    XVM vm0 = null;
    vm0 = new XVM(host1, "vm0",
        2048, // Ramsize,
        125, // Net bandwidth,
        dpRate // Memory intensity
        );
    vm0.start();
    vm0.setLoad(90);

    String[] args = new String[3];

    args[0] = "vm0";
    args[1] = "PM1";
    args[2] = "PM2";
    new Process(host1, "Migrate-" + killAt, args) {
      public void main(String[] args) {
        Host destHost = null;
        Host sourceHost = null;

        try {
          sourceHost = Host.getByName(args[1]);
          destHost = Host.getByName(args[2]);
        } catch (HostNotFoundException e) {
          Msg.error("You are trying to migrate from/to a non existing node: " + e.getMessage());
          e.printStackTrace();
        }
        if (destHost != null && sourceHost.isOn() && destHost.isOn()) {
          try {
            Msg.info("Migrate vm "+args[0]+" to node "+destHost.getName());
            VM.getVMByName(args[0]).migrate(destHost);
          } catch (HostFailureException e) {
            Msg.error("Something occurs during the migration that cannot validate the operation: " + e.getMessage());
            e.printStackTrace();
          }
        }
      }
    }.start();

    // Wait killAt ms before killing thehost
    Process.sleep(killAt);
    Msg.info("The migration process should be stopped and we should catch an exception");
    hostToKill.off();

    Process.sleep(50000);
    Msg.info("Destroy VMs");
    vm0.shutdown();
    Process.sleep(20000);
  }

  public void testVMShutdownDestroy () throws HostFailureException {
    Msg.info("**** **** **** ***** ***** Test shutdown a VM ***** ***** **** **** ****");
    Msg.info("Turn on host1, assign a VM on host1, launch a process inside the VM, and turn off the vm, " +
        "and check whether you can reallocate the same VM");

    // Create VM0
    int dpRate = 70;
    XVM vm0 = new XVM(host1, "vm0",
        2048, // Ramsize,
        125, // Net bandwidth,
        dpRate // Memory intensity
        );
    Msg.info("Start VM0");
    vm0.start();
    vm0.setLoad(90);

    Process.sleep(5000);

    Msg.info("Shutdown VM0");
    vm0.shutdown();
    Process.sleep(5000);

    Msg.info("Restart VM0");
    vm0 = new XVM(host1, "vm0",
        2048, // Ramsize,
        125, // Net bandwidth,
        dpRate // Memory intensity
        );
    vm0.start();
    vm0.setLoad(90);

    Msg.info("You suceed to recreate and restart a VM without generating any exception ! Great the Test is ok");

    Process.sleep(5000);
    vm0.shutdown();
  }
}