Class 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.CLEAN or GoalType.A2C. Goal executions can be started and stopped manually using the methods start(), stop(), stop(Exception) and upload(boolean). Goal executions can also be executed automatically using the methods executeSync() or executeAsync(), which results in the sequential execution of the above-mentioned methods start(), 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.
    • Field Detail

      • CLASS_EXT

        protected static final String[] CLASS_EXT
        Constant CLASS_EXT
      • JAR_EXT

        protected static final String[] JAR_EXT
        Constant JAR_EXT
      • WAR_EXT

        protected static final String[] WAR_EXT
        Constant WAR_EXT
      • JAR_WAR_EXT

        protected static final String[] JAR_WAR_EXT
        Constant JAR_WAR_EXT
    • Constructor Detail

      • AbstractGoal

        protected AbstractGoal​(GoalType _goal)

        Constructor for AbstractGoal.

        Parameters:
        _goal - a GoalType object.
      • AbstractGoal

        protected AbstractGoal​(GoalType _goal,
                               boolean _monitor_mem)

        Constructor for AbstractGoal.

        Parameters:
        _goal - a GoalType object.
        _monitor_mem - a boolean.
    • Method Detail

      • getId

        public String getId()

        Getter for the field id.

        Returns:
        a String object.
      • getGoalType

        public GoalType getGoalType()

        Getter for the field goalType.

        Returns:
        a GoalType object.
      • setGoalClient

        public void setGoalClient​(GoalClient _client)

        setGoalClient.

        Parameters:
        _client - a GoalClient object.
      • executeAsync

        public final void executeAsync()

        executeAsync.

      • run

        public final void run()

        run.

        Specified by:
        run in interface Runnable
      • getConfiguration

        protected final VulasConfiguration getConfiguration()
        Returns the configuration of this goal execution. If the configuration has not been set before, a new instance of VulasConfiguration is created and returned. As such, the configuration settings of different goal executions can be isolated.
        Returns:
        a VulasConfiguration object.
      • 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 from getConfiguration().
        Returns:
        a GoalContext object.
      • setGoalContext

        public final void setGoalContext​(GoalContext _ctx)

        Setter for the field goalContext.

        Parameters:
        _ctx - a GoalContext object.
      • executeTasks

        protected abstract void executeTasks()
                                      throws Exception
        MUST 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.
      • getResultObject

        protected Object getResultObject()
        Empty implementation.
        Returns:
        a Object object.
      • 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.
        Parameters:
        _e - a Exception object.
        See Also:
        stop()
      • addGoalStats

        public void addGoalStats​(String _prefix,
                                 Map<String,​Long> _stats)

        addGoalStats.

        Parameters:
        _prefix - a String object.
        _stats - a Map object.
      • addGoalStats

        public void addGoalStats​(String _key,
                                 long _val)

        addGoalStats.

        Parameters:
        _key - a String object.
        _val - a long.
      • addGoalStats

        public void addGoalStats​(String _key,
                                 int _val)

        addGoalStats.

        Parameters:
        _key - a String object.
        _val - a int.
      • addGoalStats

        public void addGoalStats​(String _key,
                                 double _val)

        addGoalStats.

        Parameters:
        _key - a String object.
        _val - a double.
      • skipGoalUpload

        protected final void skipGoalUpload()

        skipGoalUpload.

      • upload

        public boolean upload​(boolean _before)
        Uploads the JSON presentation of this goal execution to the Vulas backend. Returns true of everything went fine (upload succeeded or is not necessary), false otherwise.
        Parameters:
        _before - a boolean.
        Returns:
        a boolean.