Package com.sodius.oslc.server.core
Class FriendRehostingManager
- java.lang.Object
-
- com.sodius.oslc.server.core.FriendRehostingManager
-
public abstract class FriendRehostingManager extends Object
Manages the re-hosting of a friend application.- Since:
- 3.1.1
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
FriendRehostingManager.LogLevel
Available logging levels.static class
FriendRehostingManager.Status
The possible re-hostingTask
s' status.
-
Constructor Summary
Constructors Constructor Description FriendRehostingManager()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
conclude(Task task, Person user)
Concludes a given task by cleaning all temporary data (if thestatus
is eitherFriendRehostingManager.Status.PREVIEWED
orFriendRehostingManager.Status.COMPLETED
and bycommitting
the target friend if thestatus
isFriendRehostingManager.Status.COMPLETED
only.protected abstract void
conclude(Task task, Friend friend)
Removes all temporary data associated with the given task and, if thestatus
isFriendRehostingManager.Status.COMPLETED
, persists the given friend in the storage.static FriendRehostingManager
getInstance()
Returns the current manager instance.Class<? extends PersonService>
getPersonServiceClass()
Convenient method to retrieve the actualPersonService
class implemented by an application.protected abstract Friend
getRehostingFriend(String identifier)
Gets the re-hosting friend from the temporary location.protected abstract List<Task>
getRehostingSubtasks(Task task, URI source, Person user)
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 thesource
context.protected abstract FriendRehostingPreview
getSubtaskPreview(Task subtask, URI source, Person user)
Computes a subtask preview.protected String[]
getSubtasksIds(Task parent)
Convenient method to retrieve the subtasks ids, if any, from a parent task.abstract Optional<Task>
getTask(String identifier)
Gets the re-hostingtask
for a given identifier.protected void
log(FriendRehostingManager.LogLevel level, Task task, String message, Object... args)
Logs a message with a givenLevel
and non-interpolated arguments.protected void
log(Throwable e, Task task, String message)
Convenient method to log anerror
when an exception occurs.protected abstract Map<String,Long>
rehostSubtask(Task subtask, URI originalContext, URI targetContext, Person user)
Performs the actual re-hosting over a subtask.protected abstract void
saveLog(FriendRehostingManager.LogLevel level, Task task, String message)
Saves a Task's log entry.protected abstract void
saveRehostingFriend(Friend friend)
Saves the re-hosting friend into a temporary location.protected abstract void
saveTask(Task task)
Creates (or updates) a task.static void
setInstance(FriendRehostingManager manager)
Replaces the current manager instance with the given one.void
startPreview(URI uri, Friend source, Friend target, Person user)
Starts the (asynchronous) preview of a re-hostingtask
for a given friend.void
startRehost(Task task, Person user)
Starts the re-hosting process on the given task.abstract void
writeLog(Task task, boolean includeSubtasksLogs, OutputStream os)
Writes the task log on a given output stream.
-
-
-
Method Detail
-
getInstance
public static FriendRehostingManager getInstance()
Returns the current manager instance.- Returns:
- the current instance.
- See Also:
setInstance(FriendRehostingManager)
-
setInstance
public static void setInstance(FriendRehostingManager manager)
Replaces the current manager instance with the given one.- Parameters:
manager
- the new manager.
-
getPersonServiceClass
public Class<? extends PersonService> getPersonServiceClass()
Convenient method to retrieve the actualPersonService
class 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
PersonService
class 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 givenLevel
and non-interpolated arguments.- Parameters:
level
- the logging level.task
- the owner task.message
- the non-interpolated message.args
- the arguments to interpolate.
-
log
protected void log(Throwable e, Task task, String message)
Convenient method to log anerror
when an exception occurs.- Parameters:
e
- the occurred exception.task
- the owner task.message
- the heading message.
-
saveTask
protected abstract void saveTask(Task task) throws FriendRehostingException
Creates (or updates) a task. When this method is called to save a subtask for the first time, the extended propertyoslc:order
will 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
protected abstract void saveRehostingFriend(Friend friend) throws FriendRehostingException
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:source
anddcterms:creator
as 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
protected abstract Friend getRehostingFriend(String identifier) throws FriendRehostingException
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, Person user) 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 thesource
context. 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.user
- the executing user.- Returns:
- the set of subtasks required to complete the re-hosting process.
- Throws:
FriendRehostingException
- if retrieving the subtasks fails.
-
getSubtaskPreview
protected abstract FriendRehostingPreview getSubtaskPreview(Task subtask, URI source, Person user) 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.user
- the executing user.- Returns:
- the preview results.
- Throws:
FriendRehostingException
- if preview cannot be computed.
-
startPreview
public void startPreview(URI uri, Friend source, Friend target, Person user) throws FriendRehostingException
Starts the (asynchronous) preview of a re-hostingtask
for a given friend.- Parameters:
uri
- the URI of the service to access the re-hosting task.source
- the original friend definition.target
- the new friend definition.user
- the executing user.- Throws:
FriendRehostingException
- if theTask
cannot be started.NullPointerException
- if any argument is null.
-
getTask
public abstract Optional<Task> getTask(String identifier) throws FriendRehostingException
Gets the re-hostingtask
for 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 theTask
cannot be retrieved.
-
getSubtasksIds
protected String[] getSubtasksIds(Task parent)
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, Person user) throws FriendRehostingException
Performs the actual re-hosting over a subtask.- Parameters:
subtask
- the current subtask.originalContext
- the original context to replace.targetContext
- the new context.user
- the executing user.- Returns:
- the number of failed re-hosted links (values) per artifact (keys).
- Throws:
FriendRehostingException
- if the re-hosting fails.
-
startRehost
public void startRehost(Task task, Person user) throws FriendRehostingException
Starts the re-hosting process on the given task.- Parameters:
task
- the (preview) task to re-host.user
- the executing user.- Throws:
FriendRehostingException
- if theTask
cannot be moved to the re-host phase.NullPointerException
- if any argument is null.
-
conclude
protected abstract void conclude(Task task, Friend friend) throws FriendRehostingException
Removes all temporary data associated with the given task and, if thestatus
isFriendRehostingManager.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
public void conclude(Task task, Person user) throws FriendRehostingException
Concludes a given task by cleaning all temporary data (if thestatus
is eitherFriendRehostingManager.Status.PREVIEWED
orFriendRehostingManager.Status.COMPLETED
and bycommitting
the target friend if thestatus
isFriendRehostingManager.Status.COMPLETED
only.- Parameters:
task
- the given task.user
- the executing user.- Throws:
FriendRehostingException
- if theTask
cannot be completed.
-
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.
-
-