|
| 1 | + |
| 2 | +# # This code allows you to install a orion-ld broker in a linux system |
| 3 | +# # The manuals are here https://github.com/FIWARE/context.Orion-LD/tree/develop/doc/manuals-ld |
| 4 | +# |
| 5 | +# # INSTALL NGSI LD broker (OrionLD) |
| 6 | +# sudo docker pull mongo:3.6 |
| 7 | +# sudo docker pull fiware/orion-ld |
| 8 | +# sudo docker network create fiware_default |
| 9 | +# sudo docker run -d --name=mongo-db --network=fiware_default --expose=27017 mongo:3.6 --bind_ip_all --smallfiles |
| 10 | +# sudo docker run -d --name fiware-orionld -h orion --network=fiware_default -p 1026:1026 fiware/orion-ld -dbhost mongo-db |
| 11 | +# |
| 12 | +# # TO RELAUNCH (only if you have already installed a broker in the same machine) |
| 13 | +# sudo docker stop fiware-orionld |
| 14 | +# sudo docker rm fiware-orionld |
| 15 | +# sudo docker stop mongo-db |
| 16 | +# sudo docker rm mongo-db |
| 17 | +# sudo docker network rm fiware_default |
| 18 | +# |
| 19 | +# # CHECK INSTANCES |
| 20 | +# # Check the broker is running |
| 21 | +# curl -X GET 'http://localhost:1026/version' |
| 22 | +# |
| 23 | +# # Check what entities are in the broker |
| 24 | +# curl -X GET http://localhost:1026/ngsi-ld/v1/entities?local=true&limit=1000 |
| 25 | +# |
| 26 | +# # now the python code you can use to insert some value in the context broker according to the data model |
| 27 | +# |
| 28 | +from pysmartdatamodels import pysmartdatamodels as sdm |
| 29 | +import subprocess |
| 30 | +serverUrl = "http://localhost:1026" # supposed that your broker is installed in localhost. Edit to match your configuration |
| 31 | +dataModel = "InteroperableAssets" |
| 32 | +subject = "dataModel.DataSpace" |
| 33 | +dataSpaceIdentifier = "{'type': 'Property', 'value': 'SM4RTENANCE'}" |
| 34 | +attribute = "dataSpaceIdentifier" |
| 35 | +value = dataSpaceIdentifier |
| 36 | +# The next line creates the query for inserting this attribute in a NGSI-LD context broker if the attribute does not exist it creates it |
| 37 | +print(sdm.update_broker(dataModel, subject, attribute, value, serverUrl=serverUrl, updateThenCreate=True)) |
| 38 | + |
| 39 | +dataExchangeProtocols = {'type': 'Property', 'value': [{'name': 'Link Data event stream', 'description': 'A Linked Data Event Stream (LDES) is a technical standard that applies linked data principles to data streams, allowing for the exchange of data between silos in a sustainable and cost-effective manner. It is defined as a collection of immutable objects, called LDES members, described using the Resource Description Framework (RDF). LDES enables data publishers to publish their datasets as append-only collections, allowing consumers to replicate the full dataset and keep it synchronized, while also facilitating real-time updates and improving data usability and findability', 'identifier': 'LDES', 'version': '1.0', 'documentation': ['https://semiceu.github.io/LinkedDataEventStreams/']}, {'name': 'NGSI LD', 'description': 'NGSI-LD is an information model and API for publishing, querying, and subscribing to context information, standardized by ETSI to facilitate open exchange and sharing of structured data across various domains. It represents context information as entities with properties and relationships, using a property graph model with semantics based on RDF and the semantic web framework. NGSI-LD builds upon previous context management frameworks and can be serialized using JSON-LD, making it compatible with linked data principles and allowing for unique IRI identifiers for entities and relationships', 'identifier': 'NGSI-LD.1.6', 'version': '1.6', 'documentation': ['https://www.etsi.org/deliver/etsi_gs/CIM/001_099/009/01.06.01_60/gs_CIM009v010601p.pdf']}]} |
| 40 | +attribute = "dataExchangeProtocols" |
| 41 | +value = dataExchangeProtocols |
| 42 | +# The next line creates the query for inserting this attribute in a NGSI-LD context broker if the attribute does not exist it creates it |
| 43 | +print(sdm.update_broker(dataModel, subject, attribute, value, serverUrl=serverUrl, updateThenCreate=True)) |
| 44 | + |
| 45 | +dataModelSources = {'type': 'Property', 'value': [{'name': 'Smart Data Models', 'description': 'The Smart Data Models initiative is a collaborative effort led by FIWARE Foundation, TM Forum, IUDX, and OASC to create and promote standardized, interoperable data models across multiple sectors. It aims to support a digital marketplace of smart solutions by developing common, royalty-free data models that are publicly available. The initiative focuses on using JSON Schema as a core component, enabling exports in various formats to enhance compatibility with semantic and linked data approaches. By providing these open-licensed, standardized data models, the initiative seeks to combat data silos, improve data sharing, and facilitate application portability across different platforms and sectors, ultimately fostering innovation and interoperability in smart solutions.', 'identifier': 'Smart-Data-Models', 'internalIdentifier': 'WeatherObserved', 'version': '0.3', 'documentation': ['https://github.com/smart-data-models/dataModel.Weather/blob/master/WeatherObserved/doc/spec.md']}]} |
| 46 | +attribute = "dataModelSources" |
| 47 | +value = dataModelSources |
| 48 | +# The next line creates the query for inserting this attribute in a NGSI-LD context broker if the attribute does not exist it creates it |
| 49 | +print(sdm.update_broker(dataModel, subject, attribute, value, serverUrl=serverUrl, updateThenCreate=True)) |
| 50 | + |
| 51 | +print(" In case you have installed the orion-ld broker (see comments on the header of this program)") |
| 52 | +print(" Execute this instruction to check that the entities has been inserted") |
| 53 | +command = ['curl', '-X', 'GET', 'http://localhost:1026/ngsi-ld/v1/entities?local=true&limit=1000'] |
| 54 | +result = subprocess.run(command, capture_output=True, text=True) |
| 55 | +print(result.stdout) |
0 commit comments