public class FileSystemLogRepository extends Object implements ExecutionLogRepository
├ index.json ├ org_fenixedu_bennu_scheduler_example_ExampleTask │ ├── 4ea3e6 │ │ └── e0f643 │ │ └── 4cc7b2 │ │ └── 381e01 │ │ └── 4ea6f7 │ │ └── 1d │ │ ├── execution.json │ │ ├── files │ │ │ ├── 02bbcba853c0c09a8df49feaf6799842 │ │ └── outputIn the root of the repository, an
index.json file contains the latest execution id for every different task.
For every execution, a set of folders is generated based on the execution's id, dispersing the id among multiple
sub-directories (in this case, each sub-directory has 6-character names, meaning the repository is configured with a dispersion
factor of 6).
Inside each execution's folder, there are three main components:
execution.json file, containing the JSON for the associated ExecutionLog, as well as the id for the
previous execution of this task. This effectively creates a linked-list of executions with O(1) insertion complexity.output file, containing the task log, if it is created by the task.files folder, containing all the files added to by the task during its execution. To prevent path-traversal
attacks, the filename is hashed.| Constructor and Description |
|---|
FileSystemLogRepository(int dispersionFactor)
Creates a new
FileSystemLogRepository with the given dispersion factor, and the default logs path. |
FileSystemLogRepository(String basePath,
int dispersionFactor)
Creates a new
FileSystemLogRepository with the given dispersion factor, and the given base path. |
| Modifier and Type | Method and Description |
|---|---|
void |
appendTaskLog(ExecutionLog log,
String text)
Appends the given text to the task log for the given execution.
|
Stream<ExecutionLog> |
executionsFor(String taskName,
Optional<String> start,
int max)
Returns a
Stream containing the execution logs for the given task, up to max elements. |
Optional<byte[]> |
getFile(String taskName,
String id,
String fileName)
Retrieves the file with the given name, generated by the execution of the given task with the given ID, if it is found.
|
Optional<ExecutionLog> |
getLog(String taskName,
String id)
Returns the
ExecutionLog for the given task execution, by task name and execution id, if it exists in the
repository. |
Optional<String> |
getTaskLog(String taskName,
String id)
Returns the log generated by CronTask's
taskLog method, from the given task with the given execution id, if it is
present on the repository. |
Stream<ExecutionLog> |
latest()
Returns the latest execution of every task that has been stored in this repository.
|
void |
newExecution(ExecutionLog log)
Stores a new execution of a given task.
|
void |
setBasePath(String basePath) |
void |
storeFile(ExecutionLog log,
String fileName,
byte[] contents,
boolean append)
Stores the given file to the task execution related to the given
ExecutionLog. |
void |
update(ExecutionLog log)
Stores the updated version of the task log for the given execution.
|
public FileSystemLogRepository(String basePath, int dispersionFactor)
FileSystemLogRepository with the given dispersion factor, and the given base path.
The dispersion factor is used to determine the maximum length that each execution's folder name has, thus dispersing the
log files in a file tree, instead of a flat list.basePath - The base path to use to store the logsdispersionFactor - The dispersion factor to be usedpublic FileSystemLogRepository(int dispersionFactor)
FileSystemLogRepository with the given dispersion factor, and the default logs path.dispersionFactor - The dispersion factor to be usedpublic void setBasePath(String basePath)
public void update(ExecutionLog log)
update in interface ExecutionLogRepositorylog - The execution log to storepublic void newExecution(ExecutionLog log)
ExecutionLogRepository.update(ExecutionLog) method, in that it may
used to update the repository's index.newExecution in interface ExecutionLogRepositorylog - The new execution log to storepublic void appendTaskLog(ExecutionLog log, String text)
appendTaskLog in interface ExecutionLogRepositorylog - The execution log for which the text is to be appendedtext - The text to be appendedpublic void storeFile(ExecutionLog log, String fileName, byte[] contents, boolean append)
ExecutionLog.storeFile in interface ExecutionLogRepositorylog - The execution log for which this file is to be storedfileName - The name of the file to storecontents - The contents to storeappend - Whether the contents should be appended or replace the potentially existing filepublic Stream<ExecutionLog> latest()
latest in interface ExecutionLogRepositorypublic Stream<ExecutionLog> executionsFor(String taskName, Optional<String> start, int max)
Stream containing the execution logs for the given task, up to max elements. If a start id is
provided, the logs will start with the one with the given id, otherwise, the latest executions are returned.executionsFor in interface ExecutionLogRepositorytaskName - The name of the task for which to retrieve the logsstart - The optional task id for which to start returning the logs. If empty, the latest executions are returned, if
invalid, an empty stream is returned.max - The maximum number of elements to returnmax latest executions for the given taskpublic Optional<String> getTaskLog(String taskName, String id)
taskLog method, from the given task with the given execution id, if it is
present on the repository. Otherwise, returns an empty Optional.getTaskLog in interface ExecutionLogRepositorytaskName - The name of the task for which to retrieve the logid - The identifier of the execution for which to retrieve the logpublic Optional<byte[]> getFile(String taskName, String id, String fileName)
Optional.getFile in interface ExecutionLogRepositorytaskName - The name of the task for which to retrieve the fileid - The identifier of the execution for which to retrieve the filefileName - The filename to be retrievedpublic Optional<ExecutionLog> getLog(String taskName, String id)
ExecutionLog for the given task execution, by task name and execution id, if it exists in the
repository. Otherwise, returns an empty Optional.getLog in interface ExecutionLogRepositorytaskName - The name of the task for which to retrieve the logid - The identifier of the execution for which to retrieve the logCopyright © 2018 FenixEdu. All rights reserved.