You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@brooklyn.apache.org by Peter Abramowitsch <pa...@gmail.com> on 2019/03/11 00:20:59 UTC

Need help understanding sensors

I'm interested in adding some custom sensing in my app.  Using the
VanillaJavaApp Entity,  let's say I would like my application whose main
class is set in the blueprint to send back a dynamic "records processed
count" and have it appear in amongst the other sensors on Brooklyn's web
UI.

My Java app is not a webserver,  just a long-running process.  Is the
correct approach to create an MBean as part of my app and connect it back
to Brooklyn's server?   I'm not sure how to put all the pieces together...
or if there's a better way.  Can it be done without extending Brooklyn
itself?

Peter

Re: Need help understanding sensors

Posted by Peter Abramowitsch <pa...@gmail.com>.
Yes, turns out that postback was the simplest way and it populates the
sensors very nicely.

I do have a suggestion for the VanillaJavaApp.    It is possible to set up
more than one instance of such an entity of this type within an
application, which is great for my use case, but as far as I can tell, they
cannot all be shut down without a trick.   I need to run 16-20 instances of
VanillaJava apps from a single Brooklyn application instance.

It turns out that if a Brooklyn App launches more than one VanillaJavaApp.
there is still only one PID file which is generated -- containing only one
of the pids.  So when shutting down, only one of the Java child processes
can be killed from the Brooklyn CLI or UI.  I tricked the system by having
each of the child Vanilla apps periodically check for the existence of the
PID file.   When it is no longer there (because one of the Java apps has
been killed),  each of the other apps just initiates its own exit.   Did
that make sense?

My solution:   Add an attribute to the VanillaApp  to allow one to specify
its own PID filename, or another way to shut down its app, perhaps via JMX

Peter

On Wed, Mar 13, 2019 at 1:03 PM Geoff Macartney <ge...@gmail.com>
wrote:

> Hey Peter,
>
> Ah cool, so you are actually posting *to* Brooklyn from the app itself? If
> you have the flexibility to do that, that's great. Glad it's working out.
>
> Do let us know any thoughts you have about your experience with Brooklyn,
> usability, usefulness etc. All feedback is welcome!
>
> Best,
> Geoff
>
>
>
>
> On Tue, 12 Mar 2019 at 23:36 Peter Abramowitsch <pa...@gmail.com>
> wrote:
>
> > Thanks Geoff,
> > About ten minutes after I posted,I  realized I could just use the
> Brooklyn
> > REST API.  I just needed to launch the java app with a system property
> > containing the composed URLbase and credentials to post back with.   It
> > works great and is much easier than JMX.
> >
> > On Mon, Mar 11, 2019, 2:56 PM Geoff Macartney <geoff.macartney@gmail.com
> >
> > wrote:
> >
> > > Hi Peter
> > >
> > > I'd say an MBean is a reasonable way to expose that sort of thing to
> > > Brooklyn (or any management/orchestration tool) for a Java app.  I
> guess
> > > there would be other ways of doing it without JMX but they might be
> more
> > > ad-hoc, while this is just the sort of thing JMX is for.
> > >
> > > Since you're already thinking about using (extending) VanillaJavaApp in
> > > Brooklyn to manage your app,  you could look into adding sensors for
> > > whatever MBeans you want to expose from your app using JmxFeed. There
> is
> > > some documentation for this at [1]. You could also use the code for
> > > TomcatServerImpl [2] as a reference, as it uses JmxFeeds.
> > >
> > > Just my 2¢. It's not something I've done myself I'm afraid, so I don't
> > have
> > > any better example I can point you to.
> > >
> > > Geoff
> > >
> > > [1]
> > >
> https://brooklyn.apache.org/v/latest/blueprints/java/feeds.html#jmx-feed
> > > [2]
> > >
> > >
> >
> https://github.com/apache/brooklyn-library/blob/master/software/webapp/src/main/java/org/apache/brooklyn/entity/webapp/tomcat/TomcatServerImpl.java
> > >
> > >
> > > On Mon, 11 Mar 2019 at 00:21 Peter Abramowitsch <
> pabramowitsch@gmail.com
> > >
> > > wrote:
> > >
> > > > I'm interested in adding some custom sensing in my app.  Using the
> > > > VanillaJavaApp Entity,  let's say I would like my application whose
> > main
> > > > class is set in the blueprint to send back a dynamic "records
> processed
> > > > count" and have it appear in amongst the other sensors on Brooklyn's
> > web
> > > > UI.
> > > >
> > > > My Java app is not a webserver,  just a long-running process.  Is the
> > > > correct approach to create an MBean as part of my app and connect it
> > back
> > > > to Brooklyn's server?   I'm not sure how to put all the pieces
> > > together...
> > > > or if there's a better way.  Can it be done without extending
> Brooklyn
> > > > itself?
> > > >
> > > > Peter
> > > >
> > >
> >
>

Re: Need help understanding sensors

Posted by Peter Abramowitsch <pa...@gmail.com>.
Thank you!  I didn't know the Brooklyn yaml parser would accept json.

I use various editors including Sublime which understands yaml and many
other formats.   My problem wasn't that the syntax was illegal yaml but
that some items were assigned to the wrong collection and i was too much of
a novice at Brooklyn to see that.

Sending sample yaml files back and forth by email damaged the indentation.
This is why i prefer languages with explicit containment syntax.

P

On Thu, Mar 21, 2019, 2:26 AM Duncan Grant <du...@cloudsoft.io>
wrote:

> Peter,
>
> Just in case you hadn't realised JSON is allowed in almost all cases where
> yaml is used.  This is part of the yaml standard[1] and I think the main
> thing you lose is the ability to use anchors[2].
>
> Personally I'm a big fan of VIM and I find that as long as I keep file
> sizes quite small then yaml indentation is perfectly manageable as VIM
> shows indentation and will do simple auto-formatting.
>
> Regards
>
> Duncan
>
> [1] https://yaml.org/spec/1.2/spec.html#id2759572
> [2]
>
> https://stackoverflow.com/questions/1726802/what-is-the-difference-between-yaml-and-json-when-to-prefer-one-over-the-other
>
>
> On Sat, 16 Mar 2019 at 17:59, Peter Abramowitsch <pa...@gmail.com>
> wrote:
>
> > Hi Geoff
> >
> > Ok, I think it's good now.  I did use a brooklyn config substitution to
> > create a rundir
> >
> > run.dir: $brooklyn:config("rundir")
> >
> > And then defined it in the app
> > rundir: /Users/peterabramowitsch/manhattan/c2
> >
> > And it nicely copied the artifacts I had defined with absolute paths -
> such
> > as jars and log4g config into the rundirs.  And as you pointed out, each
> > one got its own pid.txt so each process can be managed correctly.
> >
> > Many thanks for all your help and suggestions
> >
> > Turns out some of my problems were just incorrect indentation in the
> Yaml.
> > I am a developer with 38 years of experience, and I've been through and
> > written my own tens of different formats for configuration, passing
> through
> > types where indentation mattered, like Make, Coffeescript, HAML (a rails
> > formatter) hoping to never see them again.   The problem with all of them
> > is that one can create a mess where an item belongs to the incorrect
> > collection / hash while visually it still looks perfect, and no syntax
> tool
> > will help you.  It would be difficult to do that it in a format like JSON
> > or XML.
> >
> > So here's my last suggestion.   How about JSON as an alternative input
> > format, or how about a kind of dump in Brooklyn which shows all of the
> > entities and their properties it's *about* to create before it goes about
> > creating them, throwing NPEs  whose messages are hard to decipher.
> >
> > Peter
> >
> >
> >
> > On Thu, Mar 14, 2019 at 5:18 PM Geoff Macartney <
> geoff.macartney@gmail.com
> > >
> > wrote:
> >
> > > Hi again Peter,
> > >
> > > As is often the way, looking at the email I just sent I suddenly
> realised
> > > what the problem with the pid file is - the catalog item is defining
> the
> > > run.dir as the home directory.  Just leave out the definition of
> run.dir
> > in
> > > the catalog item’s config. Then each entity gets its own run dir with
> its
> > > own pid.txt and you don’t need to do anything special to configure the
> > run
> > > dir per-entity.
> > >
> > > I knew something felt wrong! That’s what it was.
> > >
> > > Cheers
> > > Geoff
> > >
> >
>

Re: Need help understanding sensors

Posted by Duncan Grant <du...@cloudsoft.io>.
Peter,

Just in case you hadn't realised JSON is allowed in almost all cases where
yaml is used.  This is part of the yaml standard[1] and I think the main
thing you lose is the ability to use anchors[2].

Personally I'm a big fan of VIM and I find that as long as I keep file
sizes quite small then yaml indentation is perfectly manageable as VIM
shows indentation and will do simple auto-formatting.

Regards

Duncan

[1] https://yaml.org/spec/1.2/spec.html#id2759572
[2]
https://stackoverflow.com/questions/1726802/what-is-the-difference-between-yaml-and-json-when-to-prefer-one-over-the-other


On Sat, 16 Mar 2019 at 17:59, Peter Abramowitsch <pa...@gmail.com>
wrote:

> Hi Geoff
>
> Ok, I think it's good now.  I did use a brooklyn config substitution to
> create a rundir
>
> run.dir: $brooklyn:config("rundir")
>
> And then defined it in the app
> rundir: /Users/peterabramowitsch/manhattan/c2
>
> And it nicely copied the artifacts I had defined with absolute paths - such
> as jars and log4g config into the rundirs.  And as you pointed out, each
> one got its own pid.txt so each process can be managed correctly.
>
> Many thanks for all your help and suggestions
>
> Turns out some of my problems were just incorrect indentation in the Yaml.
> I am a developer with 38 years of experience, and I've been through and
> written my own tens of different formats for configuration, passing through
> types where indentation mattered, like Make, Coffeescript, HAML (a rails
> formatter) hoping to never see them again.   The problem with all of them
> is that one can create a mess where an item belongs to the incorrect
> collection / hash while visually it still looks perfect, and no syntax tool
> will help you.  It would be difficult to do that it in a format like JSON
> or XML.
>
> So here's my last suggestion.   How about JSON as an alternative input
> format, or how about a kind of dump in Brooklyn which shows all of the
> entities and their properties it's *about* to create before it goes about
> creating them, throwing NPEs  whose messages are hard to decipher.
>
> Peter
>
>
>
> On Thu, Mar 14, 2019 at 5:18 PM Geoff Macartney <geoff.macartney@gmail.com
> >
> wrote:
>
> > Hi again Peter,
> >
> > As is often the way, looking at the email I just sent I suddenly realised
> > what the problem with the pid file is - the catalog item is defining the
> > run.dir as the home directory.  Just leave out the definition of run.dir
> in
> > the catalog item’s config. Then each entity gets its own run dir with its
> > own pid.txt and you don’t need to do anything special to configure the
> run
> > dir per-entity.
> >
> > I knew something felt wrong! That’s what it was.
> >
> > Cheers
> > Geoff
> >
>

Re: Need help understanding sensors

Posted by Geoff Macartney <ge...@gmail.com>.
Hi Peter,

That's great, I'm glad you got it working as you need.  I agree with your point in your earlier email about the documentation being improved. I've raised a JIRA issue for us with your suggestion at  [1]. There is a way to get the runtime ID of an app (if I’ve understood your question right), using $brooklyn:identity(), see [2] for examples. In general if you are wanting to define locations (paths, urls etc) for software processes, you can simply put the value in a config item, and then supply that item to the process through the environment, see [3] for an example of this in action in an Elasticsearch blueprint.


I also agree with you entirely about the bother with creating YAML (and not just YAML), it can be tricky to spot indentation issues especially.  I think given the way Brooklyn works it might be tricky to create a “dry run” view of an app without actually deploying it.  One thing you could have a look at is the graphical composer in our shiny new UI. It lets you create the app graphically, and switch to a YAML view if you like, and of course it gets its indentation right :-)

Hope Brooklyn is a useful tool for you.

Best
Geoff

[1] https://issues.apache.org/jira/browse/BROOKLYN-612
[2] https://github.com/apache/brooklyn-server/pull/219
[3] https://s.apache.org/yOfP



Re: Need help understanding sensors

Posted by Peter Abramowitsch <pa...@gmail.com>.
Hi Geoff

Ok, I think it's good now.  I did use a brooklyn config substitution to
create a rundir

run.dir: $brooklyn:config("rundir")

And then defined it in the app
rundir: /Users/peterabramowitsch/manhattan/c2

And it nicely copied the artifacts I had defined with absolute paths - such
as jars and log4g config into the rundirs.  And as you pointed out, each
one got its own pid.txt so each process can be managed correctly.

Many thanks for all your help and suggestions

Turns out some of my problems were just incorrect indentation in the Yaml.
I am a developer with 38 years of experience, and I've been through and
written my own tens of different formats for configuration, passing through
types where indentation mattered, like Make, Coffeescript, HAML (a rails
formatter) hoping to never see them again.   The problem with all of them
is that one can create a mess where an item belongs to the incorrect
collection / hash while visually it still looks perfect, and no syntax tool
will help you.  It would be difficult to do that it in a format like JSON
or XML.

So here's my last suggestion.   How about JSON as an alternative input
format, or how about a kind of dump in Brooklyn which shows all of the
entities and their properties it's *about* to create before it goes about
creating them, throwing NPEs  whose messages are hard to decipher.

Peter



On Thu, Mar 14, 2019 at 5:18 PM Geoff Macartney <ge...@gmail.com>
wrote:

> Hi again Peter,
>
> As is often the way, looking at the email I just sent I suddenly realised
> what the problem with the pid file is - the catalog item is defining the
> run.dir as the home directory.  Just leave out the definition of run.dir in
> the catalog item’s config. Then each entity gets its own run dir with its
> own pid.txt and you don’t need to do anything special to configure the run
> dir per-entity.
>
> I knew something felt wrong! That’s what it was.
>
> Cheers
> Geoff
>

Re: Need help understanding sensors

Posted by Peter Abramowitsch <pa...@gmail.com>.
Hi Geoff

Thanks for your answers.  Yes, I was wondering about the use of
brooklyn.configs outside of their scope.  My problem is that even after
reading and studying the examples,  knowing that one can simply override an
attribute value without brooklyn config, made it unclear for me what
exactly the purpose or functionality of brooklyn.config was and how it
differed from simple overriding of inherited values.  Maybe the
documentation could be improved so that brooklyn.config is given an
explicit section rather than being an incidental part of several examples
and a few comments provided.    It would be helpful to understand what its
scope is within a catalog item (where can it be declared and used) and what
its intended scope is when composing an application where you set values.
Btw is there a way to get the runtime ID of an app or an entity and pass it
to the VanillaJava app in a system property.  Not the "client1" id, but the
small uuid that gets generated for those guys.

About not defining run.dir at all,  I'm not so sure, without it would mean
that my classpath definitions would need to be absolute paths and secondly,
the system needs to find its log and config folders when it's launched.  So
I'd need to add some shell commands to create those and populate the config
dir -- but where?  When there's no rundir - where exactly is home for the
app?   I didn't notice another variable that would specify home.

But anyway your comments have given me some good ideas and confidence that
I'm not far off.   I've solved the pid file problem already by having all
apps look for the existence of the file regardless of who created it.  Once
the file is gone, all apps call their shutdown hooks.

Many thanks!
Peter

On Thu, Mar 14, 2019 at 5:18 PM Geoff Macartney <ge...@gmail.com>
wrote:

> Hi again Peter,
>
> As is often the way, looking at the email I just sent I suddenly realised
> what the problem with the pid file is - the catalog item is defining the
> run.dir as the home directory.  Just leave out the definition of run.dir in
> the catalog item’s config. Then each entity gets its own run dir with its
> own pid.txt and you don’t need to do anything special to configure the run
> dir per-entity.
>
> I knew something felt wrong! That’s what it was.
>
> Cheers
> Geoff
>

Re: Need help understanding sensors

Posted by Geoff Macartney <ge...@gmail.com>.
Hi again Peter,

As is often the way, looking at the email I just sent I suddenly realised what the problem with the pid file is - the catalog item is defining the run.dir as the home directory.  Just leave out the definition of run.dir in the catalog item’s config. Then each entity gets its own run dir with its own pid.txt and you don’t need to do anything special to configure the run dir per-entity.

I knew something felt wrong! That’s what it was.

Cheers
Geoff

Re: Need help understanding sensors

Posted by Geoff Macartney <ge...@gmail.com>.
Hi Peter,

First of all thanks for the observations on VanillaJavaApp. I’ll raise a Brooklyn JIRA issue about that. More on that in a moment.

Secondly, your catalog looks broadly good, but there are a couple of observations I’d make.

The main one is that you can’t have "name: $brooklyn:config("clientname”)” in the definition of the entity in the catalog - after all this is defining the _catalog_  entity but the clientname only gets defined at the time you deploy an app.

I was able to get a catalog entry defined with the following catalog definition (using a simple “no-op” Java app):

brooklyn.catalog:
  id: htclienttemplate
  version: "1.1"
  itemType: entity
  item:
    name: htclientexample
    type: org.apache.brooklyn.entity.java.VanillaJavaApp

    brooklyn.config:
      run.dir: /Users/geoff
      children.startable.mode: FOREGROUND
      skip.install: true
      vanillaJavaApp.mainClass: com.example.VerySimpleApp
      vanillaJavaApp.args:
        - -cid
        - $brooklyn:config("clientname")
        - -rid
        - run1
        - -longnotes
        - false
        - -c
        - org.ucsf.clients.ht.DataCommonsClient
      vanillaJavaApp.classpath:
        - /Users/geoff/workspaces/github.com/apache/brooklyn/vjatest/target/vjatest-1.0.0-SNAPSHOT.jar
      vanillaJavaApp.jvmDefines:
        mongo.dbname: xxxxxxx
        mongo.username: xxxxxxx
        mongo.userpwd: xxxxxxxx
        serveraddr: mongodb://localhost:27017
        log4j.configurationFile: config/log4j-datacommons.xml
        log4jid: $brooklyn:config("clientname")
        brooklyn.credentials: xxxxxxxxxxx
        brooklyn.resturl: $brooklyn:config("resturl")
        jmx.direct.port: $brooklyn:config("jmxport")

    brooklyn.parameters:
      - name: clientname
      - name: jmxport
      - name: resturl


The other thing is that you will still run into the problem with the single pid.txt file - which will mean that you’ll need to do some workaround. You could do it in your app, but a simpler workaround would be to define “run.dir” separately for each entity:


name: testapp
location: localhost
services:
  - id: h1
    type: htclienttemplate
    name: app1
    brooklyn.config:
      run.dir: /users/geoff/a
      jmx.enabled: false
      clientname: client1
  - id: h2
    type: htclienttemplate
    name: app2
    brooklyn.config:
      run.dir: /users/geoff/b
      jmx.enabled: false
      clientname: client2


Hopefully we can soon get around to fixing VanillaJavaApp so that this is unnecessary.

Hope this is of some use,

Regards
Geoff






Re: Need help understanding sensors

Posted by Peter Abramowitsch <pa...@gmail.com>.
Hi Geoff
Sorry to bother you again.

I have a question about blueprinting and using brooklyn.parameters

I managed to write a long winded application with a couple of services
which are like a cluster, but written out fully.    That works fine.

Now  I'm trying to abstract out the entity to put in the catalog and
template three variables which need to differ between one instance of the
entity and another.

I could be misusing the syntax, but the error message I'm getting is so
vague, I don't know where to look for my problem:   Here's the definition
of the entity.  As you can see, I need the templated name to occur in a
bunch of spots

*first... in the deployment, I'm hoping to do something like this*

services:
  - type:  htclienttemplate
    clientname: ht1
    jmxport: 19001
    resturl: "
http://127.0.0.1:8081/v1/applications/infocommons/entities/ht1/sensors"
- type:  htclienttemplate
    clientname: ht2
    jmxport: 19001
    resturl: "
http://127.0.0.1:8081/v1/applications/infocommons/entities/ht2/sensors"

*And this is what I'm trying to add to the catalog.  *

brooklyn.catalog:
  id: htclienttemplate
  version: "1.1"
  itemType: entity
  item:
    name: $brooklyn:config("clientname")
    location: localhost
    type: org.apache.brooklyn.entity.java.VanillaJavaApp
    brooklyn.config:
      run.dir: /Users/peterabramowitsch/manhattan
      children.startable.mode: FOREGROUND
      skip.install: true
      vanillaJavaApp.mainClass: org.ucsf.clients.RunUcsfNlp
      vanillaJavaApp.args:
        - -cid
        - $brooklyn:config("clientname")
        - -rid
        - run1
        - -longnotes
        - false
        - -c
        - org.ucsf.clients.ht.DataCommonsClient
      vanillaJavaApp.classpath:
        -
/Users/peterabramowitsch/manhattan/lib/ht_client-0.1.0-jar-with-dependencies.jar
        -
/Users/peterabramowitsch/manhattan/lib/ucsfNlp-0.1.0-jar-with-dependencies.jar
      vanillaJavaApp.jvmDefines:
        mongo.dbname: xxxxxxx
        mongo.username: xxxxxxx
        mongo.userpwd: xxxxxxxx
        serveraddr: mongodb://localhost:27017
        log4j.configurationFile: config/log4j-datacommons.xml
        log4jid: $brooklyn:config("clientname")
        brooklyn.credentials: xxxxxxxxxxx
        brooklyn.resturl: $brooklyn:config("resturl")
        jmx.direct.port: $brooklyn:config("jmxport")
    brooklyn.parameters:
    - name: clientname
    - name: jmxport
    - name: resturl


I can't interpret the error I'm getting.......

ERROR
 Bundle BasicManagedBundle{symbolicName=htclienttemplate, version=1.1.0,
url=null} failed installation: Error installing catalog items: Failed to
install htclienttemplate:1.1.0, types
[BasicRegisteredType[htclienttemplate:1.1;null]] gave errors; 5 errors
including: Transformer for Brooklyn OASIS CAMP interpreter gave an error
creating this plan: java.lang.ClassCastException

On Wed, Mar 13, 2019 at 1:03 PM Geoff Macartney <ge...@gmail.com>
wrote:

> Hey Peter,
>
> Ah cool, so you are actually posting *to* Brooklyn from the app itself? If
> you have the flexibility to do that, that's great. Glad it's working out.
>
> Do let us know any thoughts you have about your experience with Brooklyn,
> usability, usefulness etc. All feedback is welcome!
>
> Best,
> Geoff
>
>
>
>
> On Tue, 12 Mar 2019 at 23:36 Peter Abramowitsch <pa...@gmail.com>
> wrote:
>
> > Thanks Geoff,
> > About ten minutes after I posted,I  realized I could just use the
> Brooklyn
> > REST API.  I just needed to launch the java app with a system property
> > containing the composed URLbase and credentials to post back with.   It
> > works great and is much easier than JMX.
> >
> > On Mon, Mar 11, 2019, 2:56 PM Geoff Macartney <geoff.macartney@gmail.com
> >
> > wrote:
> >
> > > Hi Peter
> > >
> > > I'd say an MBean is a reasonable way to expose that sort of thing to
> > > Brooklyn (or any management/orchestration tool) for a Java app.  I
> guess
> > > there would be other ways of doing it without JMX but they might be
> more
> > > ad-hoc, while this is just the sort of thing JMX is for.
> > >
> > > Since you're already thinking about using (extending) VanillaJavaApp in
> > > Brooklyn to manage your app,  you could look into adding sensors for
> > > whatever MBeans you want to expose from your app using JmxFeed. There
> is
> > > some documentation for this at [1]. You could also use the code for
> > > TomcatServerImpl [2] as a reference, as it uses JmxFeeds.
> > >
> > > Just my 2¢. It's not something I've done myself I'm afraid, so I don't
> > have
> > > any better example I can point you to.
> > >
> > > Geoff
> > >
> > > [1]
> > >
> https://brooklyn.apache.org/v/latest/blueprints/java/feeds.html#jmx-feed
> > > [2]
> > >
> > >
> >
> https://github.com/apache/brooklyn-library/blob/master/software/webapp/src/main/java/org/apache/brooklyn/entity/webapp/tomcat/TomcatServerImpl.java
> > >
> > >
> > > On Mon, 11 Mar 2019 at 00:21 Peter Abramowitsch <
> pabramowitsch@gmail.com
> > >
> > > wrote:
> > >
> > > > I'm interested in adding some custom sensing in my app.  Using the
> > > > VanillaJavaApp Entity,  let's say I would like my application whose
> > main
> > > > class is set in the blueprint to send back a dynamic "records
> processed
> > > > count" and have it appear in amongst the other sensors on Brooklyn's
> > web
> > > > UI.
> > > >
> > > > My Java app is not a webserver,  just a long-running process.  Is the
> > > > correct approach to create an MBean as part of my app and connect it
> > back
> > > > to Brooklyn's server?   I'm not sure how to put all the pieces
> > > together...
> > > > or if there's a better way.  Can it be done without extending
> Brooklyn
> > > > itself?
> > > >
> > > > Peter
> > > >
> > >
> >
>

Re: Need help understanding sensors

Posted by Geoff Macartney <ge...@gmail.com>.
Hey Peter,

Ah cool, so you are actually posting *to* Brooklyn from the app itself? If
you have the flexibility to do that, that's great. Glad it's working out.

Do let us know any thoughts you have about your experience with Brooklyn,
usability, usefulness etc. All feedback is welcome!

Best,
Geoff




On Tue, 12 Mar 2019 at 23:36 Peter Abramowitsch <pa...@gmail.com>
wrote:

> Thanks Geoff,
> About ten minutes after I posted,I  realized I could just use the Brooklyn
> REST API.  I just needed to launch the java app with a system property
> containing the composed URLbase and credentials to post back with.   It
> works great and is much easier than JMX.
>
> On Mon, Mar 11, 2019, 2:56 PM Geoff Macartney <ge...@gmail.com>
> wrote:
>
> > Hi Peter
> >
> > I'd say an MBean is a reasonable way to expose that sort of thing to
> > Brooklyn (or any management/orchestration tool) for a Java app.  I guess
> > there would be other ways of doing it without JMX but they might be more
> > ad-hoc, while this is just the sort of thing JMX is for.
> >
> > Since you're already thinking about using (extending) VanillaJavaApp in
> > Brooklyn to manage your app,  you could look into adding sensors for
> > whatever MBeans you want to expose from your app using JmxFeed. There is
> > some documentation for this at [1]. You could also use the code for
> > TomcatServerImpl [2] as a reference, as it uses JmxFeeds.
> >
> > Just my 2¢. It's not something I've done myself I'm afraid, so I don't
> have
> > any better example I can point you to.
> >
> > Geoff
> >
> > [1]
> > https://brooklyn.apache.org/v/latest/blueprints/java/feeds.html#jmx-feed
> > [2]
> >
> >
> https://github.com/apache/brooklyn-library/blob/master/software/webapp/src/main/java/org/apache/brooklyn/entity/webapp/tomcat/TomcatServerImpl.java
> >
> >
> > On Mon, 11 Mar 2019 at 00:21 Peter Abramowitsch <pabramowitsch@gmail.com
> >
> > wrote:
> >
> > > I'm interested in adding some custom sensing in my app.  Using the
> > > VanillaJavaApp Entity,  let's say I would like my application whose
> main
> > > class is set in the blueprint to send back a dynamic "records processed
> > > count" and have it appear in amongst the other sensors on Brooklyn's
> web
> > > UI.
> > >
> > > My Java app is not a webserver,  just a long-running process.  Is the
> > > correct approach to create an MBean as part of my app and connect it
> back
> > > to Brooklyn's server?   I'm not sure how to put all the pieces
> > together...
> > > or if there's a better way.  Can it be done without extending Brooklyn
> > > itself?
> > >
> > > Peter
> > >
> >
>

Re: Need help understanding sensors

Posted by Peter Abramowitsch <pa...@gmail.com>.
Thanks Geoff,
About ten minutes after I posted,I  realized I could just use the Brooklyn
REST API.  I just needed to launch the java app with a system property
containing the composed URLbase and credentials to post back with.   It
works great and is much easier than JMX.

On Mon, Mar 11, 2019, 2:56 PM Geoff Macartney <ge...@gmail.com>
wrote:

> Hi Peter
>
> I'd say an MBean is a reasonable way to expose that sort of thing to
> Brooklyn (or any management/orchestration tool) for a Java app.  I guess
> there would be other ways of doing it without JMX but they might be more
> ad-hoc, while this is just the sort of thing JMX is for.
>
> Since you're already thinking about using (extending) VanillaJavaApp in
> Brooklyn to manage your app,  you could look into adding sensors for
> whatever MBeans you want to expose from your app using JmxFeed. There is
> some documentation for this at [1]. You could also use the code for
> TomcatServerImpl [2] as a reference, as it uses JmxFeeds.
>
> Just my 2¢. It's not something I've done myself I'm afraid, so I don't have
> any better example I can point you to.
>
> Geoff
>
> [1]
> https://brooklyn.apache.org/v/latest/blueprints/java/feeds.html#jmx-feed
> [2]
>
> https://github.com/apache/brooklyn-library/blob/master/software/webapp/src/main/java/org/apache/brooklyn/entity/webapp/tomcat/TomcatServerImpl.java
>
>
> On Mon, 11 Mar 2019 at 00:21 Peter Abramowitsch <pa...@gmail.com>
> wrote:
>
> > I'm interested in adding some custom sensing in my app.  Using the
> > VanillaJavaApp Entity,  let's say I would like my application whose main
> > class is set in the blueprint to send back a dynamic "records processed
> > count" and have it appear in amongst the other sensors on Brooklyn's web
> > UI.
> >
> > My Java app is not a webserver,  just a long-running process.  Is the
> > correct approach to create an MBean as part of my app and connect it back
> > to Brooklyn's server?   I'm not sure how to put all the pieces
> together...
> > or if there's a better way.  Can it be done without extending Brooklyn
> > itself?
> >
> > Peter
> >
>

Re: Need help understanding sensors

Posted by Geoff Macartney <ge...@gmail.com>.
Hi Peter

I'd say an MBean is a reasonable way to expose that sort of thing to
Brooklyn (or any management/orchestration tool) for a Java app.  I guess
there would be other ways of doing it without JMX but they might be more
ad-hoc, while this is just the sort of thing JMX is for.

Since you're already thinking about using (extending) VanillaJavaApp in
Brooklyn to manage your app,  you could look into adding sensors for
whatever MBeans you want to expose from your app using JmxFeed. There is
some documentation for this at [1]. You could also use the code for
TomcatServerImpl [2] as a reference, as it uses JmxFeeds.

Just my 2¢. It's not something I've done myself I'm afraid, so I don't have
any better example I can point you to.

Geoff

[1] https://brooklyn.apache.org/v/latest/blueprints/java/feeds.html#jmx-feed
[2]
https://github.com/apache/brooklyn-library/blob/master/software/webapp/src/main/java/org/apache/brooklyn/entity/webapp/tomcat/TomcatServerImpl.java


On Mon, 11 Mar 2019 at 00:21 Peter Abramowitsch <pa...@gmail.com>
wrote:

> I'm interested in adding some custom sensing in my app.  Using the
> VanillaJavaApp Entity,  let's say I would like my application whose main
> class is set in the blueprint to send back a dynamic "records processed
> count" and have it appear in amongst the other sensors on Brooklyn's web
> UI.
>
> My Java app is not a webserver,  just a long-running process.  Is the
> correct approach to create an MBean as part of my app and connect it back
> to Brooklyn's server?   I'm not sure how to put all the pieces together...
> or if there's a better way.  Can it be done without extending Brooklyn
> itself?
>
> Peter
>