Package fr.gouv.vitam.workspace.common
Class WorkspaceFileSystem
- java.lang.Object
-
- fr.gouv.vitam.workspace.common.WorkspaceFileSystem
-
- All Implemented Interfaces:
WorkspaceContentAddressableStorage
public class WorkspaceFileSystem extends java.lang.Object implements WorkspaceContentAddressableStorage
Workspace Filesystem implementation
-
-
Constructor Summary
Constructors Constructor Description WorkspaceFileSystem(StorageConfiguration configuration)Default constructor Define the root of workspace with the storagePath property from configuration
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.io.FilecheckWorkspaceContainerSanity(java.lang.String container)java.io.FilecheckWorkspaceDirSanity(java.lang.String container, java.lang.String directory)voidcheckWorkspaceFileSanity(java.lang.String containerName, java.lang.String relativeObjectName)voidcompress(java.lang.String containerName, java.util.List<java.lang.String> folderNames, java.lang.String zipName, java.lang.String outputContainer)java.lang.StringcomputeObjectDigest(java.lang.String containerName, java.lang.String objectName, DigestType algo)compute Object Digest using a defined algorithmvoidcreateContainer(java.lang.String containerName)Creates a containervoidcreateFolder(java.lang.String containerName, java.lang.String folderName)Creates a folder (or a directory) marker depending on the servicevoiddeleteContainer(java.lang.String containerName, boolean recursive)Deletes everything inside a container recursively.voiddeleteFolder(java.lang.String containerName, java.lang.String folderName)Deletes a folder (or a directory) marker depending on the servicevoiddeleteObject(java.lang.String containerName, java.lang.String objectName)Deletes a object representing the data at location containerName/objectNameContainerInformationgetContainerInformation(java.lang.String containerName)Get container information like capacityjava.util.Map<java.lang.String,FileParams>getFilesWithParamsFromFolder(java.lang.String containerName, java.lang.String folderName)This method get all files in folder and return a map with the uri as a key and the value is a FileParams that contains whatever it needs.java.util.List<java.net.URI>getListUriDigitalObjectFromFolder(java.lang.String containerName, java.lang.String folderName)Retrieves recursively the uri list of object inside a folder rootFolder/subfolder/javax.ws.rs.core.ResponsegetObject(java.lang.String containerName, java.lang.String objectName, java.lang.Long chunkOffset, java.lang.Long maxChunkSize)Retrieves an object representing the data at location containerName/objectNamecom.fasterxml.jackson.databind.JsonNodegetObjectInformation(java.lang.String containerName, java.lang.String objectName)Retrieves information about an object at location containerName/objectNameintgetWorkspaceFreeSpace()booleanisExistingContainer(java.lang.String containerName)Determines if a container existsbooleanisExistingFolder(java.lang.String containerName, java.lang.String folderName)Determines if a folder (or a directory) existsbooleanisExistingObject(java.lang.String containerName, java.lang.String objectName)Determines if an object existsvoidpurgeContainer(java.lang.String containerName)Deletes the contents of a container at its root path without deleting the containervoidpurgeOldFilesInContainer(java.lang.String containerName, TimeToLive timeToLive)voidputAtomicObject(java.lang.String containerName, java.lang.String objectName, java.io.InputStream stream, long size)voidputObject(java.lang.String containerName, java.lang.String objectName, java.io.InputStream stream)Adds an object representing the data at location containerName/objectNamevoiduncompressObject(java.lang.String containerName, java.lang.String folderName, java.lang.String archiveMimeType, java.io.InputStream inputStreamObject)create container: will be identified by GUID and extract objects and push it on the container
-
-
-
Constructor Detail
-
WorkspaceFileSystem
public WorkspaceFileSystem(StorageConfiguration configuration) throws java.io.IOException
Default constructor Define the root of workspace with the storagePath property from configuration- Parameters:
configuration- the configuration, just StoragePath property is required- Throws:
java.io.IOException- when error occurs to create root directory
-
-
Method Detail
-
checkWorkspaceContainerSanity
public java.io.File checkWorkspaceContainerSanity(java.lang.String container) throws IllegalPathException- Throws:
IllegalPathException
-
checkWorkspaceDirSanity
public java.io.File checkWorkspaceDirSanity(java.lang.String container, java.lang.String directory) throws IllegalPathException- Throws:
IllegalPathException
-
checkWorkspaceFileSanity
public void checkWorkspaceFileSanity(java.lang.String containerName, java.lang.String relativeObjectName) throws IllegalPathException- Throws:
IllegalPathException
-
createContainer
public void createContainer(java.lang.String containerName) throws ContentAddressableStorageAlreadyExistException, ContentAddressableStorageServerExceptionDescription copied from interface:WorkspaceContentAddressableStorageCreates a container- Specified by:
createContainerin interfaceWorkspaceContentAddressableStorage- Parameters:
containerName- name of container to create- Throws:
ContentAddressableStorageAlreadyExistException- Thrown when creating a container while it (containerName) already existsContentAddressableStorageServerException- Thrown when internal server error happens
-
purgeContainer
public void purgeContainer(java.lang.String containerName) throws ContentAddressableStorageNotFoundException, ContentAddressableStorageServerExceptionDescription copied from interface:WorkspaceContentAddressableStorageDeletes the contents of a container at its root path without deleting the containerNote: this function will delete everything inside a container recursively.
- Specified by:
purgeContainerin interfaceWorkspaceContentAddressableStorage- Parameters:
containerName- name of container to purge- Throws:
ContentAddressableStorageNotFoundException- Thrown when the container cannot be located.ContentAddressableStorageServerException- Thrown when internal server error happens
-
purgeOldFilesInContainer
public void purgeOldFilesInContainer(java.lang.String containerName, TimeToLive timeToLive) throws ContentAddressableStorageException- Specified by:
purgeOldFilesInContainerin interfaceWorkspaceContentAddressableStorage- Throws:
ContentAddressableStorageException
-
deleteContainer
public void deleteContainer(java.lang.String containerName, boolean recursive) throws ContentAddressableStorageNotFoundException, ContentAddressableStorageServerExceptionDescription copied from interface:WorkspaceContentAddressableStorageDeletes everything inside a container recursively.- Specified by:
deleteContainerin interfaceWorkspaceContentAddressableStorage- Parameters:
containerName- name of the container to deleterecursive- false : deletes a container if it is empty, true : deletes everything recursively- Throws:
ContentAddressableStorageNotFoundException- Thrown when the container cannot be located.ContentAddressableStorageServerException- Thrown when internal server error happens
-
isExistingContainer
public boolean isExistingContainer(java.lang.String containerName)
Description copied from interface:WorkspaceContentAddressableStorageDetermines if a container exists- Specified by:
isExistingContainerin interfaceWorkspaceContentAddressableStorage- Parameters:
containerName- name of container- Returns:
- boolean type
-
createFolder
public void createFolder(java.lang.String containerName, java.lang.String folderName) throws ContentAddressableStorageNotFoundException, ContentAddressableStorageAlreadyExistException, ContentAddressableStorageServerExceptionDescription copied from interface:WorkspaceContentAddressableStorageCreates a folder (or a directory) marker depending on the service- Specified by:
createFolderin interfaceWorkspaceContentAddressableStorage- Parameters:
containerName- container to create the directory infolderName- full path to the folder (or directory)- Throws:
ContentAddressableStorageNotFoundException- Thrown when the container cannot be located.ContentAddressableStorageAlreadyExistException- Thrown when creating a directory while it already existsContentAddressableStorageServerException- Thrown when internal server error happens
-
deleteFolder
public void deleteFolder(java.lang.String containerName, java.lang.String folderName) throws ContentAddressableStorageNotFoundException, ContentAddressableStorageServerExceptionDescription copied from interface:WorkspaceContentAddressableStorageDeletes a folder (or a directory) marker depending on the service- Specified by:
deleteFolderin interfaceWorkspaceContentAddressableStorage- Parameters:
containerName- container to delete the folder fromfolderName- full path to the folder to delete- Throws:
ContentAddressableStorageNotFoundException- Thrown when the directory cannot be located.ContentAddressableStorageServerException- Thrown when internal server error happens
-
isExistingFolder
public boolean isExistingFolder(java.lang.String containerName, java.lang.String folderName)Description copied from interface:WorkspaceContentAddressableStorageDetermines if a folder (or a directory) exists- Specified by:
isExistingFolderin interfaceWorkspaceContentAddressableStorage- Parameters:
containerName- container where the folder residesfolderName- full path to the folder- Returns:
- boolean type
-
getListUriDigitalObjectFromFolder
public java.util.List<java.net.URI> getListUriDigitalObjectFromFolder(java.lang.String containerName, java.lang.String folderName) throws ContentAddressableStorageExceptionDescription copied from interface:WorkspaceContentAddressableStorageRetrieves recursively the uri list of object inside a folder rootFolder/subfolder/- Specified by:
getListUriDigitalObjectFromFolderin interfaceWorkspaceContentAddressableStorage- Parameters:
containerName- not null allowed container where this exists.folderName- not null allowed fully qualified folder name relative to the container.- Returns:
- a list of URI
- Throws:
ContentAddressableStorageNotFoundException- Thrown when the container cannot be located.ContentAddressableStorageException- Thrown when get action failed due some other failure
-
uncompressObject
public void uncompressObject(java.lang.String containerName, java.lang.String folderName, java.lang.String archiveMimeType, java.io.InputStream inputStreamObject) throws ContentAddressableStorageExceptionDescription copied from interface:WorkspaceContentAddressableStoragecreate container: will be identified by GUID and extract objects and push it on the container- Specified by:
uncompressObjectin interfaceWorkspaceContentAddressableStorage- Parameters:
containerName- : the container name (will be Guid created in ingest module)folderName- : the folder namearchiveMimeType- : the archive type (zip, tar, tar.gz, tar.bz2)inputStreamObject- : SIP input stream- Throws:
ContentAddressableStorageNotFoundException- Thrown when the container cannot be locatedContentAddressableStorageAlreadyExistException- Thrown when folder existsContentAddressableStorageServerException- Thrown when internal server error happensContentAddressableStorageException- Thrown when get action failed due some other failureContentAddressableStorageCompressedFileException- Thrown when the file is not a zip or an empty zip
-
putObject
public void putObject(java.lang.String containerName, java.lang.String objectName, java.io.InputStream stream) throws ContentAddressableStorageExceptionDescription copied from interface:WorkspaceContentAddressableStorageAdds an object representing the data at location containerName/objectName- Specified by:
putObjectin interfaceWorkspaceContentAddressableStorage- Parameters:
containerName- container to place the object.objectName- fully qualified object name relative to the container.stream- the data- Throws:
ContentAddressableStorageNotFoundException- Thrown when the container cannot be located.ContentAddressableStorageException- Thrown when put action failed due some other failureContentAddressableStorageAlreadyExistException- Thrown when object creating exists
-
putAtomicObject
public void putAtomicObject(java.lang.String containerName, java.lang.String objectName, java.io.InputStream stream, long size) throws ContentAddressableStorageException- Specified by:
putAtomicObjectin interfaceWorkspaceContentAddressableStorage- Throws:
ContentAddressableStorageException
-
getObject
public javax.ws.rs.core.Response getObject(java.lang.String containerName, java.lang.String objectName, java.lang.Long chunkOffset, java.lang.Long maxChunkSize) throws ContentAddressableStorageExceptionDescription copied from interface:WorkspaceContentAddressableStorageRetrieves an object representing the data at location containerName/objectNameWARNING : use this method only if the response has to be consumed right away.
- Specified by:
getObjectin interfaceWorkspaceContentAddressableStorage- Parameters:
containerName- container where this exists.objectName- fully qualified name relative to the container.- Returns:
- the object you intended to receive
- Throws:
ContentAddressableStorageNotFoundException- Thrown when the container cannot be located.ContentAddressableStorageException- Thrown when get action failed due some other failureContentAddressableStorageAlreadyExistException- Thrown when object creating exists
-
deleteObject
public void deleteObject(java.lang.String containerName, java.lang.String objectName) throws ContentAddressableStorageExceptionDescription copied from interface:WorkspaceContentAddressableStorageDeletes a object representing the data at location containerName/objectName- Specified by:
deleteObjectin interfaceWorkspaceContentAddressableStorage- Parameters:
containerName- container where this exists.objectName- fully qualified name relative to the container.- Throws:
ContentAddressableStorageNotFoundException- Thrown when the container cannot be located or the blob cannot be located in the container.ContentAddressableStorageException- Thrown when get action failed due some other failure
-
isExistingObject
public boolean isExistingObject(java.lang.String containerName, java.lang.String objectName)Description copied from interface:WorkspaceContentAddressableStorageDetermines if an object exists- Specified by:
isExistingObjectin interfaceWorkspaceContentAddressableStorage- Parameters:
containerName- container where the object residesobjectName- fully qualified name relative to the container.- Returns:
- boolean type
-
computeObjectDigest
public java.lang.String computeObjectDigest(java.lang.String containerName, java.lang.String objectName, DigestType algo) throws ContentAddressableStorageExceptionDescription copied from interface:WorkspaceContentAddressableStoragecompute Object Digest using a defined algorithm- Specified by:
computeObjectDigestin interfaceWorkspaceContentAddressableStorage- Parameters:
containerName- container where this exists.objectName- fully qualified name relative to the container.algo- Digest algo- Returns:
- the digest object as String
- Throws:
ContentAddressableStorageNotFoundException- Thrown when the container or the object cannot be locatedContentAddressableStorageServerException- Thrown when internal server error happensContentAddressableStorageException- Thrown when put action failed due some other failure
-
getContainerInformation
public ContainerInformation getContainerInformation(java.lang.String containerName) throws ContentAddressableStorageNotFoundException, ContentAddressableStorageServerException
Description copied from interface:WorkspaceContentAddressableStorageGet container information like capacity- Specified by:
getContainerInformationin interfaceWorkspaceContentAddressableStorage- Parameters:
containerName- the container name- Returns:
- container information like usableSpace
- Throws:
ContentAddressableStorageNotFoundException- thrown when storage is not available or container does not existContentAddressableStorageServerException
-
getObjectInformation
public com.fasterxml.jackson.databind.JsonNode getObjectInformation(java.lang.String containerName, java.lang.String objectName) throws ContentAddressableStorageExceptionDescription copied from interface:WorkspaceContentAddressableStorageRetrieves information about an object at location containerName/objectName- Specified by:
getObjectInformationin interfaceWorkspaceContentAddressableStorage- Parameters:
containerName- container where the object is.objectName- fully qualified name relative to the container.- Returns:
- the object informations as a JsonNode object
- Throws:
ContentAddressableStorageNotFoundException- Thrown when the container cannot be located.ContentAddressableStorageException- Thrown when get action failed due some other failure
-
getFilesWithParamsFromFolder
public java.util.Map<java.lang.String,FileParams> getFilesWithParamsFromFolder(java.lang.String containerName, java.lang.String folderName) throws ContentAddressableStorageException
This method get all files in folder and return a map with the uri as a key and the value is a FileParams that contains whatever it needs. This method can have a huge usage of memory so extract only useful data in callable clients.- Specified by:
getFilesWithParamsFromFolderin interfaceWorkspaceContentAddressableStorage- Parameters:
containerName-folderName-- Returns:
- Throws:
ContentAddressableStorageException
-
compress
public void compress(java.lang.String containerName, java.util.List<java.lang.String> folderNames, java.lang.String zipName, java.lang.String outputContainer) throws java.io.IOException, org.apache.commons.compress.archivers.ArchiveException- Parameters:
containerName- name of the containerfolderNames- list of file or directory to archivezipName- name of the archive fileoutputContainer-- Throws:
java.io.IOExceptionorg.apache.commons.compress.archivers.ArchiveException
-
getWorkspaceFreeSpace
public int getWorkspaceFreeSpace()
-
-