Package org.eclipse.steady.goals
Class AbstractGoal
- java.lang.Object
-
- org.eclipse.steady.goals.AbstractGoal
-
- All Implemented Interfaces:
Runnable
- Direct Known Subclasses:
AbstractAppGoal,AbstractSpaceGoal
public abstract class AbstractGoal extends Object implements Runnable
Represents the execution of a goal, which is triggered by client components such as the CLI and the Maven plugin. There exist different types of goals, e.g.,GoalType.CLEANorGoalType.A2C. Goal executions can be started and stopped manually using the methodsstart(),stop(),stop(Exception)andupload(boolean). Goal executions can also be executed automatically using the methodsexecuteSync()orexecuteAsync(), which results in the sequential execution of the above-mentioned methodsstart(), etc. Subclasses typically override the methods prepareExecution, executeTasks and cleanAfterExecution. See VULAS-204 in case we run into problems related to special characters in paths.
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractGoal(GoalType _goal)Constructor for AbstractGoal.protectedAbstractGoal(GoalType _goal, boolean _monitor_mem)Constructor for AbstractGoal.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddGoalStats(String _key, double _val)addGoalStats.voidaddGoalStats(String _key, int _val)addGoalStats.voidaddGoalStats(String _key, long _val)addGoalStats.voidaddGoalStats(String _prefix, Map<String,Long> _stats)addGoalStats.protected voidcheckPreconditions()CAN be overridden in subclasses.protected voidcleanAfterExecution()Empty implementation.voidexecuteAsync()executeAsync.voidexecuteSync()executeSync.protected abstract voidexecuteTasks()MUST be overridden in subclasses to implement the goal-specific tasks.protected VulasConfigurationgetConfiguration()Returns the configuration of this goal execution.GoalClientgetGoalClient()getGoalClient.GoalContextgetGoalContext()Returns the context of this goal execution.GoalTypegetGoalType()Getter for the fieldgoalType.StringgetId()Getter for the fieldid.protected ObjectgetResultObject()Empty implementation.protected voidprepareExecution()Cleans the cache of theBackendConnector.voidrun()run.booleanrunsIn(GoalClient _client)Returns true if thisAbstractGoalis executed in the givenGoalClient, false otherwise.AbstractGoalsetConfiguration(VulasConfiguration _c)Setter for the fieldconfiguration.voidsetGoalClient(GoalClient _client)setGoalClient.voidsetGoalContext(GoalContext _ctx)Setter for the fieldgoalContext.voidsetObserver(ExecutionObserver observer)Setter for the fieldobserver.protected voidskipGoalUpload()skipGoalUpload.voidstart()Starts the goal execution.voidstop()Stops the goal execution, i.e., takes the time and stops the monitoring thread (if any).voidstop(Exception _e)Stops the goal execution in response to the provided exception.StringtoJson()Creates a JSON string representing this goal execution.StringtoString()toString.booleanupload(boolean _before)Uploads the JSON presentation of this goal execution to the backend.
-
-
-
Method Detail
-
setObserver
public void setObserver(ExecutionObserver observer)
Setter for the field
observer.- Parameters:
observer- aExecutionObserverobject.
-
getGoalType
public GoalType getGoalType()
Getter for the field
goalType.- Returns:
- a
GoalTypeobject.
-
getGoalClient
public GoalClient getGoalClient()
getGoalClient.
- Returns:
- a
GoalClientobject.
-
setGoalClient
public void setGoalClient(GoalClient _client)
setGoalClient.
- Parameters:
_client- aGoalClientobject.
-
runsIn
public boolean runsIn(GoalClient _client)
Returns true if thisAbstractGoalis executed in the givenGoalClient, false otherwise.- Parameters:
_client- aGoalClientobject.- Returns:
- a boolean.
-
executeAsync
public final void executeAsync()
executeAsync.
-
executeSync
public final void executeSync() throws GoalConfigurationException, GoalExecutionExceptionexecuteSync.
- Throws:
GoalConfigurationException- if any.GoalExecutionException- if any.
-
getConfiguration
protected final VulasConfiguration getConfiguration()
Returns the configuration of this goal execution. If the configuration has not been set before, a new instance ofVulasConfigurationis created and returned. As such, the configuration settings of different goal executions can be isolated.- Returns:
- a
VulasConfigurationobject.
-
setConfiguration
public final AbstractGoal setConfiguration(VulasConfiguration _c)
Setter for the field
configuration.- Parameters:
_c- aVulasConfigurationobject.- Returns:
- a
AbstractGoalobject.
-
getGoalContext
public final GoalContext getGoalContext()
Returns the context of this goal execution. If the context has not been set before, it is constructed by reading tenant, space and app information from the configuration obtained fromgetConfiguration().- Returns:
- a
GoalContextobject.
-
setGoalContext
public final void setGoalContext(GoalContext _ctx)
Setter for the field
goalContext.- Parameters:
_ctx- aGoalContextobject.
-
prepareExecution
protected void prepareExecution() throws GoalConfigurationExceptionCleans the cache of theBackendConnector. CAN be overridden in subclasses to perform additional, goal-specific checks and preparations.- Throws:
GoalConfigurationException- if any.
-
checkPreconditions
protected void checkPreconditions() throws GoalConfigurationExceptionCAN be overridden in subclasses.- Throws:
GoalConfigurationException- if any.
-
executeTasks
protected abstract void executeTasks() throws ExceptionMUST be overridden in subclasses to implement the goal-specific tasks.- Throws:
Exception- if any.
-
cleanAfterExecution
protected void cleanAfterExecution()
Empty implementation. CAN be overridden in subclasses in order to perform goal-specific clean-up.
-
start
public void start() throws GoalConfigurationExceptionStarts the goal execution.- Throws:
GoalConfigurationException- if any.
-
stop
public void stop()
Stops the goal execution, i.e., takes the time and stops the monitoring thread (if any).
-
stop
public void stop(Exception _e)
Stops the goal execution in response to the provided exception.
-
addGoalStats
public void addGoalStats(String _key, long _val)
addGoalStats.
- Parameters:
_key- aStringobject._val- a long.
-
addGoalStats
public void addGoalStats(String _key, int _val)
addGoalStats.
- Parameters:
_key- aStringobject._val- a int.
-
addGoalStats
public void addGoalStats(String _key, double _val)
addGoalStats.
- Parameters:
_key- aStringobject._val- a double.
-
toString
public String toString()
toString.
-
toJson
public String toJson() throws IllegalStateException
Creates a JSON string representing this goal execution.- Returns:
- a
Stringobject. - Throws:
IllegalStateException
-
skipGoalUpload
protected final void skipGoalUpload()
skipGoalUpload.
-
upload
public boolean upload(boolean _before)
Uploads the JSON presentation of this goal execution to the backend. Returns true if everything went fine (upload succeeded or is not necessary), false otherwise.- Parameters:
_before- a boolean.- Returns:
- a boolean.
-
-