hu.mta.sztaki.lpds.cloud.simulator.iaas
Class VirtualMachine

java.lang.Object
  extended by hu.mta.sztaki.lpds.cloud.simulator.iaas.resourcemodel.ResourceSpreader
      extended by hu.mta.sztaki.lpds.cloud.simulator.iaas.resourcemodel.MaxMinFairSpreader
          extended by hu.mta.sztaki.lpds.cloud.simulator.iaas.resourcemodel.MaxMinConsumer
              extended by hu.mta.sztaki.lpds.cloud.simulator.iaas.VirtualMachine

public class VirtualMachine
extends MaxMinConsumer

This class represents a single virtual machine in the system. It simulates its behavior. Currently it supports three approaches for VM image storage:

  1. Local: The VA is expected to be in the PM's repository (caching), the class ensures its cloning and operates on the clone for its entire lifetime. During suspend the memory state is also stored in the PM's repository.
  2. Mixed: The VA is expected in a remote repository (e.g. it could reside in the central service in an IaaS). The class creates a local copy of this VA (in the PM's repository) so it can use it during the VM's lifetime. During suspend the memory state is also stored in the PM's repository.
  3. Remote: The VA is expected in a remote repository where it is cloned. The VM operates on the remote clone for its lifetime. During suspend the memory state is also stored in the remote repository.
Comparison of the 3 approaches:

Author:
"Gabor Kecskemeti, Distributed and Parallel Systems Group, University of Innsbruck (c) 2013" "Gabor Kecskemeti, Laboratory of Parallel and Distributed Systems, MTA SZTAKI (c) 2012"

Nested Class Summary
private static class VirtualMachine.EventSetup
          This internal interface is used to customize internal state change actions in the VM class.
(package private)  class VirtualMachine.InitialTransferEvent
           
private static class VirtualMachine.StartupProcedure
           
static class VirtualMachine.State
           
static interface VirtualMachine.StateChange
          This interface helps to receive events on status changes in virtual machines.
static class VirtualMachine.StateChangeException
          This class is defined to ensure one can differentiate errors that were caused because the functions on the VM class are called in an improper order.
 
Nested classes/interfaces inherited from class hu.mta.sztaki.lpds.cloud.simulator.iaas.resourcemodel.ResourceSpreader
ResourceSpreader.FreqSyncer
 
Field Summary
static EnumSet<VirtualMachine.State> consumingStates
           
private  VirtualMachine.State currState
           
private  StorageObject disk
           
static float loadwhilenotrunning
           
static EnumSet<VirtualMachine.State> preScheduleState
           
static EnumSet<VirtualMachine.State> preStartupStates
           
private  PhysicalMachine.ResourceAllocation ra
           
private  StorageObject savedmemory
           
private static VirtualMachine.EventSetup sdEvent
           
private static VirtualMachine.EventSetup susEvent
           
static EnumSet<VirtualMachine.State> suspendedStates
           
private  ArrayList<ResourceConsumption> suspendedTasks
           
private static VirtualMachine.EventSetup switchonEvent
           
static EnumSet<VirtualMachine.State> transferringStates
           
private  VirtualAppliance va
           
private  Repository vasource
           
private  Repository vatarget
           
private  StateDependentEventHandler<VirtualMachine.StateChange,org.apache.commons.lang3.tuple.Triple<VirtualMachine,VirtualMachine.State,VirtualMachine.State>> vmStateChangelistenerManager
           
 
Fields inherited from class hu.mta.sztaki.lpds.cloud.simulator.iaas.resourcemodel.ResourceSpreader
lastNotifTime, negligableProcessing, perTickProcessingPower, toBeAdded, toBeRemoved, underProcessing
 
Constructor Summary
VirtualMachine(VirtualAppliance va)
          Instantiates a VM object
 
Method Summary
private  void actualMigration(PhysicalMachine.ResourceAllocation target)
          This function is responsible for the actual transfer between the old physical machine and the new one.
 void destroy(boolean killTasks)
          Destroys the VM, and cleans up all repositories that could contain disk or memory states.
 PhysicalMachine.ResourceAllocation getResourceAllocation()
           
 VirtualMachine.State getState()
          Query the current state of the VM
 VirtualAppliance getVa()
          Queries the VA used by this VM
private  void initialTransfer(Repository vasource, Repository vatarget, VirtualMachine.EventSetup es)
          Ensures the transfer of the VM to the appropriate location.
protected  boolean isAcceptableConsumption(ResourceConsumption con)
           
 void migrate(PhysicalMachine.ResourceAllocation target)
          Moves all data necessary for the VMs execution from its current physical machine to another.
 ResourceConsumption newComputeTask(double total, double limit, ResourceConsumption.ConsumptionEvent e)
           
 void prepare(Repository vasource, Repository vatarget)
          Prepares the VM so it can be started without the need to clone its VA first.
private  void realResume()
           
 void resume()
          Resumes an already suspended VM.
private  void resumeAfterMigration(PhysicalMachine.ResourceAllocation target)
          This function is called after the disk and memory images of the VM are located on its new hosting repository.
 void setNonservable()
          If there are not enough resources for the VM currently, to recover from this state (and allow the VM to be rescheduled) just issue a destroy command on the VM
 void setResourceAllocation(PhysicalMachine.ResourceAllocation newRA)
           
private  void setState(VirtualMachine.State newstate)
          Always use this function to set the current VM state.
 void subscribeStateChange(VirtualMachine.StateChange consumer)
          Use this function to get notified about state changes on this VM
 void suspend()
          Suspends an already running VM.
private  void suspend(VirtualMachine.EventSetup ev)
          Just like regular suspend but allows eventsetup hooks.
 void switchoff(boolean killTasks)
          Switches off an already running machine.
 void switchOn(PhysicalMachine.ResourceAllocation allocation, Repository vasource)
          Initiates the startup procedure of a VM.
 String toString()
           
 void unsubscribeStateChange(VirtualMachine.StateChange consumer)
          Use this function to be no longer notified about state changes on this VM
 
Methods inherited from class hu.mta.sztaki.lpds.cloud.simulator.iaas.resourcemodel.MaxMinConsumer
getCounterPart, getSamePart, isConsumer, processSingleConsumption, updateConsumptionLimit
 
Methods inherited from class hu.mta.sztaki.lpds.cloud.simulator.iaas.resourcemodel.MaxMinFairSpreader
singleGroupwiseFreqUpdater
 
Methods inherited from class hu.mta.sztaki.lpds.cloud.simulator.iaas.resourcemodel.ResourceSpreader
getCurrentPowerBehavior, getPerTickProcessingPower, getSyncer, getTotalProcessed, hashCode, removeTheseConsumptions, setCurrentPowerBehavior, setPerTickProcessingPower, subscribePowerBehaviorChangeEvents, unsubscribePowerBehaviorChangeEvents
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

sdEvent

private static final VirtualMachine.EventSetup sdEvent

susEvent

private static final VirtualMachine.EventSetup susEvent

switchonEvent

private static final VirtualMachine.EventSetup switchonEvent

va

private VirtualAppliance va

ra

private PhysicalMachine.ResourceAllocation ra

disk

private StorageObject disk

savedmemory

private StorageObject savedmemory

vasource

private Repository vasource

vatarget

private Repository vatarget

consumingStates

public static final EnumSet<VirtualMachine.State> consumingStates

transferringStates

public static final EnumSet<VirtualMachine.State> transferringStates

suspendedStates

public static final EnumSet<VirtualMachine.State> suspendedStates

preStartupStates

public static final EnumSet<VirtualMachine.State> preStartupStates

preScheduleState

public static final EnumSet<VirtualMachine.State> preScheduleState

currState

private VirtualMachine.State currState

vmStateChangelistenerManager

private final StateDependentEventHandler<VirtualMachine.StateChange,org.apache.commons.lang3.tuple.Triple<VirtualMachine,VirtualMachine.State,VirtualMachine.State>> vmStateChangelistenerManager

loadwhilenotrunning

public static final float loadwhilenotrunning
See Also:
Constant Field Values

suspendedTasks

private final ArrayList<ResourceConsumption> suspendedTasks
Constructor Detail

VirtualMachine

public VirtualMachine(VirtualAppliance va)
Instantiates a VM object

Parameters:
va - the virtual appliance that should be the base for this VM
Method Detail

setState

private void setState(VirtualMachine.State newstate)
Always use this function to set the current VM state. This way all the interested parties get notified on the changes.

Parameters:
newstate - The new state the VM is in.

getVa

public VirtualAppliance getVa()
Queries the VA used by this VM

Returns:
the va used by this VM

getState

public VirtualMachine.State getState()
Query the current state of the VM

Returns:
the current vm state

prepare

public void prepare(Repository vasource,
                    Repository vatarget)
             throws VMManager.VMManagementException,
                    NetworkNode.NetworkException
Prepares the VM so it can be started without the need to clone its VA first. This function is useful in advanced scheduling situations.

Parameters:
vatarget - the disk that will host the VM.
vasource - the repository where the VA for this VM is found. If null, the function assumes it is found in the hosting PM's repository.
Throws:
VirtualMachine.StateChangeException - if the VM is not destroyed
VMManager.VMManagementException - if the VA transfer failed and the state change was reverted
NetworkNode.NetworkException

initialTransfer

private void initialTransfer(Repository vasource,
                             Repository vatarget,
                             VirtualMachine.EventSetup es)
                      throws VMManager.VMManagementException,
                             NetworkNode.NetworkException
Ensures the transfer of the VM to the appropriate location. The location is determined based on the VM storage approach used. While transferring it maintains the INITIAL_TR state. If there is a fault it falls back to the state beforehand. If successful it allows the caller to change the event on the way it sees fit.

Parameters:
pm - the physical machine that hosts the VM.
vasource - the repository where the VA for this VM is found. If null, the function assumes it is found in the hosting PM's repository.
es - The way the VM's state should be changed the function will fire an event on this channel if the VA is cloned properly
Throws:
VMManager.VMManagementException - if the VA transfer failed and the state change was reverted
NetworkNode.NetworkException

switchOn

public void switchOn(PhysicalMachine.ResourceAllocation allocation,
                     Repository vasource)
              throws VMManager.VMManagementException,
                     NetworkNode.NetworkException
Initiates the startup procedure of a VM. If the VM is in destroyed state then it ensures the disk image for the VM is ready to be used.

Parameters:
pm - the physical machine that hosts the VM.
vasource - the repository where the VA for this VM is found. If null, the function assumes it is found in the hosting PM's repository.
Throws:
VirtualMachine.StateChangeException - if the VM is not destroyed or shutdown
VMManager.VMManagementException - if the VA transfer failed and the state change was reverted
NetworkNode.NetworkException

resumeAfterMigration

private void resumeAfterMigration(PhysicalMachine.ResourceAllocation target)
                           throws NetworkNode.NetworkException
This function is called after the disk and memory images of the VM are located on its new hosting repository. The new location allows the VMs to be resumed on their new host machines. WARNING: After executing this function the VM might remain in SUSPENDED_MIG state if the resume on the new machine fails! For possible causes of this failure please check the documentation of the resume funciton.

Parameters:
target - the new resource allocation on which the resume operation should take place
Throws:
VMManager.VMManagementException - in case some errors were reported during the resume operation at the new physical machine
NetworkNode.NetworkException

actualMigration

private void actualMigration(PhysicalMachine.ResourceAllocation target)
                      throws NetworkNode.NetworkException
This function is responsible for the actual transfer between the old physical machine and the new one. This function ensures the transfer for both the disk and memory states. WARNING: in case an error occurs (e.g. there is not enough space on the target physical machine's repository) then this function leaves the VM in SUSPENDED_MIG state.

Parameters:
target - the new resource allocation on which the resume operation should take place
Throws:
NetworkNode.NetworkException

migrate

public void migrate(PhysicalMachine.ResourceAllocation target)
             throws VMManager.VMManagementException,
                    NetworkNode.NetworkException
Moves all data necessary for the VMs execution from its current physical machine to another. WARNING: in cases when the migration cannot complete, the VM will be left in a special suspended state: the SUSPENDED_MIG. This allows users to recover VMs and initiate the migration procedure to someplace else.

Parameters:
target - the new resource allocation on which the resume operation should take place
Throws:
VirtualMachine.StateChangeException - if the VM is not in running state currently
VMManager.VMManagementException - if the system have had troubles during the suspend operation.
NetworkNode.NetworkException

destroy

public void destroy(boolean killTasks)
             throws VMManager.VMManagementException
Destroys the VM, and cleans up all repositories that could contain disk or memory states.

Throws:
VirtualMachine.StateChangeException - if some parts of the VM are under transfer so it cannot be determined what to clean up.
VMManager.VMManagementException

switchoff

public void switchoff(boolean killTasks)
               throws VirtualMachine.StateChangeException
Switches off an already running machine. After the successful execution of this function, the VM's state will be shutdown.

Throws:
VirtualMachine.StateChangeException - if is not running currently

suspend

public void suspend()
             throws VMManager.VMManagementException,
                    NetworkNode.NetworkException
Suspends an already running VM. During the suspend operation, the VM's memory state is stored to enable the resume operation for fast VM startup. The VM's memory state is first created as a storage object on the PM's local repository then transferred to its designated location.

Throws:
VirtualMachine.StateChangeException - if the machine is not in running state
VMManager.VMManagementException - if there is not enough space to store the memory state (first locally, then locally/remotely depending on the VM storage scenario
NetworkNode.NetworkException

suspend

private void suspend(VirtualMachine.EventSetup ev)
              throws VMManager.VMManagementException,
                     NetworkNode.NetworkException
Just like regular suspend but allows eventsetup hooks.

Parameters:
ev - the eventsetup hook to be used when the suspend operation is complete.
Throws:
VirtualMachine.StateChangeException - see at regular suspend
VMManager.VMManagementException - see at regular suspend
NetworkNode.NetworkException

realResume

private void realResume()
                 throws VMManager.VMManagementException,
                        NetworkNode.NetworkException
Throws:
VMManager.VMManagementException
NetworkNode.NetworkException

resume

public void resume()
            throws VMManager.VMManagementException,
                   NetworkNode.NetworkException
Resumes an already suspended VM. During the resume operation, the VM's memory state is used for fast VM startup. The VM's memory state is first transferred to the PM's repository (simulating its loading to the VM's memory). Afterwards, this function cleans up the memory states as after startup the VM already changes them.

Throws:
VirtualMachine.StateChangeException - if the machine is not in suspended state
VMManager.VMManagementException - if there is not enough space to retreive the memory state to the PM's repository
NetworkNode.NetworkException

subscribeStateChange

public void subscribeStateChange(VirtualMachine.StateChange consumer)
Use this function to get notified about state changes on this VM

Parameters:
consumer - the party to be notified when the state changes

unsubscribeStateChange

public void unsubscribeStateChange(VirtualMachine.StateChange consumer)
Use this function to be no longer notified about state changes on this VM

Parameters:
consumer - the party who previously received notifications

isAcceptableConsumption

protected boolean isAcceptableConsumption(ResourceConsumption con)
Overrides:
isAcceptableConsumption in class ResourceSpreader

newComputeTask

public ResourceConsumption newComputeTask(double total,
                                          double limit,
                                          ResourceConsumption.ConsumptionEvent e)
                                   throws NetworkNode.NetworkException
Throws:
NetworkNode.NetworkException

setResourceAllocation

public void setResourceAllocation(PhysicalMachine.ResourceAllocation newRA)
                           throws VMManager.VMManagementException
Throws:
VMManager.VMManagementException

getResourceAllocation

public PhysicalMachine.ResourceAllocation getResourceAllocation()

setNonservable

public void setNonservable()
If there are not enough resources for the VM currently, to recover from this state (and allow the VM to be rescheduled) just issue a destroy command on the VM


toString

public String toString()
Overrides:
toString in class MaxMinConsumer


Copyright © 2012–2015 University of Innsbruck & MTA SZTAKI. All rights reserved.