In a declarative pipeline I want user will choose list of machines and then some action will be executed on them in parallel.
I have an extendedChoice parameter with multiSelectDelimiter: ','
When I go over the list with this code below I get the characters of node and not entire node, how can I fix it ?
for (node in nodes) {
echo node
}
This should do it:
for (node in nodes.split(',')) {
echo node
}
Related
I would like to perform a depth first search on my graph and so, get all the paths existing from a given node ('N1456' in my example), and all the nodes of theses path must have the same property "PROPERTY_TO_FILTER".
Typically, my graph is composed of two types of node, and two types of relations.
For now, I tested the following request :
WITH "
MATCH (my_node{name : 'N1456'})
CALL apoc.path.expandConfig(protein, {uniqueness:'NODE_GLOBAL', bfs : FALSE}) YIELD path
WITH path, my_node, last(nodes(path)) as subgraph
WHERE my_node<> subgraph and my_node.my_property CONTAINS 'PROPERTY_TO_FILTER'
RETURN nodes(path), length(path) AS len
ORDER BY len DESC" AS query
CALL apoc.export.json.query(query, "my_results.json", {})
YIELD properties, data
RETURN properties, data;
However, the results are not the ones attended. I get a list of paths but only the first node has the property "PROPERTY_TO_FILTER" ; this filter is not taken into account for the other nodes...
I guess I should put a filter at apoc.path.expandConfig level, but I see in the documentation that this is only possible to filter the node label, not the node properties.
Could someone help please ?
Maybe this can help:
MATCH(fromNode:LABEL{name : 'N1456'})-[r:REL_TO_TRAVERSE*1..2]->(toNode:LABEL)
WHERE toNode.my_property CONTAINS 'PROPERTY_TO_FILTER'
RETURN fromNode,r,toNode
It's called variable length pattern matching:
https://neo4j.com/docs/cypher-manual/current/syntax/patterns/#cypher-pattern-varlength
Based on this thread - Jmeter - how to return multiple ID(s) based on the array (match JSON path with array)
I managed to get ID's, for every single member of the array.
Now I need to alternate the code and to have a variable for every single ID.
What i tried is:
vars.get('array').replace("[", "").replace("]", "").split(", ").each { country ->
def result = new groovy.json.JsonSlurper().parse(prev.getResponseData()).payload.find { entry -> entry.name == country.trim() }
vars.put("tim" + ${__counter(,)}, result.id as String);
}
But, I am only able to get a single variable.
What should I do in order to save every single result.id, into variables like:
tim1, tim2, tim3...
Don't inline JMeter Functions or Variables into Groovy scripts.
As per JMeter Documentation:
The JSR223 test elements have a feature (compilation) that can significantly increase performance. To benefit from this feature:
Use Script files instead of inlining them. This will make JMeter compile them if this feature is available on ScriptEngine and cache them.
Or Use Script Text and check Cache compiled script if available property.
When using this feature, ensure your script code does not use JMeter variables or JMeter function calls directly in script code as caching would only cache first replacement. Instead use script parameters.
So I would rather recommend amending your code as follows:
vars.get('array').replace("[", "").replace("]", "").split(", ").eachWithIndex { country, index ->
def result = new groovy.json.JsonSlurper().parse(prev.getResponseData()).payload.find { entry -> entry.name == country.trim() }
if (result != null) {
vars.put("tim" + (index + 1), result.id as String);
}
}
Demo:
More information: Apache Groovy - Why and How You Should Use It
Suppose I define a node:
"somenode" [xlabel="somenode"]
Is there an automatic variable, as in make such that I can write, for example (in pseudo code) something like:
"somenode" [xlabel=$#]
You can use graphviz-py to make a variable.
Code
digraph g {
{{ some_node_name = "somenode" }}
"{{= some_node_name }}" [xlabel="{{= some_node_name }}"]
}
Output
If attribute supports type escString (which label attribute does) you can use \N for node name and \G for graph name. On edge label you can use \T for tail node name and \H for head node name.
digraph {
Node1 [xlabel="\N"]
Node2 -> Node3 [xlabel="\T" label="\H"]
}
Result:
I'm interested in gathering the key value for any network_interfaces_*_state:up attribute's running on the host with the chef-client being run on. So any network interface with a state 'up' attribute.
I have a template containing a configuration file, in which I need to gather the active network devices, using the above chef attribute. I've tried writing a few things within the default recipe file, such as:
template '/etc/foo.conf' do
....
variables ({
netdev: search(node, 'network_interfaces_*_state:up').each {r |r| puts "#{r['network']['interfaces'].select { |i,j| j['state'] == 'up' }.keys } " }
})
end
So there are two things that are obviously wrong.
Running this as knife exec -E "......" returns the interface name for state:up on all nodes. I only want it from the current node that the chef-client is being run on.
chef-client is returning an undefined method 'search' for Chef::Resource::Template, tracing back to the 'netdev' variable as posted above.
I'm unfamiliar with Ruby and using Chef at this level, and was really hoping that I could get help with understanding two things. How do I pull a attribute value from a local host, and how the heck can I write this into a recipe/cookbook?
So what you need is the first 'up' interface, assuming the loopback interface should be avoided, this should do:
template '/etc/foo.conf' do
....
variables ({
netdev: node['network']['interfaces'].select { |i,j| j['state'] == 'up' && i != 'lo' }.keys[0]
})
end
The main idea is to filter the interfaces hash on the interface state and name, keep the keys and take the first one of the resulting array.
Previous answer kept for information.
Attributes are indexed and flattened so you may search for just state:up but may find other attributes named state.
Using the flattened version you could do:
knife node search 'network_interface_*_state:up' -a network.interfaces
This is derived from the examples of nested fields in the documentation linked above.
In case you wish to get each interface up for each node you can play with the search and a little of ruby with knife exec like this :
knife exec -E "nodes.search('network_interfaces_*_state:up').each { |n| puts \"#{n} #{n['network']['interfaces'].select { |i,j| j['state'] == 'up' }.keys } \" }"
node[xxxxxxx] ["eth1", "eth2", "eth3", "usb0"]
node[yyyyyyy] ["docker0"]
node[zzzzzzz] ["eth1", "eth2", "eth3", "usb0"]
The idea is to search for nodes with up interfaces and for each filtering the interfaces whose property (j in select block as they are a hash within a hash) state is up and then keep only the keys of the resulting filtered hash which are the interfaces with state up. (side note my examples above were done with state:down to limit the results)
I'm pretty confused about this one. Given the following xml:
<sch:eventList>
<sch:event>
<sch:eventName>Event One</sch:eventName>
<sch:locationName>Location One</sch:locationName>
</sch:event>
<sch:event>
<sch:eventName>Event Two</sch:eventName>
<sch:locationName>Location Two</sch:locationName>
</sch:event>
</sch:eventList>
When using JDOM using the following code:
XPath eventNameExpression = XPath.newInstance("//sch:eventName");
XPath eventLocationExpression = XPath.newInstance("//sch:eventLocation");
XPath eventExpression = XPath.newInstance("//sch:event");
List<Element> elements = eventExpression.selectNodes(requestElement);
for(Element e: elements) {
System.out.println(eventNameExpression.valueOf(e));
System.out.println(eventLocationExpression.valueOf(e));
}
The console shows this:
Event One
Location One
Event One
Location One
What am I missing?
Don't use '//' it starts always searching at the root node. Use e.g. './sch:eventName' it is relative to the current node.