Skip to content
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

Use a separate orchestrator for each namespace #855

Merged
merged 38 commits into from
Jun 14, 2022
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
d616fa8
Reorganize ns manager and orchestrator
shorsher Jun 2, 2022
056e8b1
Instantiate Namespace Manager as the root object
awrichar Jun 3, 2022
494e897
Remove global routes
awrichar Jun 3, 2022
fceb2ee
Fix up orchestrator tests
awrichar Jun 3, 2022
30bc9e6
Merge branch 'main' of github.com:hyperledger/firefly into namespacemgr
awrichar Jun 3, 2022
3a15d6c
Resolve circular dependencies in new tree
awrichar Jun 3, 2022
a843638
Fix startup issues
awrichar Jun 3, 2022
5aaccaa
Bring back /pins route
awrichar Jun 3, 2022
865b919
Add mutex around prometheus singletons
awrichar Jun 3, 2022
2678910
Add back /status/batchmanager route
awrichar Jun 3, 2022
6c01acb
Bring back /websockets route
awrichar Jun 3, 2022
9635e2b
Group orchestrator config into a struct
awrichar Jun 6, 2022
cd6c5dd
Complete orchestrator unit tests
awrichar Jun 6, 2022
0f3facb
Complete namespace manager tests
awrichar Jun 6, 2022
ccc87cb
Implement GetNamespaces on namespace manager
awrichar Jun 6, 2022
4cd08bb
Organize plugins onto child structs
awrichar Jun 7, 2022
0f24541
Merge remote-tracking branch 'origin/main' into namespacemgr
awrichar Jun 7, 2022
a07bd87
Fix SPI routes to use proper namespaces
awrichar Jun 7, 2022
45881b5
Initialize ff_system for legacy networks
awrichar Jun 7, 2022
e6dcaff
Factor out base PluginConfig struct
awrichar Jun 8, 2022
161b6ef
Split out plugin RegisterListener from Init
awrichar Jun 8, 2022
9f6be18
Move plugin init to namespace manager
awrichar Jun 8, 2022
15ddcd5
Add separate plugin types in namespace manager
awrichar Jun 9, 2022
de9ad86
Blockchain plugin can track multiple listeners
awrichar Jun 9, 2022
492193a
Data Exchange plugin can track multiple listeners
awrichar Jun 9, 2022
382cb3e
Merge remote-tracking branch 'kaleido/pins' into namespacemgr
awrichar Jun 9, 2022
588c8f8
Database plugin can track multiple listeners
awrichar Jun 9, 2022
dc11215
Tokens plugin can track multiple listeners
awrichar Jun 9, 2022
e19f2a4
Tweak namespace parsing from dx
awrichar Jun 9, 2022
6e9cce6
Add remaining test coverage
awrichar Jun 9, 2022
7aed6c7
Remove unneeded "name" field
awrichar Jun 9, 2022
f684b6a
Merge remote-tracking branch 'origin/main' into namespacemgr
awrichar Jun 13, 2022
82467b4
Always include namespace when querying pins
awrichar Jun 13, 2022
dd4adf9
Fix for pin filter
awrichar Jun 13, 2022
f7559c9
Return empty list for identity plugins
awrichar Jun 13, 2022
140567d
Use "different namespace" instead of "wrong namespace" in log
awrichar Jun 14, 2022
6091326
Merge remote-tracking branch 'origin/main' into namespacemgr
awrichar Jun 14, 2022
f96daef
Replace "/spi/v1/operations" with "/spi/v1/namespaces/{ns}/operations"
awrichar Jun 14, 2022
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
34 changes: 17 additions & 17 deletions cmd/firefly.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
"github.com/hyperledger/firefly-common/pkg/log"
"github.com/hyperledger/firefly/internal/apiserver"
"github.com/hyperledger/firefly/internal/coreconfig"
"github.com/hyperledger/firefly/internal/orchestrator"
"github.com/hyperledger/firefly/internal/namespace"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
Expand All @@ -58,7 +58,7 @@ var showConfigCommand = &cobra.Command{
Short: "List out the configuration options",
Run: func(cmd *cobra.Command, args []string) {
// Initialize config of all plugins
getOrchestrator()
getRootManager()
_ = config.ReadConfig(configSuffix, cfgFile)

// Print it all out
Expand All @@ -72,18 +72,18 @@ var showConfigCommand = &cobra.Command{

var cfgFile string

var _utOrchestrator orchestrator.Orchestrator
var _utManager namespace.Manager

func init() {
rootCmd.PersistentFlags().StringVarP(&cfgFile, "config", "f", "", "config file")
rootCmd.AddCommand(showConfigCommand)
}

func getOrchestrator() orchestrator.Orchestrator {
if _utOrchestrator != nil {
return _utOrchestrator
func getRootManager() namespace.Manager {
if _utManager != nil {
return _utManager
}
return orchestrator.NewOrchestrator(true)
return namespace.NewNamespaceManager(true)
}

// Execute is called by the main method of the package
Expand Down Expand Up @@ -118,19 +118,19 @@ func run() error {
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)

for {
orchestratorCtx, cancelOrchestratorCtx := context.WithCancel(ctx)
o := getOrchestrator()
rootCtx, rootCancelCtx := context.WithCancel(ctx)
mgr := getRootManager()
as := apiserver.NewAPIServer()
go startFirefly(orchestratorCtx, cancelOrchestratorCtx, o, as, errChan)
go startFirefly(rootCtx, rootCancelCtx, mgr, as, errChan)
select {
case sig := <-sigs:
log.L(ctx).Infof("Shutting down due to %s", sig.String())
cancelCtx()
o.WaitStop()
mgr.WaitStop()
return nil
case <-orchestratorCtx.Done():
case <-rootCtx.Done():
log.L(ctx).Infof("Restarting due to configuration change")
o.WaitStop()
mgr.WaitStop()
// Re-read the configuration
coreconfig.Reset()
if err := config.ReadConfig(configSuffix, cfgFile); err != nil {
Expand All @@ -144,7 +144,7 @@ func run() error {
}
}

func startFirefly(ctx context.Context, cancelCtx context.CancelFunc, o orchestrator.Orchestrator, as apiserver.Server, errChan chan error) {
func startFirefly(ctx context.Context, cancelCtx context.CancelFunc, mgr namespace.Manager, as apiserver.Server, errChan chan error) {
var err error
// Start debug listener
debugPort := config.GetInt(coreconfig.DebugPort)
Expand All @@ -161,18 +161,18 @@ func startFirefly(ctx context.Context, cancelCtx context.CancelFunc, o orchestra
log.L(ctx).Debugf("Debug HTTP endpoint listening on localhost:%d", debugPort)
}

if err = o.Init(ctx, cancelCtx); err != nil {
if err = mgr.Init(ctx, cancelCtx); err != nil {
errChan <- err
return
}
if err = o.Start(); err != nil {
if err = mgr.Start(); err != nil {
errChan <- err
return
}

// Run the API Server

if err = as.Serve(ctx, o); err != nil {
if err = as.Serve(ctx, mgr); err != nil {
errChan <- err
}
}
44 changes: 22 additions & 22 deletions cmd/firefly_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"testing"

"github.com/hyperledger/firefly/mocks/apiservermocks"
"github.com/hyperledger/firefly/mocks/orchestratormocks"
"github.com/hyperledger/firefly/mocks/namespacemocks"
"github.com/spf13/viper"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
Expand All @@ -33,20 +33,20 @@ import (
const configDir = "../test/data/config"

func TestGetEngine(t *testing.T) {
assert.NotNil(t, getOrchestrator())
assert.NotNil(t, getRootManager())
}

func TestExecMissingConfig(t *testing.T) {
_utOrchestrator = &orchestratormocks.Orchestrator{}
defer func() { _utOrchestrator = nil }()
_utManager = &namespacemocks.Manager{}
defer func() { _utManager = nil }()
viper.Reset()
err := Execute()
assert.Regexp(t, "Not Found", err)
}

func TestShowConfig(t *testing.T) {
_utOrchestrator = &orchestratormocks.Orchestrator{}
defer func() { _utOrchestrator = nil }()
_utManager = &namespacemocks.Manager{}
defer func() { _utManager = nil }()
viper.Reset()
rootCmd.SetArgs([]string{"showconf"})
defer rootCmd.SetArgs([]string{})
Expand All @@ -55,33 +55,33 @@ func TestShowConfig(t *testing.T) {
}

func TestExecEngineInitFail(t *testing.T) {
o := &orchestratormocks.Orchestrator{}
o := &namespacemocks.Manager{}
o.On("Init", mock.Anything, mock.Anything).Return(fmt.Errorf("splutter"))
_utOrchestrator = o
defer func() { _utOrchestrator = nil }()
_utManager = o
defer func() { _utManager = nil }()
os.Chdir(configDir)
err := Execute()
assert.Regexp(t, "splutter", err)
}

func TestExecEngineStartFail(t *testing.T) {
o := &orchestratormocks.Orchestrator{}
o := &namespacemocks.Manager{}
o.On("Init", mock.Anything, mock.Anything).Return(nil)
o.On("Start").Return(fmt.Errorf("bang"))
_utOrchestrator = o
defer func() { _utOrchestrator = nil }()
_utManager = o
defer func() { _utManager = nil }()
os.Chdir(configDir)
err := Execute()
assert.Regexp(t, "bang", err)
}

func TestExecOkExitSIGINT(t *testing.T) {
o := &orchestratormocks.Orchestrator{}
o := &namespacemocks.Manager{}
o.On("Init", mock.Anything, mock.Anything).Return(nil)
o.On("Start").Return(nil)
o.On("WaitStop").Return()
_utOrchestrator = o
defer func() { _utOrchestrator = nil }()
_utManager = o
defer func() { _utManager = nil }()

os.Chdir(configDir)
go func() {
Expand All @@ -92,7 +92,7 @@ func TestExecOkExitSIGINT(t *testing.T) {
}

func TestExecOkRestartThenExit(t *testing.T) {
o := &orchestratormocks.Orchestrator{}
o := &namespacemocks.Manager{}
var orContext context.Context
initCount := 0
init := o.On("Init", mock.Anything, mock.Anything, mock.Anything).Return(nil)
Expand All @@ -110,16 +110,16 @@ func TestExecOkRestartThenExit(t *testing.T) {
ws.RunFn = func(a mock.Arguments) {
<-orContext.Done()
}
_utOrchestrator = o
defer func() { _utOrchestrator = nil }()
_utManager = o
defer func() { _utManager = nil }()

os.Chdir(configDir)
err := Execute()
assert.EqualError(t, err, "second run")
}

func TestExecOkRestartConfigProblem(t *testing.T) {
o := &orchestratormocks.Orchestrator{}
o := &namespacemocks.Manager{}
tmpDir, err := os.MkdirTemp(os.TempDir(), "ut")
assert.NoError(t, err)
defer os.RemoveAll(tmpDir)
Expand All @@ -135,16 +135,16 @@ func TestExecOkRestartConfigProblem(t *testing.T) {
<-orContext.Done()
os.Chdir(tmpDir) // this will mean we fail to read the config
})
_utOrchestrator = o
defer func() { _utOrchestrator = nil }()
_utManager = o
defer func() { _utManager = nil }()

os.Chdir(configDir)
err = Execute()
assert.Regexp(t, "Config File.*Not Found", err)
}

func TestAPIServerError(t *testing.T) {
o := &orchestratormocks.Orchestrator{}
o := &namespacemocks.Manager{}
o.On("Init", mock.Anything, mock.Anything).Return(nil)
o.On("Start").Return(nil)
as := &apiservermocks.Server{}
Expand Down
4 changes: 2 additions & 2 deletions docs/config_docs_generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ import (

"github.com/hyperledger/firefly-common/pkg/config"
"github.com/hyperledger/firefly/internal/apiserver"
"github.com/hyperledger/firefly/internal/orchestrator"
"github.com/hyperledger/firefly/internal/namespace"
"github.com/stretchr/testify/assert"
)

func TestGenerateConfigDocs(t *testing.T) {
// Initialize config of all plugins
orchestrator.NewOrchestrator(false)
namespace.NewNamespaceManager(false)
apiserver.InitConfig()
f, err := os.Create(filepath.Join("reference", "config.md"))
assert.NoError(t, err)
Expand Down
4 changes: 2 additions & 2 deletions docs/config_docs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ import (

"github.com/hyperledger/firefly-common/pkg/config"
"github.com/hyperledger/firefly/internal/apiserver"
"github.com/hyperledger/firefly/internal/orchestrator"
"github.com/hyperledger/firefly/internal/namespace"
"github.com/stretchr/testify/assert"
)

func TestConfigDocsUpToDate(t *testing.T) {
// Initialize config of all plugins
orchestrator.NewOrchestrator(false)
namespace.NewNamespaceManager(false)
apiserver.InitConfig()
generatedConfig, err := config.GenerateConfigMarkdown(context.Background(), config.GetKnownKeys())
assert.NoError(t, err)
Expand Down
Loading