Skip to content

Commit 1949651

Browse files
committed
[FAB-3751] Add support to configure kafka in BDD
Added concept of composition to step ordererBootstrapAdmin creating the genesis block. This makes mor explicit the requirement that the orderer boostrap requires network configuration information. Now the addition of the orderer addresses and kafka specific genesis block configuration information depend on the composition information. Increased the topology graph view. Change-Id: Icf1fc49265a24898c6c924c56c8778dc3b8e74d6 Signed-off-by: Jeff Garratt <[email protected]>
1 parent d14cfcf commit 1949651

File tree

5 files changed

+32
-27
lines changed

5 files changed

+32
-27
lines changed

bddtests/features/bootstrap.feature

+3-3
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ Feature: Bootstrap
6868

6969
# Order info includes orderer admin/orderer information and address (host:port) from previous steps
7070
# Only the peer organizations can vary.
71-
And the ordererBootstrapAdmin using cert alias "bootstrapCertAlias" creates the genesis block "ordererGenesisBlock" for chain "OrdererSystemChainId" for network config policy "<PolicyType>" and consensus "<ConsensusType>" using consortiums:
72-
| Consortium |
73-
| consortium1 |
71+
And the ordererBootstrapAdmin using cert alias "bootstrapCertAlias" creates the genesis block "ordererGenesisBlock" for chain "OrdererSystemChainId" for composition "<ComposeFile>" and consensus "<ConsensusType>" using consortiums:
72+
| Consortium |
73+
| consortium1 |
7474

7575

7676
And the orderer admins inspect and approve the genesis block for chain "OrdererSystemChainId"

bddtests/steps/bootstrap_impl.py

+10-5
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ def step_impl(context):
6262
# Simply create the user
6363
bootstrap_util.getOrdererBootstrapAdmin(context, shouldCreate=True)
6464

65-
@given(u'the ordererBootstrapAdmin using cert alias "{certAlias}" creates the genesis block "{ordererGenesisBlockName}" for chain "{ordererSystemChainIdName}" for network config policy "{networkConfigPolicy}" and consensus "{consensusType}" using consortiums')
66-
def step_impl(context, certAlias, ordererGenesisBlockName, ordererSystemChainIdName, networkConfigPolicy, consensusType):
65+
@given(u'the ordererBootstrapAdmin using cert alias "{certAlias}" creates the genesis block "{ordererGenesisBlockName}" for chain "{ordererSystemChainIdName}" for composition "{composeFile}" and consensus "{consensusType}" using consortiums')
66+
def step_impl(context, certAlias, ordererGenesisBlockName, ordererSystemChainIdName, composeFile, consensusType):
6767
directory = bootstrap_util.getDirectory(context=context)
6868
ordererBootstrapAdmin = bootstrap_util.getOrdererBootstrapAdmin(context)
6969
ordererSystemChainIdGUUID = ordererBootstrapAdmin.tags[ordererSystemChainIdName]
@@ -74,12 +74,17 @@ def step_impl(context, certAlias, ordererGenesisBlockName, ordererSystemChainIdN
7474
configGroups += ordererBootstrapAdmin.tags[configGroupName]
7575
# Concatenate signedConfigItems
7676

77+
service_names = compose.Composition(context, composeFilesYaml=composeFile, register_and_up=False).getServiceNames()
78+
7779
# Construct block
7880
nodeAdminTuple = ordererBootstrapAdmin.tags[certAlias]
7981
bootstrapCert = directory.findCertForNodeAdminTuple(nodeAdminTuple=nodeAdminTuple)
80-
(genesisBlock, envelope, genesis_block_channel_config) = bootstrap_util.createGenesisBlock(context, ordererSystemChainIdGUUID, consensusType,
81-
nodeAdminTuple=nodeAdminTuple,
82-
signedConfigItems=configGroups)
82+
(genesisBlock, envelope, genesis_block_channel_config) = bootstrap_util.createGenesisBlock(context=context,
83+
service_names=service_names,
84+
chainId=ordererSystemChainIdGUUID,
85+
consensusType=consensusType,
86+
nodeAdminTuple=nodeAdminTuple,
87+
signedConfigItems=configGroups)
8388
ordererBootstrapAdmin.setTagValue(ordererGenesisBlockName + "_genesis_channel_config", genesis_block_channel_config)
8489
ordererBootstrapAdmin.setTagValue(ordererGenesisBlockName, genesisBlock)
8590
ordererBootstrapAdmin.setTagValue("ConsensusType", consensusType)

bddtests/steps/bootstrap_util.py

+11-12
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ def setDefaultPoliciesForOrgs(channel, orgs, group_name, version=0, policy_versi
595595

596596

597597

598-
def createChannelConfigGroup(directory, hashingAlgoName="SHA256", consensusType="solo", batchTimeout="1s", batchSizeMaxMessageCount=10, batchSizeAbsoluteMaxBytes=100000000, batchSizePreferredMaxBytes=512 * 1024, channel_max_count=0):
598+
def createChannelConfigGroup(directory, service_names, hashingAlgoName="SHA256", consensusType="solo", batchTimeout="1s", batchSizeMaxMessageCount=10, batchSizeAbsoluteMaxBytes=100000000, batchSizePreferredMaxBytes=512 * 1024, channel_max_count=0):
599599

600600
channel = common_dot_configtx_pb2.ConfigGroup()
601601
# channel.groups[ApplicationGroup] = common_dot_configtx_pb2.ConfigGroup()
@@ -647,12 +647,12 @@ def createChannelConfigGroup(directory, hashingAlgoName="SHA256", consensusType=
647647
channel.groups[OrdererGroup].groups[ordererOrg.name].values[BootstrapHelper.KEY_MSP_INFO].value = toValue(
648648
getMSPConfig(org=ordererOrg, directory=directory))
649649
channel.groups[OrdererGroup].groups[ordererOrg.name].values[BootstrapHelper.KEY_MSP_INFO].mod_policy=BootstrapHelper.KEY_POLICY_ADMINS
650-
# #Kafka specific
651-
# matchingNATs = [nat for nat in directory.getNamedCtxTuples() if (("orderer" in nat.user) and ("Signer" in nat.user) and ((compose_service in nat.nodeName)))]
652-
# for broker in [org for org in directory.getOrganizations().values() if Network.Orderer in org.networks]:
653-
# channel.groups[OrdererGroup].groups[ordererOrg.name].values[BootstrapHelper.KEY_MSP_INFO].value = toValue(
654-
# ordererOrg.getMSPConfig())
655-
# channel.groups[OrdererGroup].values[BootstrapHelper.KEY_ORDERER_KAFKA_BROKERS].value = toValue(orderer_dot_configuration_pb2.KafkaBrokers(brokers=["kafka0:9092"]))
650+
651+
#Kafka specific
652+
kafka_brokers = ["{0}:9092".format(service_name) for service_name in service_names if "kafka" in service_name]
653+
if len(kafka_brokers) > 0:
654+
channel.groups[OrdererGroup].values[BootstrapHelper.KEY_ORDERER_KAFKA_BROKERS].value = toValue(
655+
orderer_dot_configuration_pb2.KafkaBrokers(brokers=kafka_brokers))
656656

657657
for vKey, vVal in channel.groups[OrdererGroup].values.iteritems():
658658
vVal.mod_policy=BootstrapHelper.KEY_POLICY_ADMINS
@@ -666,9 +666,8 @@ def createChannelConfigGroup(directory, hashingAlgoName="SHA256", consensusType=
666666

667667
#New OrdererAddress
668668
ordererAddress = common_dot_configuration_pb2.OrdererAddresses()
669-
for ordererNodeTuple, cert in [(user_node_tuple, cert) for user_node_tuple, cert in directory.ordererAdminTuples.iteritems() if
670-
"orderer" in user_node_tuple.user and "signer" in user_node_tuple.user.lower()]:
671-
ordererAddress.addresses.append("{0}:7050".format(ordererNodeTuple.nodeName))
669+
for orderer_service_name in [service_name for service_name in service_names if "orderer" in service_name]:
670+
ordererAddress.addresses.append("{0}:7050".format(orderer_service_name))
672671
assert len(ordererAddress.addresses) > 0, "No orderer nodes were found while trying to create channel ConfigGroup"
673672
channel.values[BootstrapHelper.KEY_ORDERER_ADDRESSES].value = toValue(ordererAddress)
674673

@@ -739,13 +738,13 @@ def mergeConfigGroups(configGroupTarget, configGroupSource):
739738
configGroupTarget.values[k].CopyFrom(v)
740739

741740

742-
def createGenesisBlock(context, chainId, consensusType, nodeAdminTuple, signedConfigItems=[]):
741+
def createGenesisBlock(context, service_names, chainId, consensusType, nodeAdminTuple, signedConfigItems=[]):
743742
'Generates the genesis block for starting the oderers and for use in the chain config transaction by peers'
744743
# assert not "bootstrapGenesisBlock" in context,"Genesis block already created:\n{0}".format(context.bootstrapGenesisBlock)
745744
directory = getDirectory(context)
746745
assert len(directory.ordererAdminTuples) > 0, "No orderer admin tuples defined!!!"
747746

748-
channelConfig = createChannelConfigGroup(directory=directory, consensusType=consensusType)
747+
channelConfig = createChannelConfigGroup(directory=directory, service_names=service_names, consensusType=consensusType)
749748
for configGroup in signedConfigItems:
750749
mergeConfigGroups(channelConfig, configGroup)
751750

bddtests/steps/compose.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ def GetCompositionCallbacksFromContext(cls, context):
8282
def GetUUID(cls):
8383
return GetDockerSafeUUID()
8484

85-
def __init__(self, context, composeFilesYaml, projectName = None,
86-
force_recreate = True, components = []):
85+
def __init__(self, context, composeFilesYaml, projectName=None,
86+
force_recreate=True, components=[], register_and_up=True):
8787
self.contextHelper = ContextHelper.GetHelper(context=context)
8888
if not projectName:
8989
projectName = self.contextHelper.getGuuid()
@@ -93,10 +93,11 @@ def __init__(self, context, composeFilesYaml, projectName = None,
9393
self.composeFilesYaml = composeFilesYaml
9494
self.serviceNames = []
9595
self.serviceNames = self._collectServiceNames()
96-
# Register with contextHelper (Supports docgen)
97-
self.contextHelper.registerComposition(self)
98-
[callback.composing(self, context) for callback in Composition.GetCompositionCallbacksFromContext(context)]
99-
self.up(context, force_recreate, components)
96+
if register_and_up:
97+
# Register with contextHelper (Supports docgen)
98+
self.contextHelper.registerComposition(self)
99+
[callback.composing(self, context) for callback in Composition.GetCompositionCallbacksFromContext(context)]
100+
self.up(context, force_recreate, components)
100101

101102
def _collectServiceNames(self):
102103
'First collect the services names.'

bddtests/templates/html/graph.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
</style>
1414
<div>
15-
<svg width="860" height="700"></svg>
15+
<svg width="860" height="800"></svg>
1616
</div>
1717
<script src="https://d3js.org/d3.v4.min.js"></script>
1818
<script>

0 commit comments

Comments
 (0)