Skip to content

Commit

Permalink
IS-14 Refactor bulkProperties methods (#8)
Browse files Browse the repository at this point in the history
* Add Bulk Properties Manager to Device Model

* Refactor bulkProperties GET method

* Refactor bulkProperties PATCH and PUT methods

* Updated according to latest specification

---------

Co-authored-by: Simon Lo <[email protected]>
  • Loading branch information
jonathan-r-thorpe and lo-simon authored Jul 14, 2024
1 parent 66434d1 commit 226dc59
Show file tree
Hide file tree
Showing 10 changed files with 236 additions and 77 deletions.
8 changes: 5 additions & 3 deletions Development/nmos-cpp-node/node_implementation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1287,6 +1287,8 @@ void node_implementation_init(nmos::node_model& model, nmos::experimental::contr
nmos::push_back(root_block, class_manager);
// add device-manager to root-block
nmos::push_back(root_block, device_manager);
// add bulk-properties-manager to root-block
nmos::push_back(root_block, bulk_properties_manager);

// insert control protocol resources to model
insert_root_after(delay_millis, root_block, gate);
Expand Down Expand Up @@ -1720,7 +1722,7 @@ nmos::control_protocol_property_changed_handler make_node_implementation_control
// Example Device Configuration callback for creating a back-up dataset
nmos::get_properties_by_path_handler make_node_implementation_get_properties_by_path_handler(const nmos::resources& resources, slog::base_gate& gate)
{
return [&resources, &gate](const nmos::resource& resource, bool recurse)
return [&resources, &gate](nmos::get_control_protocol_class_descriptor_handler get_control_protocol_class_descriptor, nmos::get_control_protocol_datatype_descriptor_handler get_control_protocol_datatype_descriptor, const nmos::resource& resource, bool recurse)
{
slog::log<slog::severities::info>(gate, SLOG_FLF) << nmos::stash_category(impl::categories::node_implementation) << "Do get_properties_by_path";

Expand All @@ -1732,7 +1734,7 @@ nmos::get_properties_by_path_handler make_node_implementation_get_properties_by_
// Example Device Configuration callback for validating a back-up dataset
nmos::validate_set_properties_by_path_handler make_node_implementation_validate_set_properties_by_path_handler(const nmos::resources& resources, slog::base_gate& gate)
{
return [&resources, &gate](const nmos::resource& resource, const web::json::value& backup_data_set, bool recurse)
return [&resources, &gate](nmos::get_control_protocol_class_descriptor_handler get_control_protocol_class_descriptor, nmos::get_control_protocol_datatype_descriptor_handler get_control_protocol_datatype_descriptor, const nmos::resource& resource, const web::json::value& backup_data_set, bool recurse, const web::json::array& included_property_traits)
{
slog::log<slog::severities::info>(gate, SLOG_FLF) << nmos::stash_category(impl::categories::node_implementation) << "Do validate_set_properties_by_path";

Expand All @@ -1744,7 +1746,7 @@ nmos::validate_set_properties_by_path_handler make_node_implementation_validate_
// Example Device Configuration callback for restoring a back-up dataset
nmos::set_properties_by_path_handler make_node_implementation_set_properties_by_path_handler(nmos::resources& resources, slog::base_gate& gate)
{
return [&resources, &gate](const nmos::resource& resource, const web::json::value& data_set, bool recurse, bool allow_incomplete)
return [&resources, &gate](nmos::get_control_protocol_class_descriptor_handler get_control_protocol_class_descriptor, nmos::get_control_protocol_datatype_descriptor_handler get_control_protocol_datatype_descriptor, const nmos::resource& resource, const web::json::value& data_set, bool recurse, const web::json::array& included_property_traits)
{
slog::log<slog::severities::info>(gate, SLOG_FLF) << nmos::stash_category(impl::categories::node_implementation) << "Do set_properties_by_path";

Expand Down
197 changes: 144 additions & 53 deletions Development/nmos/configuration_api.cpp

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Development/nmos/configuration_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace nmos
{
struct node_model;

web::http::experimental::listener::api_router make_configuration_api(nmos::node_model& model, web::http::experimental::listener::route_handler validate_authorization, get_control_protocol_class_descriptor_handler get_control_protocol_class_descriptor, get_control_protocol_datatype_descriptor_handler get_control_protocol_datatype_descriptor, get_control_protocol_method_descriptor_handler get_control_protocol_method_descriptor, get_properties_by_path_handler get_properties_by_path, validate_set_properties_by_path_handler validate_set_properties_by_path, set_properties_by_path_handler set_properties_by_path, control_protocol_property_changed_handler property_changed, slog::base_gate& gate);
web::http::experimental::listener::api_router make_configuration_api(nmos::node_model& model, web::http::experimental::listener::route_handler validate_authorization, get_control_protocol_class_descriptor_handler get_control_protocol_class_descriptor, get_control_protocol_datatype_descriptor_handler get_control_protocol_datatype_descriptor, get_control_protocol_method_descriptor_handler get_control_protocol_method_descriptor, control_protocol_property_changed_handler property_changed, slog::base_gate& gate);
}

#endif
6 changes: 3 additions & 3 deletions Development/nmos/control_protocol_handlers.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ namespace nmos

// Device Configuration handlers
// these callbacks should not throw exceptions
typedef std::function<web::json::value(const nmos::resource& resource, bool recurse)> get_properties_by_path_handler;
typedef std::function<web::json::value(const nmos::resource& resource, const web::json::value& backup_data_set, bool recurse)> validate_set_properties_by_path_handler;
typedef std::function<web::json::value(const nmos::resource& resource, const web::json::value& backup_data_set, bool recurse, bool allow_incomplete)> set_properties_by_path_handler;
typedef std::function<web::json::value(nmos::get_control_protocol_class_descriptor_handler get_control_protocol_class_descriptor, nmos::get_control_protocol_datatype_descriptor_handler get_control_protocol_datatype_descriptor, const nmos::resource& resource, bool recurse)> get_properties_by_path_handler;
typedef std::function<web::json::value(nmos::get_control_protocol_class_descriptor_handler get_control_protocol_class_descriptor, nmos::get_control_protocol_datatype_descriptor_handler get_control_protocol_datatype_descriptor, const nmos::resource& resource, const web::json::value& backup_data_set, bool recurse, const web::json::array& included_property_traits)> validate_set_properties_by_path_handler;
typedef std::function<web::json::value(nmos::get_control_protocol_class_descriptor_handler get_control_protocol_class_descriptor, nmos::get_control_protocol_datatype_descriptor_handler get_control_protocol_datatype_descriptor, const nmos::resource& resource, const web::json::value& backup_data_set, bool recurse, const web::json::array& included_property_traits)> set_properties_by_path_handler;

namespace experimental
{
Expand Down
32 changes: 30 additions & 2 deletions Development/nmos/control_protocol_resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1262,14 +1262,15 @@ namespace nmos
web::json::push_back(parameters, details::make_nc_parameter_descriptor(U("The values offered (this may include read-only values and also paths which are not the target role path)"), nmos::fields::nc::data_set, U("NcBulkValuesHolder"), false, false, value::null()));
web::json::push_back(parameters, details::make_nc_parameter_descriptor(U("If set the descriptor would contain all inherited elements"), nmos::fields::nc::path, U("NcRolePath"), false, false, value::null()));
web::json::push_back(parameters, details::make_nc_parameter_descriptor(U("If true will validate properties on target path and all the nested paths"), nmos::fields::nc::recurse, U("NcBoolean"), false, false, value::null()));
web::json::push_back(parameters, details::make_nc_parameter_descriptor(U("If populated (not an empty collection) will include the properties matching any of the specified traits in the restore validation. When not populated only properties without traits are validated for restore"), nmos::fields::nc::included_property_traits, U("NcPropertyTrait"), false, true, value::null()));
web::json::push_back(methods, details::make_nc_method_descriptor(U("Validate bulk properties for setting by given paths"), nc_bulk_properties_manager_validate_set_properties_by_path_method_id, U("ValidateSetPropertiesByPath"), U("NcMethodResultObjectPropertiesSetValidation"), parameters, false));
}
{
auto parameters = value::array();
web::json::push_back(parameters, details::make_nc_parameter_descriptor(U("The values offered (this may include read-only values and also paths which are not the target role path)"), nmos::fields::nc::data_set, U("NcBulkValuesHolder"), false, false, value::null()));
web::json::push_back(parameters, details::make_nc_parameter_descriptor(U("If set the descriptor would contain all inherited elements"), nmos::fields::nc::path, U("NcRolePath"), false, false, value::null()));
web::json::push_back(parameters, details::make_nc_parameter_descriptor(U("If true will validate properties on target path and all the nested paths"), nmos::fields::nc::recurse, U("NcBoolean"), false, false, value::null()));
web::json::push_back(parameters, details::make_nc_parameter_descriptor(U("If true will allow the device to restore only the role paths which pass validation(perform an incomplete restore)"), nmos::fields::nc::allow_incomplete, U("NcBoolean"), false, false, value::null()));
web::json::push_back(parameters, details::make_nc_parameter_descriptor(U("If populated (not an empty collection) will include the properties matching any of the specified traits in the restore validation. When not populated only properties without traits are validated for restore"), nmos::fields::nc::included_property_traits, U("NcPropertyTrait"), false, true, value::null()));
web::json::push_back(methods, details::make_nc_method_descriptor(U("Set bulk properties for setting by given paths"), nc_bulk_properties_manager_set_properties_by_path_method_id, U("SetPropertiesByPath"), U("NcMethodResultObjectPropertiesSetValidation"), parameters, false));
}

Expand Down Expand Up @@ -2116,6 +2117,18 @@ namespace nmos

// Device Configuration datatypes
// TODO: add link
web::json::value make_nc_property_trait_datatype()
{
using web::json::value;

auto items = value::array();
web::json::push_back(items, details::make_nc_enum_item_descriptor(U("Property is instance specific"), U("InstanceSpecific"), 1));
web::json::push_back(items, details::make_nc_enum_item_descriptor(U("Property is ephemeral"), U("Ephemeral"), 2));
web::json::push_back(items, details::make_nc_enum_item_descriptor(U("Property is immutable"), U("Immutable"), 3));
web::json::push_back(items, details::make_nc_enum_item_descriptor(U("Property value is generated by the device"), U("DeviceGenerated"), 4));
return details::make_nc_datatype_descriptor_enum(U("Property trait enumeration"), U("NcPropertyTrait"), items, value::null());
}
// TODO: add link
web::json::value make_nc_property_value_holder_datatype()
{
using web::json::value;
Expand All @@ -2125,6 +2138,7 @@ namespace nmos
web::json::push_back(fields, details::make_nc_field_descriptor(U("Property name"), nmos::fields::nc::name, U("NcString"), false, false, value::null()));
web::json::push_back(fields, details::make_nc_field_descriptor(U("Property type name. If null it means the type is any"), nmos::fields::nc::type_name, U("NcName"), true, false, value::null()));
web::json::push_back(fields, details::make_nc_field_descriptor(U("Is the property ReadOnly?"), nmos::fields::nc::is_read_only, U("NcBoolean"), true, false, value::null()));
web::json::push_back(fields, details::make_nc_field_descriptor(U("Describes the property traits as a collection of unique items"), nmos::fields::nc::traits, U("NcPropertyTrait"), false, true, value::null()));
web::json::push_back(fields, details::make_nc_field_descriptor(U("Property value"), nmos::fields::nc::value, true, false, value::null()));

return details::make_nc_datatype_descriptor_struct(U("Property value holder descriptor"), U("NcPropertyValueHolder"), fields, value::null());
Expand Down Expand Up @@ -2152,13 +2166,27 @@ namespace nmos
return details::make_nc_datatype_descriptor_struct(U("Bulk values holder descriptor"), U("NcBulkValuesHolder"), fields, value::null());
}
// TODO: add link
web::json::value make_nc_restore_validation_status_datatype()
{
using web::json::value;

auto items = value::array();
web::json::push_back(items, details::make_nc_enum_item_descriptor(U("Restore was successful"), U("Ok"), 200));
web::json::push_back(items, details::make_nc_enum_item_descriptor(U("Excluded from restore due to data provided in the request"), U("Excluded"), 204));
web::json::push_back(items, details::make_nc_enum_item_descriptor(U("Restore failed because relevant backup data set provided is invalid"), U("InvalidData"), 400));
web::json::push_back(items, details::make_nc_enum_item_descriptor(U("Restore failed because the role path is not found in the device model or the device cannot create the role path from the data set"), U("NotFound"), 404));
web::json::push_back(items, details::make_nc_enum_item_descriptor(U("Restore failed because of missing dependency information in the relevant backup data set"), U("MissingDependency"), 424));
web::json::push_back(items, details::make_nc_enum_item_descriptor(U("Restore failed due to an internal device error preventing the restore from happening"), U("DeviceError"), 500));
return details::make_nc_datatype_descriptor_enum(U("Restore validation status enumeration"), U("NcRestoreValidationStatus"), items, value::null());
}
// TODO: add link
web::json::value make_nc_object_properties_set_validation_datatype()
{
using web::json::value;

auto fields = value::array();
web::json::push_back(fields, details::make_nc_field_descriptor(U("Object role path"), nmos::fields::nc::path, U("NcRolePath"), false, false, value::null()));
web::json::push_back(fields, details::make_nc_field_descriptor(U("Validation status"), nmos::fields::nc::status, U("NcMethodStatus"), false, false, value::null()));
web::json::push_back(fields, details::make_nc_field_descriptor(U("Validation status"), nmos::fields::nc::status, U("NcRestoreValidationStatus"), false, false, value::null()));
web::json::push_back(fields, details::make_nc_field_descriptor(U("Validation status message"), nmos::fields::nc::status_message, U("NcString"), true, false, value::null()));

return details::make_nc_datatype_descriptor_struct(U("Object properties set validation descriptor"), U("NcObjectPropertiesSetValidation"), fields, value::null());
Expand Down
4 changes: 4 additions & 0 deletions Development/nmos/control_protocol_resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -441,12 +441,16 @@ namespace nmos
// Device configuration feature set datatypes
// TODO: add link
//
web::json::value make_nc_property_trait_datatype();
//
web::json::value make_nc_property_value_holder_datatype();
//
web::json::value make_nc_object_properties_holder_datatype();
//
web::json::value make_nc_bulk_values_holder_datatype();
//
web::json::value make_nc_restore_validation_status_datatype();
//
web::json::value make_nc_object_properties_set_validation_datatype();
//
web::json::value make_nc_method_result_bulk_values_holder_datatype();
Expand Down
Loading

0 comments on commit 226dc59

Please sign in to comment.