-
Notifications
You must be signed in to change notification settings - Fork 663
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
MG-2142 - Consume Things connect/disconnect event in bootstrap #2192
base: main
Are you sure you want to change the base?
Conversation
90b9f69
to
3198bd8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have question here, The event published by connectThingEvent
and disconnectThingEvent
are same event published by thing service on disconnect
and connect
?
They are not the same. The event published by things service is a notification that a thing has been connected or disconnected from a channel. The event published by |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JeffMboya I have suggestion for handling error rollbacks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While trying to assign parent group for channel , like below request
curl --location 'http://localhost/channels/795b0be8-f8d9-4101-a40f-859ed573c71c/groups/assign' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <Token>' \
--data '{
"group_ids" : [ "5c6de392-6dc4-46fc-8e2c-e6f4ce4fffab" ]
}'
In events received below logs, which use group.assign
operation , the same operation is used for thing connect, so could not different between thing connection event and group assign channel events
[#8] Received on "events.magistrala.things" with reply "_INBOX.7g7jymtBXH0wOSok79kUGo.0LlN1Z1P"
*�{"group_id":"795b0be8-f8d9-4101-a40f-859ed573c71c","member_ids":["5c6de392-6dc4-46fc-8e2c-e6f4ce4fffab"],"occurred_at":1714131210669902557,"operation":"group.assign"}
Additionally,
In the event message group_id filed contains channel id
actually here we should have group id
In member_ids field , it contains
group_id , actually here we should have channel id
This issue might be a blocker for this PR
0b87686
to
9380eef
Compare
15ddd1f
to
068d129
Compare
b78c9aa
to
f6aa2fe
Compare
repo := postgres.NewConfigRepository(db, testLog) | ||
err := deleteChannels(context.Background(), repo) | ||
require.Nil(t, err, "Channels cleanup expected to succeed.") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test this occurrences using table testing:
- Connect for an already connected thing
- Connect for a disconnected thing
- Connect for an invalid thing
- Connect for a random thing
- Connect for an empty thing
386c14c
to
73f7017
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will approve this PR but open a issue for the bootstrap test.
bootstrap/service_test.go
Outdated
repoCall2 := sdk.On("Channel", mock.Anything, mock.Anything).Return(mgsdk.Channel{}, nil) | ||
repoCall3 := boot.On("ListExisting", context.Background(), mock.Anything, mock.Anything, mock.Anything).Return(config.Channels, nil) | ||
repoCall4 := boot.On("Save", context.Background(), mock.Anything, mock.Anything).Return(mock.Anything, nil) | ||
saved, err := svc.Add(context.Background(), validToken, config) | ||
_, err := svc.Add(context.Background(), validToken, config) | ||
assert.Nil(t, err, fmt.Sprintf("Saving config expected to succeed: %s.\n", err)) | ||
repoCall.Unset() | ||
repoCall1.Unset() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this block of code. it doesn't do anything
bootstrap/service_test.go
Outdated
repoCall2 := sdk.On("Channel", mock.Anything, mock.Anything).Return(mgsdk.Channel{}, nil) | ||
repoCall3 := boot.On("ListExisting", context.Background(), mock.Anything, mock.Anything, mock.Anything).Return(config.Channels, nil) | ||
repoCall4 := boot.On("Save", context.Background(), mock.Anything, mock.Anything).Return(mock.Anything, nil) | ||
saved, err := svc.Add(context.Background(), validToken, c) | ||
_, err := svc.Add(context.Background(), validToken, c) | ||
assert.Nil(t, err, fmt.Sprintf("Saving config expected to succeed: %s.\n", err)) | ||
repoCall.Unset() | ||
repoCall1.Unset() | ||
repoCall2.Unset() | ||
repoCall3.Unset() | ||
repoCall4.Unset() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
bootstrap/service_test.go
Outdated
repoCall2 := sdk.On("Channel", mock.Anything, mock.Anything).Return(mgsdk.Channel{}, nil) | ||
repoCall3 := boot.On("ListExisting", context.Background(), mock.Anything, mock.Anything, mock.Anything).Return(config.Channels, nil) | ||
repoCall4 := boot.On("Save", context.Background(), mock.Anything, mock.Anything).Return(mock.Anything, nil) | ||
saved, err := svc.Add(context.Background(), validToken, c) | ||
_, err := svc.Add(context.Background(), validToken, c) | ||
assert.Nil(t, err, fmt.Sprintf("Saving config expected to succeed: %s.\n", err)) | ||
repoCall.Unset() | ||
repoCall1.Unset() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same
bootstrap/service_test.go
Outdated
repoCall2 := sdk.On("Channel", mock.Anything, mock.Anything).Return(mgsdk.Channel{}, nil) | ||
repoCall3 := boot.On("ListExisting", context.Background(), mock.Anything, mock.Anything, mock.Anything).Return(config.Channels, nil) | ||
repoCall4 := boot.On("Save", context.Background(), mock.Anything, mock.Anything).Return(mock.Anything, nil) | ||
saved, err := svc.Add(context.Background(), validToken, c) | ||
_, err := svc.Add(context.Background(), validToken, c) | ||
assert.Nil(t, err, fmt.Sprintf("Saving config expected to succeed: %s.\n", err)) | ||
repoCall.Unset() | ||
repoCall1.Unset() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same
bootstrap/service_test.go
Outdated
@@ -590,7 +590,7 @@ func TestRemove(t *testing.T) { | |||
repoCall2 := sdk.On("Channel", mock.Anything, mock.Anything).Return(mgsdk.Channel{}, nil) | |||
repoCall3 := boot.On("ListExisting", context.Background(), mock.Anything, mock.Anything, mock.Anything).Return(config.Channels, nil) | |||
repoCall4 := boot.On("Save", context.Background(), mock.Anything, mock.Anything).Return(mock.Anything, nil) | |||
saved, err := svc.Add(context.Background(), validToken, config) | |||
_, err := svc.Add(context.Background(), validToken, config) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same
bootstrap/service_test.go
Outdated
@@ -647,15 +647,15 @@ func TestBootstrap(t *testing.T) { | |||
repoCall2 := sdk.On("Channel", mock.Anything, mock.Anything).Return(mgsdk.Channel{}, nil) | |||
repoCall3 := boot.On("ListExisting", context.Background(), mock.Anything, mock.Anything, mock.Anything).Return(config.Channels, nil) | |||
repoCall4 := boot.On("Save", context.Background(), mock.Anything, mock.Anything).Return(mock.Anything, nil) | |||
saved, err := svc.Add(context.Background(), validToken, config) | |||
_, err := svc.Add(context.Background(), validToken, config) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same
bootstrap/service_test.go
Outdated
@@ -716,7 +716,7 @@ func TestChangeState(t *testing.T) { | |||
repoCall2 := sdk.On("Channel", mock.Anything, mock.Anything).Return(toGroup(config.Channels[0]), nil) | |||
repoCall3 := boot.On("ListExisting", context.Background(), mock.Anything, mock.Anything, mock.Anything).Return(config.Channels, nil) | |||
repoCall4 := boot.On("Save", context.Background(), mock.Anything, mock.Anything).Return(mock.Anything, nil) | |||
saved, err := svc.Add(context.Background(), validToken, config) | |||
_, err := svc.Add(context.Background(), validToken, config) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JeffMboya Please address or provide reply to @nyagamunene comments
@rodneyosodo Raised below question
In that case , Can we have additional state like Additional, we can provide option in bootstrap config, which will prevent user to manually connect disconnect things and channels using things service. |
Signed-off-by: JeffMboya <[email protected]>
Signed-off-by: JeffMboya <[email protected]> Add ConnectThing method to bootstrap Signed-off-by: JeffMboya <[email protected]> Consume ThingConnect in bootstrap Signed-off-by: JeffMboya <[email protected]> Consume ThingConnect in bootstrap Signed-off-by: JeffMboya <[email protected]> Consume ThingConnect in bootstrap Signed-off-by: JeffMboya <[email protected]> Consume ThingConnect event Signed-off-by: JeffMboya <[email protected]> Consume ThingsConnect event Signed-off-by: JeffMboya <[email protected]> Consume ThingsConnect event Signed-off-by: JeffMboya <[email protected]> Consume ThingsConnect event Signed-off-by: JeffMboya <[email protected]> Implement ReadStringSlice Signed-off-by: JeffMboya <[email protected]> Add memberKind and relation checks Signed-off-by: JeffMboya <[email protected]> Add memberKind and relation checks Signed-off-by: JeffMboya <[email protected]> Add memberKind and relation checks Signed-off-by: JeffMboya <[email protected]> Add memberKind and relation checks Signed-off-by: JeffMboya <[email protected]> Add memberKind and relation checks Signed-off-by: JeffMboya <[email protected]> Add TestDisconnectThing to configs_test Signed-off-by: JeffMboya <[email protected]> Update mocks Signed-off-by: JeffMboya <[email protected]>
Signed-off-by: JeffMboya <[email protected]> Refactor: revert to thingID and channelID Signed-off-by: JeffMboya <[email protected]>
Signed-off-by: JeffMboya <[email protected]> Refactor: add memberKind ans relation constants Signed-off-by: JeffMboya <[email protected]> Refactor: add memberKind ans relation constants Signed-off-by: JeffMboya <[email protected]> Refactor: add memberKind ans relation constants Signed-off-by: JeffMboya <[email protected]> Refactor: add memberKind ans relation constants Signed-off-by: JeffMboya <[email protected]>
Signed-off-by: JeffMboya <[email protected]>
Signed-off-by: JeffMboya <[email protected]>
Signed-off-by: JeffMboya <[email protected]>
Signed-off-by: JeffMboya <[email protected]>
Signed-off-by: JeffMboya <[email protected]>
Signed-off-by: JeffMboya <[email protected]>
Signed-off-by: JeffMboya <[email protected]>
Signed-off-by: JeffMboya <[email protected]>
Signed-off-by: JeffMboya <[email protected]>
Signed-off-by: JeffMboya <[email protected]>
Signed-off-by: JeffMboya <[email protected]>
Signed-off-by: JeffMboya <[email protected]>
Signed-off-by: JeffMboya <[email protected]>
Signed-off-by: JeffMboya <[email protected]>
Signed-off-by: JeffMboya <[email protected]>
What type of PR is this?
This is a feature because it adds the connectEvent struct to the consumer package.
What does this do?
This PR adds a new struct, connectEvent, to the consumer package. This struct contains the thingID and channelID, and is triggered whenever a Thing connects to the system.
Which issue(s) does this PR fix/relate to?
Have you included tests for your changes?
Yes, I have included tests for my changes.
Did you document any new/modified feature?
No