/** * Get the channel names found. * * @return A set of the channel names found in the configuration file or empty set if none found. */ public Set<String> getChannelNames() { Set<String> ret = Collections.EMPTY_SET; JsonObject channels = getJsonObject(jsonConfig, "channels"); if (channels != null) { final Set<String> channelNames = channels.keySet(); if (channelNames != null && !channelNames.isEmpty()) { ret = new HashSet<>(channelNames); } } return ret; }
private static Properties extractProperties(JsonObject json, String fieldName) { Properties props = new Properties(); // Extract any other grpc options JsonObject options = getJsonObject(json, fieldName); if (options != null) { for (Entry<String, JsonValue> entry : options.entrySet()) { String key = entry.getKey(); JsonValue value = entry.getValue(); props.setProperty(key, getJsonValue(value)); } } return props; }
private Map<String, JsonObject> findCertificateAuthorities() throws NetworkConfigurationException { Map<String, JsonObject> ret = new HashMap<>(); JsonObject jsonCertificateAuthorities = getJsonObject(jsonConfig, "certificateAuthorities"); if (null != jsonCertificateAuthorities) { for (Entry<String, JsonValue> entry : jsonCertificateAuthorities.entrySet()) { String name = entry.getKey(); JsonObject jsonCA = getJsonValueAsObject(entry.getValue()); if (jsonCA == null) { throw new NetworkConfigurationException(format("Error loading config. Invalid CA entry: %s", name)); } ret.put(name, jsonCA); } } return ret; }
private void getTLSCerts(String nodeName, JsonObject jsonOrderer, Properties props) { JsonObject jsonTlsCaCerts = getJsonObject(jsonOrderer, "tlsCACerts"); if (jsonTlsCaCerts != null) { String pemFilename = getJsonValueAsString(jsonTlsCaCerts.get("path")); String pemBytes = getJsonValueAsString(jsonTlsCaCerts.get("pem")); if (pemFilename != null) { // let the sdk handle non existing errors could be they don't exist during parsing but are there later. props.put("pemFile", pemFilename); } if (pemBytes != null) { props.put("pemBytes", pemBytes.getBytes()); } } }
private void createAllOrganizations(Map<String, JsonObject> foundCertificateAuthorities) throws NetworkConfigurationException { // Sanity check if (organizations != null) { throw new NetworkConfigurationException("INTERNAL ERROR: organizations has already been initialized!"); } organizations = new HashMap<>(); // organizations is a JSON object containing a nested object for each Org JsonObject jsonOrganizations = getJsonObject(jsonConfig, "organizations"); if (jsonOrganizations != null) { for (Entry<String, JsonValue> entry : jsonOrganizations.entrySet()) { String orgName = entry.getKey(); JsonObject jsonOrg = getJsonValueAsObject(entry.getValue()); if (jsonOrg == null) { throw new NetworkConfigurationException(format("Error loading config. Invalid Organization entry: %s", orgName)); } OrgInfo org = createOrg(orgName, jsonOrg, foundCertificateAuthorities); organizations.put(orgName, org); } } }
JsonObject channels = getJsonObject(jsonConfig, "channels"); JsonObject jsonChannel = getJsonObject(channels, channelName); if (jsonChannel != null) { channel = client.getChannel(channelName);
private void createAllOrderers() throws NetworkConfigurationException { // Sanity check if (orderers != null) { throw new NetworkConfigurationException("INTERNAL ERROR: orderers has already been initialized!"); } orderers = new HashMap<>(); // orderers is a JSON object containing a nested object for each orderers JsonObject jsonOrderers = getJsonObject(jsonConfig, "orderers"); if (jsonOrderers != null) { for (Entry<String, JsonValue> entry : jsonOrderers.entrySet()) { String ordererName = entry.getKey(); JsonObject jsonOrderer = getJsonValueAsObject(entry.getValue()); if (jsonOrderer == null) { throw new NetworkConfigurationException(format("Error loading config. Invalid orderer entry: %s", ordererName)); } Node orderer = createNode(ordererName, jsonOrderer, "url"); if (orderer == null) { throw new NetworkConfigurationException(format("Error loading config. Invalid orderer entry: %s", ordererName)); } orderers.put(ordererName, orderer); } } }
JsonObject jsonPeers = getJsonObject(jsonConfig, "peers");
JsonObject jsonPeers = getJsonObject(jsonChannel, "peers"); boolean foundPeer = false;
private NetworkConfig(JsonObject jsonConfig) throws InvalidArgumentException, NetworkConfigurationException { this.jsonConfig = jsonConfig; // Extract the main details String configName = getJsonValueAsString(jsonConfig.get("name")); if (configName == null || configName.isEmpty()) { throw new InvalidArgumentException("Network config must have a name"); } String configVersion = getJsonValueAsString(jsonConfig.get("version")); if (configVersion == null || configVersion.isEmpty()) { throw new InvalidArgumentException("Network config must have a version"); // TODO: Validate the version } // Preload and create all peers, orderers, etc createAllPeers(); createAllOrderers(); Map<String, JsonObject> foundCertificateAuthorities = findCertificateAuthorities(); //createAllCertificateAuthorities(); createAllOrganizations(foundCertificateAuthorities); // Validate the organization for this client JsonObject jsonClient = getJsonObject(jsonConfig, "client"); String orgName = jsonClient == null ? null : getJsonValueAsString(jsonClient.get("organization")); if (orgName == null || orgName.isEmpty()) { throw new InvalidArgumentException("A client organization must be specified"); } clientOrganization = getOrganizationInfo(orgName); if (clientOrganization == null) { throw new InvalidArgumentException("Client organization " + orgName + " is not defined"); } }
/** * Get the channel names found. * * @return A set of the channel names found in the configuration file or empty set if none found. */ public Set<String> getChannelNames() { Set<String> ret = Collections.EMPTY_SET; JsonObject channels = getJsonObject(jsonConfig, "channels"); if (channels != null) { final Set<String> channelNames = channels.keySet(); if (channelNames != null && !channelNames.isEmpty()) { ret = new HashSet<>(channelNames); } } return ret; }
/** * Get the channel names found. * * @return A set of the channel names found in the configuration file or empty set if none found. */ public Set<String> getChannelNames() { Set<String> ret = Collections.EMPTY_SET; JsonObject channels = getJsonObject(jsonConfig, "channels"); if (channels != null) { final Set<String> channelNames = channels.keySet(); if (channelNames != null && !channelNames.isEmpty()) { ret = new HashSet<>(channelNames); } } return ret; }
private static Properties extractProperties(JsonObject json, String fieldName) { Properties props = new Properties(); // Extract any other grpc options JsonObject options = getJsonObject(json, fieldName); if (options != null) { for (Entry<String, JsonValue> entry : options.entrySet()) { String key = entry.getKey(); JsonValue value = entry.getValue(); props.setProperty(key, getJsonValue(value)); } } return props; }
private static Properties extractProperties(JsonObject json, String fieldName) { Properties props = new Properties(); // Extract any other grpc options JsonObject options = getJsonObject(json, fieldName); if (options != null) { for (Entry<String, JsonValue> entry : options.entrySet()) { String key = entry.getKey(); JsonValue value = entry.getValue(); props.setProperty(key, getJsonValue(value)); } } return props; }
private Map<String, JsonObject> findCertificateAuthorities() throws NetworkConfigurationException { Map<String, JsonObject> ret = new HashMap<>(); JsonObject jsonCertificateAuthorities = getJsonObject(jsonConfig, "certificateAuthorities"); if (null != jsonCertificateAuthorities) { for (Entry<String, JsonValue> entry : jsonCertificateAuthorities.entrySet()) { String name = entry.getKey(); JsonObject jsonCA = getJsonValueAsObject(entry.getValue()); if (jsonCA == null) { throw new NetworkConfigurationException(format("Error loading config. Invalid CA entry: %s", name)); } ret.put(name, jsonCA); } } return ret; }
private Map<String, JsonObject> findCertificateAuthorities() throws NetworkConfigurationException { Map<String, JsonObject> ret = new HashMap<>(); JsonObject jsonCertificateAuthorities = getJsonObject(jsonConfig, "certificateAuthorities"); if (null != jsonCertificateAuthorities) { for (Entry<String, JsonValue> entry : jsonCertificateAuthorities.entrySet()) { String name = entry.getKey(); JsonObject jsonCA = getJsonValueAsObject(entry.getValue()); if (jsonCA == null) { throw new NetworkConfigurationException(format("Error loading config. Invalid CA entry: %s", name)); } ret.put(name, jsonCA); } } return ret; }
private void getTLSCerts(String nodeName, JsonObject jsonOrderer, Properties props) { JsonObject jsonTlsCaCerts = getJsonObject(jsonOrderer, "tlsCACerts"); if (jsonTlsCaCerts != null) { String pemFilename = getJsonValueAsString(jsonTlsCaCerts.get("path")); String pemBytes = getJsonValueAsString(jsonTlsCaCerts.get("pem")); if (pemFilename != null) { // let the sdk handle non existing errors could be they don't exist during parsing but are there later. props.put("pemFile", pemFilename); } if (pemBytes != null) { props.put("pemBytes", pemBytes.getBytes()); } } }
private void getTLSCerts(String nodeName, JsonObject jsonOrderer, Properties props) { JsonObject jsonTlsCaCerts = getJsonObject(jsonOrderer, "tlsCACerts"); if (jsonTlsCaCerts != null) { String pemFilename = getJsonValueAsString(jsonTlsCaCerts.get("path")); String pemBytes = getJsonValueAsString(jsonTlsCaCerts.get("pem")); if (pemFilename != null) { // let the sdk handle non existing errors could be they don't exist during parsing but are there later. props.put("pemFile", pemFilename); } if (pemBytes != null) { props.put("pemBytes", pemBytes.getBytes()); } } }
private void createAllOrganizations(Map<String, JsonObject> foundCertificateAuthorities) throws NetworkConfigurationException { // Sanity check if (organizations != null) { throw new NetworkConfigurationException("INTERNAL ERROR: organizations has already been initialized!"); } organizations = new HashMap<>(); // organizations is a JSON object containing a nested object for each Org JsonObject jsonOrganizations = getJsonObject(jsonConfig, "organizations"); if (jsonOrganizations != null) { for (Entry<String, JsonValue> entry : jsonOrganizations.entrySet()) { String orgName = entry.getKey(); JsonObject jsonOrg = getJsonValueAsObject(entry.getValue()); if (jsonOrg == null) { throw new NetworkConfigurationException(format("Error loading config. Invalid Organization entry: %s", orgName)); } OrgInfo org = createOrg(orgName, jsonOrg, foundCertificateAuthorities); organizations.put(orgName, org); } } }
private void createAllOrganizations(Map<String, JsonObject> foundCertificateAuthorities) throws NetworkConfigurationException { // Sanity check if (organizations != null) { throw new NetworkConfigurationException("INTERNAL ERROR: organizations has already been initialized!"); } organizations = new HashMap<>(); // organizations is a JSON object containing a nested object for each Org JsonObject jsonOrganizations = getJsonObject(jsonConfig, "organizations"); if (jsonOrganizations != null) { for (Entry<String, JsonValue> entry : jsonOrganizations.entrySet()) { String orgName = entry.getKey(); JsonObject jsonOrg = getJsonValueAsObject(entry.getValue()); if (jsonOrg == null) { throw new NetworkConfigurationException(format("Error loading config. Invalid Organization entry: %s", orgName)); } OrgInfo org = createOrg(orgName, jsonOrg, foundCertificateAuthorities); organizations.put(orgName, org); } } }