orca.policy.core
Class BrokerSimplePolicyPlugin

java.lang.Object
  extended by orca.shirako.core.Policy
      extended by orca.shirako.core.BrokerPolicy
          extended by orca.policy.core.BrokerBasePolicyPlugin
              extended by orca.policy.core.BrokerSimplePolicyPlugin
All Implemented Interfaces:
IBrokerPolicy, IClientPolicy, IInitialize, IPolicy, IRecover, ISerialize, IServerPolicy
Direct Known Subclasses:
BrokerPriorityPolicyPlugin

public class BrokerSimplePolicyPlugin
extends BrokerBasePolicyPlugin

AgentSimplePolicyPlugin is a simple implementation of an agent's plugin interface. It buffers requests for allocation periods and when it performs allocations of resources it does so in FIFO giving preference to extending requests.

Author:
grit

Field Summary
protected  long ADVANCE_TIME
          How far in the future is an Agent allocating resources (starting time).
protected  long CALL_INTERVAL
          Number of cycles between two consecutive allocations.
protected static long CLOCK_SKEW
          The amount of time over specific policy decisions the agent must add when communicating with other agents as a client (e.g.
protected  long lastAllocation
          Last time we allocated requests
protected  boolean ready
          Indicates if the agent is ready to accept requests
static java.lang.String REQUEST_TYPE
          Specifies the type of ticket being requested
 
Fields inherited from class orca.policy.core.BrokerBasePolicyPlugin
calendar, PropertyDiscoverTypes, PropertyTypeCount, PropertyTypeDescriptionPrefix, PropertyTypeNamePrefix, requireApproval
 
Fields inherited from class orca.shirako.core.BrokerPolicy
recoverer
 
Fields inherited from class orca.shirako.core.Policy
actor, clock, guid, logger, PropertyGuid
 
Constructor Summary
BrokerSimplePolicyPlugin()
           
 
Method Summary
 void allocate(long cycle)
          Run an allocation of requests against all sources, given a set of pending bids by using FCFS giving extends priority.
protected  void allocateExtending(java.util.Iterator sources, long startTime, java.util.Vector<java.lang.String> requestTypes)
          Iterates through all of the sources and allocates resources to their extending bids based on FIFO.
protected  void allocateNewBids(java.util.Iterator newBids, java.util.Hashtable<ResourceType,ReservationClient> sourceHash, long startTime, java.util.Vector<java.lang.String> requestTypes)
          Iterates through all of the new bids and allocates resources based on FIFO.
 boolean bind(BrokerReservation reservation)
          Handles an incoming request to allocate resources and issue a ticket for the reservation.
protected  long calculateAvailable(long startTime, ReservationClient source, BrokerReservation reservation)
          Calculate the available resources for a particular start time
protected  java.util.Hashtable<ResourceType,ReservationClient> createSourceHashtable(java.util.Iterator sources)
          Create a Hashtable of the sources by type.
 boolean extend(BrokerReservation reservation)
          Handles an incoming request to extend previously allocated resources and issue a ticket for the reservation.
protected  ResourceSet extractTicket(BrokerReservation reservation, ReservationClient source, Term approved, long resourceShare)
          Extract the ticket from the source and check to see if the resulting ticket satisfies the request
 Bids formulateBids(long cycle)
          Formulate a collection of bids to extend.
protected  long getAllocation(BrokerReservation reservation)
          Returns the allocation time for this reservation
protected  Term getApprovedTerm(BrokerReservation reservation)
          Determine the approved term of a reservation
protected  long getNextAllocation(long currentCycle)
          Returns the cycle of the next allocation period.
 long getRenew(ReservationClient reservation)
          Call up to the agent to receive the advanceTime.
protected  long getStartForAllocation(long allocationCycle)
          Returns the start time of reservations for an allocation at the given cycle.
 void prepare(long cycle)
          Informs the policy that processing for a new cycle is about to begin.
protected  ReservationSet processRenewing(ReservationSet renewing, ReservationSet pending)
          Performs checks on renewing reservations.
 java.util.Properties query(java.util.Properties properties)
          Returns the ADVANCE_TIME of an agent's allocation in the properties.
protected  void satisfyAllocation(BrokerReservation reservation, ReservationClient source, long resourceShare, long startResTime)
          Performs all of the checks and necessary functions to allocate a ticket to a reservation from a source.
protected  void switchSource(java.util.Iterator sources, long startTime, java.util.Hashtable<ResourceType,ReservationClient> sourceHash)
          Determine if a reservation has switched its source and place the request onto the correct source.
protected  boolean verifyWantedResources(BrokerReservation reservation, ReservationClient source, long startTime, int wanted)
          Ensure that there are sufficient resources to allocate the number of requested resources
 
Methods inherited from class orca.policy.core.BrokerBasePolicyPlugin
addForApproval, addForApprovalCalendar, addToCalendar, approve, checkPending, close, closed, count, donate, finish, getClosing, getForApproval, initialize, notApprove, release, release, releaseNotApproved, remove, removeForApproval, revisit, revisitClient, revisitServer
 
Methods inherited from class orca.shirako.core.BrokerPolicy
demand, getHoldings, getHoldings, getRedeeming, prepareExtend, prepareReserve, reset, revisit, ticketSatisfies, updateTicketComplete
 
Methods inherited from class orca.shirako.core.Policy
error, extend, getGuid, internalError, logError, logWarn, reset, save, 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
extend, getGuid, setActor, setLogger
 
Methods inherited from interface orca.shirako.api.ISerialize
reset, save, save
 
Methods inherited from interface orca.shirako.api.IPolicy
extend, getGuid, setActor, setLogger
 
Methods inherited from interface orca.shirako.api.ISerialize
reset, save, save
 

Field Detail

REQUEST_TYPE

public static final java.lang.String REQUEST_TYPE
Specifies the type of ticket being requested

See Also:
Constant Field Values

CALL_INTERVAL

protected long CALL_INTERVAL
Number of cycles between two consecutive allocations.


ADVANCE_TIME

protected long ADVANCE_TIME
How far in the future is an Agent allocating resources (starting time).


lastAllocation

protected long lastAllocation
Last time we allocated requests


ready

protected boolean ready
Indicates if the agent is ready to accept requests


CLOCK_SKEW

protected static long CLOCK_SKEW
The amount of time over specific policy decisions the agent must add when communicating with other agents as a client (e.g. renew()). Clock skew must be at least one if the agent is ticked after the upstream agent(s). At some point in time we may want this to not be static and learn it from what we see in the system, but for now it is static.

Constructor Detail

BrokerSimplePolicyPlugin

public BrokerSimplePolicyPlugin()
Method Detail

prepare

public void prepare(long cycle)
Informs the policy that processing for a new cycle is about to begin. The policy should initialize whatever internal state is necessary to process a new cycle. 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:
prepare in interface IPolicy
Overrides:
prepare in class Policy
Parameters:
cycle - the cycle number that is about to be processed

formulateBids

public Bids formulateBids(long cycle)
Formulate a collection of bids to extend. AgentSimple does not request new reservations, only extends existing ones. Formulates bids to the upstream broker(s). The method should determine whether to issue bids on the current cycle. This method should consider the current demand, call broker(s) to obtain necessary information and decide how to distribute its resource demand. When deciding how to bid, also consider any expiring reservation and decide whether to renew and adjust their units. The code should only formulate the bids: the actor will then issue them. This method is invoked with the kernel lock on.

Here are some guidelines for implementing this method:


Specified by:
formulateBids in interface IClientPolicy
Overrides:
formulateBids in class BrokerPolicy
Parameters:
cycle - The current time
Returns:
Two collections:
  • ticketing - set of new reservations
  • extending - set of reservations to be extended Can be null if no action should be taken

processRenewing

protected ReservationSet processRenewing(ReservationSet renewing,
                                         ReservationSet pending)
Performs checks on renewing reservations. Updates the terms to suggest new terms, stores the extend on the pending list. Returns a fresh ReservationSet of expiring reservations to try to renew in this bidding cycle.

Parameters:
renewing - collection of the renewing reservations
pending - collection of reservations that are pending
Returns:
non-null set of renewals
Throws:
java.lang.Exception - rare

allocate

public void allocate(long cycle)
              throws java.lang.Exception
Run an allocation of requests against all sources, given a set of pending bids by using FCFS giving extends priority. This simple policy runs through the bids in iterator order, and give every request min(requested,available) until we run out. It gives priority to extending requests compared to new requests. Assumes that there is only 1 source reservation per type. Makes the assumption that we allocate resources sequentially in time, so there are never less resources available in the future.
Allocates resources to all clients who have requested them. 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:
allocate in interface IServerPolicy
Overrides:
allocate in class BrokerPolicy
Parameters:
cycle - the cycle for this allocation
Throws:
java.lang.Exception

allocateNewBids

protected void allocateNewBids(java.util.Iterator newBids,
                               java.util.Hashtable<ResourceType,ReservationClient> sourceHash,
                               long startTime,
                               java.util.Vector<java.lang.String> requestTypes)
                        throws java.lang.Exception
Iterates through all of the new bids and allocates resources based on FIFO. Only allocates requests with types specified in requestTypes or all requests if requestTypes is null. Requests are associated with their appropriate source.

Parameters:
newBids - new bids to be allocated
sourceHash - the sources for this allocation
startTime - when the allocation begins
requestTypes - determines which request type is being allocated. A requestTypes of null indicates that any requestType may be allocated.
Throws:
java.lang.Exception

allocateExtending

protected void allocateExtending(java.util.Iterator sources,
                                 long startTime,
                                 java.util.Vector<java.lang.String> requestTypes)
                          throws java.lang.Exception
Iterates through all of the sources and allocates resources to their extending bids based on FIFO. Only allocates requests with types specified in requestTypes or all requests if requestTypes is null.

Parameters:
sources - sources for this allocation
startTime - when the allocation begins
requestTypes - determines which request type is being allocated. A requestType of null indicates that any requestType may be allocated.
Throws:
java.lang.Exception

verifyWantedResources

protected boolean verifyWantedResources(BrokerReservation reservation,
                                        ReservationClient source,
                                        long startTime,
                                        int wanted)
                                 throws java.lang.Exception
Ensure that there are sufficient resources to allocate the number of requested resources

Parameters:
reservation - reservation being allocated
source - source proposed for the requesting reservation
startTime - start of the proposed ticket
wanted - number of resources being requested
Returns:
true if there are sufficient resources, false otherwise
Throws:
java.lang.Exception

createSourceHashtable

protected java.util.Hashtable<ResourceType,ReservationClient> createSourceHashtable(java.util.Iterator sources)
Create a Hashtable of the sources by type. Only allows one source per type.

Parameters:
sources - sources for this allocation
Returns:
a Hashtable of the sources

switchSource

protected void switchSource(java.util.Iterator sources,
                            long startTime,
                            java.util.Hashtable<ResourceType,ReservationClient> sourceHash)
                     throws java.lang.Exception
Determine if a reservation has switched its source and place the request onto the correct source. This should be rare.

Parameters:
sources - sources for this allocation
startTime - start of the requested tickets
sourceHash - all of the sources for this allocation sorted by type
Throws:
java.lang.Exception

calculateAvailable

protected long calculateAvailable(long startTime,
                                  ReservationClient source,
                                  BrokerReservation reservation)
Calculate the available resources for a particular start time

Parameters:
startTime - start of proposed ticket
source - source who's resources are being counted
reservation - reservation associated with the counting (may be used to get start/end times)
Returns:
the available resources

getApprovedTerm

protected Term getApprovedTerm(BrokerReservation reservation)
Determine the approved term of a reservation

Parameters:
reservation -
Returns:
the approved term

satisfyAllocation

protected void satisfyAllocation(BrokerReservation reservation,
                                 ReservationClient source,
                                 long resourceShare,
                                 long startResTime)
                          throws java.lang.Exception
Performs all of the checks and necessary functions to allocate a ticket to a reservation from a source. Performs time shifting of a request's term if allowed, extracts units from the source, and assigns reservation.

Parameters:
reservation - request being allocated resources
source - source request is being allocated from
resourceShare - number of resources being allocated to the request
startResTime - when the ticket for the request starts
Throws:
java.lang.Exception

extractTicket

protected ResourceSet extractTicket(BrokerReservation reservation,
                                    ReservationClient source,
                                    Term approved,
                                    long resourceShare)
                             throws java.lang.Exception
Extract the ticket from the source and check to see if the resulting ticket satisfies the request

Parameters:
reservation - reservation being requested
source - source request is being extracted from
approved - the approved term for this ticket
resourceShare - number of resources being allocated to this ticket
Returns:
the newly extracted ticket
Throws:
java.lang.Exception

getNextAllocation

protected long getNextAllocation(long currentCycle)
Returns the cycle of the next allocation period. Does not update state.

Parameters:
currentCycle - the current cycle
Returns:
allocation cycle

getAllocation

protected long getAllocation(BrokerReservation reservation)
                      throws java.lang.Exception
Returns the allocation time for this reservation

Parameters:
reservation - reservation being assigned to an allocation
Returns:
allocation cycle for this reservation
Throws:
java.lang.Exception

getStartForAllocation

protected long getStartForAllocation(long allocationCycle)
Returns the start time of reservations for an allocation at the given cycle.

Parameters:
allocationCycle - allocation cycle
Returns:
the start time for reservation in this allocation cycle

getRenew

public long getRenew(ReservationClient reservation)
              throws java.lang.Exception
Call up to the agent to receive the advanceTime. Do time based on newStart so that requests are aligned with.
Returns the renew time of a given reservation

Specified by:
getRenew in class BrokerBasePolicyPlugin
Parameters:
reservation - reservation to calculate renew time from
Throws:
java.lang.Exception

bind

public boolean bind(BrokerReservation reservation)
             throws java.lang.Exception
Handles an incoming request to allocate resources and issue a ticket for the 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 allocation protocol can be obtained by calling reservation.getRequestedResources().getRequestProperties(). 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 IServerPolicy
Overrides:
bind in class BrokerPolicy
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

extend

public boolean extend(BrokerReservation reservation)
               throws java.lang.Exception
Handles an incoming request to extend previously allocated resources and issue a ticket for the reservation. The requested resources can be obtained by calling reservation.getRequestedResources(). Properties specific to the allocation protocol can be obtained by calling reservation.getRequestedResources().getRequestProperties(). The requested lease term can be obtained by calling reservation.getRequestedTerm(). The new term must extend the currently allocated term. 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.

While the policy is free to modify the term as it wishes, care must be taken that the client reservation is not closed before the extension is actually granted.

Specified by:
extend in interface IServerPolicy
Overrides:
extend in class BrokerPolicy
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

query

public java.util.Properties query(java.util.Properties properties)
Returns the ADVANCE_TIME of an agent's allocation in the properties. This is used so that service managers and downstream brokers know how early to bid. If the requested properties is null, the agent returns all of the properties that it has defined.
Answers a query from another actor. This method is intended to be used to obtain policy-specific parameters and information. This method should be used when writing more complex policies requiring additional interaction among actors. Instead of extending the proxies to support passing/obtaining the required information, policy code can use the query interface to request/obtain such information. This method is invoked with the kernel lock on: the implementation should not block for prolonged periods of time. If necessary, future versions will update this interface two allow query responses to be delivered using callbacks.

Specified by:
query in interface IPolicy
Overrides:
query in class BrokerBasePolicyPlugin
Returns:
a properties list of outgoing values. If the incoming properties collection is null or empty, should return all possible properties that can be relevant to the caller.


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