use of org.hyperledger.fabric.sdk.ChannelConfiguration in project fabric-sdk-java by hyperledger.
the class End2endIT method constructChannel.
Channel constructChannel(String name, HFClient client, SampleOrg sampleOrg) throws Exception {
// //////////////////////////
// Construct the channel
//
out("Constructing channel %s", name);
// boolean doPeerEventing = false;
boolean doPeerEventing = !testConfig.isRunningAgainstFabric10() && BAR_CHANNEL_NAME.equals(name);
// boolean doPeerEventing = !testConfig.isRunningAgainstFabric10() && FOO_CHANNEL_NAME.equals(name);
// Only peer Admin org
client.setUserContext(sampleOrg.getPeerAdmin());
Collection<Orderer> orderers = new LinkedList<>();
for (String orderName : sampleOrg.getOrdererNames()) {
Properties ordererProperties = testConfig.getOrdererProperties(orderName);
// example of setting keepAlive to avoid timeouts on inactive http2 connections.
// Under 5 minutes would require changes to server side to accept faster ping rates.
ordererProperties.put("grpc.NettyChannelBuilderOption.keepAliveTime", new Object[] { 5L, TimeUnit.MINUTES });
ordererProperties.put("grpc.NettyChannelBuilderOption.keepAliveTimeout", new Object[] { 8L, TimeUnit.SECONDS });
ordererProperties.put("grpc.NettyChannelBuilderOption.keepAliveWithoutCalls", new Object[] { true });
if (!clientTLSProperties.isEmpty()) {
ordererProperties.putAll(clientTLSProperties.get(sampleOrg.getName()));
}
orderers.add(client.newOrderer(orderName, sampleOrg.getOrdererLocation(orderName), ordererProperties));
}
// Just pick the first orderer in the list to create the channel.
Orderer anOrderer = orderers.iterator().next();
orderers.remove(anOrderer);
ChannelConfiguration channelConfiguration = new ChannelConfiguration(new File(TEST_FIXTURES_PATH + "/sdkintegration/e2e-2Orgs/" + TestConfig.FAB_CONFIG_GEN_VERS + "/" + name + ".tx"));
// Create channel that has only one signer that is this orgs peer admin. If channel creation policy needed more signature they would need to be added too.
Channel newChannel = client.newChannel(name, anOrderer, channelConfiguration, client.getChannelConfigurationSignature(channelConfiguration, sampleOrg.getPeerAdmin()));
out("Created channel %s", name);
// test with both cases when doing peer eventing.
boolean everyother = true;
for (String peerName : sampleOrg.getPeerNames()) {
String peerLocation = sampleOrg.getPeerLocation(peerName);
// test properties for peer.. if any.
Properties peerProperties = testConfig.getPeerProperties(peerName);
if (peerProperties == null) {
peerProperties = new Properties();
}
if (!clientTLSProperties.isEmpty()) {
peerProperties.putAll(clientTLSProperties.get(sampleOrg.getName()));
}
// Example of setting specific options on grpc's NettyChannelBuilder
peerProperties.put("grpc.NettyChannelBuilderOption.maxInboundMessageSize", 9000000);
Peer peer = client.newPeer(peerName, peerLocation, peerProperties);
if (doPeerEventing && everyother) {
// Default is all roles.
newChannel.joinPeer(peer, createPeerOptions());
} else {
// Set peer to not be all roles but eventing.
newChannel.joinPeer(peer, createPeerOptions().setPeerRoles(PeerRole.NO_EVENT_SOURCE));
}
out("Peer %s joined channel %s", peerName, name);
everyother = !everyother;
}
// just for testing ...
if (doPeerEventing) {
// Make sure there is one of each type peer at the very least.
assertFalse(newChannel.getPeers(EnumSet.of(PeerRole.EVENT_SOURCE)).isEmpty());
assertFalse(newChannel.getPeers(PeerRole.NO_EVENT_SOURCE).isEmpty());
}
for (Orderer orderer : orderers) {
// add remaining orderers if any.
newChannel.addOrderer(orderer);
}
for (String eventHubName : sampleOrg.getEventHubNames()) {
final Properties eventHubProperties = testConfig.getEventHubProperties(eventHubName);
eventHubProperties.put("grpc.NettyChannelBuilderOption.keepAliveTime", new Object[] { 5L, TimeUnit.MINUTES });
eventHubProperties.put("grpc.NettyChannelBuilderOption.keepAliveTimeout", new Object[] { 8L, TimeUnit.SECONDS });
if (!clientTLSProperties.isEmpty()) {
eventHubProperties.putAll(clientTLSProperties.get(sampleOrg.getName()));
}
EventHub eventHub = client.newEventHub(eventHubName, sampleOrg.getEventHubLocation(eventHubName), eventHubProperties);
newChannel.addEventHub(eventHub);
}
newChannel.initialize();
out("Finished initialization channel %s", name);
// Just checks if channel can be serialized and deserialized .. otherwise this is just a waste :)
byte[] serializedChannelBytes = newChannel.serializeChannel();
newChannel.shutdown(true);
return client.deSerializeChannel(serializedChannelBytes).initialize();
}
Aggregations