Skip to content

Commit

Permalink
Deadcode cleanup: attachstdin/out in dockercontroller
Browse files Browse the repository at this point in the history
This is in prep for FAB-1855 later in the series.

Change-Id: Ia0e178b6e056f0a9ec7649d3f91ad1e75194224b
Signed-off-by: Greg Haskins <gregory.haskins@gmail.com>
  • Loading branch information
ghaskins committed Jan 25, 2017
1 parent 4e6359a commit ba01bfe
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 26 deletions.
24 changes: 10 additions & 14 deletions core/container/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ import (

//abstract virtual image for supporting arbitrary virual machines
type vm interface {
Deploy(ctxt context.Context, ccid ccintf.CCID, args []string, env []string, attachstdin bool, attachstdout bool, reader io.Reader) error
Start(ctxt context.Context, ccid ccintf.CCID, args []string, env []string, attachstdin bool, attachstdout bool, reader io.Reader) error
Deploy(ctxt context.Context, ccid ccintf.CCID, args []string, env []string, reader io.Reader) error
Start(ctxt context.Context, ccid ccintf.CCID, args []string, env []string, reader io.Reader) error
Stop(ctxt context.Context, ccid ccintf.CCID, timeout uint, dontkill bool, dontremove bool) error
Destroy(ctxt context.Context, ccid ccintf.CCID, force bool, noprune bool) error
GetVMName(ccID ccintf.CCID) (string, error)
Expand Down Expand Up @@ -137,17 +137,15 @@ type VMCResp struct {
//CreateImageReq - properties for creating an container image
type CreateImageReq struct {
ccintf.CCID
Reader io.Reader
AttachStdin bool
AttachStdout bool
Args []string
Env []string
Reader io.Reader
Args []string
Env []string
}

func (bp CreateImageReq) do(ctxt context.Context, v vm) VMCResp {
var resp VMCResp

if err := v.Deploy(ctxt, bp.CCID, bp.Args, bp.Env, bp.AttachStdin, bp.AttachStdout, bp.Reader); err != nil {
if err := v.Deploy(ctxt, bp.CCID, bp.Args, bp.Env, bp.Reader); err != nil {
resp = VMCResp{Err: err}
} else {
resp = VMCResp{}
Expand All @@ -163,17 +161,15 @@ func (bp CreateImageReq) getCCID() ccintf.CCID {
//StartImageReq - properties for starting a container.
type StartImageReq struct {
ccintf.CCID
Reader io.Reader
Args []string
Env []string
AttachStdin bool
AttachStdout bool
Reader io.Reader
Args []string
Env []string
}

func (si StartImageReq) do(ctxt context.Context, v vm) VMCResp {
var resp VMCResp

if err := v.Start(ctxt, si.CCID, si.Args, si.Env, si.AttachStdin, si.AttachStdout, si.Reader); err != nil {
if err := v.Start(ctxt, si.CCID, si.Args, si.Env, si.Reader); err != nil {
resp = VMCResp{Err: err}
} else {
resp = VMCResp{}
Expand Down
2 changes: 1 addition & 1 deletion core/container/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func TestVMCBuildImage(t *testing.T) {
//creat a CreateImageReq obj and send it to VMCProcess
go func() {
defer close(c)
cir := CreateImageReq{CCID: ccintf.CCID{ChaincodeSpec: &pb.ChaincodeSpec{ChaincodeID: &pb.ChaincodeID{Name: "simple"}}}, Reader: tarRdr, AttachStdout: true}
cir := CreateImageReq{CCID: ccintf.CCID{ChaincodeSpec: &pb.ChaincodeSpec{ChaincodeID: &pb.ChaincodeID{Name: "simple"}}}, Reader: tarRdr}
_, err := VMCProcess(ctxt, "Docker", cir)
if err != nil {
t.Fail()
Expand Down
18 changes: 9 additions & 9 deletions core/container/dockercontroller/dockercontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ func getDockerHostConfig() *docker.HostConfig {
return hostConfig
}

func (vm *DockerVM) createContainer(ctxt context.Context, client *docker.Client, imageID string, containerID string, args []string, env []string, attachstdin bool, attachstdout bool) error {
config := docker.Config{Cmd: args, Image: imageID, Env: env, AttachStdin: attachstdin, AttachStdout: attachstdout}
func (vm *DockerVM) createContainer(ctxt context.Context, client *docker.Client, imageID string, containerID string, args []string, env []string) error {
config := docker.Config{Cmd: args, Image: imageID, Env: env}
copts := docker.CreateContainerOptions{Name: containerID, Config: &config, HostConfig: getDockerHostConfig()}
dockerLogger.Debugf("Create container: %s", containerID)
_, err := client.CreateContainer(copts)
Expand All @@ -112,7 +112,7 @@ func (vm *DockerVM) createContainer(ctxt context.Context, client *docker.Client,
return nil
}

func (vm *DockerVM) deployImage(client *docker.Client, ccid ccintf.CCID, args []string, env []string, attachstdin bool, attachstdout bool, reader io.Reader) error {
func (vm *DockerVM) deployImage(client *docker.Client, ccid ccintf.CCID, args []string, env []string, reader io.Reader) error {
id, _ := vm.GetVMName(ccid)
outputbuf := bytes.NewBuffer(nil)
opts := docker.BuildImageOptions{
Expand All @@ -137,11 +137,11 @@ func (vm *DockerVM) deployImage(client *docker.Client, ccid ccintf.CCID, args []
//for docker inputbuf is tar reader ready for use by docker.Client
//the stream from end client to peer could directly be this tar stream
//talk to docker daemon using docker Client and build the image
func (vm *DockerVM) Deploy(ctxt context.Context, ccid ccintf.CCID, args []string, env []string, attachstdin bool, attachstdout bool, reader io.Reader) error {
func (vm *DockerVM) Deploy(ctxt context.Context, ccid ccintf.CCID, args []string, env []string, reader io.Reader) error {
client, err := cutil.NewDockerClient()
switch err {
case nil:
if err = vm.deployImage(client, ccid, args, env, attachstdin, attachstdout, reader); err != nil {
if err = vm.deployImage(client, ccid, args, env, reader); err != nil {
return err
}
default:
Expand All @@ -151,7 +151,7 @@ func (vm *DockerVM) Deploy(ctxt context.Context, ccid ccintf.CCID, args []string
}

//Start starts a container using a previously created docker image
func (vm *DockerVM) Start(ctxt context.Context, ccid ccintf.CCID, args []string, env []string, attachstdin bool, attachstdout bool, reader io.Reader) error {
func (vm *DockerVM) Start(ctxt context.Context, ccid ccintf.CCID, args []string, env []string, reader io.Reader) error {
imageID, _ := vm.GetVMName(ccid)
client, err := cutil.NewDockerClient()
if err != nil {
Expand All @@ -166,18 +166,18 @@ func (vm *DockerVM) Start(ctxt context.Context, ccid ccintf.CCID, args []string,
vm.stopInternal(ctxt, client, containerID, 0, false, false)

dockerLogger.Debugf("Start container %s", containerID)
err = vm.createContainer(ctxt, client, imageID, containerID, args, env, attachstdin, attachstdout)
err = vm.createContainer(ctxt, client, imageID, containerID, args, env)
if err != nil {
//if image not found try to create image and retry
if err == docker.ErrNoSuchImage {
if reader != nil {
dockerLogger.Debugf("start-could not find image ...attempt to recreate image %s", err)
if err = vm.deployImage(client, ccid, args, env, attachstdin, attachstdout, reader); err != nil {
if err = vm.deployImage(client, ccid, args, env, reader); err != nil {
return err
}

dockerLogger.Debug("start-recreated image successfully")
if err = vm.createContainer(ctxt, client, imageID, containerID, args, env, attachstdin, attachstdout); err != nil {
if err = vm.createContainer(ctxt, client, imageID, containerID, args, env); err != nil {
dockerLogger.Errorf("start-could not recreate container post recreate image: %s", err)
return err
}
Expand Down
4 changes: 2 additions & 2 deletions core/container/inproccontroller/inproccontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (vm *InprocVM) getInstance(ctxt context.Context, ipctemplate *inprocContain
}

//Deploy verifies chaincode is registered and creates an instance for it. Currently only one instance can be created
func (vm *InprocVM) Deploy(ctxt context.Context, ccid ccintf.CCID, args []string, env []string, attachstdin bool, attachstdout bool, reader io.Reader) error {
func (vm *InprocVM) Deploy(ctxt context.Context, ccid ccintf.CCID, args []string, env []string, reader io.Reader) error {
path := ccid.ChaincodeSpec.ChaincodeID.Path

ipctemplate := typeRegistry[path]
Expand Down Expand Up @@ -153,7 +153,7 @@ func (ipc *inprocContainer) launchInProc(ctxt context.Context, id string, args [
}

//Start starts a previously registered system codechain
func (vm *InprocVM) Start(ctxt context.Context, ccid ccintf.CCID, args []string, env []string, attachstdin bool, attachstdout bool, reader io.Reader) error {
func (vm *InprocVM) Start(ctxt context.Context, ccid ccintf.CCID, args []string, env []string, reader io.Reader) error {
path := ccid.ChaincodeSpec.ChaincodeID.Path

ipctemplate := typeRegistry[path]
Expand Down

0 comments on commit ba01bfe

Please sign in to comment.