Class QuotaService
java.lang.Object
edu.ucsb.nceas.metacat.dataone.quota.QuotaService
- Direct Known Subclasses:
PortalQuotaService
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
Modifier and TypeFieldDescriptionprotected static BookKeeperClient
static int
protected static ExecutorService
static String
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected 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 serviceprotected boolean
isLastUnarchivedInChain
(String pid, String sid) Checking if the given pid is last one in this series chain hasn't been archivedprotected boolean
isLastUndeletedInChain
(String pid, String sid) Checking if the given pid is last one in this series chain hasn't been deletedprotected 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.
-
Field Details
-
nodeId
-
DEFAULT_QUOTA_ID
public static int DEFAULT_QUOTA_ID -
executor
-
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 usedrequestor
- the subject of the user who requests the usageinstanceId
- the id of the object will be applied the quotasysmeta
- the system metadata of the object which will use the quotamethod
- 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 checkedsid
- 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 checkedsid
- 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 usagequotaSubject
- the subject of the quota which will be usedrequestor
- the subject of the user who requests the usagequotaType
- the type of quotaquantity
- 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
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 withinstanceId
- the id of the usage instance (pid for the storage type, and sid for the portal type)quantity
- the amount of the usage
-
deleteUsage
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 withinstanceId
- the id of the usage instance (pid for the storage type, and sid for the portal type)quantity
- the amount of the usage
-