Class QuotaService

java.lang.Object
edu.ucsb.nceas.metacat.dataone.quota.QuotaService
Direct Known Subclasses:
PortalQuotaService

public abstract class QuotaService extends Object
A class represents an abstract quota service. Its child classes, such as PortalQuotaService and StorageQuotaService should implement the abstract method - enforce.
Author:
tao
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected static BookKeeperClient
     
    static int
     
    protected static ExecutorService
     
    static String
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected int
    checkQuota(boolean checkEnoughSpace, String quotaSubject, String requestor, String quotaType, double quantity, String instanceId)
    Check if the quota has enough space for this request.
    protected void
    deleteUsage(int quotaId, String instanceId, double quantity)
    Delete a usage associated with the given quota id in the remote book keeper server.
    abstract void
    enforce(String quotaSubject, org.dataone.service.types.v1.Subject requestor, String instanceId, org.dataone.service.types.v2.SystemMetadata sysmeta, String method)
    The method will be implemented by the child classes to enforce the quota service
    protected boolean
    Checking if the given pid is last one in this series chain hasn't been archived
    protected boolean
    Checking if the given pid is last one in this series chain hasn't been deleted
    protected void
    updateUsage(int quotaId, String instanceId, double quantity)
    Update a usage with the archived status associated with the given quota id in the remote book keeper server.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • nodeId

      public static String nodeId
    • DEFAULT_QUOTA_ID

      public static int DEFAULT_QUOTA_ID
    • executor

      protected static ExecutorService executor
    • client

      protected static BookKeeperClient client
  • Constructor Details

    • QuotaService

      public QuotaService()
  • Method Details

    • enforce

      public abstract void enforce(String quotaSubject, org.dataone.service.types.v1.Subject requestor, String instanceId, org.dataone.service.types.v2.SystemMetadata sysmeta, String method) throws org.dataone.service.exceptions.ServiceFailure, org.dataone.service.exceptions.InvalidRequest, org.dataone.service.exceptions.InsufficientResources, org.dataone.service.exceptions.NotImplemented, org.dataone.service.exceptions.NotFound, UnsupportedEncodingException
      The method will be implemented by the child classes to enforce the quota service
      Parameters:
      quotaSubject - the subject of the quota which will be used
      requestor - the subject of the user who requests the usage
      instanceId - the id of the object will be applied the quota
      sysmeta - the system metadata of the object which will use the quota
      method - the method name which will call the createUsage method (create or update)
      Throws:
      org.dataone.service.exceptions.ServiceFailure
      org.dataone.service.exceptions.InvalidRequest
      org.dataone.service.exceptions.InsufficientResources
      org.dataone.service.exceptions.NotImplemented
      org.dataone.service.exceptions.NotFound
      UnsupportedEncodingException
    • isLastUnarchivedInChain

      protected boolean isLastUnarchivedInChain(String pid, String sid) throws org.dataone.service.exceptions.InvalidRequest, org.dataone.service.exceptions.ServiceFailure
      Checking if the given pid is last one in this series chain hasn't been archived
      Parameters:
      pid - the pid of the object will be checked
      sid - the id of the series chain will be checked
      Returns:
      true if the pid is the last one hasn't been archived; otherwise false.
      Throws:
      SQLException
      org.dataone.service.exceptions.InvalidRequest
      org.dataone.service.exceptions.ServiceFailure
    • isLastUndeletedInChain

      protected boolean isLastUndeletedInChain(String pid, String sid) throws org.dataone.service.exceptions.InvalidRequest, org.dataone.service.exceptions.ServiceFailure
      Checking if the given pid is last one in this series chain hasn't been deleted
      Parameters:
      pid - the pid of the object will be checked
      sid - the id of the series chain will be checked
      Returns:
      true if the pid is the last one hasn't been deleted; otherwise false.
      Throws:
      SQLException
      org.dataone.service.exceptions.InvalidRequest
      org.dataone.service.exceptions.ServiceFailure
    • checkQuota

      protected int checkQuota(boolean checkEnoughSpace, String quotaSubject, String requestor, String quotaType, double quantity, String instanceId) throws org.dataone.service.exceptions.InvalidRequest, org.dataone.service.exceptions.ServiceFailure, org.dataone.service.exceptions.InsufficientResources, org.dataone.service.exceptions.NotFound, UnsupportedEncodingException
      Check if the quota has enough space for this request. If there is not enough space, an exception will be thrown
      Parameters:
      checkEnoughSpace - indicator if we need to check if the found quota has enough space for this usage
      quotaSubject - the subject of the quota which will be used
      requestor - the subject of the user who requests the usage
      quotaType - the type of quota
      quantity - the amount of the usage for the request
      Returns:
      the quota id which will be used. -1 will be returned if the quota service is disabled
      Throws:
      org.dataone.service.exceptions.InvalidRequest
      IOException
      org.dataone.service.exceptions.ServiceFailure
      org.dataone.service.exceptions.NotFound
      org.apache.http.client.ClientProtocolException
      org.dataone.service.exceptions.InsufficientResources
      UnsupportedEncodingException
    • updateUsage

      protected void updateUsage(int quotaId, String instanceId, double quantity)
      Update a usage with the archived status associated with the given quota id in the remote book keeper server. Locally we will add a new record with the archived status in the table. It will be run by another thread. Metacat executes it without checking if the service is enabled. So the caller should check it.
      Parameters:
      quotaId - the quota id which the usage will be associated with
      instanceId - the id of the usage instance (pid for the storage type, and sid for the portal type)
      quantity - the amount of the usage
    • deleteUsage

      protected void deleteUsage(int quotaId, String instanceId, double quantity)
      Delete a usage associated with the given quota id in the remote book keeper server. However, locally we will add a new record with the deleted status in the table. It will be run by another thread. Metacat executes it without checking if the service is enabled. So the caller should check it.
      Parameters:
      quotaId - the quota id which the usage will be associated with
      instanceId - the id of the usage instance (pid for the storage type, and sid for the portal type)
      quantity - the amount of the usage