Skip to content

Commit

Permalink
Add rpc methods to retrieve astarte properties
Browse files Browse the repository at this point in the history
Co-authored-by: Riccardo Gallo <riccardo.gallo@secomind.com>
Signed-off-by: Luca Arato <luca.arato@secomind.com>
  • Loading branch information
lucaato and rgallor committed Dec 10, 2024
1 parent 5ff0672 commit 3ba3e46
Show file tree
Hide file tree
Showing 14 changed files with 657 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python-code-generation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
- name: Compile from source the grpc_python_plugin
if: steps.cache-grpc-python-plugin-restore.outputs.cache-hit != 'true'
run: |
git clone -b v1.66.1 https://github.com/grpc/grpc
git clone -b v1.67.0 https://github.com/grpc/grpc
cd grpc
git submodule update --init
cmake .
Expand Down
6 changes: 6 additions & 0 deletions proto/astarteplatform/msghub/interface.proto
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,9 @@ message InterfacesJson {
message InterfacesName {
repeated string names = 1; // An array of interfaces' names
}

/* */
enum Ownership {
DEVICE = 0;
SERVER = 1;
}
7 changes: 7 additions & 0 deletions proto/astarteplatform/msghub/message_hub_service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import "google/protobuf/empty.proto";
import "astarteplatform/msghub/astarte_message.proto";
import "astarteplatform/msghub/node.proto";
import "astarteplatform/msghub/interface.proto";
import "astarteplatform/msghub/property.proto";

service MessageHub {
/* This function should be used to attach a node to an instance of the Astarte message hub.
Expand All @@ -41,4 +42,10 @@ service MessageHub {
rpc AddInterfaces(InterfacesJson) returns (google.protobuf.Empty){}
/* This function should be used to remove one or more interfaces from an instance of the Astarte message hub. */
rpc RemoveInterfaces(InterfacesName) returns (google.protobuf.Empty){}
/* */
rpc GetProperties(InterfacesName) returns (StoredProperties){}
/* */
rpc GetAllProperties(StoredPropertiesFilter) returns (StoredProperties){}
/* */
rpc GetProperty(PropertyIdentifier) returns (Property) {}
}
60 changes: 60 additions & 0 deletions proto/astarteplatform/msghub/property.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* This file is part of Astarte.
*
* Copyright 2024 SECO Mind Srl
*
* 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.
*
* SPDX-License-Identifier: Apache-2.0
*/


syntax = "proto3";

package astarteplatform.msghub;

import "astarteplatform/msghub/astarte_message.proto";
import "astarteplatform/msghub/astarte_type.proto";
import "astarteplatform/msghub/interface.proto";

/* */
message Property {
string path = 1; // Property path.
oneof value { // Astarte data.
AstarteDataTypeIndividual astarte_property = 2; // Individual property data
AstarteUnset astarte_unset = 3; // Unset property
}
}

/* */
message InterfaceProperties {
Ownership ownership = 1;
int32 version_major = 2;
repeated Property properties = 3;
}

/* */
message StoredProperties {
map<string, InterfaceProperties> interface_properties = 1;
}

/* */
message StoredPropertiesFilter {
optional Ownership ownership = 1;
}

/* */
message PropertyIdentifier {
string interface_name = 1;
string path = 2;
}
4 changes: 3 additions & 1 deletion python/astarteplatform/msghub/interface_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions python/astarteplatform/msghub/interface_pb2.pyi
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
from google.protobuf.internal import containers as _containers
from google.protobuf.internal import enum_type_wrapper as _enum_type_wrapper
from google.protobuf import descriptor as _descriptor
from google.protobuf import message as _message
from typing import ClassVar as _ClassVar, Iterable as _Iterable, Optional as _Optional

DESCRIPTOR: _descriptor.FileDescriptor

class Ownership(int, metaclass=_enum_type_wrapper.EnumTypeWrapper):
__slots__ = ()
DEVICE: _ClassVar[Ownership]
SERVER: _ClassVar[Ownership]
DEVICE: Ownership
SERVER: Ownership

class InterfacesJson(_message.Message):
__slots__ = ("interfaces_json",)
INTERFACES_JSON_FIELD_NUMBER: _ClassVar[int]
Expand Down
7 changes: 4 additions & 3 deletions python/astarteplatform/msghub/message_hub_service_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions python/astarteplatform/msghub/message_hub_service_pb2.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ from google.protobuf import empty_pb2 as _empty_pb2
from astarteplatform.msghub import astarte_message_pb2 as _astarte_message_pb2
from astarteplatform.msghub import node_pb2 as _node_pb2
from astarteplatform.msghub import interface_pb2 as _interface_pb2
from astarteplatform.msghub import property_pb2 as _property_pb2
from google.protobuf import descriptor as _descriptor
from typing import ClassVar as _ClassVar

Expand Down
133 changes: 133 additions & 0 deletions python/astarteplatform/msghub/message_hub_service_pb2_grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from astarteplatform.msghub import astarte_message_pb2 as astarteplatform_dot_msghub_dot_astarte__message__pb2
from astarteplatform.msghub import interface_pb2 as astarteplatform_dot_msghub_dot_interface__pb2
from astarteplatform.msghub import node_pb2 as astarteplatform_dot_msghub_dot_node__pb2
from astarteplatform.msghub import property_pb2 as astarteplatform_dot_msghub_dot_property__pb2
from google.protobuf import empty_pb2 as google_dot_protobuf_dot_empty__pb2


Expand Down Expand Up @@ -42,6 +43,21 @@ def __init__(self, channel):
request_serializer=astarteplatform_dot_msghub_dot_interface__pb2.InterfacesName.SerializeToString,
response_deserializer=google_dot_protobuf_dot_empty__pb2.Empty.FromString,
_registered_method=True)
self.GetProperties = channel.unary_unary(
'/astarteplatform.msghub.MessageHub/GetProperties',
request_serializer=astarteplatform_dot_msghub_dot_interface__pb2.InterfacesName.SerializeToString,
response_deserializer=astarteplatform_dot_msghub_dot_property__pb2.StoredProperties.FromString,
_registered_method=True)
self.GetAllProperties = channel.unary_unary(
'/astarteplatform.msghub.MessageHub/GetAllProperties',
request_serializer=astarteplatform_dot_msghub_dot_property__pb2.StoredPropertiesFilter.SerializeToString,
response_deserializer=astarteplatform_dot_msghub_dot_property__pb2.StoredProperties.FromString,
_registered_method=True)
self.GetProperty = channel.unary_unary(
'/astarteplatform.msghub.MessageHub/GetProperty',
request_serializer=astarteplatform_dot_msghub_dot_property__pb2.PropertyIdentifier.SerializeToString,
response_deserializer=astarteplatform_dot_msghub_dot_property__pb2.Property.FromString,
_registered_method=True)


class MessageHubServicer(object):
Expand Down Expand Up @@ -83,6 +99,27 @@ def RemoveInterfaces(self, request, context):
context.set_details('Method not implemented!')
raise NotImplementedError('Method not implemented!')

def GetProperties(self, request, context):
"""
"""
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
context.set_details('Method not implemented!')
raise NotImplementedError('Method not implemented!')

def GetAllProperties(self, request, context):
"""
"""
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
context.set_details('Method not implemented!')
raise NotImplementedError('Method not implemented!')

def GetProperty(self, request, context):
"""
"""
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
context.set_details('Method not implemented!')
raise NotImplementedError('Method not implemented!')


def add_MessageHubServicer_to_server(servicer, server):
rpc_method_handlers = {
Expand Down Expand Up @@ -111,6 +148,21 @@ def add_MessageHubServicer_to_server(servicer, server):
request_deserializer=astarteplatform_dot_msghub_dot_interface__pb2.InterfacesName.FromString,
response_serializer=google_dot_protobuf_dot_empty__pb2.Empty.SerializeToString,
),
'GetProperties': grpc.unary_unary_rpc_method_handler(
servicer.GetProperties,
request_deserializer=astarteplatform_dot_msghub_dot_interface__pb2.InterfacesName.FromString,
response_serializer=astarteplatform_dot_msghub_dot_property__pb2.StoredProperties.SerializeToString,
),
'GetAllProperties': grpc.unary_unary_rpc_method_handler(
servicer.GetAllProperties,
request_deserializer=astarteplatform_dot_msghub_dot_property__pb2.StoredPropertiesFilter.FromString,
response_serializer=astarteplatform_dot_msghub_dot_property__pb2.StoredProperties.SerializeToString,
),
'GetProperty': grpc.unary_unary_rpc_method_handler(
servicer.GetProperty,
request_deserializer=astarteplatform_dot_msghub_dot_property__pb2.PropertyIdentifier.FromString,
response_serializer=astarteplatform_dot_msghub_dot_property__pb2.Property.SerializeToString,
),
}
generic_handler = grpc.method_handlers_generic_handler(
'astarteplatform.msghub.MessageHub', rpc_method_handlers)
Expand Down Expand Up @@ -256,3 +308,84 @@ def RemoveInterfaces(request,
timeout,
metadata,
_registered_method=True)

@staticmethod
def GetProperties(request,
target,
options=(),
channel_credentials=None,
call_credentials=None,
insecure=False,
compression=None,
wait_for_ready=None,
timeout=None,
metadata=None):
return grpc.experimental.unary_unary(
request,
target,
'/astarteplatform.msghub.MessageHub/GetProperties',
astarteplatform_dot_msghub_dot_interface__pb2.InterfacesName.SerializeToString,
astarteplatform_dot_msghub_dot_property__pb2.StoredProperties.FromString,
options,
channel_credentials,
insecure,
call_credentials,
compression,
wait_for_ready,
timeout,
metadata,
_registered_method=True)

@staticmethod
def GetAllProperties(request,
target,
options=(),
channel_credentials=None,
call_credentials=None,
insecure=False,
compression=None,
wait_for_ready=None,
timeout=None,
metadata=None):
return grpc.experimental.unary_unary(
request,
target,
'/astarteplatform.msghub.MessageHub/GetAllProperties',
astarteplatform_dot_msghub_dot_property__pb2.StoredPropertiesFilter.SerializeToString,
astarteplatform_dot_msghub_dot_property__pb2.StoredProperties.FromString,
options,
channel_credentials,
insecure,
call_credentials,
compression,
wait_for_ready,
timeout,
metadata,
_registered_method=True)

@staticmethod
def GetProperty(request,
target,
options=(),
channel_credentials=None,
call_credentials=None,
insecure=False,
compression=None,
wait_for_ready=None,
timeout=None,
metadata=None):
return grpc.experimental.unary_unary(
request,
target,
'/astarteplatform.msghub.MessageHub/GetProperty',
astarteplatform_dot_msghub_dot_property__pb2.PropertyIdentifier.SerializeToString,
astarteplatform_dot_msghub_dot_property__pb2.Property.FromString,
options,
channel_credentials,
insecure,
call_credentials,
compression,
wait_for_ready,
timeout,
metadata,
_registered_method=True)
41 changes: 41 additions & 0 deletions python/astarteplatform/msghub/property_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 3ba3e46

Please sign in to comment.