Exemplo n.º 1
0
 private static void HandleIfError(IResult result, StatusCode statusCode, IAlleyLogger logger)
 {
     if (result.IsFailure)
     {
         logger.Error(result.Message);
         throw new RpcException(new Status(statusCode, result.Message));
     }
 }
Exemplo n.º 2
0
        public virtual async Task <MetricsSummary> Fetch()
        {
            try
            {
                var result = await _httpClient.GetStringAsync(_query);

                return(JsonConvert.DeserializeObject <MetricsSummary>(result));
            }
            catch (Exception e)
            {
                _logger.Error(e.Message);
                throw;
            }
        }
Exemplo n.º 3
0
 private async Task RunAsync()
 {
     while (true)
     {
         try
         {
             var healthTask  = _healthRegistration.Start();
             var metricsTask = _metricsRegistration.Start();
             await Task.WhenAny(healthTask, metricsTask);
         }
         catch (Exception e)
         {
             _logger.Error(Messages.MonitoringCrashed(e.Message));
         }
     }
 }
Exemplo n.º 4
0
        public IResult RegisterMicroservice(string microserviceName, IEnumerable <string> servicesNames)
        {
            if (string.IsNullOrEmpty(microserviceName) || string.IsNullOrWhiteSpace(microserviceName))
            {
                var failureMessage = Messages.MicroserviceNameCanNotBeNullOrEmptyOrWhitespace();
                _logger.Error(failureMessage);
                return(Result.Failure(failureMessage));
            }

            if (servicesNames == null || !servicesNames.Any())
            {
                var failureMessage = Messages.CanNotRegisterMicroserviceWithoutServices(microserviceName);
                _logger.Error(failureMessage);
                return(Result.Failure(failureMessage));
            }

            var microservice = new Microservice(microserviceName, servicesNames);

            if (!_microservices.TryAdd(microserviceName, microservice))
            {
                var failureMessage = Messages.MicroserviceHasBeenAlreadyRegisteredMessage(microserviceName);
                _logger.Error(failureMessage);
                return(Result.Failure(failureMessage));
            }

            var message = servicesNames
                          .Where(serviceName => !_servicesOwners.TryAdd(serviceName, microservice))
                          .Aggregate(string.Empty, (current, serviceName) =>
                                     current + Messages.ServiceHasBeenAlreadyRegisteredMessage(serviceName));

            var result = string.IsNullOrEmpty(message) ?
                         Result.Success(Messages.MicroserviceHasBeenRegistered(microserviceName)) :
                         Result.Failure(message);

            _logger.LogResult(result);

            return(result);
        }