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

MF-552 - Use event sourcing to keep Bootstrap service in sync with Things service #603

Merged
merged 16 commits into from
Mar 4, 2019

Conversation

dborovcanin
Copy link
Collaborator

@dborovcanin dborovcanin commented Feb 18, 2019

What does this do?

This PR adds the use of event sourcing from Things service to keep corresponding Bootstrap service entities in sync.

Which issue(s) does this PR fix/relate to?

This PR resolves #552.

List any changes that modify/break current functionality

There are 2 major API changes:
- List of Configs does not return Channels
- Update Config is split to Config fields update and Config connections update

Have you included tests for your changes?

Yes.

Did you document any new/modified functionality?

Yes, docs are up to date.

drasko
drasko previously approved these changes Feb 18, 2019
Copy link
Contributor

@drasko drasko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

manuio
manuio previously approved these changes Feb 22, 2019
Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com>
Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com>
Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com>
Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com>
Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com>
Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com>
Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com>
Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com>
Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com>
Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com>
@codecov-io
Copy link

codecov-io commented Feb 24, 2019

Codecov Report

Merging #603 into master will decrease coverage by 0.41%.
The diff coverage is 82.17%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #603      +/-   ##
==========================================
- Coverage   87.13%   86.72%   -0.42%     
==========================================
  Files          62       62              
  Lines        3437     3623     +186     
==========================================
+ Hits         2995     3142     +147     
- Misses        304      327      +23     
- Partials      138      154      +16
Impacted Files Coverage Δ
bootstrap/state.go 100% <ø> (ø) ⬆️
bootstrap/api/responses.go 100% <100%> (ø) ⬆️
bootstrap/api/transport.go 97.89% <100%> (+0.15%) ⬆️
bootstrap/api/endpoint.go 100% <100%> (ø) ⬆️
bootstrap/postgres/init.go 92.85% <100%> (+3.11%) ⬆️
bootstrap/postgres/configs.go 73.07% <72.97%> (-2.34%) ⬇️
bootstrap/api/requests.go 95.55% <80%> (-4.45%) ⬇️
bootstrap/service.go 84.42% <90.47%> (+2.65%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a60a5c1...e3cea73. Read the comment docs.

Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com>
Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com>
drasko
drasko previously approved these changes Feb 25, 2019
Copy link
Contributor

@drasko drasko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

manuio
manuio previously approved these changes Feb 25, 2019
Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com>
assert.Equal(t, tc.res, data, fmt.Sprintf("%s: expected response '%s' got '%s'", tc.desc, tc.res, data))
var view config
err = json.NewDecoder(res.Body).Decode(&view)
if err != io.EOF {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inline.


func (lm *loggingMiddleware) RemoveConfigHandler(id string) (err error) {
defer func(begin time.Time) {
message := fmt.Sprintf("Method removeConfig for config %s took %s to complete", id, time.Since(begin))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.


func (lm *loggingMiddleware) UpdateChannelHandler(channel bootstrap.Channel) (err error) {
defer func(begin time.Time) {
message := fmt.Sprintf("Method updateChannel for channel %s took %s to complete", channel.ID, time.Since(begin))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.


for rows.Next() {
c := bootstrap.Channel{}
if err = rows.Scan(&c.ID, &c.Name, &c.Metadata); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use :=.


for rows.Next() {
c := bootstrap.Channel{}
if err = rows.Scan(&c.ID, &c.Name, &c.Metadata); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use :=.

return err
}

if err = insertChannels(key, channels, tx); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use :=.

return err
}

if err = updateConnections(key, id, connections, tx); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use :=.

var channels []bootstrap.Channel
for rows.Next() {
var ch bootstrap.Channel
if err = rows.Scan(&ch.ID, &ch.Name, &ch.Metadata); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use :=.

Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com>
@@ -205,6 +242,75 @@ func (crm *configRepositoryMock) RemoveUnknown(key, id string) error {
}

func (crm *configRepositoryMock) SaveUnknown(key, id string) error {
crm.mu.Lock()
crm.mu.Unlock()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't defer needed here?


func (crm *configRepositoryMock) DisconnectThing(channelID, thingID string) error {
crm.mu.Lock()
crm.mu.Unlock()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here - defer

Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com>
Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com>
Copy link
Contributor

@anovakovic01 anovakovic01 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link
Contributor

@drasko drasko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@dborovcanin dborovcanin merged commit 3300814 into absmach:master Mar 4, 2019
@dborovcanin dborovcanin deleted the MF-552 branch March 4, 2019 16:42
davide83 pushed a commit to davide83/mainflux that referenced this pull request May 13, 2019
…ings service (absmach#603)

* Use separate table for Channels

Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com>

* Add inital event sourcing subscription

Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com>

* Add Channel update sync

Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com>

* Add Thing remove sync

Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com>

* Add Channel remove sync

Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com>

* Update service add method marshalling metadata

Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com>

* Make separate methods for connection update

Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com>

* Add diconnect event sync

Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com>

* Update Configs repository mock

Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com>

* Fix service tests

Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com>

* Update repository tests

Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com>

* Update API docs

Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com>

* Update Location header

Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com>

* Update README.md

Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com>

* Fix tests mutex lock

Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com>

* Fix method names in logs

Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com>
manuio pushed a commit that referenced this pull request Oct 12, 2020
…ings service (#603)

* Use separate table for Channels

Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com>

* Add inital event sourcing subscription

Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com>

* Add Channel update sync

Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com>

* Add Thing remove sync

Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com>

* Add Channel remove sync

Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com>

* Update service add method marshalling metadata

Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com>

* Make separate methods for connection update

Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com>

* Add diconnect event sync

Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com>

* Update Configs repository mock

Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com>

* Fix service tests

Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com>

* Update repository tests

Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com>

* Update API docs

Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com>

* Update Location header

Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com>

* Update README.md

Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com>

* Fix tests mutex lock

Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com>

* Fix method names in logs

Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use event sourcing to keep Bootstrap service in sync with Things service
5 participants