Class 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 Detail

      • DEBUG_ENABLED

        protected static final boolean DEBUG_ENABLED
        Indicates if debug is enabled.
    • 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
      • 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 object
        newDataSetID - final DataSetID for the object
        Throws:
        Exception - if an exception occurs:
        ObjectNotRegisteredException: if object does not exist
        ObjectNotRegisteredException
      • 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 exist
        ObjectNotRegisteredException
      • 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 object
        srcBackend - ID of the source backend
        destBackend - 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 exist
        ObjectNotRegisteredException
      • 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 migrated
        newObjBackends - the objects for every new destination backend
        unregisterBackend - 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 exist
        ExecutionEnvironmentNotExistException
      • 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 exist
        ObjectNotRegisteredException
      • 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 replicas
        ObjectNotRegisteredException
      • 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 federated
        dataClayID - 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 unfederated
        dataClayID - 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 object
        dataClayID - 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 dataClay
        dataClayID - 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.
      • getDbHandler

        public MetaDataServiceDB getDbHandler()
        Method used for unit testing.
        Returns:
        The db handler reference of this manager.
      • closeDbHandler

        public void closeDbHandler()
        Close DbHandler