2 using System.Collections;
3 using System.Collections.Generic;
5 using System.Text.RegularExpressions;
22 private readonly List<Uri?> _urls;
32 public Regex?
IpRegex {
get;
private set; }
42 public int Count => _urls.Count;
48 public Uri?
this[
int index] => index >= 0 && index < _urls.Count ? _urls[index] :
null;
60 _urls =
new List<Uri?>();
102 _urls =
new List<Uri?>();
108 throw new ArgumentNullException(nameof(db));
127 if (!is_multi_head_ingest_enabled)
135 if (system_properties.TryGetValue(
"conf.worker_http_server_urls", out
string? worker_urls_str) && !
string.IsNullOrEmpty(worker_urls_str))
137 ParseWorkerUrls(worker_urls_str);
142 ParseWorkerIpsAndPorts(system_properties, db);
146 if (_urls.Count == 0)
158 foreach (var url
in urls)
160 workerList._urls.Add(url);
179 if (
string.IsNullOrEmpty(ip_prefix))
183 var regex =
new Regex(
"^" + Regex.Escape(ip_prefix) +
".*");
192 private void ParseWorkerUrls(
string worker_urls_str)
194 string[] worker_url_lists = worker_urls_str.Split(
';');
197 for (
int i = 1; i < worker_url_lists.Length; ++i)
199 string url_list = worker_url_lists[i];
202 if (
string.IsNullOrEmpty(url_list))
209 string[] urls = url_list.Split(
',');
211 bool matching_url_found =
false;
214 foreach (
string url_str
in urls)
222 var tempUri =
new Uri(url_str);
223 matching_url_found =
IpRegex.IsMatch(tempUri.Host);
228 matching_url_found =
true;
231 if (matching_url_found)
233 Uri url =
new Uri(url_str);
244 if (!matching_url_found)
253 private void ParseWorkerIpsAndPorts(IDictionary<string, string> system_properties,
Kinetica db)
262 string[] worker_ip_lists = worker_ips_str.Split(
';');
263 string[] worker_ports = worker_ports_str.Split(
';');
266 if (worker_ip_lists.Length != worker_ports.Length)
273 string scheme = db.
URL.Scheme;
276 for (
int i = 1; i < worker_ip_lists.Length; ++i)
278 string ip_list = worker_ip_lists[i];
281 if (
string.IsNullOrEmpty(ip_list))
288 string[] ips = ip_list.Split(
',');
290 bool matching_ip_found =
false;
293 foreach (
string ip
in ips)
299 matching_ip_found =
IpRegex.IsMatch(ip);
301 matching_ip_found =
true;
303 if (matching_ip_found)
305 UriBuilder uri_builder =
new UriBuilder(scheme, ip,
int.Parse(worker_ports[i]));
306 Uri url = uri_builder.Uri;
313 throw new KineticaException($
"Error creating URL for worker #{i}: {ex.Message}");
317 if (!matching_ip_found)
363 return _urls.Where(u => u !=
null).Cast<Uri>();
379 .Where(u => u !=
null)
380 .Select(u => u!.ToString())
390 public Uri?
Get(
int index)
392 return index >= 0 && index < _urls.Count ? _urls[index] :
null;
403 return _urls.GetEnumerator();
406 IEnumerator IEnumerable.GetEnumerator()
void AddOrNull(Uri? url)
Adds a URL or null (for removed rank) to the worker list.
void Add(Uri url)
Adds a URL to the worker list.
A set of string constants for the parameter property_map.
A set of results returned by Kinetica.showSystemProperties.
IEnumerable< Uri > GetActiveUrlsEnumerator()
Returns an enumerator that iterates through only active (non-null) worker URLs.
A list of worker URLs to use for multi-head operations.
HAFailoverManager? HAManager
Gets the HA failover manager instance.
WorkerList()
Creates an empty WorkerList that can be populated manually with worker URLs to support multi-head ope...
bool IsMultiHeadEnabled
Whether multi-head I/O is enabled on the server.
bool IsEmpty
Returns whether the worker list is empty.
bool DisableAutoDiscovery
Whether auto-discovery is disabled
static WorkerList FromUrls(IEnumerable< Uri > urls)
Creates a WorkerList from explicit URLs.
WorkerList(Kinetica db, Regex? ip_regex)
Creates a WorkerList and automatically populates it with the worker URLs from Kinetica to support mul...
const string TRUE
Indicates that the system is configured for multi-head ingestion.
IEnumerable< Uri > GetActiveUrls()
Gets all active (non-null) URLs in the worker list.
ShowSystemPropertiesResponse showSystemProperties(ShowSystemPropertiesRequest request_)
Returns server configuration and version related information to the caller.
int ActiveCount
Gets the number of active (non-null) workers in the list.
Regex? IpRegex
The IP regex used to filter worker URLs, if one was specified.
const string CONF_WORKER_HTTP_SERVER_IPS
Semicolon (';') separated string of IP addresses of all the ingestion-enabled worker heads of the sys...
int Count
Gets the number of workers in the list (including removed ranks).
void Clear()
Clears all URLs from the worker list.
List< string > ToUrlStrings()
Converts the worker list to a list of URL strings.
IDictionary< string, string > property_map
A map of server configuration parameters and version information.
const string CONF_WORKER_HTTP_SERVER_PORTS
Semicolon (';') separated string of the port numbers of all the ingestion-enabled worker ranks of the...
bool IsQueriedUrlList
Whether this worker list was created by querying the server.
Uri? Get(int index)
Gets the URL at the specified index, or null if the rank was removed or index is out of bounds.
IEnumerator< Uri?> GetEnumerator()
Returns an enumerator that iterates through the worker URLs.
const string CONF_ENABLE_WORKER_HTTP_SERVERS
Boolean value indicating whether the system is configured for multi-head ingestion.
Uri URL
URL for Kinetica Server (including "http:" and port)
static WorkerList WithIpPrefix(Kinetica db, string? ip_prefix)
Creates a WorkerList and automatically populates it with the worker URLs from Kinetica,...