private bool IsHealthCheckSuppressed(ServiceDiscoveryConfig config) { if (config.SuppressHealthCheckAfterServiceUnused.HasValue) { var serviceUnuseTime = DateTime.Now.Subtract(LastEndpointRequest); //If a service was unused for pre-defined time period, always treat it as healthy. if (serviceUnuseTime > config.SuppressHealthCheckAfterServiceUnused.Value) { return(true); } } return(false); }
private string BuildUri(IEndPointHandle endpoint, ServiceDiscoveryConfig config) { var useHttps = config.UseHttpsOverride ?? UseHttpsDefault; var urlTemplate = useHttps ? "https://{0}:{1}/" : "http://{0}:{1}/"; var port = endpoint.Port ?? DefaultPort ?? config.DefaultPort; if (port == null) { throw new ConfigurationException("Cannot access service. Service Port not configured. See tags to find missing configuration", unencrypted: new Tags { { "ServiceName", ServiceName }, { "Required configuration key", $"Discovery.{ServiceName}.DefaultPort" } }); } return(string.Format(urlTemplate, endpoint.HostName, port)); }
private Node CreateNode(string host, ServiceDiscoveryConfig config) { var parts = host.Split(':'); string hostName = parts[0]; if (parts.Length == 2 && ushort.TryParse(parts[1], out ushort port)) { return(new Node(hostName, port)); } else if (parts.Length == 1) { return(new Node(hostName, config.DefaultPort)); } else { throw Ex.IncorrectHostFormatInConfig(host, _serviceName); } }
private async Task <IServiceDiscoverySource> GetDiscoverySource(ServiceDeployment serviceDeployment, ServiceDiscoveryConfig config) { var source = _serviceDiscoveryLoader.GetDiscoverySource(serviceDeployment, config); await source.Init().ConfigureAwait(false); return(source); }
private int?GetEffectivePort(Node node, ServiceDiscoveryConfig config) { return(node.Port ?? DefaultPort ?? config.DefaultPort); }
private int?GetEffectivePort(IEndPointHandle endpoint, ServiceDiscoveryConfig config) { return(endpoint.Port ?? DefaultPort ?? config.DefaultPort); }
public IServiceDiscoverySource GetDiscoverySource(ServiceDeployment serviceDeployment, ServiceDiscoveryConfig serviceDiscoveryConfig) { return(new LocalDiscoverySource(serviceDeployment)); }
public IServiceDiscoverySource GetDiscoverySource(DeploymentIdentifier deploymentIdentifier, ServiceDiscoveryConfig serviceDiscoveryConfig) { var source = _getSources(deploymentIdentifier).FirstOrDefault(f => f.SourceName.Equals(serviceDiscoveryConfig.Source, StringComparison.InvariantCultureIgnoreCase)); if (source == null) { throw new ConfigurationException($"Discovery Source '{serviceDiscoveryConfig.Source}' is not supported."); } return(source); }
private async Task <ServiceDiscoverySourceBase> GetServiceDiscoverySource(ServiceDeployment serviceDeployment, ServiceDiscoveryConfig config) { var discoverySource = _discoverySourceLoader.GetDiscoverySource(serviceDeployment, config); // TODO: RemoteHostPool should either deal with uninitialized source or request different class which represents initialized source await discoverySource.InitCompleted.ConfigureAwait(false); return(discoverySource); }
private (HttpClient httpClient, bool isHttps, bool isNewCreated) GetHttpClient(ServiceDiscoveryConfig serviceConfig, DiscoveryConfig defaultConfig, bool tryHttps, string hostname, int basePort) { var forceHttps = serviceConfig.UseHttpsOverride ?? (ServiceInterfaceRequiresHttps || defaultConfig.UseHttpsOverride); var useHttps = tryHttps || forceHttps; string securityRole = serviceConfig.SecurityRole; var verificationMode = serviceConfig.ServerCertificateVerification ?? defaultConfig.ServerCertificateVerification; var supplyClientCertificate = (serviceConfig.ClientCertificateVerification ?? defaultConfig.ClientCertificateVerification) == ClientCertificateVerificationMode.VerifyIdenticalRootCertificate; var httpKey = new HttpClientConfiguration(useHttps, securityRole, serviceConfig.RequestTimeout, verificationMode, supplyClientCertificate); lock (HttpClientLock) { if (LastHttpClient != null && LastHttpClientKey.Equals(httpKey)) { return(httpClient : LastHttpClient, isHttps : useHttps, isNewCreated : false); } // In case we're trying HTTPs and the previous request on this instance was HTTP (or if this is the first request) if (Not(forceHttps) && httpKey.UseHttps && Not(LastHttpClientKey?.UseHttps ?? false)) { var now = DateTime.Now; if (now - _lastHttpsTestTime > _httpsTestInterval) { _lastHttpsTestTime = now; RunHttpsAvailabilityTest(httpKey, hostname, basePort); } httpKey = new HttpClientConfiguration( useHttps: false, securityRole: null, timeout: httpKey.Timeout, verificationMode: httpKey.VerificationMode, supplyClientCertificate: httpKey.SupplyClientCertificate); } var isNewCreated = false; if (!(LastHttpClientKey?.Equals(httpKey) ?? false)) { isNewCreated = true; var equalState = (LastHttpClientKey?.Equals(httpKey))?.ToString() ?? "FirstTime"; Log.Info(msg => msg($"DelayDebug : GetHttpClient created new HttpClient (isEqual={equalState})")); // we expect this not to be equal ever var messageHandler = _httpMessageHandlerFactory(httpKey); var httpClient = CreateHttpClient(messageHandler, httpKey.Timeout); LastHttpClient = httpClient; LastHttpClientKey = httpKey; _httpMessageHandler = messageHandler; } return(httpClient : LastHttpClient, isHttps : httpKey.UseHttps, isNewCreated : isNewCreated); } }
public ConfigDiscoverySource(string deploymentName, ServiceDiscoveryConfig serviceDiscoveryConfig, ILog log) : base(deploymentName) { _serviceDiscoveryConfig = serviceDiscoveryConfig; Log = log; EndPoints = GetEndPointsInitialValue(); }
public IServiceDiscoverySource GetDiscoverySource(DeploymentIdentifier deploymentIdentifier, ServiceDiscoveryConfig serviceDiscoveryConfig) { return(new LocalDiscoverySource(deploymentIdentifier)); }
public static string GetDeploymentName(DeploymentIdentifier deploymentIdentifier, ServiceDiscoveryConfig serviceDiscoverySettings) { if (serviceDiscoverySettings.Scope == ServiceScope.Zone) { return(deploymentIdentifier.ServiceName); } return(deploymentIdentifier.GetConsulServiceName()); }
public ServiceDiscoverySourceBase GetDiscoverySource(ServiceDeployment serviceDeployment, ServiceDiscoveryConfig serviceDiscoveryConfig) { return(new LocalDiscoverySource(serviceDeployment.ServiceName)); }
public ServiceDiscoverySourceBase GetDiscoverySource(ServiceDeployment serviceDeployment, ServiceDiscoveryConfig serviceDiscoverySettings) { switch (serviceDiscoverySettings.Source) { case DiscoverySource.Config: return(_getConfigDiscoverySource(serviceDeployment.ServiceName, serviceDiscoverySettings)); case DiscoverySource.Consul: return(_getConsulDiscoverySource(serviceDeployment, serviceDiscoverySettings)); case DiscoverySource.Local: return(new LocalDiscoverySource(serviceDeployment.ServiceName)); } throw new ConfigurationException($"Source '{serviceDiscoverySettings.Source}' is not supported by any configuration."); }