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.File
checkWorkspaceContainerSanity(java.lang.String container)
java.io.File
checkWorkspaceDirSanity(java.lang.String container, java.lang.String directory)
void
checkWorkspaceFileSanity(java.lang.String containerName, java.lang.String relativeObjectName)
void
compress(java.lang.String containerName, java.util.List<java.lang.String> folderNames, java.lang.String zipName, java.lang.String outputContainer)
java.lang.String
computeObjectDigest(java.lang.String containerName, java.lang.String objectName, DigestType algo)
compute Object Digest using a defined algorithmvoid
createContainer(java.lang.String containerName)
Creates a containervoid
createFolder(java.lang.String containerName, java.lang.String folderName)
Creates a folder (or a directory) marker depending on the servicevoid
deleteContainer(java.lang.String containerName, boolean recursive)
Deletes everything inside a container recursively.void
deleteFolder(java.lang.String containerName, java.lang.String folderName)
Deletes a folder (or a directory) marker depending on the servicevoid
deleteObject(java.lang.String containerName, java.lang.String objectName)
Deletes a object representing the data at location containerName/objectNameContainerInformation
getContainerInformation(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.Response
getObject(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.JsonNode
getObjectInformation(java.lang.String containerName, java.lang.String objectName)
Retrieves information about an object at location containerName/objectNameint
getWorkspaceFreeSpace()
boolean
isExistingContainer(java.lang.String containerName)
Determines if a container existsboolean
isExistingFolder(java.lang.String containerName, java.lang.String folderName)
Determines if a folder (or a directory) existsboolean
isExistingObject(java.lang.String containerName, java.lang.String objectName)
Determines if an object existsvoid
purgeContainer(java.lang.String containerName)
Deletes the contents of a container at its root path without deleting the containervoid
purgeOldFilesInContainer(java.lang.String containerName, TimeToLive timeToLive)
void
putAtomicObject(java.lang.String containerName, java.lang.String objectName, java.io.InputStream stream, long size)
void
putObject(java.lang.String containerName, java.lang.String objectName, java.io.InputStream stream)
Adds an object representing the data at location containerName/objectNamevoid
uncompressObject(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, ContentAddressableStorageServerException
Description copied from interface:WorkspaceContentAddressableStorage
Creates a container- Specified by:
createContainer
in 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, ContentAddressableStorageServerException
Description copied from interface:WorkspaceContentAddressableStorage
Deletes the contents of a container at its root path without deleting the containerNote: this function will delete everything inside a container recursively.
- Specified by:
purgeContainer
in 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:
purgeOldFilesInContainer
in interfaceWorkspaceContentAddressableStorage
- Throws:
ContentAddressableStorageException
-
deleteContainer
public void deleteContainer(java.lang.String containerName, boolean recursive) throws ContentAddressableStorageNotFoundException, ContentAddressableStorageServerException
Description copied from interface:WorkspaceContentAddressableStorage
Deletes everything inside a container recursively.- Specified by:
deleteContainer
in 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:WorkspaceContentAddressableStorage
Determines if a container exists- Specified by:
isExistingContainer
in interfaceWorkspaceContentAddressableStorage
- Parameters:
containerName
- name of container- Returns:
- boolean type
-
createFolder
public void createFolder(java.lang.String containerName, java.lang.String folderName) throws ContentAddressableStorageNotFoundException, ContentAddressableStorageAlreadyExistException, ContentAddressableStorageServerException
Description copied from interface:WorkspaceContentAddressableStorage
Creates a folder (or a directory) marker depending on the service- Specified by:
createFolder
in 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, ContentAddressableStorageServerException
Description copied from interface:WorkspaceContentAddressableStorage
Deletes a folder (or a directory) marker depending on the service- Specified by:
deleteFolder
in 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:WorkspaceContentAddressableStorage
Determines if a folder (or a directory) exists- Specified by:
isExistingFolder
in 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 ContentAddressableStorageException
Description copied from interface:WorkspaceContentAddressableStorage
Retrieves recursively the uri list of object inside a folder rootFolder/subfolder/- Specified by:
getListUriDigitalObjectFromFolder
in 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 ContentAddressableStorageException
Description copied from interface:WorkspaceContentAddressableStorage
create container: will be identified by GUID and extract objects and push it on the container- Specified by:
uncompressObject
in 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 ContentAddressableStorageException
Description copied from interface:WorkspaceContentAddressableStorage
Adds an object representing the data at location containerName/objectName- Specified by:
putObject
in 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:
putAtomicObject
in 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 ContentAddressableStorageException
Description copied from interface:WorkspaceContentAddressableStorage
Retrieves an object representing the data at location containerName/objectNameWARNING : use this method only if the response has to be consumed right away.
- Specified by:
getObject
in 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 ContentAddressableStorageException
Description copied from interface:WorkspaceContentAddressableStorage
Deletes a object representing the data at location containerName/objectName- Specified by:
deleteObject
in 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:WorkspaceContentAddressableStorage
Determines if an object exists- Specified by:
isExistingObject
in 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 ContentAddressableStorageException
Description copied from interface:WorkspaceContentAddressableStorage
compute Object Digest using a defined algorithm- Specified by:
computeObjectDigest
in 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:WorkspaceContentAddressableStorage
Get container information like capacity- Specified by:
getContainerInformation
in 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 ContentAddressableStorageException
Description copied from interface:WorkspaceContentAddressableStorage
Retrieves information about an object at location containerName/objectName- Specified by:
getObjectInformation
in 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:
getFilesWithParamsFromFolder
in 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.IOException
org.apache.commons.compress.archivers.ArchiveException
-
getWorkspaceFreeSpace
public int getWorkspaceFreeSpace()
-
-