Update Resource Configs via rhq-cli

Rafael Soares rafaelcba at gmail.com
Tue May 31 04:10:29 UTC 2011


Hello Guys!

I applyed more time in this issue and now I got the solution! o/

A script like this solve my problem:

var rgc = new ResourceGroupCriteria();
rgc.addFilterName("JBossAS5-Instances");
rgc.fetchExplicitResources(true);
var jbossGroupList = ResourceGroupManager.findResourceGroupsByCriteria(rgc);
rgc.fetchExplicitResources(true);
var jbossGroup = jbossGroupList.get(0);
var jbossResourcesArray = jbossGroup.explicitResources.toArray();

for( i in jbossResourcesArray ) {
   var res = jbossResourcesArray[i];
   var jboss = ProxyFactory.getResource(res.id);
   var avail  = AvailabilityManager.getCurrentAvailabilityForResource(
jboss.id);

   println("");
   println("");
   println("  " + jboss.name );
   println("    - Availability: " + avail.availabilityType.getName());
   println("    - Started     : " + avail.startTime.toGMTString());
   println("");

   var jbossConfig = ConfigurationManager.getPluginConfiguration(jboss.id);
   var jbossConfigPropList = jbossConfig.getList("logEventSources");
   var jbossConfigLogEventSourcesMap = jbossConfigPropList.list.get(0);

   var jbossConfigLogEventSourcesMapPropertySimpleEnabled =
jbossConfigLogEventSourcesMap.getSimple("enabled");
   jbossConfigLogEventSourcesMapPropertySimpleEnabled.setBooleanValue(true);

   var jbossConfigLogEventSourcesMapPropertySimpleIncludesPattern =
jbossConfigLogEventSourcesMap.getSimple("includesPattern");

 jbossConfigLogEventSourcesMapPropertySimpleIncludesPattern.setStringValue(".*SQLException.*");

   var jbossConfigLogEventSourcesMapPropertySimpleMinimumSeverity =
jbossConfigLogEventSourcesMap.getSimple("minimumSeverity");

 jbossConfigLogEventSourcesMapPropertySimpleMinimumSeverity.setStringValue("error");

   ConfigurationManager.updatePluginConfiguration(jboss.id, jbossConfig);

   var latestPluginConfigurations =
ConfigurationManager.getLatestPluginConfigurationUpdate(jboss.id);
   println("latestPluginConfigurations: " +
latestPluginConfigurations.toString());
}

Now I can automate the logEvents configuration for all my JBossAS instances
in the RHQ inventory - with a simple JS script and the power of rhq-cli \o/.

Thanks.
____________________________
Rafael Torres Coelho Soares
rafaelcba at gmail.com
http://rafaeltuelho.wordpress.com
Brasília - DF - Brasil


On Mon, May 30, 2011 at 16:49, Rafael Soares <rafaelcba at gmail.com> wrote:

> Hello!
>
> I need to enable the log events for a lot of JBossAS5 resources. This task
> is boring and takes a long time to finish if you do it manually through RHQ
> UI. So I'm trying to do this via rhq-cli. how can I update a JBossAS5
> resource's configuration using the RHQ Remote/Domain API?
>
> I'm trying using a JS script like this:
>
> var serverJBoss = ProxyFactory.getResource(<resource ID>);
> var mapJBossConfig =
> serverJBoss.pluginConfiguration.getMap().get("logEventSources").getList().get(0).getMap();
>
> This return a java.util.Map holding the PropertySimple's objects like this:
>
> {*enabled*=PropertySimple[id=345369, name=enabled, value=false,
> override=null], *logFilePath*=PropertySimple[id=345368, name=logFilePath,
> value=/u01/app/jboss/jboss-4.2.2.GA/server/defaul/log/server.log,
> override=null], *includesPattern*=PropertySimple[id=345371,
> name=includesPattern, value=null, override=null], *minimumSeverity*=PropertySimple[id=345372,
> name=minimumSeverity, value=null, override=null], *dateFormat*=PropertySimple[id=345370,
> name=dateFormat, value=null, override=null]}
>
> After update these ProperySimple's objs how can I update the Resource's
> Configuration on Server? Can someone help me?
>
> Thanks!
> ____________________________
> Rafael Torres Coelho Soares
> rafaelcba at gmail.com
> http://rafaeltuelho.wordpress.com
> Brasília - DF - Brasil
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://fedorahosted.org/pipermail/rhq-devel/attachments/20110531/732cd176/attachment.html 


More information about the rhq-devel mailing list