Skip to content

Commit

Permalink
FIWARE Context Broker integration (#124)
Browse files Browse the repository at this point in the history
* Add FiwareNode implementation and tests

Signed-off-by: Irene Bandera <irenebandera@eprosima.com>

* Fix python linter

Signed-off-by: Irene Bandera <irenebandera@eprosima.com>

* Add Flask dependency to project_dependencies action.yml

Signed-off-by: Irene Bandera <irenebandera@eprosima.com>

* Add requests dependency to project_dependencies action.yml

Signed-off-by: Irene Bandera <irenebandera@eprosima.com>

* Add configuration params for FiwareNode

Signed-off-by: Irene Bandera <irenebandera@eprosima.com>

* Add FiwareNode c++ implementation

Signed-off-by: Irene Bandera <irenebandera@eprosima.com>

* Add documentation

Signed-off-by: Irene Bandera <irenebandera@eprosima.com>

* Add run(), post_data() and get_inference() methods

Signed-off-by: Irene Bandera <irenebandera@eprosima.com>

* Update docs

Signed-off-by: Irene Bandera <irenebandera@eprosima.com>

* Add review changes

Signed-off-by: Denisa <denisa@eprosima.com>

* Fix returning  errors in Fiware Context Broker

Signed-off-by: Denisa <denisa@eprosima.com>

* Use BooleanWaitHandler for handling inference data

Signed-off-by: Denisa <denisa@eprosima.com>

---------

Signed-off-by: Irene Bandera <irenebandera@eprosima.com>
Signed-off-by: Denisa <denisa@eprosima.com>
Co-authored-by: Denisa <denisa@eprosima.com>
  • Loading branch information
irenebm and depink5 authored Sep 6, 2024
1 parent d8fe609 commit e8284ec
Show file tree
Hide file tree
Showing 14 changed files with 790 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .github/actions/project_dependencies/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ runs:
with:
packages: pytest pywin32

- name: Install Flask and requests dependencies
uses: eProsima/eProsima-CI/multiplatform/install_python_packages@v0
with:
packages: flask requests

- name: Install Fast DDS dependencies
uses: eProsima/eProsima-CI/multiplatform/install_fastdds_dependencies@v0
with:
Expand Down
68 changes: 68 additions & 0 deletions amlip_cpp/include/amlip_cpp/node/FiwareNode.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Copyright 2024 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/**
* @file FiwareNode.hpp
*/

#ifndef AMLIPCPP__SRC_CPP_NODE_FIWARENODE_HPP
#define AMLIPCPP__SRC_CPP_NODE_FIWARENODE_HPP

#include <functional>

#include <amlip_cpp/node/ParentNode.hpp>

namespace eprosima {
namespace amlip {
namespace node {

/**
*
* @brief This is a specialization of AML-IP Node that interacts with FIWARE Context Broker and handles inference data.
*
* Fiware Nodes are the ones in charge of reading data from a context broker entity data, requesting inference from an Inference Node and sending the inferred solution to the context broker entity.
*
*/
class FiwareNode : public ParentNode
{
public:

/**
* @brief Construct a new Fiware Node object.
*
* @param name name of the Node (it is advisable to use a unique, or at least a representative name).
*/
AMLIP_CPP_DllAPI FiwareNode(
const char* name,
uint32_t domain_id);

AMLIP_CPP_DllAPI FiwareNode(
const char* name);

//! Same as previous ctor but with a string argument.
AMLIP_CPP_DllAPI FiwareNode(
const std::string& name);

/**
* @brief Destroy the Fiware Node object and its internal DDS entities.
*
*/
AMLIP_CPP_DllAPI ~FiwareNode();
};

} /* namespace node */
} /* namespace amlip */
} /* namespace eprosima */

#endif /* AMLIPCPP__SRC_CPP_NODE_FIWARENODE_HPP */
3 changes: 2 additions & 1 deletion amlip_cpp/include/amlip_cpp/types/status/NodeKind.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ ENUMERATION_BUILDER(
edge,
inference,
model_receiver,
model_sender
model_sender,
fiware
);

} /* namespace types */
Expand Down
66 changes: 66 additions & 0 deletions amlip_cpp/src/cpp/node/FiwareNode.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// Copyright 2024 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/**
* @file FiwareNode.cpp
*/

#include <cpp_utils/Log.hpp>

#include <amlip_cpp/node/FiwareNode.hpp>

#include <dds/Participant.hpp>
#include <dds/network_utils/topic.hpp>

namespace eprosima {
namespace amlip {
namespace node {

FiwareNode::FiwareNode(
const char* name,
uint32_t domain_id)
: ParentNode(name, types::NodeKind::fiware, types::StateKind::running, domain_id)
{
logInfo(AMLIPCPP_NODE_FIWARE, "Created new Fiware Node: " << *this << ".");
}

FiwareNode::FiwareNode(
const char* name)
: FiwareNode(name, dds::Participant::default_domain_id())
{
}

FiwareNode::FiwareNode(
const std::string& name)
: FiwareNode(name.c_str(), dds::Participant::default_domain_id())
{
}

FiwareNode::~FiwareNode()
{
change_status_(types::StateKind::stopped);
logDebug(AMLIPCPP_NODE_FIWARE, "Destroying Fiware Node: " << *this << ".");
}

std::ostream& operator <<(
std::ostream& os,
const FiwareNode& node)
{
os << "FIWARE_NODE{" << node.id() << "}";
return os;
}

} /* namespace node */
} /* namespace amlip */
} /* namespace eprosima */
4 changes: 4 additions & 0 deletions amlip_docs/rst/notes/forthcoming_version.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@ This release includes the following **CI improvements**:

* Upgrade to Ubuntu Noble (24.04).
* Remove Ubuntu Focal (20.04) from the CI.

This release will include a new **AML-IP node**:

* :ref:`Fiware <user_manual_nodes_fiware>`: node that interacts with FIWARE Context Broker to handle inference data.
2 changes: 1 addition & 1 deletion amlip_docs/rst/notes/notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ This release adds new **features**:
* Implement asynchronous request model in ``ModelManagerReceiver``.
* Add ``fastdds.application.id`` property to participants and endpoints.
* Add ``fastdds.application.metadata`` property to participants and endpoints.
* Add ``MainNode`` costructor with ``domain`` parameter in Python bindings.
* Add ``MainNode`` constructor with ``domain`` parameter in Python bindings.
* Add Python bindings for Agent Nodes.
* Rename ``agent_tool`` package to ``amlip_agent``.

Expand Down
6 changes: 6 additions & 0 deletions amlip_docs/rst/spelling_wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,9 @@ url
Vulcanexus
wget
yaml
detections
namespacing
Dev
Utils
Foonathan
Fiware
41 changes: 41 additions & 0 deletions amlip_docs/rst/user_manual/nodes/fiware.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
.. include:: ../../exports/alias.include

.. _user_manual_nodes_fiware:

###########
Fiware Node
###########

This kind of node interacts with the `FIWARE context broker <https://fiware-orion.readthedocs.io/en/master/>`__ in order to handle inference data.
It provides mechanisms to read data from a context broker entity, request inference from an :ref:`user_manual_nodes_inference`, and send the inference to the context broker entity.
To facilitate the inference requests, the Fiware Node includes an :ref:`user_manual_nodes_edge`.

Steps
-----

* Create a new :code:`FiwareNode` object with at least a :code:`name`, a :code:`server_ip` and a :code:`server_port`.
* Start the Flask server.

.. tabs::

.. tab:: Python

.. code-block:: python
server_ip = '192.168.1.1'
server_port = 1028
# Create a new Fiware Node
node = FiwareNode(name='My_Fiware_Node',
server_ip=server_ip,
server_port=server_port,
context_broker_ip='localhost',
context_broker_port=1026,
entity_id='ID_entity',
entity_data='data',
entity_solution='inference',
domain=0,
logger=CustomLogger(logger_name='FiwareNode', log_level=logging.WARNING))
# Start the Flask server
fiware_node.run()
5 changes: 3 additions & 2 deletions amlip_docs/rst/user_manual/nodes/nodes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,11 @@ Node Kinds
:maxdepth: 1

agent
status
main
computing
edge
fiware
inference
main
model_manager_receiver
model_manager_sender
status
Loading

0 comments on commit e8284ec

Please sign in to comment.