Skip to content

Commit

Permalink
FABJ-442 Servicediscovery logging enhancements.
Browse files Browse the repository at this point in the history
Change-Id: Ifcee5666086aba778749f02cd54d2bbdf21804f8
Signed-off-by: rickr <cr22rc@gmail.com>
  • Loading branch information
cr22rc committed May 17, 2019
1 parent 0dd377e commit a8ef7ce
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/main/java/org/hyperledger/fabric/sdk/Channel.java
Original file line number Diff line number Diff line change
Expand Up @@ -1141,7 +1141,7 @@ void sdUpdate(SDNetwork sdNetwork) throws InvalidArgumentException, ServiceDisco
return;
}
if (null == orderer) {
logger.debug(format("Channel %s doing channel update adding new orderer endpoint: %s", name, sdOrderer.getEndPoint()));
logger.debug(format("Channel %s doing channel update adding new orderer mspid: %s, endpoint: %s", name, sdOrderer.getMspid(), sdOrderer.getEndPoint()));

sdOrdererAddition.addOrderer(new SDOrdererAdditionInfo() {

Expand Down Expand Up @@ -1217,7 +1217,7 @@ public Map<String, Orderer> getEndpointMap() {
return;
}

logger.debug(format("Channel %s doing channel update found new peer endpoint %s", name, sdEndorser.getEndpoint()));
logger.debug(format("Channel %s doing channel update found new peer mspid: %s, endpoint: %s", name, sdEndorser.getMspid(), sdEndorser.getEndpoint()));

sdPeerAddition.addPeer(new SDPeerAdditionInfo() {

Expand Down
49 changes: 44 additions & 5 deletions src/main/java/org/hyperledger/fabric/sdk/ServiceDiscovery.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import org.hyperledger.fabric.sdk.transaction.TransactionContext;

import static java.lang.String.format;
import static org.hyperledger.fabric.sdk.helper.Utils.toHexString;

public class ServiceDiscovery {
private static final Log logger = LogFactory.getLog(ServiceDiscovery.class);
Expand Down Expand Up @@ -114,11 +115,17 @@ class SDNetwork {
long discoveryTime;

void addTlsCert(String mspid, byte[] cert) {
if (IS_TRACE_LEVEL) {
logger.trace(format("Channel %s service discovery MSPID %s adding TLSCert %s", channelName, mspid, toHexString(cert)));
}
tlsCerts.computeIfAbsent(mspid, k -> new LinkedList<>()).add(cert);

}

void addTlsIntermCert(String mspid, byte[] cert) {
if (IS_TRACE_LEVEL) {
logger.trace(format("Channel %s service discovery MSPID %s adding intermediate TLSCert %s", channelName, mspid, toHexString(cert)));
}
tlsIntermCerts.computeIfAbsent(mspid, k -> new LinkedList<>()).add(cert);

}
Expand Down Expand Up @@ -173,21 +180,31 @@ Set<String> getChaincodesNames() {

}

Collection<byte[]> getTlsCerts(String mspid) {
Collection<byte[]> getTlsCerts(final String mspid) {

final Collection<byte[]> bytes = tlsCerts.get(mspid);
if (null == bytes) {
logger.debug(format("Channel %s no tls ca certs for mspid: %s", channelName, mspid));
return Collections.emptyList();

}
if (bytes.isEmpty()) {
logger.debug(format("Channel %s no tls ca certs for mspid: %s", channelName, mspid));
}
return Collections.unmodifiableCollection(bytes);
}

Collection<byte[]> getTlsIntermediateCerts(String mspid) {
final Collection<byte[]> bytes = tlsIntermCerts.get(mspid);

if (null == bytes) {
logger.debug(format("Channel %s no tls intermediary ca certs for mspid: %s", channelName, mspid));
return Collections.emptyList();

}
if (bytes.isEmpty()) {
logger.debug(format("Channel %s no tls intermediary ca certs for mspid: %s", channelName, mspid));
}
return Collections.unmodifiableCollection(bytes);

}
Expand All @@ -211,7 +228,7 @@ SDNetwork networkDiscovery(TransactionContext ltransactionContext, boolean force
}
ret = null;

for (Peer serviceDiscoveryPeer : speers) {
for (final Peer serviceDiscoveryPeer : speers) {

try {

Expand Down Expand Up @@ -306,9 +323,19 @@ SDNetwork networkDiscovery(TransactionContext ltransactionContext, boolean force

Protocol.Endpoints value = i.getValue();
for (Protocol.Endpoint l : value.getEndpointList()) {
logger.trace(format("Channel %s discovered orderer MSPID: %s, endpoint: %s:%s", channelName, mspid, l.getHost(), l.getPort()));
logger.trace(format("Channel: %s peer: %s discovered orderer MSPID: %s, endpoint: %s:%s", channelName, serviceDiscoveryPeer, mspid, l.getHost(), l.getPort()));
String endpoint = (l.getHost() + ":" + l.getPort()).trim().toLowerCase();

SDOrderer discoveredAlready = ordererEndpoints.get(endpoint);
if (discoveredAlready != null) {
if (!mspid.equals(discoveredAlready.getMspid())) {
logger.error(format("Service discovery in channel: %s, peer: %s found Orderer endpoint: %s with two mspids: '%s', '%s'", channelName, serviceDiscoveryPeer, endpoint, mspid, discoveredAlready.getMspid()));
continue; // report it and ignore.
}
logger.debug(format("Service discovery in channel: %s, peer: %s found Orderer endpoint: %s mspid: %s discovered twice", channelName, serviceDiscoveryPeer, endpoint, mspid));
continue;
}

final SDOrderer sdOrderer = new SDOrderer(mspid, endpoint, lsdNetwork.getTlsCerts(mspid), lsdNetwork.getTlsIntermediateCerts(mspid));

ordererEndpoints.put(sdOrderer.getEndPoint(), sdOrderer);
Expand All @@ -322,12 +349,24 @@ SDNetwork networkDiscovery(TransactionContext ltransactionContext, boolean force

for (Map.Entry<String, Protocol.Peers> peers : membership.getPeersByOrgMap().entrySet()) {
final String mspId = peers.getKey();
Protocol.Peers peer = peers.getValue();
final Protocol.Peers peer = peers.getValue();

for (Protocol.Peer pp : peer.getPeersList()) {

SDEndorser ppp = new SDEndorser(pp, lsdNetwork.getTlsCerts(mspId), lsdNetwork.getTlsIntermediateCerts(mspId));
logger.trace(format("Channel %s discovered peer MSPID: %s, endpoint: %s", channelName, mspId, ppp.getEndpoint()));

SDEndorser discoveredAlready = lsdNetwork.endorsers.get(ppp.getEndpoint());
if (null != discoveredAlready) {
if (!mspId.equals(discoveredAlready.getMspid())) {
logger.error(format("Service discovery in channel: %s, peer: %s, found endorser endpoint: %s with two mspids: '%s', '%s'", channelName, serviceDiscoveryPeer, ppp.getEndpoint(), mspId, discoveredAlready.getMspid()));
continue; // report it and ignore.
}
logger.debug(format("Service discovery in channel %s peer: %s found Endorser endpoint: %s mspid: %s discovered twice", channelName, serviceDiscoveryPeer, ppp.getEndpoint(), mspId));
continue;
}

logger.trace(format("Channel %s peer: %s discovered peer mspid group: %s, endpoint: %s, mspid: %s", channelName, serviceDiscoveryPeer, mspId, ppp.getEndpoint(), ppp.getMspid()));

lsdNetwork.endorsers.put(ppp.getEndpoint(), ppp);

}
Expand Down

0 comments on commit a8ef7ce

Please sign in to comment.