diff --git a/integration/nwo/fsc/fsc.go b/integration/nwo/fsc/fsc.go index 619344877..5751fcd20 100755 --- a/integration/nwo/fsc/fsc.go +++ b/integration/nwo/fsc/fsc.go @@ -29,6 +29,7 @@ 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" + "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" @@ -492,8 +493,11 @@ func (p *Platform) GenerateCoreConfig(peer *node2.Replica) { "NodeKVSSQLDataSource": func() string { return GetPersistenceDataSource(peer.Peer) }, "Resolvers": func() []*Resolver { return resolvers }, "WebEnabled": func() bool { return p.Topology.WebEnabled }, - "TracingEndpoint": func() string { return fmt.Sprintf("0.0.0.0:%d", optl.JaegerCollectorPort) }, - }).Parse(p.Topology.Templates.CoreTemplate()) + "TracingEndpoint": func() string { + return utils.DefaultString(p.Topology.Monitoring.TracingEndpoint, fmt.Sprintf("0.0.0.0:%d", optl.JaegerCollectorPort)) + }, + }). + Parse(p.Topology.Templates.CoreTemplate()) Expect(err).NotTo(HaveOccurred()) Expect(t.Execute(io.MultiWriter(core), p)).NotTo(HaveOccurred()) } @@ -591,8 +595,8 @@ func (p *Platform) GenerateCmd(output io.Writer, node *node2.Replica) string { Expect(t.Execute(io.MultiWriter(output), struct { *Platform - *node2.Peer - }{p, node.Peer})).NotTo(HaveOccurred()) + *node2.Replica + }{p, node})).NotTo(HaveOccurred()) return p.NodeCmdPackage(node) } @@ -617,7 +621,7 @@ func (p *Platform) NodeCmdDir(peer *node2.Replica) string { wd, err := os.Getwd() Expect(err).ToNot(HaveOccurred()) - return filepath.Join(wd, "cmd", peer.UniqueName) + return filepath.Join(wd, "cmd", peer.Name) } func (p *Platform) NodeCmdPackage(peer *node2.Replica) string { @@ -630,11 +634,11 @@ func (p *Platform) NodeCmdPackage(peer *node2.Replica) string { // both can be built from these paths if withoutGoPath := strings.TrimPrefix(wd, filepath.Join(gopath, "src")); withoutGoPath != wd { return strings.TrimPrefix( - filepath.Join(withoutGoPath, "cmd", peer.UniqueName), + filepath.Join(withoutGoPath, "cmd", peer.Name), string(filepath.Separator), ) } - return filepath.Join(wd, "cmd", peer.UniqueName) + return filepath.Join(wd, "cmd", peer.Name) } func (p *Platform) NodeCmdPath(peer *node2.Replica) string { diff --git a/integration/nwo/fsc/topology.go b/integration/nwo/fsc/topology.go index b16016349..3b4f32a5c 100755 --- a/integration/nwo/fsc/topology.go +++ b/integration/nwo/fsc/topology.go @@ -43,9 +43,10 @@ type Topology struct { } type Monitoring struct { - TracingType tracing.TracerType `yaml:"tracingType,omitempty"` - MetricsType string `yaml:"metricsType,omitempty"` - TLS bool `yaml:"tls,omitempty"` + TracingType tracing.TracerType `yaml:"tracingType,omitempty"` + TracingEndpoint string `yaml:"tracingEndpoint,omitempty"` + MetricsType string `yaml:"metricsType,omitempty"` + TLS bool `yaml:"tls,omitempty"` } // NewTopology returns an empty FSC network topology. diff --git a/integration/nwo/orion/init.go b/integration/nwo/orion/init.go index 12dbdb8aa..77e9d083b 100644 --- a/integration/nwo/orion/init.go +++ b/integration/nwo/orion/init.go @@ -15,32 +15,55 @@ import ( "github.com/hyperledger-labs/orion-sdk-go/pkg/config" logger2 "github.com/hyperledger-labs/orion-server/pkg/logger" "github.com/hyperledger-labs/orion-server/pkg/types" - . "github.com/onsi/gomega" ) -func (p *Platform) InitOrionServer() { +type HelperConfig struct { + *InitConfig `yaml:"init"` +} + +type InitConfig struct { + ServerUrl string `yaml:"serverUrl"` + CACertPath string `yaml:"caCertPath"` + ServerID string `yaml:"serverID"` + AdminID string `yaml:"adminID"` + AdminCertPath string `yaml:"adminCertPath"` + AdminPrivateKeyPath string `yaml:"adminPrivateKeyPath"` + CertPaths map[string]string `yaml:"certPaths"` + DBs []DB `yaml:"dbs"` +} + +func (p *InitConfig) Init() error { logger.Infof("initializing orion server") - bcDB := p.CreateDBInstance() + bcDB, err := p.CreateDBInstance() + if err != nil { + return err + } logger.Infof("create admin session") - session := p.CreateUserSession(bcDB, "admin") - p.initDBs(session) - p.initUsers(session) + session, err := p.CreateUserSession(bcDB) + if err != nil { + return err + } + if err := p.initDBs(session); err != nil { + return err + } + if err := p.initUsers(session); err != nil { + return err + } + return nil } -func (p *Platform) CreateUserSession(bcdb bcdb.BCDB, user string) bcdb.DBSession { - session, err := bcdb.Session(&config.SessionConfig{ +func (p *InitConfig) CreateUserSession(bcdb bcdb.BCDB) (bcdb.DBSession, error) { + return bcdb.Session(&config.SessionConfig{ UserConfig: &config.UserConfig{ - UserID: user, - CertPath: p.pem(user), - PrivateKeyPath: p.key(user), + UserID: p.AdminID, + CertPath: p.AdminCertPath, + PrivateKeyPath: p.AdminPrivateKeyPath, }, TxTimeout: time.Second * 5, }) - Expect(err).ToNot(HaveOccurred()) - return session } -func (p *Platform) CreateDBInstance() bcdb.BCDB { +func (p *InitConfig) CreateDBInstance() (bcdb.BCDB, error) { c := &logger2.Config{ Level: "info", OutputPath: []string{"stdout"}, @@ -49,51 +72,60 @@ func (p *Platform) CreateDBInstance() bcdb.BCDB { Name: "bcdb-client", } clientLogger, err := logger2.New(c) - Expect(err).ToNot(HaveOccurred()) + if err != nil { + return nil, err + } - bcDB, err := bcdb.Create(&config.ConnectionConfig{ + return bcdb.Create(&config.ConnectionConfig{ RootCAs: []string{ - p.caPem(), + p.CACertPath, }, ReplicaSet: []*config.Replica{ { - ID: p.localConfig.Server.Identity.ID, - Endpoint: p.serverUrl.String(), + ID: p.ServerID, + Endpoint: p.ServerUrl, }, }, Logger: clientLogger, }) - Expect(err).ToNot(HaveOccurred()) - - return bcDB } -func (p *Platform) initDBs(session bcdb.DBSession) { +func (p *InitConfig) initDBs(session bcdb.DBSession) error { tx, err := session.DBsTx() - Expect(err).ToNot(HaveOccurred()) + if err != nil { + return err + } - logger.Infof("creating databases [%v]", p.Topology.DBs) - for _, db := range p.Topology.DBs { - err = tx.CreateDB(db.Name, nil) - Expect(err).ToNot(HaveOccurred()) + logger.Infof("creating databases [%v]", p.DBs) + for _, db := range p.DBs { + if err := tx.CreateDB(db.Name, nil); err != nil { + return err + } } txID, txReceipt, err := tx.Commit(true) - Expect(err).ToNot(HaveOccurred()) + if err != nil { + return err + } logger.Infof("transaction to create carDB has been submitted, txID = %s, txReceipt = %s", txID, txReceipt.String()) + return nil } -func (p *Platform) initUsers(session bcdb.DBSession) { - for _, db := range p.Topology.DBs { +func (p *InitConfig) initUsers(session bcdb.DBSession) error { + for _, db := range p.DBs { for _, role := range db.Roles { usersTx, err := session.UsersTx() - Expect(err).ToNot(HaveOccurred()) + if err != nil { + return err + } - certPath := p.pem(role) + certPath := p.CertPaths[role] certFile, err := os.ReadFile(certPath) - Expect(err).ToNot(HaveOccurred()) + if err != nil { + return err + } certBlock, _ := pem.Decode(certFile) err = usersTx.PutUser( &types.User{ @@ -108,14 +140,17 @@ func (p *Platform) initUsers(session bcdb.DBSession) { }) if err != nil { usersTx.Abort() - Expect(err).ToNot(HaveOccurred()) + return err } txID, receipt, err := usersTx.Commit(true) - Expect(err).ToNot(HaveOccurred()) + if err != nil { + return err + } logger.Infof("transaction to provision user record has been committed, user-ID: %s, txID = %s, block = %d, txIdx = %d", role, txID, receipt.GetResponse().GetReceipt().GetHeader().GetBaseHeader().GetNumber(), receipt.GetResponse().GetReceipt().GetTxIndex()) } } + return nil } func usersMap(users ...string) map[string]bool { diff --git a/integration/nwo/orion/platform.go b/integration/nwo/orion/platform.go index 484d90b7a..48ca191d0 100755 --- a/integration/nwo/orion/platform.go +++ b/integration/nwo/orion/platform.go @@ -22,6 +22,7 @@ import ( api2 "github.com/hyperledger-labs/fabric-smart-client/integration/nwo/api" "github.com/hyperledger-labs/fabric-smart-client/integration/nwo/common" "github.com/hyperledger-labs/fabric-smart-client/integration/nwo/common/docker" + "github.com/hyperledger-labs/fabric-smart-client/integration/nwo/fabric/network" "github.com/hyperledger-labs/fabric-smart-client/integration/nwo/fsc" "github.com/hyperledger-labs/fabric-smart-client/platform/view/services/flogging" "github.com/hyperledger-labs/orion-server/config" @@ -31,6 +32,12 @@ import ( "gopkg.in/yaml.v2" ) +const ( + Port = network.HostPort + PeerPortID = "peer" + OrdererPortID = "orderer" +) + var logger = flogging.MustGetLogger("nwo.orion") type Identity struct { @@ -194,7 +201,8 @@ func (p *Platform) PostRun(load bool) { Expect(err).NotTo(HaveOccurred()) p.StartOrionServer() - p.InitOrionServer() + err = p.InitOrionServer() + Expect(err).NotTo(HaveOccurred()) } func (p *Platform) Cleanup() { @@ -225,6 +233,26 @@ func (p *Platform) replaceForDocker(origin string) string { return strings.Replace(origin, p.rootDir(), "/etc/orion-server", 1) } +func ReadHelperConfig(configPath string) (*HelperConfig, error) { + data, err := os.ReadFile(configPath) + if err != nil { + return nil, err + } + var c HelperConfig + if err := yaml.Unmarshal(data, &c); err != nil { + return nil, err + } + return &c, err +} + +func (p *Platform) InitOrionServer() error { + c, err := ReadHelperConfig(p.HelperConfigPath()) + if err != nil { + return err + } + return c.InitConfig.Init() +} + func (p *Platform) generateExtension() { fscTopology := p.Context.TopologyByName("fsc").(*fsc.Topology) for _, node := range fscTopology.Nodes { @@ -245,8 +273,8 @@ func (p *Platform) generateExtension() { return []Identity{ { Name: role, - Cert: p.pem(role), - Key: p.key(role), + Cert: p.PemPath(role), + Key: p.KeyPath(role), }, } }, @@ -264,8 +292,11 @@ func (p *Platform) generateExtension() { } func (p *Platform) writeConfigFile() { - p.nodePort = p.Context.ReservePort() - p.peerPort = p.Context.ReservePort() + p.Context.SetPortsByPeerID("", PeerPortID, api2.Ports{Port: p.Context.ReservePort()}) + p.Context.SetPortsByOrdererID("", OrdererPortID, api2.Ports{Port: p.Context.ReservePort()}) + + p.nodePort = p.Context.PortsByOrdererID("", OrdererPortID)[Port] + p.peerPort = p.Context.PortsByPeerID("", PeerPortID)[Port] p.localConfig = &config.LocalConfiguration{ Server: config.ServerConf{ @@ -361,6 +392,37 @@ func (p *Platform) writeConfigFile() { p.saveServerUrl(p.serverUrl) Expect(err).ToNot(HaveOccurred()) + + certPaths := map[string]string{} + for _, db := range p.Topology.DBs { + for _, role := range db.Roles { + certPaths[role] = p.PemPath(role) + } + } + init := &InitConfig{ + ServerUrl: p.ServerUrl(), + CACertPath: p.caPem(), + ServerID: p.ServerID(), + AdminID: "admin", + AdminCertPath: p.PemPath("admin"), + AdminPrivateKeyPath: p.KeyPath("admin"), + DBs: p.Topology.DBs, + CertPaths: certPaths, + } + + i, err := yaml.Marshal(HelperConfig{InitConfig: init}) + Expect(err).ToNot(HaveOccurred()) + + Expect(os.MkdirAll(p.configDir(), 0766)).To(Succeed()) + Expect(os.WriteFile(p.HelperConfigPath(), i, 0766)).To(Succeed()) +} + +func (p *Platform) ServerUrl() string { + return p.serverUrl.String() +} + +func (p *Platform) ServerID() string { + return p.localConfig.Server.Identity.ID } func (p *Platform) rootDir() string { @@ -419,27 +481,19 @@ func (p *Platform) walDir() string { ) } -func (p *Platform) serverPem() string { - return filepath.Join(p.roleCryptoDir("server"), "server.pem") -} +func (p *Platform) serverPem() string { return p.PemPath("server") } -func (p *Platform) serverKey() string { - return filepath.Join(p.roleCryptoDir("server"), "server.key") -} +func (p *Platform) serverKey() string { return p.KeyPath("server") } -func (p *Platform) caPem() string { - return filepath.Join(p.roleCryptoDir("CA"), "CA.pem") -} +func (p *Platform) caPem() string { return p.PemPath("CA") } -func (p *Platform) adminPem() string { - return filepath.Join(p.roleCryptoDir("admin"), "admin.pem") -} +func (p *Platform) adminPem() string { return p.PemPath("admin") } -func (p *Platform) pem(role string) string { +func (p *Platform) PemPath(role string) string { return filepath.Join(p.roleCryptoDir(role), role+".pem") } -func (p *Platform) key(role string) string { +func (p *Platform) KeyPath(role string) string { return filepath.Join(p.roleCryptoDir(role), role+".key") } @@ -457,6 +511,13 @@ func (p *Platform) boostrapSharedConfig() string { ) } +func (p *Platform) HelperConfigPath() string { + return filepath.Join( + p.configDir(), + "helper-config.yaml", + ) +} + func (p *Platform) configFile() string { return filepath.Join( p.configDir(), diff --git a/integration/nwo/orion/topology.go b/integration/nwo/orion/topology.go index 36875a390..72ef940fe 100755 --- a/integration/nwo/orion/topology.go +++ b/integration/nwo/orion/topology.go @@ -30,8 +30,8 @@ func WithRole(role string) node.Option { } type DB struct { - Name string - Roles []string + Name string `yaml:"name,omitempty"` + Roles []string `yaml:"roles,omitempty"` } type Topology struct {