orca.policy.core
Class AuthorityBasePolicyPlugin

java.lang.Object
  extended by orca.shirako.core.Policy
      extended by orca.shirako.core.AuthorityPolicy
          extended by orca.policy.core.AuthorityBasePolicyPlugin
All Implemented Interfaces:
IAuthorityPolicy, IInitialize, IPolicy, IRecover, ISerialize, IServerPolicy

public class AuthorityBasePolicyPlugin
extends AuthorityPolicy

The base for authority policy implementations

Author:
aydan

Field Summary
protected  AuthorityCalendar calendar
          The authority's calendar.
protected  java.util.Hashtable<java.lang.String,IResourceControl> controls
          ResourceControl objects indexed by resource type.
protected  java.util.Hashtable<java.lang.String,IResourceControl> controlsByGuid
          Resource control objects indexed by guid.
protected  boolean lazyClose
          If true, we will use lazy revocation.
static java.lang.String PropertyResourceControlClassPrefix
           
static java.lang.String PropertyResourceControlPrefix
           
static java.lang.String PropertyResourceControlsCount
           
static java.lang.String PropertyResourceControlTypesPrefix
           
protected  java.util.Hashtable<IResourceControl,java.util.Properties> tempProperties
          The important properties for persistence
 
Fields inherited from class orca.shirako.core.AuthorityPolicy
PropertySourceTicket, recoverer, tickets
 
Fields inherited from class orca.shirako.core.Policy
actor, clock, guid, logger, PropertyGuid
 
Constructor Summary
AuthorityBasePolicyPlugin()
          Creates a new instance.
 
Method Summary
protected  ResourceSet assign(AuthorityReservation reservation)
          Assign resources for the given reservation
 void assign(long cycle)
          Assigns leases to incoming tickets.
 void available(ResourceSet rset)
          Informs the policy that concrete resources previously marked as unavailable are now available.
 boolean bind(AuthorityReservation r)
          Handles a requests to allocate resources for a ticketed reservation.
 void close(ResourceReservation reservation)
          Notifies the policy that a reservation is about to be closed.
 void closed(ResourceReservation reservation)
          Notifies the policy that a reservation has been closed.
 void correctDeficit(AuthorityReservation reservation)
           
 ResourceSet correctFailed(ResourceSet rset)
          Incorporates fixed, but previously failed, resources back to the policy
 void donate(ResourceSet rset)
          Accepts concrete resources to be used for allocation of client requests.
 void eject(ResourceSet rset)
          Ejects concrete resources from the inventory.
protected  void error(java.lang.String string)
          Log and report an error
 boolean extend(AuthorityReservation reservation)
          Handles a requests to extend the allocation of previously allocated resources.
 void extend(ResourceReservation reservation, ResourceSet resources, Term term)
          Notifies the policy that a reservation is about to be extended.
 void finish(long cycle)
          Informs the mapper that all processing for the specified cycle is complete.
 void freed(ResourceSet rset)
          Informs the policy that a set of resources can be considered as free.
 AuthorityCalendar getCalendar()
          Returns the calendar used by this policy
protected  long getClose(Term term)
          Return the cycle when a term closes
 ReservationSet getClosing(long cycle)
          Returns a set of reservations that must be closed.
 IResourceControl getControl(ID guid)
           
protected  IResourceControl getControl(ResourceType type)
          Obtains the control object for the given resource type
 java.util.Hashtable<IResourceControl,java.util.List<java.lang.String>> getControlTypes()
          Returns a reverse map of resource control to resource types.
 ReservationSet getRequests(long cycle)
           
protected  java.lang.String getTypes(java.util.Hashtable<IResourceControl,java.util.List<java.lang.String>> types, IResourceControl c)
          Returns a comma-separated strings of all resource types the given resource control is registered to serve.
 void initialize()
          Initializes the object.
protected  void initializeControls()
          Initializes all registered controls.
protected  boolean isExpired(ResourceReservation r)
          See if a reservation has expired
protected  void map(AuthorityReservation r)
          Maps a reservation.
protected  void mapForCycle(ReservationSet requests, long cycle)
          Orders mapper request processing for this cycle.
protected  void mapGrowing(ReservationSet bids)
          Maps reservations that are growing in this cycle (redeems or expanding extends), and removes them from the bid set.
protected  void mapShrinking(ReservationSet bids)
          Maps reservations that are shrinking or staying the same (extending with no flex) in this cycle, and removes them from the bid set.
protected  void registerAndRevisit(AuthorityReservation r)
          Registers the reservation in the calendar and performs revisit with the control.
 void registerControl(ResourceType type, IResourceControl control)
          Registers the given control for the specified resource type.
 void registerControl(java.lang.String types, IResourceControl control)
          Registers the given control for all of the specified types.
 void release(ResourceSet rset)
          Releases concrete resources that are no longer in use.
 void remove(ResourceReservation reservation)
          Notifies the policy that a reservation is about to be removed.
protected  void reschedule(AuthorityReservation r)
          Reschedule a reservation into the calendar
 void reset(java.util.Properties p)
          De-serializes the object from the given properties list.
protected  void resetControls(java.util.Properties p)
           
 void revisit(IActor actor, java.util.Properties p)
          Recovers state of the component using a previously saved properties list and a references to the actor this component belongs to.
 void revisit(ResourceReservation r)
          Informs the mapper about a reservation.
protected  void revisitAuthority(AuthorityReservation r)
           
protected  void revisitControls(IActor actor)
          Initiates recovery for controls.
 void save(java.util.Properties p)
          Serializes the object into the given properties list.
protected  void saveControls(java.util.Properties p)
          Serializes all registered controls
 void setResourceControl(IResourceControl control)
          Registers the control.
NOTE: reserved only to be called from ContainerIntializer.
 int unavailable(ResourceSet rset)
          Informs the policy that concrete resources are about to become unavailable.
 
Methods inherited from class orca.shirako.core.AuthorityPolicy
allocate, bind, donate, exportResources, extend, finishCorrectDeficit, reset
 
Methods inherited from class orca.shirako.core.Policy
getGuid, internalError, logError, logWarn, prepare, query, save, setActor, setLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface orca.shirako.api.IPolicy
getGuid, prepare, query, setActor, setLogger
 
Methods inherited from interface orca.shirako.api.ISerialize
save
 

Field Detail

PropertyResourceControlsCount

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

PropertyResourceControlTypesPrefix

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

PropertyResourceControlClassPrefix

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

PropertyResourceControlPrefix

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

calendar

protected AuthorityCalendar calendar
The authority's calendar. A calendar of all requests


controls

protected java.util.Hashtable<java.lang.String,IResourceControl> controls
ResourceControl objects indexed by resource type.


controlsByGuid

protected java.util.Hashtable<java.lang.String,IResourceControl> controlsByGuid
Resource control objects indexed by guid.


tempProperties

protected java.util.Hashtable<IResourceControl,java.util.Properties> tempProperties
The important properties for persistence


lazyClose

protected boolean lazyClose
If true, we will use lazy revocation.

Constructor Detail

AuthorityBasePolicyPlugin

public AuthorityBasePolicyPlugin()
Creates a new instance.

Method Detail

initialize

public void initialize()
                throws java.lang.Exception
Description copied from interface: IInitialize
Initializes the object.

Specified by:
initialize in interface IInitialize
Overrides:
initialize in class AuthorityPolicy
Throws:
java.lang.Exception

initializeControls

protected void initializeControls()
                           throws java.lang.Exception
Initializes all registered controls.

Throws:
java.lang.Exception

save

public void save(java.util.Properties p)
          throws java.lang.Exception
Description copied from interface: ISerialize
Serializes the object into the given properties list.

Specified by:
save in interface ISerialize
Overrides:
save in class Policy
Parameters:
p - properties list to serialize the object into
Throws:
java.lang.Exception

reset

public void reset(java.util.Properties p)
           throws java.lang.Exception
Description copied from interface: ISerialize
De-serializes the object from the given properties list.

Specified by:
reset in interface ISerialize
Overrides:
reset in class Policy
Parameters:
p - properties list containing the serialized version of the object
Throws:
java.lang.Exception

getControlTypes

public java.util.Hashtable<IResourceControl,java.util.List<java.lang.String>> getControlTypes()
Returns a reverse map of resource control to resource types. The table is indexed by the resource control object and each entry is a linked list of resource types.

Returns:
a table of all of the different control types

getTypes

protected java.lang.String getTypes(java.util.Hashtable<IResourceControl,java.util.List<java.lang.String>> types,
                                    IResourceControl c)
                             throws java.lang.Exception
Returns a comma-separated strings of all resource types the given resource control is registered to serve.

Parameters:
types - the control types
c - a control
Returns:
a string representation of the control types
Throws:
java.lang.Exception

saveControls

protected void saveControls(java.util.Properties p)
                     throws java.lang.Exception
Serializes all registered controls

Parameters:
p - properties
Throws:
java.lang.Exception

resetControls

protected void resetControls(java.util.Properties p)
                      throws java.lang.Exception
Throws:
java.lang.Exception

registerAndRevisit

protected void registerAndRevisit(AuthorityReservation r)
                           throws java.lang.Exception
Registers the reservation in the calendar and performs revisit with the control.

Parameters:
r - reservation to register
Throws:
java.lang.Exception - if the control responsible for this reservation is missing

revisit

public void revisit(ResourceReservation r)
             throws java.lang.Exception
Description copied from interface: IPolicy
Informs the mapper about a reservation. Called during recovery/startup. The mapper must re-establish any state required for the management of the reservation.

Specified by:
revisit in interface IPolicy
Overrides:
revisit in class AuthorityPolicy
Throws:
java.lang.Exception

revisitAuthority

protected void revisitAuthority(AuthorityReservation r)
                         throws java.lang.Exception
Throws:
java.lang.Exception

revisit

public void revisit(IActor actor,
                    java.util.Properties p)
             throws java.lang.Exception
Description copied from interface: IRecover
Recovers state of the component using a previously saved properties list and a references to the actor this component belongs to. The component can use the actor object to access other objects necessary for its complete recovery.

Specified by:
revisit in interface IRecover
Overrides:
revisit in class AuthorityPolicy
Parameters:
actor - actor object the component belongs to
p - properties list containing configuration data about the component
Throws:
java.lang.Exception

revisitControls

protected void revisitControls(IActor actor)
                        throws java.lang.Exception
Initiates recovery for controls.

Parameters:
actor -
Throws:
java.lang.Exception

registerControl

public void registerControl(ResourceType type,
                            IResourceControl control)
Registers the given control for the specified resource type. If the policy plugin has already been initialized, the control should be initialized.

Parameters:
type - resource type
control - the control

registerControl

public void registerControl(java.lang.String types,
                            IResourceControl control)
                     throws java.lang.Exception
Registers the given control for all of the specified types.

Parameters:
types - set of resource types
control - the control
Throws:
java.lang.Exception

setResourceControl

public void setResourceControl(IResourceControl control)
                        throws java.lang.Exception
Registers the control.
NOTE: reserved only to be called from ContainerIntializer. User should use registerControl instead.

Parameters:
control - the control
Throws:
java.lang.Exception

getControl

protected IResourceControl getControl(ResourceType type)
Obtains the control object for the given resource type

Parameters:
type - resource type
Returns:
a control
Throws:
java.lang.Exception

getControl

public IResourceControl getControl(ID guid)

donate

public void donate(ResourceSet rset)
            throws java.lang.Exception
Description copied from interface: IAuthorityPolicy
Accepts concrete resources to be used for allocation of client requests. The policy should add the resources represented by this resource set to its inventory. This method is invoked with the kernel lock on.

Specified by:
donate in interface IAuthorityPolicy
Overrides:
donate in class AuthorityPolicy
Parameters:
rset - resource set representing resources to be used for allocation
Throws:
java.lang.Exception

eject

public void eject(ResourceSet rset)
           throws java.lang.Exception
Description copied from interface: IAuthorityPolicy
Ejects concrete resources from the inventory. Resource ejection is unconditional: the policy must remove the specified concrete nodes from its inventory. Any nodes that reside on ejected hosts should be marked as failed. The policy should take no action to destroy those nodes.

Specified by:
eject in interface IAuthorityPolicy
Overrides:
eject in class AuthorityPolicy
Throws:
java.lang.Exception

available

public void available(ResourceSet rset)
               throws java.lang.Exception
Description copied from interface: IAuthorityPolicy
Informs the policy that concrete resources previously marked as unavailable are now available.

Specified by:
available in interface IAuthorityPolicy
Overrides:
available in class AuthorityPolicy
Throws:
java.lang.Exception

unavailable

public int unavailable(ResourceSet rset)
                throws java.lang.Exception
Description copied from interface: IAuthorityPolicy
Informs the policy that concrete resources are about to become unavailable. The policy should stop using the concrete resources but should not remove them from its inventory. If the policy currently has active allocations on at least one unit from the concrete resources it should return -1 to indicate that at least one resource cannot be marked unavailable. If the caller still wants to mark a host with hosted nodes as unavailable, the caller may use some administrative interface to move hosts away from the problematic host and then it can retry the operation. Alternatively, the caller may use eject to force the removal of the concrete resources from the policy inventory.

Specified by:
unavailable in interface IAuthorityPolicy
Overrides:
unavailable in class AuthorityPolicy
Returns:
Throws:
java.lang.Exception

finish

public void finish(long cycle)
Description copied from interface: IPolicy
Informs the mapper that all processing for the specified cycle is complete. The mapper can safely discard any state associated with the cycle or any previous cycles. This method is invoked with the kernel lock on.

Note: The cycle number parameter is redundant and is passed for convenience. The policy can always obtain the cycle number by calling IActor.getCurrentCycle().

Specified by:
finish in interface IPolicy
Overrides:
finish in class Policy
Parameters:
cycle - the cycle number that has just passed

bind

public boolean bind(AuthorityReservation r)
             throws java.lang.Exception
Description copied from interface: IAuthorityPolicy
Handles a requests to allocate resources for a ticketed reservation. The requested resources can be obtained by calling reservation.getRequestedResources(). The requested lease term can be obtained by calling reservation.getRequestedTerm(). Properties specific to the lease protocol can be obtained by calling reservation.getRequestedResources().getConfigurationProperties(). This method is invoked with the kernel lock on.

If the policy completed processing this request, the functions should return true. If no further intervention is required, e.g., approval by an administrator, the policy should also clear the bidPending flag.

The policy may decide to defer the request for a later time. In this case the function should return false and the bidPending flag should remain unchanged.

This method may be invoked multiple times for a given reservation, i.e., if the policy delays the allocation, the system will continue invoking this method at later times until the policy completes processing this request.

Specified by:
bind in interface IAuthorityPolicy
Overrides:
bind in class AuthorityPolicy
Parameters:
r - reservation to allocate resources for.
Returns:
true, if the request has been fulfilled, false, if the allocation of resources will be delayed until a later time.
Throws:
java.lang.Exception

extend

public boolean extend(AuthorityReservation reservation)
               throws java.lang.Exception
Description copied from interface: IAuthorityPolicy
Handles a requests to extend the allocation of previously allocated resources. The requested resources can be obtained by calling reservation.getRequestedResources(). The requested lease term can be obtained by calling reservation.getRequestedTerm(). Properties specific to the lease protocol can be obtained by calling reservation.getRequestedResources().getConfigurationProperties(). This method is invoked with the kernel lock on.

If the policy completed processing this request, the functions should return true. If no further intervention is required, e.g., approval by an administrator, the policy should also clear the bidPending flag.

The policy may decide to defer the request for a later time. In this case the function should return false and the bidPending flag should remain unchanged.

This method may be invoked multiple times for a given reservation, i.e., if the policy delays the allocation, the system will continue invoking this method at later times until the policy completes processing this request.

Specified by:
extend in interface IAuthorityPolicy
Overrides:
extend in class AuthorityPolicy
Parameters:
reservation - reservation to allocate resources for.
Returns:
true, if the request has been fulfilled, false, if the allocation of resources will be delayed until a later time.
Throws:
java.lang.Exception

assign

protected ResourceSet assign(AuthorityReservation reservation)
                      throws java.lang.Exception
Assign resources for the given reservation

Parameters:
reservation - the request
Returns:
a set of resources for the request
Throws:
java.lang.Exception

correctDeficit

public void correctDeficit(AuthorityReservation reservation)
                    throws java.lang.Exception
Specified by:
correctDeficit in interface IAuthorityPolicy
Overrides:
correctDeficit in class AuthorityPolicy
Throws:
java.lang.Exception

assign

public void assign(long cycle)
            throws java.lang.Exception
Description copied from interface: IAuthorityPolicy
Assigns leases to incoming tickets. This method is called by the policy once per cycle. The method should determine whether to perform resource allocation on the given cycle and what requests to consider in that process. This method is invoked with the kernel lock on.

Specified by:
assign in interface IAuthorityPolicy
Overrides:
assign in class AuthorityPolicy
Parameters:
cycle - the cycle the authority is making assignment for
Throws:
java.lang.Exception

mapForCycle

protected void mapForCycle(ReservationSet requests,
                           long cycle)
                    throws java.lang.Exception
Orders mapper request processing for this cycle.

Parameters:
requests - The requests for this cycle
cycle - The cycle
Throws:
java.lang.Exception

mapShrinking

protected void mapShrinking(ReservationSet bids)
                     throws java.lang.Exception
Maps reservations that are shrinking or staying the same (extending with no flex) in this cycle, and removes them from the bid set.

Parameters:
bids - set of deferred operations for this cycle (non-null)
Throws:
java.lang.Exception

mapGrowing

protected void mapGrowing(ReservationSet bids)
                   throws java.lang.Exception
Maps reservations that are growing in this cycle (redeems or expanding extends), and removes them from the bid set.

Parameters:
bids - set of deferred operations for this cycle (non-null)
Throws:
java.lang.Exception

map

protected void map(AuthorityReservation r)
            throws java.lang.Exception
Maps a reservation. Indicates we will approve the request: update its expire time in the calendar, and issue a map probe. The map probe will result in a retry of the mapper request through bind or extend above, which will release the request to the associated mapper.

Parameters:
r - the reservation
Throws:
java.lang.Exception

reschedule

protected void reschedule(AuthorityReservation r)
Reschedule a reservation into the calendar

Parameters:
r - the reservation

getClose

protected long getClose(Term term)
Return the cycle when a term closes

Parameters:
term - the term
Returns:
the cycle of the end of a term

correctFailed

public ResourceSet correctFailed(ResourceSet rset)
                          throws java.lang.Exception
Description copied from interface: IAuthorityPolicy
Incorporates fixed, but previously failed, resources back to the policy

Specified by:
correctFailed in interface IAuthorityPolicy
Overrides:
correctFailed in class AuthorityPolicy
Parameters:
rset - the resources
Throws:
java.lang.Exception

release

public void release(ResourceSet rset)
Description copied from interface: IAuthorityPolicy
Releases concrete resources that are no longer in use. The set may represent active as well as failed resources. The policy must decide what to do with the released resources. Resources that have been properly closed/terminated are safe to be considered free for future use. Failed resources, however, are problematic. If the policy has no information about the cause of the failure and does not posses the means to recover the falure it should not consider the resources as free. In such cases, and administrator may need to correct the failure manually. When/if the failure is corrected and the resources are safe to be reused, the administrator will issue a call to IAuthorityPolicy.freed(ResourceSet), which is used to free resources unconditionally.

Specified by:
release in interface IAuthorityPolicy
Overrides:
release in class AuthorityPolicy
Parameters:
rset - the resource set to be released
See Also:
#closed(ResourceReservation)}

freed

public void freed(ResourceSet rset)
Description copied from interface: IAuthorityPolicy
Informs the policy that a set of resources can be considered as free. Most probably these resources represent previously failed resources, which have been repaired by an administrator. The policy must update its data structures to reflect the fact that the incoming resources are not longer in use. The policy should regard any state information that individual resource units may contain.

Specified by:
freed in interface IAuthorityPolicy
Overrides:
freed in class AuthorityPolicy

close

public void close(ResourceReservation reservation)
Notifies the policy that a reservation is about to be closed. This method will be invoked for every reservation that is about to be closed, even if the close was triggered by the policy itself. The policy should update its internal state/cancel pending operations associated with the reservation. This method is invoked with the kernel lock on.

Specified by:
close in interface IPolicy
Overrides:
close in class Policy
Parameters:
reservation - reservation about to close

closed

public void closed(ResourceReservation reservation)
Notifies the policy that a reservation has been closed. This method will be invoked for every reservation that closes successfully. The policy must uncommit any resources associated with the reservation, e.g, physical machines, currency, etc. This method is invoked with the kernel lock on.

Note: For an authority resources are released using the #IAuthorityPolicy.release(ResourceSet) method. Authority policy implementations should not consider the resources of the passed reservation as released. The release will take place once all configuration actions complete.

Specified by:
closed in interface IPolicy
Overrides:
closed in class Policy
Parameters:
reservation - closed reservation
See Also:
IAuthorityPolicy.release(ResourceSet)

remove

public void remove(ResourceReservation reservation)
Notifies the policy that a reservation is about to be removed. This method will be invoked for each reservation that is to be removed from the system. The policy should remove any state that it maintains for the reservation. This method is invoked with the kernel lock on.

Note: Only failed and closed reservations can be removed. The system will not invoke this method if the reservation is not closed or failed.

Specified by:
remove in interface IPolicy
Overrides:
remove in class Policy
Parameters:
reservation - reservation to be removed

extend

public void extend(ResourceReservation reservation,
                   ResourceSet resources,
                   Term term)
Notifies the policy that a reservation is about to be extended. This method will be invoked only for reservations, whose extensions have not been triggered by the policy, e.g, from the management interface. The policy should update its state to reflect the extend request. This method is invoked with the kernel lock on.

Specified by:
extend in interface IPolicy
Overrides:
extend in class Policy
Parameters:
reservation - reservation to be extended
resources - resource set used for the extension
term - term used for the extension

error

protected void error(java.lang.String string)
              throws java.lang.Exception
Log and report an error

Overrides:
error in class Policy
Parameters:
string - the error
Throws:
java.lang.Exception

isExpired

protected boolean isExpired(ResourceReservation r)
                     throws java.lang.Exception
See if a reservation has expired

Parameters:
r - reservation
Returns:
true if the reservation expired; otherwise, return false
Throws:
java.lang.Exception

getCalendar

public AuthorityCalendar getCalendar()
Returns the calendar used by this policy

Returns:

getRequests

public ReservationSet getRequests(long cycle)
Overrides:
getRequests in class AuthorityPolicy

getClosing

public ReservationSet getClosing(long cycle)
Returns a set of reservations that must be closed. This method is invoked with the kernel lock on.

Specified by:
getClosing in interface IPolicy
Overrides:
getClosing in class Policy
Parameters:
cycle - the current cycle


Copyright © 2007 Network/Internet Computing Lab. All Rights Reserved.