Package com.sodius.oslc.server.core
Class FriendRehostingManager
java.lang.Object
com.sodius.oslc.server.core.FriendRehostingManager
Manages the re-hosting of a friend application.
- Since:
- 3.1.1
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumAvailable logging levels.static enumThe possible re-hostingTasks' status. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidConcludes a given task, for thecurrent user, by cleaning all temporary data (if thestatusis eitherFriendRehostingManager.Status.PREVIEWEDorFriendRehostingManager.Status.COMPLETEDand bycommittingthe target friend if thestatusisFriendRehostingManager.Status.COMPLETEDonly.protected abstract voidRemoves all temporary data associated with the given task and, if thestatusisFriendRehostingManager.Status.COMPLETED, persists the given friend in the storage.static FriendRehostingManagerReturns the current manager instance.Class<? extends PersonService>Convenient method to retrieve the actualPersonServiceclass implemented by an application.protected abstract FriendgetRehostingFriend(String identifier) Gets the re-hosting friend from the temporary location.getRehostingSubtasks(Task task, URI source) Determines the subtasks required to complete the re-hosting process, typically one per impacted project which means: an OSLC-enabled project associated with at least one remote project having thesourcecontext.protected abstract FriendRehostingPreviewgetSubtaskPreview(Task subtask, URI source) Computes a subtask preview.protected String[]getSubtasksIds(Task parent) Convenient method to retrieve the subtasks ids, if any, from a parent task.Gets the re-hostingtaskfor a given identifier.protected voidlog(FriendRehostingManager.LogLevel level, Task task, String message, Object... args) Logs a message with a givenLeveland non-interpolated arguments.protected voidConvenient method to log anerrorwhen an exception occurs.rehostSubtask(Task subtask, URI originalContext, URI targetContext) Performs the actual re-hosting over a subtask and thecurrent user.protected abstract voidsaveLog(FriendRehostingManager.LogLevel level, Task task, String message) Saves a Task's log entry.protected abstract voidsaveRehostingFriend(Friend friend) Saves the re-hosting friend into a temporary location.protected abstract voidCreates (or updates) a task.static voidsetInstance(FriendRehostingManager manager) Replaces the current manager instance with the given one.voidstartPreview(URI uri, Friend source, Friend target) Starts the (asynchronous) preview of a re-hostingtaskfor a given friend and thecurrent user.voidstartRehost(Task task) Starts the re-hosting process on the given task and for thecurrent user.abstract voidwriteLog(Task task, boolean includeSubtasksLogs, OutputStream os) Writes the task log on a given output stream.
-
Constructor Details
-
FriendRehostingManager
public FriendRehostingManager()
-
-
Method Details
-
getInstance
Returns the current manager instance.- Returns:
- the current instance.
- See Also:
-
setInstance
Replaces the current manager instance with the given one.- Parameters:
manager- the new manager.
-
getPersonServiceClass
Convenient method to retrieve the actualPersonServiceclass implemented by an application. This method is used to create URIs to the final Person service which can change the service path.- Returns:
- the actual
PersonServiceclass with the real path to the service end-point.
-
saveLog
protected abstract void saveLog(FriendRehostingManager.LogLevel level, Task task, String message) throws FriendRehostingException Saves a Task's log entry. Implementation of this class MUST keep apart the logging messages of each task.- Parameters:
level- the log level.task- the owner task.message- the message to log.- Throws:
FriendRehostingException- if saving fails.
-
log
protected void log(FriendRehostingManager.LogLevel level, Task task, String message, Object... args) Logs a message with a givenLeveland non-interpolated arguments.- Parameters:
level- the logging level.task- the owner task.message- the non-interpolated message.args- the arguments to interpolate.
-
log
Convenient method to log anerrorwhen an exception occurs.- Parameters:
e- the occurred exception.task- the owner task.message- the heading message.
-
saveTask
Creates (or updates) a task. When this method is called to save a subtask for the first time, the extended propertyoslc:orderwill be present so implementations can take advantage of it and use it to determine the proper order when thesubtasks are retrieved.- Parameters:
task- the task to save.- Throws:
FriendRehostingException- if saving fails.
-
saveRehostingFriend
Saves the re-hosting friend into a temporary location. The entry MUST be removed when the process isconcluded. Implementations MUST care about saving the extended propertiesdcterms:sourceanddcterms:creatoras well as making sure the friend will be accessible by its identifier (which is the same as the re-hosting task process).- Parameters:
friend- the re-hosting friend.- Throws:
FriendRehostingException- if saving fails.
-
getRehostingFriend
Gets the re-hosting friend from the temporary location.- Parameters:
identifier- the friend (re-hosting task) identifier.- Returns:
- the friend being re-hosted
- Throws:
FriendRehostingException- if retrieving the friend fails.
-
getRehostingSubtasks
protected abstract List<Task> getRehostingSubtasks(Task task, URI source) throws FriendRehostingException Determines the subtasks required to complete the re-hosting process, typically one per impacted project which means: an OSLC-enabled project associated with at least one remote project having thesourcecontext. Implementations can include additional subtask to change the remote project associations, for example, or to perform any GC-related duty.Implementations MUST fill only the title and description properties and SHOULD use the project/container title (or key) as the subtask title. Subtasks MUST come in the desired execution order and the
getTask(String)method implementation MUST retrieve them in the same order.- Parameters:
task- the main re-hosting task.source- the original context URI.- Returns:
- the set of subtasks required to complete the re-hosting process.
- Throws:
FriendRehostingException- if retrieving the subtasks fails.- Since:
- 4.0.0
-
getSubtaskPreview
protected abstract FriendRehostingPreview getSubtaskPreview(Task subtask, URI source) throws FriendRehostingException Computes a subtask preview. Implementations MUST determine how many links in how many artifacts are impacted. It is up to the implementation to decide whether to keep track of these artifacts/links ids for a possible faster re-hosting phase or not.- Parameters:
subtask- the current subtask.source- the original context URI.- Returns:
- the preview results.
- Throws:
FriendRehostingException- if preview cannot be computed.- Since:
- 4.0.0
-
startPreview
Starts the (asynchronous) preview of a re-hostingtaskfor a given friend and thecurrent user.- Parameters:
uri- the URI of the service to access the re-hosting task.source- the original friend definition.target- the new friend definition.- Throws:
FriendRehostingException- if theTaskcannot be started.NullPointerException- if any argument is null.- Since:
- 4.0.0
-
getTask
Gets the re-hostingtaskfor a given identifier.- Parameters:
identifier- the task's identifier.- Returns:
- an empty optional if no re-hosting process is undergoing; the contained task reference otherwise.
- Throws:
FriendRehostingException- if theTaskcannot be retrieved.
-
getSubtasksIds
Convenient method to retrieve the subtasks ids, if any, from a parent task.- Parameters:
parent- the parent task.- Returns:
- identifiers of the subtasks.
-
rehostSubtask
protected abstract Map<String,Long> rehostSubtask(Task subtask, URI originalContext, URI targetContext) throws FriendRehostingException Performs the actual re-hosting over a subtask and thecurrent user.- Parameters:
subtask- the current subtask.originalContext- the original context to replace.targetContext- the new context.- Returns:
- the number of failed re-hosted links (values) per artifact (keys).
- Throws:
FriendRehostingException- if the re-hosting fails.- Since:
- 4.0.0
-
startRehost
Starts the re-hosting process on the given task and for thecurrent user.- Parameters:
task- the (preview) task to re-host.- Throws:
FriendRehostingException- if theTaskcannot be moved to the re-host phase.NullPointerException- if any argument is null.- Since:
- 4.0.0
-
conclude
Removes all temporary data associated with the given task and, if thestatusisFriendRehostingManager.Status.COMPLETED, persists the given friend in the storage. Implementations MUST remove the re-hosting friend from the temporary location and SHOULD use the same DB transaction, if applicable, to commit all DB data at once.- Parameters:
task- the given task.friend- the (updated) re-hosting friend.- Throws:
FriendRehostingException- if task cannot be concluded.
-
conclude
Concludes a given task, for thecurrent user, by cleaning all temporary data (if thestatusis eitherFriendRehostingManager.Status.PREVIEWEDorFriendRehostingManager.Status.COMPLETEDand bycommittingthe target friend if thestatusisFriendRehostingManager.Status.COMPLETEDonly.- Parameters:
task- the given task.- Throws:
FriendRehostingException- if theTaskcannot be completed.- Since:
- 4.0.0
-
writeLog
public abstract void writeLog(Task task, boolean includeSubtasksLogs, OutputStream os) throws IOException, FriendRehostingException Writes the task log on a given output stream.- Parameters:
task- the given task.includeSubtasksLogs- whether to include subtasks logs.os- the given output stream.- Throws:
IOException- if some IO exception occurs.FriendRehostingException- if the writing cannot be completed by any other reason.
-