Retrieving attributes from a resource group with a tempate composition - openstack

I want to create multiple copies of some resources defined in a template. How do I retrieve the attributes of the resources created in this fashion.
To illustrate, here is a template to create a random string (I call word.yaml):
heat_template_version: rocky
resources:
word:
type: OS::Heat::RandomString
Because I want a list of such random strings, I use an OS::Heat::ResourceGroup calling the template from word.yaml:
heat_template_version: rocky
resources:
composition:
type: OS::Heat::ResourceGroup
properties:
count: 2
resource_def:
type: word.yaml
outputs:
composition:
value: {get_attr: [composition, resource.word]}
Rubbing together the explanation of OS::Heat::ResourceGroup (ResourceGroup) and the template composition documentation (nested attributes), I expected a list of strings in my output, yet I get:
{
"outputs": [
{
"output_key": "composition",
"description": "No description given",
"output_error": "Member 'word' not found in group resource 'composition'.",
"output_value": null
}
]
}
What am I missing about the interaction of the resource group and the template composition?

Found the answer: I need to specify the attribute to retrieve as outpus of the composition. So the word.yaml would look like this:
heat_template_version: rocky
resources:
word:
type: OS::Heat::RandomString
outputs:
word:
description: the word
value: {get_attr: [word]}
And the composition, like so:
heat_template_version: rocky
resources:
composition:
type: OS::Heat::ResourceGroup
properties:
count: 2
resource_def:
type: word.yaml
outputs:
composition:
value: {get_attr: [composition, word]}
Yielding the expected output:
{
"output_key": "composition",
"description": "No description given",
"output_value": [
{
"value": "gB7ZcXgNjJlEtf8N47yFCOQyH0a1bb9c"
},
{
"value": "wXN4jAKgPqbf5i3GDR6qMkzfC7jF0xdC"
}
]
}

Related

Mukle 4 : RAML : how to define the schema of a POST BODY request in a RAML file?

A POST REST request having 3 body params as follows:
{
"name" : "ABC",
"age": 34,
"uniqueID": "12345sdfgh"
}
My requirement is to define constraints (type, maxlength, min length, regex, etc.) for each field name, age and unique id.
How can I define that?
There are some different ways to define it. The 'pure' RAML way it is to define a data type fragment for the data object using RAML definitions for types. Those should cover all your needs.
Example:
dataType.raml
#%RAML 1.0 DataType
type: object
displayName: Booking
properties:
BookingDetail:
type: object
required: true
displayName: "BookingDetail"
description: "BookingDetail"
properties:
Name:
type: string
required: true
displayName: "Name"
description: "Name"
example: "John"
NumberOfDays:
type: integer
required: true
minimum: 1
maximum: 10
API:
#%RAML 1.0
title: so-type
/bookings:
post:
body:
application/json:
type: !include dataType.raml
You can also use JSON schemas if you prefer:
/orders:
post:
body:
application/json:
type: !include schemas/OrdersSchema.json
One more thing, I think. To require input to comply with a regex, you might do this:
properties:
Name:
type: string
required: true
displayName: "Name"
description: "Name"
pattern: ^[-A-Za-z ]+$
example: "John"
That pattern is overly restrictive, but does match many Western traditional names. Your own regex is presumably more carefully constructed.

Google Schema.org Math solvers structured data for multiple fields

Trying to setup schema markup for a simple math solver action with two fields. Let's say addition.
1+1=2
Here is Google's doc and example:
{
"#context": "https://schema.org",
"#type": ["MathSolver", "LearningResource"],
"name": "An awesome math solver",
"url": "https://www.mathdomain.com/",
"usageInfo": "https://www.mathdomain.com/privacy",
"inLanguage": "en",
"potentialAction": [{
"#type": "SolveMathAction",
"target": "https://mathdomain.com/solve?q={math_expression_string}",
"mathExpression-input": "required name=math_expression_string",
"eduQuestionType": ["Polynomial Equation","Derivative"]
}],
"learningResourceType": "Math solver"
}
How do we add multiple variables for two numbers?
return {
'#context': 'https://schema.org',
'#type': ['MathSolver', 'LearningResource'],
...
potentialAction: [
{
'#type': 'SolveMathAction',
target: `domain.com/?num1={num1}&num2={num2}`,
'mathExpression-input': 'required name=num1 name=num2',
eduQuestionType: ['addition', 'sum']
},
],
learningResourceType: 'Math solver'
};
Schema.org says about mathExpression (note: mathExpression-input doesnt seem to exist) but does fall under Thing > Intangible EntryPoint
A mathematical expression (e.g. 'x^2-3x=0') that may be solved for > a specific variable, simplified, or transformed. This can take many > formats, e.g. LaTeX, Ascii-Math, or math as you would write with a > keyboard.
But can this be setup for URL params to accept multiple fields within the mathExpression-input instead of a single math expression?

Polymorphism in Swagger produces strange error message on discriminator

I'm writing a service with a GET that can return one of five different but closely related types. Since the user wants the option of searching through all five types at once, it has to be a single get call. I'm returning JSON, which can easily handle any type.
I'm trying to do this in Swagger, using their polymorphism feature, which I've never tried before. I'm doing it just like in the example, except under "definitions" instead of "components/schemas". But I'm getting a strange error message that I can't understand. The swagger file is below. The error says this:
Schema error at definitions['Event'].discriminator should be string
It gives this on line 49, which says discriminator:
So, my two questions are: How can I fix it? And will this even give me what I need?
swagger: '2.0'
info:
description: RESTful API to retrieve Titles Metadata
version: 1.0.0
title: Swagger Mystery
schemes:
- https
paths:
/event:
get:
operationId: getEvent
summary: searches names
description: |
Search by names, across all types, or by a specific type.
produces:
- application/json
parameters:
- in: query
name: title
description: name to search for
required: true
type: string
- in: query
name: start
required: false
type: boolean
- in: query
name: type
required: false
type: string
description: |
May be "contest", "partner", "sponsor", or "dancer". If missing, will search for all types.
responses:
'200':
description: search results
# I also don't know why I need to comment these out.
# content:
# application/json:
# schema:
# type: array
# items:
# $ref: '#/definitions/Event'
'400':
description: bad input parameter
definitions:
Event:
type: object
discriminator:
propertyName: eventType
properties:
eventType:
type: string
id:
type: integer
format: int64
name:
type: string
description:
type: string
contests:
type: array
items:
$ref: '#/definitions/Contest'
required:
- id
- name
- description
- contests
- eventType
Contest:
allOf:
- $ref: '#/definitions/Event'
- type: object
properties:
parentEvent:
type: string
venue:
type: string
required:
- parentEvent
- venue
Dancer:
allOf:
- $ref: '#/definitions/Event'
- type: object
properties:
eventInvitationDate:
type: string
format: date
venue:
type: string
required:
- eventInvitationDate
- venue
# Sponsor:
# allOf:
# - $ref: '#/definitions/Event'
# - type: object
# properties:
# invitationDate:
# type: string
# format: date
# parentEvent:
# type: string
# partners:
# type: array
# items:
# $ref: '#/definitions/Partner'
Partner:
allOf:
- $ref: '#/definitions/Event'
- type: object
properties:
invitationDate:
type: string
format: date
parentEvent:
type: string
venue:
type: string
required:
- invitationDate
- parentEvent
- venue
# two problems:
# 1. Schema error at definitions['Event'].discriminator
# should be string on line 49 (discriminator:)
# 2. Resolver error:
# e is undefined
# (no line number)
# (This error goes away when I comment out Sponsor.)
The error occurs because you are mixing OpenAPI 2.0 and 3.0 syntax.
Your spec is swagger: '2.0' but the following is 3.0 syntax:
discriminator:
propertyName: eventType
In OpenAPI 2.0, the value of discriminator is the property name:
discriminator: eventType
Also, OpenAPI 2.0 assumes that the possible values of the discriminator property (in this case eventType) are exactly the same as the model names in definitions. That is:
If eventType can be event, partner etc. in lowercase, then the model names must also be in lowercase – event, not Event.
If eventType is some code like e, p, d etc., the model names must be e, p, d etc. instead of Event, Partner etc.
Check out questions for more examples of discriminator usage in OpenAPI 2.0:
Swagger Inheritance and Composition
“discriminator” in polymorphism, OpenAPI 2.0 (Swagger 2.0)
Swagger: variant schema shape dependant on field value

swagger editor reference definition inside another definition

Inside my definitions I'm using inheritance. In the example below, the PERSON-PATCH properties are coming in without issue. Now I want to take the PERSON-BIO properties and show that's a sub-object inside the PersonGet. I can't figure out the syntax to do that.
PersonBio:
type: object
properties: &PERSON-BIO
nickname:
type: string
description: The nickname for the Person
... other properties chopped out ...
minProperties: 1
PersonGet:
type: object
properties:
<<: *PERSON-PATCH
ident:
type: integer
format: int32
description: The SQL ident of the Person
bio:
<<: *PERSON-BIO
OK, just figured this out;
PersonGet:
type: object
properties:
<<: *PERSON-PATCH
bio:
$ref: '#/definitions/PersonBio'

Autocomplete with Elasticsearch

I’m trying to use Elasticsearch to index a city database and get autocomplete on a field.
Here is my FOSElasticaBundle configuration :
fos_elastica:
indexes:
xxxxxxx:
settings:
index:
analysis:
analyzer:
custom_analyzer:
type: custom
tokenizer: nGram
filter: [lowercase, asciifolding, stopwords_fr, elision, snowball_fr, word_delimiter]
custom_search_analyzer:
type: custom
tokenizer: standard
filter: [lowercase, asciifolding, stopwords_fr, elision, snowball_fr, word_delimiter]
tokenizer:
nGram:
type: nGram
min_gram: 4
max_gram: 20
filter:
snowball_fr:
type: snowball
language: French
elision:
type: elision
articles: [l, m, t, qu, n, s, j, d]
stopwords_fr:
type: stop
stopwords: [_french_]
ignore_case: true
types:
cities:
mappings:
id:
name: { search_analyzer: custom_analyzer, index_analyzer: custom_analyzer, type: string, store: yes }
persistence:
driver: orm
model: XXXXX\MainBundle\Entity\City
provider: { query_builder_method: createSearchIndexQueryBuilder }
listener: ~
finder: ~
repository: XXXXX\SearchBundle\Repository\CitySearchRepository
My query looks like this :
{
"query": {
"match": {
"name": "xxxxxx"
}
}
}
But my problem is here :
When I type “Pa”, I get 242 results (ok)
When I type “Par”, I get no results (WTF)
When I type “Pari”, I get 22 results (ok)
When I type “Paris”, I get 10 results (ok)
It’s my first time with Elasticsearch, I think the solution is nearby, but if somebody has the same issue, I’m curious to know more about it.
Thanks, have a good day ;)
In your query you are doing a match. It means that you will look for documents that have the (analyzed) value you are looking for.
You should have a look on the completion suggester, it is the best way to implement suggestions for autocomplete.
If you are lazy you can just use a prefix query:
{
"prefix" : { "user" : "Pa" }
}

Resources