@@ -315,8 +315,7 @@ func (chaincodeSupport *ChaincodeSupport) getTLSFiles(keyPair *accesscontrol.Cer
315
315
}
316
316
317
317
//get args and env given chaincodeID
318
- func (chaincodeSupport * ChaincodeSupport ) getLaunchConfigs (cccid * ccprovider.CCContext , cLang pb.ChaincodeSpec_Type ) (args []string , envs []string , filesToUpload map [string ][]byte , err error ) {
319
- canName := cccid .GetCanonicalName ()
318
+ func (chaincodeSupport * ChaincodeSupport ) getLaunchConfigs (canName string , cLang pb.ChaincodeSpec_Type ) (args []string , envs []string , filesToUpload map [string ][]byte , err error ) {
320
319
envs = []string {"CORE_CHAINCODE_ID_NAME=" + canName }
321
320
322
321
// ----------------------------------------------------------------------------
@@ -331,9 +330,9 @@ func (chaincodeSupport *ChaincodeSupport) getLaunchConfigs(cccid *ccprovider.CCC
331
330
// ----------------------------------------------------------------------------
332
331
var certKeyPair * accesscontrol.CertAndPrivKeyPair
333
332
if chaincodeSupport .peerTLS {
334
- certKeyPair , err = chaincodeSupport .certGenerator .Generate (cccid . GetCanonicalName () )
333
+ certKeyPair , err = chaincodeSupport .certGenerator .Generate (canName )
335
334
if err != nil {
336
- return nil , nil , nil , errors .WithMessage (err , fmt .Sprintf ("failed generating TLS cert for %s" , cccid . GetCanonicalName () ))
335
+ return nil , nil , nil , errors .WithMessage (err , fmt .Sprintf ("failed generating TLS cert for %s" , canName ))
337
336
}
338
337
envs = append (envs , "CORE_PEER_TLS_ENABLED=true" )
339
338
envs = append (envs , fmt .Sprintf ("CORE_TLS_CLIENT_KEY_PATH=%s" , TLSClientKeyPath ))
@@ -378,51 +377,61 @@ func (chaincodeSupport *ChaincodeSupport) getLaunchConfigs(cccid *ccprovider.CCC
378
377
379
378
//---------- Begin - launchAndWaitForRegister related functionality --------
380
379
381
- //a launcher interface to encapsulate chaincode execution. This
382
- //helps with UT of launchAndWaitForRegister
380
+ // launcherIntf encapsulate chaincode execution. This helps with UT of
381
+ // launchAndWaitForRegister.
383
382
type launcherIntf interface {
384
- launch (ctxt context.Context , notfy chan bool ) (container.VMCResp , error )
383
+ launch (ctxt context.Context , notfiy chan bool ) (container.VMCResp , error )
385
384
}
386
385
387
386
//ccLaucherImpl will use the container launcher mechanism to launch the actual chaincode
388
387
type ccLauncherImpl struct {
389
- ctxt context. Context
390
- ccSupport * ChaincodeSupport
391
- cccid * ccprovider. CCContext
392
- cds * pb.ChaincodeDeploymentSpec
393
- builder api.BuildSpecFactory
388
+ support * ChaincodeSupport
389
+ canonicalName string
390
+ version string
391
+ cds * pb.ChaincodeDeploymentSpec
392
+ builder api.BuildSpecFactory
394
393
}
395
394
396
395
//launches the chaincode using the supplied context and notifier
397
- func (ccl * ccLauncherImpl ) launch (ctxt context.Context , notfy chan bool ) (container.VMCResp , error ) {
398
- //launch the chaincode
399
- args , env , filesToUpload , err := ccl .ccSupport .getLaunchConfigs (ccl .cccid , ccl .cds .ChaincodeSpec .Type )
396
+ func (ccl * ccLauncherImpl ) launch (ctxt context.Context , notify chan bool ) (container.VMCResp , error ) {
397
+ // launch the chaincode
398
+ args , env , filesToUpload , err := ccl .support .getLaunchConfigs (ccl .canonicalName , ccl .cds .ChaincodeSpec .Type )
400
399
if err != nil {
401
400
return container.VMCResp {}, err
402
401
}
403
402
404
- canName := ccl .cccid .GetCanonicalName ()
405
-
406
- chaincodeLogger .Debugf ("start container: %s(networkid:%s,peerid:%s)" , canName , ccl .ccSupport .peerNetworkID , ccl .ccSupport .peerID )
403
+ chaincodeLogger .Debugf ("start container: %s(networkid:%s,peerid:%s)" , ccl .canonicalName , ccl .support .peerNetworkID , ccl .support .peerID )
407
404
chaincodeLogger .Debugf ("start container with args: %s" , strings .Join (args , " " ))
408
405
chaincodeLogger .Debugf ("start container with env:\n \t %s" , strings .Join (env , "\n \t " ))
409
406
410
- //set up the shadow handler JIT before container launch to
411
- //reduce window of when an external chaincode can sneak in
412
- //and use the launching context and make it its own
407
+ // set up the shadow handler JIT before container launch to
408
+ // reduce window of when an external chaincode can sneak in
409
+ // and use the launching context and make it its own
413
410
preLaunchFunc := func () error {
414
- ccl .ccSupport .preLaunchSetup (canName , notfy )
411
+ ccl .support .preLaunchSetup (ccl . canonicalName , notify )
415
412
return nil
416
413
}
417
414
418
- ccid := ccintf.CCID {ChaincodeSpec : ccl .cds .ChaincodeSpec , NetworkID : ccl .ccSupport .peerNetworkID , PeerID : ccl .ccSupport .peerID , Version : ccl .cccid .Version }
419
- sir := container.StartImageReq {CCID : ccid , Builder : ccl .builder , Args : args , Env : env , FilesToUpload : filesToUpload , PrelaunchFunc : preLaunchFunc }
420
- ipcCtxt := context .WithValue (ctxt , ccintf .GetCCHandlerKey (), ccl .ccSupport )
421
-
422
- vmtype , _ := ccl .ccSupport .getVMType (ccl .cds )
423
- resp , err := container .VMCProcess (ipcCtxt , vmtype , sir )
415
+ ipcCtxt := context .WithValue (ctxt , ccintf .GetCCHandlerKey (), ccl .support )
416
+ sir := container.StartImageReq {
417
+ CCID : ccintf.CCID {
418
+ ChaincodeSpec : ccl .cds .ChaincodeSpec ,
419
+ NetworkID : ccl .support .peerNetworkID ,
420
+ PeerID : ccl .support .peerID ,
421
+ Version : ccl .version ,
422
+ },
423
+ Builder : ccl .builder ,
424
+ Args : args ,
425
+ Env : env ,
426
+ FilesToUpload : filesToUpload ,
427
+ PrelaunchFunc : preLaunchFunc ,
428
+ }
429
+ vmtype , err := ccl .support .getVMType (ccl .cds )
430
+ if err != nil {
431
+ return container.VMCResp {}, err
432
+ }
424
433
425
- return resp , err
434
+ return container . VMCProcess ( ipcCtxt , vmtype , sir )
426
435
}
427
436
428
437
//launchAndWaitForRegister will launch container if not already running. Use
@@ -673,9 +682,16 @@ func (chaincodeSupport *ChaincodeSupport) Launch(context context.Context, cccid
673
682
}
674
683
}
675
684
676
- builder := func () (io.Reader , error ) { return platforms .GenerateDockerBuild (cds ) }
677
-
678
- err = chaincodeSupport .launchAndWaitForRegister (context , cccid , cds , & ccLauncherImpl {context , chaincodeSupport , cccid , cds , builder })
685
+ launcher := & ccLauncherImpl {
686
+ support : chaincodeSupport ,
687
+ canonicalName : cccid .GetCanonicalName (),
688
+ version : cccid .Version ,
689
+ cds : cds ,
690
+ builder : func () (io.Reader , error ) {
691
+ return platforms .GenerateDockerBuild (cds )
692
+ },
693
+ }
694
+ err = chaincodeSupport .launchAndWaitForRegister (context , cccid , cds , launcher )
679
695
if err != nil {
680
696
chaincodeLogger .Errorf ("launchAndWaitForRegister failed: %+v" , err )
681
697
return cID , cMsg , err
0 commit comments