Skip to content

Commit 3d11489

Browse files
author
Jason Yellick
committed
FAB-9603 Remove dead code from core/container
This is a bunch of cruft from v0.5/v0.6 particularly in the chaincode space. This is unneeded code. Since it is a burden to maintain, and (because it is unused) poorly maintained, it should be removed. Change-Id: Id77a9289432885e8780c9d4d19b1f06afdb6174a Signed-off-by: Jason Yellick <jyellick@us.ibm.com>
1 parent 1496b78 commit 3d11489

File tree

4 files changed

+53
-124
lines changed

4 files changed

+53
-124
lines changed

core/chaincode/exectransaction_test.go

+3-23
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ import (
3535
"github.com/hyperledger/fabric/core/common/ccprovider"
3636
"github.com/hyperledger/fabric/core/config"
3737
"github.com/hyperledger/fabric/core/container"
38-
"github.com/hyperledger/fabric/core/container/ccintf"
3938
"github.com/hyperledger/fabric/core/ledger"
4039
"github.com/hyperledger/fabric/core/ledger/ledgerconfig"
4140
"github.com/hyperledger/fabric/core/ledger/ledgermgmt"
@@ -537,7 +536,7 @@ func checkFinalState(cccid *ccprovider.CCContext, a int, b int) error {
537536
}
538537

539538
// Invoke chaincode_example02
540-
func invokeExample02Transaction(ctxt context.Context, cccid *ccprovider.CCContext, cID *pb.ChaincodeID, chaincodeType pb.ChaincodeSpec_Type, args []string, destroyImage bool, chaincodeSupport *ChaincodeSupport) error {
539+
func invokeExample02Transaction(ctxt context.Context, cccid *ccprovider.CCContext, cID *pb.ChaincodeID, chaincodeType pb.ChaincodeSpec_Type, args []string, chaincodeSupport *ChaincodeSupport) error {
541540
// the ledger is created with genesis block. Start block number 1 onwards
542541
var nextBlockNumber uint64 = 1
543542
f := "init"
@@ -552,25 +551,6 @@ func invokeExample02Transaction(ctxt context.Context, cccid *ccprovider.CCContex
552551

553552
time.Sleep(time.Second)
554553

555-
if destroyImage {
556-
chaincodeSupport.Stop(ctxt, cccid, &pb.ChaincodeDeploymentSpec{ChaincodeSpec: spec})
557-
dir := container.DestroyImageReq{
558-
CCID: ccintf.CCID{
559-
ChaincodeSpec: spec,
560-
// NetworkID: chaincodeSupport.peerNetworkID,
561-
// PeerID: chaincodeSupport.peerID,
562-
},
563-
Force: true,
564-
NoPrune: true,
565-
}
566-
567-
_, err = container.VMCProcess(ctxt, container.DOCKER, dir)
568-
if err != nil {
569-
err = fmt.Errorf("Error destroying image: %s", err)
570-
return err
571-
}
572-
}
573-
574554
f = "invoke"
575555
invokeArgs := append([]string{f}, args...)
576556
spec = &pb.ChaincodeSpec{ChaincodeId: cID, Input: &pb.ChaincodeInput{Args: util.ToChaincodeArgs(invokeArgs...)}}
@@ -786,7 +766,7 @@ func TestExecuteInvokeTransaction(t *testing.T) {
786766
ccID := &pb.ChaincodeID{Name: chaincodeName, Path: tc.chaincodePath, Version: chaincodeVersion}
787767

788768
args := []string{"a", "b", "10"}
789-
err = invokeExample02Transaction(ctxt, cccid, ccID, tc.chaincodeType, args, true, chaincodeSupport)
769+
err = invokeExample02Transaction(ctxt, cccid, ccID, tc.chaincodeType, args, chaincodeSupport)
790770
if err != nil {
791771
t.Fail()
792772
t.Logf("Error invoking transaction: %s", err)
@@ -825,7 +805,7 @@ func TestExecuteInvokeInvalidTransaction(t *testing.T) {
825805

826806
//FAIL, FAIL!
827807
args := []string{"x", "-1"}
828-
err = invokeExample02Transaction(ctxt, cccid, ccID, pb.ChaincodeSpec_GOLANG, args, false, chaincodeSupport)
808+
err = invokeExample02Transaction(ctxt, cccid, ccID, pb.ChaincodeSpec_GOLANG, args, chaincodeSupport)
829809

830810
//this HAS to fail with expectedDeltaStringPrefix
831811
if err != nil {

core/chaincode/multichains_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func TestExecuteInvokeOnManyChains(t *testing.T) {
4545
args := []string{"a", "b", "10"}
4646
for _, c := range chains {
4747
cccid := ccprovider.NewCCContext(c, "example02", "0", "", false, nil, nil)
48-
err = invokeExample02Transaction(ctxt, cccid, chaincodeID, pb.ChaincodeSpec_GOLANG, args, false, chaincodeSupport)
48+
err = invokeExample02Transaction(ctxt, cccid, chaincodeID, pb.ChaincodeSpec_GOLANG, args, chaincodeSupport)
4949
if err != nil {
5050
t.Fail()
5151
t.Logf("Error invoking transaction: %s", err)

core/container/controller.go

+6-70
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,13 @@
11
/*
2-
Copyright IBM Corp. 2016 All Rights Reserved.
2+
Copyright IBM Corp. All Rights Reserved.
33
4-
Licensed under the Apache License, Version 2.0 (the "License");
5-
you may not use this file except in compliance with the License.
6-
You may obtain a copy of the License at
7-
8-
http://www.apache.org/licenses/LICENSE-2.0
9-
10-
Unless required by applicable law or agreed to in writing, software
11-
distributed under the License is distributed on an "AS IS" BASIS,
12-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
See the License for the specific language governing permissions and
14-
limitations under the License.
4+
SPDX-License-Identifier: Apache-2.0
155
*/
166

177
package container
188

199
import (
2010
"fmt"
21-
"io"
2211
"sync"
2312

2413
"golang.org/x/net/context"
@@ -44,21 +33,16 @@ type VMController struct {
4433
containerLocks map[string]*refCountedLock
4534
}
4635

47-
//singleton...acess through NewVMController
48-
var vmcontroller *VMController
36+
var vmcontroller = &VMController{
37+
containerLocks: make(map[string]*refCountedLock),
38+
}
4939

5040
//constants for supported containers
5141
const (
5242
DOCKER = "Docker"
5343
SYSTEM = "System"
5444
)
5545

56-
//NewVMController - creates/returns singleton
57-
func init() {
58-
vmcontroller = new(VMController)
59-
vmcontroller.containerLocks = make(map[string]*refCountedLock)
60-
}
61-
6246
func (vmc *VMController) newVM(typ string) api.VM {
6347
var v api.VM
6448

@@ -68,7 +52,7 @@ func (vmc *VMController) newVM(typ string) api.VM {
6852
case SYSTEM:
6953
v = &inproccontroller.InprocVM{}
7054
default:
71-
v = &dockercontroller.DockerVM{}
55+
vmLogger.Panicf("Programming error: unsupported VM type: %s", typ)
7256
}
7357
return v
7458
}
@@ -124,30 +108,6 @@ type VMCResp struct {
124108
Resp interface{}
125109
}
126110

127-
//CreateImageReq - properties for creating an container image
128-
type CreateImageReq struct {
129-
ccintf.CCID
130-
Reader io.Reader
131-
Args []string
132-
Env []string
133-
}
134-
135-
func (bp CreateImageReq) do(ctxt context.Context, v api.VM) VMCResp {
136-
var resp VMCResp
137-
138-
if err := v.Deploy(ctxt, bp.CCID, bp.Args, bp.Env, bp.Reader); err != nil {
139-
resp = VMCResp{Err: err}
140-
} else {
141-
resp = VMCResp{}
142-
}
143-
144-
return resp
145-
}
146-
147-
func (bp CreateImageReq) getCCID() ccintf.CCID {
148-
return bp.CCID
149-
}
150-
151111
//StartContainerReq - properties for starting a container.
152112
type StartContainerReq struct {
153113
ccintf.CCID
@@ -200,30 +160,6 @@ func (si StopContainerReq) getCCID() ccintf.CCID {
200160
return si.CCID
201161
}
202162

203-
//DestroyImageReq - properties for stopping a container.
204-
type DestroyImageReq struct {
205-
ccintf.CCID
206-
Timeout uint
207-
Force bool
208-
NoPrune bool
209-
}
210-
211-
func (di DestroyImageReq) do(ctxt context.Context, v api.VM) VMCResp {
212-
var resp VMCResp
213-
214-
if err := v.Destroy(ctxt, di.CCID, di.Force, di.NoPrune); err != nil {
215-
resp = VMCResp{Err: err}
216-
} else {
217-
resp = VMCResp{}
218-
}
219-
220-
return resp
221-
}
222-
223-
func (di DestroyImageReq) getCCID() ccintf.CCID {
224-
return di.CCID
225-
}
226-
227163
//VMCProcess should be used as follows
228164
// . construct a context
229165
// . construct req of the right type (e.g., CreateImageReq)

core/container/controller_test.go

+43-30
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"testing"
2727
"time"
2828

29+
"github.com/hyperledger/fabric/core/container/api"
2930
"github.com/hyperledger/fabric/core/container/ccintf"
3031
"github.com/hyperledger/fabric/core/container/dockercontroller"
3132
"github.com/hyperledger/fabric/core/container/inproccontroller"
@@ -125,45 +126,59 @@ func getCodeChainBytesInMem() (io.Reader, error) {
125126
return inputbuf, nil
126127
}
127128

128-
//set to true by providing "-run-controller-tests" command line option... Tests will create a docker image called "simple"
129-
var runTests bool
129+
//CreateImageReq - properties for creating an container image
130+
type CreateImageReq struct {
131+
ccintf.CCID
132+
Reader io.Reader
133+
Args []string
134+
Env []string
135+
}
130136

131-
func testForSkip(t *testing.T) {
132-
//run tests
133-
if !runTests {
134-
t.SkipNow()
137+
func (bp CreateImageReq) do(ctxt context.Context, v api.VM) VMCResp {
138+
var resp VMCResp
139+
if err := v.Deploy(ctxt, bp.CCID, bp.Args, bp.Env, bp.Reader); err != nil {
140+
resp = VMCResp{Err: err}
141+
} else {
142+
resp = VMCResp{}
135143
}
144+
return resp
145+
}
146+
func (bp CreateImageReq) getCCID() ccintf.CCID {
147+
return bp.CCID
136148
}
137149

138-
func TestVMCBuildImage(t *testing.T) {
139-
testForSkip(t)
150+
func createImage() {
140151
var ctxt = context.Background()
141-
142152
//get the tarball for codechain
143153
tarRdr, err := getCodeChainBytesInMem()
144154
if err != nil {
145-
t.Fail()
146-
t.Logf("Error reading tar file: %s", err)
147-
return
155+
panic(err)
148156
}
149157

150-
c := make(chan struct{})
158+
//create a the image needed for the rest of the tests obj and send it to VMCProcess
159+
cir := CreateImageReq{CCID: ccintf.CCID{ChaincodeSpec: &pb.ChaincodeSpec{ChaincodeId: &pb.ChaincodeID{Name: "simple"}}}, Reader: tarRdr}
160+
resp, err := VMCProcess(ctxt, "Docker", cir)
161+
eResp := VMCResp{}
162+
if err != nil || resp != eResp {
163+
panic(fmt.Sprintf("err: %s, resp: %s", err, resp))
164+
}
165+
}
151166

152-
//creat a CreateImageReq obj and send it to VMCProcess
153-
go func() {
154-
defer close(c)
155-
cir := CreateImageReq{CCID: ccintf.CCID{ChaincodeSpec: &pb.ChaincodeSpec{ChaincodeId: &pb.ChaincodeID{Name: "simple"}}}, Reader: tarRdr}
156-
_, err := VMCProcess(ctxt, "Docker", cir)
157-
if err != nil {
158-
t.Fail()
159-
t.Logf("Error creating image: %s", err)
160-
return
161-
}
162-
}()
167+
//set to true by providing "-run-controller-tests" command line option... Tests will create a docker image called "simple"
168+
var runTests bool
163169

164-
//wait for VMController to complete.
165-
fmt.Println("VMCBuildImage-waiting for response")
166-
<-c
170+
// tests will fail if we don't build an image to start and stop, so check to see if this has been done
171+
var imageCreated bool
172+
173+
func testForSkip(t *testing.T) {
174+
if !imageCreated {
175+
createImage()
176+
}
177+
178+
//run tests
179+
if !runTests {
180+
t.SkipNow()
181+
}
167182
}
168183

169184
func TestVMCStartContainer(t *testing.T) {
@@ -278,7 +293,5 @@ func TestNewVM(t *testing.T) {
278293
ivm := vm.(*inproccontroller.InprocVM)
279294
assert.NotNil(t, ivm, "Requested System VM but newVM did not return inproccontroller.InprocVM")
280295

281-
vm = vmcontroller.newVM("")
282-
dvm = vm.(*dockercontroller.DockerVM)
283-
assert.NotNil(t, dvm, "Requested default VM but newVM did not return dockercontroller.DockerVM")
296+
assert.Panics(t, func() { vmcontroller.newVM("") }, "Requested unknown VM but did not panic")
284297
}

0 commit comments

Comments
 (0)