Skip to content

Support for Orion deployment #607

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions integration/nwo/fsc/fsc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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())
}
Expand Down Expand Up @@ -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)
}
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down
7 changes: 4 additions & 3 deletions integration/nwo/fsc/topology.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
107 changes: 71 additions & 36 deletions integration/nwo/orion/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand All @@ -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{
Expand All @@ -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 {
Expand Down
Loading
Loading