Skip to content

Commit 90281f4

Browse files
author
Jason Yellick
committed
FAB-9807 Remove unused VM methods
Killing yet more dead code. Change-Id: Ia2d94def5d51e1c2b3891d2a58420526f9d815a5 Signed-off-by: Jason Yellick <jyellick@us.ibm.com>
1 parent 7bc73ea commit 90281f4

File tree

5 files changed

+8
-217
lines changed

5 files changed

+8
-217
lines changed

core/container/controller.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,8 @@ type Builder interface {
2929

3030
//VM is an abstract virtual image for supporting arbitrary virual machines
3131
type VM interface {
32-
Deploy(ctxt context.Context, ccid ccintf.CCID, args []string, env []string, reader io.Reader) error
3332
Start(ctxt context.Context, ccid ccintf.CCID, args []string, env []string, filesToUpload map[string][]byte, builder Builder) error
3433
Stop(ctxt context.Context, ccid ccintf.CCID, timeout uint, dontkill bool, dontremove bool) error
35-
Destroy(ctxt context.Context, ccid ccintf.CCID, force bool, noprune bool) error
36-
GetVMName(ccID ccintf.CCID) string
3734
}
3835

3936
type refCountedLock struct {
@@ -165,7 +162,8 @@ func (vmc *VMController) Process(ctxt context.Context, vmtype string, req VMCReq
165162

166163
c := make(chan error)
167164
go func() {
168-
id := v.GetVMName(req.GetCCID())
165+
ccid := req.GetCCID()
166+
id := ccid.GetName()
169167
vmc.lockContainer(id)
170168
err := req.Do(ctxt, v)
171169
vmc.unlockContainer(id)

core/container/dockercontroller/dockercontroller.go

-44
Original file line numberDiff line numberDiff line change
@@ -213,25 +213,6 @@ func (vm *DockerVM) deployImage(client dockerClient, ccid ccintf.CCID,
213213
return nil
214214
}
215215

216-
//Deploy use the reader containing targz to create a docker image
217-
//for docker inputbuf is tar reader ready for use by docker.Client
218-
//the stream from end client to peer could directly be this tar stream
219-
//talk to docker daemon using docker Client and build the image
220-
func (vm *DockerVM) Deploy(ctxt context.Context, ccid ccintf.CCID,
221-
args []string, env []string, reader io.Reader) error {
222-
223-
client, err := vm.getClientFnc()
224-
switch err {
225-
case nil:
226-
if err = vm.deployImage(client, ccid, args, env, reader); err != nil {
227-
return err
228-
}
229-
default:
230-
return fmt.Errorf("Error creating docker client: %s", err)
231-
}
232-
return nil
233-
}
234-
235216
//Start starts a container using a previously created docker image
236217
func (vm *DockerVM) Start(ctxt context.Context, ccid ccintf.CCID,
237218
args []string, env []string, filesToUpload map[string][]byte, builder container.Builder) error {
@@ -443,31 +424,6 @@ func (vm *DockerVM) stopInternal(ctxt context.Context, client dockerClient,
443424
return err
444425
}
445426

446-
//Destroy destroys an image
447-
func (vm *DockerVM) Destroy(ctxt context.Context, ccid ccintf.CCID, force bool, noprune bool) error {
448-
id, err := vm.GetVMNameForDocker(ccid)
449-
if err != nil {
450-
return err
451-
}
452-
453-
client, err := vm.getClientFnc()
454-
if err != nil {
455-
dockerLogger.Errorf("destroy-cannot create client %s", err)
456-
return err
457-
}
458-
id = strings.Replace(id, ":", "_", -1)
459-
460-
err = client.RemoveImageExtended(id, docker.RemoveImageOptions{Force: force, NoPrune: noprune})
461-
462-
if err != nil {
463-
dockerLogger.Errorf("error while destroying image: %s", err)
464-
} else {
465-
dockerLogger.Debugf("Destroyed image %s", id)
466-
}
467-
468-
return err
469-
}
470-
471427
// GetVMName generates the VM name from peer information. It accepts a format
472428
// function parameter to allow different formatting based on the desired use of
473429
// the name.

core/container/dockercontroller/dockercontroller_test.go

+6-60
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,13 @@ import (
3333
)
3434

3535
// This test used to be part of an integration style test in core/container, moved to here
36-
func TestRealPath(t *testing.T) {
36+
func TestIntegrationPath(t *testing.T) {
3737
coreutil.SetupTestConfig()
3838
ctxt := context.Background()
3939
dc := NewDockerVM("", "")
4040
ccid := ccintf.CCID{Name: "simple"}
41-
reader := getCodeChainBytesInMem()
4241

43-
err := dc.Deploy(ctxt, ccid, nil, nil, reader)
44-
require.NoError(t, err)
45-
46-
err = dc.Start(ctxt, ccid, nil, nil, nil, nil)
42+
err := dc.Start(ctxt, ccid, nil, nil, nil, InMemBuilder{})
4743
require.NoError(t, err)
4844

4945
// Stop, killing, and deleting
@@ -85,34 +81,6 @@ func TestGetDockerHostConfig(t *testing.T) {
8581
testutil.AssertEquals(t, hostConfig.CPUShares, int64(1024*1024*1024*2))
8682
}
8783

88-
func Test_Deploy(t *testing.T) {
89-
dvm := DockerVM{}
90-
ccid := ccintf.CCID{Name: "simple"}
91-
//get the tarball for codechain
92-
tarRdr := getCodeChainBytesInMem()
93-
args := make([]string, 1)
94-
env := make([]string, 1)
95-
ctx := context.Background()
96-
97-
// getMockClient returns error
98-
getClientErr = true
99-
dvm.getClientFnc = getMockClient
100-
err := dvm.Deploy(ctx, ccid, args, env, tarRdr)
101-
testerr(t, err, false)
102-
getClientErr = false
103-
104-
// Failure case: dockerClient.BuildImage returns error
105-
buildErr = true
106-
dvm.getClientFnc = getMockClient
107-
err = dvm.Deploy(ctx, ccid, args, env, tarRdr)
108-
testerr(t, err, false)
109-
buildErr = false
110-
111-
// Success case
112-
err = dvm.Deploy(ctx, ccid, args, env, tarRdr)
113-
testerr(t, err, true)
114-
}
115-
11684
func Test_Start(t *testing.T) {
11785
dvm := DockerVM{}
11886
ccid := ccintf.CCID{Name: "simple"}
@@ -213,30 +181,6 @@ func Test_Stop(t *testing.T) {
213181
testerr(t, err, true)
214182
}
215183

216-
func Test_Destroy(t *testing.T) {
217-
dvm := DockerVM{}
218-
ccid := ccintf.CCID{Name: "simple"}
219-
ctx := context.Background()
220-
221-
// Failure cases
222-
// Case 1: getMockClient returns error
223-
getClientErr = true
224-
dvm.getClientFnc = getMockClient
225-
err := dvm.Destroy(ctx, ccid, true, true)
226-
testerr(t, err, false)
227-
getClientErr = false
228-
229-
// Case 2: dockerClient.RemoveImageExtended returns error
230-
removeImgErr = true
231-
err = dvm.Destroy(ctx, ccid, true, true)
232-
testerr(t, err, false)
233-
removeImgErr = false
234-
235-
// Success case
236-
err = dvm.Destroy(ctx, ccid, true, true)
237-
testerr(t, err, true)
238-
}
239-
240184
type testCase struct {
241185
name string
242186
vm *DockerVM
@@ -314,7 +258,9 @@ func TestGetVMName(t *testing.T) {
314258
assert.NotNil(t, err, "Expected error")
315259
}*/
316260

317-
func getCodeChainBytesInMem() io.Reader {
261+
type InMemBuilder struct{}
262+
263+
func (imb InMemBuilder) Build() (io.Reader, error) {
318264
startTime := time.Now()
319265
inputbuf := bytes.NewBuffer(nil)
320266
gw := gzip.NewWriter(inputbuf)
@@ -327,7 +273,7 @@ func getCodeChainBytesInMem() io.Reader {
327273
tr.Write([]byte(dockerFileContents))
328274
tr.Close()
329275
gw.Close()
330-
return inputbuf
276+
return inputbuf, nil
331277
}
332278

333279
func testerr(t *testing.T, err error, succ bool) {

core/container/inproccontroller/inproccontroller.go

-30
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ package inproccontroller
88

99
import (
1010
"fmt"
11-
"io"
1211

1312
"github.com/hyperledger/fabric/common/flogging"
1413
"github.com/hyperledger/fabric/core/chaincode/shim"
@@ -107,29 +106,6 @@ func (vm *InprocVM) getInstance(ctxt context.Context, ipctemplate *inprocContain
107106
return ipc, nil
108107
}
109108

110-
//Deploy verifies chaincode is registered and creates an instance for it. Currently only one instance can be created
111-
func (vm *InprocVM) Deploy(ctxt context.Context, ccid ccintf.CCID, args []string, env []string, reader io.Reader) error {
112-
path := ccid.GetName()
113-
inprocLogger.Debugf("Deploying chaincode instance: %s", path)
114-
115-
ipctemplate := vm.registry.typeRegistry[path]
116-
if ipctemplate == nil {
117-
return fmt.Errorf(fmt.Sprintf("%s not registered. Please register the system chaincode in inprocinstances.go", path))
118-
}
119-
120-
if ipctemplate.chaincode == nil {
121-
return fmt.Errorf(fmt.Sprintf("%s system chaincode does not contain chaincode instance", path))
122-
}
123-
124-
instName := vm.GetVMName(ccid)
125-
_, err := vm.getInstance(ctxt, ipctemplate, instName, args, env)
126-
127-
//FUTURE ... here is where we might check code for safety
128-
inprocLogger.Debugf("registered : %s", path)
129-
130-
return err
131-
}
132-
133109
func (ipc *inprocContainer) launchInProc(ctxt context.Context, id string, args []string, env []string, ccSupport ccintf.CCSupport) error {
134110
peerRcvCCSend := make(chan *pb.ChaincodeMessage)
135111
ccRcvPeerSend := make(chan *pb.ChaincodeMessage)
@@ -251,12 +227,6 @@ func (vm *InprocVM) Stop(ctxt context.Context, ccid ccintf.CCID, timeout uint, d
251227
return nil
252228
}
253229

254-
//Destroy destroys an image
255-
func (vm *InprocVM) Destroy(ctxt context.Context, ccid ccintf.CCID, force bool, noprune bool) error {
256-
//not implemented
257-
return nil
258-
}
259-
260230
// GetVMName ignores the peer and network name as it just needs to be unique in
261231
// process. It accepts a format function parameter to allow different
262232
// formatting based on the desired use of the name.

core/container/inproccontroller/inproccontroller_test.go

-79
Original file line numberDiff line numberDiff line change
@@ -131,74 +131,6 @@ func (r MockReader) Read(p []byte) (n int, err error) {
131131
return 1, nil
132132
}
133133

134-
func TestDeployNotRegistered(t *testing.T) {
135-
mockContext := MockContext{}
136-
r := NewRegistry()
137-
vm := NewInprocVM(r)
138-
139-
ccid := ccintf.CCID{Name: "name"}
140-
141-
mockInprocContainer := &inprocContainer{
142-
chaincode: MockShim{},
143-
}
144-
145-
args := []string{"a", "b"}
146-
env := []string{"a", "b"}
147-
mockReader := MockReader{}
148-
ipc := &inprocContainer{args: args, env: env, chaincode: mockInprocContainer.chaincode, stopChan: make(chan struct{})}
149-
r.instRegistry["instName"] = ipc
150-
151-
err := vm.Deploy(mockContext, ccid, args, env, mockReader)
152-
153-
assert.NotNil(t, err, "err should not be nil")
154-
assert.Equal(t, err.Error(), "name not registered. Please register the system chaincode in inprocinstances.go", "error message should be correct")
155-
}
156-
157-
func TestDeployNoChaincodeInstance(t *testing.T) {
158-
mockContext := MockContext{}
159-
r := NewRegistry()
160-
vm := NewInprocVM(r)
161-
162-
ccid := ccintf.CCID{Name: "name"}
163-
164-
mockInprocContainer := &inprocContainer{}
165-
166-
args := []string{"a", "b"}
167-
env := []string{"a", "b"}
168-
mockReader := MockReader{}
169-
170-
ipc := &inprocContainer{args: args, env: env, chaincode: mockInprocContainer.chaincode, stopChan: make(chan struct{})}
171-
172-
r.typeRegistry["name"] = ipc
173-
174-
err := vm.Deploy(mockContext, ccid, args, env, mockReader)
175-
assert.NotNil(t, err, "err should not be nil")
176-
assert.Equal(t, err.Error(), "name system chaincode does not contain chaincode instance")
177-
}
178-
179-
func TestDeployChaincode(t *testing.T) {
180-
mockContext := MockContext{}
181-
r := NewRegistry()
182-
vm := NewInprocVM(r)
183-
184-
ccid := ccintf.CCID{Name: "name"}
185-
186-
mockInprocContainer := &inprocContainer{
187-
chaincode: MockShim{},
188-
}
189-
190-
args := []string{"a", "b"}
191-
env := []string{"a", "b"}
192-
mockReader := MockReader{}
193-
194-
ipc := &inprocContainer{args: args, env: env, chaincode: mockInprocContainer.chaincode, stopChan: make(chan struct{})}
195-
196-
r.typeRegistry["name"] = ipc
197-
198-
err := vm.Deploy(mockContext, ccid, args, env, mockReader)
199-
assert.Nil(t, err, "err should be nil")
200-
}
201-
202134
type MockCCSupport struct {
203135
}
204136

@@ -497,14 +429,3 @@ func TestStopIPCNotRunning(t *testing.T) {
497429
assert.NotNil(t, err, "err should not be nil")
498430
assert.Equal(t, err.Error(), "name-1 not running", "error should be correct")
499431
}
500-
501-
func TestDestroy(t *testing.T) {
502-
vm := NewInprocVM(NewRegistry())
503-
mockContext := MockContext{}
504-
ccid := ccintf.CCID{
505-
Name: "name",
506-
Version: "1",
507-
}
508-
err := vm.Destroy(mockContext, ccid, true, true)
509-
assert.Nil(t, err, "err should be nil")
510-
}

0 commit comments

Comments
 (0)