Error 500 in Orion CB when creating a new FiwareService - fiware

I'm using Fiware Orion CB version 2.1.0 on top of a MongoDB 4.0.5. Everything seems to work fine once I've started it, but, after a while (a copule of days) ingesting data with no problems, now, everytime I try to create a new entity in a new fiwareservice I get an 500 error from OrionCB (if I try to create the same entity in an exisiting FS, it works), and I have to reboot both, Mongo and Orion containers to get this new FS creation works.
The request is:
curl --location --request POST 'context.infinitech.easier-ai.eu/v2/entities/' \
--header 'fiware-service: itscenterctag' \
--header 'fiware-servicepath: /vehicle' \
--header 'Authorization: Bearer XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' \
--header 'Content-Type: application/json' \
--data-raw ' {
"id": "TEST",
"type": "test",
"dateObserved": {
"type": "DateTime",
"value": "2020-10-02T14:00:00.00Z",
"metadata": {}
},
"test": {
"type": "Number",
"value": 6.1,
"metadata": {
"timestamp": {
"type": "DateTime",
"value": "2020-10-02T14:00:00.00Z"
}
}
},
"location": {
"type": "geo:json",
"value": {
"type": "Point",
"coordinates": [
-7.733611,
42.079166
]
},
"metadata": {}
},
"name": {
"type": "Text",
"value": "test",
"metadata": {}
}
}'
Orion Response:
{
"error": "InternalError",
"description": "Database Error (collection: orion-itscenterctag.entities - insert(): { _id: { id: "TEST", type: "test", servicePath: "/vehicle" }, attrNames: [ "dateObserved", "test", "location", "name" ], attrs: { dateObserved: { type: "DateTime", creDate: 1603208149, modDate: 1603208149, value: 1601647200.0, mdNames: [] }, test: { type: "Number", creDate: 1603208149, modDate: 1603208149, value: 6.1, md: { timestamp: { type: "DateTime", value: 1601647200.0 } }, mdNames: [ "timestamp" ] }, location: { type: "geo:json", creDate: 1603208149, modDate: 1603208149, value: { type: "Point", coordinates: [ -7.733611, 42.079166 ] }, mdNames: [] }, name: { type: "Text", creDate: 1603208149, modDate: 1603208149, value: "test", mdNames: [] } }, creDate: 1603208149, modDate: 1603208149, location: { attrName: "location", coords: { type: "Point", coordinates: [ -7.733611, 42.079166 ] } }, lastCorrelator: "ec0dba3a-12e9-11eb-a65d-52e1fcc227da" } - exception: OperationException: { index: 0, code: 8, errmsg: "1: Operation not permitted", op: { _id: { id: "TEST", type: "test", servicePath: "/vehicle" }, attrNames: [ "dateObserved", "test", "location", "name" ], attrs: { dateObserved: { type: "DateTime", creDate: 1603208149, modDate: 1603208149, value: 1601647200.0, mdNames: [] }, test: { type: "Number", creDate: 1603208149, modDate: 1603208149, value: 6.1, md: { timestamp: { type: "DateTime", value: 1601647200.0 } }, mdNames: [ "timestamp" ] }, location: { type: "geo:json", creDate: 1603208149, modDate: 1603208149, value: { type: "Point", coordinates: [ -7.733611, 42.079166 ] }, mdNames: [] }, name: { type: "Text", creDate: 1603208149, modDate: 1603208149, value: "test", mdNames: [] } }, creDate: 1603208149, modDate: 1603208149, location: { attrName: "location", coords: { type: "Point", coordinates: [ -7.733611, 42.079166 ] } }, lastCorrelator: "ec0dba3a-12e9-11eb-a65d-52e1fcc227da" } })"
}
From MongoDB log I get:
2020-10-20T15:35:49.592+0000 E STORAGE [conn1] WiredTiger error (1) [1603208149:592173][1:0x7ff40cab4700], WT_SESSION.create: __posix_open_file, 715: /data/db/collection-18--6388608708582174430.wt: handle-open: open: Operation not permitted Raw: [1603208149:592173][1:0x7ff40cab4700], WT_SESSION.create: __posix_open_file, 715: /data/db/collection-18--6388608708582174430.wt: handle-open: open: Operation not permitted
2020-10-20T15:35:49.592+0000 E - [conn1] Assertion: UnknownError: 1: Operation not permitted src/mongo/db/catalog/database_impl.cpp 831
2020-10-20T15:35:49.597+0000 I STORAGE [conn1] createCollection: orion-itscenterctag.entities with generated UUID: a9c4273f-cddd-42bf-af6b-cbd96cbe034d
2020-10-20T15:35:49.598+0000 E STORAGE [conn1] WiredTiger error (1) [1603208149:598543][1:0x7ff40cab4700], WT_SESSION.create: __posix_open_file, 715: /data/db/collection-19--6388608708582174430.wt: handle-open: open: Operation not permitted Raw: [1603208149:598543][1:0x7ff40cab4700], WT_SESSION.create: __posix_open_file, 715: /data/db/collection-19--6388608708582174430.wt: handle-open: open: Operation not permitted
2020-10-20T15:35:49.598+0000 E - [conn1] Assertion: UnknownError: 1: Operation not permitted src/mongo/db/catalog/database_impl.cpp 831
2020-10-20T15:35:49.598+0000 I STORAGE [conn1] createCollection: orion-itscenterctag.entities with generated UUID: 49b14431-f217-48e7-93ed-d2f2f8e7a4fc
2020-10-20T15:35:49.600+0000 E STORAGE [conn1] WiredTiger error (1) [1603208149:600253][1:0x7ff40cab4700], WT_SESSION.create: __posix_open_file, 715: /data/db/collection-20--6388608708582174430.wt: handle-open: open: Operation not permitted Raw: [1603208149:600253][1:0x7ff40cab4700], WT_SESSION.create: __posix_open_file, 715: /data/db/collection-20--6388608708582174430.wt: handle-open: open: Operation not permitted
2020-10-20T15:35:49.600+0000 E - [conn1] Assertion: UnknownError: 1: Operation not permitted src/mongo/db/catalog/database_impl.cpp 831
2020-10-20T15:35:49.600+0000 I STORAGE [conn1] createCollection: orion-itscenterctag.entities with generated UUID: 600ec5a0-6841-4948-93c8-4fd062223479
2020-10-20T15:35:49.601+0000 E STORAGE [conn1] WiredTiger error (1) [1603208149:601495][1:0x7ff40cab4700], WT_SESSION.create: __posix_open_file, 715: /data/db/collection-21--6388608708582174430.wt: handle-open: open: Operation not permitted Raw: [1603208149:601495][1:0x7ff40cab4700], WT_SESSION.create: __posix_open_file, 715: /data/db/collection-21--6388608708582174430.wt: handle-open: open: Operation not permitted
2020-10-20T15:35:49.601+0000 E - [conn1] Assertion: UnknownError: 1: Operation not permitted src/mongo/db/catalog/database_impl.cpp 831
UPDATE:
This ONLY happens when trying to create a new FiwareService (by creating a new entity in a new FS). Managing any exisiting entity within already created FS works fine.
UPDATE II: (According comments)
> use orion-foo
switched to db orion-foo
> db.entities.insert({x:1})
WriteResult({
"nInserted" : 0,
"writeError" : {
"code" : 8,
"errmsg" : "1: Operation not permitted"
}
})

Taking into account the inforamtion in UPDATEII, it seems the problem is in the MongoDB instance itself, not in Orion. I mean, the fail got at mongo shell shows that the database itself is not allowing to create new databases (no matter who is creating them, either Orion, you at the mongo shell or a third application connected to MongoDB).
Thus, I'd suggest to review your database setup. What is a bit suprissing is that according to the report it works at the beginning but it start to fail after a while. Maybe some out-of-band operations (i.e. an administration process) is changing permissions on the move?

Related

Event Pattern to match boolean values in Amazon EventBridge

I was wondering how we can match boolean type value of false instead of checking just exists?
I am unable to find anything for a boolean value in the documentation Content filtering in Amazon EventBridge event patterns
Thank you in advance
Sample Event:
"requestParameters": {
"publicAccessBlock": "",
"bucketName": "sri123publicaccess",
"PublicAccessBlockConfiguration": {
"xmlns": "http://s3.amazonaws.com/doc/2006-03-01/",
"RestrictPublicBuckets": true,
"BlockPublicPolicy": true,
"BlockPublicAcls": true,
"IgnorePublicAcls": true
},
"Host": "s3.amazonaws.com"
},
Event Pattern:
{
"source": ["aws.s3"],
"detail-type": ["AWS API Call via CloudTrail"],
"detail": {
"eventSource": ["s3.amazonaws.com"],
"eventName": ["PutBucketPublicAccessBlock", "DeleteBucketPublicAccessBlock"],
"$or": [{
"RestrictPublicBuckets": [{
"exists": false
}]
}, {
"BlockPublicPolicy": [{
"exists": false
}]
}, {
"BlockPublicAcls": [{
"exists": false
}]
}, {
"IgnorePublicAcls": [{
"exists": false
}]
}]
}
}
The pattern to match boolean values is the one you'd expect:
"RestrictPublicBuckets": [true]
Beyond that, for your pattern to match your event, you must also properly nest the attributes:
"detail": {
"requestParameters": {
"PublicAccessBlockConfiguration": {
"$or": [
{"RestrictPublicBuckets": [true]},
{"BlockPublicPolicy": [true]},
{"BlockPublicAcls": [true]},
{"IgnorePublicAcls": [true]},
]
}
},
}

parse json response using ansible

I need to parse the json response from an API request using ansible and then take action on items returned in the response. Here is part of my ansible playbook -
```- name: Invoke Import API
uri:
url: "{{ atl_bitbucket_dataset_url }}/rest/api/1.0/migration/imports"
user: admin
password: "{{ atl_bitbucket_admin_password }}"
method: POST
follow_redirects: yes
force_basic_auth: yes
creates: "{{ atl_product_home_shared }}/data/migration/import/lock.file"
body: "{ \"archivePath\": \"{{ atl_bitbucket_dataset_url | basename }}\" }"
body_format: json
return_content: yes
register: response
until: response.status == 200
retries: 6
delay: 15
failed_when: response.response.json.state != 'INITIALISING'
- name: get status of import
debug: var=response```
and here is the json response i got on a previous run
```TASK [bitbucket_dataset_restore : get status of import] ************************
ok: [localhost] => {
"response": {
"attempts": 1,
"cache_control": "no-cache, no-transform",
"changed": false,
"connection": "close",
"content": "{\"id\":1,\"initiator\":{\"name\":\"admin\",\"emailAddress\":\"admin#yourcompany.com\",\"id\":1,\"displayName\":\"AdminIstrator\",\"active\":true,\"slug\":\"admin\",\"type\":\"NORMAL\",\"links\":{\"self\":[{\"href\":\"http://bbdc-test-loadbala-t6vnlr2363vl-1404860112.us-west-2.elb.amazonaws.com/users/admin\"}]}},\"nodeId\":\"e72aa995-5016-4b2c-80e8-edba5eda3ab4\",\"progress\":{\"percentage\":0},\"startDate\":1574803309090,\"state\":\"INITIALISING\",\"type\":\"com.atlassian.bitbucket.migration.import\",\"updateDate\":1574803309090}",
"content_type": "application/json;charset=UTF-8",
"cookies": {},
"cookies_string": "",
"date": "Tue, 26 Nov 2019 21:21:49 GMT",
"elapsed": 1,
"failed": false,
"failed_when_result": False,
"json": {
"id": 1,
"initiator": {
"active": True,
"displayName": "AdminIstrator",
"emailAddress": "admin#yourcompany.com",
"id": 1,
"links": {
"self": [
{
"href": "http://bbdc-test-loadbala-t6vnlr2363vl-1404860112.us-west-2.elb.amazonaws.com/users/admin"
}
]
},
"name": "admin",
"slug": "admin",
"type": "NORMAL"
},
"nodeId": "e72aa995-5016-4b2c-80e8-edba5eda3ab4",
"progress": {
"percentage": 0
},
"startDate": 1574803309090,
"state": "INITIALISING",
"type": "com.atlassian.bitbucket.migration.import",
"updateDate": 1574803309090
},
"msg": "OK (unknown bytes)",
"redirected": False,
"status": 200,
"transfer_encoding": "chunked",
"url": "http://localhost:7990/rest/api/1.0/migration/imports",
"vary": "accept-encoding,x-auserid,cookie,x-ausername,accept-encoding",
"warnings": [
"The value True (type bool) in a string field was converted to u'True' (type string). If this does not look like what you expect, quote the entire value to ensure it does not change."
],
"x_arequestid": "#XXAH7Kx1281x1x0",
"x_asen": "SEN-500",
"x_auserid": "1",
"x_ausername": "admin",
"x_content_type_options": "nosniff"
}
}```
I want to retrieve the value "state": "INITIALISING" and the "id": 1. I have tried various methods response.response.json.state or response['response']['json']['state']. And it has not worked. Can anyone help me on how i can retrieve those values so i can use in other tasks further down?
I was able to fix this by adding is defined. So my code looks like this -
failed_when: output is defined and output.json is defined and output.json.state != 'INITIALISING'

Find documents where all objects in array have specific value

I have the following documents in MongoDB:
{
name: "document1",
data: [{
name: "xxxxx",
status: "delivered"
},{
name: "xxxxx",
status: "In Process"
},{
name: "xxxxx",
status: "Not Started"
}]
},{
name: "document2",
data: [{
name: "xxxxx",
status: "delivered"
},{
name: "xxxxx",
status: "delivered"
},{
name: "xxxxx",
status: "delivered"
}]
}
I want to find all documents where all objects inside the "data" array have the status "delivered", I used to use $ne: 'Not Started', but now that more status options have been introduced, this doesn't work. Perhaps I could do a $ne: $and and include all negative options, but any new status will give issues.
You can use $not with $elemMatch
db.collection.find({
"data": {
"$not": {
"$elemMatch": {
"status": {
$ne: "delivered"
}
}
}
},
"data.status": "delivered"
})
Here is fiddle https://mongoplayground.net/p/digdoFC6yF0
You can use $not.
{
$and: [
{ 'data.status': { $not: /Not Started/},
{'data.status': "delivered"}
]
}
Note that $not must receive a regex and not just plain string.

Make an optional option required when another one is defined in JSON Schema

I would like to define certificate and privateKey required when secure flag is set to true. Is this possible to achieve?
{
type: 'object',
properties: {
'secure': {
title: 'Serve files over HTTPS',
description: 'Flag telling whether to serve contents over HTTPS and WSS',
type: 'boolean',
default: false
},
'certificate': {
title: 'Certificate file',
description: 'Location of the certificate file',
type: 'string'
},
'privateKey': {
title: 'Private key file',
description: 'Location of the private key file',
type: 'string'
}
}
You can use 'dependencies' keyword.
{
dependencies: {
secure: ['certificate', 'privateKey']
}
}
You can even specify the schema the data should match when secure is present:
{
dependencies: {
secure: {
properties: {
certificate: {
type: 'string'
}
privateKey: {
type: 'string'
}
},
required: ['certificate', 'privateKey']
}
}
}
Are you asking to have the schema content-dependent? I mean "what the schema allows depends on what's in the target (json) content"?
You can't do that.
There is a way, but it isn't pretty. You need to use the anyOf keyword to define how you want it to validate when secure is true and how you want it to validate when secure is false.
{
"type": "object",
"properties": {
"secure": {
"title": "Serve files over HTTPS",
"description": "Flag telling whether to serve contents over HTTPS and WSS",
"type": "boolean"
}
},
"anyOf": [
{
"type": "object",
"properties": {
"secure": {
"enum": [true]
},
"certificate": {
"title": "Certificate file",
"description": "Location of the certificate file",
"type": "string"
},
"privateKey": {
"title": "Private key file",
"description": "Location of the private key file",
"type": "string"
}
},
"required": ["certificate", "privateKey"]
},
{
"type": "object",
"properties": {
"secure": {
"enum": [false]
}
}
}
]
}

Parsing Json in Groovy

I have a following json string:
[ { id: '123', name: 'bla bla', type: 'Source', isLeaf: true },
{ id: '3425', name: 'test test', type: 'Reference', isLeaf: false },
{ id: '12678', name: 'tags', type: 'Source', isLeaf: false },
]
I am trying to parse this using JsonSlurper but getting error:
groovy.json.JsonException: Lexing failed on line: 1, column: 5, while reading 'i', no possible valid JSON value or punctuation could be recognized.
How do I parse it and access the id:'3425'?
Your Json is invalid, you need to use double quote to delimit strings and you also need to put quotes around the keys in your Json like so:
[ { "id": "123", "name": "bla bla", "type": "Source", "isLeaf": true },
{ "id": "3425", "name": "test test", "type": "Reference", "isLeaf": false },
{ "id": "12678", "name": "tags", "type": "Source", "isLeaf": false },
]
You can then do:
def ids = new groovy.json.JsonSlurper().parseText( json ).id
assert ids[ 1 ] == '3425'