org.gcube.vremanagement.resourcebroker.impl.services
Class GHNReservationHandler

java.lang.Object
  extended by org.gcube.vremanagement.resourcebroker.impl.services.GHNReservationHandler

public final class GHNReservationHandler
extends java.lang.Object

All the reservations of the GHNs to use during a decision making workflow are proxed by this component.

Makes use of persistent singleton resource (SingletonResourceStorage) and stores internally to it a global list of GHNDescriptor grouped by scope (GCUBEScope) and for each PlanBuilderWorkflow the list of GHNDescriptor entries owned by it (these lists are so referred as private since the GHNs registered there cannot be used by other workflow sessions).

The concurrent access to such shared resources are intermediated by this component that is the only responsible to handle GHN profiles, to retrieve them from the IS service and to properly update and manage them.

In the actual implementation the access to the GHNReservationHandler is in a singleton pattern. This implies that the access to this class follows the following schema:

 GHNReservationHandler handler = GHNReservationHandler.getInstance();
 handler.getNextGHN(...);
 

Author:
Daniele Strollo (ISTI-CNR)

Method Summary
 void addGHNDescriptor(GHNDescriptor ghn)
          Stores inside the list of global GHNs the one passed in input.
 boolean containsReservationFor(PlanBuilderIdentifier wfID)
          States if there is a reservation associated to a workflow identifier.
 GHNDescriptor getGHNByID(PlanBuilderIdentifier wfID, GCUBEScope scope, java.lang.String ghnID)
           Given a GHN ID returns the corresponding descriptor stored in the local cache.
 java.util.List<GHNDescriptor> getGlobalGHNsForScope(GCUBEScope scope, boolean applySorting)
          Deprecated. do not use this explicitly it is used only internally.
static GHNReservationHandler getInstance()
           
 GHNDescriptor getNextGHN(GCUBEScope scope, PlanBuilderIdentifier wfID, boolean reserve)
          Returns a new GHNDescriptor for a given GCUBEScope that can be assigned to a workflow uniquely identified by its PlanBuilderIdentifier.
 GHNDescriptor getNextMatchingGHN(GCUBEScope scope, PlanBuilderIdentifier wfID, Requirement[] requirements, boolean reserve)
          Used to retrieve the list of GHNs matching the input requirements.
 GHNReservation getReservationFor(PlanBuilderIdentifier wfID)
          Deprecated. for internal use only
 java.util.List<GHNDescriptor> getReservedGHNs(GCUBEScope scope, PlanBuilderIdentifier wfID)
          Access the permanent resource to retrieve the list of GHNDescriptor that have been reserved for a well defined PlanBuilderIdentifier.
 boolean isResourceLoaded()
           
 void reserveGHN(PlanBuilderIdentifier wfID, GHNDescriptor ghn)
          Makes a new reservation for a GHN registered into a scope.
 void revokeExpiredReservations()
          Deprecated. for internal use only.
 void revokeFailedReservation(PlanBuilderIdentifier wfID)
          Revokes all the reservations assigned to a plan identified by its PlanBuilderIdentifier.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static GHNReservationHandler getInstance()

getGHNByID

public GHNDescriptor getGHNByID(PlanBuilderIdentifier wfID,
                                GCUBEScope scope,
                                java.lang.String ghnID)
                         throws GCUBEFault

Given a GHN ID returns the corresponding descriptor stored in the local cache. If no element matches then null is returned.

The search is applied to both global and private GHNs that are reserved for the PlanBuilderIdentifier workflow session.

Note: If no PlanBuilderIdentifier is given (null) the GHN profile is search only inside the global list of GHNDescriptor for that scope.

Parameters:
wfID - the requesting workflow. If null the GHN descriptor will be searched only in the globally defined list of GHNs for that scope by ignoring the reserved ones.
scope - the scope the GHN is registered in.
ghnID - the ID of ghn to search.
Returns:
null if no element matches the request.
Throws:
GCUBEFault

getNextMatchingGHN

public GHNDescriptor getNextMatchingGHN(GCUBEScope scope,
                                        PlanBuilderIdentifier wfID,
                                        Requirement[] requirements,
                                        boolean reserve)
                                 throws GCUBEFault
Used to retrieve the list of GHNs matching the input requirements.

Parameters:
scope -
wfID -
Throws:
GCUBEFault

addGHNDescriptor

public void addGHNDescriptor(GHNDescriptor ghn)
                      throws GCUBEFault
Stores inside the list of global GHNs the one passed in input.

Parameters:
ghn - the GHNDescriptor to store.
Throws:
GCUBEFault

getGlobalGHNsForScope

public java.util.List<GHNDescriptor> getGlobalGHNsForScope(GCUBEScope scope,
                                                           boolean applySorting)
                                                    throws GCUBEFault
Deprecated. do not use this explicitly it is used only internally.

For internal use only. Initializes the GHN profiles for a given scope, stores them in the persistent resource and starts the timed thread demanded to their updating. Only at first invocation an access to the IS is needed. After the access to the IS for updated/created GHNs is demanded to the TUpdateGHNProfiles timed thread. The retrieved elements are implicitely stored inside the persistent state.

Note: This method is called only once per scope since it overwrites the GHNProfiles with the new ones. At initialization phase ServiceInitializer calls it for pre-fetching the GHNs for default scopes.

Throws:
GCUBEFault

getNextGHN

public GHNDescriptor getNextGHN(GCUBEScope scope,
                                PlanBuilderIdentifier wfID,
                                boolean reserve)
                         throws GCUBEFault
Returns a new GHNDescriptor for a given GCUBEScope that can be assigned to a workflow uniquely identified by its PlanBuilderIdentifier.

Parameters:
scope - the gCube scope in which the GHN must be retrieved.
wfID - the unique identifier of requesting PlanBuilderWorkflow.
reserve - if the returned GHNDescriptor should be reserved for the workflow.
Returns:
null if no GHN found satisfying the required conditions.
Throws:
GCUBEFault - if something goes wrong.

getReservedGHNs

public java.util.List<GHNDescriptor> getReservedGHNs(GCUBEScope scope,
                                                     PlanBuilderIdentifier wfID)
                                              throws GCUBEFault
Access the permanent resource to retrieve the list of GHNDescriptor that have been reserved for a well defined PlanBuilderIdentifier. Here the wfID parameter in mandatory.

Parameters:
scope - the scope in which the GHNDescriptor is published.
wfID - the plan identifier for which looking up the reserved GHNs.
Returns:
the list of GHNDescriptor reserved in the plan identified by wfID.
Throws:
GCUBEFault - in case of failure.

reserveGHN

public void reserveGHN(PlanBuilderIdentifier wfID,
                       GHNDescriptor ghn)
                throws GCUBEFault
Makes a new reservation for a GHN registered into a scope.

Parameters:
wfID - the PlanBuilderWorkflow owning the reservation.
ghn - the GHNDescriptor to reserve.
Throws:
GCUBEFault

revokeExpiredReservations

public void revokeExpiredReservations()
                               throws GCUBEFault
Deprecated. for internal use only.

Revokes all the reservations for which the time slot has expired. Invoked internally by TRevokeReservations.

Throws:
GCUBEFault

revokeFailedReservation

public void revokeFailedReservation(PlanBuilderIdentifier wfID)
                             throws GCUBEFault
Revokes all the reservations assigned to a plan identified by its PlanBuilderIdentifier. This functionality is used when the TTL for the reservation expires or when the decision making workflow internally fails.

Parameters:
wfID - the plan identifier.
Throws:
GCUBEFault - if something goes wrong.

containsReservationFor

public boolean containsReservationFor(PlanBuilderIdentifier wfID)
States if there is a reservation associated to a workflow identifier.


getReservationFor

public GHNReservation getReservationFor(PlanBuilderIdentifier wfID)
                                 throws GCUBEFault
Deprecated. for internal use only

For internal use. Gets from the persistent resource the data structure used to store reservations. Notice that there is a queue of reserved GHNDescriptor for each PlanBuilderWorkflow instance.

Note: If no reservation is associated a new one will be created and internally stored.

Parameters:
wfID - the PlanBuilderWorkflow identifier.
Returns:
the list of reservation stored inside the persistent resource.
Throws:
GCUBEFault - if resource is not available

isResourceLoaded

public boolean isResourceLoaded()