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
          The event that will be received upon the completion of the VA's copy from vasource to vatarget.
private static class VirtualMachine.StartupProcedure
          Provides an implementation of the eventsetup class for the startup procedure which is modelled with a single taks that utilizes a single core of the VM for a specified amount of time (in ticks)
static class VirtualMachine.State
          the possible states of a virtual machine in DISSECT-CF.
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
          the set of those VM states that are expected to consume energy
private  VirtualMachine.State currState
          the current state of the VM
private  StorageObject disk
          the VM's disk that is stored on the vatarget.
static EnumSet<VirtualMachine.State> preScheduleState
          the set of states that show that a VM scheduler was not able to schedule the VM (maybe just yet)
static EnumSet<VirtualMachine.State> preStartupStates
          the states that can preceed the startup phase
private  PhysicalMachine.ResourceAllocation ra
          the resource allocation of this VM (this is only not null when the VM is actually running on a pm, or about to run)
private  StorageObject savedmemory
          if the VM is suspended then its memory is saved in the following storage object.
private static VirtualMachine.EventSetup sdEvent
          The operations to do on shutdown
private static VirtualMachine.EventSetup susEvent
          The operations to do on suspend
static EnumSet<VirtualMachine.State> suspendedStates
          the states in which the VM is suspended to disk
private  ArrayList<ResourceConsumption> suspendedTasks
          the list of resourceconsumptions (i.e.
private static VirtualMachine.EventSetup switchonEvent
          The operations to do on switchon
static EnumSet<VirtualMachine.State> transferringStates
          the set of those VM states that are transferring VM related data
private  VirtualAppliance va
          the virtual appliance that this VM is using for its disk
private  Repository vasource
          where should the VM's virtual appliance be located
private  Repository vatarget
          where should the VM's disk storage be placed during the VM's initiation procedure.
private  StateDependentEventHandler<VirtualMachine.StateChange,org.apache.commons.lang3.tuple.Triple<VirtualMachine,VirtualMachine.State,VirtualMachine.State>> vmStateChangelistenerManager
          the local handler of VM state change events.
 
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()
          Determines what is the resource allocation currently used by the VM.
 VirtualMachine.State getState()
          Queries 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)
          determines if a resourceconsumption object can be registered.
 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)
          This is the function that users are expected to use to create computing tasks on the VMs (not using resourceconsumptions directly).
 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()
          Actually manages the resume operation (could be invoked from migration as well as from resume)
 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)
          Allows to set a new resource allocation for the VM This function will notify the resource allocation about the acquiration of the resources by utilizing the use function!
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()
          A nice single line output for the VM that shows its state and resource allocation as well as the tasks it is running.
 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
The operations to do on shutdown


susEvent

private static final VirtualMachine.EventSetup susEvent
The operations to do on suspend


switchonEvent

private static final VirtualMachine.EventSetup switchonEvent
The operations to do on switchon


va

private VirtualAppliance va
the virtual appliance that this VM is using for its disk


ra

private PhysicalMachine.ResourceAllocation ra
the resource allocation of this VM (this is only not null when the VM is actually running on a pm, or about to run)


disk

private StorageObject disk
the VM's disk that is stored on the vatarget. if the VM is not past its initial transfer phase then the disk could be null.


savedmemory

private StorageObject savedmemory
if the VM is suspended then its memory is saved in the following storage object.


vasource

private Repository vasource
where should the VM's virtual appliance be located


vatarget

private Repository vatarget
where should the VM's disk storage be placed during the VM's initiation procedure.


consumingStates

public static final EnumSet<VirtualMachine.State> consumingStates
the set of those VM states that are expected to consume energy


transferringStates

public static final EnumSet<VirtualMachine.State> transferringStates
the set of those VM states that are transferring VM related data


suspendedStates

public static final EnumSet<VirtualMachine.State> suspendedStates
the states in which the VM is suspended to disk


preStartupStates

public static final EnumSet<VirtualMachine.State> preStartupStates
the states that can preceed the startup phase


preScheduleState

public static final EnumSet<VirtualMachine.State> preScheduleState
the set of states that show that a VM scheduler was not able to schedule the VM (maybe just yet)


currState

private VirtualMachine.State currState
the current state of the VM


vmStateChangelistenerManager

private final StateDependentEventHandler<VirtualMachine.StateChange,org.apache.commons.lang3.tuple.Triple<VirtualMachine,VirtualMachine.State,VirtualMachine.State>> vmStateChangelistenerManager
the local handler of VM state change events.


suspendedTasks

private final ArrayList<ResourceConsumption> suspendedTasks
the list of resourceconsumptions (i.e. compute tasks) that were suspended and need to be resumed after the VM itself is resumed.

Constructor Detail

VirtualMachine

public VirtualMachine(VirtualAppliance va)
Instantiates a VM object

Parameters:
va - the virtual appliance that should be the base for this VM,
Throws:
IllegalStateException - if the va is null
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()
Queries 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:
vatarget - the storage that will host the VM's working image (typically this is going to be the disk of the PM 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.
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 - if the VA's transfer cannot be completed (e.g., because of connectivity issues)

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 (i.e. first it starts the inittransfer procedure).

Parameters:
allocation - the resource allocation which will be used to deploy the VM on.
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
Actually manages the resume operation (could be invoked from migration as well as from resume)

Throws:
VMManager.VMManagementException - if the VM's memory cannot be recalled.

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)
determines if a resourceconsumption object can be registered. it is going to be determined acceptable all the time if the VM is in one of its consuming states.

Overrides:
isAcceptableConsumption in class ResourceSpreader
Parameters:
con - the consumption that is asked to be registered
Returns:
true if the consumption can be registered in this spreader's underprocessing list

newComputeTask

public ResourceConsumption newComputeTask(double total,
                                          double limit,
                                          ResourceConsumption.ConsumptionEvent e)
                                   throws NetworkNode.NetworkException
This is the function that users are expected to use to create computing tasks on the VMs (not using resourceconsumptions directly). The computing tasks created with this function are going to utilize CPUs and if there is a background load defined for the VM then during the processing of the CPU related activities there will be constant network activities modelled as well. The background network load represents cases when the VM's disk is hosted on the network (and thus inherent disk activities that would occur during CPU related activities can be modeled). Please note the backgorund load is the property of the VA (i.e. the VA represents an application and therefore one who creates the VA should know its disk related activities when the application is executed)

Parameters:
total - the amount of processing to be done (in number of instructions)
limit - the amount of processing this new compute task is allowed to do in a single tick (in instructions/tick). If there should be no limit for the processing then one can use the constant named ResourceConsumption.unlimitedProcessing.
e - the object to be notified about the completion of the computation ordered here
Returns:
the resource consumption object that will represent the CPU consumption. Could return null if the consumption cannot be registered or when there is no resoruce for the VM
Throws:
NetworkNode.NetworkException - if the background network load is not possible to simulate.

setResourceAllocation

public void setResourceAllocation(PhysicalMachine.ResourceAllocation newRA)
                           throws VMManager.VMManagementException
Allows to set a new resource allocation for the VM This function will notify the resource allocation about the acquiration of the resources by utilizing the use function!

Parameters:
newRA - the allocation to be used later on
Throws:
VMManager.VMManagementException - if the VM is already running using a host

getResourceAllocation

public PhysicalMachine.ResourceAllocation getResourceAllocation()
Determines what is the resource allocation currently used by the VM.

Returns:
the resource set used by the VM, null if there is no resource used by the VM currently

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()
A nice single line output for the VM that shows its state and resource allocation as well as the tasks it is running. Good for debugging and tracing.

Overrides:
toString in class MaxMinConsumer


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