5 Commits

Author SHA1 Message Date
Adrian Zuercher
5990e8ee11 tipo .gitea
All checks were successful
Build DBM Service / build (amd64, .exe, windows) (push) Successful in 2m41s
Build DBM Service / build (amd64, , linux) (push) Successful in 2m44s
Build DBM Service / build (arm, 6, , linux) (push) Successful in 2m36s
Build DBM Service / build (arm64, , linux) (push) Successful in 2m34s
2025-08-07 12:20:10 +02:00
Adrian Zuercher
48d05eec7e repo name change 2025-08-07 12:18:57 +02:00
Adrian Zuercher
bc2e582203 send value for correct table update 2025-08-06 22:02:18 +02:00
Adrian Zuercher
21e4231e24 add and improve remove driver function and rename datapoint 2025-07-31 12:20:49 +02:00
Adrian Zuercher
b21101958d add write ping before pinghandler starts 2025-07-27 09:05:53 +02:00
23 changed files with 248 additions and 143 deletions

View File

@@ -0,0 +1,89 @@
name: Build DBM Service
on:
push:
tags:
- '*'
env:
APP_NAME: tecamino-dbm
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
include:
- os: windows
arch: amd64
ext: .exe
- os: linux
arch: amd64
ext: ""
- os: linux
arch: arm64
ext: ""
- os: linux
arch: arm
arm_version: 6
ext: ""
steps:
- uses: actions/checkout@v4
- name: Ensure latest Go is installed in /data/go
run: |
export GOROOT=/data/go/go
export PATH=$GOROOT/bin:$PATH
export GOCACHE=/data/gocache
export GOMODCACHE=/data/gomodcache
mkdir -p $GOCACHE $GOMODCACHE
if [ ! -x "$GOROOT/bin/go" ]; then
echo "Go not found in $GOROOT, downloading latest stable..."
GO_VERSION=$(curl -s https://go.dev/VERSION?m=text | head -n1)
echo "Latest version is $GO_VERSION"
mkdir -p /data/go
curl -sSL "https://go.dev/dl/${GO_VERSION}.linux-amd64.tar.gz" -o /tmp/go.tar.gz
tar -C /data/go -xzf /tmp/go.tar.gz
else
echo "Using cached Go from $GOROOT"
fi
go version
- name: Download Go dependencies
run: |
export GOROOT=/data/go/go
export PATH=$GOROOT/bin:$PATH
export GOCACHE=/data/gocache
export GOMODCACHE=/data/gomodcache
mkdir -p $GOCACHE $GOMODCACHE
go mod download
- name: Build binary
run: |
export GOROOT=/data/go/go
export PATH=$GOROOT/bin:$PATH
export GOCACHE=/data/gocache
export GOMODCACHE=/data/gomodcache
mkdir -p $GOCACHE $GOMODCACHE
OUTPUT="bin/${APP_NAME}-${{ matrix.os }}-${{ matrix.arch }}"
if [ -n "${{ matrix.arm_version }}" ]; then
OUTPUT="${OUTPUT}v${{ matrix.arm_version }}"
export GOARM=${{ matrix.arm_version }}
fi
OUTPUT="${OUTPUT}${{ matrix.ext }}"
echo "Building $OUTPUT"
GOOS=${{ matrix.os }} GOARCH=${{ matrix.arch }} go build -ldflags="-s -w" -trimpath -o "$OUTPUT"
shell: bash
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: ${{ env.APP_NAME }}-${{ matrix.os }}-${{ matrix.arch }}
path: bin/

View File

@@ -1,48 +0,0 @@
name: Build Go Binaries
on:
push:
branches: [ main ]
pull_request:
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
goos: [linux, windows]
goarch: [amd64, arm, arm64]
exclude:
- goos: windows
goarch: arm
- goos: windows
goarch: arm64
steps:
- uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.24.0'
- name: Set up Git credentials for private modules
run: |
git config --global url."https://${{ secrets.GH_PAT }}@github.com/".insteadOf "https://github.com/"
echo "GOPRIVATE=github.com/tecamino/*" >> $GITHUB_ENV
- name: Build binary
run: |
mkdir -p build
if [ "${{ matrix.goos }}" == "windows" ]; then
GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} go build -ldflags="-s -w" -trimpath -o build/tecamino-dbm-${{ matrix.goos }}-${{ matrix.goarch }}.exe main.go
else
GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} go build -ldflags="-s -w" -trimpath -o build/tecamino-dbm-${{ matrix.goos }}-${{ matrix.goarch }} main.go
fi
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: binaries-${{ matrix.goos }}-${{ matrix.goarch }}
path: build/

View File

@@ -3,8 +3,8 @@ package args
import ( import (
"flag" "flag"
"github.com/tecamino/tecamino-dbm/cert" "gitea.tecamino.com/paadi/tecamino-dbm/cert"
"github.com/tecamino/tecamino-dbm/models" "gitea.tecamino.com/paadi/tecamino-dbm/models"
) )
// DBM cli arguments // DBM cli arguments

View File

@@ -5,8 +5,8 @@ import (
"net/http" "net/http"
"time" "time"
json_dataModels "gitea.tecamino.com/paadi/tecamino-json_data/models"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
json_dataModels "github.com/tecamino/tecamino-json_data/models"
) )
func (d *DBMHandler) SaveData(c *gin.Context) { func (d *DBMHandler) SaveData(c *gin.Context) {

View File

@@ -9,10 +9,10 @@ import (
"sync" "sync"
"time" "time"
"github.com/tecamino/tecamino-dbm/args" "gitea.tecamino.com/paadi/tecamino-dbm/args"
"github.com/tecamino/tecamino-dbm/models" "gitea.tecamino.com/paadi/tecamino-dbm/models"
ws "github.com/tecamino/tecamino-dbm/websocket" ws "gitea.tecamino.com/paadi/tecamino-dbm/websocket"
"github.com/tecamino/tecamino-logger/logging" "gitea.tecamino.com/paadi/tecamino-logger/logging"
) )
type DBMHandler struct { type DBMHandler struct {

View File

@@ -1,8 +1,8 @@
package dbm package dbm
import ( import (
json_data "github.com/tecamino/tecamino-json_data" json_data "gitea.tecamino.com/paadi/tecamino-json_data"
json_dataModels "github.com/tecamino/tecamino-json_data/models" json_dataModels "gitea.tecamino.com/paadi/tecamino-json_data/models"
) )
func (d *DBMHandler) Get(req *json_dataModels.Request, id string) { func (d *DBMHandler) Get(req *json_dataModels.Request, id string) {

View File

@@ -1,12 +1,11 @@
package dbm package dbm
import ( import (
"fmt"
"net/http" "net/http"
json_data "gitea.tecamino.com/paadi/tecamino-json_data"
json_dataModels "gitea.tecamino.com/paadi/tecamino-json_data/models"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
json_data "github.com/tecamino/tecamino-json_data"
json_dataModels "github.com/tecamino/tecamino-json_data/models"
) )
func (d *DBMHandler) Json_Data(c *gin.Context) { func (d *DBMHandler) Json_Data(c *gin.Context) {
@@ -46,10 +45,6 @@ func (d *DBMHandler) Json_Data(c *gin.Context) {
} }
if len(payload.Set) > 0 { if len(payload.Set) > 0 {
resp.Set, err = d.DBM.CreateDatapoints(payload.Set...) resp.Set, err = d.DBM.CreateDatapoints(payload.Set...)
for i, o := range resp.Set {
fmt.Println(1000, i, o)
fmt.Println(1001, o.HasChild)
}
if err != nil { if err != nil {
r := json_data.NewResponse() r := json_data.NewResponse()
r.SetError() r.SetError()

View File

@@ -3,7 +3,7 @@ package dbm
import ( import (
"fmt" "fmt"
json_dataModels "github.com/tecamino/tecamino-json_data/models" json_dataModels "gitea.tecamino.com/paadi/tecamino-json_data/models"
) )
func (d *DBMHandler) Set(req *json_dataModels.Request, id string) { func (d *DBMHandler) Set(req *json_dataModels.Request, id string) {

View File

@@ -3,7 +3,7 @@ package dbm
import ( import (
"fmt" "fmt"
json_dataModels "github.com/tecamino/tecamino-json_data/models" json_dataModels "gitea.tecamino.com/paadi/tecamino-json_data/models"
) )
func (d *DBMHandler) Subscribe(req *json_dataModels.Request, id string) { func (d *DBMHandler) Subscribe(req *json_dataModels.Request, id string) {

View File

@@ -1,9 +1,9 @@
package dbm package dbm
import ( import (
"gitea.tecamino.com/paadi/tecamino-dbm/models"
json_dataModels "gitea.tecamino.com/paadi/tecamino-json_data/models"
"github.com/google/uuid" "github.com/google/uuid"
"github.com/tecamino/tecamino-dbm/models"
json_dataModels "github.com/tecamino/tecamino-json_data/models"
) )
func (d *DBMHandler) AddSystemDps() (err error) { func (d *DBMHandler) AddSystemDps() (err error) {

View File

@@ -3,9 +3,9 @@ package dbm
import ( import (
"encoding/json" "encoding/json"
"gitea.tecamino.com/paadi/tecamino-dbm/auth"
json_dataModels "gitea.tecamino.com/paadi/tecamino-json_data/models"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/tecamino/tecamino-dbm/auth"
json_dataModels "github.com/tecamino/tecamino-json_data/models"
) )
const ( const (

View File

@@ -3,5 +3,8 @@ package drivers
type Drivers []Driver type Drivers []Driver
type Driver interface { type Driver interface {
NewArtNetDriver(string)
AddAddress() AddAddress()
} }
//func Add

6
go.mod
View File

@@ -1,14 +1,14 @@
module github.com/tecamino/tecamino-dbm module gitea.tecamino.com/paadi/tecamino-dbm
go 1.24.0 go 1.24.0
require ( require (
gitea.tecamino.com/paadi/tecamino-json_data v0.1.0
gitea.tecamino.com/paadi/tecamino-logger v0.2.1
github.com/gin-contrib/cors v1.7.5 github.com/gin-contrib/cors v1.7.5
github.com/gin-gonic/gin v1.10.0 github.com/gin-gonic/gin v1.10.0
github.com/google/uuid v1.6.0 github.com/google/uuid v1.6.0
github.com/gorilla/websocket v1.5.3 github.com/gorilla/websocket v1.5.3
github.com/tecamino/tecamino-json_data v0.0.21
github.com/tecamino/tecamino-logger v0.2.0
) )
require ( require (

8
go.sum
View File

@@ -1,3 +1,7 @@
gitea.tecamino.com/paadi/tecamino-json_data v0.1.0 h1:zp3L8qUvkVqzuesQdMh/SgZZZbX3pGD9NYa6jtz+JvA=
gitea.tecamino.com/paadi/tecamino-json_data v0.1.0/go.mod h1:/FKhbVYuhiNlQp4552rJJQIhynjLarDzfrgXpupkwZU=
gitea.tecamino.com/paadi/tecamino-logger v0.2.1 h1:sQTBKYPdzn9mmWX2JXZBtGBvNQH7cuXIwsl4TD0aMgE=
gitea.tecamino.com/paadi/tecamino-logger v0.2.1/go.mod h1:FkzRTldUBBOd/iy2upycArDftSZ5trbsX5Ira5OzJgM=
github.com/bytedance/sonic v1.13.2 h1:8/H1FempDZqC4VqjptGo14QQlJx8VdZJegxs6wwfqpQ= github.com/bytedance/sonic v1.13.2 h1:8/H1FempDZqC4VqjptGo14QQlJx8VdZJegxs6wwfqpQ=
github.com/bytedance/sonic v1.13.2/go.mod h1:o68xyaF9u2gvVBuGHPlUVCy+ZfmNNO5ETf1+KgkJhz4= github.com/bytedance/sonic v1.13.2/go.mod h1:o68xyaF9u2gvVBuGHPlUVCy+ZfmNNO5ETf1+KgkJhz4=
github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU= github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU=
@@ -71,10 +75,6 @@ github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/tecamino/tecamino-json_data v0.0.21 h1:ZRN9wyn+p6J1T4b0e9xf1HStVaAy4wb+3yZ9xn5LFc0=
github.com/tecamino/tecamino-json_data v0.0.21/go.mod h1:LLlyD7Wwqplb2BP4PeO86EokEcTRidlW5MwgPd1T2JY=
github.com/tecamino/tecamino-logger v0.2.0 h1:NPH/Gg9qRhmVoW8b39i1eXu/LEftHc74nyISpcRG+XU=
github.com/tecamino/tecamino-logger v0.2.0/go.mod h1:0M1E9Uei/qw3e3WA1x3lBo1eP3H5oeYE7GjYrMahnj8=
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI= github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE= github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE=

View File

@@ -3,10 +3,10 @@ package main
import ( import (
"fmt" "fmt"
"gitea.tecamino.com/paadi/tecamino-dbm/args"
"gitea.tecamino.com/paadi/tecamino-dbm/dbm"
ws "gitea.tecamino.com/paadi/tecamino-dbm/websocket"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/tecamino/tecamino-dbm/args"
"github.com/tecamino/tecamino-dbm/dbm"
ws "github.com/tecamino/tecamino-dbm/websocket"
) )
func main() { func main() {

View File

@@ -2,18 +2,17 @@ package models
import ( import (
"encoding/json" "encoding/json"
"errors"
"fmt" "fmt"
"regexp" "regexp"
"strings" "strings"
"time" "time"
"gitea.tecamino.com/paadi/tecamino-dbm/utils"
ws "gitea.tecamino.com/paadi/tecamino-dbm/websocket"
wsModels "gitea.tecamino.com/paadi/tecamino-dbm/websocket/models"
json_data "gitea.tecamino.com/paadi/tecamino-json_data"
json_dataModels "gitea.tecamino.com/paadi/tecamino-json_data/models"
"github.com/google/uuid" "github.com/google/uuid"
"github.com/tecamino/tecamino-dbm/utils"
ws "github.com/tecamino/tecamino-dbm/websocket"
wsModels "github.com/tecamino/tecamino-dbm/websocket/models"
json_data "github.com/tecamino/tecamino-json_data"
json_dataModels "github.com/tecamino/tecamino-json_data/models"
) )
const ( const (
@@ -70,17 +69,13 @@ func (d *Datapoint) Set(path string, set json_dataModels.Set) (bool, error) {
if set.Driver == nil { if set.Driver == nil {
return changed, nil return changed, nil
} }
if set.Driver.Type == "" {
return changed, errors.New("driver type missing")
}
if set.Driver.Bus == "" {
return changed, errors.New("driver bus name missing")
}
if d.Drivers == nil { if d.Drivers == nil {
d.Drivers = json_dataModels.NewDrivers() d.Drivers = json_dataModels.Drivers{}
} }
d.Drivers.AddDriver(set.Driver.Type, set.Driver.Bus, set.Driver.Address) d.Drivers.AddDriver(set.Driver)
changed = true
d.UpdateDateTime = time.Now().UnixMilli() d.UpdateDateTime = time.Now().UnixMilli()
return changed, nil return changed, nil
@@ -99,6 +94,27 @@ func (d *Datapoint) CreateDatapoints(uuids *Uuids, sets ...json_dataModels.Set)
for _, dp := range sets { for _, dp := range sets {
if dp.Path == "" && dp.Uuid != uuid.Nil {
existing := uuids.GetDatapoint(dp.Uuid)
_, err := existing.Set("", dp)
if err != nil {
return nil, err
}
created = append(created, json_dataModels.Set{
Uuid: existing.Uuid,
Path: existing.Path,
Type: existing.Type,
Value: existing.Value,
Rights: existing.ReadWrite,
Drivers: &existing.Drivers,
Updated: true,
HasChild: existing.HasChild,
})
existing.Publish(OnChange)
continue
}
parts := strings.Split(dp.Path, ":") parts := strings.Split(dp.Path, ":")
current := d current := d
@@ -106,6 +122,7 @@ func (d *Datapoint) CreateDatapoints(uuids *Uuids, sets ...json_dataModels.Set)
if current.Datapoints == nil { if current.Datapoints == nil {
current.Datapoints = make(map[string]*Datapoint) current.Datapoints = make(map[string]*Datapoint)
} }
if i == len(parts)-1 { if i == len(parts)-1 {
// Leaf node: create or update datapoint // Leaf node: create or update datapoint
if existing, ok := current.Datapoints[part]; ok { if existing, ok := current.Datapoints[part]; ok {
@@ -126,7 +143,6 @@ func (d *Datapoint) CreateDatapoints(uuids *Uuids, sets ...json_dataModels.Set)
}) })
existing.Publish(OnChange) existing.Publish(OnChange)
} else { } else {
var uid uuid.UUID = uuid.New() var uid uuid.UUID = uuid.New()
if dp.Uuid != uuid.Nil { if dp.Uuid != uuid.Nil {
@@ -147,8 +163,8 @@ func (d *Datapoint) CreateDatapoints(uuids *Uuids, sets ...json_dataModels.Set)
} }
//add uuid to flat map for faster lookup //add uuid to flat map for faster lookup
uuids.AddDatapoint(current, ndp) renamedDps := uuids.AddDatapoint(current, ndp)
created = append(created, renamedDps...)
created = append(created, json_dataModels.Set{ created = append(created, json_dataModels.Set{
Uuid: ndp.Uuid, Uuid: ndp.Uuid,
Path: ndp.Path, Path: ndp.Path,
@@ -183,8 +199,8 @@ func (d *Datapoint) CreateDatapoints(uuids *Uuids, sets ...json_dataModels.Set)
} }
//add uuid to flat map for faster lookup //add uuid to flat map for faster lookup
uuids.AddDatapoint(current, newDp) renamedDps := uuids.AddDatapoint(current, newDp)
created = append(created, renamedDps...)
created = append(created, json_dataModels.Set{ created = append(created, json_dataModels.Set{
Uuid: newDp.Uuid, Uuid: newDp.Uuid,
Path: newDp.Path, Path: newDp.Path,
@@ -304,6 +320,8 @@ func (d *Datapoint) UpdateValue(value any) error {
return nil return nil
} }
// removes datapoint and its children if path is given
// if path and
func (d *Datapoint) RemoveDatapoint(set json_dataModels.Set) (sets []json_dataModels.Set, err error) { func (d *Datapoint) RemoveDatapoint(set json_dataModels.Set) (sets []json_dataModels.Set, err error) {
parts := strings.Split(set.Path, ":") parts := strings.Split(set.Path, ":")
@@ -324,20 +342,37 @@ func (d *Datapoint) RemoveDatapoint(set json_dataModels.Set) (sets []json_dataMo
toDelete := parts[len(parts)-1] toDelete := parts[len(parts)-1]
if dp, ok := current.Datapoints[toDelete]; ok { if dp, ok := current.Datapoints[toDelete]; ok {
s, p := removeChildren(dp) //if driver information found, remoove only driver information
sets = append(sets, s...) if set.Driver != nil {
publishes = append(publishes, p...) dp.RemoveDriver(set.Driver)
publishes = append(publishes, json_dataModels.Publish{ publishes = append(publishes, json_dataModels.Publish{
Event: OnDelete, Event: OnChange,
Uuid: dp.Uuid, Uuid: dp.Uuid,
Path: dp.Path, Path: dp.Path,
}) Value: dp.Value,
sets = append(sets, json_dataModels.Set{ Drivers: &dp.Drivers,
Uuid: dp.Uuid, })
Path: dp.Path, sets = append(sets, json_dataModels.Set{
}) Uuid: dp.Uuid,
delete(current.Datapoints, toDelete) Path: dp.Path,
Drivers: &dp.Drivers,
Value: dp.Value,
})
} else {
s, pubs := removeChildren(dp)
sets = append(sets, s...)
publishes = append(publishes, pubs...)
publishes = append(publishes, json_dataModels.Publish{
Event: OnDelete,
Uuid: dp.Uuid,
Path: dp.Path,
})
sets = append(sets, json_dataModels.Set{
Uuid: dp.Uuid,
Path: dp.Path,
})
delete(current.Datapoints, toDelete)
}
r := json_data.NewResponse() r := json_data.NewResponse()
r.Publish = append(r.Publish, publishes...) r.Publish = append(r.Publish, publishes...)
@@ -442,7 +477,7 @@ func (d *Datapoint) AddSubscribtion(conn *wsModels.Client, sub json_dataModels.S
} }
} }
func (d *Datapoint) RenamePaths(oldPath string) { func (d *Datapoint) RenamePaths(oldPath string) (renamed []json_dataModels.Set) {
visited := make(map[*Datapoint]bool) visited := make(map[*Datapoint]bool)
if len(d.Datapoints) == 0 { if len(d.Datapoints) == 0 {
@@ -451,11 +486,22 @@ func (d *Datapoint) RenamePaths(oldPath string) {
for _, dp := range d.Datapoints { for _, dp := range d.Datapoints {
dp.Path = strings.Replace(dp.Path, oldPath, d.Path, 1) dp.Path = strings.Replace(dp.Path, oldPath, d.Path, 1)
dp.renameSubPaths(oldPath, d.Path, visited) renamedDps := dp.renameSubPaths(oldPath, d.Path, visited)
renamed = append(renamed, renamedDps...)
renamed = append(renamed, json_dataModels.Set{
Uuid: dp.Uuid,
Path: dp.Path,
Type: dp.Type,
Value: dp.Value,
Rights: dp.ReadWrite,
Drivers: &dp.Drivers,
HasChild: dp.HasChild,
})
} }
return
} }
func (d *Datapoint) renameSubPaths(oldPath, newPath string, visited map[*Datapoint]bool) { func (d *Datapoint) renameSubPaths(oldPath, newPath string, visited map[*Datapoint]bool) (renamed []json_dataModels.Set) {
if visited[d] { if visited[d] {
return return
} }
@@ -467,14 +513,29 @@ func (d *Datapoint) renameSubPaths(oldPath, newPath string, visited map[*Datapoi
for _, dp := range d.Datapoints { for _, dp := range d.Datapoints {
dp.Path = strings.Replace(dp.Path, oldPath, newPath, 1) dp.Path = strings.Replace(dp.Path, oldPath, newPath, 1)
dp.renameSubPaths(oldPath, newPath, visited) renamedDps := dp.renameSubPaths(oldPath, newPath, visited)
renamed = append(renamed, renamedDps...)
renamed = append(renamed, json_dataModels.Set{
Uuid: dp.Uuid,
Path: dp.Path,
Type: dp.Type,
Value: dp.Value,
Rights: dp.ReadWrite,
Drivers: &dp.Drivers,
HasChild: dp.HasChild,
})
} }
return
} }
func (d *Datapoint) RemoveSubscribtion(client *wsModels.Client) { func (d *Datapoint) RemoveSubscribtion(client *wsModels.Client) {
delete(d.Subscriptions, client) delete(d.Subscriptions, client)
} }
func (d *Datapoint) RemoveDriver(driver *json_dataModels.Driver) {
d.Drivers.RemoveDriver(driver)
}
func (d *Datapoint) Publish(eventType string) error { func (d *Datapoint) Publish(eventType string) error {
r := json_data.NewResponse() r := json_data.NewResponse()
r.AddPublish(json_dataModels.Publish{ r.AddPublish(json_dataModels.Publish{

View File

@@ -5,11 +5,11 @@ import (
"runtime" "runtime"
"time" "time"
"gitea.tecamino.com/paadi/tecamino-dbm/utils"
ws "gitea.tecamino.com/paadi/tecamino-dbm/websocket"
json_dataModels "gitea.tecamino.com/paadi/tecamino-json_data/models"
"gitea.tecamino.com/paadi/tecamino-logger/logging"
"github.com/google/uuid" "github.com/google/uuid"
"github.com/tecamino/tecamino-dbm/utils"
ws "github.com/tecamino/tecamino-dbm/websocket"
json_dataModels "github.com/tecamino/tecamino-json_data/models"
"github.com/tecamino/tecamino-logger/logging"
) )
type DBM struct { type DBM struct {

View File

@@ -1,6 +1,6 @@
package models package models
import wsModels "github.com/tecamino/tecamino-dbm/websocket/models" import wsModels "gitea.tecamino.com/paadi/tecamino-dbm/websocket/models"
type Subscriptions map[*wsModels.Client]*Subscription type Subscriptions map[*wsModels.Client]*Subscription

View File

@@ -1,10 +1,8 @@
package models package models
import ( import (
"fmt" json_dataModels "gitea.tecamino.com/paadi/tecamino-json_data/models"
"github.com/google/uuid" "github.com/google/uuid"
json_dataModels "github.com/tecamino/tecamino-json_data/models"
) )
type Uuids map[uuid.UUID]*Datapoint type Uuids map[uuid.UUID]*Datapoint
@@ -13,7 +11,7 @@ func NewUuids() *Uuids {
return &Uuids{} return &Uuids{}
} }
func (u *Uuids) AddDatapoint(parentDp, newDp *Datapoint) { func (u *Uuids) AddDatapoint(parentDp, newDp *Datapoint) (renamed []json_dataModels.Set) {
if odp, ok := (*u)[newDp.Uuid]; ok { if odp, ok := (*u)[newDp.Uuid]; ok {
if odp.Path == newDp.Path { if odp.Path == newDp.Path {
return return
@@ -21,14 +19,14 @@ func (u *Uuids) AddDatapoint(parentDp, newDp *Datapoint) {
newDp.Datapoints = odp.Datapoints newDp.Datapoints = odp.Datapoints
newDp.HasChild = len(odp.Datapoints) > 0 newDp.HasChild = len(odp.Datapoints) > 0
odp.Datapoints = map[string]*Datapoint{} odp.Datapoints = map[string]*Datapoint{}
newDp.RenamePaths(odp.Path) renamed = newDp.RenamePaths(odp.Path)
rmDps, _ := parentDp.RemoveDatapoint(json_dataModels.Set{Path: odp.Path}) rmDps, _ := parentDp.RemoveDatapoint(json_dataModels.Set{Path: odp.Path})
datapoints := u.GetDatapointByPath("System:Datapoints") datapoints := u.GetDatapointByPath("System:Datapoints")
datapoints.UpdateValue(datapoints.Value.(uint64) - uint64(len(rmDps))) datapoints.UpdateValue(datapoints.Value.(uint64) - uint64(len(rmDps)))
fmt.Println(11, newDp.HasChild)
} }
(*u)[newDp.Uuid] = newDp (*u)[newDp.Uuid] = newDp
return
} }
func (u *Uuids) GetDatapoint(uuid uuid.UUID) *Datapoint { func (u *Uuids) GetDatapoint(uuid uuid.UUID) *Datapoint {

View File

@@ -7,13 +7,13 @@ import (
"testing" "testing"
"time" "time"
"gitea.tecamino.com/paadi/tecamino-dbm/args"
"gitea.tecamino.com/paadi/tecamino-dbm/cert"
"gitea.tecamino.com/paadi/tecamino-dbm/dbm"
"gitea.tecamino.com/paadi/tecamino-dbm/models"
"gitea.tecamino.com/paadi/tecamino-dbm/utils"
ws "gitea.tecamino.com/paadi/tecamino-dbm/websocket"
"github.com/google/uuid" "github.com/google/uuid"
"github.com/tecamino/tecamino-dbm/args"
"github.com/tecamino/tecamino-dbm/cert"
"github.com/tecamino/tecamino-dbm/dbm"
"github.com/tecamino/tecamino-dbm/models"
"github.com/tecamino/tecamino-dbm/utils"
ws "github.com/tecamino/tecamino-dbm/websocket"
) )
func TestCreateDps(t *testing.T) { func TestCreateDps(t *testing.T) {

View File

@@ -5,10 +5,10 @@ import (
"fmt" "fmt"
"sync" "sync"
"gitea.tecamino.com/paadi/tecamino-dbm/websocket/models"
wsModels "gitea.tecamino.com/paadi/tecamino-dbm/websocket/models"
json_dataModels "gitea.tecamino.com/paadi/tecamino-json_data/models"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/tecamino/tecamino-dbm/websocket/models"
wsModels "github.com/tecamino/tecamino-dbm/websocket/models"
json_dataModels "github.com/tecamino/tecamino-json_data/models"
) )
// serves as connection handler of websocket // serves as connection handler of websocket
@@ -38,7 +38,6 @@ func (cH *ClientHandler) ConnectNewClient(id string, c *gin.Context) (client *mo
client, err = models.ConnectNewClient(id, c) client, err = models.ConnectNewClient(id, c)
client.OnClose = func(code int, reason string) { client.OnClose = func(code int, reason string) {
fmt.Println(23, "closing", id)
delete(cH.Clients, id) delete(cH.Clients, id)
} }

View File

@@ -17,7 +17,7 @@ var Broadcast Clients = make(Clients)
const ( const (
// Time allowed to write a message to the peer. // Time allowed to write a message to the peer.
writeWait = 30 * time.Second writeWait = 10 * time.Second
// Time allowed to read the next pong message from the peer. // Time allowed to read the next pong message from the peer.
pongWait = 30 * time.Second pongWait = 30 * time.Second
@@ -69,12 +69,15 @@ func ConnectNewClient(id string, c *gin.Context) (*Client, error) {
Broadcast[client.Id] = client Broadcast[client.Id] = client
conn.SetReadDeadline(time.Now().Add(pongWait))
conn.SetPingHandler(func(appData string) error { conn.SetPingHandler(func(appData string) error {
if client.OnPing != nil { if client.OnPing != nil {
client.OnPing() client.OnPing()
} }
conn.SetReadDeadline(time.Now().Add(pongWait))
conn.SetWriteDeadline(time.Now().Add(writeWait)) conn.SetWriteDeadline(time.Now().Add(writeWait))
conn.SetReadDeadline(time.Now().Add(writeWait))
if err := client.conn.WriteControl(websocket.PongMessage, []byte(appData), time.Now().Add(pongWait)); err != nil { if err := client.conn.WriteControl(websocket.PongMessage, []byte(appData), time.Now().Add(pongWait)); err != nil {
client.OnError(err) client.OnError(err)
} }
@@ -162,6 +165,11 @@ func (c *Client) PingInterval(interval time.Duration) {
ticker := time.NewTicker(interval) ticker := time.NewTicker(interval)
defer ticker.Stop() defer ticker.Stop()
if err := c.conn.WriteControl(websocket.PingMessage, []byte("ping"), time.Now().Add(pongWait)); err != nil {
c.OnError(err)
return
}
for range ticker.C { for range ticker.C {
if c.OnPing != nil { if c.OnPing != nil {
c.OnPing() c.OnPing()

View File

@@ -6,11 +6,11 @@ import (
"sync" "sync"
"time" "time"
"gitea.tecamino.com/paadi/tecamino-dbm/cert"
"gitea.tecamino.com/paadi/tecamino-dbm/utils"
"gitea.tecamino.com/paadi/tecamino-logger/logging"
"github.com/gin-contrib/cors" "github.com/gin-contrib/cors"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/tecamino/tecamino-dbm/cert"
"github.com/tecamino/tecamino-dbm/utils"
"github.com/tecamino/tecamino-logger/logging"
) )
// server model for database manager websocket // server model for database manager websocket