Skip to content

Commit

Permalink
Included new stores in config for integration tests
Browse files Browse the repository at this point in the history
Signed-off-by: Alexandros Filios <[email protected]>
  • Loading branch information
alexandrosfilios committed Jan 22, 2025
1 parent f1b76c6 commit 0f2286a
Show file tree
Hide file tree
Showing 19 changed files with 326 additions and 165 deletions.
33 changes: 26 additions & 7 deletions integration/nwo/fabric/network/network_support.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import (
"github.com/hyperledger-labs/fabric-smart-client/integration/nwo/fabric/fabricconfig"
"github.com/hyperledger-labs/fabric-smart-client/integration/nwo/fabric/topology"
"github.com/hyperledger-labs/fabric-smart-client/integration/nwo/fsc/node"
"github.com/hyperledger-labs/fabric-smart-client/platform/view/services/db/driver/badger"
"github.com/hyperledger-labs/fabric-smart-client/platform/view/services/db/driver/sql"
"github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gexec"
Expand Down Expand Up @@ -1368,6 +1370,8 @@ const (
AdminPort api.PortName = "Admin"
)

const VaultPersistencePrefix = "fabric.vault"

// PeerPortNames returns the list of ports that need to be reserved for a Peer.
func PeerPortNames() []api.PortName {
return []api.PortName{ListenPort, ChaincodePort, EventsPort, ProfilePort, OperationsPort, P2PPort, WebPort}
Expand Down Expand Up @@ -1611,13 +1615,14 @@ func (n *Network) GenerateCoreConfig(p *topology.Peer) {
"OrdererAddress": func(o *topology.Orderer, portName api.PortName) string { return n.OrdererAddress(o, portName) },
"PeerAddress": func(o *topology.Peer, portName api.PortName) string { return n.PeerAddress(o, portName) },
"CACertsBundlePath": func() string { return n.CACertsBundlePath() },
"FSCNodeVaultPath": func() string { return n.FSCNodeVaultDir(uniqueName) },
"FSCNodeVaultPersistence": func() node.PersistenceOpts { return p.FSCNode.Options.GetPersistence("fabric.vault") },
"FabricName": func() string { return n.topology.Name() },
"DefaultNetwork": func() bool { return defaultNetwork },
"Driver": func() string { return driver },
"Chaincodes": func(channel string) []*topology.ChannelChaincode { return n.Chaincodes(channel) },
"TLSEnabled": func() bool { return tlsEnabled },
"VaultOpts": func() node.PersistenceOpts {
return n.PersistenceOpts(VaultPersistencePrefix, uniqueName, p.FSCNode.Options)
},
"FabricName": func() string { return n.topology.Name() },
"DefaultNetwork": func() bool { return defaultNetwork },
"Driver": func() string { return driver },
"Chaincodes": func(channel string) []*topology.ChannelChaincode { return n.Chaincodes(channel) },
"TLSEnabled": func() bool { return tlsEnabled },
}).Parse(coreTemplate)
Expect(err).NotTo(HaveOccurred())

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

func (n *Network) PersistenceOpts(prefix string, uniqueName string, o *node.Options) node.PersistenceOpts {
if sqlOpts := o.GetPersistence(prefix); sqlOpts != nil {
return node.PersistenceOpts{
Type: sql.SQLPersistence,
SQL: sqlOpts,
}
} else {
return node.PersistenceOpts{
Type: badger.BadgerPersistence,
Badger: &node.BadgerOpts{Path: n.FSCNodeVaultDir(uniqueName)},
}
}
}

func (n *Network) PeersByName(names []string) []*topology.Peer {
var peers []*topology.Peer
for _, p := range n.Peers {
Expand Down
16 changes: 9 additions & 7 deletions integration/nwo/fabric/topology.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package fabric

import (
"github.com/hyperledger-labs/fabric-smart-client/integration/nwo/common/context"
"github.com/hyperledger-labs/fabric-smart-client/integration/nwo/fabric/network"
"github.com/hyperledger-labs/fabric-smart-client/integration/nwo/fabric/opts"
"github.com/hyperledger-labs/fabric-smart-client/integration/nwo/fabric/topology"
"github.com/hyperledger-labs/fabric-smart-client/integration/nwo/fsc/node"
Expand Down Expand Up @@ -182,17 +183,18 @@ func NewTopologyWithName(name string) *topology.Topology {
}
}

// WithPostgresVaultPersistence is a configuration with SQL vault persistence
func WithPostgresVaultPersistence(config postgres.DataSourceProvider) node.Option {
const VaultPersistencePrefix = network.VaultPersistencePrefix

// WithPostgresPersistence is a configuration with SQL persistence
func WithPostgresPersistence(config postgres.DataSourceProvider, prefixes ...string) node.Option {
return func(o *node.Options) error {
if config != nil {
o.PutPersistence("fabric.vault", node.PersistenceOpts{
Type: sql.SQLPersistence,
SQL: node.SQLOpts{
for _, prefix := range prefixes {
o.PutSQLPersistence(prefix, node.SQLOpts{
DataSource: config.DataSource(),
DriverType: sql.Postgres,
},
})
})
}
}
return nil
}
Expand Down
20 changes: 10 additions & 10 deletions integration/nwo/fabric/topology/core_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,18 +316,18 @@ fabric:
{{- end }}
vault:
persistence:
# Persistence type can be \'badger\' (on disk) or \'memory\'
type: {{ FSCNodeVaultPersistence.Type }}
# Persistence type can be \'badger\' (on disk), \'memory\' or \'sql\'
type: {{ VaultOpts.Type }}
opts:
{{- if eq FSCNodeVaultPersistence.Type "sql" }}
driver: {{ FSCNodeVaultPersistence.SQL.DriverType }}
dataSource: {{ FSCNodeVaultPersistence.SQL.DataSource }}
# {{- else if eq FSCNodeVaultPersistence.Type "orion" }}
# network: {{ FSCNodeVaultPersistence.Orion.Network }}
# database: {{ FSCNodeVaultPersistence.Orion.Database }}
# creator: {{ FSCNodeVaultPersistence.Orion.Creator }}
{{- if eq VaultOpts.Type "sql" }}
driver: {{ VaultOpts.SQL.DriverType }}
dataSource: {{ VaultOpts.SQL.DataSource }}
{{- else if eq VaultOpts.Type "badger" }}
path: {{ VaultOpts.Badger.Path }}
{{- else if eq VaultOpts.Type "memory" }}
# Memory has hard-coded opts
{{- else }}
path: {{ FSCNodeVaultPath }}
# Unknown type {{ VaultOpts.Type }}
{{- end }}
txidstore:
cache:
Expand Down
75 changes: 50 additions & 25 deletions integration/nwo/fsc/fsc.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ import (
"github.com/hyperledger-labs/fabric-smart-client/integration/nwo/fsc/commands"
node2 "github.com/hyperledger-labs/fabric-smart-client/integration/nwo/fsc/node"
"github.com/hyperledger-labs/fabric-smart-client/integration/nwo/monitoring/optl"
driver2 "github.com/hyperledger-labs/fabric-smart-client/platform/common/driver"
"github.com/hyperledger-labs/fabric-smart-client/platform/common/utils"
tracing2 "github.com/hyperledger-labs/fabric-smart-client/platform/view/sdk/tracing"
"github.com/hyperledger-labs/fabric-smart-client/platform/view/services/client/view"
view2 "github.com/hyperledger-labs/fabric-smart-client/platform/view/services/client/view/cmd"
"github.com/hyperledger-labs/fabric-smart-client/platform/view/services/client/web"
"github.com/hyperledger-labs/fabric-smart-client/platform/view/services/crypto"
"github.com/hyperledger-labs/fabric-smart-client/platform/view/services/db/driver/badger"
"github.com/hyperledger-labs/fabric-smart-client/platform/view/services/db/driver/sql"
"github.com/hyperledger-labs/fabric-smart-client/platform/view/services/grpc"
"github.com/miracl/conflate"
Expand Down Expand Up @@ -483,17 +483,36 @@ func (p *Platform) GenerateCoreConfig(peer *node2.Replica) {
}

t, err := template.New("peer").Funcs(template.FuncMap{
"Replica": func() *node2.Replica { return peer },
"Peer": func() *node2.Peer { return peer.Peer },
"NetworkID": func() string { return p.NetworkID },
"Topology": func() *Topology { return p.Topology },
"Extensions": func() []string { return extensions },
"ToLower": func(s string) string { return strings.ToLower(s) },
"ReplaceAll": func(s, old, new string) string { return strings.Replace(s, old, new, -1) },
"NodeKVSPath": func() string { return p.NodeKVSDir(peer) },
"NodeKVSPersistence": func() node2.PersistenceOpts { return peer.Options.GetPersistence("fsc") },
"Resolvers": func() []*Resolver { return resolvers },
"WebEnabled": func() bool { return p.Topology.WebEnabled },
"Replica": func() *node2.Replica { return peer },
"Peer": func() *node2.Peer { return peer.Peer },
"NetworkID": func() string { return p.NetworkID },
"Topology": func() *Topology { return p.Topology },
"Extensions": func() []string { return extensions },
"ToLower": func(s string) string { return strings.ToLower(s) },
"ReplaceAll": func(s, old, new string) string { return strings.Replace(s, old, new, -1) },
"KVSOpts": func() node2.PersistenceOpts {
return p.PersistenceOpts(KvsPersistencePrefix, peer.UniqueName, peer.Options, "kvs")
},
"BindingOpts": func() node2.PersistenceOpts {
return p.PersistenceOpts(BindingPersistencePrefix, peer.UniqueName, peer.Options, "binding")
},
"SignerInfoOpts": func() node2.PersistenceOpts {
return p.PersistenceOpts(SignerInfoPersistencePrefix, peer.UniqueName, peer.Options, "signer")
},
"AuditInfoOpts": func() node2.PersistenceOpts {
return p.PersistenceOpts(AuditInfoPersistencePrefix, peer.UniqueName, peer.Options, "audit")
},
"EndorseTxOpts": func() node2.PersistenceOpts {
return p.PersistenceOpts(EndorseTxPersistencePrefix, peer.UniqueName, peer.Options, "etx")
},
"EnvelopeOpts": func() node2.PersistenceOpts {
return p.PersistenceOpts(EnvelopePersistencePrefix, peer.UniqueName, peer.Options, "env")
},
"MetadataOpts": func() node2.PersistenceOpts {
return p.PersistenceOpts(MetadataPersistencePrefix, peer.UniqueName, peer.Options, "metadata")
},
"Resolvers": func() []*Resolver { return resolvers },
"WebEnabled": func() bool { return p.Topology.WebEnabled },
"TracingEndpoint": func() string {
return utils.DefaultString(p.Topology.Monitoring.TracingEndpoint, fmt.Sprintf("0.0.0.0:%d", optl.JaegerCollectorPort))
},
Expand All @@ -502,6 +521,21 @@ func (p *Platform) GenerateCoreConfig(peer *node2.Replica) {
Parse(p.Topology.Templates.CoreTemplate())
Expect(err).NotTo(HaveOccurred())
Expect(t.Execute(io.MultiWriter(core), p)).NotTo(HaveOccurred())

}

func (p *Platform) PersistenceOpts(prefix string, uniqueName string, o *node2.Options, dirName string) node2.PersistenceOpts {
if sqlOpts := o.GetPersistence(prefix); sqlOpts != nil {
return node2.PersistenceOpts{
Type: sql.SQLPersistence,
SQL: sqlOpts,
}
} else {
return node2.PersistenceOpts{
Type: badger.BadgerPersistence,
Badger: &node2.BadgerOpts{Path: p.NodeStorageDir(uniqueName, dirName)},
}
}
}

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

t, err := template.New("node").Funcs(template.FuncMap{
"Alias": func(s string) string { return node.Node.Alias(s) },
"InstallView": func() bool { return len(node.Node.Responders) != 0 || len(node.Node.Factories) != 0 },
"InstallPostgres": func() bool { return GetPersistenceType(node.Peer) == sql.SQLPersistence },
"Alias": func(s string) string { return node.Node.Alias(s) },
"InstallView": func() bool { return len(node.Node.Responders) != 0 || len(node.Node.Factories) != 0 },
}).Parse(p.Topology.Templates.NodeTemplate())
Expect(err).NotTo(HaveOccurred())

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

func (p *Platform) NodeKVSDir(peer *node2.Replica) string {
return filepath.Join(p.Context.RootDir(), "fsc", "nodes", peer.UniqueName, "kvs")
func (p *Platform) NodeStorageDir(uniqueName string, dirName string) string {
return filepath.Join(p.Context.RootDir(), "fsc", "nodes", uniqueName, dirName)
}

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

func GetPersistenceType(peer *node2.Peer) driver2.PersistenceType {
return peer.Options.GetPersistence("fsc").Type
}

func GetPersistenceDataSource(peer *node2.Peer) string {
return peer.Options.GetPersistence("fsc").SQL.DataSource
}

// PeerPortNames returns the list of ports that need to be reserved for a Peer.
func PeerPortNames() []api.PortName {
return []api.PortName{ListenPort, P2PPort, WebPort}
Expand Down
Loading

0 comments on commit 0f2286a

Please sign in to comment.