Package es.bsc.dataclay.metadataservice
Class MetaDataService
- java.lang.Object
-
- es.bsc.dataclay.util.management.AbstractManager
-
- es.bsc.dataclay.metadataservice.MetaDataService
-
- All Implemented Interfaces:
CommonManager
public final class MetaDataService extends AbstractManager
This class is responsible to manage information related to an object (metaclassID of the object, backend in which is stored, interface and contract used for creating the object...).
-
-
Field Summary
Fields Modifier and Type Field Description protected static boolean
DEBUG_ENABLED
Indicates if debug is enabled.-
Fields inherited from class es.bsc.dataclay.util.management.AbstractManager
dataSource
-
-
Constructor Summary
Constructors Constructor Description MetaDataService(SQLiteDataSource dataSource)
Instantiates an MetaDataService that uses the Backend configuration provided.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
changeDataSetID(ObjectID objectID, DataSetID newDataSetID)
This operation allows to explicitly register an dataSetID replacement.void
changeObjectID(ObjectID oldObjectID, ObjectID newObjectID)
This operation allows to explicitly register an objectID replacement.boolean
checkDatasetIsEmpty(DataSetID datasetID)
Checks that given dataset has no object.boolean
checkIsFederatedWith(ObjectID objectID, DataClayInstanceID dataClayID)
Checks whether the object is actually federated with dataClay instance identified with given IDboolean
checkObjectInSrcNotInDest(ObjectID objectID, ExecutionEnvironmentID srcBackend, ExecutionEnvironmentID destBackend)
This operation verifies that the object with ID provided exists in the backend with ID provided as source backend and not in the destination backend.void
cleanCaches()
Method that cleans the caches of the manager.void
closeDbHandler()
Close DbHandlerObjectID
deleteAlias(String alias)
Delete alias of objectboolean
existsExternalObject(ObjectID objectID)
Checks if the object is actually a federated objectboolean
existsObject(ObjectID objectID)
Checks whether an objects exists or not.boolean
externalObjectIsRegistered(ObjectID objectID)
Checks if the object is actually a federated object with unregistered flag = falseboolean
externalObjectIsUnregistered(ObjectID objectID)
Checks if the object is actually a federated object with unregistered flag = trueboolean
federateObjectWith(ObjectID objectID, DataClayInstanceID dataClayID)
Registers an object to be federated with an external dataClay identified with the given IDSet<ObjectID>
getAllObjectIDsRegistered()
Get all objects registered in systemSet<DataClayInstanceID>
getDataClaysOurObjectIsFederatedWith(ObjectID objectID)
Get all dataClays object provided is federated withMetaDataServiceDB
getDbHandler()
Method used for unit testing.DataClayInstanceID
getExternalSourceDataClayOfObject(ObjectID objectID)
Method that retrieves the info of external source dataClay of this objectMap<ExecutionEnvironmentID,ExecutionEnvironment>
getObjectBackends(ObjectID objectID)
This operation gets all the backend IDs that contain the object with ID provided.MemoryCache<ObjectID,ObjectMetaData>
getObjectCache()
Get the MetaDataService::objectMDCacheTuple<ObjectID,MetaDataInfo>
getObjectInfoFromAlias(String alias)
Get object ID from aliasMetaDataInfo
getObjectMetaData(ObjectID objectID)
This operation retrieves the metadata of an object.Set<ObjectID>
getObjectsFederatedWithDataClay(DataClayInstanceID extDataClayInstanceID)
Method that retrieves all the objects federated/belonging to dataClay with ID provided.Map<ObjectID,MetaDataInfo>
getObjectsOfSpecificClass(MetaClassID classID)
Returns information about the objects instantiating a given class.Set<ObjectID>
getUnregisteredExternalObjects()
Get unregistered external objects.void
markExternalObjectAsRegistered(ObjectID objectID)
Update external object to be marked as registeredvoid
markExternalObjectAsUnregistered(ObjectID objectID)
Update external object to be marked as unregisteredboolean
migrateObjectsToBackend(ExecutionEnvironmentID srcBackendID, Map<ExecutionEnvironmentID,Set<ObjectID>> newObjBackends, boolean unregisterBackend)
This operations removes the srcBackendID from the locations of the specified objects and adds the corresponding new location from newObjBackends to each of them.void
migrateObjectToBackend(ObjectID objectID, ExecutionEnvironmentID srcBackendID, ExecutionEnvironmentID destBackendID)
This operation moves an object from source location to destination locationvoid
registerExternalObject(ObjectID objectID, DataClayInstanceID dataClayID)
Registers an object that is federated from an external dataClay instance.MetaDataInfo
registerObject(ObjectID objectID, MetaClassID metaClassID, DataSetID datasetIDofProvider, Set<ExecutionEnvironmentID> backendIDs, boolean isReadOnly, String alias, CommonMessages.Langs lang, AccountID ownerID)
This operation registers the MetaData of an object.Map<ObjectID,MetaDataInfo>
registerVersions(Map<ObjectID,ObjectID> versionToOriginalMapping, ExecutionEnvironmentID backendID, CommonMessages.Langs lang)
Registers a set of versions, copying parts of the metadata from the original objectsvoid
setObjectReadOnly(ObjectID objectID)
This operation modifies the permissions of the object with ID provided to read-onlyvoid
setObjectReadWrite(ObjectID objectID)
This operation modifies the permissions of the object with ID provided to read-writeboolean
unfederateObjectWith(ObjectID objectID, DataClayInstanceID dataClayID)
Unfederate object with an external dataClay identified with the given IDvoid
unregisterExternalObject(ObjectID objectID)
Unregisters an object that is federated from an external dataClay instance.void
unregisterObject(ObjectID objectID)
This operation unregisters an object with ID provided.void
vacuumDB()
This operation cleans DB after unregistering objects
-
-
-
Constructor Detail
-
MetaDataService
public MetaDataService(SQLiteDataSource dataSource)
Instantiates an MetaDataService that uses the Backend configuration provided.- Parameters:
dataSource
- Data source.
-
-
Method Detail
-
existsObject
public boolean existsObject(ObjectID objectID)
Checks whether an objects exists or not.- Parameters:
objectID
- ID of the object to be checked.- Returns:
- True if the objectID is registered in the service, false otherwise.
- Throws:
Exception
- if any exception occurs
-
getObjectBackends
public Map<ExecutionEnvironmentID,ExecutionEnvironment> getObjectBackends(ObjectID objectID)
This operation gets all the backend IDs that contain the object with ID provided.- Parameters:
objectID
- ID of the object to query- Returns:
- The set of backends corresponding to those containing a replica of the object specified. The result can be empty.
- Throws:
Exception
- if an exception occurs:
ObjectNotRegisteredException: if the object is not registered.
-
getObjectMetaData
public MetaDataInfo getObjectMetaData(ObjectID objectID)
This operation retrieves the metadata of an object.- Parameters:
objectID
- ID of the object- Returns:
- the metadata of the given object
- Throws:
Exception
- if an exception occurs:
ObjectNotRegisteredException: if the object is not registered
-
getAllObjectIDsRegistered
public Set<ObjectID> getAllObjectIDsRegistered()
Get all objects registered in system- Returns:
- ids of all registered objects
-
getObjectInfoFromAlias
public Tuple<ObjectID,MetaDataInfo> getObjectInfoFromAlias(String alias)
Get object ID from alias- Parameters:
alias
- Alias of the object- Returns:
- the ID of the object if it is found and its metadata
- Throws:
Exception
- if an exception occurs:
ObjectNotRegisteredException: if the object is not registered
-
deleteAlias
public ObjectID deleteAlias(String alias)
Delete alias of object- Parameters:
alias
- Alias of the object- Returns:
- ID of the object
- Throws:
Exception
- if an exception occurs:
ObjectNotRegisteredException: if the object is not registered
-
getObjectsOfSpecificClass
public Map<ObjectID,MetaDataInfo> getObjectsOfSpecificClass(MetaClassID classID)
Returns information about the objects instantiating a given class.- Parameters:
classID
- the id of the class- Returns:
- a map indexed by the object ids with their info
-
registerObject
public MetaDataInfo registerObject(ObjectID objectID, MetaClassID metaClassID, DataSetID datasetIDofProvider, Set<ExecutionEnvironmentID> backendIDs, boolean isReadOnly, String alias, CommonMessages.Langs lang, AccountID ownerID) throws ObjectAlreadyRegisteredException, AliasAlreadyInUseException
This operation registers the MetaData of an object.- Parameters:
objectID
- ID of the objectmetaClassID
- ID of the class of the objectdatasetIDofProvider
- ID of the dataset where the object is createdbackendIDs
- IDs of the backeds where the object is stored (replicas)isReadOnly
- whether the object is readonly or notalias
- alias for the objectlang
- Object languageownerID
- Owner account ID- Returns:
- MetaDataInfo of the registered object
- Throws:
ObjectAlreadyRegisteredException
- if the object was already registeredAliasAlreadyInUseException
- if some of the aliases provided already exist
-
changeObjectID
public void changeObjectID(ObjectID oldObjectID, ObjectID newObjectID) throws ObjectNotRegisteredException, ObjectAlreadyRegisteredException
This operation allows to explicitly register an objectID replacement. If newObjectID is already registered, an exception is raised and the old ID is kept.- Parameters:
oldObjectID
- original ID of the objectnewObjectID
- final ID for the object- Throws:
Exception
- if an exception occurs:
ObjectNotRegisteredException: if object does not exist ObjectAlreadyRegisteredException: if new id is already being usedObjectNotRegisteredException
ObjectAlreadyRegisteredException
-
changeDataSetID
public void changeDataSetID(ObjectID objectID, DataSetID newDataSetID) throws ObjectNotRegisteredException
This operation allows to explicitly register an dataSetID replacement.- Parameters:
objectID
- original ID of the objectnewDataSetID
- final DataSetID for the object- Throws:
Exception
- if an exception occurs:
ObjectNotRegisteredException: if object does not existObjectNotRegisteredException
-
registerVersions
public Map<ObjectID,MetaDataInfo> registerVersions(Map<ObjectID,ObjectID> versionToOriginalMapping, ExecutionEnvironmentID backendID, CommonMessages.Langs lang) throws ObjectNotRegisteredException
Registers a set of versions, copying parts of the metadata from the original objects- Parameters:
versionToOriginalMapping
- Mapping from version objectID to original objectIDbackendID
- Backend in which the version is storedlang
- Language doing the operation (should match the object's one)- Returns:
- the metadata of the original objects (it will be required for consolidate)
- Throws:
Exception
- if an exception occurs:
ObjectNotRegisteredException: if an object does not existObjectNotRegisteredException
-
unregisterObject
public void unregisterObject(ObjectID objectID) throws ObjectNotRegisteredException
This operation unregisters an object with ID provided. This also unregisters all replicas and returns its locations.- Parameters:
objectID
- ID of the object to unregister- Throws:
Exception
- if an exception occurs:
ObjectNotRegisteredException: if object does not existObjectNotRegisteredException
-
vacuumDB
public void vacuumDB()
This operation cleans DB after unregistering objects
-
checkDatasetIsEmpty
public boolean checkDatasetIsEmpty(DataSetID datasetID)
Checks that given dataset has no object.- Parameters:
datasetID
- the ID of the dataset to be checked- Returns:
- Whether the dataset is empty or not.
- Throws:
Exception
- if an exception occurs.
-
checkObjectInSrcNotInDest
public boolean checkObjectInSrcNotInDest(ObjectID objectID, ExecutionEnvironmentID srcBackend, ExecutionEnvironmentID destBackend) throws ObjectNotRegisteredException
This operation verifies that the object with ID provided exists in the backend with ID provided as source backend and not in the destination backend.- Parameters:
objectID
- ID of the objectsrcBackend
- ID of the source backenddestBackend
- ID of the destination backend- Returns:
- TRUE if the object exists in the source backend and not in the destination backend. FALSE otherwise.
- Throws:
Exception
- if an exception occurs ObjectNotRegisteredException: if the object does not existObjectNotRegisteredException
-
migrateObjectToBackend
public void migrateObjectToBackend(ObjectID objectID, ExecutionEnvironmentID srcBackendID, ExecutionEnvironmentID destBackendID) throws ObjectNotRegisteredException, ExecutionEnvironmentNotExistException
This operation moves an object from source location to destination location- Parameters:
objectID
- ID of the object to modifysrcBackendID
- ID of the backend of the replica to be moveddestBackendID
- ID of the backend in which the object is 'moved'- Throws:
Exception
- if an exception occurs:
ObjectNotRegisteredException: if the object does not exist or it is not present in source backend ExecutionEnvironmentNotExistException: if destination backend does not existObjectNotRegisteredException
ExecutionEnvironmentNotExistException
-
migrateObjectsToBackend
public boolean migrateObjectsToBackend(ExecutionEnvironmentID srcBackendID, Map<ExecutionEnvironmentID,Set<ObjectID>> newObjBackends, boolean unregisterBackend) throws ExecutionEnvironmentNotExistException
This operations removes the srcBackendID from the locations of the specified objects and adds the corresponding new location from newObjBackends to each of them. If unregisterBackend is set to true, the srcBackendID is unregistered. WARNING: This function is not checking whether the srcBackendID becomes totally empty after migrating specified objects!!! For that, we would need an structure to keep which objects has every backend- Parameters:
srcBackendID
- ID of the unregistered backend from which objects are migratednewObjBackends
- the objects for every new destination backendunregisterBackend
- whether to unregister the srcBackendID or not- Returns:
- TRUE if the backend has been successfully unregistered. FALSE otherwise.
- Throws:
Exception
- if an exception occurs:
ExecutionEnvironmentNotExistException: if backend does not existExecutionEnvironmentNotExistException
-
setObjectReadOnly
public void setObjectReadOnly(ObjectID objectID) throws ObjectNotRegisteredException
This operation modifies the permissions of the object with ID provided to read-only- Parameters:
objectID
- ID of the object- Throws:
Exception
- if an exception occurs:
ObjectNotRegisteredException: if the object does not existObjectNotRegisteredException
-
setObjectReadWrite
public void setObjectReadWrite(ObjectID objectID) throws ObjectNotRegisteredException
This operation modifies the permissions of the object with ID provided to read-write- Parameters:
objectID
- ID of the object- Throws:
Exception
- if an exception occurs:
ObjectNotRegisteredException: if the object does not exist
ObjectHasReplicas: if the object has replicasObjectNotRegisteredException
-
federateObjectWith
public boolean federateObjectWith(ObjectID objectID, DataClayInstanceID dataClayID)
Registers an object to be federated with an external dataClay identified with the given ID- Parameters:
objectID
- id of the object to be federateddataClayID
- id of the external dataClay- Returns:
- false if the object cannot be federated, either because it was already federated or dataClayID is not registered true otherwise.
-
unfederateObjectWith
public boolean unfederateObjectWith(ObjectID objectID, DataClayInstanceID dataClayID)
Unfederate object with an external dataClay identified with the given ID- Parameters:
objectID
- id of the object to be unfederateddataClayID
- id of the external dataClay- Returns:
- false if the object cannot be unfederated, either because it was not federated or others. true otherwise.
-
checkIsFederatedWith
public boolean checkIsFederatedWith(ObjectID objectID, DataClayInstanceID dataClayID)
Checks whether the object is actually federated with dataClay instance identified with given ID- Parameters:
objectID
- id of the objectdataClayID
- id of the external dataClay instance- Returns:
- true if the object is federated. false otherwise.
-
getDataClaysOurObjectIsFederatedWith
public Set<DataClayInstanceID> getDataClaysOurObjectIsFederatedWith(ObjectID objectID)
Get all dataClays object provided is federated with- Parameters:
objectID
- ID of the object- Returns:
- dataClay IDs the object is federated with
-
registerExternalObject
public void registerExternalObject(ObjectID objectID, DataClayInstanceID dataClayID)
Registers an object that is federated from an external dataClay instance.- Parameters:
objectID
- ID of the federated object in the external dataClaydataClayID
- id of the external source dataClay
-
unregisterExternalObject
public void unregisterExternalObject(ObjectID objectID)
Unregisters an object that is federated from an external dataClay instance.- Parameters:
objectID
- ID of the federated object in the external dataClay
-
existsExternalObject
public boolean existsExternalObject(ObjectID objectID)
Checks if the object is actually a federated object- Parameters:
objectID
- id of the object- Returns:
- TRUE if object is external.
-
externalObjectIsRegistered
public boolean externalObjectIsRegistered(ObjectID objectID)
Checks if the object is actually a federated object with unregistered flag = false- Parameters:
objectID
- id of the object- Returns:
- TRUE if object is external.
-
externalObjectIsUnregistered
public boolean externalObjectIsUnregistered(ObjectID objectID)
Checks if the object is actually a federated object with unregistered flag = true- Parameters:
objectID
- id of the object- Returns:
- TRUE if object is external.
-
markExternalObjectAsUnregistered
public void markExternalObjectAsUnregistered(ObjectID objectID)
Update external object to be marked as unregistered- Parameters:
objectID
- ID of the object to update- Throws:
DbObjectNotExistException
- if object does not exist
-
markExternalObjectAsRegistered
public void markExternalObjectAsRegistered(ObjectID objectID)
Update external object to be marked as registered- Parameters:
objectID
- ID of the object to update- Throws:
DbObjectNotExistException
- if object does not exist
-
getUnregisteredExternalObjects
public Set<ObjectID> getUnregisteredExternalObjects()
Get unregistered external objects.- Returns:
- id of external objects unregistered
-
getExternalSourceDataClayOfObject
public DataClayInstanceID getExternalSourceDataClayOfObject(ObjectID objectID)
Method that retrieves the info of external source dataClay of this object- Parameters:
objectID
- id of the object- Returns:
- info of the external source dataClay
-
getObjectsFederatedWithDataClay
public Set<ObjectID> getObjectsFederatedWithDataClay(DataClayInstanceID extDataClayInstanceID)
Method that retrieves all the objects federated/belonging to dataClay with ID provided.- Parameters:
extDataClayInstanceID
- id of dataclay- Returns:
- all the objects federated/belonging to dataClay with ID provided.
-
getObjectCache
public MemoryCache<ObjectID,ObjectMetaData> getObjectCache()
Get the MetaDataService::objectMDCache- Returns:
- the Object MetaData Cache
-
getDbHandler
public MetaDataServiceDB getDbHandler()
Method used for unit testing.- Returns:
- The db handler reference of this manager.
-
closeDbHandler
public void closeDbHandler()
Close DbHandler
-
cleanCaches
public void cleanCaches()
Description copied from interface:CommonManager
Method that cleans the caches of the manager. Used on testing.- Specified by:
cleanCaches
in interfaceCommonManager
- Specified by:
cleanCaches
in classAbstractManager
-
-