Skip to content

Commit 1f60a54

Browse files
committed
Move plugin start calls to namespace manager
Avoid starting plugins more than once. Signed-off-by: Andrew Richardson <andrew.richardson@kaleido.io>
1 parent 3f77c04 commit 1f60a54

File tree

6 files changed

+80
-68
lines changed

6 files changed

+80
-68
lines changed

internal/namespace/manager.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,21 @@ func (nm *namespaceManager) Start() error {
220220
metrics.Registry()
221221
}
222222
for _, ns := range nm.namespaces {
223+
if ns.plugins.Blockchain.Plugin != nil {
224+
if err := ns.plugins.Blockchain.Plugin.Start(); err != nil {
225+
return err
226+
}
227+
}
228+
if ns.plugins.DataExchange.Plugin != nil {
229+
if err := ns.plugins.DataExchange.Plugin.Start(); err != nil {
230+
return err
231+
}
232+
}
233+
for _, plugin := range ns.plugins.Tokens {
234+
if err := plugin.Plugin.Start(); err != nil {
235+
return err
236+
}
237+
}
223238
if err := ns.orchestrator.Start(); err != nil {
224239
return err
225240
}

internal/namespace/manager_test.go

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"github.com/hyperledger/firefly/internal/database/difactory"
3030
"github.com/hyperledger/firefly/internal/dataexchange/dxfactory"
3131
"github.com/hyperledger/firefly/internal/identity/iifactory"
32+
"github.com/hyperledger/firefly/internal/orchestrator"
3233
"github.com/hyperledger/firefly/internal/sharedstorage/ssfactory"
3334
"github.com/hyperledger/firefly/internal/tokens/tifactory"
3435
"github.com/hyperledger/firefly/mocks/blockchainmocks"
@@ -1126,7 +1127,70 @@ func TestStart(t *testing.T) {
11261127
mo.AssertExpectations(t)
11271128
}
11281129

1129-
func TestStartFail(t *testing.T) {
1130+
func TestStartBlockchainFail(t *testing.T) {
1131+
nm := newTestNamespaceManager(true)
1132+
defer nm.cleanup(t)
1133+
1134+
nm.namespaces = map[string]*namespace{
1135+
"ns": {
1136+
plugins: orchestrator.Plugins{
1137+
Blockchain: orchestrator.BlockchainPlugin{
1138+
Plugin: nm.mbi,
1139+
},
1140+
},
1141+
},
1142+
}
1143+
1144+
nm.mbi.On("Start").Return(fmt.Errorf("pop"))
1145+
1146+
err := nm.Start()
1147+
assert.EqualError(t, err, "pop")
1148+
1149+
}
1150+
1151+
func TestStartDataExchangeFail(t *testing.T) {
1152+
nm := newTestNamespaceManager(true)
1153+
defer nm.cleanup(t)
1154+
1155+
nm.namespaces = map[string]*namespace{
1156+
"ns": {
1157+
plugins: orchestrator.Plugins{
1158+
DataExchange: orchestrator.DataExchangePlugin{
1159+
Plugin: nm.mdx,
1160+
},
1161+
},
1162+
},
1163+
}
1164+
1165+
nm.mdx.On("Start").Return(fmt.Errorf("pop"))
1166+
1167+
err := nm.Start()
1168+
assert.EqualError(t, err, "pop")
1169+
1170+
}
1171+
1172+
func TestStartTokensFail(t *testing.T) {
1173+
nm := newTestNamespaceManager(true)
1174+
defer nm.cleanup(t)
1175+
1176+
nm.namespaces = map[string]*namespace{
1177+
"ns": {
1178+
plugins: orchestrator.Plugins{
1179+
Tokens: []orchestrator.TokensPlugin{{
1180+
Plugin: nm.mti,
1181+
}},
1182+
},
1183+
},
1184+
}
1185+
1186+
nm.mti.On("Start").Return(fmt.Errorf("pop"))
1187+
1188+
err := nm.Start()
1189+
assert.EqualError(t, err, "pop")
1190+
1191+
}
1192+
1193+
func TestStartOrchestratorFail(t *testing.T) {
11301194
nm := newTestNamespaceManager(true)
11311195
defer nm.cleanup(t)
11321196

internal/orchestrator/orchestrator.go

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -262,29 +262,16 @@ func (or *orchestrator) Start() (err error) {
262262
if err == nil {
263263
err = or.broadcast.Start()
264264
}
265-
if err == nil {
266-
err = or.messaging.Start()
267-
}
268265
if err == nil {
269266
err = or.sharedDownload.Start()
270267
}
271268
}
272-
if err == nil {
273-
err = or.blockchain().Start()
274-
}
275269
if err == nil {
276270
err = or.events.Start()
277271
}
278272
if err == nil {
279273
err = or.operations.Start()
280274
}
281-
if err == nil {
282-
for _, el := range or.tokens() {
283-
if err = el.Start(); err != nil {
284-
break
285-
}
286-
}
287-
}
288275
or.started = true
289276
return err
290277
}

internal/orchestrator/orchestrator_test.go

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -379,41 +379,6 @@ func TestStartBatchFail(t *testing.T) {
379379
assert.EqualError(t, err, "pop")
380380
}
381381

382-
func TestStartTokensFail(t *testing.T) {
383-
coreconfig.Reset()
384-
or := newTestOrchestrator()
385-
defer or.cleanup(t)
386-
or.mdi.On("GetNamespace", mock.Anything, "ns").Return(nil, nil)
387-
or.mdi.On("UpsertNamespace", mock.Anything, mock.Anything, true).Return(nil)
388-
or.mmp.On("ConfigureContract", mock.Anything, &core.FireFlyContracts{}).Return(nil)
389-
or.mbi.On("Start").Return(nil)
390-
or.mba.On("Start").Return(nil)
391-
or.mem.On("Start").Return(nil)
392-
or.mbm.On("Start").Return(nil)
393-
or.mpm.On("Start").Return(nil)
394-
or.msd.On("Start").Return(nil)
395-
or.mom.On("Start").Return(nil)
396-
or.mti.On("Start").Return(fmt.Errorf("pop"))
397-
err := or.Start()
398-
assert.EqualError(t, err, "pop")
399-
}
400-
401-
func TestStartBlockchainsFail(t *testing.T) {
402-
coreconfig.Reset()
403-
or := newTestOrchestrator()
404-
defer or.cleanup(t)
405-
or.mdi.On("GetNamespace", mock.Anything, "ns").Return(nil, nil)
406-
or.mdi.On("UpsertNamespace", mock.Anything, mock.Anything, true).Return(nil)
407-
or.mmp.On("ConfigureContract", mock.Anything, &core.FireFlyContracts{}).Return(nil)
408-
or.mbm.On("Start").Return(nil)
409-
or.mpm.On("Start").Return(nil)
410-
or.mba.On("Start").Return(nil)
411-
or.msd.On("Start").Return(nil)
412-
or.mbi.On("Start").Return(fmt.Errorf("pop"))
413-
err := or.Start()
414-
assert.EqualError(t, err, "pop")
415-
}
416-
417382
func TestStartBlockchainsConfigureFail(t *testing.T) {
418383
coreconfig.Reset()
419384
or := newTestOrchestrator()
@@ -431,12 +396,9 @@ func TestStartStopOk(t *testing.T) {
431396
or.mdi.On("GetNamespace", mock.Anything, "ns").Return(nil, nil)
432397
or.mdi.On("UpsertNamespace", mock.Anything, mock.Anything, true).Return(nil)
433398
or.mmp.On("ConfigureContract", mock.Anything, &core.FireFlyContracts{}).Return(nil)
434-
or.mbi.On("Start").Return(nil)
435399
or.mba.On("Start").Return(nil)
436400
or.mem.On("Start").Return(nil)
437401
or.mbm.On("Start").Return(nil)
438-
or.mpm.On("Start").Return(nil)
439-
or.mti.On("Start").Return(nil)
440402
or.msd.On("Start").Return(nil)
441403
or.mom.On("Start").Return(nil)
442404
or.mba.On("WaitStop").Return(nil)

internal/privatemessaging/privatemessaging.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ type Manager interface {
4949
core.Named
5050
GroupManager
5151

52-
Start() error
5352
NewMessage(msg *core.MessageInOut) sysmessaging.MessageSender
5453
SendMessage(ctx context.Context, in *core.MessageInOut, waitConfirm bool) (out *core.Message, err error)
5554
RequestReply(ctx context.Context, request *core.MessageInOut) (reply *core.MessageInOut, err error)
@@ -161,10 +160,6 @@ func (pm *privateMessaging) Name() string {
161160
return "PrivateMessaging"
162161
}
163162

164-
func (pm *privateMessaging) Start() error {
165-
return pm.exchange.Start()
166-
}
167-
168163
func (pm *privateMessaging) dispatchPinnedBatch(ctx context.Context, state *batch.DispatchState) error {
169164
err := pm.dispatchBatchCommon(ctx, state)
170165
if err != nil {

internal/privatemessaging/privatemessaging_test.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -535,14 +535,3 @@ func TestTransferBlobsOpInsertFail(t *testing.T) {
535535

536536
mdi.AssertExpectations(t)
537537
}
538-
539-
func TestStart(t *testing.T) {
540-
pm, cancel := newTestPrivateMessaging(t)
541-
defer cancel()
542-
543-
mdx := pm.exchange.(*dataexchangemocks.Plugin)
544-
mdx.On("Start").Return(nil)
545-
546-
err := pm.Start()
547-
assert.NoError(t, err)
548-
}

0 commit comments

Comments
 (0)