Skip to content

Commit

Permalink
FAB-11024 ChaincodeContainerInfo to ccprovider
Browse files Browse the repository at this point in the history
Prior to changing the ChaincodeProvider interface to use
ChaincodeContainerInfo instead of DeploymentSpecs, the
ChaincodeContainerInfo must be removed from the chaincode/lifecycle
package to avoid import cycles.

Change-Id: I9928726d4fcb04dc31841ba392fd20130448d8ae
Signed-off-by: Jason Yellick <jyellick@us.ibm.com>
  • Loading branch information
Jason Yellick committed Jul 16, 2018
1 parent 5f9de08 commit f5182d4
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 60 deletions.
8 changes: 4 additions & 4 deletions core/chaincode/chaincode_support.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ import (

// Runtime is used to manage chaincode runtime instances.
type Runtime interface {
Start(ccci *lifecycle.ChaincodeContainerInfo, codePackage []byte) error
Stop(ccci *lifecycle.ChaincodeContainerInfo) error
Start(ccci *ccprovider.ChaincodeContainerInfo, codePackage []byte) error
Stop(ccci *ccprovider.ChaincodeContainerInfo) error
}

// Launcher is used to launch chaincode runtimes.
type Launcher interface {
Launch(ccci *lifecycle.ChaincodeContainerInfo) error
Launch(ccci *ccprovider.ChaincodeContainerInfo) error
}

// Lifecycle provides a way to retrieve chaincode definitions and the packages necessary to run them
Expand All @@ -41,7 +41,7 @@ type Lifecycle interface {
GetChaincodeDefinition(chaincodeName string, txSim ledger.QueryExecutor) (ccprovider.ChaincodeDefinition, error)

// ChaincodeContainerInfo returns the package necessary to launch a chaincode
ChaincodeContainerInfo(chainID string, chaincodeID string) (*lifecycle.ChaincodeContainerInfo, error)
ChaincodeContainerInfo(chainID string, chaincodeID string) (*ccprovider.ChaincodeContainerInfo, error)
}

// ChaincodeSupport responsible for providing interfacing with chaincodes from the Peer.
Expand Down
12 changes: 6 additions & 6 deletions core/chaincode/chaincode_support_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,7 @@ func getLaunchConfigs(t *testing.T, cr *ContainerRuntime) {
func TestStartAndWaitSuccess(t *testing.T) {
handlerRegistry := NewHandlerRegistry(false)
fakeRuntime := &mock.Runtime{}
fakeRuntime.StartStub = func(_ *lifecycle.ChaincodeContainerInfo, _ []byte) error {
fakeRuntime.StartStub = func(_ *ccprovider.ChaincodeContainerInfo, _ []byte) error {
handlerRegistry.Ready("testcc:0")
return nil
}
Expand All @@ -1042,7 +1042,7 @@ func TestStartAndWaitSuccess(t *testing.T) {
PackageProvider: fakePackageProvider,
}

ccci := &lifecycle.ChaincodeContainerInfo{
ccci := &ccprovider.ChaincodeContainerInfo{
Type: "GOLANG",
Name: "testcc",
Version: "0",
Expand All @@ -1059,7 +1059,7 @@ func TestStartAndWaitSuccess(t *testing.T) {
//test timeout error
func TestStartAndWaitTimeout(t *testing.T) {
fakeRuntime := &mock.Runtime{}
fakeRuntime.StartStub = func(_ *lifecycle.ChaincodeContainerInfo, _ []byte) error {
fakeRuntime.StartStub = func(_ *ccprovider.ChaincodeContainerInfo, _ []byte) error {
time.Sleep(time.Second)
return nil
}
Expand All @@ -1075,7 +1075,7 @@ func TestStartAndWaitTimeout(t *testing.T) {
PackageProvider: fakePackageProvider,
}

ccci := &lifecycle.ChaincodeContainerInfo{
ccci := &ccprovider.ChaincodeContainerInfo{
Type: "GOLANG",
Name: "testcc",
Version: "0",
Expand All @@ -1092,7 +1092,7 @@ func TestStartAndWaitTimeout(t *testing.T) {
//test container return error
func TestStartAndWaitLaunchError(t *testing.T) {
fakeRuntime := &mock.Runtime{}
fakeRuntime.StartStub = func(_ *lifecycle.ChaincodeContainerInfo, _ []byte) error {
fakeRuntime.StartStub = func(_ *ccprovider.ChaincodeContainerInfo, _ []byte) error {
return errors.New("Bad lunch; upset stomach")
}

Expand All @@ -1107,7 +1107,7 @@ func TestStartAndWaitLaunchError(t *testing.T) {
PackageProvider: fakePackageProvider,
}

ccci := &lifecycle.ChaincodeContainerInfo{
ccci := &ccprovider.ChaincodeContainerInfo{
Type: "GOLANG",
Name: "testcc",
Version: "0",
Expand Down
6 changes: 3 additions & 3 deletions core/chaincode/container_runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
"strings"

"github.com/hyperledger/fabric/core/chaincode/accesscontrol"
"github.com/hyperledger/fabric/core/chaincode/lifecycle"
"github.com/hyperledger/fabric/core/chaincode/platforms"
"github.com/hyperledger/fabric/core/common/ccprovider"
"github.com/hyperledger/fabric/core/container"
"github.com/hyperledger/fabric/core/container/ccintf"
pb "github.com/hyperledger/fabric/protos/peer"
Expand Down Expand Up @@ -44,7 +44,7 @@ type ContainerRuntime struct {
}

// Start launches chaincode in a runtime environment.
func (c *ContainerRuntime) Start(ccci *lifecycle.ChaincodeContainerInfo, codePackage []byte) error {
func (c *ContainerRuntime) Start(ccci *ccprovider.ChaincodeContainerInfo, codePackage []byte) error {
cname := ccci.Name + ":" + ccci.Version

lc, err := c.LaunchConfig(cname, ccci.Type)
Expand Down Expand Up @@ -82,7 +82,7 @@ func (c *ContainerRuntime) Start(ccci *lifecycle.ChaincodeContainerInfo, codePac
}

// Stop terminates chaincode and its container runtime environment.
func (c *ContainerRuntime) Stop(ccci *lifecycle.ChaincodeContainerInfo) error {
func (c *ContainerRuntime) Stop(ccci *ccprovider.ChaincodeContainerInfo) error {
scr := container.StopContainerReq{
CCID: ccintf.CCID{
Name: ccci.Name,
Expand Down
10 changes: 5 additions & 5 deletions core/chaincode/container_runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (

"github.com/hyperledger/fabric/core/chaincode"
"github.com/hyperledger/fabric/core/chaincode/accesscontrol"
"github.com/hyperledger/fabric/core/chaincode/lifecycle"
"github.com/hyperledger/fabric/core/chaincode/mock"
"github.com/hyperledger/fabric/core/common/ccprovider"
"github.com/hyperledger/fabric/core/container"
"github.com/hyperledger/fabric/core/container/ccintf"
pb "github.com/hyperledger/fabric/protos/peer"
Expand Down Expand Up @@ -163,7 +163,7 @@ func TestContainerRuntimeStart(t *testing.T) {
PeerAddress: "peer.example.com",
}

ccci := &lifecycle.ChaincodeContainerInfo{
ccci := &ccprovider.ChaincodeContainerInfo{
Type: pb.ChaincodeSpec_GOLANG.String(),
Name: "chaincode-name",
Version: "chaincode-version",
Expand Down Expand Up @@ -208,7 +208,7 @@ func TestContainerRuntimeStartErrors(t *testing.T) {
PeerAddress: "peer.example.com",
}

ccci := &lifecycle.ChaincodeContainerInfo{
ccci := &ccprovider.ChaincodeContainerInfo{
Type: tc.chaincodeType,
Name: "chaincode-id-name",
Version: "chaincode-version",
Expand All @@ -225,7 +225,7 @@ func TestContainerRuntimeStop(t *testing.T) {
Processor: fakeProcessor,
}

ccci := &lifecycle.ChaincodeContainerInfo{
ccci := &ccprovider.ChaincodeContainerInfo{
Type: pb.ChaincodeSpec_GOLANG.String(),
Name: "chaincode-id-name",
Version: "chaincode-version",
Expand Down Expand Up @@ -265,7 +265,7 @@ func TestContainerRuntimeStopErrors(t *testing.T) {
Processor: fakeProcessor,
}

ccci := &lifecycle.ChaincodeContainerInfo{
ccci := &ccprovider.ChaincodeContainerInfo{
Type: pb.ChaincodeSpec_GOLANG.String(),
Name: "chaincode-id-name",
Version: "chaincode-version",
Expand Down
17 changes: 3 additions & 14 deletions core/chaincode/lifecycle/lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,8 @@ type Lifecycle struct {
InstantiatedChaincodeStore InstantiatedChaincodeStore
}

// ChaincodeContainerInfo is yet another synonym for the data required to start/stop a chaincode.
type ChaincodeContainerInfo struct {
Name string
Version string
Path string
Type string

// ContainerType is not a great name, but 'DOCKER' and 'SYSTEM' are the valid types
ContainerType string
}

// GetChaincodeDeploymentSpec retrieves a chaincode deployment spec for the specified chaincode.
func (l *Lifecycle) ChaincodeContainerInfo(channelID, chaincodeName string) (*ChaincodeContainerInfo, error) {
func (l *Lifecycle) ChaincodeContainerInfo(channelID, chaincodeName string) (*ccprovider.ChaincodeContainerInfo, error) {
cds, err := l.InstantiatedChaincodeStore.ChaincodeDeploymentSpec(channelID, chaincodeName)
if err != nil {
return nil, errors.Wrapf(err, "could not retrieve deployment spec for %s/%s", channelID, chaincodeName)
Expand All @@ -51,8 +40,8 @@ func (l *Lifecycle) GetChaincodeDefinition(chaincodeName string, txSim ledger.Qu
return l.InstantiatedChaincodeStore.ChaincodeDefinition(chaincodeName, txSim)
}

func DeploymentSpecToChaincodeContainerInfo(cds *pb.ChaincodeDeploymentSpec) *ChaincodeContainerInfo {
return &ChaincodeContainerInfo{
func DeploymentSpecToChaincodeContainerInfo(cds *pb.ChaincodeDeploymentSpec) *ccprovider.ChaincodeContainerInfo {
return &ccprovider.ChaincodeContainerInfo{
Name: cds.Name(),
Version: cds.Version(),
Path: cds.Path(),
Expand Down
19 changes: 9 additions & 10 deletions core/chaincode/mock/lifecycle.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 11 additions & 11 deletions core/chaincode/mock/runtime.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions core/chaincode/runtime_launcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ package chaincode
import (
"time"

"github.com/hyperledger/fabric/core/chaincode/lifecycle"
"github.com/hyperledger/fabric/core/common/ccprovider"
"github.com/hyperledger/fabric/core/container/inproccontroller"
"github.com/pkg/errors"
)
Expand All @@ -33,7 +33,7 @@ type RuntimeLauncher struct {
StartupTimeout time.Duration
}

func (r *RuntimeLauncher) Launch(ccci *lifecycle.ChaincodeContainerInfo) error {
func (r *RuntimeLauncher) Launch(ccci *ccprovider.ChaincodeContainerInfo) error {
var codePackage []byte
if ccci.ContainerType != inproccontroller.ContainerType {
var err error
Expand Down
10 changes: 5 additions & 5 deletions core/chaincode/runtime_launcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (

"github.com/hyperledger/fabric/core/chaincode"
"github.com/hyperledger/fabric/core/chaincode/fake"
lc "github.com/hyperledger/fabric/core/chaincode/lifecycle"
"github.com/hyperledger/fabric/core/chaincode/mock"
"github.com/hyperledger/fabric/core/common/ccprovider"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/pkg/errors"
Expand All @@ -25,7 +25,7 @@ var _ = Describe("RuntimeLauncher", func() {
fakeRegistry *fake.LaunchRegistry
launchState *chaincode.LaunchState

ccci *lc.ChaincodeContainerInfo
ccci *ccprovider.ChaincodeContainerInfo

runtimeLauncher *chaincode.RuntimeLauncher
)
Expand All @@ -36,15 +36,15 @@ var _ = Describe("RuntimeLauncher", func() {
fakeRegistry.LaunchingReturns(launchState, nil)

fakeRuntime = &mock.Runtime{}
fakeRuntime.StartStub = func(*lc.ChaincodeContainerInfo, []byte) error {
fakeRuntime.StartStub = func(*ccprovider.ChaincodeContainerInfo, []byte) error {
launchState.Notify(nil)
return nil
}

fakePackageProvider = &mock.PackageProvider{}
fakePackageProvider.GetChaincodeCodePackageReturns([]byte("code-package"), nil)

ccci = &lc.ChaincodeContainerInfo{
ccci = &ccprovider.ChaincodeContainerInfo{
Name: "chaincode-name",
Path: "chaincode-path",
Version: "chaincode-version",
Expand Down Expand Up @@ -137,7 +137,7 @@ var _ = Describe("RuntimeLauncher", func() {

Context("when handler registration fails", func() {
BeforeEach(func() {
fakeRuntime.StartStub = func(*lc.ChaincodeContainerInfo, []byte) error {
fakeRuntime.StartStub = func(*ccprovider.ChaincodeContainerInfo, []byte) error {
launchState.Notify(errors.New("papaya"))
return nil
}
Expand Down
Loading

0 comments on commit f5182d4

Please sign in to comment.