Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle device registration limit in HK and RM #71

Merged
merged 2 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Added
- Add support for device deletion.
- Add support to realm update.
- Add `device_registration_limit` field to `CreateRealm`, `GetRealmReply`
and `UpdateRealm`.
- Add `GetDeviceRegistrationLimit[Reply]` to retrieve the maximum
number of registered devices per realm.

## [1.1.0] - 2023-06-20

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,9 @@ defmodule Astarte.RPC.Protocol.Housekeeping.CreateRealm do
type: Astarte.RPC.Protocol.Housekeeping.CreateRealm.DatacenterReplicationFactorsEntry,
json_name: "datacenterReplicationFactors",
map: true

field :device_registration_limit, 7,
proto3_optional: true,
type: :int64,
json_name: "deviceRegistrationLimit"
end
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// This file is part of Astarte.
//
// Copyright 2017 Ispirata Srl
// Copyright 2017-2023 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.
Expand All @@ -27,4 +27,5 @@ message CreateRealm {
int32 replication_factor = 4;
ReplicationClass replication_class = 5;
map<string, int32> datacenter_replication_factors = 6;
optional int64 device_registration_limit = 7;
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,9 @@ defmodule Astarte.RPC.Protocol.Housekeeping.GetRealmReply do
type: Astarte.RPC.Protocol.Housekeeping.GetRealmReply.DatacenterReplicationFactorsEntry,
json_name: "datacenterReplicationFactors",
map: true

field :device_registration_limit, 6,
proto3_optional: true,
type: :int64,
json_name: "deviceRegistrationLimit"
end
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// This file is part of Astarte.
//
// Copyright 2017 Ispirata Srl
// Copyright 2017-2023 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.
Expand All @@ -26,4 +26,5 @@ message GetRealmReply {
int32 replication_factor = 3;
ReplicationClass replication_class = 4;
map<string, int32> datacenter_replication_factors = 5;
optional int64 device_registration_limit = 6;
}
34 changes: 28 additions & 6 deletions lib/astarte_rpc/protocol/proto/housekeeping/update_realm.pb.ex
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
defmodule Astarte.RPC.Protocol.Housekeeping.UpdateRealm.DatacenterReplicationFactorsEntry do
defmodule Astarte.RPC.Protocol.Housekeeping.RemoveLimit do
@moduledoc false

use Protobuf, protoc_gen_elixir_version: "0.12.0", syntax: :proto3
end

defmodule Astarte.RPC.Protocol.Housekeeping.SetLimit do
@moduledoc false

use Protobuf, map: true, protoc_gen_elixir_version: "0.11.0", syntax: :proto3
use Protobuf, protoc_gen_elixir_version: "0.12.0", syntax: :proto3

field :value, 1, type: :int64
end

defmodule Astarte.RPC.Protocol.Housekeeping.UpdateRealm.DatacenterReplicationFactorsEntry do
@moduledoc false

def fully_qualified_name, do: "UpdateRealm.DatacenterReplicationFactorsEntry"
use Protobuf, map: true, protoc_gen_elixir_version: "0.12.0", syntax: :proto3

field :key, 1, type: :string
field :value, 2, type: :int32
Expand All @@ -12,9 +24,9 @@ end
defmodule Astarte.RPC.Protocol.Housekeeping.UpdateRealm do
@moduledoc false

use Protobuf, protoc_gen_elixir_version: "0.11.0", syntax: :proto3
use Protobuf, protoc_gen_elixir_version: "0.12.0", syntax: :proto3

def fully_qualified_name, do: "UpdateRealm"
oneof :device_registration_limit, 0

field :realm, 1, proto3_optional: true, type: :string
field :jwt_public_key_pem, 3, proto3_optional: true, type: :string, json_name: "jwtPublicKeyPem"
Expand All @@ -26,7 +38,7 @@ defmodule Astarte.RPC.Protocol.Housekeeping.UpdateRealm do

field :replication_class, 5,
proto3_optional: true,
type: Astarte.RPC.Protocol.Housekeeping.ReplicationClass,
type: ReplicationClass,
json_name: "replicationClass",
enum: true

Expand All @@ -35,4 +47,14 @@ defmodule Astarte.RPC.Protocol.Housekeeping.UpdateRealm do
type: Astarte.RPC.Protocol.Housekeeping.UpdateRealm.DatacenterReplicationFactorsEntry,
json_name: "datacenterReplicationFactors",
map: true

field :set_limit, 7,
type: Astarte.RPC.Protocol.Housekeeping.SetLimit,
json_name: "setLimit",
oneof: 0

field :remove_limit, 8,
type: Astarte.RPC.Protocol.Housekeeping.RemoveLimit,
json_name: "removeLimit",
oneof: 0
end
10 changes: 10 additions & 0 deletions lib/astarte_rpc/protocol/proto/housekeeping/update_realm.proto
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,20 @@ syntax = "proto3";

import "lib/astarte_rpc/protocol/proto/housekeeping/replication_class.proto";

message RemoveLimit {}

message SetLimit {
int64 value = 1;
}

message UpdateRealm {
optional string realm = 1;
optional string jwt_public_key_pem = 3;
optional int32 replication_factor = 4;
optional ReplicationClass replication_class = 5;
map<string, int32> datacenter_replication_factors = 6;
oneof device_registration_limit {
SetLimit set_limit = 7;
RemoveLimit remove_limit= 8;
}
}
5 changes: 5 additions & 0 deletions lib/astarte_rpc/protocol/proto/realm_management/call.pb.ex
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,9 @@ defmodule Astarte.RPC.Protocol.RealmManagement.Call do
type: Astarte.RPC.Protocol.RealmManagement.DeleteDevice,
json_name: "deleteDevice",
oneof: 0

field :get_device_registration_limit, 20,
type: Astarte.RPC.Protocol.RealmManagement.GetDeviceRegistrationLimit,
json_name: "getDeviceRegistrationLimit",
oneof: 0
end
2 changes: 2 additions & 0 deletions lib/astarte_rpc/protocol/proto/realm_management/call.proto
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import "lib/astarte_rpc/protocol/proto/realm_management/delete_trigger_policy.pr
import "lib/astarte_rpc/protocol/proto/realm_management/get_trigger_policies_list.proto";
import "lib/astarte_rpc/protocol/proto/realm_management/get_trigger_policy_source.proto";
import "lib/astarte_rpc/protocol/proto/realm_management/delete_device.proto";
import "lib/astarte_rpc/protocol/proto/realm_management/get_device_registration_limit.proto";


message Call {
Expand All @@ -60,5 +61,6 @@ message Call {
GetTriggerPoliciesList get_trigger_policies_list = 17;
GetTriggerPolicySource get_trigger_policy_source = 18;
DeleteDevice delete_device = 19;
GetDeviceRegistrationLimit get_device_registration_limit = 20;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
defmodule Astarte.RPC.Protocol.RealmManagement.GetDeviceRegistrationLimit do
@moduledoc false

use Protobuf, protoc_gen_elixir_version: "0.11.0", syntax: :proto3

def fully_qualified_name, do: "GetDeviceRegistrationLimit"

field :realm_name, 1, proto3_optional: true, type: :string, json_name: "realmName"
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// This file is part of Astarte.
//
// Copyright 2023 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.
//

syntax = "proto3";

message GetDeviceRegistrationLimit {
optional string realm_name = 1;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
defmodule Astarte.RPC.Protocol.RealmManagement.GetDeviceRegistrationLimitReply do
@moduledoc false

use Protobuf, protoc_gen_elixir_version: "0.11.0", syntax: :proto3

def fully_qualified_name, do: "GetDeviceRegistrationLimitReply"

field :device_registration_limit, 1,
proto3_optional: true,
type: :int64,
json_name: "deviceRegistrationLimit"
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// This file is part of Astarte.
//
// Copyright 2023 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.
//

syntax = "proto3";

message GetDeviceRegistrationLimitReply {
optional int64 device_registration_limit = 1;
}
5 changes: 5 additions & 0 deletions lib/astarte_rpc/protocol/proto/realm_management/reply.pb.ex
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,9 @@ defmodule Astarte.RPC.Protocol.RealmManagement.Reply do
type: Astarte.RPC.Protocol.RealmManagement.GetTriggerPolicySourceReply,
json_name: "getTriggerPolicySourceReply",
oneof: 0

field :get_device_registration_limit_reply, 14,
type: Astarte.RPC.Protocol.RealmManagement.GetDeviceRegistrationLimitReply,
json_name: "getDeviceRegistrationLimitReply",
oneof: 0
end
2 changes: 2 additions & 0 deletions lib/astarte_rpc/protocol/proto/realm_management/reply.proto
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import "lib/astarte_rpc/protocol/proto/realm_management/get_triggers_list_reply.
import "lib/astarte_rpc/protocol/proto/realm_management/get_health_reply.proto";
import "lib/astarte_rpc/protocol/proto/realm_management/get_trigger_policies_list_reply.proto";
import "lib/astarte_rpc/protocol/proto/realm_management/get_trigger_policy_source_reply.proto";
import "lib/astarte_rpc/protocol/proto/realm_management/get_device_registration_limit_reply.proto";


message Reply {
Expand All @@ -47,5 +48,6 @@ message Reply {
GetHealthReply get_health_reply = 11;
GetTriggerPoliciesListReply get_trigger_policies_list_reply = 12;
GetTriggerPolicySourceReply get_trigger_policy_source_reply = 13;
GetDeviceRegistrationLimitReply get_device_registration_limit_reply = 14;
}
}
69 changes: 68 additions & 1 deletion test/astarte/rpc/protocol/housekeeping_test.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#
# This file is part of Astarte.
#
# Copyright 2017 Ispirata Srl
# Copyright 2017-2023 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.
Expand Down Expand Up @@ -32,7 +32,7 @@
version = 42

rpc =
Astarte.RPC.Protocol.Housekeeping.Call.new(

Check warning on line 35 in test/astarte/rpc/protocol/housekeeping_test.exs

View workflow job for this annotation

GitHub Actions / Build and Test (rabbitmq:3.12.0-management)

Astarte.RPC.Protocol.Housekeeping.Call.new/1 is deprecated. Build the struct by hand with %MyMessage{...} or use struct/2
call: {:create_realm, create_realm_call},
version: version
)
Expand Down Expand Up @@ -86,4 +86,71 @@
assert CreateRealm.decode(serialized_payload) == create_realm_call
end
end

test "GetRealmReply payload is correctly serialized when no device_registration_limit is set" do
get_realm_reply =
Astarte.RPC.Protocol.Housekeeping.GetRealmReply.new(

Check warning on line 92 in test/astarte/rpc/protocol/housekeeping_test.exs

View workflow job for this annotation

GitHub Actions / Build and Test (rabbitmq:3.12.0-management)

Astarte.RPC.Protocol.Housekeeping.GetRealmReply.new/1 is deprecated. Build the struct by hand with %MyMessage{...} or use struct/2
realm_name: "testRealm",
jwt_public_key_pem: "",
replication_class: :SIMPLE_STRATEGY,
replication_factor: 0
)

encoded = Astarte.RPC.Protocol.Housekeeping.GetRealmReply.encode(get_realm_reply)

assert %Astarte.RPC.Protocol.Housekeeping.GetRealmReply{
realm_name: "testRealm",
jwt_public_key_pem: "",
replication_class: :SIMPLE_STRATEGY,
replication_factor: 0,
device_registration_limit: nil
} = Astarte.RPC.Protocol.Housekeeping.GetRealmReply.decode(encoded)
end

describe "UpdateRealm" do
alias Astarte.RPC.Protocol.Housekeeping.UpdateRealm
alias Astarte.RPC.Protocol.Housekeeping.SetLimit
alias Astarte.RPC.Protocol.Housekeeping.RemoveLimit

test "is correctly serialized when device_registration_limit is set" do
update_realm = %UpdateRealm{
realm: "testRealm",
device_registration_limit: {:set_limit, %SetLimit{value: 1}}
}

encoded = UpdateRealm.encode(update_realm)

assert %UpdateRealm{
realm: "testRealm",
device_registration_limit: {:set_limit, %SetLimit{value: 1}}
} = UpdateRealm.decode(encoded)
end

test "is correctly serialized when device_registration_limit is missing" do
update_realm = %UpdateRealm{
realm: "testRealm"
}

encoded = UpdateRealm.encode(update_realm)

assert %UpdateRealm{
realm: "testRealm",
device_registration_limit: nil
} = UpdateRealm.decode(encoded)
end

test "is correctly serialized when device_registration_limit is removed" do
update_realm = %UpdateRealm{
realm: "testRealm",
device_registration_limit: {:remove_limit, %RemoveLimit{}}
}

encoded = UpdateRealm.encode(update_realm)

assert %UpdateRealm{
realm: "testRealm",
device_registration_limit: {:remove_limit, %RemoveLimit{}}
} = UpdateRealm.decode(encoded)
end
end
end
Loading