Class BookKeeperClient

java.lang.Object
edu.ucsb.nceas.metacat.dataone.quota.BookKeeperClient

public class BookKeeperClient extends Object
A client class to access the BookKeeper service
Author:
tao
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
     
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    A private constructor
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    createUsage(org.dataone.bookkeeper.api.Usage usage)
    Create a usage record for a given quota identifier in the book keeper service.
    int
    deleteUsage(int quotaId, String instanceId)
    Delete the usage with the given quota type and instance id in the remote book keeper service
    Get the singleton instance of the BookKeeplerClient class
    List<org.dataone.bookkeeper.api.Quota>
    listQuotas(String quotaSubject, String requestor, String quotaType)
    List the quotas associated with the given subject
    int
    updateUsage(int quotaId, String instanceId, org.dataone.bookkeeper.api.Usage usage)
    Update an existing usage with the given quota id and instance id

    Methods inherited from class java.lang.Object

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

    • DEFAULT_REMOTE_USAGE_ID

      public static final int DEFAULT_REMOTE_USAGE_ID
      See Also:
  • Constructor Details

    • BookKeeperClient

      protected BookKeeperClient() throws org.dataone.service.exceptions.ServiceFailure
      A private constructor
      Throws:
      IOException
      org.dataone.service.exceptions.ServiceFailure
  • Method Details

    • getInstance

      public static BookKeeperClient getInstance() throws org.dataone.service.exceptions.ServiceFailure
      Get the singleton instance of the BookKeeplerClient class
      Returns:
      the instance of the class
      Throws:
      IOException
      org.dataone.service.exceptions.ServiceFailure
    • listQuotas

      public List<org.dataone.bookkeeper.api.Quota> listQuotas(String quotaSubject, String requestor, String quotaType) throws org.dataone.service.exceptions.ServiceFailure, org.dataone.service.exceptions.NotFound, org.dataone.service.exceptions.InvalidRequest, UnsupportedEncodingException
      List the quotas associated with the given subject
      Parameters:
      quotaSubject - the subject who owns the quotas
      requestor - the subject of user who will request a usage
      quotaType - the type of the quotas (storage or portal)
      Returns:
      the list of quotas associated with the subject.
      Throws:
      IOException
      org.apache.http.client.ClientProtocolException
      org.dataone.service.exceptions.NotFound
      org.dataone.service.exceptions.ServiceFailure
      org.dataone.service.exceptions.InvalidRequest
      UnsupportedEncodingException
    • createUsage

      public int createUsage(org.dataone.bookkeeper.api.Usage usage) throws org.apache.http.client.ClientProtocolException, IOException, org.dataone.service.exceptions.ServiceFailure
      Create a usage record for a given quota identifier in the book keeper service. If it fails, an exception will be thrown
      Parameters:
      usage - the object of the usage will be created
      Returns:
      the usage id from the remote book keeper server
      Throws:
      org.apache.http.client.ClientProtocolException
      IOException
      org.dataone.service.exceptions.ServiceFailure
    • deleteUsage

      public int deleteUsage(int quotaId, String instanceId) throws org.dataone.service.exceptions.InvalidRequest, org.apache.http.client.ClientProtocolException, org.dataone.service.exceptions.ServiceFailure, IOException
      Delete the usage with the given quota type and instance id in the remote book keeper service
      Parameters:
      quotaType - the quota type associated with the usage
      instanceId - the instance id associated with the usage
      Returns:
      the remote usage id which was deleted. If it returns the default value -1, it means there is no remote usage matching the quota id and instance id and Metacat did nothing.
      Throws:
      org.dataone.service.exceptions.InvalidRequest
      org.apache.http.client.ClientProtocolException
      org.dataone.service.exceptions.ServiceFailure
      IOException
    • updateUsage

      public int updateUsage(int quotaId, String instanceId, org.dataone.bookkeeper.api.Usage usage) throws org.dataone.service.exceptions.InvalidRequest, org.apache.http.client.ClientProtocolException, org.dataone.service.exceptions.ServiceFailure, IOException
      Update an existing usage with the given quota id and instance id
      Parameters:
      quotaId - the quota id which the existing usage matches
      instanceId - the instance id which the existing usage matches
      usage - the new usage value will be used
      Returns:
      the remote usage id which was updated. If it returns the default value -1, it means there is no remote usage matching the quota id and instance id and Metacat did nothing.
      Throws:
      org.dataone.service.exceptions.InvalidRequest
      org.apache.http.client.ClientProtocolException
      org.dataone.service.exceptions.ServiceFailure
      IOException