I have the following puppet example template:
{
"servers" : [ {
"port" : 9200,
"host" : "localhost",
"queries" : [
<% @markets.each do |market| -%>
{
"outputWriters" : [ { "@class" : "com.googlecode.jmxtrans.model.output.StdOutWriter" } ],
"obj" : "solr/market_<%= market %>:type=queryResultCache,id=org.apache.solr.search.LRUCache",
"attr" : [ "hits","hitratio" ]
},
<% end -%>
],
"numQueryThreads" : 2
} ],
}
Applying it with market=['UK','FR','IT'], I get the following:
{
"servers" : [ {
"port" : 9200,
"host" : "localhost",
"queries" : [
{
"outputWriters" : [ { "@class" : "com.googlecode.jmxtrans.model.output.StdOutWriter" } ],
"obj" : "solr/market_UK:type=queryResultCache,id=org.apache.solr.search.LRUCache",
"attr" : [ "hits","hitratio" ]
},
{
"outputWriters" : [ { "@class" : "com.googlecode.jmxtrans.model.output.StdOutWriter" } ],
"obj" : "solr/market_FR:type=queryResultCache,id=org.apache.solr.search.LRUCache",
"attr" : [ "hits","hitratio" ]
},
{
"outputWriters" : [ { "@class" : "com.googlecode.jmxtrans.model.output.StdOutWriter" } ],
"obj" : "solr/market_IT:type=queryResultCache,id=org.apache.solr.search.LRUCache",
"attr" : [ "hits","hitratio" ]
},
],
"numQueryThreads" : 2
} ],
}
The problem is the last comma, which makes it an invalid solr config.
Instead of applying markets.each do, I could use market.map and join(','). but how to use map in this case?
I can use map as follows:
<%= @markets.map{ |market| "hello_"+market }.join(',') -%>
this would print hello_UK,hello_FR,hello_IT
(note that we don't have a comma after hello_IT),
but I would need something like this:
{
"servers" : [ {
"port" : 9200,
"host" : "localhost",
"queries" : [
<% @markets.map |market| -%>
{
"outputWriters" : [ { "@class" : "com.googlecode.jmxtrans.model.output.StdOutWriter" } ],
"obj" : "solr/market_<%= market %>:type=queryResultCache,id=org.apache.solr.search.LRUCache",
"attr" : [ "hits","hitratio" ]
},
<% }.join(',') -%>
],
"numQueryThreads" : 2
} ],
}
this does not work.
so, how to make it work? or how to modify my puppet template to remove the last comma?