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

Eclipse Kanto Local Digital Twins initial contribution #1

Merged
merged 1 commit into from
May 10, 2022
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
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.go text eol=lf
45 changes: 45 additions & 0 deletions .github/workflows/validation.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Validation

on:
pull_request:
branches:
- main
paths-ignore:
- "**/*.md"
push:
branches:
- main
paths-ignore:
- "**/*.md"

jobs:
validation:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: '1.17.2'
- name: Setup
run: |
go mod download
go install golang.org/x/lint/golint@latest
go get -t ./...
- name: Format
run: |
unformatted_code=$(gofmt -l .)
if [ -n "$unformatted_code" ]; then
echo "Improperly formatted code:"
echo "$unformatted_code"
exit 1
fi
- name: Lint
run: |
golint -set_exit_status ./...
- name: Vet
run: |
go vet ./...
- name: Test
run: |
go test ./... -coverprofile coverage.out -covermode count -tags=unit
go tool cover -func coverage.out
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
**/log/
.idea/
.vscode/
69 changes: 69 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# How to Contribute to Eclipse Kanto - Local Digital Twins

First of all, thanks for considering to contribute to Eclipse Kanto - Local Digital Twins. We really
appreciate the time and effort you want to spend helping to improve things around here.

In order to get you started as fast as possible we need to go through some organizational issues first, though.

## Eclipse Contributor Agreement

Before your contribution can be accepted by the project team contributors must
electronically sign the Eclipse Contributor Agreement (ECA).

* http://www.eclipse.org/legal/ECA.php

Commits that are provided by non-committers must have a Signed-off-by field in
the footer indicating that the author is aware of the terms by which the
contribution has been provided to the project. The non-committer must
additionally have an Eclipse Foundation account and must have a signed Eclipse
Contributor Agreement (ECA) on file.

For more information, please see the Eclipse Committer Handbook:
https://www.eclipse.org/projects/handbook/#resources-commit

## Code Style Guide

* Keep the code well-formatted through: `gofmt`
* Keep the code error-free through: `go vet` and `golint`
* Avoid common mistakes and pitfalls following: [Go Code Review Comments](https://github.com/golang/go/wiki/CodeReviewComments)

## Making Your Changes

* Fork the repository on GitHub.
* Create a new branch for your changes.
* Make your changes following the code style guide (see Code Style Guide section above).
* When you create new files make sure you include a proper license header at the top of the file (see License Header section below).
* Make sure you include test cases for non-trivial features.
* Make sure test cases provide sufficient code coverage (see GitHub actions for minimal accepted coverage).
* Make sure the test suite passes after your changes.
* Commit your changes into that branch.
* Use descriptive and meaningful commit messages. Start the first line of the commit message with the issue number and titile e.g. `[#9865] Add token based authentication`.
* Squash multiple commits that are related to each other semantically into a single one.
* Make sure you use the `-s` flag when committing as explained above.
* Push your changes to your branch in your forked repository.

## License Header

Please make sure any file you newly create contains a proper license header like this:

Adjusted for Go files:
```go
// Copyright (c) <year> Contributors to the Eclipse Foundation
//
// See the NOTICE file(s) distributed with this work for additional
// information regarding copyright ownership.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License 2.0 which is available at
// http://www.eclipse.org/legal/epl-2.0
//
// SPDX-License-Identifier: EPL-2.0
```

## Submitting the Changes

Submit a pull request via the normal GitHub UI.

## After Submitting

* Do not use your branch for any other development, otherwise further changes that you make will be visible in the PR.
163 changes: 163 additions & 0 deletions NOTICE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
# Notices for Eclipse Kanto - Local Digital Twins

This content is produced and maintained by the Eclipse Kanto project.

* Project home: https://eclipse.org/kanto

## Trademarks

Eclipse Kanto, and the Eclipse Kanto Logo are trademarks of the Eclipse Foundation.
Eclipse, and the Eclipse Logo are registered trademarks of the Eclipse Foundation.

## Copyright

All content is the property of the respective authors or their employers.
For more information regarding authorship of content, please consult the
listed source code repository logs.

## Declared Project Licenses

This program and the accompanying materials are made available under the terms
of the Eclipse Public License v2.0 which is available at
https://www.eclipse.org/legal/epl-2.0/

SPDX-License-Identifier: EPL-2.0

## Source Code

The project maintains all source code repositories in the following GitHub organization:

* https://github.com/eclipse-kanto

## Third-party Content

This project makes use of the follow third party projects.

golang/go (1.17.2)

* License: BSD 3-Clause "New" or "Revised" License
* Project: https://github.com/golang/go
* Source: https://github.com/golang/go/releases/tag/go1.17.2

Jeffail/gabs (2.6.1)

* License: MIT License
* Project: https://github.com/Jeffail/gabs
* Source: https://github.com/Jeffail/gabs/releases/tag/v2.6.1

ThreeDotsLabs/watermill (1.1.1)

* License: MIT License
* Project: https://github.com/ThreeDotsLabs/watermill
* Source: https://github.com/ThreeDotsLabs/watermill/releases/tag/v1.1.1

cenkalti/backoff (3.0.0)

* License: MIT License
* Project: https://github.com/cenkalti/backoff
* Source: https://github.com/cenkalti/backoff/releases/tag/v3.0.0

eclipse/ditto-clients-golang (0.0.0-20220225085802-cf3b306280d3)

* License: Eclipse Public License v2.0
* Project: https://github.com/eclipse/ditto-clients-golang
* Source: https://github.com/eclipse/ditto-clients-golang/tree/cf3b306280d3453473ae8dd65e78f978e2c838ea

eclipse/paho.mqtt.golang (1.3.5)

* License: Eclipse Distribution License v1.0
* Project: https://github.com/eclipse/paho.mqtt.golang
* Source: https://github.com/eclipse/paho.mqtt.golang/releases/tag/v1.3.5

fsnotify/fsnotify (1.5.1)

* License: BSD 3-Clause "New" or "Revised" License
* Project: https://github.com/fsnotify/fsnotify
* Source: https://github.com/fsnotify/fsnotify/releases/tag/v1.5.1

google/uuid (1.1.1)

* License: BSD 3-Clause "New" or "Revised" License
* Project: https://github.com/google/uuid
* Source: https://github.com/google/uuid/releases/tag/v1.1.1

gorilla/websocket (1.4.2)

* License: BSD 2-Clause "Simplified" License
* Project: https://github.com/gorilla/websocket
* Source: https://github.com/gorilla/websocket/releases/tag/v1.4.2

hashicorp/go-multierror (1.0.0)

* License: Mozilla Public License 2.0
* Project: https://github.com/hashicorp/go-multierror
* Source: https://github.com/hashicorp/go-multierror/releases/tag/v1.0.0

hashicorp/errwrap (1.0.0)

* License: Mozilla Public License 2.0
* Project: https://github.com/hashicorp/errwrap
* Source: https://github.com/hashicorp/errwrap/releases/tag/v1.0.0

lithammer/shortuuid (3.0.4)

* License: MIT License
* Project: https://github.com/lithammer/shortuuid
* Source: https://github.com/lithammer/shortuuid/releases/tag/v3.0.4

oklog/ulid (1.3.1)

* License: Apache License 2.0
* Project: https://github.com/oklog/ulid
* Source: https://github.com/oklog/ulid/releases/tag/v1.3.1

pkg/errors (0.9.1)

* License: BSD 2-Clause "Simplified" License
* Project: https://github.com/pkg/errors
* Source: http://github.com/pkg/errors/releases/tag/v0.9.1

natefinch/lumberjack (2.0.0)

* License: MIT License
* Project: https://github.com/natefinch/lumberjack
* Source: https://github.com/natefinch/lumberjack/releases/tag/v2.0.0

google/go-tpm (0.3.2)

* License: Apache License 2.0
* Project: https://github.com/google/go-tpm
* Source: https://github.com/google/go-tpm/releases/tag/v0.3.2

golang.org/x/net (0.0.0-20210405180319-a5a99cb37ef4)

* License: BSD 3-Clause "New" or "Revised" License
* Project: https://github.com/golang/net
* Source: https://github.com/golang/net/tree/a5a99cb37ef4b68617775ab669177656090ab396

golang.org/x/sys (0.0.0-20210630005230-0f9fa26af87c)

* License: BSD 3-Clause "New" or "Revised" License
* Project: https://github.com/golang/sys
* Source: https://github.com/golang/sys/tree/0f9fa26af87c481a6877a4ca1330699ba9a30673

imdario/mergo (0.3.12)

* License: BSD 3-Clause "New" or "Revised" License
* Project: https://github.com/imdario/mergo
* Source: https://github.com/imdario/mergo/releases/tag/0.3.12

golang.org/x/time (v0.0.0-20190308202827-9d24e82272b4)

* License: BSD 3-Clause "New" or "Revised" License
* Project: https://github.com/golang/time
* Source: https://github.com/golang/time/tree/9d24e82272b4f38b78bc8cff74fa936d31ccd8ef

## Cryptography

Content may contain encryption software. The country in which you are currently
may have restrictions on the import, possession, and use, and/or re-export to
another country, of encryption software. BEFORE using any encryption software,
please check the country's laws, regulations and policies concerning the import,
possession, or use, and re-export of encryption software, to see if this is
permitted.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
![Kanto logo](https://github.com/eclipse-kanto/kanto/raw/main/logo/kanto.svg)

# Eclipse Kanto - Local Digital Twins

The local digital twins is the component that sits between the cloud and the local message broker at the edge.
Its role is to provide connectivity to the cloud, as well as to ensure that digital twin state is available on a
local level even in offline mode (no matter of the connection state).

Such capabilities were implemented to support offline scenarios and advanced edge computing involving
synchronization with the cloud after disruptions or outages. The synchronization mechanisms were also designed in a
way to significantly reduce data traffic, and efficiently prevent data loss due to long-lasting disruptions.

## Community

* [GitHub Issues](https://github.com/eclipse-kanto/local-digital-twins/issues)
* [Mailing List](https://accounts.eclipse.org/mailing-list/kanto-dev)
53 changes: 53 additions & 0 deletions cmd/twins/events.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Copyright (c) 2022 Contributors to the Eclipse Foundation
//
// See the NOTICE file(s) distributed with this work for additional
// information regarding copyright ownership.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License 2.0 which is available at
// http://www.eclipse.org/legal/epl-2.0
//
// SPDX-License-Identifier: EPL-2.0

package main

import (
"github.com/ThreeDotsLabs/watermill/message"

"github.com/eclipse-kanto/local-digital-twins/internal/commands"
"github.com/eclipse-kanto/local-digital-twins/internal/persistence"
"github.com/eclipse-kanto/suite-connector/logger"

conn "github.com/eclipse-kanto/suite-connector/connector"
)

const (
topicsEvent = "event/#,e/#"
)

func eventsBus(router *message.Router,
honoPub message.Publisher,
mosquittoClient *conn.MQTTConnection,
deviceInfo commands.DeviceInfo,
storage persistence.ThingsStorage,
logger logger.Logger,
) *message.Handler {
mosquittoSub := conn.NewSubscriber(mosquittoClient, conn.QosAtLeastOnce, false, router.Logger(), nil)

h := &commands.Handler{
DeviceInfo: deviceInfo,
MosquittoPub: conn.NewPublisher(mosquittoClient, conn.QosAtLeastOnce, router.Logger(), nil),
HonoPub: honoPub,
Storage: storage,
Logger: logger,
}

//Gateway -> Mosquitto Broker -> Message bus -> Hono
return router.AddHandler("events_bus",
topicsEvent,
mosquittoSub,
conn.TopicEmpty,
honoPub,
h.HandleCommand,
)
}
Loading