Search code examples
apacheexecutioncontextbrooklyn

Posting a Task to the Web Consoles Execution(Management) Context


In the apache brooklyn web interface we would like to display some content for the sytsem managers. The content is too long to be served as a simple sensor value.

Our idea was to create a task and write the content into the output stream of the task, and then offer the REST based URL to the managers like this: /v1/activities/{task}/stream/stdout (Of course the link masked with some nice text)

The stream and task is created like this:

LOG.info("{} Creating Activity for ClusterReport Feed", this);
activity = Tasks.builder().
    displayName("clusterReportFeed").
    description("Output for the Cluster Report Feed").
    body(new Runnable() {
        @Override
        public void run() {
            //DO NOTHING
        }
    }).
    parallel(true).
    build();

LOG.info("{} Task Created with Id: " + activity.getId(), this);
Entities.submit(server, activity).getUnchecked();

The task seems to be created and the interraction works perfectly fine. However when I want to access the tasks output stream from my browser using a prepared URL I get the error that the task does not exist.

Our idea is that we are not in the right Management/Execution Context. The Web page is running in an other context compared to the entities and their sensors. How can we put a task so that it's visible for the web consoles context also.

Is it possible to write the content into a file and then offer it for download via Jetty(brooklyns web server)? That would be a much simpler way.


Solution

  • Many tasks in Brooklyn default to being transient - i.e. they are deleted shortly after they complete (things like effector invocations are by default non-transient).

    You can mark your task as non-transient using the code below in your use of the task builder:

    .tag(BrooklynTaskTags.NON_TRANSIENT_TASK_TAG)
    

    However, note that (as of Brooklyn version 0.9.0) tasks are kept in-memory using soft references. This means the stdout of the task will likely be lost at some point in the future, when that memory is needed for other in-memory objects.

    For your use-case, would it make sense to have this as an effector result perhaps?

    Or could you write to an object store such as S3 instead? The S3-approach would seem best to me.

    For writing it to a file, care must be taken when used with Brooklyn high-availability. Would you write to a shared volume?

    If you do write to a file, then you'd need to provide a web-extension so that people can access the contents of that file. As of Brooklyn 0.9.0, you can add your own WARs in code when calling BrooklynLauncher (which calls BrooklynWebServer).