Skip to content

Commit b63ee56

Browse files
yeasyryjones
authored andcommitted
[FAB-5861] Fix mis-usage in container/image
This patchset fixes the following issues related to Docker: * Name and ID are different in Docker, now we mixed the usage; * Docker image does not support start/stop. The start/stop req is actually for Docker containers. Change-Id: I4150c0b273acd0c8e6c13c2f5929301836fd5277 Signed-off-by: Baohua Yang <yangbaohua@gmail.com>
1 parent 30be7cb commit b63ee56

File tree

4 files changed

+40
-40
lines changed

4 files changed

+40
-40
lines changed

core/chaincode/chaincode_support.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ func (ccl *ccLauncherImpl) launch(ctxt context.Context, notify chan bool) (conta
411411
}
412412

413413
ipcCtxt := context.WithValue(ctxt, ccintf.GetCCHandlerKey(), ccl.support)
414-
sir := container.StartImageReq{
414+
sir := container.StartContainerReq{
415415
CCID: ccintf.CCID{
416416
ChaincodeSpec: ccl.cds.ChaincodeSpec,
417417
NetworkID: ccl.support.peerNetworkID,
@@ -547,10 +547,10 @@ func (chaincodeSupport *ChaincodeSupport) Stop(context context.Context, cccid *c
547547
}
548548

549549
//stop the chaincode
550-
sir := container.StopImageReq{CCID: ccintf.CCID{ChaincodeSpec: cds.ChaincodeSpec, NetworkID: chaincodeSupport.peerNetworkID, PeerID: chaincodeSupport.peerID, Version: cccid.Version}, Timeout: 0}
550+
sir := container.StopContainerReq{CCID: ccintf.CCID{ChaincodeSpec: cds.ChaincodeSpec, NetworkID: chaincodeSupport.peerNetworkID, PeerID: chaincodeSupport.peerID, Version: cccid.Version}, Timeout: 0}
551551
// The line below is left for debugging. It replaces the line above to keep
552552
// the chaincode container around to give you a chance to get data
553-
//sir := container.StopImageReq{CCID: ccintf.CCID{ChaincodeSpec: cds.ChaincodeSpec, NetworkID: chaincodeSupport.peerNetworkID, PeerID: chaincodeSupport.peerID, ChainID: cccid.ChainID, Version: cccid.Version}, Timeout: 0, Dontremove: true}
553+
//sir := container.StopContainerReq{CCID: ccintf.CCID{ChaincodeSpec: cds.ChaincodeSpec, NetworkID: chaincodeSupport.peerNetworkID, PeerID: chaincodeSupport.peerID, ChainID: cccid.ChainID, Version: cccid.Version}, Timeout: 0, Dontremove: true}
554554

555555
vmtype, _ := chaincodeSupport.getVMType(cds)
556556

core/container/controller.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ func (bp CreateImageReq) getCCID() ccintf.CCID {
148148
return bp.CCID
149149
}
150150

151-
//StartImageReq - properties for starting a container.
152-
type StartImageReq struct {
151+
//StartContainerReq - properties for starting a container.
152+
type StartContainerReq struct {
153153
ccintf.CCID
154154
Builder api.BuildSpecFactory
155155
Args []string
@@ -158,7 +158,7 @@ type StartImageReq struct {
158158
PrelaunchFunc api.PrelaunchFunc
159159
}
160160

161-
func (si StartImageReq) do(ctxt context.Context, v api.VM) VMCResp {
161+
func (si StartContainerReq) do(ctxt context.Context, v api.VM) VMCResp {
162162
var resp VMCResp
163163

164164
if err := v.Start(ctxt, si.CCID, si.Args, si.Env, si.FilesToUpload, si.Builder, si.PrelaunchFunc); err != nil {
@@ -170,12 +170,12 @@ func (si StartImageReq) do(ctxt context.Context, v api.VM) VMCResp {
170170
return resp
171171
}
172172

173-
func (si StartImageReq) getCCID() ccintf.CCID {
173+
func (si StartContainerReq) getCCID() ccintf.CCID {
174174
return si.CCID
175175
}
176176

177-
//StopImageReq - properties for stopping a container.
178-
type StopImageReq struct {
177+
//StopContainerReq - properties for stopping a container.
178+
type StopContainerReq struct {
179179
ccintf.CCID
180180
Timeout uint
181181
//by default we will kill the container after stopping
@@ -184,7 +184,7 @@ type StopImageReq struct {
184184
Dontremove bool
185185
}
186186

187-
func (si StopImageReq) do(ctxt context.Context, v api.VM) VMCResp {
187+
func (si StopContainerReq) do(ctxt context.Context, v api.VM) VMCResp {
188188
var resp VMCResp
189189

190190
if err := v.Stop(ctxt, si.CCID, si.Timeout, si.Dontkill, si.Dontremove); err != nil {
@@ -196,7 +196,7 @@ func (si StopImageReq) do(ctxt context.Context, v api.VM) VMCResp {
196196
return resp
197197
}
198198

199-
func (si StopImageReq) getCCID() ccintf.CCID {
199+
func (si StopContainerReq) getCCID() ccintf.CCID {
200200
return si.CCID
201201
}
202202

core/container/controller_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ func TestVMCStartContainer(t *testing.T) {
176176
//create a StartImageReq obj and send it to VMCProcess
177177
go func() {
178178
defer close(c)
179-
sir := StartImageReq{CCID: ccintf.CCID{ChaincodeSpec: &pb.ChaincodeSpec{ChaincodeId: &pb.ChaincodeID{Name: "simple"}}}}
179+
sir := StartContainerReq{CCID: ccintf.CCID{ChaincodeSpec: &pb.ChaincodeSpec{ChaincodeId: &pb.ChaincodeID{Name: "simple"}}}}
180180
_, err := VMCProcess(ctxt, "Docker", sir)
181181
if err != nil {
182182
t.Fail()
@@ -188,7 +188,7 @@ func TestVMCStartContainer(t *testing.T) {
188188
//wait for VMController to complete.
189189
fmt.Println("VMCStartContainer-waiting for response")
190190
<-c
191-
stopr := StopImageReq{CCID: ccintf.CCID{ChaincodeSpec: &pb.ChaincodeSpec{ChaincodeId: &pb.ChaincodeID{Name: "simple"}}}, Timeout: 0, Dontremove: true}
191+
stopr := StopContainerReq{CCID: ccintf.CCID{ChaincodeSpec: &pb.ChaincodeSpec{ChaincodeId: &pb.ChaincodeID{Name: "simple"}}}, Timeout: 0, Dontremove: true}
192192
VMCProcess(ctxt, "Docker", stopr)
193193
}
194194

@@ -204,10 +204,10 @@ func TestVMCCreateAndStartContainer(t *testing.T) {
204204
defer close(c)
205205

206206
//stop and delete the container first (if it exists)
207-
stopir := StopImageReq{CCID: ccintf.CCID{ChaincodeSpec: &pb.ChaincodeSpec{ChaincodeId: &pb.ChaincodeID{Name: "simple"}}}, Timeout: 0}
207+
stopir := StopContainerReq{CCID: ccintf.CCID{ChaincodeSpec: &pb.ChaincodeSpec{ChaincodeId: &pb.ChaincodeID{Name: "simple"}}}, Timeout: 0}
208208
VMCProcess(ctxt, "Docker", stopir)
209209

210-
startir := StartImageReq{CCID: ccintf.CCID{ChaincodeSpec: &pb.ChaincodeSpec{ChaincodeId: &pb.ChaincodeID{Name: "simple"}}}}
210+
startir := StartContainerReq{CCID: ccintf.CCID{ChaincodeSpec: &pb.ChaincodeSpec{ChaincodeId: &pb.ChaincodeID{Name: "simple"}}}}
211211
r, err := VMCProcess(ctxt, "Docker", startir)
212212
if err != nil {
213213
t.Fail()
@@ -224,7 +224,7 @@ func TestVMCCreateAndStartContainer(t *testing.T) {
224224
//wait for VMController to complete.
225225
fmt.Println("VMCStartContainer-waiting for response")
226226
<-c
227-
//stopr := StopImageReq{ID: "simple", Timeout: 0, Dontremove: true}
227+
//stopr := StopContainerReq{ID: "simple", Timeout: 0, Dontremove: true}
228228
//VMCProcess(ctxt, "Docker", stopr)
229229
}
230230

@@ -234,14 +234,14 @@ func TestVMCSyncStartContainer(t *testing.T) {
234234
var ctxt = context.Background()
235235

236236
//creat a StartImageReq obj and send it to VMCProcess
237-
sir := StartImageReq{CCID: ccintf.CCID{ChaincodeSpec: &pb.ChaincodeSpec{ChaincodeId: &pb.ChaincodeID{Name: "simple"}}}}
237+
sir := StartContainerReq{CCID: ccintf.CCID{ChaincodeSpec: &pb.ChaincodeSpec{ChaincodeId: &pb.ChaincodeID{Name: "simple"}}}}
238238
_, err := VMCProcess(ctxt, "Docker", sir)
239239
if err != nil {
240240
t.Fail()
241241
t.Logf("Error starting container: %s", err)
242242
return
243243
}
244-
stopr := StopImageReq{CCID: ccintf.CCID{ChaincodeSpec: &pb.ChaincodeSpec{ChaincodeId: &pb.ChaincodeID{Name: "simple"}}}, Timeout: 0, Dontremove: true}
244+
stopr := StopContainerReq{CCID: ccintf.CCID{ChaincodeSpec: &pb.ChaincodeSpec{ChaincodeId: &pb.ChaincodeID{Name: "simple"}}}, Timeout: 0, Dontremove: true}
245245
VMCProcess(ctxt, "Docker", stopr)
246246
}
247247

@@ -252,10 +252,10 @@ func TestVMCStopContainer(t *testing.T) {
252252

253253
c := make(chan struct{})
254254

255-
//creat a StopImageReq obj and send it to VMCProcess
255+
//creat a StopContainerReq obj and send it to VMCProcess
256256
go func() {
257257
defer close(c)
258-
sir := StopImageReq{CCID: ccintf.CCID{ChaincodeSpec: &pb.ChaincodeSpec{ChaincodeId: &pb.ChaincodeID{Name: "simple"}}}, Timeout: 0}
258+
sir := StopContainerReq{CCID: ccintf.CCID{ChaincodeSpec: &pb.ChaincodeSpec{ChaincodeId: &pb.ChaincodeID{Name: "simple"}}}, Timeout: 0}
259259
_, err := VMCProcess(ctxt, "Docker", sir)
260260
if err != nil {
261261
t.Fail()

core/container/dockercontroller/dockercontroller.go

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ func (vm *DockerVM) Deploy(ctxt context.Context, ccid ccintf.CCID,
217217
//Start starts a container using a previously created docker image
218218
func (vm *DockerVM) Start(ctxt context.Context, ccid ccintf.CCID,
219219
args []string, env []string, filesToUpload map[string][]byte, builder container.BuildSpecFactory, prelaunchFunc container.PrelaunchFunc) error {
220-
imageID, err := vm.GetVMName(ccid, formatImageName)
220+
imageName, err := vm.GetVMName(ccid, formatImageName)
221221
if err != nil {
222222
return err
223223
}
@@ -228,47 +228,47 @@ func (vm *DockerVM) Start(ctxt context.Context, ccid ccintf.CCID,
228228
return err
229229
}
230230

231-
containerID, err := vm.GetVMName(ccid, nil)
231+
containerName, err := vm.GetVMName(ccid, nil)
232232
if err != nil {
233233
return err
234234
}
235235

236236
attachStdout := viper.GetBool("vm.docker.attachStdout")
237237

238238
//stop,force remove if necessary
239-
dockerLogger.Debugf("Cleanup container %s", containerID)
240-
vm.stopInternal(ctxt, client, containerID, 0, false, false)
239+
dockerLogger.Debugf("Cleanup container %s", containerName)
240+
vm.stopInternal(ctxt, client, containerName, 0, false, false)
241241

242-
dockerLogger.Debugf("Start container %s", containerID)
243-
err = vm.createContainer(ctxt, client, imageID, containerID, args, env, attachStdout)
242+
dockerLogger.Debugf("Start container %s", containerName)
243+
err = vm.createContainer(ctxt, client, imageName, containerName, args, env, attachStdout)
244244
if err != nil {
245245
//if image not found try to create image and retry
246246
if err == docker.ErrNoSuchImage {
247247
if builder != nil {
248248
dockerLogger.Debugf("start-could not find image <%s> (container id <%s>), because of <%s>..."+
249-
"attempt to recreate image", imageID, containerID, err)
249+
"attempt to recreate image", imageName, containerName, err)
250250

251251
reader, err1 := builder()
252252
if err1 != nil {
253253
dockerLogger.Errorf("Error creating image builder for image <%s> (container id <%s>), "+
254-
"because of <%s>", imageID, containerID, err1)
254+
"because of <%s>", imageName, containerName, err1)
255255
}
256256

257257
if err1 = vm.deployImage(client, ccid, args, env, reader); err1 != nil {
258258
return err1
259259
}
260260

261261
dockerLogger.Debug("start-recreated image successfully")
262-
if err1 = vm.createContainer(ctxt, client, imageID, containerID, args, env, attachStdout); err1 != nil {
262+
if err1 = vm.createContainer(ctxt, client, imageName, containerName, args, env, attachStdout); err1 != nil {
263263
dockerLogger.Errorf("start-could not recreate container post recreate image: %s", err1)
264264
return err1
265265
}
266266
} else {
267-
dockerLogger.Errorf("start-could not find image <%s>, because of %s", imageID, err)
267+
dockerLogger.Errorf("start-could not find image <%s>, because of %s", imageName, err)
268268
return err
269269
}
270270
} else {
271-
dockerLogger.Errorf("start-could not recreate container <%s>, because of %s", containerID, err)
271+
dockerLogger.Errorf("start-could not recreate container <%s>, because of %s", containerName, err)
272272
return err
273273
}
274274
}
@@ -285,7 +285,7 @@ func (vm *DockerVM) Start(ctxt context.Context, ccid ccintf.CCID,
285285
// The returned error is not used outside the scope of this function. Assign the
286286
// error to a local variable to prevent clobbering the function variable 'err'.
287287
err := client.AttachToContainer(docker.AttachToContainerOptions{
288-
Container: containerID,
288+
Container: containerName,
289289
OutputStream: w,
290290
ErrorStream: w,
291291
Logs: true,
@@ -306,7 +306,7 @@ func (vm *DockerVM) Start(ctxt context.Context, ccid ccintf.CCID,
306306
case <-attached:
307307
// successful attach
308308
case <-time.After(10 * time.Second):
309-
dockerLogger.Errorf("Timeout while attaching to IO channel in container %s", containerID)
309+
dockerLogger.Errorf("Timeout while attaching to IO channel in container %s", containerName)
310310
return
311311
}
312312

@@ -320,8 +320,8 @@ func (vm *DockerVM) Start(ctxt context.Context, ccid ccintf.CCID,
320320
is := bufio.NewReader(r)
321321

322322
// Acquire a custom logger for our chaincode, inheriting the level from the peer
323-
containerLogger := flogging.MustGetLogger(containerID)
324-
logging.SetLevel(logging.GetLevel("peer"), containerID)
323+
containerLogger := flogging.MustGetLogger(containerName)
324+
logging.SetLevel(logging.GetLevel("peer"), containerName)
325325

326326
for {
327327
// Loop forever dumping lines of text into the containerLogger
@@ -330,7 +330,7 @@ func (vm *DockerVM) Start(ctxt context.Context, ccid ccintf.CCID,
330330
if err2 != nil {
331331
switch err2 {
332332
case io.EOF:
333-
dockerLogger.Infof("Container %s has closed its IO channel", containerID)
333+
dockerLogger.Infof("Container %s has closed its IO channel", containerName)
334334
default:
335335
dockerLogger.Errorf("Error reading container output: %s", err2)
336336
}
@@ -363,14 +363,14 @@ func (vm *DockerVM) Start(ctxt context.Context, ccid ccintf.CCID,
363363

364364
gw.Close()
365365

366-
err = client.UploadToContainer(containerID, docker.UploadToContainerOptions{
366+
err = client.UploadToContainer(containerName, docker.UploadToContainerOptions{
367367
InputStream: bytes.NewReader(payload.Bytes()),
368368
Path: "/",
369369
NoOverwriteDirNonDir: false,
370370
})
371371

372372
if err != nil {
373-
return fmt.Errorf("Error uploading files to the container instance %s: %s", containerID, err)
373+
return fmt.Errorf("Error uploading files to the container instance %s: %s", containerName, err)
374374
}
375375
}
376376

@@ -381,13 +381,13 @@ func (vm *DockerVM) Start(ctxt context.Context, ccid ccintf.CCID,
381381
}
382382

383383
// start container with HostConfig was deprecated since v1.10 and removed in v1.2
384-
err = client.StartContainer(containerID, nil)
384+
err = client.StartContainer(containerName, nil)
385385
if err != nil {
386386
dockerLogger.Errorf("start-could not start container: %s", err)
387387
return err
388388
}
389389

390-
dockerLogger.Debugf("Started container %s", containerID)
390+
dockerLogger.Debugf("Started container %s", containerName)
391391
return nil
392392
}
393393

0 commit comments

Comments
 (0)