Skip to content

Commit 0e578a8

Browse files
author
Jason Yellick
committed
FAB-10996 Cleanup runtime launcher interface
Presently, the runtime launcher has a dependency on lifecycle that doesn't actually need to exist. Instead, the runtime launcher should simply accept a description of the chaincode to launch. Change-Id: Ie9703afa8d7567e188f3e0b4cf59301ef29d6890 Signed-off-by: Jason Yellick <jyellick@us.ibm.com>
1 parent 03aabd7 commit 0e578a8

File tree

4 files changed

+53
-181
lines changed

4 files changed

+53
-181
lines changed

core/chaincode/chaincode_support.go

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ type Runtime interface {
3131

3232
// Launcher is used to launch chaincode runtimes.
3333
type Launcher interface {
34-
Launch(context context.Context, channelID, chaincodeName string) error
35-
LaunchInit(context context.Context, ccci *lifecycle.ChaincodeContainerInfo) error
34+
Launch(context context.Context, ccci *lifecycle.ChaincodeContainerInfo) error
3635
}
3736

3837
// Lifecycle provides a way to retrieve chaincode definitions and the packages necessary to run them
@@ -61,6 +60,7 @@ type ChaincodeSupport struct {
6160
HandlerRegistry *HandlerRegistry
6261
Launcher Launcher
6362
sccp sysccprovider.SystemChaincodeProvider
63+
Lifecycle Lifecycle
6464
}
6565

6666
// NewChaincodeSupport creates a new ChaincodeSupport instance.
@@ -91,6 +91,11 @@ func NewChaincodeSupport(
9191
certGenerator = nil
9292
}
9393

94+
cs.Lifecycle = &lifecycle.Lifecycle{
95+
Executor: cs,
96+
InstantiatedChaincodeStore: chaincodeStore,
97+
}
98+
9499
cs.Runtime = &ContainerRuntime{
95100
CertGenerator: certGenerator,
96101
Processor: processor,
@@ -108,11 +113,7 @@ func NewChaincodeSupport(
108113
Runtime: cs.Runtime,
109114
Registry: cs.HandlerRegistry,
110115
PackageProvider: packageProvider,
111-
Lifecycle: &lifecycle.Lifecycle{
112-
Executor: cs,
113-
InstantiatedChaincodeStore: chaincodeStore,
114-
},
115-
StartupTimeout: config.StartupTimeout,
116+
StartupTimeout: config.StartupTimeout,
116117
}
117118

118119
return cs
@@ -132,7 +133,7 @@ func (cs *ChaincodeSupport) LaunchInit(ctx context.Context, cccid *ccprovider.CC
132133
ccci := lifecycle.DeploymentSpecToChaincodeContainerInfo(spec)
133134
ccci.Version = cccid.Version
134135

135-
return cs.Launcher.LaunchInit(ctx, ccci)
136+
return cs.Launcher.Launch(ctx, ccci)
136137
}
137138

138139
// Launch starts executing chaincode if it is not already running. This method
@@ -155,8 +156,14 @@ func (cs *ChaincodeSupport) Launch(ctx context.Context, cccid *ccprovider.CCCont
155156
// used to support system chaincode. It should really be instantiated with the
156157
// appropriate reference to ChaincodeSupport.
157158
ctx = context.WithValue(ctx, ccintf.GetCCHandlerKey(), cs)
159+
chaincodeName := spec.GetChaincodeSpec().Name()
160+
161+
ccci, err := cs.Lifecycle.ChaincodeContainerInfo(cccid.ChainID, chaincodeName)
162+
if err != nil {
163+
return errors.Wrapf(err, "[channel %s] failed to get chaincode container info for %s", cccid.ChainID, chaincodeName)
164+
}
158165

159-
return cs.Launcher.Launch(ctx, cccid.ChainID, spec.ChaincodeSpec.ChaincodeId.Name)
166+
return cs.Launcher.Launch(ctx, ccci)
160167
}
161168

162169
// Stop stops a chaincode if running.

core/chaincode/chaincode_support_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,7 +1047,7 @@ func TestStartAndWaitSuccess(t *testing.T) {
10471047
}
10481048

10491049
//actual test - everythings good
1050-
err := launcher.start(context.Background(), ccci)
1050+
err := launcher.Launch(context.Background(), ccci)
10511051
if err != nil {
10521052
t.Fatalf("expected success but failed with error %s", err)
10531053
}
@@ -1080,7 +1080,7 @@ func TestStartAndWaitTimeout(t *testing.T) {
10801080
}
10811081

10821082
//the actual test - timeout 1000 > 500
1083-
err := launcher.start(context.Background(), ccci)
1083+
err := launcher.Launch(context.Background(), ccci)
10841084
if err == nil {
10851085
t.Fatalf("expected error but succeeded")
10861086
}
@@ -1112,7 +1112,7 @@ func TestStartAndWaitLaunchError(t *testing.T) {
11121112
}
11131113

11141114
//actual test - container launch gives error
1115-
err := launcher.start(context.Background(), ccci)
1115+
err := launcher.Launch(context.Background(), ccci)
11161116
if err == nil {
11171117
t.Fatalf("expected error but succeeded")
11181118
}

core/chaincode/runtime_launcher.go

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -31,46 +31,11 @@ type RuntimeLauncher struct {
3131
Runtime Runtime
3232
Registry LaunchRegistry
3333
PackageProvider PackageProvider
34-
Lifecycle Lifecycle
3534
StartupTimeout time.Duration
3635
}
3736

38-
// LaunchInit launches a container which is not yet defined in the LSCC table
39-
// This is only necessary for the pre v1.3 lifecycle
40-
func (r *RuntimeLauncher) LaunchInit(ctx context.Context, ccci *lifecycle.ChaincodeContainerInfo) error {
41-
err := r.start(ctx, ccci)
42-
if err != nil {
43-
chaincodeLogger.Errorf("start failed: %+v", err)
44-
return err
45-
}
46-
47-
chaincodeLogger.Debug("launch complete")
48-
49-
return nil
50-
}
51-
52-
// Launch chaincode with the appropriate runtime.
53-
func (r *RuntimeLauncher) Launch(ctx context.Context, channelID, chaincodeName string) error {
54-
ccci, err := r.Lifecycle.ChaincodeContainerInfo(channelID, chaincodeName)
55-
if err != nil {
56-
return errors.Wrapf(err, "[channel %s] failed to get chaincode container info for %s", channelID, chaincodeName)
57-
}
58-
59-
err = r.start(ctx, ccci)
60-
if err != nil {
61-
chaincodeLogger.Errorf("start failed: %+v", err)
62-
return err
63-
}
64-
65-
chaincodeLogger.Debug("launch complete")
66-
67-
return nil
68-
}
69-
70-
func (r *RuntimeLauncher) start(ctx context.Context, ccci *lifecycle.ChaincodeContainerInfo) error {
37+
func (r *RuntimeLauncher) Launch(ctx context.Context, ccci *lifecycle.ChaincodeContainerInfo) error {
7138
var codePackage []byte
72-
// Note, it is not actually possible for cds.CodePackage to be non-nil in the real world
73-
// But some of the tests rely on the idea that it might be set.
7439
if ccci.ContainerType != inproccontroller.ContainerType {
7540
var err error
7641
codePackage, err = r.PackageProvider.GetChaincodeCodePackage(ccci.Name, ccci.Version)
@@ -113,5 +78,6 @@ func (r *RuntimeLauncher) start(ctx context.Context, ccci *lifecycle.ChaincodeCo
11378
return err
11479
}
11580

81+
chaincodeLogger.Debug("launch complete")
11682
return nil
11783
}

0 commit comments

Comments
 (0)