Commit 7c6241cf authored by David Enyeart's avatar David Enyeart Committed by Gerrit Code Review
Browse files

Merge "[FAB-12802] Pass metrics provider to ledgermgmt"

parents f5a25e29 96208305
......@@ -26,6 +26,7 @@ import (
configtxtest "github.com/hyperledger/fabric/common/configtx/test"
"github.com/hyperledger/fabric/common/ledger/blkstorage/fsblkstorage"
"github.com/hyperledger/fabric/common/ledger/testutil"
"github.com/hyperledger/fabric/common/metrics/disabled"
"github.com/hyperledger/fabric/common/util"
lgr "github.com/hyperledger/fabric/core/ledger"
"github.com/hyperledger/fabric/core/ledger/ledgerconfig"
......@@ -308,6 +309,7 @@ func testutilNewProvider(t *testing.T) lgr.PeerLedgerProvider {
assert.NoError(t, err)
provider.Initialize(&lgr.Initializer{
DeployedChaincodeInfoProvider: &mock.DeployedChaincodeInfoProvider{},
MetricsProvider: &disabled.Provider{},
})
return provider
}
......
......@@ -10,6 +10,7 @@ import (
"testing"
"github.com/hyperledger/fabric/common/ledger/testutil"
"github.com/hyperledger/fabric/common/metrics/disabled"
"github.com/hyperledger/fabric/core/ledger"
"github.com/hyperledger/fabric/core/ledger/mock"
"github.com/hyperledger/fabric/protos/ledger/rwset/kvrwset"
......@@ -29,6 +30,7 @@ func TestStateListener(t *testing.T) {
provider.Initialize(&ledger.Initializer{
DeployedChaincodeInfoProvider: &mock.DeployedChaincodeInfoProvider{},
StateListeners: []ledger.StateListener{mockListener},
MetricsProvider: &disabled.Provider{},
})
bg, gb := testutil.NewBlockGenerator(t, channelid, false)
......
......@@ -11,6 +11,8 @@ import (
"path/filepath"
"testing"
"github.com/hyperledger/fabric/common/metrics/disabled"
"github.com/hyperledger/fabric/common/ledger/blkstorage/fsblkstorage"
"github.com/hyperledger/fabric/common/ledger/util"
"github.com/hyperledger/fabric/core/ledger/ledgerconfig"
......@@ -132,6 +134,7 @@ func initLedgerMgmt() {
&ledgermgmt.Initializer{
CustomTxProcessors: peer.ConfigTxProcessors,
DeployedChaincodeInfoProvider: &lscc.DeployedCCInfoProvider{},
MetricsProvider: &disabled.Provider{},
},
)
}
......
......@@ -11,6 +11,7 @@ import (
"github.com/golang/protobuf/proto"
commonledger "github.com/hyperledger/fabric/common/ledger"
"github.com/hyperledger/fabric/common/metrics"
"github.com/hyperledger/fabric/protos/common"
"github.com/hyperledger/fabric/protos/ledger/rwset"
"github.com/hyperledger/fabric/protos/ledger/rwset/kvrwset"
......@@ -22,6 +23,7 @@ type Initializer struct {
StateListeners []StateListener
DeployedChaincodeInfoProvider DeployedChaincodeInfoProvider
MembershipInfoProvider MembershipInfoProvider
MetricsProvider metrics.Provider
}
// PeerLedgerProvider provides handle to ledger instances
......
......@@ -11,6 +11,7 @@ import (
"sync"
"github.com/hyperledger/fabric/common/flogging"
"github.com/hyperledger/fabric/common/metrics"
"github.com/hyperledger/fabric/core/chaincode/platforms"
"github.com/hyperledger/fabric/core/common/ccprovider"
"github.com/hyperledger/fabric/core/ledger"
......@@ -42,6 +43,7 @@ type Initializer struct {
PlatformRegistry *platforms.Registry
DeployedChaincodeInfoProvider ledger.DeployedChaincodeInfoProvider
MembershipInfoProvider ledger.MembershipInfoProvider
MetricsProvider metrics.Provider
}
// Initialize initializes ledgermgmt
......@@ -71,6 +73,7 @@ func initialize(initializer *Initializer) {
StateListeners: finalStateListeners,
DeployedChaincodeInfoProvider: initializer.DeployedChaincodeInfoProvider,
MembershipInfoProvider: initializer.MembershipInfoProvider,
MetricsProvider: initializer.MetricsProvider,
})
ledgerProvider = provider
logger.Info("ledger mgmt initialized")
......
......@@ -21,6 +21,8 @@ import (
"os"
"testing"
"github.com/hyperledger/fabric/common/metrics/disabled"
"github.com/hyperledger/fabric/common/configtx/test"
"github.com/hyperledger/fabric/core/chaincode/platforms"
"github.com/hyperledger/fabric/core/chaincode/platforms/golang"
......@@ -90,6 +92,7 @@ func TestLedgerMgmt(t *testing.T) {
// Restart ledger mgmt with existing ledgers
Initialize(&Initializer{
PlatformRegistry: platforms.NewRegistry(&golang.Platform{}),
MetricsProvider: &disabled.Provider{},
})
l, err = OpenLedger(ledgerID)
assert.NoError(t, err)
......
/*
Copyright IBM Corp. 2016 All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package ledgermgmt
......@@ -20,6 +9,7 @@ import (
"fmt"
"os"
"github.com/hyperledger/fabric/common/metrics/disabled"
"github.com/hyperledger/fabric/core/chaincode/platforms"
"github.com/hyperledger/fabric/core/chaincode/platforms/golang"
"github.com/hyperledger/fabric/core/ledger/ledgerconfig"
......@@ -48,6 +38,9 @@ func InitializeExistingTestEnvWithInitializer(initializer *Initializer) {
if initializer.DeployedChaincodeInfoProvider == nil {
initializer.DeployedChaincodeInfoProvider = &mock.DeployedChaincodeInfoProvider{}
}
if initializer.MetricsProvider == nil {
initializer.MetricsProvider = &disabled.Provider{}
}
if initializer.PlatformRegistry == nil {
initializer.PlatformRegistry = platforms.NewRegistry(&golang.Platform{})
}
......
......@@ -20,6 +20,7 @@ import (
commonledger "github.com/hyperledger/fabric/common/ledger"
"github.com/hyperledger/fabric/common/ledger/blockledger"
fileledger "github.com/hyperledger/fabric/common/ledger/blockledger/file"
"github.com/hyperledger/fabric/common/metrics"
"github.com/hyperledger/fabric/common/policies"
"github.com/hyperledger/fabric/core/chaincode/platforms"
"github.com/hyperledger/fabric/core/comm"
......@@ -201,7 +202,9 @@ var validationWorkersSemaphore *semaphore.Weighted
// Initialize sets up any chains that the peer has from the persistence. This
// function should be called at the start up when the ledger and gossip
// ready
func Initialize(init func(string), ccp ccprovider.ChaincodeProvider, sccp sysccprovider.SystemChaincodeProvider, pm txvalidator.PluginMapper, pr *platforms.Registry, deployedCCInfoProvider ledger.DeployedChaincodeInfoProvider, membershipProvider ledger.MembershipInfoProvider) {
func Initialize(init func(string), ccp ccprovider.ChaincodeProvider, sccp sysccprovider.SystemChaincodeProvider,
pm txvalidator.PluginMapper, pr *platforms.Registry, deployedCCInfoProvider ledger.DeployedChaincodeInfoProvider,
membershipProvider ledger.MembershipInfoProvider, metricsProvider metrics.Provider) {
nWorkers := viper.GetInt("peer.validatorPoolSize")
if nWorkers <= 0 {
nWorkers = runtime.NumCPU()
......@@ -218,6 +221,7 @@ func Initialize(init func(string), ccp ccprovider.ChaincodeProvider, sccp sysccp
PlatformRegistry: pr,
DeployedChaincodeInfoProvider: deployedCCInfoProvider,
MembershipInfoProvider: membershipProvider,
MetricsProvider: metricsProvider,
})
ledgerIds, err := ledgermgmt.GetLedgerIDs()
if err != nil {
......
......@@ -8,6 +8,7 @@ package peer
import (
"github.com/hyperledger/fabric/common/channelconfig"
"github.com/hyperledger/fabric/common/metrics"
"github.com/hyperledger/fabric/common/policies"
"github.com/hyperledger/fabric/core/chaincode/platforms"
"github.com/hyperledger/fabric/core/committer/txvalidator"
......@@ -30,7 +31,7 @@ type Operations interface {
GetMSPIDs(cid string) []string
GetPolicyManager(cid string) policies.Manager
InitChain(cid string)
Initialize(init func(string), ccp ccprovider.ChaincodeProvider, sccp sysccprovider.SystemChaincodeProvider, pm txvalidator.PluginMapper, pr *platforms.Registry, deployedCCInfoProvider ledger.DeployedChaincodeInfoProvider, membershipProvider ledger.MembershipInfoProvider)
Initialize(init func(string), ccp ccprovider.ChaincodeProvider, sccp sysccprovider.SystemChaincodeProvider, pm txvalidator.PluginMapper, pr *platforms.Registry, deployedCCInfoProvider ledger.DeployedChaincodeInfoProvider, membershipProvider ledger.MembershipInfoProvider, metricsProvider metrics.Provider)
}
type peerImpl struct {
......@@ -42,7 +43,7 @@ type peerImpl struct {
getMSPIDs func(cid string) []string
getPolicyManager func(cid string) policies.Manager
initChain func(cid string)
initialize func(init func(string), ccp ccprovider.ChaincodeProvider, sccp sysccprovider.SystemChaincodeProvider, mapper txvalidator.PluginMapper, pr *platforms.Registry, deployedCCInfoProvider ledger.DeployedChaincodeInfoProvider, membershipProvider ledger.MembershipInfoProvider)
initialize func(init func(string), ccp ccprovider.ChaincodeProvider, sccp sysccprovider.SystemChaincodeProvider, mapper txvalidator.PluginMapper, pr *platforms.Registry, deployedCCInfoProvider ledger.DeployedChaincodeInfoProvider, membershipProvider ledger.MembershipInfoProvider, metricsProvider metrics.Provider)
}
// Default provides in implementation of the Peer interface that provides
......@@ -73,6 +74,6 @@ func (p *peerImpl) GetLedger(cid string) ledger.PeerLedger { return p.getL
func (p *peerImpl) GetMSPIDs(cid string) []string { return p.getMSPIDs(cid) }
func (p *peerImpl) GetPolicyManager(cid string) policies.Manager { return p.getPolicyManager(cid) }
func (p *peerImpl) InitChain(cid string) { p.initChain(cid) }
func (p *peerImpl) Initialize(init func(string), ccp ccprovider.ChaincodeProvider, sccp sysccprovider.SystemChaincodeProvider, mapper txvalidator.PluginMapper, pr *platforms.Registry, deployedCCInfoProvider ledger.DeployedChaincodeInfoProvider, membershipProvider ledger.MembershipInfoProvider) {
p.initialize(init, ccp, sccp, mapper, pr, deployedCCInfoProvider, membershipProvider)
func (p *peerImpl) Initialize(init func(string), ccp ccprovider.ChaincodeProvider, sccp sysccprovider.SystemChaincodeProvider, mapper txvalidator.PluginMapper, pr *platforms.Registry, deployedCCInfoProvider ledger.DeployedChaincodeInfoProvider, membershipProvider ledger.MembershipInfoProvider, metricsProvider metrics.Provider) {
p.initialize(init, ccp, sccp, mapper, pr, deployedCCInfoProvider, membershipProvider, metricsProvider)
}
......@@ -14,6 +14,7 @@ import (
configtxtest "github.com/hyperledger/fabric/common/configtx/test"
"github.com/hyperledger/fabric/common/localmsp"
"github.com/hyperledger/fabric/common/metrics/disabled"
mscc "github.com/hyperledger/fabric/common/mocks/scc"
"github.com/hyperledger/fabric/core/chaincode/platforms"
"github.com/hyperledger/fabric/core/comm"
......@@ -86,14 +87,14 @@ func TestInitialize(t *testing.T) {
cleanup := setupPeerFS(t)
defer cleanup()
Initialize(nil, &ccprovider.MockCcProviderImpl{}, (&mscc.MocksccProviderFactory{}).NewSystemChaincodeProvider(), txvalidator.MapBasedPluginMapper(map[string]validation.PluginFactory{}), nil, &ledgermocks.DeployedChaincodeInfoProvider{}, nil)
Initialize(nil, &ccprovider.MockCcProviderImpl{}, (&mscc.MocksccProviderFactory{}).NewSystemChaincodeProvider(), txvalidator.MapBasedPluginMapper(map[string]validation.PluginFactory{}), nil, &ledgermocks.DeployedChaincodeInfoProvider{}, nil, &disabled.Provider{})
}
func TestCreateChainFromBlock(t *testing.T) {
cleanup := setupPeerFS(t)
defer cleanup()
Initialize(nil, &ccprovider.MockCcProviderImpl{}, (&mscc.MocksccProviderFactory{}).NewSystemChaincodeProvider(), txvalidator.MapBasedPluginMapper(map[string]validation.PluginFactory{}), &platforms.Registry{}, &ledgermocks.DeployedChaincodeInfoProvider{}, nil)
Initialize(nil, &ccprovider.MockCcProviderImpl{}, (&mscc.MocksccProviderFactory{}).NewSystemChaincodeProvider(), txvalidator.MapBasedPluginMapper(map[string]validation.PluginFactory{}), &platforms.Registry{}, &ledgermocks.DeployedChaincodeInfoProvider{}, nil, &disabled.Provider{})
testChainID := fmt.Sprintf("mytestchainid-%d", rand.Int())
block, err := configtxtest.MakeGenesisBlock(testChainID)
if err != nil {
......
......@@ -162,7 +162,6 @@ func serve(args []string) error {
defer metricsShutdown()
membershipInfoProvider := privdata.NewMembershipInfoProvider(createSelfSignedData(), identityDeserializerFactory)
//initialize resource management exit
ledgermgmt.Initialize(
&ledgermgmt.Initializer{
......@@ -170,6 +169,7 @@ func serve(args []string) error {
PlatformRegistry: pr,
DeployedChaincodeInfoProvider: deployedCCInfoProvider,
MembershipInfoProvider: membershipInfoProvider,
MetricsProvider: metricsProvider,
},
)
......@@ -333,7 +333,8 @@ func serve(args []string) error {
logger.Panicf("Failed subscribing to chaincode lifecycle updates")
}
cceventmgmt.GetMgr().Register(cid, sub)
}, ccp, sccp, txvalidator.MapBasedPluginMapper(validationPluginsByName), pr, deployedCCInfoProvider, membershipInfoProvider)
}, ccp, sccp, txvalidator.MapBasedPluginMapper(validationPluginsByName),
pr, deployedCCInfoProvider, membershipInfoProvider, metricsProvider)
if viper.GetBool("peer.discovery.enabled") {
registerDiscoveryService(peerServer, policyMgr, lifecycle)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment