Skip to content

Commit 03aabd7

Browse files
author
Jason Yellick
committed
FAB-10995 runtime_launcher chaincode spec removal
This CR completes the removal of the chaincode spec from the runtime_launcher.go file. There is some additional refactoring, especially of the test required, but this will follow in a subsequent CR. Change-Id: I8b71811f534fee6fcda77bc7bafb64c319a10ab3 Signed-off-by: Jason Yellick <jyellick@us.ibm.com>
1 parent 2fffd02 commit 03aabd7

File tree

3 files changed

+43
-73
lines changed

3 files changed

+43
-73
lines changed

core/chaincode/chaincode_support.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ type Runtime interface {
3232
// Launcher is used to launch chaincode runtimes.
3333
type Launcher interface {
3434
Launch(context context.Context, channelID, chaincodeName string) error
35-
LaunchInit(context context.Context, cccid *ccprovider.CCContext, spec *pb.ChaincodeDeploymentSpec) error
35+
LaunchInit(context context.Context, ccci *lifecycle.ChaincodeContainerInfo) error
3636
}
3737

3838
// Lifecycle provides a way to retrieve chaincode definitions and the packages necessary to run them
@@ -129,7 +129,10 @@ func (cs *ChaincodeSupport) LaunchInit(ctx context.Context, cccid *ccprovider.CC
129129

130130
ctx = context.WithValue(ctx, ccintf.GetCCHandlerKey(), cs)
131131

132-
return cs.Launcher.LaunchInit(ctx, cccid, spec)
132+
ccci := lifecycle.DeploymentSpecToChaincodeContainerInfo(spec)
133+
ccci.Version = cccid.Version
134+
135+
return cs.Launcher.LaunchInit(ctx, ccci)
133136
}
134137

135138
// Launch starts executing chaincode if it is not already running. This method

core/chaincode/runtime_launcher.go

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ import (
1010
"time"
1111

1212
"github.com/hyperledger/fabric/core/chaincode/lifecycle"
13-
"github.com/hyperledger/fabric/core/common/ccprovider"
14-
pb "github.com/hyperledger/fabric/protos/peer"
13+
"github.com/hyperledger/fabric/core/container/inproccontroller"
1514
"github.com/pkg/errors"
1615
"golang.org/x/net/context"
1716
)
@@ -38,15 +37,7 @@ type RuntimeLauncher struct {
3837

3938
// LaunchInit launches a container which is not yet defined in the LSCC table
4039
// This is only necessary for the pre v1.3 lifecycle
41-
func (r *RuntimeLauncher) LaunchInit(ctx context.Context, cccid *ccprovider.CCContext, spec *pb.ChaincodeDeploymentSpec) error {
42-
ccci := &lifecycle.ChaincodeContainerInfo{
43-
Name: spec.Name(),
44-
Version: cccid.Version,
45-
Path: spec.Path(),
46-
Type: spec.CCType(),
47-
ContainerType: spec.ExecEnv.String(),
48-
}
49-
40+
func (r *RuntimeLauncher) LaunchInit(ctx context.Context, ccci *lifecycle.ChaincodeContainerInfo) error {
5041
err := r.start(ctx, ccci)
5142
if err != nil {
5243
chaincodeLogger.Errorf("start failed: %+v", err)
@@ -80,7 +71,7 @@ func (r *RuntimeLauncher) start(ctx context.Context, ccci *lifecycle.ChaincodeCo
8071
var codePackage []byte
8172
// Note, it is not actually possible for cds.CodePackage to be non-nil in the real world
8273
// But some of the tests rely on the idea that it might be set.
83-
if ccci.ContainerType != pb.ChaincodeDeploymentSpec_SYSTEM.String() {
74+
if ccci.ContainerType != inproccontroller.ContainerType {
8475
var err error
8576
codePackage, err = r.PackageProvider.GetChaincodeCodePackage(ccci.Name, ccci.Version)
8677
if err != nil {

core/chaincode/runtime_launcher_test.go

Lines changed: 35 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ var _ = Describe("RuntimeLauncher", func() {
3434
proposal *pb.Proposal
3535
chaincodeID *pb.ChaincodeID
3636
deploymentSpec *pb.ChaincodeDeploymentSpec
37+
ccci *lc.ChaincodeContainerInfo
3738

3839
runtimeLauncher *chaincode.RuntimeLauncher
3940

@@ -122,57 +123,32 @@ var _ = Describe("RuntimeLauncher", func() {
122123
Expect(err).To(MatchError("[channel chain-id] failed to get chaincode container info for chaincode-name: king-kong"))
123124
})
124125
})
126+
})
125127

126-
Context("when the returned deployment spec has a nil chaincode package", func() {
127-
BeforeEach(func() {
128-
})
129-
130-
It("gets the package from the package provider", func() {
131-
err := runtimeLauncher.Launch(context.Background(), cccid.ChainID, invocationSpec.ChaincodeSpec.Name())
132-
Expect(err).NotTo(HaveOccurred())
133-
134-
Expect(fakePackageProvider.GetChaincodeCodePackageCallCount()).To(Equal(1))
135-
name, version := fakePackageProvider.GetChaincodeCodePackageArgsForCall(0)
136-
Expect(name).To(Equal("info-name"))
137-
Expect(version).To(Equal("info-version"))
138-
})
139-
140-
Context("when getting the package fails", func() {
141-
BeforeEach(func() {
142-
fakePackageProvider.GetChaincodeCodePackageReturns(nil, errors.New("tangerine"))
143-
})
144-
145-
It("returns a wrapped error", func() {
146-
err := runtimeLauncher.Launch(context.Background(), cccid.ChainID, invocationSpec.ChaincodeSpec.Name())
147-
Expect(err).To(MatchError("failed to get chaincode package: tangerine"))
148-
})
149-
})
128+
Context("when launch is provided with a deployment spec", func() {
129+
BeforeEach(func() {
130+
deploymentSpec.CodePackage = []byte("code-package")
131+
ccci = lc.DeploymentSpecToChaincodeContainerInfo(deploymentSpec)
150132
})
151133

152-
Context("when launching a system chaincode", func() {
153-
BeforeEach(func() {
154-
ccciReturnValue.ContainerType = "SYSTEM"
155-
})
156-
157-
It("does not get the codepackage", func() {
158-
err := runtimeLauncher.Launch(context.Background(), cccid.ChainID, invocationSpec.ChaincodeSpec.Name())
159-
Expect(err).NotTo(HaveOccurred())
160-
Expect(fakePackageProvider.GetChaincodeCodePackageCallCount()).To(Equal(0))
161-
})
134+
It("does not get the deployment spec from lifecycle", func() {
135+
err := runtimeLauncher.LaunchInit(context.Background(), ccci)
136+
Expect(err).NotTo(HaveOccurred())
137+
Expect(fakeLifecycle.ChaincodeContainerInfoCallCount()).To(Equal(0))
162138
})
163139
})
164140

165141
It("registers the chaincode as launching", func() {
166-
err := runtimeLauncher.LaunchInit(context.Background(), cccid, deploymentSpec)
142+
err := runtimeLauncher.LaunchInit(context.Background(), ccci)
167143
Expect(err).NotTo(HaveOccurred())
168144

169145
Expect(fakeRegistry.LaunchingCallCount()).To(Equal(1))
170146
cname := fakeRegistry.LaunchingArgsForCall(0)
171-
Expect(cname).To(Equal("chaincode-name:context-version"))
147+
Expect(cname).To(Equal("chaincode-name:chaincode-version"))
172148
})
173149

174150
It("starts the runtime for the chaincode", func() {
175-
err := runtimeLauncher.LaunchInit(context.Background(), cccid, deploymentSpec)
151+
err := runtimeLauncher.LaunchInit(context.Background(), ccci)
176152
Expect(err).NotTo(HaveOccurred())
177153

178154
Expect(fakeRuntime.StartCallCount()).To(Equal(1))
@@ -182,7 +158,7 @@ var _ = Describe("RuntimeLauncher", func() {
182158
Name: deploymentSpec.Name(),
183159
Path: deploymentSpec.Path(),
184160
Type: deploymentSpec.CCType(),
185-
Version: cccid.Version,
161+
Version: deploymentSpec.Version(),
186162
ContainerType: "DOCKER",
187163
}))
188164
Expect(codePackage).To(Equal([]byte("code-package")))
@@ -192,15 +168,15 @@ var _ = Describe("RuntimeLauncher", func() {
192168
fakeRuntime.StartReturns(nil)
193169

194170
errCh := make(chan error, 1)
195-
go func() { errCh <- runtimeLauncher.LaunchInit(context.Background(), cccid, deploymentSpec) }()
171+
go func() { errCh <- runtimeLauncher.LaunchInit(context.Background(), ccci) }()
196172

197173
Consistently(errCh).ShouldNot(Receive())
198174
launchState.Notify(nil)
199175
Eventually(errCh).Should(Receive(BeNil()))
200176
})
201177

202178
It("does not deregister the chaincode", func() {
203-
err := runtimeLauncher.LaunchInit(context.Background(), cccid, deploymentSpec)
179+
err := runtimeLauncher.LaunchInit(context.Background(), ccci)
204180
Expect(err).NotTo(HaveOccurred())
205181

206182
Expect(fakeRegistry.DeregisterCallCount()).To(Equal(0))
@@ -212,8 +188,8 @@ var _ = Describe("RuntimeLauncher", func() {
212188
})
213189

214190
It("returns an error", func() {
215-
err := runtimeLauncher.LaunchInit(context.Background(), cccid, deploymentSpec)
216-
Expect(err).To(MatchError("failed to register chaincode-name:context-version as launching: gargoyle"))
191+
err := runtimeLauncher.LaunchInit(context.Background(), ccci)
192+
Expect(err).To(MatchError("failed to register chaincode-name:chaincode-version as launching: gargoyle"))
217193
})
218194
})
219195

@@ -223,12 +199,12 @@ var _ = Describe("RuntimeLauncher", func() {
223199
})
224200

225201
It("returns a wrapped error", func() {
226-
err := runtimeLauncher.LaunchInit(context.Background(), cccid, deploymentSpec)
202+
err := runtimeLauncher.LaunchInit(context.Background(), ccci)
227203
Expect(err).To(MatchError("error starting container: banana"))
228204
})
229205

230206
It("stops the runtime", func() {
231-
runtimeLauncher.LaunchInit(context.Background(), cccid, deploymentSpec)
207+
runtimeLauncher.LaunchInit(context.Background(), ccci)
232208

233209
Expect(fakeRuntime.StopCallCount()).To(Equal(1))
234210
ctx, ccci := fakeRuntime.StopArgsForCall(0)
@@ -237,17 +213,17 @@ var _ = Describe("RuntimeLauncher", func() {
237213
Name: deploymentSpec.Name(),
238214
Path: deploymentSpec.Path(),
239215
Type: deploymentSpec.CCType(),
240-
Version: cccid.Version,
216+
Version: deploymentSpec.Version(),
241217
ContainerType: "DOCKER",
242218
}))
243219
})
244220

245221
It("deregisters the chaincode", func() {
246-
runtimeLauncher.LaunchInit(context.Background(), cccid, deploymentSpec)
222+
runtimeLauncher.LaunchInit(context.Background(), ccci)
247223

248224
Expect(fakeRegistry.DeregisterCallCount()).To(Equal(1))
249225
cname := fakeRegistry.DeregisterArgsForCall(0)
250-
Expect(cname).To(Equal("chaincode-name:context-version"))
226+
Expect(cname).To(Equal("chaincode-name:chaincode-version"))
251227
})
252228
})
253229

@@ -260,12 +236,12 @@ var _ = Describe("RuntimeLauncher", func() {
260236
})
261237

262238
It("returns an error", func() {
263-
err := runtimeLauncher.LaunchInit(context.Background(), cccid, deploymentSpec)
239+
err := runtimeLauncher.LaunchInit(context.Background(), ccci)
264240
Expect(err).To(MatchError("chaincode registration failed: papaya"))
265241
})
266242

267243
It("stops the runtime", func() {
268-
runtimeLauncher.LaunchInit(context.Background(), cccid, deploymentSpec)
244+
runtimeLauncher.LaunchInit(context.Background(), ccci)
269245

270246
Expect(fakeRuntime.StopCallCount()).To(Equal(1))
271247
ctx, ccci := fakeRuntime.StopArgsForCall(0)
@@ -274,17 +250,17 @@ var _ = Describe("RuntimeLauncher", func() {
274250
Name: deploymentSpec.Name(),
275251
Path: deploymentSpec.Path(),
276252
Type: deploymentSpec.CCType(),
277-
Version: cccid.Version,
253+
Version: deploymentSpec.Version(),
278254
ContainerType: "DOCKER",
279255
}))
280256
})
281257

282258
It("deregisters the chaincode", func() {
283-
runtimeLauncher.LaunchInit(context.Background(), cccid, deploymentSpec)
259+
runtimeLauncher.LaunchInit(context.Background(), ccci)
284260

285261
Expect(fakeRegistry.DeregisterCallCount()).To(Equal(1))
286262
cname := fakeRegistry.DeregisterArgsForCall(0)
287-
Expect(cname).To(Equal("chaincode-name:context-version"))
263+
Expect(cname).To(Equal("chaincode-name:chaincode-version"))
288264
})
289265
})
290266

@@ -295,12 +271,12 @@ var _ = Describe("RuntimeLauncher", func() {
295271
})
296272

297273
It("returns a meaningful error", func() {
298-
err := runtimeLauncher.LaunchInit(context.Background(), cccid, deploymentSpec)
299-
Expect(err).To(MatchError("timeout expired while starting chaincode chaincode-name:context-version for transaction"))
274+
err := runtimeLauncher.LaunchInit(context.Background(), ccci)
275+
Expect(err).To(MatchError("timeout expired while starting chaincode chaincode-name:chaincode-version for transaction"))
300276
})
301277

302278
It("stops the runtime", func() {
303-
runtimeLauncher.LaunchInit(context.Background(), cccid, deploymentSpec)
279+
runtimeLauncher.LaunchInit(context.Background(), ccci)
304280

305281
Expect(fakeRuntime.StopCallCount()).To(Equal(1))
306282
ctx, ccci := fakeRuntime.StopArgsForCall(0)
@@ -309,17 +285,17 @@ var _ = Describe("RuntimeLauncher", func() {
309285
Name: deploymentSpec.Name(),
310286
Path: deploymentSpec.Path(),
311287
Type: deploymentSpec.CCType(),
312-
Version: cccid.Version,
288+
Version: deploymentSpec.Version(),
313289
ContainerType: "DOCKER",
314290
}))
315291
})
316292

317293
It("deregisters the chaincode", func() {
318-
runtimeLauncher.LaunchInit(context.Background(), cccid, deploymentSpec)
294+
runtimeLauncher.LaunchInit(context.Background(), ccci)
319295

320296
Expect(fakeRegistry.DeregisterCallCount()).To(Equal(1))
321297
cname := fakeRegistry.DeregisterArgsForCall(0)
322-
Expect(cname).To(Equal("chaincode-name:context-version"))
298+
Expect(cname).To(Equal("chaincode-name:chaincode-version"))
323299
})
324300
})
325301

@@ -330,7 +306,7 @@ var _ = Describe("RuntimeLauncher", func() {
330306
})
331307

332308
It("preserves the initial error", func() {
333-
err := runtimeLauncher.LaunchInit(context.Background(), cccid, deploymentSpec)
309+
err := runtimeLauncher.LaunchInit(context.Background(), ccci)
334310
Expect(err).To(MatchError("error starting container: whirled-peas"))
335311
Expect(fakeRuntime.StopCallCount()).To(Equal(1))
336312
})

0 commit comments

Comments
 (0)