How to call MCollective from java client

209 Views Asked by At

I have setup a cluster using puppet. Now I need to call call puppet agents for puppet master. For that I am planing to use MCollective. I have another requirement, need to call MCollective from a java client in order to achieve change client configurations from master and restart the servers. Is there a way to do it?. Thanks, Irham

1

There are 1 best solutions below

0
On

I solved the problem by using jruby. I installed the ruby gems mcollective-client,json and jruby-openssl using rvm. In the following example I am calling a simple mco puppet runonce

Java code

ScriptingContainer ruby = new ScriptingContainer(LocalVariableBehavior.PERSISTENT);
Object result = ruby.runScriptlet(PathType.ABSOLUTE,"/opt/ruby_test.rb");

Ruby code

 require 'rubygems'
 require 'mcollective'
 include MCollective::RPC
 mc = rpcclient("puppet")
 printrpc mc.runonce()
 mc.disconnect