You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@brooklyn.apache.org by Azhar I Hashmi <ai...@us.ibm.com> on 2015/01/22 02:10:58 UTC

"using variable later in postprovisionscript or any other script"

Hello,

Brooklyn provides a way to define variable and set their value using
sensor.  However, I am not able to successfully use those variables.  I
could not find those variables. I defined them in two different ways to use
them later in post script but was not able to find them. Here is a piece of
the YAML blueprint example:

memberSpec:
    $brooklyn:entitySpec:
      type: brooklyn.entity.webapp.tomcat.TomcatServer
      id: tomcatServer
      location:
        named:standard-location-wdc01:
          customizerType:
io.cloudsoft.ibm.mms.amp.location.SoftlayerLocationCustomizer
          postInstallScriptUri: https://USE_VARIABLE_IN_SCRIPT.sh
          privateNetworkOnly: false
      brooklyn.config:
        https.port: 8443+
        MY_VARIABLE: $brooklyn:formatString("%s",
              component("BSSMySQLDB").attributeWhenReady
("host.subnet.address"))
        setup.script: https://USE_VARIABLE_IN_SCRIPT.sh
        setup.script.vars:
          $brooklyn:formatString("tomcatPublicIP:%s,runPath:%s,webappUrl
:%s",
                                  component
("tomcatServer").attributeWhenReady("host.address"),
                                  component
("tomcatServer").attributeWhenReady("run.dir"),
                                  component
("tomcatServer").attributeWhenReady("webapp.url"))

Question 1:  How do I use these variables in my scrips?
Question 2: I need following jars and xml file in Tomcat/apache catalina
lib and conf directories respectively.  However, following piece of yaml
blueprint put them under /home/...../install/...../lib/  and
/home/...../install/..../conf/ directories.  I need the jar files under lib
folder of Catalina/tomcat 's lib directory and .xml file under
/home/..../apps/.......TomcatEntity/conf  directory.  Is there a variable
that I can use in <key,value> pair instead of lib/ and conf/ directories?

files.install:
          "
http://central.maven.org/maven2/org/apache/tomcat/tomcat-dbcp/7.0.30/tomcat-dbcp-7.0.30.jar
": lib/tomcat-dbcp-7.0.30.jar
          "
http://central.maven.org/maven2/mysql/mysql-connector-java/5.1.10/mysql-connector-java-5.1.10.jar
": lib/mysql-connector-java-5.1.10.jar
          "https://provision/tomcat-users.xml": conf/tomcat-users.xml


Thanks
Azhar



From:	Alex Heneveld <al...@cloudsoftcorp.com>
To:	dev@brooklyn.incubator.apache.org
Date:	01/21/2015 06:08 PM
Subject:	Re: "force resolution of localhost to be loopback, otherwise we
            hit problems"




Sam-

If the localhost IP is set up right there should be no problem changing
or removing the flag in the launch script for that one case.

Background though is exactly as Richard described.  Several people have
hit problems deploying to "localhost" because localhost is mapped to a
bad IP address.

This can happen in clouds where /etc/hosts is foolishly set up.

Worse, on Mac it was sometimes the case that localhost resolves to the
subnet IP.  That IP would be cached, and then if you change wifi points,
localhost deployments could get very confused.  This might be better in
yosemite (localhost resolves to 127.0.0.1 for me at least) but it's hard
to be sure.  Maybe someone else knows better?

Why do you want localhost to resolve to something else?  It seems unusual.

--A


On 19/01/2015 10:34, Richard Downer wrote:
> Sam,
>
> I would guess that if the hostname/domain name are properly configured
> everything should work. Unfortunately, it's easy to *not* quite
> configure networking correctly.
>
> My understanding of the canonical way to set the system hostname and
> domain name is as follows:
>
> /etc/hosts:
>
> 127.0.0.1  hostname hostname.domainname localhost
> # that must be the first non-comment line
>
> Configure the system hostname (without domainname); IIRC, on
> Debian-derivatives you write it to the file /etc/hostname, and on
> RedHat-derivatives there's a variable in /etc/sysconfig/network
>
> Then either run "hostname newhostname" or "service network restart" or
reboot.
>
> Check it works:
> # hostname
> (returns the bare hostname)
> # hostname --fqdn
> (returns the hostname and DNS domainname)
>
>
>
>
> On 18 January 2015 at 10:32, Sam Corbett <sa...@cloudsoftcorp.com>
wrote:
>> BrooklynServiceAttributes defines the property and has a comment saying:
>>
>> /** in some cases localhost does not resolve correctly
>>   * (e.g. to an interface which is defined locally but not in operation,
>>   * or where multiple NICs are available and java's
>> InetAddress.getLocalHost() strategy is not doing what is desired);
>>   * use this to supply a specific address (e.g. "127.0.0.1" or a
specific IP
>> on a specific NIC or FW)
>>   */
>>
>> I guess this answers my question but it doesn't give me much assurance.
>>
>> On 18 January 2015 at 10:02, Sam Corbett <sa...@cloudsoftcorp.com>
>> wrote:
>>
>>> Hi,
>>>
>>> The `brooklyn` launch script sets
>>> `-Dbrooklyn.location.localhost.address=127.0.0.1` with the cryptic
>>> explanation that 'otherwise we hit problems'. Can anybody explain what
>>> problems are avoided? I have a case in which I'd like the hostname of a
>>> localhost location to be the hostname of the machine, but I'd also like
to
>>> know what will happen if I change or remove the flag.
>>>
>>> Thanks,
>>>
>>> Sam
>>>


Re: "using variable later in postprovisionscript or any other script"

Posted by Alex Heneveld <al...@cloudsoftcorp.com>.
Hi Azhar,

The ${config.myVarA} syntax is for Freemarker templates.  It looks a lot 
like scripts -- both use the ${...} syntax -- but they are treated 
differently.  Because Freemarker is evaluated in Brooklyn then sent to 
the box we have access to all config etc there.  OTOH scripts are simply 
uploaded and evaluated and the only injection mechanism used is the 
`shell.env` map (because we don't want to send all config there).  So in 
your shell you have to continue to use the ${myvar1} style.

Best
Alex


On 22/01/2015 23:51, Azhar I Hashmi wrote:
>
> Thanks Alex,
>
> If i can refer to *${config.myvarA}* in my script then why would I 
> define *myvar1 *in*env.shell *other then what you described 
> *type-define *vs*non-type-defined *keys and their *scope. *Also*, 
> myvar1 or env.myvarA *are set as environment variables only for*that 
> session* during installation or can I access them later by logging 
> into the box? I tried to see the value of these variables as 
> predefined environment variables but I could not find them in *env* or 
> *printenv *on linux machine.
>
> So I can use alias like this*env.myvar1 *? Do not need 
> **prefix*config.* or *env.shell.* right in the script ?
>
> Thanks
> Azhar
>
>
>
> Inactive hide details for Alex Heneveld ---01/22/2015 05:29:30 
> PM---Azhar- What you propose I think could work. But I think itAlex 
> Heneveld ---01/22/2015 05:29:30 PM---Azhar- What you propose I think 
> could work. But I think it would also work and
>
> From: Alex Heneveld <al...@cloudsoftcorp.com>
> To: dev@brooklyn.incubator.apache.org
> Date: 01/22/2015 05:29 PM
> Subject: Re: "using variable later in postprovisionscript or any other 
> script"
>
> ------------------------------------------------------------------------
>
>
>
>
> Azhar-
>
> What you propose I think could work.  But I think it would also work and
> be cleaner to split out your config, e.g.
>
>   brooklyn.config:
>     myvarA:
> $brooklyn:component("machine").attributeWhenReady("host.address")
>   shell.env:
>     myvar1: $brooklyn:config("myvarA")
>
> and then in templates refer to ${config.myvarA}.
>
> Only subtlety is that "myvarA" *must* be in `brooklyn.config` because it
> is not a type-defined config key.  `shell.env` could be put under
> `brooklyn.config` or at the top level because it *is* a config key known
> at the type.  (It has a flag/alias "env" so you could also just call it
> `env`.)
>
> HTH + thanks for the nice comments on the new docs!
>
> --A
>
>
> On 22/01/2015 22:59, Azhar I Hashmi wrote:
> >
> > Thanks a lot Svet!
> >
> > Actually, I figured that there is files.runtime that I can use exactly
> > as you described and also came to know env.shell after our call and I
> > love the new documentation related to Entity's config, sensor etc.....
> >
> > Couple of questions:
> > Instead of hard coding the path like this: I saw in the doc that there
> > is a config to get to that path i.e. "*expandedinstall.dir". *Do you
> > think I can use config variable to get that value?
> >
> > files.install:
> >
> > 
>  "http://central.maven.org/maven2/org/apache/tomcat/tomcat-dbcp/7.0.30/tomcat-dbcp-7.0.30.jar": 
>
> > apache-tomcat-7.0.56/lib/tomcat-dbcp-7.0.30.jar
> >
> > Can I do this for example:
> >
> > files.install:
> >
> > 
>  "http://central.maven.org/maven2/org/apache/tomcat/tomcat-dbcp/7.0.30/tomcat-dbcp-7.0.30.jar": 
>
> > *${expandedinstal.dir}*/lib/tomcat-dbcp-7.0.30.jar
> > (OR)
> >
> > 
> "http://central.maven.org/maven2/org/apache/tomcat/tomcat-dbcp/7.0.30/tomcat-dbcp-7.0.30.jar": 
>
> > *${config.expandedinstal.dir}*/lib/tomcat-dbcp-7.0.30.jar
> >
> > Also:
> >
> >
> > According to the definition it takes a java map. So in your example:
> >
> > shell.env:
> >    myvar:
> > $brooklyn:component("machine").attributeWhenReady("host.address")
> > - type: brooklyn.entity.machine.MachineEntity
> >  id: machine
> > I can have multiple vars like this:
> >
> > shell.env:
> > *myvar1:
> > $brooklyn:component("machine").attributeWhenReady("host.address")*
> > *    myvar2:
> > $brooklyn:component("TOMCAT_ID").attributeWhenReady("host.address")*
> > *    myvar3:
> > 
> $brooklyn:component("MY_SQLID").attributeWhenReady("host.subnet.address")*
> > - type: brooklyn.entity.machine.MachineEntity
> >
> >
> > Also, in my */tmp/script.sh*
> >
> > Can I do this *${config.shell.env.myvar1} ,
> > ${config.shell.env.myvar2},* and *${config.shell.env.myvar3}* to get
> > their values that are set by brooklyn? Is my understanding correct? If
> > not please correct me.
> >
> >
> > Thanks a lot!
> >
> > Azhar


Re: "using variable later in postprovisionscript or any other script"

Posted by Azhar I Hashmi <ai...@us.ibm.com>.
Thanks Alex,

If i can refer to ${config.myvarA} in my script then why would I define
myvar1 in env.shell other then what you described type-define vs
non-type-defined keys and their scope.  Also, myvar1 or env.myvarA are set
as environment variables only for that session during installation or can I
access them later by logging into the box?  I tried to see the value of
these variables as predefined environment variables but I could not find
them in env or printenv on linux machine.

So I can use alias like this env.myvar1 ?  Do not need  prefix config. or
env.shell. right in the script ?

Thanks
Azhar





From:	Alex Heneveld <al...@cloudsoftcorp.com>
To:	dev@brooklyn.incubator.apache.org
Date:	01/22/2015 05:29 PM
Subject:	Re: "using variable later in postprovisionscript or any other
            script"




Azhar-

What you propose I think could work.  But I think it would also work and
be cleaner to split out your config, e.g.

   brooklyn.config:
     myvarA:
$brooklyn:component("machine").attributeWhenReady("host.address")
   shell.env:
     myvar1: $brooklyn:config("myvarA")

and then in templates refer to ${config.myvarA}.

Only subtlety is that "myvarA" *must* be in `brooklyn.config` because it
is not a type-defined config key.  `shell.env` could be put under
`brooklyn.config` or at the top level because it *is* a config key known
at the type.  (It has a flag/alias "env" so you could also just call it
`env`.)

HTH + thanks for the nice comments on the new docs!

--A


On 22/01/2015 22:59, Azhar I Hashmi wrote:
>
> Thanks a lot Svet!
>
> Actually, I figured that there is files.runtime that I can use exactly
> as you described and also came to know env.shell after our call and I
> love the new documentation related to Entity's config, sensor etc.....
>
> Couple of questions:
> Instead of hard coding the path like this: I saw in the doc that there
> is a config to get to that path i.e. "*expandedinstall.dir". *Do you
> think I can use config variable to get that value?
>
> files.install:
>
>  "
http://central.maven.org/maven2/org/apache/tomcat/tomcat-dbcp/7.0.30/tomcat-dbcp-7.0.30.jar
":
> apache-tomcat-7.0.56/lib/tomcat-dbcp-7.0.30.jar
>
> Can I do this for example:
>
> files.install:
>
>  "
http://central.maven.org/maven2/org/apache/tomcat/tomcat-dbcp/7.0.30/tomcat-dbcp-7.0.30.jar
":
> *${expandedinstal.dir}*/lib/tomcat-dbcp-7.0.30.jar
> (OR)
>
> "
http://central.maven.org/maven2/org/apache/tomcat/tomcat-dbcp/7.0.30/tomcat-dbcp-7.0.30.jar
":
> *${config.expandedinstal.dir}*/lib/tomcat-dbcp-7.0.30.jar
>
> Also:
>
>
> According to the definition it takes a java map. So in your example:
>
> shell.env:
>    myvar:
> $brooklyn:component("machine").attributeWhenReady("host.address")
> - type: brooklyn.entity.machine.MachineEntity
>  id: machine
> I can have multiple vars like this:
>
> shell.env:
> *myvar1:
> $brooklyn:component("machine").attributeWhenReady("host.address")*
> *    myvar2:
> $brooklyn:component("TOMCAT_ID").attributeWhenReady("host.address")*
> *    myvar3:
> $brooklyn:component("MY_SQLID").attributeWhenReady
("host.subnet.address")*
> - type: brooklyn.entity.machine.MachineEntity
>
>
> Also, in my */tmp/script.sh*
>
> Can I do this *${config.shell.env.myvar1} ,
> ${config.shell.env.myvar2},* and *${config.shell.env.myvar3}* to get
> their values that are set by brooklyn? Is my understanding correct? If
> not please correct me.
>
>
> Thanks a lot!
>
> Azhar
>
> Inactive hide details for Svetoslav Neykov ---01/22/2015 04:44:06
> AM---Hi Azhar, I tried your blueprint and here's what I founSvetoslav
> Neykov ---01/22/2015 04:44:06 AM---Hi Azhar, I tried your blueprint
> and here's what I found out:
>
> From: Svetoslav Neykov <sv...@cloudsoftcorp.com>
> To: dev@brooklyn.incubator.apache.org
> Date: 01/22/2015 04:44 AM
> Subject: Re: "using variable later in postprovisionscript or any other
> script"
>
> ------------------------------------------------------------------------
>
>
>
> Hi Azhar,
>
> I tried your blueprint and here's what I found out:
> 1.
>  * setup.script needs to be specified inside the location. I tried to
> pass it inside the entity config, but it's not picked up.
>  * setup.script can be used only with jclouds locations. It's doesn't
> get executed for localhost or byon.
>  * When passing formatString parameters to setup.script.vars you will
> get a " Cannot coerce type class " exception. It's not supported
> currently.
>  * setup.script should only be used for system-wide configuration
> where you don't need dynamic parameters.
>  * In your case it's best to move all tomcat configuration from your
> script into a custom server.conf template and pass it to the entity.
> To access the entity config use ${config.MY_VARIABLE}.
>  * If you really need to pass variables to a script then you can use
> one of pre.install.command, post.install.command. The former will get
> executed before any installation steps take place so if you need to
> execute a script download it from a URL. The latter can use the files
> from files.install. Both work with localhost and byon. Note that the
> values for those are bash commands, not script URLs.
>  * To pass parameters to the above use shell.env.
>  * Here's a tested example:
>
> location: <location>
> services:
> - type: brooklyn.entity.webapp.tomcat.TomcatServer
>  brooklyn.config:
>    files.install:
>
>  "
http://central.maven.org/maven2/org/apache/tomcat/tomcat-dbcp/7.0.30/tomcat-dbcp-7.0.30.jar
":
> apache-tomcat-7.0.56/lib/tomcat-dbcp-7.0.30.jar
>
>  "
http://central.maven.org/maven2/mysql/mysql-connector-java/5.1.10/mysql-connector-java-5.1.10.jar
":
> apache-tomcat-7.0.56/lib/mysql-connector-java-5.1.10.jar
>      "<script url>": "/tmp/myscript.sh"
>    files.runtime:
>
>  "https://provision/tomcat-users.xml <
https://artifactory:AP5QT5YLhmBu3ET9Qe8wwkrNs3r@artifactory.mms.ibmcloud.com/artifactory/ext-release-local/amm-bss/provision/tomcat-users.xml
>":
> conf/tomcat-users.xml
>  pre.install.command: bash <(wget <script url> -qO -)
>  post.install.command: chmod +x /tmp/myscript.sh;/tmp/myscript.sh
>  shell.env:
>    myvar:
> $brooklyn:component("machine").attributeWhenReady("host.address")
> - type: brooklyn.entity.machine.MachineEntity
>  id: machine
>
>
> 2. When you want to copy tomcat libraries you need files.install (as
> used in your example). Since the tomcat distribution is extracted one
> level below the "files.install" folder you need:
>
> files.install:
>  "
http://central.maven.org/maven2/org/apache/tomcat/tomcat-dbcp/7.0.30/tomcat-dbcp-7.0.30.jar
":
> apache-tomcat-7.0.56/lib/tomcat-dbcp-7.0.30.jar
>  "
http://central.maven.org/maven2/mysql/mysql-connector-java/5.1.10/mysql-connector-java-5.1.10.jar
":
> apache-tomcat-7.0.56/lib/mysql-connector-java-5.1.10.jar
>
> For tomcat-users.xml add:
>
> files.runtime:
>  "https://provision/tomcat-users.xml <
https://artifactory:AP5QT5YLhmBu3ET9Qe8wwkrNs3r@artifactory.mms.ibmcloud.com/artifactory/ext-release-local/amm-bss/provision/tomcat-users.xml
>":
> conf/tomcat-users.xml
>
> which will copy the file to the ../apps/../conf folder.
>
> Svet.
>
> > On 22.01.2015 г., at 3:10, Azhar I Hashmi <ai...@us.ibm.com> wrote:
> >
> > Hello,
> >
> > Brooklyn provides a way to define variable and set their value using
> sensor. However, I am not able to successfully use those variables. I
> could not find those variables. I defined them in two different ways
> to use them later in post script but was not able to find them. Here
> is a piece of the YAML blueprint example:
> >
> > memberSpec:
> > $brooklyn:entitySpec:
> > type: brooklyn.entity.webapp.tomcat.TomcatServer
> > id: tomcatServer
> > location:
> > named:standard-location-wdc01:
> > customizerType:
> io.cloudsoft.ibm.mms.amp.location.SoftlayerLocationCustomizer
> > postInstallScriptUri:
> https://USE_VARIABLE_IN_SCRIPT.sh <
https://artifactory:AP5QT5YLhmBu3ET9Qe8wwkrNs3r@artifactory.mms.ibmcloud.com/artifactory/ext-release-local/amm-bss/provision/bss-tomcat.sh
>
> > privateNetworkOnly: false
> > brooklyn.config:
> > https.port: 8443+
> > MY_VARIABLE: $brooklyn:formatString("%s",
> > component("BSSMySQLDB").attributeWhenReady("host.subnet.address"))
> > setup.script:
> https://USE_VARIABLE_IN_SCRIPT <
https://artifactory:AP5QT5YLhmBu3ET9Qe8wwkrNs3r@artifactory.mms.ibmcloud.com/artifactory/ext-release-local/amm-bss/provision/bss-tomcat.sh
>.sh
> > setup.script.vars:
> > $brooklyn:formatString("tomcatPublicIP:%s,runPath:%s,webappUrl:%s",
> > component("tomcatServer").attributeWhenReady("host.address"),
> > component("tomcatServer").attributeWhenReady("run.dir"),
> > component("tomcatServer").attributeWhenReady("webapp.url"))
> >
> > Question 1: How do I use these variables in my scrips?
> > Question 2: I need following jars and xml file in Tomcat/apache
> catalina lib and conf directories respectively. However, following
> piece of yaml blueprint put them under /home/...../install/...../lib/
> and /home/...../install/..../conf/ directories. I need the jar files
> under lib folder of Catalina/tomcat 's lib directory and .xml file
> under /home/..../apps/.......TomcatEntity/conf directory. Is there a
> variable that I can use in <key,value> pair instead of lib/ and conf/
> directories?
> >
> > files.install:
> >
> "
http://central.maven.org/maven2/org/apache/tomcat/tomcat-dbcp/7.0.30/tomcat-dbcp-7.0.30.jar
 <
http://central.maven.org/maven2/org/apache/tomcat/tomcat-dbcp/7.0.30/tomcat-dbcp-7.0.30.jar
>":
> lib/tomcat-dbcp-7.0.30.jar
> >
> "
http://central.maven.org/maven2/mysql/mysql-connector-java/5.1.10/mysql-connector-java-5.1.10.jar
 <
http://central.maven.org/maven2/mysql/mysql-connector-java/5.1.10/mysql-connector-java-5.1.10.jar
>":
> lib/mysql-connector-java-5.1.10.jar
> >
> "https://provision/tomcat-users.xml <
https://artifactory:AP5QT5YLhmBu3ET9Qe8wwkrNs3r@artifactory.mms.ibmcloud.com/artifactory/ext-release-local/amm-bss/provision/tomcat-users.xml
>":
> conf/tomcat-users.xml
> >
> >
> > Thanks
> > Azhar
> >
>
>


Re: "using variable later in postprovisionscript or any other script"

Posted by Alex Heneveld <al...@cloudsoftcorp.com>.
Azhar-

The syntax ${expandedinstal.dir} isn't allowed here.  Brooklyn needs to 
know the context where that variable can be resolved.  So it would have 
to be $brooklyn:config("expandedinstall.dir") or similar for sensors.  
But see the "files.install" documentation -- it is taken relative to the 
install directory, so you can just say:

     files.install:
       
"http://central.maven.org/maven2/org/apache/tomcat/tomcat-dbcp/7.0.30/tomcat-dbcp-7.0.30.jar"*: 
*lib/tomcat-dbcp-7.0.30.jar
       
"http://central.maven.org/maven2/mysql/mysql-connector-java/5.1.10/mysql-connector-java-5.1.10.jar": 
lib/mysql-connector-java-5.1.10.jar

--A



On 23/01/2015 03:54, Azhar I Hashmi wrote:
>
> Alex:
>
> brooklyn.config:
> https.port: 8443+
> tomcat.serverxml: http://tomcat-server.xml 
> <https://artifactory:AP5QT5YLhmBu3ET9Qe8wwkrNs3r@artifactory.mms.ibmcloud.com/artifactory/ext-release-local/amm-bss/provision/bss-tomcat-server.xml>
> MySqlDBPrivateIP: $brooklyn:formatString("jdbc:%s%s",
> component("MySQLDB").attributeWhenReady("datastore.url"), "prod")
> libPath: ${expandedinstal.dir}/lib/tomcat-dbcp-7.0.30.jar
> files.install:
> "http://central.maven.org/maven2/org/apache/tomcat/tomcat-dbcp/7.0.30/tomcat-dbcp-7.0.30.jar"*: 
> $**brooklyn:config("libPath")*
> "http://central.maven.org/maven2/mysql/mysql-connector-java/5.1.10/mysql-connector-java-5.1.10.jar": 
> ${expandedinstal.dir}/lib/mysql-connector-java-5.1.10.jar
> "https://tomcat.sh 
> <https://artifactory:AP5QT5YLhmBu3ET9Qe8wwkrNs3r@artifactory.mms.ibmcloud.com/artifactory/ext-release-local/amm-bss/provision/bss-tomcat.sh>": 
> /tmp/tomcat-setup-script.sh
>
>
> Throws this error:
>
> Cannot coerce or set
> {http://central.maven.org/maven2/org/apache/tomcat/tomcat-dbcp/7.0.30/tomcat-dbcp-7.0.30.jar=*$brooklyn:component(THIS, 
> ).config(libPath),*
> http://central.maven.org/maven2/mysql/mysql-connector-java/5.1.10/mysql-connector-java-5.1.10.jar=${expandedinstal.dir}/lib/mysql-connector-java-5.1.10.jar,
> https://tomcat.sh=/tmp/tomcat-setup-script.sh}
> to files.install[ConfigKey:java.util.Map
>
>
> What is correct syntax here?
>
> Thanks
> Azhar
>
>
>
> Inactive hide details for Alex Heneveld ---01/22/2015 05:29:30 
> PM---Azhar- What you propose I think could work. But I think itAlex 
> Heneveld ---01/22/2015 05:29:30 PM---Azhar- What you propose I think 
> could work. But I think it would also work and
>
> From: Alex Heneveld <al...@cloudsoftcorp.com>
> To: dev@brooklyn.incubator.apache.org
> Date: 01/22/2015 05:29 PM
> Subject: Re: "using variable later in postprovisionscript or any other 
> script"
>
> ------------------------------------------------------------------------
>
>
>
>
> Azhar-
>
> What you propose I think could work.  But I think it would also work and
> be cleaner to split out your config, e.g.
>
>   brooklyn.config:
>     myvarA:
> $brooklyn:component("machine").attributeWhenReady("host.address")
>   shell.env:
> *m**yvar1: $brooklyn:config**("myvarA"*)
>
> and then in templates refer to ${config.myvarA}.
>
> Only subtlety is that "myvarA" *must* be in `brooklyn.config` because it
> is not a type-defined config key.  `shell.env` could be put under
> `brooklyn.config` or at the top level because it *is* a config key known
> at the type.  (It has a flag/alias "env" so you could also just call it
> `env`.)
>
> HTH + thanks for the nice comments on the new docs!
>
> --A
>
>


Re: "using variable later in postprovisionscript or any other script"

Posted by Azhar I Hashmi <ai...@us.ibm.com>.

Alex:

  brooklyn.config:
    https.port: 8443+
    tomcat.serverxml: http://tomcat-server.xml
    MySqlDBPrivateIP: $brooklyn:formatString("jdbc:%s%s",
              component("MySQLDB").attributeWhenReady("datastore.url"),
"prod")
    libPath: ${expandedinstal.dir}/lib/tomcat-dbcp-7.0.30.jar
    files.install:
      "
http://central.maven.org/maven2/org/apache/tomcat/tomcat-dbcp/7.0.30/tomcat-dbcp-7.0.30.jar
": $brooklyn:config("libPath")
      "
http://central.maven.org/maven2/mysql/mysql-connector-java/5.1.10/mysql-connector-java-5.1.10.jar
": ${expandedinstal.dir}/lib/mysql-connector-java-5.1.10.jar
      "https://tomcat.sh": /tmp/tomcat-setup-script.sh


Throws this error:

Cannot coerce or set

{http://central.maven.org/maven2/org/apache/tomcat/tomcat-dbcp/7.0.30/tomcat-dbcp-7.0.30.jar=
$brooklyn:component(THIS, ).config(libPath),

http://central.maven.org/maven2/mysql/mysql-connector-java/5.1.10/mysql-connector-java-5.1.10.jar=
${expandedinstal.dir}/lib/mysql-connector-java-5.1.10.jar,
 https://tomcat.sh=/tmp/tomcat-setup-script.sh}
 to files.install[ConfigKey:java.util.Map


What is correct syntax here?

Thanks
Azhar





From:	Alex Heneveld <al...@cloudsoftcorp.com>
To:	dev@brooklyn.incubator.apache.org
Date:	01/22/2015 05:29 PM
Subject:	Re: "using variable later in postprovisionscript or any other
            script"




Azhar-

What you propose I think could work.  But I think it would also work and
be cleaner to split out your config, e.g.

   brooklyn.config:
     myvarA:
$brooklyn:component("machine").attributeWhenReady("host.address")
   shell.env:
     myvar1: $brooklyn:config("myvarA")

and then in templates refer to ${config.myvarA}.

Only subtlety is that "myvarA" *must* be in `brooklyn.config` because it
is not a type-defined config key.  `shell.env` could be put under
`brooklyn.config` or at the top level because it *is* a config key known
at the type.  (It has a flag/alias "env" so you could also just call it
`env`.)

HTH + thanks for the nice comments on the new docs!

--A


Re: "using variable later in postprovisionscript or any other script"

Posted by Alex Heneveld <al...@cloudsoftcorp.com>.
Azhar-

What you propose I think could work.  But I think it would also work and 
be cleaner to split out your config, e.g.

   brooklyn.config:
     myvarA: 
$brooklyn:component("machine").attributeWhenReady("host.address")
   shell.env:
     myvar1: $brooklyn:config("myvarA")

and then in templates refer to ${config.myvarA}.

Only subtlety is that "myvarA" *must* be in `brooklyn.config` because it 
is not a type-defined config key.  `shell.env` could be put under 
`brooklyn.config` or at the top level because it *is* a config key known 
at the type.  (It has a flag/alias "env" so you could also just call it 
`env`.)

HTH + thanks for the nice comments on the new docs!

--A


On 22/01/2015 22:59, Azhar I Hashmi wrote:
>
> Thanks a lot Svet!
>
> Actually, I figured that there is files.runtime that I can use exactly 
> as you described and also came to know env.shell after our call and I 
> love the new documentation related to Entity's config, sensor etc.....
>
> Couple of questions:
> Instead of hard coding the path like this: I saw in the doc that there 
> is a config to get to that path i.e. "*expandedinstall.dir". *Do you 
> think I can use config variable to get that value?
>
> files.install:
>     
>  "http://central.maven.org/maven2/org/apache/tomcat/tomcat-dbcp/7.0.30/tomcat-dbcp-7.0.30.jar": 
> apache-tomcat-7.0.56/lib/tomcat-dbcp-7.0.30.jar
>
> Can I do this for example:
>
> files.install:
>     
>  "http://central.maven.org/maven2/org/apache/tomcat/tomcat-dbcp/7.0.30/tomcat-dbcp-7.0.30.jar": 
> *${expandedinstal.dir}*/lib/tomcat-dbcp-7.0.30.jar
> (OR)
>       
> "http://central.maven.org/maven2/org/apache/tomcat/tomcat-dbcp/7.0.30/tomcat-dbcp-7.0.30.jar": 
> *${config.expandedinstal.dir}*/lib/tomcat-dbcp-7.0.30.jar
>
> Also:
>
>
> According to the definition it takes a java map. So in your example:
>
> shell.env:
>    myvar: 
> $brooklyn:component("machine").attributeWhenReady("host.address")
> - type: brooklyn.entity.machine.MachineEntity
>  id: machine
> I can have multiple vars like this:
>
> shell.env:
> *myvar1: 
> $brooklyn:component("machine").attributeWhenReady("host.address")*
> *    myvar2: 
> $brooklyn:component("TOMCAT_ID").attributeWhenReady("host.address")*
> *    myvar3: 
> $brooklyn:component("MY_SQLID").attributeWhenReady("host.subnet.address")*
> - type: brooklyn.entity.machine.MachineEntity
>
>
> Also, in my */tmp/script.sh*
>
> Can I do this *${config.shell.env.myvar1} , 
> ${config.shell.env.myvar2},* and *${config.shell.env.myvar3}* to get 
> their values that are set by brooklyn? Is my understanding correct? If 
> not please correct me.
>
>
> Thanks a lot!
>
> Azhar
>
> Inactive hide details for Svetoslav Neykov ---01/22/2015 04:44:06 
> AM---Hi Azhar, I tried your blueprint and here's what I founSvetoslav 
> Neykov ---01/22/2015 04:44:06 AM---Hi Azhar, I tried your blueprint 
> and here's what I found out:
>
> From: Svetoslav Neykov <sv...@cloudsoftcorp.com>
> To: dev@brooklyn.incubator.apache.org
> Date: 01/22/2015 04:44 AM
> Subject: Re: "using variable later in postprovisionscript or any other 
> script"
>
> ------------------------------------------------------------------------
>
>
>
> Hi Azhar,
>
> I tried your blueprint and here's what I found out:
> 1.
>  * setup.script needs to be specified inside the location. I tried to 
> pass it inside the entity config, but it's not picked up.
>  * setup.script can be used only with jclouds locations. It's doesn't 
> get executed for localhost or byon.
>  * When passing formatString parameters to setup.script.vars you will 
> get a " Cannot coerce type class " exception. It's not supported 
> currently.
>  * setup.script should only be used for system-wide configuration 
> where you don't need dynamic parameters.
>  * In your case it's best to move all tomcat configuration from your 
> script into a custom server.conf template and pass it to the entity. 
> To access the entity config use ${config.MY_VARIABLE}.
>  * If you really need to pass variables to a script then you can use 
> one of pre.install.command, post.install.command. The former will get 
> executed before any installation steps take place so if you need to 
> execute a script download it from a URL. The latter can use the files 
> from files.install. Both work with localhost and byon. Note that the 
> values for those are bash commands, not script URLs.
>  * To pass parameters to the above use shell.env.
>  * Here's a tested example:
>
> location: <location>
> services:
> - type: brooklyn.entity.webapp.tomcat.TomcatServer
>  brooklyn.config:
>    files.install:
>     
>  "http://central.maven.org/maven2/org/apache/tomcat/tomcat-dbcp/7.0.30/tomcat-dbcp-7.0.30.jar": 
> apache-tomcat-7.0.56/lib/tomcat-dbcp-7.0.30.jar
>     
>  "http://central.maven.org/maven2/mysql/mysql-connector-java/5.1.10/mysql-connector-java-5.1.10.jar": 
> apache-tomcat-7.0.56/lib/mysql-connector-java-5.1.10.jar
>      "<script url>": "/tmp/myscript.sh"
>    files.runtime:
>     
>  "https://provision/tomcat-users.xml <https://artifactory:AP5QT5YLhmBu3ET9Qe8wwkrNs3r@artifactory.mms.ibmcloud.com/artifactory/ext-release-local/amm-bss/provision/tomcat-users.xml>": 
> conf/tomcat-users.xml
>  pre.install.command: bash <(wget <script url> -qO -)
>  post.install.command: chmod +x /tmp/myscript.sh;/tmp/myscript.sh
>  shell.env:
>    myvar: 
> $brooklyn:component("machine").attributeWhenReady("host.address")
> - type: brooklyn.entity.machine.MachineEntity
>  id: machine
>
>
> 2. When you want to copy tomcat libraries you need files.install (as 
> used in your example). Since the tomcat distribution is extracted one 
> level below the "files.install" folder you need:
>
> files.install:
>  "http://central.maven.org/maven2/org/apache/tomcat/tomcat-dbcp/7.0.30/tomcat-dbcp-7.0.30.jar": 
> apache-tomcat-7.0.56/lib/tomcat-dbcp-7.0.30.jar
>  "http://central.maven.org/maven2/mysql/mysql-connector-java/5.1.10/mysql-connector-java-5.1.10.jar": 
> apache-tomcat-7.0.56/lib/mysql-connector-java-5.1.10.jar
>
> For tomcat-users.xml add:
>
> files.runtime:
>  "https://provision/tomcat-users.xml <https://artifactory:AP5QT5YLhmBu3ET9Qe8wwkrNs3r@artifactory.mms.ibmcloud.com/artifactory/ext-release-local/amm-bss/provision/tomcat-users.xml>": 
> conf/tomcat-users.xml
>
> which will copy the file to the ../apps/../conf folder.
>
> Svet.
>
> > On 22.01.2015 г., at 3:10, Azhar I Hashmi <ai...@us.ibm.com> wrote:
> >
> > Hello,
> >
> > Brooklyn provides a way to define variable and set their value using 
> sensor. However, I am not able to successfully use those variables. I 
> could not find those variables. I defined them in two different ways 
> to use them later in post script but was not able to find them. Here 
> is a piece of the YAML blueprint example:
> >
> > memberSpec:
> > $brooklyn:entitySpec:
> > type: brooklyn.entity.webapp.tomcat.TomcatServer
> > id: tomcatServer
> > location:
> > named:standard-location-wdc01:
> > customizerType: 
> io.cloudsoft.ibm.mms.amp.location.SoftlayerLocationCustomizer
> > postInstallScriptUri: 
> https://USE_VARIABLE_IN_SCRIPT.sh <https://artifactory:AP5QT5YLhmBu3ET9Qe8wwkrNs3r@artifactory.mms.ibmcloud.com/artifactory/ext-release-local/amm-bss/provision/bss-tomcat.sh>
> > privateNetworkOnly: false
> > brooklyn.config:
> > https.port: 8443+
> > MY_VARIABLE: $brooklyn:formatString("%s",
> > component("BSSMySQLDB").attributeWhenReady("host.subnet.address"))
> > setup.script: 
> https://USE_VARIABLE_IN_SCRIPT <https://artifactory:AP5QT5YLhmBu3ET9Qe8wwkrNs3r@artifactory.mms.ibmcloud.com/artifactory/ext-release-local/amm-bss/provision/bss-tomcat.sh>.sh
> > setup.script.vars:
> > $brooklyn:formatString("tomcatPublicIP:%s,runPath:%s,webappUrl:%s",
> > component("tomcatServer").attributeWhenReady("host.address"),
> > component("tomcatServer").attributeWhenReady("run.dir"),
> > component("tomcatServer").attributeWhenReady("webapp.url"))
> >
> > Question 1: How do I use these variables in my scrips?
> > Question 2: I need following jars and xml file in Tomcat/apache 
> catalina lib and conf directories respectively. However, following 
> piece of yaml blueprint put them under /home/...../install/...../lib/ 
> and /home/...../install/..../conf/ directories. I need the jar files 
> under lib folder of Catalina/tomcat 's lib directory and .xml file 
> under /home/..../apps/.......TomcatEntity/conf directory. Is there a 
> variable that I can use in <key,value> pair instead of lib/ and conf/ 
> directories?
> >
> > files.install:
> > 
> "http://central.maven.org/maven2/org/apache/tomcat/tomcat-dbcp/7.0.30/tomcat-dbcp-7.0.30.jar <http://central.maven.org/maven2/org/apache/tomcat/tomcat-dbcp/7.0.30/tomcat-dbcp-7.0.30.jar>": 
> lib/tomcat-dbcp-7.0.30.jar
> > 
> "http://central.maven.org/maven2/mysql/mysql-connector-java/5.1.10/mysql-connector-java-5.1.10.jar <http://central.maven.org/maven2/mysql/mysql-connector-java/5.1.10/mysql-connector-java-5.1.10.jar>": 
> lib/mysql-connector-java-5.1.10.jar
> > 
> "https://provision/tomcat-users.xml <https://artifactory:AP5QT5YLhmBu3ET9Qe8wwkrNs3r@artifactory.mms.ibmcloud.com/artifactory/ext-release-local/amm-bss/provision/tomcat-users.xml>": 
> conf/tomcat-users.xml
> >
> >
> > Thanks
> > Azhar
> >
>
>


Re: "using variable later in postprovisionscript or any other script"

Posted by Azhar I Hashmi <ai...@us.ibm.com>.
Thanks a lot Svet!

Actually, I figured that there is files.runtime that I can use exactly as
you  described and also came to know env.shell after our call and I love
the new documentation related to Entity's config, sensor etc.....

Couple of questions:
Instead of hard coding the path like this: I saw in the doc that there is a
config to get to that path i.e.  "expandedinstall.dir". Do you think I can
use config variable to get that value?

files.install:
      "
http://central.maven.org/maven2/org/apache/tomcat/tomcat-dbcp/7.0.30/tomcat-dbcp-7.0.30.jar
": apache-tomcat-7.0.56/lib/tomcat-dbcp-7.0.30.jar

Can I do this for example:

files.install:
      "
http://central.maven.org/maven2/org/apache/tomcat/tomcat-dbcp/7.0.30/tomcat-dbcp-7.0.30.jar
": ${expandedinstal.dir}/lib/tomcat-dbcp-7.0.30.jar
(OR)
      "
http://central.maven.org/maven2/org/apache/tomcat/tomcat-dbcp/7.0.30/tomcat-dbcp-7.0.30.jar
": ${config.expandedinstal.dir}/lib/tomcat-dbcp-7.0.30.jar

Also:


According to the definition it takes a java map. So in your example:

shell.env:
    myvar: $brooklyn:component("machine").attributeWhenReady
("host.address")
- type: brooklyn.entity.machine.MachineEntity
  id: machine
I can have multiple vars like this:

shell.env:
    myvar1: $brooklyn:component("machine").attributeWhenReady
("host.address")
    myvar2: $brooklyn:component("TOMCAT_ID").attributeWhenReady
("host.address")
    myvar3: $brooklyn:component("MY_SQLID").attributeWhenReady
("host.subnet.address")
- type: brooklyn.entity.machine.MachineEntity


Also, in my /tmp/script.sh

Can I do this ${config.shell.env.myvar1} , ${config.shell.env.myvar2}, and
${config.shell.env.myvar3} to get their values that are set by brooklyn?
Is my understanding correct? If not please correct me.


Thanks a lot!

Azhar



From:	Svetoslav Neykov <sv...@cloudsoftcorp.com>
To:	dev@brooklyn.incubator.apache.org
Date:	01/22/2015 04:44 AM
Subject:	Re: "using variable later in postprovisionscript or any other
            script"



Hi Azhar,

I tried your blueprint and here?s what I found out:
1.
  * setup.script needs to be specified inside the location. I tried to pass
it inside the entity config, but it?s not picked up.
  * setup.script can be used only with jclouds locations. It?s doesn?t get
executed for localhost or byon.
  * When passing formatString parameters to setup.script.vars you will get
a " Cannot coerce type class ? exception. It?s not supported currently.
  * setup.script should only be used for system-wide configuration where
you don?t need dynamic parameters.
  * In your case it?s best to move all tomcat configuration from your
script into a custom server.conf template and pass it to the entity. To
access the entity config use ${config.MY_VARIABLE}.
  * If you really need to pass variables to a script then you can use one
of pre.install.command, post.install.command. The former will get executed
before any installation steps take place so if you need to execute a script
download it from a URL. The latter can use the files from files.install.
Both work with localhost and byon. Note that the values for those are bash
commands, not script URLs.
  * To pass parameters to the above use shell.env.
  * Here?s a tested example:

location: <location>
services:
- type: brooklyn.entity.webapp.tomcat.TomcatServer
  brooklyn.config:
    files.install:
      "
http://central.maven.org/maven2/org/apache/tomcat/tomcat-dbcp/7.0.30/tomcat-dbcp-7.0.30.jar
": apache-tomcat-7.0.56/lib/tomcat-dbcp-7.0.30.jar
      "
http://central.maven.org/maven2/mysql/mysql-connector-java/5.1.10/mysql-connector-java-5.1.10.jar
": apache-tomcat-7.0.56/lib/mysql-connector-java-5.1.10.jar
      ?<script url>": "/tmp/myscript.sh"
    files.runtime:
      "https://provision/tomcat-users.xml <
https://artifactory:AP5QT5YLhmBu3ET9Qe8wwkrNs3r@artifactory.mms.ibmcloud.com/artifactory/ext-release-local/amm-bss/provision/tomcat-users.xml
>": conf/tomcat-users.xml
  pre.install.command: bash <(wget <script url> -qO -)
  post.install.command: chmod +x /tmp/myscript.sh;/tmp/myscript.sh
  shell.env:
    myvar: $brooklyn:component("machine").attributeWhenReady
("host.address")
- type: brooklyn.entity.machine.MachineEntity
  id: machine


2. When you want to copy tomcat libraries you need files.install (as used
in your example). Since the tomcat distribution is extracted one level
below the ?files.install? folder you need:

files.install:
  "
http://central.maven.org/maven2/org/apache/tomcat/tomcat-dbcp/7.0.30/tomcat-dbcp-7.0.30.jar
": apache-tomcat-7.0.56/lib/tomcat-dbcp-7.0.30.jar
  "
http://central.maven.org/maven2/mysql/mysql-connector-java/5.1.10/mysql-connector-java-5.1.10.jar
": apache-tomcat-7.0.56/lib/mysql-connector-java-5.1.10.jar

For tomcat-users.xml add:

files.runtime:
  "https://provision/tomcat-users.xml <
https://artifactory:AP5QT5YLhmBu3ET9Qe8wwkrNs3r@artifactory.mms.ibmcloud.com/artifactory/ext-release-local/amm-bss/provision/tomcat-users.xml
>": conf/tomcat-users.xml

which will copy the file to the ../apps/../conf folder.

Svet.

> On 22.01.2015 г., at 3:10, Azhar I Hashmi <ai...@us.ibm.com> wrote:
>
> Hello,
>
> Brooklyn provides a way to define variable and set their value using
sensor. However, I am not able to successfully use those variables. I could
not find those variables. I defined them in two different ways to use them
later in post script but was not able to find them. Here is a piece of the
YAML blueprint example:
>
> memberSpec:
> $brooklyn:entitySpec:
> type: brooklyn.entity.webapp.tomcat.TomcatServer
> id: tomcatServer
> location:
> named:standard-location-wdc01:
> customizerType:
io.cloudsoft.ibm.mms.amp.location.SoftlayerLocationCustomizer
> postInstallScriptUri: https://USE_VARIABLE_IN_SCRIPT.sh <
https://artifactory:AP5QT5YLhmBu3ET9Qe8wwkrNs3r@artifactory.mms.ibmcloud.com/artifactory/ext-release-local/amm-bss/provision/bss-tomcat.sh
>
> privateNetworkOnly: false
> brooklyn.config:
> https.port: 8443+
> MY_VARIABLE: $brooklyn:formatString("%s",
> component("BSSMySQLDB").attributeWhenReady("host.subnet.address"))
> setup.script: https://USE_VARIABLE_IN_SCRIPT <
https://artifactory:AP5QT5YLhmBu3ET9Qe8wwkrNs3r@artifactory.mms.ibmcloud.com/artifactory/ext-release-local/amm-bss/provision/bss-tomcat.sh
>.sh
> setup.script.vars:
> $brooklyn:formatString("tomcatPublicIP:%s,runPath:%s,webappUrl:%s",
> component("tomcatServer").attributeWhenReady("host.address"),
> component("tomcatServer").attributeWhenReady("run.dir"),
> component("tomcatServer").attributeWhenReady("webapp.url"))
>
> Question 1: How do I use these variables in my scrips?
> Question 2: I need following jars and xml file in Tomcat/apache catalina
lib and conf directories respectively. However, following piece of yaml
blueprint put them under /home/...../install/...../lib/
and /home/...../install/..../conf/ directories. I need the jar files under
lib folder of Catalina/tomcat 's lib directory and .xml file
under /home/..../apps/.......TomcatEntity/conf directory. Is there a
variable that I can use in <key,value> pair instead of lib/ and conf/
directories?
>
> files.install:
> "
http://central.maven.org/maven2/org/apache/tomcat/tomcat-dbcp/7.0.30/tomcat-dbcp-7.0.30.jar
 <
http://central.maven.org/maven2/org/apache/tomcat/tomcat-dbcp/7.0.30/tomcat-dbcp-7.0.30.jar
>": lib/tomcat-dbcp-7.0.30.jar
> "
http://central.maven.org/maven2/mysql/mysql-connector-java/5.1.10/mysql-connector-java-5.1.10.jar
 <
http://central.maven.org/maven2/mysql/mysql-connector-java/5.1.10/mysql-connector-java-5.1.10.jar
>": lib/mysql-connector-java-5.1.10.jar
> "https://provision/tomcat-users.xml <
https://artifactory:AP5QT5YLhmBu3ET9Qe8wwkrNs3r@artifactory.mms.ibmcloud.com/artifactory/ext-release-local/amm-bss/provision/tomcat-users.xml
>": conf/tomcat-users.xml
>
>
> Thanks
> Azhar
>


NEW DOC-- AWESOME! But......

Posted by Azhar I Hashmi <ai...@us.ibm.com>.
Hello guys,

I loved the new doc:
https://brooklyn.incubator.apache.org/learnmore/catalog/index.html
It really helped me a lot to understand and to use config/sensors etc....

However, this new doc is still incomplete for some entries for example:  It
is missing some of the configs.  In Tomcat entity it does not have
files.install. I believe it should be there b/c I used it and it works
fine.

The other issue is the description is not complete. For example:



This does not tell what should be the key in this map.  For example, I
cannot put any customize keys like  ":my_ram_key". I do not think customize
keys are supported by Brooklyn yet. I think document should list all
possible values for the map that Brooklyn   can understand and consume. For
example:
           minRam, minCores and minDisk, etc....

And provide an example, like this:

provisioning.properties:
  minRam: 2048mb
  minCores: 2
  minDisk: 25gb


Similarly, I have no idea what is it mean that "(will substitute things
like ${version} automatically)" if my download.url: http:// MY_URL how come
it will be replaced in version ?????




Thanks

Azhar





From:	Svetoslav Neykov <sv...@cloudsoftcorp.com>
To:	dev@brooklyn.incubator.apache.org
Date:	01/22/2015 04:44 AM
Subject:	Re: "using variable later in postprovisionscript or any other
            script"



Hi Azhar,

I tried your blueprint and here?s what I found out:
1.
  * setup.script needs to be specified inside the location. I tried to pass
it inside the entity config, but it?s not picked up.
  * setup.script can be used only with jclouds locations. It?s doesn?t get
executed for localhost or byon.
  * When passing formatString parameters to setup.script.vars you will get
a " Cannot coerce type class ? exception. It?s not supported currently.
  * setup.script should only be used for system-wide configuration where
you don?t need dynamic parameters.
  * In your case it?s best to move all tomcat configuration from your
script into a custom server.conf template and pass it to the entity. To
access the entity config use ${config.MY_VARIABLE}.
  * If you really need to pass variables to a script then you can use one
of pre.install.command, post.install.command. The former will get executed
before any installation steps take place so if you need to execute a script
download it from a URL. The latter can use the files from files.install.
Both work with localhost and byon. Note that the values for those are bash
commands, not script URLs.
  * To pass parameters to the above use shell.env.
  * Here?s a tested example:

location: <location>
services:
- type: brooklyn.entity.webapp.tomcat.TomcatServer
  brooklyn.config:
    files.install:
      "
http://central.maven.org/maven2/org/apache/tomcat/tomcat-dbcp/7.0.30/tomcat-dbcp-7.0.30.jar
": apache-tomcat-7.0.56/lib/tomcat-dbcp-7.0.30.jar
      "
http://central.maven.org/maven2/mysql/mysql-connector-java/5.1.10/mysql-connector-java-5.1.10.jar
": apache-tomcat-7.0.56/lib/mysql-connector-java-5.1.10.jar
      ?<script url>": "/tmp/myscript.sh"
    files.runtime:
      "https://provision/tomcat-users.xml <
https://artifactory:AP5QT5YLhmBu3ET9Qe8wwkrNs3r@artifactory.mms.ibmcloud.com/artifactory/ext-release-local/amm-bss/provision/tomcat-users.xml
>": conf/tomcat-users.xml
  pre.install.command: bash <(wget <script url> -qO -)
  post.install.command: chmod +x /tmp/myscript.sh;/tmp/myscript.sh
  shell.env:
    myvar: $brooklyn:component("machine").attributeWhenReady
("host.address")
- type: brooklyn.entity.machine.MachineEntity
  id: machine


2. When you want to copy tomcat libraries you need files.install (as used
in your example). Since the tomcat distribution is extracted one level
below the ?files.install? folder you need:

files.install:
  "
http://central.maven.org/maven2/org/apache/tomcat/tomcat-dbcp/7.0.30/tomcat-dbcp-7.0.30.jar
": apache-tomcat-7.0.56/lib/tomcat-dbcp-7.0.30.jar
  "
http://central.maven.org/maven2/mysql/mysql-connector-java/5.1.10/mysql-connector-java-5.1.10.jar
": apache-tomcat-7.0.56/lib/mysql-connector-java-5.1.10.jar

For tomcat-users.xml add:

files.runtime:
  "https://provision/tomcat-users.xml <
https://artifactory:AP5QT5YLhmBu3ET9Qe8wwkrNs3r@artifactory.mms.ibmcloud.com/artifactory/ext-release-local/amm-bss/provision/tomcat-users.xml
>": conf/tomcat-users.xml

which will copy the file to the ../apps/../conf folder.

Svet.

> On 22.01.2015 г., at 3:10, Azhar I Hashmi <ai...@us.ibm.com> wrote:
>
> Hello,
>
> Brooklyn provides a way to define variable and set their value using
sensor. However, I am not able to successfully use those variables. I could
not find those variables. I defined them in two different ways to use them
later in post script but was not able to find them. Here is a piece of the
YAML blueprint example:
>
> memberSpec:
> $brooklyn:entitySpec:
> type: brooklyn.entity.webapp.tomcat.TomcatServer
> id: tomcatServer
> location:
> named:standard-location-wdc01:
> customizerType:
io.cloudsoft.ibm.mms.amp.location.SoftlayerLocationCustomizer
> postInstallScriptUri: https://USE_VARIABLE_IN_SCRIPT.sh <
https://artifactory:AP5QT5YLhmBu3ET9Qe8wwkrNs3r@artifactory.mms.ibmcloud.com/artifactory/ext-release-local/amm-bss/provision/bss-tomcat.sh
>
> privateNetworkOnly: false
> brooklyn.config:
> https.port: 8443+
> MY_VARIABLE: $brooklyn:formatString("%s",
> component("BSSMySQLDB").attributeWhenReady("host.subnet.address"))
> setup.script: https://USE_VARIABLE_IN_SCRIPT <
https://artifactory:AP5QT5YLhmBu3ET9Qe8wwkrNs3r@artifactory.mms.ibmcloud.com/artifactory/ext-release-local/amm-bss/provision/bss-tomcat.sh
>.sh
> setup.script.vars:
> $brooklyn:formatString("tomcatPublicIP:%s,runPath:%s,webappUrl:%s",
> component("tomcatServer").attributeWhenReady("host.address"),
> component("tomcatServer").attributeWhenReady("run.dir"),
> component("tomcatServer").attributeWhenReady("webapp.url"))
>
> Question 1: How do I use these variables in my scrips?
> Question 2: I need following jars and xml file in Tomcat/apache catalina
lib and conf directories respectively. However, following piece of yaml
blueprint put them under /home/...../install/...../lib/
and /home/...../install/..../conf/ directories. I need the jar files under
lib folder of Catalina/tomcat 's lib directory and .xml file
under /home/..../apps/.......TomcatEntity/conf directory. Is there a
variable that I can use in <key,value> pair instead of lib/ and conf/
directories?
>
> files.install:
> "
http://central.maven.org/maven2/org/apache/tomcat/tomcat-dbcp/7.0.30/tomcat-dbcp-7.0.30.jar
 <
http://central.maven.org/maven2/org/apache/tomcat/tomcat-dbcp/7.0.30/tomcat-dbcp-7.0.30.jar
>": lib/tomcat-dbcp-7.0.30.jar
> "
http://central.maven.org/maven2/mysql/mysql-connector-java/5.1.10/mysql-connector-java-5.1.10.jar
 <
http://central.maven.org/maven2/mysql/mysql-connector-java/5.1.10/mysql-connector-java-5.1.10.jar
>": lib/mysql-connector-java-5.1.10.jar
> "https://provision/tomcat-users.xml <
https://artifactory:AP5QT5YLhmBu3ET9Qe8wwkrNs3r@artifactory.mms.ibmcloud.com/artifactory/ext-release-local/amm-bss/provision/tomcat-users.xml
>": conf/tomcat-users.xml
>
>
> Thanks
> Azhar
>


Re: "using variable later in postprovisionscript or any other script"

Posted by Azhar I Hashmi <ai...@us.ibm.com>.
Hi Stev,

I have a question related to the statement:

"* When passing formatString parameters to setup.script.vars you will get a
" Cannot coerce type class “ exception. It’s not supported currently."

Actually, I used formatString in following yaml and i did not get any
error.  However, I did not try to use these variables in my script later on
as a post.launch.command.

- type: brooklyn.entity.database.mysql.MySqlNode
  id: MySQLDB
  name: MySql DB
  location:
.......
.....

  brooklyn.config:
    datastore.creation.script.url: https://my.sql
    bssTomcatPrivateIP: $brooklyn:formatString("jdbc:%s/%s",
              component("TomcatServer").attributeWhenReady
("host.subnet.address"), "MY_DB")
    setup.script.vars:
        $brooklyn:formatString("TomcatPrivateIP:%s, TomcatPublicIP2:%s",
                                component
("TomcatServer").attributeWhenReady("host.subnet.address"),
                                component
("TomcatServer").attributeWhenReady("host.address"))
    provisioning.properties:
      minRam: 2048mb
      minCores: 2
      minDisk: 100gb

Out of curiosity, these setup.script,.var only for setup.script  value? In
other words, these setup script variables can ONLY be used in the script
that I pass in setup.script config?  If answer is NO i.e. these variables
can be used in any script like I can run a script in post.install.command
that can use these variables.

Can you please give me an example how would I use them in a script like:  $
{config.setup,scripts.var.TomcatPrivateIP}  and  $
{config.setup,scripts.var.TomcatPublicIP2} to get values? Or is there a
better way ?

Thanks
Azhar




From:	Svetoslav Neykov <sv...@cloudsoftcorp.com>
To:	dev@brooklyn.incubator.apache.org
Date:	01/22/2015 04:44 AM
Subject:	Re: "using variable later in postprovisionscript or any other
            script"



Hi Azhar,

I tried your blueprint and here’s what I found out:
1.
  * setup.script needs to be specified inside the location. I tried to pass
it inside the entity config, but it’s not picked up.
  * setup.script can be used only with jclouds locations. It’s doesn’t get
executed for localhost or byon.
  * When passing formatString parameters to setup.script.vars you will get
a " Cannot coerce type class “ exception. It’s not supported currently.
  * setup.script should only be used for system-wide configuration where
you don’t need dynamic parameters.
  * In your case it’s best to move all tomcat configuration from your
script into a custom server.conf template and pass it to the entity. To
access the entity config use ${config.MY_VARIABLE}.
  * If you really need to pass variables to a script then you can use one
of pre.install.command, post.install.command. The former will get executed
before any installation steps take place so if you need to execute a script
download it from a URL. The latter can use the files from files.install.
Both work with localhost and byon. Note that the values for those are bash
commands, not script URLs.
  * To pass parameters to the above use shell.env.


Re: "using variable later in postprovisionscript or any other script"

Posted by Svetoslav Neykov <sv...@cloudsoftcorp.com>.
Hi Azhar,

I tried your blueprint and here’s what I found out:
1. 
  * setup.script needs to be specified inside the location. I tried to pass it inside the entity config, but it’s not picked up.
  * setup.script can be used only with jclouds locations. It’s doesn’t get executed for localhost or byon.
  * When passing formatString parameters to setup.script.vars you will get a " Cannot coerce type class “ exception. It’s not supported currently.
  * setup.script should only be used for system-wide configuration where you don’t need dynamic parameters.
  * In your case it’s best to move all tomcat configuration from your script into a custom server.conf template and pass it to the entity. To access the entity config use ${config.MY_VARIABLE}.
  * If you really need to pass variables to a script then you can use one of pre.install.command, post.install.command. The former will get executed before any installation steps take place so if you need to execute a script download it from a URL. The latter can use the files from files.install. Both work with localhost and byon. Note that the values for those are bash commands, not script URLs.
  * To pass parameters to the above use shell.env.
  * Here’s a tested example:

location: <location>
services:
- type: brooklyn.entity.webapp.tomcat.TomcatServer
  brooklyn.config:
    files.install:
      "http://central.maven.org/maven2/org/apache/tomcat/tomcat-dbcp/7.0.30/tomcat-dbcp-7.0.30.jar": apache-tomcat-7.0.56/lib/tomcat-dbcp-7.0.30.jar
      "http://central.maven.org/maven2/mysql/mysql-connector-java/5.1.10/mysql-connector-java-5.1.10.jar": apache-tomcat-7.0.56/lib/mysql-connector-java-5.1.10.jar   
      “<script url>": "/tmp/myscript.sh"
    files.runtime:
      "https://provision/tomcat-users.xml <https://artifactory:AP5QT5YLhmBu3ET9Qe8wwkrNs3r@artifactory.mms.ibmcloud.com/artifactory/ext-release-local/amm-bss/provision/tomcat-users.xml>": conf/tomcat-users.xml
  pre.install.command: bash <(wget <script url> -qO -)
  post.install.command: chmod +x /tmp/myscript.sh;/tmp/myscript.sh
  shell.env: 
    myvar: $brooklyn:component("machine").attributeWhenReady("host.address")
- type: brooklyn.entity.machine.MachineEntity
  id: machine


2. When you want to copy tomcat libraries you need files.install (as used in your example). Since the tomcat distribution is extracted one level below the “files.install” folder you need:

files.install:
  "http://central.maven.org/maven2/org/apache/tomcat/tomcat-dbcp/7.0.30/tomcat-dbcp-7.0.30.jar": apache-tomcat-7.0.56/lib/tomcat-dbcp-7.0.30.jar
  "http://central.maven.org/maven2/mysql/mysql-connector-java/5.1.10/mysql-connector-java-5.1.10.jar": apache-tomcat-7.0.56/lib/mysql-connector-java-5.1.10.jar   

For tomcat-users.xml add:

files.runtime:
  "https://provision/tomcat-users.xml <https://artifactory:AP5QT5YLhmBu3ET9Qe8wwkrNs3r@artifactory.mms.ibmcloud.com/artifactory/ext-release-local/amm-bss/provision/tomcat-users.xml>": conf/tomcat-users.xml

which will copy the file to the ../apps/../conf folder.

Svet.

> On 22.01.2015 г., at 3:10, Azhar I Hashmi <ai...@us.ibm.com> wrote:
> 
> Hello,
> 
> Brooklyn provides a way to define variable and set their value using sensor. However, I am not able to successfully use those variables. I could not find those variables. I defined them in two different ways to use them later in post script but was not able to find them. Here is a piece of the YAML blueprint example:
> 
> memberSpec:
> $brooklyn:entitySpec:
> type: brooklyn.entity.webapp.tomcat.TomcatServer
> id: tomcatServer
> location:
> named:standard-location-wdc01:
> customizerType: io.cloudsoft.ibm.mms.amp.location.SoftlayerLocationCustomizer
> postInstallScriptUri: https://USE_VARIABLE_IN_SCRIPT.sh <https://artifactory:AP5QT5YLhmBu3ET9Qe8wwkrNs3r@artifactory.mms.ibmcloud.com/artifactory/ext-release-local/amm-bss/provision/bss-tomcat.sh>
> privateNetworkOnly: false
> brooklyn.config:
> https.port: 8443+
> MY_VARIABLE: $brooklyn:formatString("%s",
> component("BSSMySQLDB").attributeWhenReady("host.subnet.address"))
> setup.script: https://USE_VARIABLE_IN_SCRIPT <https://artifactory:AP5QT5YLhmBu3ET9Qe8wwkrNs3r@artifactory.mms.ibmcloud.com/artifactory/ext-release-local/amm-bss/provision/bss-tomcat.sh>.sh
> setup.script.vars:
> $brooklyn:formatString("tomcatPublicIP:%s,runPath:%s,webappUrl:%s",
> component("tomcatServer").attributeWhenReady("host.address"),
> component("tomcatServer").attributeWhenReady("run.dir"),
> component("tomcatServer").attributeWhenReady("webapp.url"))
> 
> Question 1: How do I use these variables in my scrips?
> Question 2: I need following jars and xml file in Tomcat/apache catalina lib and conf directories respectively. However, following piece of yaml blueprint put them under /home/...../install/...../lib/ and /home/...../install/..../conf/ directories. I need the jar files under lib folder of Catalina/tomcat 's lib directory and .xml file under /home/..../apps/.......TomcatEntity/conf directory. Is there a variable that I can use in <key,value> pair instead of lib/ and conf/ directories?
> 
> files.install:
> "http://central.maven.org/maven2/org/apache/tomcat/tomcat-dbcp/7.0.30/tomcat-dbcp-7.0.30.jar <http://central.maven.org/maven2/org/apache/tomcat/tomcat-dbcp/7.0.30/tomcat-dbcp-7.0.30.jar>": lib/tomcat-dbcp-7.0.30.jar
> "http://central.maven.org/maven2/mysql/mysql-connector-java/5.1.10/mysql-connector-java-5.1.10.jar <http://central.maven.org/maven2/mysql/mysql-connector-java/5.1.10/mysql-connector-java-5.1.10.jar>": lib/mysql-connector-java-5.1.10.jar
> "https://provision/tomcat-users.xml <https://artifactory:AP5QT5YLhmBu3ET9Qe8wwkrNs3r@artifactory.mms.ibmcloud.com/artifactory/ext-release-local/amm-bss/provision/tomcat-users.xml>": conf/tomcat-users.xml
> 
> 
> Thanks
> Azhar
>