Skip to content

Commit 0f2286a

Browse files
Included new stores in config for integration tests
Signed-off-by: Alexandros Filios <alexandros.filios@ibm.com>
1 parent f1b76c6 commit 0f2286a

File tree

19 files changed

+326
-165
lines changed

19 files changed

+326
-165
lines changed

integration/nwo/fabric/network/network_support.go

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ import (
2727
"github.com/hyperledger-labs/fabric-smart-client/integration/nwo/fabric/fabricconfig"
2828
"github.com/hyperledger-labs/fabric-smart-client/integration/nwo/fabric/topology"
2929
"github.com/hyperledger-labs/fabric-smart-client/integration/nwo/fsc/node"
30+
"github.com/hyperledger-labs/fabric-smart-client/platform/view/services/db/driver/badger"
31+
"github.com/hyperledger-labs/fabric-smart-client/platform/view/services/db/driver/sql"
3032
"github.com/onsi/ginkgo/v2"
3133
. "github.com/onsi/gomega"
3234
"github.com/onsi/gomega/gexec"
@@ -1368,6 +1370,8 @@ const (
13681370
AdminPort api.PortName = "Admin"
13691371
)
13701372

1373+
const VaultPersistencePrefix = "fabric.vault"
1374+
13711375
// PeerPortNames returns the list of ports that need to be reserved for a Peer.
13721376
func PeerPortNames() []api.PortName {
13731377
return []api.PortName{ListenPort, ChaincodePort, EventsPort, ProfilePort, OperationsPort, P2PPort, WebPort}
@@ -1611,13 +1615,14 @@ func (n *Network) GenerateCoreConfig(p *topology.Peer) {
16111615
"OrdererAddress": func(o *topology.Orderer, portName api.PortName) string { return n.OrdererAddress(o, portName) },
16121616
"PeerAddress": func(o *topology.Peer, portName api.PortName) string { return n.PeerAddress(o, portName) },
16131617
"CACertsBundlePath": func() string { return n.CACertsBundlePath() },
1614-
"FSCNodeVaultPath": func() string { return n.FSCNodeVaultDir(uniqueName) },
1615-
"FSCNodeVaultPersistence": func() node.PersistenceOpts { return p.FSCNode.Options.GetPersistence("fabric.vault") },
1616-
"FabricName": func() string { return n.topology.Name() },
1617-
"DefaultNetwork": func() bool { return defaultNetwork },
1618-
"Driver": func() string { return driver },
1619-
"Chaincodes": func(channel string) []*topology.ChannelChaincode { return n.Chaincodes(channel) },
1620-
"TLSEnabled": func() bool { return tlsEnabled },
1618+
"VaultOpts": func() node.PersistenceOpts {
1619+
return n.PersistenceOpts(VaultPersistencePrefix, uniqueName, p.FSCNode.Options)
1620+
},
1621+
"FabricName": func() string { return n.topology.Name() },
1622+
"DefaultNetwork": func() bool { return defaultNetwork },
1623+
"Driver": func() string { return driver },
1624+
"Chaincodes": func(channel string) []*topology.ChannelChaincode { return n.Chaincodes(channel) },
1625+
"TLSEnabled": func() bool { return tlsEnabled },
16211626
}).Parse(coreTemplate)
16221627
Expect(err).NotTo(HaveOccurred())
16231628

@@ -1629,6 +1634,20 @@ func (n *Network) GenerateCoreConfig(p *topology.Peer) {
16291634
}
16301635
}
16311636

1637+
func (n *Network) PersistenceOpts(prefix string, uniqueName string, o *node.Options) node.PersistenceOpts {
1638+
if sqlOpts := o.GetPersistence(prefix); sqlOpts != nil {
1639+
return node.PersistenceOpts{
1640+
Type: sql.SQLPersistence,
1641+
SQL: sqlOpts,
1642+
}
1643+
} else {
1644+
return node.PersistenceOpts{
1645+
Type: badger.BadgerPersistence,
1646+
Badger: &node.BadgerOpts{Path: n.FSCNodeVaultDir(uniqueName)},
1647+
}
1648+
}
1649+
}
1650+
16321651
func (n *Network) PeersByName(names []string) []*topology.Peer {
16331652
var peers []*topology.Peer
16341653
for _, p := range n.Peers {

integration/nwo/fabric/topology.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package fabric
88

99
import (
1010
"github.com/hyperledger-labs/fabric-smart-client/integration/nwo/common/context"
11+
"github.com/hyperledger-labs/fabric-smart-client/integration/nwo/fabric/network"
1112
"github.com/hyperledger-labs/fabric-smart-client/integration/nwo/fabric/opts"
1213
"github.com/hyperledger-labs/fabric-smart-client/integration/nwo/fabric/topology"
1314
"github.com/hyperledger-labs/fabric-smart-client/integration/nwo/fsc/node"
@@ -182,17 +183,18 @@ func NewTopologyWithName(name string) *topology.Topology {
182183
}
183184
}
184185

185-
// WithPostgresVaultPersistence is a configuration with SQL vault persistence
186-
func WithPostgresVaultPersistence(config postgres.DataSourceProvider) node.Option {
186+
const VaultPersistencePrefix = network.VaultPersistencePrefix
187+
188+
// WithPostgresPersistence is a configuration with SQL persistence
189+
func WithPostgresPersistence(config postgres.DataSourceProvider, prefixes ...string) node.Option {
187190
return func(o *node.Options) error {
188191
if config != nil {
189-
o.PutPersistence("fabric.vault", node.PersistenceOpts{
190-
Type: sql.SQLPersistence,
191-
SQL: node.SQLOpts{
192+
for _, prefix := range prefixes {
193+
o.PutSQLPersistence(prefix, node.SQLOpts{
192194
DataSource: config.DataSource(),
193195
DriverType: sql.Postgres,
194-
},
195-
})
196+
})
197+
}
196198
}
197199
return nil
198200
}

integration/nwo/fabric/topology/core_template.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -316,18 +316,18 @@ fabric:
316316
{{- end }}
317317
vault:
318318
persistence:
319-
# Persistence type can be \'badger\' (on disk) or \'memory\'
320-
type: {{ FSCNodeVaultPersistence.Type }}
319+
# Persistence type can be \'badger\' (on disk), \'memory\' or \'sql\'
320+
type: {{ VaultOpts.Type }}
321321
opts:
322-
{{- if eq FSCNodeVaultPersistence.Type "sql" }}
323-
driver: {{ FSCNodeVaultPersistence.SQL.DriverType }}
324-
dataSource: {{ FSCNodeVaultPersistence.SQL.DataSource }}
325-
# {{- else if eq FSCNodeVaultPersistence.Type "orion" }}
326-
# network: {{ FSCNodeVaultPersistence.Orion.Network }}
327-
# database: {{ FSCNodeVaultPersistence.Orion.Database }}
328-
# creator: {{ FSCNodeVaultPersistence.Orion.Creator }}
322+
{{- if eq VaultOpts.Type "sql" }}
323+
driver: {{ VaultOpts.SQL.DriverType }}
324+
dataSource: {{ VaultOpts.SQL.DataSource }}
325+
{{- else if eq VaultOpts.Type "badger" }}
326+
path: {{ VaultOpts.Badger.Path }}
327+
{{- else if eq VaultOpts.Type "memory" }}
328+
# Memory has hard-coded opts
329329
{{- else }}
330-
path: {{ FSCNodeVaultPath }}
330+
# Unknown type {{ VaultOpts.Type }}
331331
{{- end }}
332332
txidstore:
333333
cache:

integration/nwo/fsc/fsc.go

Lines changed: 50 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ import (
2929
"github.com/hyperledger-labs/fabric-smart-client/integration/nwo/fsc/commands"
3030
node2 "github.com/hyperledger-labs/fabric-smart-client/integration/nwo/fsc/node"
3131
"github.com/hyperledger-labs/fabric-smart-client/integration/nwo/monitoring/optl"
32-
driver2 "github.com/hyperledger-labs/fabric-smart-client/platform/common/driver"
3332
"github.com/hyperledger-labs/fabric-smart-client/platform/common/utils"
3433
tracing2 "github.com/hyperledger-labs/fabric-smart-client/platform/view/sdk/tracing"
3534
"github.com/hyperledger-labs/fabric-smart-client/platform/view/services/client/view"
3635
view2 "github.com/hyperledger-labs/fabric-smart-client/platform/view/services/client/view/cmd"
3736
"github.com/hyperledger-labs/fabric-smart-client/platform/view/services/client/web"
3837
"github.com/hyperledger-labs/fabric-smart-client/platform/view/services/crypto"
38+
"github.com/hyperledger-labs/fabric-smart-client/platform/view/services/db/driver/badger"
3939
"github.com/hyperledger-labs/fabric-smart-client/platform/view/services/db/driver/sql"
4040
"github.com/hyperledger-labs/fabric-smart-client/platform/view/services/grpc"
4141
"github.com/miracl/conflate"
@@ -483,17 +483,36 @@ func (p *Platform) GenerateCoreConfig(peer *node2.Replica) {
483483
}
484484

485485
t, err := template.New("peer").Funcs(template.FuncMap{
486-
"Replica": func() *node2.Replica { return peer },
487-
"Peer": func() *node2.Peer { return peer.Peer },
488-
"NetworkID": func() string { return p.NetworkID },
489-
"Topology": func() *Topology { return p.Topology },
490-
"Extensions": func() []string { return extensions },
491-
"ToLower": func(s string) string { return strings.ToLower(s) },
492-
"ReplaceAll": func(s, old, new string) string { return strings.Replace(s, old, new, -1) },
493-
"NodeKVSPath": func() string { return p.NodeKVSDir(peer) },
494-
"NodeKVSPersistence": func() node2.PersistenceOpts { return peer.Options.GetPersistence("fsc") },
495-
"Resolvers": func() []*Resolver { return resolvers },
496-
"WebEnabled": func() bool { return p.Topology.WebEnabled },
486+
"Replica": func() *node2.Replica { return peer },
487+
"Peer": func() *node2.Peer { return peer.Peer },
488+
"NetworkID": func() string { return p.NetworkID },
489+
"Topology": func() *Topology { return p.Topology },
490+
"Extensions": func() []string { return extensions },
491+
"ToLower": func(s string) string { return strings.ToLower(s) },
492+
"ReplaceAll": func(s, old, new string) string { return strings.Replace(s, old, new, -1) },
493+
"KVSOpts": func() node2.PersistenceOpts {
494+
return p.PersistenceOpts(KvsPersistencePrefix, peer.UniqueName, peer.Options, "kvs")
495+
},
496+
"BindingOpts": func() node2.PersistenceOpts {
497+
return p.PersistenceOpts(BindingPersistencePrefix, peer.UniqueName, peer.Options, "binding")
498+
},
499+
"SignerInfoOpts": func() node2.PersistenceOpts {
500+
return p.PersistenceOpts(SignerInfoPersistencePrefix, peer.UniqueName, peer.Options, "signer")
501+
},
502+
"AuditInfoOpts": func() node2.PersistenceOpts {
503+
return p.PersistenceOpts(AuditInfoPersistencePrefix, peer.UniqueName, peer.Options, "audit")
504+
},
505+
"EndorseTxOpts": func() node2.PersistenceOpts {
506+
return p.PersistenceOpts(EndorseTxPersistencePrefix, peer.UniqueName, peer.Options, "etx")
507+
},
508+
"EnvelopeOpts": func() node2.PersistenceOpts {
509+
return p.PersistenceOpts(EnvelopePersistencePrefix, peer.UniqueName, peer.Options, "env")
510+
},
511+
"MetadataOpts": func() node2.PersistenceOpts {
512+
return p.PersistenceOpts(MetadataPersistencePrefix, peer.UniqueName, peer.Options, "metadata")
513+
},
514+
"Resolvers": func() []*Resolver { return resolvers },
515+
"WebEnabled": func() bool { return p.Topology.WebEnabled },
497516
"TracingEndpoint": func() string {
498517
return utils.DefaultString(p.Topology.Monitoring.TracingEndpoint, fmt.Sprintf("0.0.0.0:%d", optl.JaegerCollectorPort))
499518
},
@@ -502,6 +521,21 @@ func (p *Platform) GenerateCoreConfig(peer *node2.Replica) {
502521
Parse(p.Topology.Templates.CoreTemplate())
503522
Expect(err).NotTo(HaveOccurred())
504523
Expect(t.Execute(io.MultiWriter(core), p)).NotTo(HaveOccurred())
524+
525+
}
526+
527+
func (p *Platform) PersistenceOpts(prefix string, uniqueName string, o *node2.Options, dirName string) node2.PersistenceOpts {
528+
if sqlOpts := o.GetPersistence(prefix); sqlOpts != nil {
529+
return node2.PersistenceOpts{
530+
Type: sql.SQLPersistence,
531+
SQL: sqlOpts,
532+
}
533+
} else {
534+
return node2.PersistenceOpts{
535+
Type: badger.BadgerPersistence,
536+
Badger: &node2.BadgerOpts{Path: p.NodeStorageDir(uniqueName, dirName)},
537+
}
538+
}
505539
}
506540

507541
func (p *Platform) BootstrapViewNodeGroupRunner() ifrit.Runner {
@@ -589,9 +623,8 @@ func (p *Platform) GenerateCmd(output io.Writer, node *node2.Replica) string {
589623
}
590624

591625
t, err := template.New("node").Funcs(template.FuncMap{
592-
"Alias": func(s string) string { return node.Node.Alias(s) },
593-
"InstallView": func() bool { return len(node.Node.Responders) != 0 || len(node.Node.Factories) != 0 },
594-
"InstallPostgres": func() bool { return GetPersistenceType(node.Peer) == sql.SQLPersistence },
626+
"Alias": func(s string) string { return node.Node.Alias(s) },
627+
"InstallView": func() bool { return len(node.Node.Responders) != 0 || len(node.Node.Factories) != 0 },
595628
}).Parse(p.Topology.Templates.NodeTemplate())
596629
Expect(err).NotTo(HaveOccurred())
597630

@@ -611,8 +644,8 @@ func (p *Platform) NodeClientConfigPath(peer *node2.Replica) string {
611644
return filepath.Join(p.Context.RootDir(), "fsc", "nodes", peer.UniqueName, "client-config.yaml")
612645
}
613646

614-
func (p *Platform) NodeKVSDir(peer *node2.Replica) string {
615-
return filepath.Join(p.Context.RootDir(), "fsc", "nodes", peer.UniqueName, "kvs")
647+
func (p *Platform) NodeStorageDir(uniqueName string, dirName string) string {
648+
return filepath.Join(p.Context.RootDir(), "fsc", "nodes", uniqueName, dirName)
616649
}
617650

618651
func (p *Platform) NodeConfigPath(peer *node2.Replica) string {
@@ -873,14 +906,6 @@ func (p *Platform) nextColor() string {
873906
return fmt.Sprintf("%dm", color)
874907
}
875908

876-
func GetPersistenceType(peer *node2.Peer) driver2.PersistenceType {
877-
return peer.Options.GetPersistence("fsc").Type
878-
}
879-
880-
func GetPersistenceDataSource(peer *node2.Peer) string {
881-
return peer.Options.GetPersistence("fsc").SQL.DataSource
882-
}
883-
884909
// PeerPortNames returns the list of ports that need to be reserved for a Peer.
885910
func PeerPortNames() []api.PortName {
886911
return []api.PortName{ListenPort, P2PPort, WebPort}

0 commit comments

Comments
 (0)