public override Exception AllEndpointsUnreachable(EndPointsResult endPointsResult, Exception lastException, string lastExceptionEndPoint, string unreachableHosts)
 {
     if (endPointsResult.EndPoints.Length == 0)
     {
         return(new EnvironmentException("No endpoint were specified in the configuration for the " +
                                         "requested service. Please make sure you've specified a list of hosts for the requested " +
                                         "service in the configuration. If you're a developer and want to access a service on your " +
                                         "local machine, change service configuration to Discovery.[ServiceName].Mode=\"Local\". " +
                                         "See tags for the name of the service requested, and for the " +
                                         "configuration path where the list of endpoints are expected to be specified.",
                                         unencrypted: new Tags
         {
             { "requestedService", Deployment },
             { "missingConfigPath", $"Discovery.{Deployment}.Hosts" }
         }));
     }
     else
     {
         return(new ServiceUnreachableException("All endpoints defined by the configuration for the requested service are unreachable. " +
                                                "Please make sure the remote hosts specified in the configuration are correct and are " +
                                                "functioning properly. See tags for the name of the requested service, the list of hosts " +
                                                "that are unreachable, and the configuration path they were loaded from. See the inner " +
                                                "exception for one of the causes a remote host was declared unreachable.",
                                                lastException,
                                                unencrypted: new Tags
         {
             { "unreachableHosts", unreachableHosts },
             { "configPath", $"Discovery.{Deployment}.Hosts" },
             { "requestedService", Deployment },
             { "innerExceptionIsForEndPoint", lastExceptionEndPoint }
         }));
     }
 }
예제 #2
0
 public LocalDiscoverySource(DeploymentIdentifier deploymentIdentifier) : base($"{CurrentApplicationInfo.HostName}-{deploymentIdentifier.ServiceName}")
 {
     Result = new EndPointsResult {
         EndPoints = new[] { new EndPoint {
                                 HostName = CurrentApplicationInfo.HostName
                             } }
     };
 }
 public ConfigDiscoverySource(DeploymentIdentifier deployment, Func <DiscoveryConfig> getConfig, ILog log) : base(deployment.ServiceName)
 {
     _serviceDiscoveryConfig = getConfig().Services[deployment.ServiceName];
     Log    = log;
     Result = new EndPointsResult {
         EndPoints = GetEndPointsInitialValue()
     };
 }
예제 #4
0
 public override Exception AllEndpointsUnreachable(EndPointsResult endPointsResult, Exception lastException, string lastExceptionEndPoint, string unreachableHosts)
 {
     return(new ServiceUnreachableException("Service source is configured to 'Local' Discovery mode, but is not reachable on local machine. See tags for more details.",
                                            lastException,
                                            unencrypted: new Tags
     {
         { "unreachableHosts", unreachableHosts },
         { "configPath", $"Discovery.{Deployment}.Source" },
         { "requestedService", Deployment },
         { "innerExceptionIsForEndPoint", lastExceptionEndPoint }
     }));
 }
예제 #5
0
        public override Exception AllEndpointsUnreachable(EndPointsResult endPointsResult, Exception lastException, string lastExceptionEndPoint, string unreachableHosts)
        {
            if (endPointsResult.EndPoints.Length == 0)
            {
                var tags = new Tags
                {
                    { "requestedService", Deployment },
                    { "consulAddress", ConsulClient?.ConsulAddress?.ToString() },
                    { "requestTime", endPointsResult.RequestDateTime.ToString("yyyy-MM-dd HH:mm:ss.fff") },
                    { "requestLog", endPointsResult.RequestLog },
                    { "responseLog", endPointsResult.ResponseLog },
                    { "queryDefined", endPointsResult.IsQueryDefined.ToString() },
                    { "consulError", endPointsResult.Error?.ToString() },
                    { "activeVersion", endPointsResult.ActiveVersion }
                };

                if (_lastResult == null)
                {
                    return(new ProgrammaticException("Response not arrived from Consul. " +
                                                     "This should not happen, ConsulDiscoverySource should await until a result is returned from Consul.", unencrypted: tags));
                }

                else if (endPointsResult.Error != null)
                {
                    return(new EnvironmentException("Error calling Consul. See tags for details.", unencrypted: tags));
                }
                else if (endPointsResult.IsQueryDefined == false)
                {
                    return(new ServiceUnreachableException("Service doesn't exist on Consul. See tags for details.", unencrypted: tags));
                }
                else
                {
                    return(new EnvironmentException("No endpoint were specified in Consul for the requested service and service's active version.", unencrypted: tags));
                }
            }
            else
            {
                return(new ServiceUnreachableException("All endpoints defined by Consul for the requested service are unreachable. " +
                                                       "Please make sure the endpoints on Consul are correct and are functioning properly. " +
                                                       "See tags for the name of the requested service, and address of consul from which they were loaded. " +
                                                       "exception for one of the causes a remote host was declared unreachable.",
                                                       lastException,
                                                       unencrypted: new Tags
                {
                    { "consulAddress", ConsulClient.ConsulAddress.ToString() },
                    { "unreachableHosts", unreachableHosts },
                    { "requestedService", Deployment },
                    { "innerExceptionIsForEndPoint", lastExceptionEndPoint }
                }));
            }
        }
예제 #6
0
        private void ConsulResultChanged(EndPointsResult newResult)
        {
            lock (_resultLocker)
            {
                var shouldReportChanges = false;
                if (newResult.IsQueryDefined != Result.IsQueryDefined && !_firstTime)
                {
                    shouldReportChanges = true;
                    if (newResult.IsQueryDefined == false)
                    {
                        _log.Warn(x => x("Service has become undefined on Consul", unencryptedTags: new { serviceName = Deployment }));
                    }
                    else
                    {
                        _log.Info(x => x("Service has become defined on Consul", unencryptedTags: new { serviceName = Deployment }));
                    }
                }
                else if (!OrderedEndpoints(newResult.EndPoints).SequenceEqual(OrderedEndpoints(Result.EndPoints)))
                {
                    shouldReportChanges = true;
                    _log.Info(_ => _("Obtained a new list of endpoints for service from Consul", unencryptedTags: new
                    {
                        serviceName = Deployment,
                        endpoints   = string.Join(", ", newResult.EndPoints.Select(e => e.HostName + ':' + (e.Port?.ToString() ?? "")))
                    }));
                }

                if (_firstTime || newResult.Error == null || Result.Error != null)
                {
                    Result = newResult;
                }

                if (shouldReportChanges && !_firstTime)
                {
                    EndpointsChangedBroadcast.Post(Result);
                }

                _lastResult = newResult;
                _firstTime  = false;
            }
            _firstResultInitialized.TrySetResult(true);
        }
 public abstract Exception AllEndpointsUnreachable(
     EndPointsResult endPointsResult, Exception lastException, string lastExceptionEndPoint, string unreachableHosts);