Skip to content
This repository has been archived by the owner on Apr 5, 2023. It is now read-only.

Commit

Permalink
Merge pull request #367 from bstasyszyn/365
Browse files Browse the repository at this point in the history
feat: Added a 'Tags' field to the config value
  • Loading branch information
fqutishat authored Feb 18, 2020
2 parents a4e4361 + 8654e10 commit fc25d20
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 12 deletions.
4 changes: 4 additions & 0 deletions pkg/config/ledgerconfig/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ type App struct {
Format Format
// Config contains the actual configuration
Config string
// Tags contains optional tags that describe the data
Tags []string `json:",omitempty"`
// Components zero or more component configs
Components []*Component
}
Expand Down Expand Up @@ -130,6 +132,8 @@ type Component struct {
Format Format
// Config contains the actual configuration
Config string
// Tags contains optional tags that describe the data
Tags []string `json:",omitempty"`
}

// Validate validates the Component
Expand Down
7 changes: 5 additions & 2 deletions pkg/config/ledgerconfig/config/keyvalue.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,20 +132,23 @@ type Value struct {
Format Format
// Config contains the actual configuration
Config string
// Tags contains an optional set of tags that describe the data
Tags []string
}

// NewValue returns a new config Value
func NewValue(txID string, config string, format Format) *Value {
func NewValue(txID string, config string, format Format, tags ...string) *Value {
return &Value{
TxID: txID,
Config: config,
Format: format,
Tags: tags,
}
}

// String returns a readable string for the value
func (v *Value) String() string {
return fmt.Sprintf("(TxID:%s),(Config:%s),(Format:%s)", v.TxID, v.Config, v.Format)
return fmt.Sprintf("(TxID:%s),(Config:%s),(Format:%s),(Tags:%s)", v.TxID, v.Config, v.Format, v.Tags)
}

// KeyValue contains the key and the value for the key
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/ledgerconfig/config/keyvalue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func TestKey_String(t *testing.T) {

func TestValue_String(t *testing.T) {
kv := NewKeyValue(NewAppKey(msp1, app1, v1), NewValue(tx1, "some config", FormatOther))
require.Equal(t, "[(MSP:org1MSP),(Peer:),(AppName:app1),(AppVersion:v1),(Comp:),(CompVersion:)]=[(TxID:tx1),(Config:some config),(Format:OTHER)]", kv.String())
require.Equal(t, "[(MSP:org1MSP),(Peer:),(AppName:app1),(AppVersion:v1),(Comp:),(CompVersion:)]=[(TxID:tx1),(Config:some config),(Format:OTHER),(Tags:[])]", kv.String())
}

func TestKey_Validate(t *testing.T) {
Expand Down
8 changes: 4 additions & 4 deletions pkg/config/ledgerconfig/mgr/keyvaluemap.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (c keyValueMap) populateApp(mspID string, app *config.App, txID string) {

if app.Config != "" {
logger.Debugf("[%s] ... adding config for app [%s] ...", txID, app.AppName)
c[*config.NewAppKey(mspID, app.AppName, app.Version)] = config.NewValue(txID, app.Config, app.Format)
c[*config.NewAppKey(mspID, app.AppName, app.Version)] = config.NewValue(txID, app.Config, app.Format, app.Tags...)
}
}

Expand All @@ -67,22 +67,22 @@ func (c keyValueMap) populatePeerApp(mspID, peerID string, app *config.App, txID

if app.Config != "" {
logger.Debugf("[%s] ... adding config for peer [%s] and app [%s] ...", txID, peerID, app.AppName)
c[*config.NewPeerKey(mspID, peerID, app.AppName, app.Version)] = config.NewValue(txID, app.Config, app.Format)
c[*config.NewPeerKey(mspID, peerID, app.AppName, app.Version)] = config.NewValue(txID, app.Config, app.Format, app.Tags...)
}
}

func (c keyValueMap) populateComponents(mspID string, app *config.App, txID string) {
logger.Debugf("[%s] ... adding components for app [%s] ...", txID, app.AppName)
for _, comp := range app.Components {
logger.Debugf("[%s] ... adding component [%s:%s] for app [%s] ...", txID, comp.Name, comp.Version, app.AppName)
c[*config.NewComponentKey(mspID, app.AppName, app.Version, comp.Name, comp.Version)] = config.NewValue(txID, comp.Config, comp.Format)
c[*config.NewComponentKey(mspID, app.AppName, app.Version, comp.Name, comp.Version)] = config.NewValue(txID, comp.Config, comp.Format, comp.Tags...)
}
}

func (c keyValueMap) populatePeerComponents(mspID, peerID string, app *config.App, txID string) {
logger.Debugf("[%s] ... adding components for peer [%s] and app [%s] ...", txID, peerID, app.AppName)
for _, comp := range app.Components {
logger.Debugf("[%s] ... adding component [%s:%s] for peer [%s] and app [%s] ...", txID, comp.Name, comp.Version, peerID, app.AppName)
c[*config.NewPeerComponentKey(mspID, peerID, app.AppName, app.Version, comp.Name, comp.Version)] = config.NewValue(txID, comp.Config, comp.Format)
c[*config.NewPeerComponentKey(mspID, peerID, app.AppName, app.Version, comp.Name, comp.Version)] = config.NewValue(txID, comp.Config, comp.Format, comp.Tags...)
}
}
30 changes: 26 additions & 4 deletions pkg/config/ledgerconfig/mgr/updatemgr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ const (
app1 = "app1"
app2 = "app2"
app3 = "app3"
app7 = "app7"
app8 = "app8"

comp1 = "comp1"
comp2 = "comp2"
Expand All @@ -43,10 +45,12 @@ const (
txID2 = "tx2"
txID3 = "tx3"

msp1App1V1Config = "msp1-app1-v1-config"
msp1App1V2Config = "msp1-app1-v2-config"
msp1App2V1Config = `{"msp":"msp1", key1": "value1"}`
msp1App2V2Config = `{"msp":"msp1", "key1_1": "value1"}`
msp1App1V1Config = "msp1-app1-v1-config"
msp1App1V2Config = "msp1-app1-v2-config"
msp1App2V1Config = `{"msp":"msp1", key1": "value1"}`
msp1App2V2Config = `{"msp":"msp1", "key1_1": "value1"}`
msp1App7V1Config = `{"msp":"msp1", "key7": "value7"}`
msp1App8V1Comp1V1Config = `{"msp":"msp1", "key7": "value7"}`

msp2App1V1Config = "msp2-app1-v1-config"
msp2App1V2Config = "msp2-app1-v2-config"
Expand Down Expand Up @@ -262,6 +266,18 @@ var (
},
},
}
appConfigWithTags = &config.Config{
MspID: msp1,
Apps: []*config.App{
{AppName: app7, Version: v1, Config: msp1App7V1Config, Format: config.FormatJSON, Tags: []string{"tag1", "tag2"}},
{
AppName: app8, Version: v1,
Components: []*config.Component{
{Name: comp1, Version: v1, Config: msp1App8V1Comp1V1Config, Format: config.FormatJSON, Tags: []string{"tag1"}},
},
},
},
}
)

func TestUpdateManager_StoreError(t *testing.T) {
Expand Down Expand Up @@ -385,6 +401,12 @@ func TestUpdateManager_Save(t *testing.T) {
requireEqualValue(t, r, config.NewPeerComponentKey(msp1, peer1, app1, v1, comp1, v1), config.NewValue(txID2, peer1App1V1Comp1V1ConfigUpdate, config.FormatOther))
requireEqualValue(t, r, config.NewPeerComponentKey(msp1, peer2, app2, v1, comp1, v1), config.NewValue(txID2, peer2App2V1Comp1V1Config, config.FormatYAML))
})
t.Run("App with tags", func(t *testing.T) {
require.NoError(t, m.Save(txID3, appConfigWithTags))

requireEqualValue(t, r, config.NewAppKey(msp1, app7, v1), config.NewValue(txID3, msp1App7V1Config, config.FormatJSON, "tag1", "tag2"))
requireEqualValue(t, r, config.NewComponentKey(msp1, app8, v1, comp1, v1), config.NewValue(txID3, msp1App8V1Comp1V1Config, config.FormatJSON, "tag1"))
})
}

func TestUpdateManager_ValidationError(t *testing.T) {
Expand Down
6 changes: 6 additions & 0 deletions test/bddtests/config_steps.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ func (cp *configPreprocessor) visitApps(srcApps []*App) ([]*App, error) {
AppName: a.AppName,
Version: a.Version,
Format: a.Format,
Tags: a.Tags,
Config: config,
Components: components,
}
Expand All @@ -140,6 +141,7 @@ func (cp *configPreprocessor) visitComponents(srcComponents []*Component) ([]*Co
Name: c.Name,
Version: c.Version,
Format: c.Format,
Tags: c.Tags,
Config: config,
}
}
Expand Down Expand Up @@ -221,6 +223,8 @@ type App struct {
Format Format
// Config contains the actual configuration
Config string
// Tags contains optional tags that describe the data
Tags []string `json:",omitempty"`
// Components zero or more component configs
Components []*Component `json:",omitempty"`
}
Expand All @@ -235,4 +239,6 @@ type Component struct {
Format Format
// Config contains the actual configuration
Config string
// Tags contains optional tags that describe the data
Tags []string `json:",omitempty"`
}
4 changes: 3 additions & 1 deletion test/bddtests/features/ledger_config.feature
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ Feature: ledger-config
@ledger_config_s1
Scenario: Save, get and delete application config
# Save and query app1 v1 config
Given variable "msp1App1V1Config" is assigned the JSON value '{"MspID":"MSP1","Apps":[{"AppName":"app1","Version":"v1","Config":"msp1-app1-v1-config","Format":"Other"}]}'
Given variable "msp1App1V1Config" is assigned the JSON value '{"MspID":"MSP1","Apps":[{"AppName":"app1","Version":"v1","Config":"msp1-app1-v1-config","Format":"Other","Tags":["tag1","tag2"]}]}'
When client invokes chaincode "configscc" with args "save,${msp1App1V1Config}" on the "mychannel" channel
And we wait 1 seconds
Given variable "msp1App1Criteria" is assigned the JSON value '{"MspID":"MSP1","AppName":"app1"}'
When client queries chaincode "configscc" with args "get,${msp1App1Criteria}" on a single peer in the "peerorg1" org on the "mychannel" channel
Then the JSON path "#" of the response has 1 items
And the JSON path "0.Config" of the response equals "msp1-app1-v1-config"
And the JSON path "0.Tags.0" of the response equals "tag1"
And the JSON path "0.Tags.1" of the response equals "tag2"

# Save and query app1 v2 config
Given variable "msp1App1V2Config" is assigned the JSON value '{"MspID":"MSP1","Apps":[{"AppName":"app1","Version":"v2","Config":"msp1-app1-v2-config","Format":"Other"}]}'
Expand Down

0 comments on commit fc25d20

Please sign in to comment.