* Sets the information for the host used by the control connection. * @param {Boolean} initializing * @param {Connection} c * @param {Boolean} setCurrentHost Determines if the host retrieved must be set as the current host * @param result
(initializing, setCurrentHost, c, result)
| 732 | * @param result |
| 733 | */ |
| 734 | _setLocalInfo(initializing, setCurrentHost, c, result) { |
| 735 | if (!result || !result.rows || !result.rows.length) { |
| 736 | this.log('warning', 'No local info could be obtained'); |
| 737 | return; |
| 738 | } |
| 739 | |
| 740 | const row = result.rows[0]; |
| 741 | |
| 742 | let localHost; |
| 743 | |
| 744 | // Note that with SNI enabled, we can trust that rpc_address will contain a valid value. |
| 745 | const endpoint = !this.options.sni |
| 746 | ? c.endpoint |
| 747 | : `${row['rpc_address']}:${this.options.protocolOptions.port}`; |
| 748 | |
| 749 | if (initializing) { |
| 750 | localHost = new Host(endpoint, this.protocolVersion, this.options, this.metadata); |
| 751 | this.hosts.set(endpoint, localHost); |
| 752 | this.log('info', `Adding host ${endpoint}`); |
| 753 | } else { |
| 754 | localHost = this.hosts.get(endpoint); |
| 755 | |
| 756 | if (!localHost) { |
| 757 | this.log('error', 'Localhost could not be found'); |
| 758 | return; |
| 759 | } |
| 760 | } |
| 761 | |
| 762 | localHost.datacenter = row['data_center']; |
| 763 | localHost.rack = row['rack']; |
| 764 | localHost.tokens = row['tokens']; |
| 765 | localHost.hostId = row['host_id']; |
| 766 | localHost.cassandraVersion = row['release_version']; |
| 767 | setDseParameters(localHost, row); |
| 768 | this.metadata.setPartitioner(row['partitioner']); |
| 769 | this.log('info', 'Local info retrieved'); |
| 770 | |
| 771 | if (setCurrentHost) { |
| 772 | // Set the host as the one being used by the ControlConnection. |
| 773 | this.host = localHost; |
| 774 | } |
| 775 | } |
| 776 | |
| 777 | /** |
| 778 | * @param {Boolean} initializing Determines whether this function was called in order to initialize the control |
no test coverage detected