Skip to content

Commit 3be3a89

Browse files
Merge pull request #309 from sdcio/configdiffadjustments
Config diff adjustments
2 parents eeb6b0b + 95b713e commit 3be3a89

14 files changed

+214
-61
lines changed

pkg/datastore/transaction_rpc.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,14 @@ func (d *Datastore) replaceIntent(ctx context.Context, transaction *types.Transa
9191
log.TraceFn(func() []interface{} { return []interface{}{root.String()} })
9292

9393
// perform validation
94-
validationResult := root.Validate(ctx, d.config.Validation)
94+
validationResult, validationStats := root.Validate(ctx, d.config.Validation)
9595
validationResult.ErrorsStr()
9696
if validationResult.HasErrors() {
9797
return nil, validationResult.JoinErrors()
9898
}
9999

100100
warnings := validationResult.WarningsStr()
101-
101+
log.Debugf("Transaction: %s - validation stats - %s", transaction.GetTransactionId(), validationStats.String())
102102
log.Infof("Transaction: %s - validation passed", transaction.GetTransactionId())
103103

104104
// we use the TargetSourceReplace, that adjustes the tree results in a way
@@ -218,7 +218,9 @@ func (d *Datastore) lowlevelTransactionSet(ctx context.Context, transaction *typ
218218
log.Debug(root.String())
219219

220220
// perform validation
221-
validationResult := root.Validate(ctx, d.config.Validation)
221+
validationResult, validationStats := root.Validate(ctx, d.config.Validation)
222+
223+
log.Debugf("Transaction: %s - Validation Stats: %s", transaction.GetTransactionId(), validationStats.String())
222224

223225
// prepare the response struct
224226
result := &sdcpb.TransactionSetResponse{

pkg/datastore/tree_operation_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,7 @@ func TestDatastore_populateTree(t *testing.T) {
823823
}
824824
fmt.Println(root.String())
825825

826-
validationResult := root.Validate(ctx, validationConfig)
826+
validationResult, _ := root.Validate(ctx, validationConfig)
827827

828828
fmt.Printf("Validation Errors:\n%v\n", strings.Join(validationResult.ErrorsStr(), "\n"))
829829
fmt.Printf("Tree:%s\n", root.String())

pkg/datastore/tree_operation_validation_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ func TestDatastore_validateTree(t *testing.T) {
205205
t.Error(err)
206206
}
207207

208-
validationResult := root.Validate(ctx, validationConfig)
208+
validationResult, _ := root.Validate(ctx, validationConfig)
209209

210210
t.Log(root.String())
211211

pkg/tree/entry.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,11 @@ type Entry interface {
7575
// GetDeletes returns the cache-updates that are not updated, have no lower priority value left and hence should be deleted completely
7676
GetDeletes(entries []types.DeleteEntry, aggregatePaths bool) ([]types.DeleteEntry, error)
7777
// Walk takes the EntryVisitor and applies it to every Entry in the tree
78-
Walk(f EntryVisitor) error
78+
Walk(ctx context.Context, v EntryVisitor) error
7979
// Validate kicks off validation
80-
Validate(ctx context.Context, resultChan chan<- *types.ValidationResultEntry, vCfg *config.Validation)
80+
Validate(ctx context.Context, resultChan chan<- *types.ValidationResultEntry, statChan chan<- *types.ValidationStat, vCfg *config.Validation)
8181
// validateMandatory the Mandatory schema field
82-
validateMandatory(ctx context.Context, resultChan chan<- *types.ValidationResultEntry)
82+
validateMandatory(ctx context.Context, resultChan chan<- *types.ValidationResultEntry, statChan chan<- *types.ValidationStat)
8383
// validateMandatoryWithKeys is an internally used function that us called by validateMandatory in case
8484
// the container has keys defined that need to be skipped before the mandatory attributes can be checked
8585
validateMandatoryWithKeys(ctx context.Context, level int, attributes []string, choiceName string, resultChan chan<- *types.ValidationResultEntry)
@@ -157,4 +157,7 @@ type Entry interface {
157157
BlameConfig(includeDefaults bool) (*sdcpb.BlameTreeElement, error)
158158
}
159159

160-
type EntryVisitor func(s *sharedEntryAttributes) error
160+
type EntryVisitor interface {
161+
Visit(ctx context.Context, s *sharedEntryAttributes) error
162+
Up()
163+
}

pkg/tree/entry_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ func Test_Validation_Leaflist_Min_Max(t *testing.T) {
531531

532532
t.Log(root.String())
533533

534-
validationResult := root.Validate(context.TODO(), validationConfig)
534+
validationResult, _ := root.Validate(context.TODO(), validationConfig)
535535

536536
// check if errors are received
537537
// If so, join them and return the cumulated errors
@@ -571,7 +571,7 @@ func Test_Validation_Leaflist_Min_Max(t *testing.T) {
571571
}
572572
}
573573

574-
validationResult := root.Validate(context.TODO(), validationConfig)
574+
validationResult, _ := root.Validate(context.TODO(), validationConfig)
575575

576576
// check if errors are received
577577
// If so, join them and return the cumulated errors
@@ -617,7 +617,7 @@ func Test_Validation_Leaflist_Min_Max(t *testing.T) {
617617
}
618618
}
619619

620-
validationResult := root.Validate(context.TODO(), validationConfig)
620+
validationResult, _ := root.Validate(context.TODO(), validationConfig)
621621

622622
// check if errors are received
623623
// If so, join them and return the cumulated errors
@@ -1213,7 +1213,7 @@ func Test_Validation_String_Pattern(t *testing.T) {
12131213
t.Error(err)
12141214
}
12151215

1216-
validationResult := root.Validate(context.TODO(), validationConfig)
1216+
validationResult, _ := root.Validate(context.TODO(), validationConfig)
12171217

12181218
// check if errors are received
12191219
// If so, join them and return the cumulated errors
@@ -1250,7 +1250,7 @@ func Test_Validation_String_Pattern(t *testing.T) {
12501250
t.Error(err)
12511251
}
12521252

1253-
validationResult := root.Validate(context.TODO(), validationConfig)
1253+
validationResult, _ := root.Validate(context.TODO(), validationConfig)
12541254

12551255
// check if errors are received
12561256
// If so, join them and return the cumulated errors
@@ -1346,7 +1346,7 @@ func Test_Validation_Deref(t *testing.T) {
13461346
t.Error(err)
13471347
}
13481348

1349-
validationResult := root.Validate(context.TODO(), validationConfig)
1349+
validationResult, _ := root.Validate(context.TODO(), validationConfig)
13501350

13511351
// check if errors are received
13521352
// If so, join them and return the cumulated errors

pkg/tree/root_entry.go

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"os"
77
"strings"
8+
"sync"
89

910
"github.com/sdcio/data-server/pkg/config"
1011
"github.com/sdcio/data-server/pkg/tree/importer"
@@ -88,26 +89,44 @@ func (r *RootEntry) ImportConfig(ctx context.Context, basePath types.PathSlice,
8889
return e.ImportConfig(ctx, importer, intentName, intentPrio, flags)
8990
}
9091

91-
func (r *RootEntry) Validate(ctx context.Context, vCfg *config.Validation) types.ValidationResults {
92+
func (r *RootEntry) Validate(ctx context.Context, vCfg *config.Validation) (types.ValidationResults, *types.ValidationStatOverall) {
9293
// perform validation
9394
// we use a channel and cumulate all the errors
9495
validationResultEntryChan := make(chan *types.ValidationResultEntry, 10)
96+
validationStatChan := make(chan *types.ValidationStat, 10)
9597

9698
// start validation in a seperate goroutine
9799
go func() {
98-
r.sharedEntryAttributes.Validate(ctx, validationResultEntryChan, vCfg)
100+
r.sharedEntryAttributes.Validate(ctx, validationResultEntryChan, validationStatChan, vCfg)
99101
close(validationResultEntryChan)
102+
close(validationStatChan)
100103
}()
101104

102105
// create a ValidationResult struct
103106
validationResult := types.ValidationResults{}
107+
validationStatOverall := types.NewValidationStatOverall()
104108

105-
// read from the validationResult channel
106-
for e := range validationResultEntryChan {
107-
validationResult.AddEntry(e)
108-
}
109+
syncWait := &sync.WaitGroup{}
110+
syncWait.Add(1)
111+
go func() {
112+
// read from the validationResult channel
113+
for e := range validationResultEntryChan {
114+
validationResult.AddEntry(e)
115+
}
116+
syncWait.Done()
117+
}()
118+
119+
syncWait.Add(1)
120+
go func() {
121+
// read from the validationResult channel
122+
for e := range validationStatChan {
123+
validationStatOverall.MergeStat(e)
124+
}
125+
syncWait.Done()
126+
}()
109127

110-
return validationResult
128+
syncWait.Wait()
129+
return validationResult, validationStatOverall
111130
}
112131

113132
// String returns the string representation of the Tree.

0 commit comments

Comments
 (0)