how do I implement if condition in my cloudformation stack - json

I have two attributes in my stack enviornment and iamprofileName. If I select one of the non-prod enviornment i.e "use1dev","use1qa". I should get MyPlatformEC2NonProd as default value in "IAMProfileName"
If I select one of the prod enviornments i.e "useProd1","useProd2".I must get MyPlatformEC2Prod as default value in "IAMProfileName"
How can I achieve this
"Environment" : {
"Description" : "Environment being deployed to - use1dev, use1qa,
use1sbox etc",
"Type" : "String",
"Default" : "use1sbox",
"AllowedValues" : ["use1dev","use1qa","useProd1","useProd2"]
},
"IAMProfileName" : {
"Default" : "MyPlatformEC2",
"Type" : "String",
"Description" : "Name of IAM profile to attach to created
machines",
"AllowedValues" : ["MyPlatformEC2","MyPlatformEC2NonProd"]

Use CloudFormation conditions. For example in your case, I would do something like the following:
Conditions:
"ProdProfileCondition": {
"Fn::Or": [
{"Fn::Equals": ["useProd1", {"Ref": "Environment"}]},
{"Fn::Equals": ["useProd2", {"Ref": "Environment"}]},
]
}
Now wherever you want to use the IAMProfileName value, use something like the following,
SomeAWSResource:
Properties:
"ProfileName" : [{
"Fn::If" : [
"ProdProfileCondition",
{"Ref" : "MyPlatformEC2"},
{"Ref" : "MyPlatformEC2NonProd"}
]
}]
For more information on how to use conditionals, check out the following link.
Also, you can achieve more complicated conditionals using Jinja, just create a template and fill values according to conditions. But I wouldn't go into details of that because what you need can be fulfilled by this already.
https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-conditions.html

Related

JPath for partial query match

I'm trying to learn json jpath query. I have successfully been able to return data based on exact searches.
For example at the site: https://jsonpath.com/ I can successfully retrieve the type of phone based on phone number:
JSON
{
"firstName": "John",
"lastName" : "doe",
"age" : 26,
"address" : {
"streetAddress": "naist street",
"city" : "Nara",
"postalCode" : "630-0192"
},
"phoneNumbers": [
{
"type" : "iPhone",
"number": "0123-4567-8888"
},
{
"type" : "home",
"number": "0123-4567-8910"
}
]
}
Query
$.[?(#.number== '0123-4567-8888')].type
However I can't find any examples that show me how to match a partial search result. I'm trying to write a query where I provide just "0123" and hence get back both "home" and "iPhone" returned as results.How can I do this?
You can use =~ match filter operator which allows providing a regular expression instead of strict value so given you amend your query like:
$.phoneNumbers[?(#.number=~/.*0123.*/)].type
you will get both types as the result:
More information: JMeter's JSON Path Extractor Plugin - Advanced Usage Scenarios

Translating engine gives same guids & viewableIDs to diferrent files of complex model

Recently I was trying to implement scenario where I could link views in 3D viewer with views on original revit model.
I zipped linked files and upload them
Upload more times same zip file with changed rootFileName to provide all aspects of a model and translate all
download their manifest.jsons
link views on revit side with view in the viewer using viewableID and uniqueID of original revit view
In here I will provide real shortened examples of manifest outputs
eg file 1.
{
"guid" : "578dd62c-d5dc-8da0-1c75-aa6b0be8ba76",
"name" : "3D pohled",
"success" : "100%",
"hasThumbnail" : "true",
"status" : "success",
"type" : "folder",
"progress" : "complete",
"children" : [{
"guid" : "07e30540-b182-cd58-1c1f-eb46bc58fb9c",
"name" : "{3D}",
"success" : "100%",
"size" : 771479.0,
"hasThumbnail" : "true",
"role" : "3d",
"viewableID" : "8af1141e-a7ca-22b4-d104-d7331a1c0454",
"status" : "success",
"type" : "geometry",
"progress" : "complete",
"children" : [{
"guid" : "429ba882-f0a0-40fa-96e6-c6e02d9fc601-00022cda",
"name" : "{3D}",
"role" : "3d",
"camera" : [22586.240234, 40687.59375, 32810.621094, 54.133858, -29.527559, 16437.923828, -0.160696, -0.29039, 0.943319, 0.547078, 0, 1, 1],
"status" : "success",
"type" : "view",
"progress" : "complete"
}, {
"guid" : "9a3b544b-3c15-9304-f6f8-2c4db7a7dcb3",
"type" : "resource",
"role" : "graphics",
"urn" : "urn:adsk.viewing:fs.file:dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6dGVzdGJfMTIzZWUvRkhfRmFzJUMzJUExZGFfdi4wMS56aXA/output/Resource/3D_pohled/_3D_/_3D_.svf",
"mime" : "application/autodesk-svf",
"size" : 680482.0
}
]
}
]
}
eg. file 2
{
"guid" : "578dd62c-d5dc-8da0-1c75-aa6b0be8ba76",
"name" : "3D pohled",
"success" : "100%",
"hasThumbnail" : "true",
"status" : "success",
"type" : "folder",
"progress" : "complete",
"children" : [{
"guid" : "07e30540-b182-cd58-1c1f-eb46bc58fb9c",
"name" : "{3D}",
"success" : "100%",
"size" : 7648740.0,
"hasThumbnail" : "true",
"role" : "3d",
"viewableID" : "8af1141e-a7ca-22b4-d104-d7331a1c0454",
"status" : "success",
"type" : "geometry",
"progress" : "complete",
"children" : [{
"guid" : "429ba882-f0a0-40fa-96e6-c6e02d9fc601-00022cda",
"name" : "{3D}",
"role" : "3d",
"camera" : [40927.800781, 19529.832031, 36075.765625, 54.958988, -27.723097, 16418.119141, -0.359014, -0.171787, 0.917387, 0.320998, 0, 1, 1],
"status" : "success",
"type" : "view",
"progress" : "complete"
}, {
"guid" : "9a3b544b-3c15-9304-f6f8-2c4db7a7dcb3",
"type" : "resource",
"role" : "graphics",
"urn" : "urn:adsk.viewing:fs.file:dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6dGVzdGJfMTIzZWUvRkhfVFpCX1ZaVC56aXA/output/Resource/3D_pohled/_3D_/_3D_.svf",
"mime" : "application/autodesk-svf",
"size" : 7552662.0
}
]
}
]
}
as you see each time URN of file is different, still viewableID and guids are the same. This is not suppose to happen and represents a real problem when working with the information. In manifest.json is also missing information about original revit guid(uniqueid) from which view it was generated, which is needed to uniqely identify view on revit side.
I think it is a bug and needs to be solved and also adding revit view guid into output manifest would help a lot. Because name property is not unique enough, the other guids has no practical use.
Any help would be greatly appreciated
The ids will be the same if they are translated from the same file (i.e. the unique ID used by Revit on its views), regardless the file name. So if you have a .rvt with a view, duplicate this file with different name, translate them both, they will have the same id on that view.
EDIT October 17, 2016
We have updated the translation engine in 9/26/2016 and the viewableID in the bubble is the same as the UniqueId of a Revit View, for both 3d and 2d. That way you can use the viewableId to implement your feature feature.
It is reasonably well known that Revit elements' "unique" ids are not, in fact, true GUIDs. Two copies of a file will have exactly the same "unique" ids for the elements in those files (they are not re-generated on a save-as operation). The purpose of the Unique id in Revit was to provide a mechanism to facilitate worksharing where element ids are not "stable" and may change during a reload latest event where element ids from the central conflict with local Element Ids.
Here is some information from The Building Coder about this topic:
http://thebuildingcoder.typepad.com/blog/2014/04/element-id-export-unique-navisworks-and-other-ids.html#3
In terms of your specific question: "How can i identify, uniquely, the views in revit when traversing manifest.json?" I would suggest that you might (if you have the ability) add the Revit filename as part of the name of the exported view which you have uploaded and translated. Tease that back out of the URN to determine which view you actually have.
If that doesn't work, maybe you could help us better understand this statement:
Upload more times same zip file with changed rootFileName to provide all aspects of a model and translate all
what is this attempting to achieve? different implementations on the viewer side of the same view data? And if so, maybe you can tell us more about exactly what you're trying to ultimately achieve and we can offer some more specific suggestions.

Is there any way to preserve the order while generating patch for json files ?

I am new to Json stuff i.e. JSON PATCH.
I have scenario where I need to figure out between two version of Json files of same object, for that I am using json-patch-master.
But unfortunately the patch generated interpreting it differently i.e. the order differently hence getting unexpected/invalid results.
Could anyone help me how to preserve the order while generating Json Patch ?
**Here is the actual example.
Original Json file :**
[ {
"name" : "name1",
"roolNo" : "1"
}, {
"name" : "name2",
"roolNo" : "2"
}, {
"name" : "name3",
"roolNo" : "3"
}, {
"name" : "name4",
"roolNo" : "4"
} ]
**Modified/New Json file: i.e. removed 2nd node of original file.**
[ {
"name" : "name1",
"roolNo" : "1"
}, {
"name" : "name3",
"roolNo" : "3"
}, {
"name" : "name4",
"roolNo" : "4"
} ]
**Patch/Diff Generated :**
[ {"op":"remove","path":"/3"},
{"op":"replace","path":"/1/name","value":"name3"},
{"op":"replace","path":"/1/roolNo","value":"3"},
{"op":"replace","path":"/2/name","value":"name4"},
{"op":"replace","path":"/2/roolNo","value":"4"}]
Very time I generate Diff/Patch it is giving different path/diff results.
And moreover the interpretation is different i.e. order is not preserving.
**Is there any way to get expected results i.e. [ {"op":"remove","path":"/1"} ] , in other words generated a patch/diff based some order so will get what is expected. ?
How to handle this kind of scenario ?**
Please help me.
Thank you so much.
~Shyam
We are currently working on this issue in Starcounter-Jack/JSON-Patch.
It seems to work nice with native Array.Observe- http://jsfiddle.net/tomalec/p4s7aw96/.
Try Starcounter-Jack/JSON-Patch issues/65_ArrayObserve branch
we will release it as new version once shim and performance will be checked.
Feel free to add you comments at JSON-Patch issue board

Elasticsearch queries on "empty index"

in my application I use several elasticsearch indices, which will contain no indexed documents in their initial state. I consider that can be called "empty" :)
The document's mapping is correct and working.
The application also has a relational database that contain entities, that MIGHT have documents associated in elasticsearch.
In the initial state of the appliation it is very common that there are only entities without documents, so not a single document has been indexed, therefore "empty index". The index has been created nevertheless and also the document's mapping has been put to the index and is present in the indexes metadata.
Anyway, when I query elasticsearch with a SearchQuery to find an document for one of the entities (the document contains an unique id from the entity), elasticsearch will throw an ElasticSearchException, that complains about no mapping present for field xy etc.
BUT IF I insert one single blank document into the index first, the query wont fail.
Is there a way to "initialize" an index in a way to prevent the query from failing and to get rid of the silly "dummy document workaround"?
UPDATE:
Plus, the workaround with the dummy doc pollutes the index, as for example a count query now returns always +1....so I added a deletion to the workaround as well...
Your questions lacks details and is not clear. If you had provided gist of your index schema and query, that would have helped. You should have also provided the version of elasticsearch that you are using.
"No mapping" exception that you have mentioned has nothing to do with initializing the index with some data. Most likely you are sorting on the field which doesn't exist. This is common if you are querying multiple indexes at once.
Solution: Solution is based on the version of elasticsearch. If you are on 1.3.x or lower then you should use ignore_unmapped. If you are on a version greater than 1.3.5 then you should use unmapped_type.
Click here to read official documentation.
If you are find the documentation confusing, then this example will make it clear:
Lets create two indexes testindex1 and testindex2
curl -XPUT localhost:9200/testindex1 -d '{"mappings":{"type1":{"properties":{"firstname":{"type":"string"},"servers":{"type":"nested","properties":{"name":{"type":"string"},"location":{"type":"nested","properties":{"name":{"type":"string"}}}}}}}}}'
curl -XPUT localhost:9200/testindex2 -d '{"mappings":{"type1":{"properties":{"firstname":{"type":"string"},"computers":{"type":"nested","properties":{"name":{"type":"string"},"location":{"type":"nested","properties":{"name":{"type":"string"}}}}}}}}}'
The only difference between these two indexes is - testindex1 has "server" field and textindex2 has "computers" field.
Now let's insert test data in both the indexes.
Index test data on testindex1:
curl -XPUT localhost:9200/testindex1/type1/1 -d '{"firstname":"servertom","servers":[{"name":"server1","location":[{"name":"location1"},{"name":"location2"}]},{"name":"server2","location":[{"name":"location1"}]}]}'
curl -XPUT localhost:9200/testindex1/type1/2 -d '{"firstname":"serverjerry","servers":[{"name":"server2","location":[{"name":"location5"}]}]}'
Index test data on testindex2:
curl -XPUT localhost:9200/testindex2/type1/1 -d '{"firstname":"computertom","computers":[{"name":"computer1","location":[{"name":"location1"},{"name":"location2"}]},{"name":"computer2","location":[{"name":"location1"}]}]}'
curl -XPUT localhost:9200/testindex2/type1/2 -d '{"firstname":"computerjerry","computers":[{"name":"computer2","location":[{"name":"location5"}]}]}'
Query examples:
Using "unmapped_type" for elasticsearch version > 1.3.x
curl -XPOST 'localhost:9200/testindex2/_search?pretty' -d '{"fields":["firstname"],"query":{"match_all":{}},"sort":[{"servers.location.name":{"order":"desc","unmapped_type":"string"}}]}'
Using "ignore_unmapped" for elasticsearch version <= 1.3.5
curl -XPOST 'localhost:9200/testindex2/_search?pretty' -d '{"fields":["firstname"],"query":{"match_all":{}},"sort":[{"servers.location.name":{"order":"desc","ignore_unmapped":"true"}}]}'
Output of query1:
{
"took" : 15,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 2,
"max_score" : null,
"hits" : [ {
"_index" : "testindex2",
"_type" : "type1",
"_id" : "1",
"_score" : null,
"fields" : {
"firstname" : [ "computertom" ]
},
"sort" : [ null ]
}, {
"_index" : "testindex2",
"_type" : "type1",
"_id" : "2",
"_score" : null,
"fields" : {
"firstname" : [ "computerjerry" ]
},
"sort" : [ null ]
} ]
}
}
Output of query2:
{
"took" : 10,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 2,
"max_score" : null,
"hits" : [ {
"_index" : "testindex2",
"_type" : "type1",
"_id" : "1",
"_score" : null,
"fields" : {
"firstname" : [ "computertom" ]
},
"sort" : [ -9223372036854775808 ]
}, {
"_index" : "testindex2",
"_type" : "type1",
"_id" : "2",
"_score" : null,
"fields" : {
"firstname" : [ "computerjerry" ]
},
"sort" : [ -9223372036854775808 ]
} ]
}
}
Note:
These examples were created on elasticserch 1.4.
These examples also demonstrate how to do sorting on nested fields.
Are you doing a sort when you search? I've run into the same issue ("No mapping found for [field] in order to sort on"), but only when trying to sort results. In that case, the solution is simply to add the ignore_unmapped: true property to the sort parameter in your query:
{
...
"body": {
...
"sort": [
{"field_name": {
"order": "asc",
"ignore_unmapped": true
}}
]
...
}
...
}
I found my solution here:
No mapping found for field in order to sort on in ElasticSearch

MongoDB AND Comparison Fails

I have a Collection named StudentCollection with two documents given below,
> db.studentCollection.find().pretty()
{
"_id" : ObjectId("52d7c0c744b4dd77efe93df7"),
"regno" : 101,
"name" : "Ajeesh",
"gender" : "Male",
"docs" : [
"voterid",
"passport",
"drivinglic"
]
}
{
"_id" : ObjectId("52d7c6a144b4dd77efe93df8"),
"regno" : 102,
"name" : "Sathish",
"gender" : "Male",
"dob" : ISODate("2013-12-09T21:05:00Z")
}
Why does the below query returns a document when it doesn't fulfil the criteria which I gave in find command. I know it's a bad & stupid query for AND comparison. I tried this with MySQL and it doesn't return anything as expected but why does NOSQL makes problem. I hope it's considering the last field for comparison.
> db.studentCollection.find({regno:101,regno:102}).pretty()
{
"_id" : ObjectId("52d7c6a144b4dd77efe93df8"),
"regno" : 102,
"name" : "Sathish",
"gender" : "Male",
"dob" : ISODate("2013-12-09T21:05:00Z")
}
Can anyone brief why does Mongodb works this way?
MongoDB leverages JSON/BSON and names should be unique (http://www.ietf.org/rfc/rfc4627.txt # 2.2.) Found this in another post How to generate a JSON object dynamically with duplicate keys? . I am guessing the value for 'regno' gets overridden to '102' in your case.
If what you want is an OR query, try the following:
db.studentCollection.find ( { $or : [ { "regno" : "101" }, {"regno":"102"} ] } );
Or even better, use $in:
db.studentCollection.find ( { "regno" : { $in: ["101", "102"] } } );
Hope this helps!
Edit : Typo!
MongoDB converts your query to a Javascript document. Since you have not mentioned anything for $and condition in your document, your query clause is getting overwritten by the last value which is "regno":"102". Hence you get last document as result.
If you want to use an $and, you may use any of the following:
db.studentCollection.find({$and:[{regno:"102"}, {regno:"101"}]});
db.studentCollection.find({regno:{$gte:"101", $lte:"102"}});