Skip to content
Open
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
99 changes: 48 additions & 51 deletions pkg/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,8 @@ package cache

import (
"context"
"fmt"

sdcpb "github.com/sdcio/sdc-protos/sdcpb"
"github.com/sdcio/sdc-protos/tree_persist"
"google.golang.org/protobuf/proto"
)

type Client interface {
Expand All @@ -37,59 +34,59 @@ type Client interface {
InstanceIntentGetAll(ctx context.Context, cacheName string, excludeIntentNames []string, intentChan chan<- *tree_persist.Intent, errChan chan<- error)
}

type Update struct {
path []string
value []byte
priority int32
owner string
ts int64
}
// type Update struct {
// path []string
// value []byte
// priority int32
// owner string
// ts int64
// }

func NewUpdate(path []string, value []byte, priority int32, owner string, ts int64) *Update {
return &Update{
path: path,
value: value,
priority: priority,
owner: owner,
ts: ts,
}
}
// func NewUpdate(path []string, value []byte, priority int32, owner string, ts int64) *Update {
// return &Update{
// path: path,
// value: value,
// priority: priority,
// owner: owner,
// ts: ts,
// }
// }

func (u *Update) GetPath() []string {
return u.path
}
// func (u *Update) GetPath() []string {
// return u.path
// }

func (u *Update) Value() (*sdcpb.TypedValue, error) {
tv := new(sdcpb.TypedValue)
err := proto.Unmarshal(u.value, tv)
if err != nil {
return nil, err
}
return tv, nil
}
// func (u *Update) Value() (*sdcpb.TypedValue, error) {
// tv := new(sdcpb.TypedValue)
// err := proto.Unmarshal(u.value, tv)
// if err != nil {
// return nil, err
// }
// return tv, nil
// }

func (u *Update) Bytes() []byte {
return u.value
}
// func (u *Update) Bytes() []byte {
// return u.value
// }

func (u *Update) Priority() int32 {
return u.priority
}
// func (u *Update) Priority() int32 {
// return u.priority
// }

func (u *Update) Owner() string {
return u.owner
}
// func (u *Update) Owner() string {
// return u.owner
// }

func (u *Update) TS() int64 {
return u.ts
}
// func (u *Update) TS() int64 {
// return u.ts
// }

func (u *Update) String() string {
val := "error decoding value"
v, err := u.Value()
if err == nil {
// if no error occured we use the value
val = v.String()
}
return fmt.Sprintf("path: %s, owner: %s, priority: %d, value: %s", u.path, u.owner, u.priority, val)
}
// func (u *Update) String() string {
// val := "error decoding value"
// v, err := u.Value()
// if err == nil {
// // if no error occured we use the value
// val = v.String()
// }
// return fmt.Sprintf("path: %s, owner: %s, priority: %d, value: %s", u.path, u.owner, u.priority, val)
// }
3 changes: 1 addition & 2 deletions pkg/datastore/tree_operation_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"testing"

"github.com/openconfig/ygot/ygot"
"github.com/sdcio/data-server/pkg/cache"
schemaClient "github.com/sdcio/data-server/pkg/datastore/clients/schema"
"github.com/sdcio/data-server/pkg/pool"
"github.com/sdcio/data-server/pkg/tree"
Expand Down Expand Up @@ -57,7 +56,7 @@ func TestDatastore_validateTree(t *testing.T) {
intentName string
intentPrio int32
intentDelete bool
intendedStoreUpdates []*cache.Update
intendedStoreUpdates []*types.Update
NotOnlyNewOrUpdated bool // it negated when used in the call, usually we want it to be true
expectedWarnings []string
nonRevertive bool
Expand Down
43 changes: 20 additions & 23 deletions pkg/utils/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ import (
"strings"

"github.com/openconfig/gnmi/proto/gnmi"
"github.com/sdcio/data-server/pkg/cache"
"github.com/sdcio/schema-server/pkg/utils"
sdcpb "github.com/sdcio/sdc-protos/sdcpb"
"google.golang.org/protobuf/proto"
)

func GetJsonValue(tv *sdcpb.TypedValue, ietf bool) (any, error) {
Expand Down Expand Up @@ -234,23 +231,23 @@ func BoolPtr(b bool) *bool {
return &b
}

func SdcpbUpdateToCacheUpdate(upd *sdcpb.Update, owner string, prio int32) (*cache.Update, error) {
b, err := proto.Marshal(upd.Value)
if err != nil {
return nil, err
}
return cache.NewUpdate(utils.ToStrings(upd.GetPath(), false, false), b, prio, owner, 0), nil
}

func SdcpbUpdatesToCacheUpdates(upds []*sdcpb.Update, owner string, prio int32) ([]*cache.Update, error) {
result := []*cache.Update{}
for _, upd := range upds {
cUpd, err := SdcpbUpdateToCacheUpdate(upd, owner, prio)
if err != nil {
return nil, err
}
result = append(result, cUpd)
}

return result, nil
}
// func SdcpbUpdateToCacheUpdate(upd *sdcpb.Update, owner string, prio int32) (*cache.Update, error) {
// b, err := proto.Marshal(upd.Value)
// if err != nil {
// return nil, err
// }
// return cache.NewUpdate(utils.ToStrings(upd.GetPath(), false, false), b, prio, owner, 0), nil
// }

// func SdcpbUpdatesToCacheUpdates(upds []*sdcpb.Update, owner string, prio int32) ([]*cache.Update, error) {
// result := []*cache.Update{}
// for _, upd := range upds {
// cUpd, err := SdcpbUpdateToCacheUpdate(upd, owner, prio)
// if err != nil {
// return nil, err
// }
// result = append(result, cUpd)
// }

// return result, nil
// }
Loading