@@ -13,8 +13,8 @@ import (
13
13
"strings"
14
14
15
15
"github.com/hyperledger/fabric/core/chaincode/accesscontrol"
16
+ "github.com/hyperledger/fabric/core/chaincode/lifecycle"
16
17
"github.com/hyperledger/fabric/core/chaincode/platforms"
17
- "github.com/hyperledger/fabric/core/common/ccprovider"
18
18
"github.com/hyperledger/fabric/core/container"
19
19
"github.com/hyperledger/fabric/core/container/ccintf"
20
20
"github.com/hyperledger/fabric/core/container/dockercontroller"
@@ -47,10 +47,10 @@ type ContainerRuntime struct {
47
47
}
48
48
49
49
// Start launches chaincode in a runtime environment.
50
- func (c * ContainerRuntime ) Start (ctxt context.Context , cccid * ccprovider. CCContext , cds * pb. ChaincodeDeploymentSpec ) error {
51
- cname := cccid . GetCanonicalName ()
50
+ func (c * ContainerRuntime ) Start (ctxt context.Context , ccci * lifecycle. ChaincodeContainerInfo , codePackage [] byte ) error {
51
+ cname := ccci . Name + ":" + ccci . Version
52
52
53
- lc , err := c .LaunchConfig (cname , cds . ChaincodeSpec .Type )
53
+ lc , err := c .LaunchConfig (cname , ccci .Type )
54
54
if err != nil {
55
55
return err
56
56
}
@@ -61,43 +61,41 @@ func (c *ContainerRuntime) Start(ctxt context.Context, cccid *ccprovider.CCConte
61
61
62
62
scr := container.StartContainerReq {
63
63
Builder : & container.PlatformBuilder {
64
- Type : cds . CCType () ,
65
- Name : cds .Name () ,
66
- Version : cds .Version () ,
67
- Path : cds .Path () ,
68
- CodePackage : cds . Bytes () ,
64
+ Type : ccci . Type ,
65
+ Name : ccci .Name ,
66
+ Version : ccci .Version ,
67
+ Path : ccci .Path ,
68
+ CodePackage : codePackage ,
69
69
PlatformRegistry : c .PlatformRegistry ,
70
70
},
71
71
Args : lc .Args ,
72
72
Env : lc .Envs ,
73
73
FilesToUpload : lc .Files ,
74
74
CCID : ccintf.CCID {
75
- Name : cds . ChaincodeSpec . ChaincodeId .Name ,
76
- Version : cccid .Version ,
75
+ Name : ccci .Name ,
76
+ Version : ccci .Version ,
77
77
},
78
78
}
79
79
80
- vmtype := getVMType (cds )
81
-
82
- if err := c .Processor .Process (ctxt , vmtype , scr ); err != nil {
80
+ if err := c .Processor .Process (ctxt , ccci .ContainerType , scr ); err != nil {
83
81
return errors .WithMessage (err , "error starting container" )
84
82
}
85
83
86
84
return nil
87
85
}
88
86
89
87
// Stop terminates chaincode and its container runtime environment.
90
- func (c * ContainerRuntime ) Stop (ctxt context.Context , cccid * ccprovider. CCContext , cds * pb. ChaincodeDeploymentSpec ) error {
88
+ func (c * ContainerRuntime ) Stop (ctxt context.Context , ccci * lifecycle. ChaincodeContainerInfo ) error {
91
89
scr := container.StopContainerReq {
92
90
CCID : ccintf.CCID {
93
- Name : cds . ChaincodeSpec . ChaincodeId .Name ,
94
- Version : cccid .Version ,
91
+ Name : ccci .Name ,
92
+ Version : ccci .Version ,
95
93
},
96
94
Timeout : 0 ,
97
95
Dontremove : false ,
98
96
}
99
97
100
- if err := c .Processor .Process (ctxt , getVMType ( cds ) , scr ); err != nil {
98
+ if err := c .Processor .Process (ctxt , ccci . ContainerType , scr ); err != nil {
101
99
return errors .WithMessage (err , "error stopping container" )
102
100
}
103
101
@@ -138,19 +136,19 @@ type LaunchConfig struct {
138
136
}
139
137
140
138
// LaunchConfig creates the LaunchConfig for chaincode running in a container.
141
- func (c * ContainerRuntime ) LaunchConfig (cname string , ccType pb. ChaincodeSpec_Type ) (* LaunchConfig , error ) {
139
+ func (c * ContainerRuntime ) LaunchConfig (cname string , ccType string ) (* LaunchConfig , error ) {
142
140
var lc LaunchConfig
143
141
144
142
// common environment variables
145
143
lc .Envs = append (c .CommonEnv , "CORE_CHAINCODE_ID_NAME=" + cname )
146
144
147
145
// language specific arguments
148
146
switch ccType {
149
- case pb .ChaincodeSpec_GOLANG , pb .ChaincodeSpec_CAR :
147
+ case pb .ChaincodeSpec_GOLANG . String () , pb .ChaincodeSpec_CAR . String () :
150
148
lc .Args = []string {"chaincode" , fmt .Sprintf ("-peer.address=%s" , c .PeerAddress )}
151
- case pb .ChaincodeSpec_JAVA :
149
+ case pb .ChaincodeSpec_JAVA . String () :
152
150
lc .Args = []string {"/root/chaincode-java/start" , "--peerAddress" , c .PeerAddress }
153
- case pb .ChaincodeSpec_NODE :
151
+ case pb .ChaincodeSpec_NODE . String () :
154
152
lc .Args = []string {"/bin/sh" , "-c" , fmt .Sprintf ("cd /usr/local/src; npm start -- --peer.address %s" , c .PeerAddress )}
155
153
default :
156
154
return nil , errors .Errorf ("unknown chaincodeType: %s" , ccType )
0 commit comments