Skip to content

Commit

Permalink
[FAB-10417] endpointconfig return type refactoring
Browse files Browse the repository at this point in the history
- endpointConfig.NetworkConfig to return only entity
since it is always preloaded and it is not a search function
-endpointConfig.OrderersConfig() to return only entity
since it is always preloaded and it is not a search function
-endpointConfig.NetworkPeers to return preloaded network peers
-endpointConfig.PeerConfigs by orgname to do dictionary
based search.
-endpointConfig.ChannelConfig logic optimized
-endpointConfig.ChannelPeers to do dictionary
based search.
-endpointConfig.ChannelOrderers to do dictionary
based search.

- FIXED DEVSTABLE ISSUES: changed tages from 'latest'
to 'stable'



Change-Id: I3474fdfc47db8409e2031c672faef0905d017ccd
Signed-off-by: Sudesh Shetty <sudesh.shetty@securekey.com>
  • Loading branch information
sudeshrshetty committed May 31, 2018
1 parent 9bae250 commit e067020
Show file tree
Hide file tree
Showing 26 changed files with 357 additions and 392 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ endif
FABRIC_TOOLS_STABLE_TAG := $(ARCH)-$(FABRIC_STABLE_VERSION)
FABRIC_TOOLS_PREV_TAG := $(ARCH)-$(FABRIC_PREV_VERSION)
FABRIC_TOOLS_PRERELEASE_TAG := $(ARCH)-$(FABRIC_PRERELEASE_VERSION)
FABRIC_TOOLS_DEVSTABLE_TAG := latest
FABRIC_TOOLS_DEVSTABLE_TAG := stable

# The version of dep that will be installed by depend-install (or in the CI)
GO_DEP_COMMIT := v0.4.1
Expand Down
5 changes: 1 addition & 4 deletions pkg/client/common/discovery/dynamicdiscovery/localservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,7 @@ func (s *LocalService) queryPeers() ([]fab.Peer, error) {
}

func (s *LocalService) getTarget(ctx contextAPI.Client) (*fab.PeerConfig, error) {
peers, ok := ctx.EndpointConfig().NetworkPeers()
if !ok {
return nil, errors.New("failed to get network peers")
}
peers := ctx.EndpointConfig().NetworkPeers()
mspID := ctx.Identifier().MSPID
for _, p := range peers {
// Need to go to a peer with the local MSPID, otherwise the request will be rejected
Expand Down
6 changes: 1 addition & 5 deletions pkg/client/common/discovery/staticdiscovery/localprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,7 @@ func (dp *LocalProvider) Initialize(fabPvdr contextAPI.Providers) error {
// CreateLocalDiscoveryService return a local discovery service
func (dp *LocalProvider) CreateLocalDiscoveryService(mspID string) (fab.DiscoveryService, error) {
peers := []fab.Peer{}

netPeers, ok := dp.config.NetworkPeers()
if !ok {
return nil, errors.New("unable to read configuration for network peers")
}
netPeers := dp.config.NetworkPeers()

logger.Debugf("Found %d peers", len(netPeers))

Expand Down
7 changes: 2 additions & 5 deletions pkg/client/msp/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,8 @@ func New(clientProvider context.ClientProvider, opts ...ClientOption) (*Client,
if msp.orgName == "" {
return nil, errors.New("organization is not provided")
}
networkConfig, ok := ctx.EndpointConfig().NetworkConfig()
if !ok {
return nil, errors.New("failed to get NetworkConfig")
}
_, ok = networkConfig.Organizations[strings.ToLower(msp.orgName)]
networkConfig := ctx.EndpointConfig().NetworkConfig()
_, ok := networkConfig.Organizations[strings.ToLower(msp.orgName)]
if !ok {
return nil, fmt.Errorf("non-existent organization: '%s'", msp.orgName)
}
Expand Down
13 changes: 2 additions & 11 deletions pkg/client/resmgmt/resmgmt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,20 +343,11 @@ func TestJoinChannelNoOrdererConfig(t *testing.T) {

// Misconfigured channel orderer
configBackend = getInvalidChannelOrdererBackend(backend...)
invalidChOrdererConfig, err := fabImpl.ConfigFromBackend(configBackend)
_, err = fabImpl.ConfigFromBackend(configBackend)

if err != nil {
if err == nil || !strings.Contains(err.Error(), "failed to load channel orderers: Could not find Orderer Config for channel orderer") {
t.Fatal(err)
}
ctx.SetEndpointConfig(invalidChOrdererConfig)

rc = setupResMgmtClient(t, ctx)

err = rc.JoinChannel("mychannel", WithTargets(peer1))

if err == nil || !strings.Contains(err.Error(), "failed to find orderer for request: orderer not found: orderers lookup failed") {
t.Fatalf("Should have failed to join channel since channel orderer has been misconfigured")
}

// Misconfigured global orderer (cert cannot be loaded)
configBackend = getInvalidOrdererBackend(backend...)
Expand Down
6 changes: 3 additions & 3 deletions pkg/common/providers/fab/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ type CommManager interface {
//EndpointConfig contains endpoint network configurations
type EndpointConfig interface {
Timeout(TimeoutType) time.Duration
OrderersConfig() ([]OrdererConfig, bool)
OrderersConfig() []OrdererConfig
OrdererConfig(nameOrURL string) (*OrdererConfig, bool)
PeersConfig(org string) ([]PeerConfig, bool)
PeerConfig(nameOrURL string) (*PeerConfig, bool)
NetworkConfig() (*NetworkConfig, bool)
NetworkPeers() ([]NetworkPeer, bool)
NetworkConfig() *NetworkConfig
NetworkPeers() []NetworkPeer
ChannelConfig(name string) (*ChannelNetworkConfig, bool)
ChannelPeers(name string) ([]ChannelPeer, bool)
ChannelOrderers(name string) ([]OrdererConfig, bool)
Expand Down
15 changes: 6 additions & 9 deletions pkg/common/providers/test/mockfab/mockfab.gen.go

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

5 changes: 1 addition & 4 deletions pkg/fab/channel/transactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,7 @@ func orderersFromChannel(ctx context.Client, channelID string) ([]fab.Orderer, e

func orderersByTarget(ctx context.Client) (map[string]fab.OrdererConfig, error) {
ordererDict := map[string]fab.OrdererConfig{}
orderersConfig, ok := ctx.EndpointConfig().OrderersConfig()
if !ok {
return nil, errors.New("loading orderers config failed")
}
orderersConfig := ctx.EndpointConfig().OrderersConfig()

for _, oc := range orderersConfig {
address := endpoint.ToAddress(oc.URL)
Expand Down
15 changes: 4 additions & 11 deletions pkg/fab/comm/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ func NetworkPeerConfig(cfg fab.EndpointConfig, key string) (*fab.NetworkPeer, er
}

// find MSP ID
networkPeers, ok := cfg.NetworkPeers()
if !ok {
return nil, errors.New("unable to load network peer config")
}
networkPeers := cfg.NetworkPeers()

var mspID string
for _, peer := range networkPeers {
Expand Down Expand Up @@ -52,11 +49,7 @@ func SearchPeerConfigFromURL(cfg fab.EndpointConfig, url string) (*fab.PeerConfi

//If the given url is already parsed URL through entity matcher, then 'cfg.PeerConfig()'
//may return NoMatchingPeerEntity error. So retry with network peer URLs
networkPeers, ok := cfg.NetworkPeers()
if !ok {
return nil, errors.New("unable to load network peer config")
}

networkPeers := cfg.NetworkPeers()
for _, peer := range networkPeers {
if peer.URL == url {
return &peer.PeerConfig, nil
Expand All @@ -68,8 +61,8 @@ func SearchPeerConfigFromURL(cfg fab.EndpointConfig, url string) (*fab.PeerConfi

// MSPID returns the MSP ID for the requested organization
func MSPID(cfg fab.EndpointConfig, org string) (string, bool) {
networkConfig, ok := cfg.NetworkConfig()
if !ok {
networkConfig := cfg.NetworkConfig()
if networkConfig == nil {
return "", false
}
// viper lowercases all key maps, org is lower case
Expand Down
Loading

0 comments on commit e067020

Please sign in to comment.