Class DefaultTaskExecutionContext

java.lang.Object
com.xebialabs.xlrelease.domain.tasks.plugin.DefaultTaskExecutionContext
All Implemented Interfaces:
com.xebialabs.xlrelease.osgi.api.tasks.TaskExecutionContext

public class DefaultTaskExecutionContext extends Object implements com.xebialabs.xlrelease.osgi.api.tasks.TaskExecutionContext
The host's TaskExecutionContext, backed by a PluginTask and its configuration.

Reads come straight from the configuration CI; writes are buffered rather than applied to the CI. That is not an optimisation - the CI a worker holds is a detached copy, and the only supported way to persist task changes is to hand results back through the release actor (which ScriptResultsService then applies). Writing directly here would appear to work and silently lose data.

Most methods are not thread-safe, matching the interface's contract. The output streams, log(String) and isAborted() are the documented exceptions, because output is normally produced by whatever is doing the work rather than by the thread that called execute.

Secrets are not pre-decrypted. A password property is handed out as a Secret whose reveal() decrypts on demand and records the value in this execution's SecretRegistry, which is also what the output streams mask against - so anything an extension actually read is masked, at whatever depth it was found.

  • Constructor Details

    • DefaultTaskExecutionContext

      public DefaultTaskExecutionContext(com.xebialabs.xlrelease.domain.PluginTask task, boolean resume)
  • Method Details

    • getTaskId

      public String getTaskId()
      Specified by:
      getTaskId in interface com.xebialabs.xlrelease.osgi.api.tasks.TaskExecutionContext
    • getReleaseId

      public String getReleaseId()
      Specified by:
      getReleaseId in interface com.xebialabs.xlrelease.osgi.api.tasks.TaskExecutionContext
    • getTaskType

      public String getTaskType()
      Specified by:
      getTaskType in interface com.xebialabs.xlrelease.osgi.api.tasks.TaskExecutionContext
    • isResume

      public boolean isResume()
      Specified by:
      isResume in interface com.xebialabs.xlrelease.osgi.api.tasks.TaskExecutionContext
    • getConfiguration

      public com.xebialabs.xlrelease.domain.PluginTaskConfiguration getConfiguration()
      Specified by:
      getConfiguration in interface com.xebialabs.xlrelease.osgi.api.tasks.TaskExecutionContext
    • bind

      public <T> T bind(Class<T> recordType)
      Specified by:
      bind in interface com.xebialabs.xlrelease.osgi.api.tasks.TaskExecutionContext
    • getInputProperty

      public <T> Optional<T> getInputProperty(String name, Class<T> type)
      Specified by:
      getInputProperty in interface com.xebialabs.xlrelease.osgi.api.tasks.TaskExecutionContext
    • secret

      public Optional<com.xebialabs.xlrelease.osgi.api.tasks.Secret> secret(String name)
      Specified by:
      secret in interface com.xebialabs.xlrelease.osgi.api.tasks.TaskExecutionContext
    • secret

      public Optional<com.xebialabs.xlrelease.osgi.api.tasks.Secret> secret(com.xebialabs.deployit.plugin.api.udm.ConfigurationItem ci, String name)
      Specified by:
      secret in interface com.xebialabs.xlrelease.osgi.api.tasks.TaskExecutionContext
    • maskMessage

      public String maskMessage(String message)
      message with every secret revealed in this execution masked. For text that leaves the worker outside the output streams, such as a failure message.
    • secretRegistry

      public com.xebialabs.xlrelease.osgi.api.tasks.SecretRegistry secretRegistry()
      The secrets revealed during this execution, for the worker to install as ambient while the extension runs so that record binding - which has no other route to this context - registers what it reveals for masking.
    • setOutputs

      public <T> void setOutputs(T record)
      Specified by:
      setOutputs in interface com.xebialabs.xlrelease.osgi.api.tasks.TaskExecutionContext
    • setOutputProperty

      public void setOutputProperty(String name, Object value)
      Specified by:
      setOutputProperty in interface com.xebialabs.xlrelease.osgi.api.tasks.TaskExecutionContext
    • getOutputProperty

      public <T> Optional<T> getOutputProperty(String name, Class<T> type)
      Specified by:
      getOutputProperty in interface com.xebialabs.xlrelease.osgi.api.tasks.TaskExecutionContext
    • stdout

      public com.xebialabs.xlrelease.osgi.api.tasks.TaskOutput stdout()
      Specified by:
      stdout in interface com.xebialabs.xlrelease.osgi.api.tasks.TaskExecutionContext
    • stderr

      public com.xebialabs.xlrelease.osgi.api.tasks.TaskOutput stderr()
      Specified by:
      stderr in interface com.xebialabs.xlrelease.osgi.api.tasks.TaskExecutionContext
    • log

      public void log(String message)
      Specified by:
      log in interface com.xebialabs.xlrelease.osgi.api.tasks.TaskExecutionContext
    • isAborted

      public boolean isAborted()
      A plain read of the volatile flag, deliberately not consulting the thread's interrupted status: the interface promises this is thread-safe and, once true, stays true. An interrupt is neither - it is invisible to a thread the extension started itself, and is cleared by any catch (InterruptedException) along the way.
      Specified by:
      isAborted in interface com.xebialabs.xlrelease.osgi.api.tasks.TaskExecutionContext
    • markAborted

      public void markAborted()
      Marks this execution as aborted, so an extension polling isAborted() - from any thread - sees it turn true and can return promptly.

      Called by PluginTaskAbortRegistry when a release author aborts the task. One-way: nothing clears it, which is what lets the interface promise that it stays true.

    • setLogSink

      public void setLogSink(PluginTaskLogSink sink)
      For the worker to wire the live sink before the extension runs.
    • closeOutputs

      public void closeOutputs()
      Flushes and closes both output streams, so a final line with no trailing newline is not lost.

      Called by the worker on every path once execute has returned or thrown.

    • setStatusLine

      public void setStatusLine(String statusLine)
      Specified by:
      setStatusLine in interface com.xebialabs.xlrelease.osgi.api.tasks.TaskExecutionContext
    • addComment

      public void addComment(String markdown)
      Specified by:
      addComment in interface com.xebialabs.xlrelease.osgi.api.tasks.TaskExecutionContext
    • getComments

      public List<com.xebialabs.xlrelease.osgi.api.tasks.TaskComment> getComments()
      Specified by:
      getComments in interface com.xebialabs.xlrelease.osgi.api.tasks.TaskExecutionContext
    • toResults

      public PluginTaskResults toResults(Integer resumeDelaySeconds, boolean awaitSignal)
      Everything the extension wrote, ready to hand back through the release actor.
      Parameters:
      resumeDelaySeconds - from a suspendFor outcome, else null
      awaitSignal - true for an awaitSignal outcome