JMeter populate user defined variables for forEach Controller - for-loop

I have a service API to be tested which returns some default values of various parameters for different countries. country code being a template parameter of the service. i.e.
http://${hostname}:${port}/country/${countryCode}
One of the country code I can use is "ALL" (the others being "IN", "US" , "UK" , "MX" ...) which will return all the countries supported by the API and the response will contain the country code as well.
Thus I am able to populate all the country codes I need to test. The groovy scipt
import groovy.json.JsonSlurper
def slurper = new JsonSlurper()
def result = slurper.parseText(prev.getResponseDataAsString())
assert prev.isResponseCodeOK()
def countries = result.country
assert countries instanceof List // Should get as [IN, US, UK, MX] for e.g.
def numOfCountries = countries.size()
I am trying to use the variable "countries" which is a list of all the countries I need to test the service in a ForEachController. For this I will be needing the UDV Names in the format
country_1 , country_2 , country_3 ...
How do I save the elements of list to the UDVs with that name format. The problem is I do not know or rather cannot assume how many countries are supported, so the UDVs cannot be named in advance.
Can that be done ? Am I going the correct way for the problem ? Any different approach is welcome.
Thanks

I'm not familiar with groovy, but here goes:
You have the list of countries- you get that in your script. If you create a for loop (in your groovy script), you can dynamically create your variable name ("country_" + [loop iterator]) and plug that into your vars.put().
So:
for(int x=0; x < v.size(); x++)
{
String country_name = "country_" + x;
vars.put(country_name, v[x]);
}

Related

terrraform get yaml values

I need to get the values from the yaml snippet into 1. the Route53 Zones where I need the apex_nme to be the zone names and 2. the records to be added as Route53 records into the specific zones. I have no clue how to do this. Any help is highly appreciated.
resource "aws_route53_zone" "this" {
for_each = {
for apex in var.source_domains : apex => {
name = apex.name
}
}
}
resource "aws_route53_record" "this" {
for_each = {
for records in var.source_domains : records => {
zone_id = aws_route53_zone.this[each.key].zone_id
name = subdomains.records
type = "A"
records = ["192.168.0.1"]
}
}
}
source_domains:
- apax_name: elastic2ls.com
records:
- elastic2ls.com
- www.elastic2ls.com
- apax_name: elastic2ls.ch
records:
- elastic2ls.ch
- www.elastic2ls.ch
- image.elastic2ls.ch
- m.elastic2ls.ch
- static.elastic2ls.ch
Your question is presented as if it's about YAML parsing, but I suspect you're really asking about how to write the for_each expression for aws_route53_record.this to create all of the records across all of the domains.
For completeness, I'll note that you could get var.source_domains to be populated from that YAML by making the calling module define that variable with an expression like this:
module "example" {
source = "../modules/example"
source_domains = yamldecode(file("${path.module}/example.yaml")).source_domains
# ...
}
Inside the module itself then, I'd first declare that module with a suitable type constraint to make it clear what data structure we're expecting, like this:
variable "source_domains" {
type = set(object({
apax_name = string
records = set(string)
}))
}
Here I defined both the top-level structure and the nested record as set types, because the way we're going to use them means that the ordering isn't important and we're expecting them all to be unique.
With all of that in place we can start to write out the resource definitions. Let's start with the zones, which are the simpler case because var.source_domains already meets the main requirement of having one element per resource instance we want to declare:
resource "aws_route53_zone" "example" {
for_each = {
for d in var.source_domains : d.apax_name => d
}
name = each.value.apax_name
}
With the example YAML input you shared, this block will declare two instances of this resource:
aws_route53_zone.example["elastic2ls.com"]
aws_route53_zone.example["elastic2ls.ch"]
The aws_route53_record declaration is a little trickier because we need to project the input data structure into a new structure where there's one element per record we want to declare, rather than one element per zone. Flattening nested data structures for for_each is a common use for the flatten function, and we can adapt the networks and subnets example from the documentation to work with zones and records instead:
locals {
zone_records = flatten([
for d in var.source_domains : [
for r in d.records : {
zone_name = d.apax_name
zone_id = aws_route53_zone.example[d.apax_name].id
record = r
}
]
])
}
This local value is constructing a list of objects where each object represents one valid pairing of zone and record. That means that the number of elements matches the number of aws_route53_record instances we need to declare, and so we can use this data structure in for_each:
resource "aws_route53_record" "example" {
for_each = {
for zr in local.zone_records : zr.record => zr
}
zone_id = each.value.zone_id
name = each.value.record
# ...
}
This example diverges a little from the typical flatten/for_each pattern because all of your record names already have the zone name embedded in them anyway, and so we don't need the usual expression to generate a compound unique key with multiple parts, like "${subnet.network_key}.${subnet.subnet_key}" in the documentation's example. The record name alone is sufficient for a unique key across all pairs in this case.
This then, again based on your example YAML, will declare the following instances:
aws_route53_record.example["elastic2ls.com"]
aws_route53_record.example["www.elastic2ls.com"]
aws_route53_record.example["elastic2ls.ch"]
aws_route53_record.example["www.elastic2ls.ch"]
aws_route53_record.example["image.elastic2ls.ch"]
aws_route53_record.example["m.elastic2ls.ch"]
aws_route53_record.example["static.elastic2ls.ch"]

Attribute routing not working with dictionaries

Being new to attribute routing, I'd like to ask for help getting this to work.
This test is a simple dynamic DB table viewer: Given a table name (or stored query name or whatever) and optionally some WHERE parameters, return query results.
Table COMPANIES (one of any number of tables which has an associated SELECT query stored somewhere, keyed by table name):
ID NAME HQ INDUSTRY
1 Apple USA Consumer electronics
2 Bose USA Low-quality, expensive audio equipment
3 Nokia FIN Mobile Phones
Controller:
[Route("view/{table}/{parameters}")]
public object Get(string table, Dictionary<string, string> parameters) {
var sql = GetSql(table);
var dbArgs = new DynamicParameters(parameters);
return Database.Query(sql, dbArgs); // Return stuff/unrelated to problem
}
SQL stored in some resource or table. Obviously the parameters must match exactly:
SELECT * FROM companies
WHERE name = :name
-- OR hq = :hq
-- OR ...etc. Doesn't matter since it never gets this far.
Request (Should look clean, but the exact URL format isn't important):
www.website.com/view/companies?hq=fin --> 404: No matching controller
www.website.com/view/companies/hq=fin --> parameters is null
www.website.com/view/companies/hq=fin&name=nokia --> Exception: A potentially dangerous Request.Path value was detected from the client (&).
When I use: [Route("view/{table}{parameters}")] I get:
A path segment cannot contain two consecutive parameters. They must be separated by a '/' or by a literal string. Parameter name: routeTemplate. Makes sense.
My question is: How do I accept a table name and any number of unknown parameters in the usual key1=val1&key2=val2 form (not some awkward indexed format like the one mentioned here) which will be later bound to SQL parameters, preferably using a vanilla data structure rather than something like FormCollection.
I don't think that binding URL parameters to a Dictionary is built-in to the framework. I'm sure there's a way to extend it if you wanted to.
I think quickest (but still acceptable) option is to get the query string parameters using Request.GetQueryNameValuePairs() like this:
[Route("view/{table}")]
public object Get(string table) {
Dictionary<string, string> parameters = Request.GetQueryNameValuePairs()
.ToDictionary(x => x.Key, x => x.Value);
var sql = GetSql(table);
var dbArgs = new DynamicParameters(parameters);
return Database.Query(sql, dbArgs); // Return stuff/unrelated to problem
}

How do I retrieve a list of groups for each user using Alfresco Javascript API

I'm totally new to Alfresco and their Javascript API so please bear that in mind...
I want to be able to view a list of groups for every user in Alfresco repository.
This is the code I have at the moment:
var gens = search.luceneSearch("TYPE:\"{http://www.alfresco.org/model/content/1.0}person\"");
var logFile = space.childByNamePath("log_user_groups.csv");
if (logFile == null) {
logFile = space.createFile("log_user_groups.csv");
}
logFile.content = "";
for (var i=0; i<gens.length;i++) {
logFile.content += gens[i].properties["cm:userName"]+"\n";
var groupes= people.getContainerGroups(gens[i]);
for (var j=0; j<groupes.length;j++) {
logFile.content += "\t"+groupes[j].properties.shortName +"\t";
logFile.content += "\t"+groupes[j].properties.fullName +"\t";
logFile.content += "\t"+groupes[j].properties.displayName +"\n";
}
}
The file is created with the user name shown correctly. However the group properties 'shortName', 'fullName' and 'displayName' are all null. In fact I printed out all the properties of the 'groupes' object and every field of the object is 'undefined'.
Does any body know what I am doing wrong?
Any help would be greatly appreciated.
Norm.
The easiest way would be to turn it on its head. Instead, for each group ask what groups and what users it contains. At the end, invert it.
You'll want to start with the Root Groups. The groups JS object in Alfresco will give you these, and others. It's implemented by ScriptAuthorityService, so you'll likely want to look at the JavaDocs
First up, get the root groups
var rootGroups = groups.getAllRootGroups() ;
For each group, get all the users in the group (direct and inherited) with getAllUsers(), and store those somewhere. Now, get all the child groups with getChildGroups(). Process each of these in the same way, recursing as needed.
I needed something similar (a complete list of groups) so I did this:
var temp = [];
function addGroups (groups)
{
for each (group in groups)
{
temp.push(group.getDisplayName());
addGroups(group.getChildGroups());
}
}
addGroups(groups.getAllRootGroups());
This works to a point. The problem is that getDisplayName() returns a very non-pretty group name. Normally when dealing with documents and displaying a group name associated with a user I would do people.getContainerGroups() and use group.properties["cm:authorityName"] to get a displayable name (as mentioned above), however the groups I receive from getAllRootGroups() do not have properties (group.properties is undefined).
Does anyone have any idea why the group list returned this way wouldn't have the same properties as those returned by people.getContainerGroups()?
I guess you're using the wrong properties name.
You need the following:
Full Name: groupes[j].properties["usr:authorityName"]
Display Name: groupes[j].properties["usr:authorityDisplayName"]
Short Name: I don't know :) maybe groupes[j].properties["usr:authorityShortName"]
You can also just get the NodeRef id.
Then login to Alfresco explorer. Then go to the administration console --> Node Browser
Paste the id (it should be something like workspace://spacesStore//biglongUUID).There you can see al the properties related to the group.
Or you could just loop the groupes[k].properties map and print all the properties.

Interacting With Class Objects in Ruby

How can I interact with objects I've created based on their given attributes in Ruby?
To give some context, I'm parsing a text file that might have several hundred entries like the following:
ASIN: B00137RNIQ
-------------------------Status Info-------------------------
Upload created: 2010-04-09 09:33:45
Upload state: Imported
Upload state id: 3
I can parse the above with regular expressions and use the data to create new objects in a "Product" class:
class Product
attr_reader :asin, :creation_date, :upload_state, :upload_state_id
def initialize(asin, creation_date, upload_state, upload_state_id)
#asin = asin
#creation_date = creation_date
#upload_state = upload_state
#upload_state_id = upload_state_id
end
end
After parsing, the raw text from above will be stored in an object that look like this:
[#<Product:0x00000101006ef8 #asin="B00137RNIQ", #creation_date="2010-04-09 09:33:45 ", #upload_state="Imported ", #upload_state_id="3">]
How can I then interact with the newly created class objects? For example, how might I pull all the creation dates for objects with an upload_state_id of 3? I get the feeling I'm going to have to write class methods, but I'm a bit stuck on where to start.
You would need to store the Product objects in a collection. I'll use an array
product_collection = []
# keep adding parse products into the collection as many as they are
product_collection << parsed_product_obj
#next select the subset where upload_state_ud = 3
state_3_products = product_collection.select{|product| product.upload_state_id == 3}
attr reader is a declarative way of defining properties/attributes on your product class. So you can access each value as obj.attribute like I have done for upload_state_id above.
select selects the elements in the target collection, which meet a specific criteria. Each element is assigned to product, and if the criteria evaluates to true is placed in the output collection.

Google app engine countrycode in key_name

I have a table with countrycodes, whats the best way to store these 2 digit codes, just in a regular property or in the key_name property?
I thought using key_name will produce faster performance?
Ton.
Whether or not you want to use key_name depends on how you want to use it. I'm not entirely certain how you want to use these country codes based on the information in your question. Let's say, however, that you want to be able to look up the full name of the country based on the two-letter code, for instance, to get "United States" from "us". In that case, you could have an entity like this:
class CountryName(db.Model):
name = db.StringProperty()
#classmethod
def lookup_by_code(cls, code):
country_name = ""
country = cls.get_by_key_name(code)
if country is not None:
country_name = country.name
return country_name
Now, this code is not complete; you'd need to populate the model with data, and this approach does not allow for reverse lookups -- getting the code when you have the country name, but this should give you an idea of how you might be able to use key_names. Doing it this way would be substantially faster then, say, having a model that contained both code and name as fields.

Resources