Could anyone explain how to use Jsonball with JClouds - jclouds

I am trying to do something like following
BootstrapConfig config = BootstrapConfig.builder().runList(runlist).attributes(new JsonBall("{ \"cassandra\" : { \"cluster_name\" : \"testing Baby\"}}")).build();
but it's not working...
I am not sure how to use Jsonball..
thnx

The code looks good. As Chef attributes have an arbitrary structure, we can't have the corresponding Java one, so we use the JsonBall object as a placeholder for any JSON string.
After generating the bootstrap configuration, however, you need to do the following to generate the bootstrap script:
chefService.updateBootstrapConfigForGroup("groupname", config);
Statement bootstrap = chefService.createBootstrapScriptForGroup("groupname");
That will generate the bootstrap script you can pass to the ComputeService methods.
The first call will persist the bootstrap configuration in a data bag, so it can be reused later to bootstrap more nodes with the same configuration.
The second line will read the contents of that data bag and generate the corresponding bootstrap script.

Related

Yeoman pass prompt answers to subgenerator

I have a yeoman generator with some subgenerators.
I know I can pass options from the parent- to the subgenerators when calling composeWith(...).
But how can I pass the answers I get from prompting? The are not available at the point when composeWith is called.
For example I prompt in the generator for an app name and want to provide this to all the subgenerators as options?
One way to do this is using the built-in config.
In the "parent" generator:
configuring(){
this.log('Saving configuration in .yo-rc.json')
const answers = this.answers.answers()
for(const key in answers){
this.config.set(key, answers[key])
}
this.config.save()
}
In the "child" generator, to populate templates:
const templateData = {
...this.config.getAll(),
...
}
this.fs.copyTpl(
this.templatePath(),
this.destinationPath(),
templateData
)
This should be simple enough to change for your use case, eg perhaps you'd want this.config.get(something) in the child generator.
Just note this won't work across different generators; only between a generator and its own sub-generators:
The .yo-rc.json file is a JSON file where configuration objects from multiple generators are stored. Each generator configuration is namespaced to ensure no naming conflicts occur between generators.
This also means each generator configuration is sandboxed and can only be shared between sub-generators. You cannot share configurations between different generators using the storage API. Use options and arguments during invocation to share data between different generators.
Oh, found in the related questions that I could call the subgenerator after prompting, instead of the initialize-method (as in the quite outdated tutorial)

Ruby operations on template variables - Chef

I have written following template in my chef cookbook recipe
template '/etc/app.conf' do
variables({
my_id: Chef::HTTP.new(https://example.com).get('/',{header})
})
end
And my erb file is
Output is : <%= #my_id %>
I actually want to perform some ruby operations(mainly filter out and count the components of my_id) and then pass those values(count of each component) back to the template and use it further. What should be erb configuration or anything thats need to be added in template block?
(Here, my_id actually has the subnets and I want to get those the count of those subnets and its values so that I can use it further to perform another http request and get the nodes in each of the subnet).
Don't know much about Chef Cookbooks but you can write some ruby within an ERB template. It is not the cleanest solution I believe though.
See here on how to embed code in your ERB
The thing you pasted from (hopefully you were summarizing since you missed a bunch of quotes in there) was only a quick tip. To get JSON data you want to use Chef::HTTP::SimpleJSON, the will do the parsing for you and whatnot.
variables data: Chef::HTTP::SimpleJSON.new('https://whatever.com/').get('/foo')

Generate URL of resources that are handled by Grails AssetPipeline

I need to access a local JSON file. Since Grails 2.4 implements the AssetPipeline plugin by default, I saved my local JSON file at:
/grails-app/assets/javascript/vendor/me/json/local.json
Now what I need is to generate a URL to this JSON file, to be used as a function parameter on my JavaScript's $.getJSON() . I've tried using:
var URL.local = ""${ raw(asset.assetPath(src: "local.json")) }";
but it generates an invalid link:
console.log(URL.local);
// prints /project/assets/local.json
// instead of /project/assets/vendor/me/json/local.json
I also encountered the same scenario with images that are handled by AssetPipeline1.9.9— that are supposed to be inserted dynamically on the page. How can I generate the URL pointing this resource? I know, I can always provide a static String for the URL, but it seems there would be a more proper solution.
EDIT
I was asked if I could move the local JSON file directly under the assets/javascript root directory instead of placing it under a subdirectory to for an easier solution. I prefer not to, for organization purposes.
Have you tried asset.assetPath(src: "/me/json/local.json")
The assets plugin looks in all of the immediate children of assets/. Your local.json file would need to be placed in /project/assets/foo/ for your current code to pick it up.
Check out the relevant documentation here which contains an example.
The first level deep within the assets folder is simply used for organization purposes and can contain folders of any name you wish. File types also don't need to be in any specific folder. These folders are omitted from the URL mappings and relative path calculations.

Overriding plugin views in Grails 2.2

I'm trying to customize the HTML markup of the excellent FilterPane grails plugin, however I'm having some difficulty. FilterPane provides a bunch of tags for rendering the search/filter form, and I would like to override these in my application.
I had thought that I could simply copy the _tagName.gsps that I wanted to override from
plugins/filterpane-2.0.1.1/grails-app/views/filterpane
into
grails-app/views/filterpane
and modify them, however it looks like Grails never checks whether the application is overriding the views of a plugin, if the render method is called with a plugin name property specified.
org.codehaus.groovy.grails.web.pages.GroovyPagesTemplateRenderer.findAndCacheTemplate contains the following code in a private method:
...
GroovyPageScriptSource scriptSource;
if (pluginName == null) {
scriptSource = groovyPageLocator.findTemplateInBinding(templatePath, pageScope);
} else {
scriptSource = groovyPageLocator.findTemplateInBinding(pluginName, templatePath, pageScope);
}
...
so when a non-null pluginName is specified, we just grab the plugin's view and never check whether the application is overriding it.
I thought a simple way to get around this problem would be to just override GrailsConventionGroovyPageLocator.findTemplateInBinding, or some other similar method in GrailsConventionGroovyPageLocator, however it doesn't appear to be possible to do this from within a Grails application either!
I created a simple class overriding GrailsConventionGroovyPageLocator, replacing the findTemplateInBinding method with one that checks the application's view directory before checking that of the plugin. I then modified resources.groovy, adding a doWithSpring closure to replace the beanClass property of the default groovyPageLocator:
def doWithSpring = {
def pageLocator = delegate.getBeanDefinition("groovyPageLocator")
pageLocator.beanClass = MyConventionGroovyPageLocator
}
However this doesn't seem to be called when my application starts up.
I'm really at a loss here. I'd expected this to be straightforward, but it's turned into a bit of a can of worms. Does anyone have any suggestions? All I want to do is override the views provided by a plugin...
You can modify the plugin source, instead of changing the location of the template.
The location is: user_home\.grails\version\projects\project\plugins\plugin-name
I am not a grails expert, but in order to override plugin views you should recreate them in your main projects views folder. For example, I changed the /auth/login.gsp from Spring Security Plugin by simply creating the same thing in my /project/views/auth/login.gsp. If you make changes into the plugin files itself you could potentially lose them if you uninstall the plugin.
In order to change a view in a template of a plugin, perform the command
grails install-templates
source
This will copy the templates of the plugins to your project which you then can customize. What this does with for example the scaffolding plugin, is copy files to src/templates/scaffolding (note, not grails-app/templates/scaffolding). Therefore, in your case, I would try copying the files to src/views/filterpane

How to cache an xml file and read its attributes in Rails?

I have a file that represents all components of a game. I want to load the file into cache on boot, then have the ability to call the attributes of the file from the controllers. How do I begin?
I like http://cobravsmongoose.rubyforge.org for most simple XML handling:
CobraVsMongoose.xml_to_hash(File.open('path/to/xml').gets)
As for your specific case, I would add an initializer which requires cvm and sets the value above to a constant, which you could then access wherever you want...
# config/initializers/load_xml.rb
require 'cobravsmongoose'
MY_XML = CobraVsMongoose.xml_to_hash(File.open('path/to/xml').gets)
Try out REXML, its an XML parsing library for Ruby. I think it comes with the standard version of Ruby, so you shouldn't even need to install a gem.

Resources