internal string GetHostname(NodesExt nodeExt, BucketConfig bucketConfig) { if (UseAlternateAddress) { var networkResolution = bucketConfig.NetworkResolution == Couchbase.NetworkResolution.Auto ? Couchbase.NetworkResolution.External : bucketConfig.NetworkResolution; var hostname = nodeExt.AlternateAddresses[networkResolution].Hostname; _mappedNodeInfo = $"NetworkResolution [{bucketConfig.NetworkResolution}] using alternate mapping {nodeExt.Hostname} to {hostname}."; return(hostname); } _mappedNodeInfo = $"NetworkResolution [{bucketConfig.NetworkResolution}] using default {nodeExt?.Hostname}"; return(nodeExt?.Hostname); }
public NodeAdapter(Node node, NodesExt nodeExt, BucketConfig bucketConfig) { var node1 = node; //Detect if we should be using alternate addresses for hostname UseAlternateAddress = UseAlternateNetwork(nodeExt, bucketConfig); // get hostname (uses alternate network hostname if configured) Hostname = GetHostname(node, nodeExt, bucketConfig); if (node != null) { CouchbaseApiBase = node.CouchApiBase.Replace("$HOST", Hostname); CouchbaseApiBaseHttps = node.CouchApiBaseHttps; } if (nodeExt != null) { // get services, will use alternate network ports if configured var services = GetServicePorts(nodeExt, bucketConfig); // if not using alternate network and node is null if (!UseAlternateNetwork(nodeExt, bucketConfig) && node == null && !bucketConfig.IsGlobal) { // if using nodeExt and node is null, the KV service may not be available yet and should be disabled (set to 0) // this prevents the server's data service being marked as active before it is ready // see https://issues.couchbase.com/browse/JVMCBC-564, https://issues.couchbase.com/browse/NCBC-1791 and // https://issues.couchbase.com/browse/NCBC-1808 for more details services.Kv = 0; services.KvSsl = 0; } ConfigureServicePorts(services); } else { if (node1 != null) { MgmtApiSsl = node1.Ports.HttpsMgmt; Moxi = node1.Ports.Proxy; KeyValue = node1.Ports.Direct; KeyValueSsl = node1.Ports.SslDirect; ViewsSsl = node1.Ports.HttpsCapi; } Views = new Uri(CouchbaseApiBase).Port; } }
internal Services GetServicePorts(NodesExt nodeExt, BucketConfig bucketConfig) { if (UseAlternateAddress) { var networkResolution = bucketConfig.NetworkResolution == Couchbase.NetworkResolution.Auto ? Couchbase.NetworkResolution.External : bucketConfig.NetworkResolution; var ports = nodeExt.AlternateAddresses[networkResolution].Ports; if (ports != null) { return(ports); } } return(nodeExt?.Services); }
private string GetHostname(Node node, NodesExt nodeExt, BucketConfig bucketConfig) { // try to use NodeExt hostname (uses alternate network if configured) var hostname = GetHostname(nodeExt, bucketConfig); // if hostname is invalid, use node's hostname if (string.IsNullOrWhiteSpace(hostname)) { hostname = node.Hostname; } if (hostname.Contains("$HOST")) { return("localhost"); } var parts = hostname.Split(':'); switch (parts.Length) { case 1: // hostname or IPv4 no port hostname = parts[0]; break; case 2: // hostname or IPv4 with port hostname = parts[0]; break; default: // IPv6 // is it [a:b:c:d]:<port> if (parts.First().StartsWith("[") && parts[parts.Length - 2].EndsWith("]")) { hostname = string.Join(":", parts.Take(parts.Length - 1)); } else { hostname = string.Join(":", parts); } break; } return(hostname); }
public void ResolveHostName() { for (var i = 0; i < VBucketServerMap.ServerList.Length; i++) { var nodeExt = NodesExt?.FirstOrDefault(x => x.Hostname != null && VBucketServerMap.ServerList[i].Contains(x.Hostname)); if (nodeExt != null && nodeExt.HasAlternateAddress) { var effectiveNetworkResolution = string.Compare(NetworkResolution, Couchbase.NetworkResolution.Auto, StringComparison.CurrentCultureIgnoreCase) == 0 ? Couchbase.NetworkResolution.External : NetworkResolution; //The SSL port is resolved later var alternateAddress = nodeExt.AlternateAddresses[effectiveNetworkResolution]; VBucketServerMap.ServerList[i] = alternateAddress.Hostname + ":" + alternateAddress.Ports.Kv; } } }
public override int GetHashCode() { unchecked { var hashCode = (int)Rev; hashCode = (hashCode * 397) ^ (Name != null ? Name.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (Uri != null ? Uri.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (StreamingUri != null ? StreamingUri.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (Nodes != null ? Nodes.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (NodesExt != null ? NodesExt.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (NodeLocator != null ? NodeLocator.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (Uuid != null ? Uuid.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (Ddocs != null ? Ddocs.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (VBucketServerMap != null ? VBucketServerMap.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (BucketCapabilitiesVer != null ? BucketCapabilitiesVer.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (BucketCapabilities != null ? BucketCapabilities.GetHashCode() : 0); return(hashCode); } }
internal bool UseAlternateNetwork(NodesExt nodeExt, BucketConfig bucketConfig) { // make sure we have at least an alternate network hostname (alternate ports are optional) if (nodeExt == null || !nodeExt.HasAlternateAddress || bucketConfig.NetworkResolution == NetworkResolution.Default) { return(false); } if (bucketConfig.NetworkResolution == NetworkResolution.Auto || bucketConfig.NetworkResolution == NetworkResolution.External) { return(string.Compare(nodeExt.Hostname, nodeExt.AlternateAddresses[Couchbase.NetworkResolution.External].Hostname, StringComparison.InvariantCultureIgnoreCase) != 0); } //It's a custom configuration being used - try it. if (nodeExt.AlternateAddresses.ContainsKey(bucketConfig.NetworkResolution)) { return(true); } throw new CouchbaseException($"Cannot resolve NetworkResolution - {bucketConfig.NetworkResolution}"); }
internal bool UseAlternateNetwork(NodesExt nodeExt, BucketConfig bucketConfig) { // make sure we have at least an alternate network hostname (alternate ports are optional) if (string.IsNullOrWhiteSpace(nodeExt?.AlternateAddresses?.External?.Hostname)) { return(false); } switch (bucketConfig.NetworkType) { case NetworkTypes.Auto: // use alternate network if bucket config and nodeExt's hostname don't match return(string.Compare(nodeExt.Hostname, bucketConfig.SurrogateHost, StringComparison.Ordinal) != 0); case NetworkTypes.External: case NetworkTypes.Default: return(true); default: return(false); } }
public static bool SupportsKeyValue(this NodesExt nodesExt) { return(nodesExt.Services?.Kv > 0 || nodesExt.Services?.KvSsl > 0); }
public static int GetKeyValuePort(this NodesExt nodesExt, ClusterOptions clusterOptions) { return(clusterOptions.EnableTls ? nodesExt.Services.KvSsl : nodesExt.Services.Kv); }
public static string GetHostName(this NodesExt nodesExt) { //TODO add support using AlternateAddress hostname return(nodesExt.Hostname.Contains("$HOST") ? "localhost" : nodesExt.Hostname); }
public static bool SupportsQuery(this NodesExt nodesExt) { return(nodesExt.Services?.N1Ql > 0 || nodesExt.Services?.N1QlSsl > 0); }
public static bool SupportsAnalytics(this NodesExt nodesExt) { return(nodesExt.Services?.Cbas > 0 || nodesExt.Services?.CbasSsl > 0); }
public static bool SupportsSearch(this NodesExt nodesExt) { return(nodesExt.Services?.Fts > 0 || nodesExt.Services?.FtsSsl > 0); }
public static int GetKeyValuePort(this NodesExt nodesExt, Couchbase.Configuration configuration) { return(configuration.UseSsl ? nodesExt.Services.KvSsl : nodesExt.Services.Kv); }
public static string GetHostName(this NodesExt nodesExt) { //TODO add support using AlternateAddress hostname return(nodesExt.Hostname.Contains(ConstantsString.HostPlaceHolder) ? "localhost" : nodesExt.Hostname); }