eu.xtreemos.xosd.resallocator
Class ResAllocator

java.lang.Object
  extended by eu.xtreemos.system.eventmachine.stage.AbstractStage
      extended by eu.xtreemos.system.eventmachine.stage.AbstractReceivingStage
          extended by eu.xtreemos.system.eventmachine.stage.Abstract2wayStage
              extended by eu.xtreemos.xosd.resallocator.ResAllocator
All Implemented Interfaces:
eu.xtreemos.system.eventmachine.queue.IEventHandler, eu.xtreemos.system.eventmachine.stage.IStage

public class ResAllocator
extends eu.xtreemos.system.eventmachine.stage.Abstract2wayStage

ResAllocator is a class that provides the functionality of a reservation manager for a local node to the other services. It is mostly used by the global reservation manager, providing the information about available resources and their reservations on a per-node level. Each node has list of resources that can be managed by the reservations. Each resource holds a separate time table, which is filled with time table elements (TTElm objects).

Author:
uros

Field Summary
static java.lang.String CPU_ID
           
(package private) static org.apache.log4j.Logger logger
           
static java.lang.String RAM_ID
           
protected  boolean resMonInfo
          Have we obtained the Resource Monitor's information yet?
static java.lang.String ROOT_ID
           
(package private)  FrontendWrapper wrapper
          In order to encapsulate the functionality of the service and of the backend, the service calls a wrapper.
 
Fields inherited from class eu.xtreemos.system.eventmachine.stage.Abstract2wayStage
context, counter, curContext, sink
 
Fields inherited from class eu.xtreemos.system.eventmachine.stage.AbstractReceivingStage
queue
 
Fields inherited from class eu.xtreemos.system.eventmachine.stage.AbstractStage
handlerChain, handlerGroup, handlerThreads, name, running, serviceListeners
 
Constructor Summary
ResAllocator()
           
 
Method Summary
 java.lang.Integer addResourceProperty(java.lang.String resID, IResourceProperty property)
          dummy method that allows "on-hand" addition of properties.
 java.lang.Boolean attachToJob(java.lang.String jobID, java.lang.String reservationID)
          Associates a job with a reservation id.
 Request createRequestsPurgeReservationsBefore(java.util.GregorianCalendar date)
          creates a request for purging all elements that finish before the given date.
 java.lang.String createReservation(Request info)
          Creates a reservation with a given request.
 java.util.ArrayList<java.lang.String> createReservations(java.util.ArrayList<Request> reservations)
          creates a massive a sequence of reservations. returns the ids of reservatins with a 1:1 mapping regarding their place.
 java.lang.Boolean detachFromJob(java.lang.String jobID, java.lang.String reservationID)
          Removes connection between a job and reservation id.
 FreeSlots getAllFreeSlotsFor(java.lang.String resourceID)
          Returns all free slots in a timetable for some resource.
 java.lang.Object getAllResources()
           
 java.util.ArrayList getDaemonsReply(java.util.ArrayList list)
           
 FreeSlots getFreeSlotsFor(java.lang.String resourceID, java.util.GregorianCalendar from, java.util.GregorianCalendar to)
          Returns all free slots for a given time frame for a specific resource.
 java.lang.String getHandledEventType()
           
 java.util.ArrayList<java.lang.String> getInitializedResources()
          returns all initialized resources
 java.util.ArrayList<java.lang.String> getReservationResources(java.lang.String reservationID)
          Returns all resources that are used by some reservation.
 java.util.ArrayList<ReservationSlot> getReservationsInfo(java.util.ArrayList<java.lang.String> ids)
          For a list of the IDs obtained from the createReservation(Request), the method builds a list of reservation slots descriptors, effectively returning the timetable entries usable for the reservations.
 java.util.ArrayList<TTElm> getSelection(java.lang.String resID, java.util.Hashtable constraints)
          get all time table elements with selected attributes for a resource.
 void handleEvent(java.lang.Object event)
           
 void init()
          Request info about some resources from the resource monitor.
 java.lang.Integer initializeResource(java.lang.String id)
          In order to make a new resource available and manageable (the ones that are not initialized in the startup process), one needs to register them, so that the system prepares a timetable for the reservations.
 java.lang.Integer invokeInit()
           
 java.lang.Integer invokeInitFailed(java.lang.Exception ex)
           
 java.lang.Integer invokeInitSucceeded(java.util.ArrayList<ResourceDescriptorRecord> result)
           
 java.lang.Boolean releaseReservation(java.lang.String reservationID)
          Removes all entries regarding a reservation id.
 java.lang.Boolean removeJob(java.lang.String jobID)
           
 java.util.ArrayList<java.lang.String> removeReservations(java.util.ArrayList<java.lang.String> reservationIDs)
          Clears the reservations associated with the selected reservation IDs from the allocation table.
 java.util.ArrayList<java.lang.String> reservationsForJob(java.lang.String jobID)
          Remove any info regarding a job.
 java.lang.Boolean restoreForCheckpointBefore(java.util.ArrayList<java.lang.String> reservationIDs)
          restores the state of all timetables just before the creation of the given reservation.
 java.util.ArrayList<TTElm> selectAvailable(java.lang.String resourceID, java.lang.Integer amount)
          selects available from all elements (see selectAvailableDT(String, Integer, GregorianCalendar, GregorianCalendar) description!)
 java.util.ArrayList<TTElm> selectAvailableDT(java.lang.String resourceID, java.lang.Integer amount, java.util.GregorianCalendar from, java.util.GregorianCalendar to)
          selects all already reserved elements within a timetable for some resource (identified by resourceID), where the amount of available resource property CurrentAmount is smaller than MaxAmount by more than given parameter "amount".
 java.lang.Boolean updateReservation(java.lang.String reservationID, Request info)
          Updates a reservation with a request, but leaving the reservation id intact.
 java.lang.Boolean updateReservations(java.util.ArrayList<UpdateRequest> requests)
          Creates a series of reservation updates.
 
Methods inherited from class eu.xtreemos.system.eventmachine.stage.Abstract2wayStage
getContext, removeContext, SendException, SendException, SendException, SendReply, SendReply, SendReply, setSink
 
Methods inherited from class eu.xtreemos.system.eventmachine.stage.AbstractReceivingStage
dequeue, getSource
 
Methods inherited from class eu.xtreemos.system.eventmachine.stage.AbstractStage
addHandler, addHandler, addServiceListener, getName, getShortName, getThreadCount, notifyServiceInitialised, notifyServiceStarted, notifyServiceStopped, processEvent, removeHandler, removeServiceListener, setThreadCount, start, stop
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CPU_ID

public static final java.lang.String CPU_ID
See Also:
Constant Field Values

RAM_ID

public static final java.lang.String RAM_ID
See Also:
Constant Field Values

ROOT_ID

public static final java.lang.String ROOT_ID
See Also:
Constant Field Values

logger

static org.apache.log4j.Logger logger

resMonInfo

protected boolean resMonInfo
Have we obtained the Resource Monitor's information yet?


wrapper

FrontendWrapper wrapper
In order to encapsulate the functionality of the service and of the backend, the service calls a wrapper.

Constructor Detail

ResAllocator

public ResAllocator()
Method Detail

init

public void init()
Request info about some resources from the resource monitor. Sets up the maximal values for the "usual" resources, like cpu speed, ram size, free root disk size, etc.

Specified by:
init in interface eu.xtreemos.system.eventmachine.stage.IStage
Overrides:
init in class eu.xtreemos.system.eventmachine.stage.AbstractStage

invokeInit

public java.lang.Integer invokeInit()

invokeInitSucceeded

public java.lang.Integer invokeInitSucceeded(java.util.ArrayList<ResourceDescriptorRecord> result)

invokeInitFailed

public java.lang.Integer invokeInitFailed(java.lang.Exception ex)

getAllResources

public java.lang.Object getAllResources()

getDaemonsReply

public java.util.ArrayList getDaemonsReply(java.util.ArrayList list)

getHandledEventType

public java.lang.String getHandledEventType()
Specified by:
getHandledEventType in class eu.xtreemos.system.eventmachine.stage.AbstractReceivingStage

handleEvent

public void handleEvent(java.lang.Object event)
                 throws java.lang.Exception
Specified by:
handleEvent in interface eu.xtreemos.system.eventmachine.queue.IEventHandler
Specified by:
handleEvent in class eu.xtreemos.system.eventmachine.stage.AbstractReceivingStage
Throws:
java.lang.Exception

createReservation

public java.lang.String createReservation(Request info)
Creates a reservation with a given request. Returns new reservation id, if the reservation succeeds, otherwise, returns null. When reservation fails, coherent state is restored automatically.

Parameters:
info -
Returns:

updateReservation

public java.lang.Boolean updateReservation(java.lang.String reservationID,
                                           Request info)
Updates a reservation with a request, but leaving the reservation id intact. Gets true, if all went well, false if it fails. The coherent state is restored automatically.

Parameters:
reservationID -
info -
Returns:

updateReservations

public java.lang.Boolean updateReservations(java.util.ArrayList<UpdateRequest> requests)
                                     throws AttributeConformanceException
Creates a series of reservation updates. Note that if one fails, all other are nullified also and the state of all TimeTables is returned to the original state before the call.

Parameters:
requests -
Returns:
Throws:
AttributeConformanceException

releaseReservation

public java.lang.Boolean releaseReservation(java.lang.String reservationID)
Removes all entries regarding a reservation id. Note, that here the only criteria is a reservation id and not the whole needed info, for example how much of the resource needs to be freed as well. Use this method wisely, otherwise, please use create/update reservation methods and use remove request.

Parameters:
reservationID -
Returns:

removeReservations

public java.util.ArrayList<java.lang.String> removeReservations(java.util.ArrayList<java.lang.String> reservationIDs)
                                                         throws java.lang.Exception
Clears the reservations associated with the selected reservation IDs from the allocation table. Note the comment on the releaseReservation method!

Returns:
A collection of reservation IDs where the removal failed. Empty collection means the operation has fully succeeded.
Throws:
java.lang.Exception

getReservationResources

public java.util.ArrayList<java.lang.String> getReservationResources(java.lang.String reservationID)
Returns all resources that are used by some reservation.

Parameters:
reservationID -
Returns:

attachToJob

public java.lang.Boolean attachToJob(java.lang.String jobID,
                                     java.lang.String reservationID)
Associates a job with a reservation id. This is only on a semantic level, and should be used whenever reservations are dependent.

Parameters:
jobID -
reservationID -
Returns:

detachFromJob

public java.lang.Boolean detachFromJob(java.lang.String jobID,
                                       java.lang.String reservationID)
Removes connection between a job and reservation id. This is managed by the user/service and not automatically. Associations betweem reservations should be used whenever they are dependent.

Parameters:
jobID -
reservationID -
Returns:

removeJob

public java.lang.Boolean removeJob(java.lang.String jobID)

reservationsForJob

public java.util.ArrayList<java.lang.String> reservationsForJob(java.lang.String jobID)
Remove any info regarding a job. Managed by the user/service.

Parameters:
jobID -
Returns:

getAllFreeSlotsFor

public FreeSlots getAllFreeSlotsFor(java.lang.String resourceID)
Returns all free slots in a timetable for some resource.

Parameters:
resourceID -
Returns:
null if no such resource exists or there was error with attribute conformance.

getFreeSlotsFor

public FreeSlots getFreeSlotsFor(java.lang.String resourceID,
                                 java.util.GregorianCalendar from,
                                 java.util.GregorianCalendar to)
Returns all free slots for a given time frame for a specific resource.

Parameters:
resourceID -
from -
to -
Returns:

selectAvailable

public java.util.ArrayList<TTElm> selectAvailable(java.lang.String resourceID,
                                                  java.lang.Integer amount)
selects available from all elements (see selectAvailableDT(String, Integer, GregorianCalendar, GregorianCalendar) description!)

Parameters:
resourceID -
amount -
Returns:

selectAvailableDT

public java.util.ArrayList<TTElm> selectAvailableDT(java.lang.String resourceID,
                                                    java.lang.Integer amount,
                                                    java.util.GregorianCalendar from,
                                                    java.util.GregorianCalendar to)
selects all already reserved elements within a timetable for some resource (identified by resourceID), where the amount of available resource property CurrentAmount is smaller than MaxAmount by more than given parameter "amount". Also, the sharing value of such element must not be EXCLUSIVE.

Parameters:
resourceID -
amount -
from -
to -
Returns:

initializeResource

public java.lang.Integer initializeResource(java.lang.String id)
In order to make a new resource available and manageable (the ones that are not initialized in the startup process), one needs to register them, so that the system prepares a timetable for the reservations.

Parameters:
id -
Returns:

getInitializedResources

public java.util.ArrayList<java.lang.String> getInitializedResources()
returns all initialized resources

Returns:

createRequestsPurgeReservationsBefore

public Request createRequestsPurgeReservationsBefore(java.util.GregorianCalendar date)
creates a request for purging all elements that finish before the given date. Since it is of no value to the executor and job manager to have reservations before current real time, all past reservations can be removed without any loss of info.

Parameters:
date -
Returns:

addResourceProperty

public java.lang.Integer addResourceProperty(java.lang.String resID,
                                             IResourceProperty property)
dummy method that allows "on-hand" addition of properties. Should be replaced by proper initialization system ...

Parameters:
resID -
property -

getSelection

public java.util.ArrayList<TTElm> getSelection(java.lang.String resID,
                                               java.util.Hashtable constraints)
get all time table elements with selected attributes for a resource. The contraints are a map of attribute types and their values.

Parameters:
resID -
constraints -
Returns:

getReservationsInfo

public java.util.ArrayList<ReservationSlot> getReservationsInfo(java.util.ArrayList<java.lang.String> ids)
For a list of the IDs obtained from the createReservation(Request), the method builds a list of reservation slots descriptors, effectively returning the timetable entries usable for the reservations. Get required information for the ReservationManager about all reservations slots in the time table regarding some reservation id.

Parameters:
reservationIDs - A collection of the IDs obtained from createReservation(Request).
Returns:
A collection of timetable entry descriptors.

createReservations

public java.util.ArrayList<java.lang.String> createReservations(java.util.ArrayList<Request> reservations)
creates a massive a sequence of reservations. returns the ids of reservatins with a 1:1 mapping regarding their place. If one of the reservations fails, all of them must fail also. If reservation fails, but restoring succeeds, the empty array is returned, otherwise, if the restoring fails also, the null object is returned.

Parameters:
reservations -
Returns:

restoreForCheckpointBefore

public java.lang.Boolean restoreForCheckpointBefore(java.util.ArrayList<java.lang.String> reservationIDs)
restores the state of all timetables just before the creation of the given reservation. If it was already restored or if there is no info about it, the call fails otherwise, it succeeds.

Parameters:
reservationID -
Returns:
Throws:
AttributeConformanceException