mirror of https://github.com/dotnet/tye.git
Browse Source
* Random cleanup - Remove fully qualified namespaces - Deleted some unused types - Move types to infrastructure - Move path normalization to ApplicationFactory layer - Renamed IngressService to HttpProxyServicepull/209/head
committed by
GitHub
18 changed files with 209 additions and 243 deletions
@ -1,36 +0,0 @@ |
|||
// Licensed to the .NET Foundation under one or more agreements.
|
|||
// The .NET Foundation licenses this file to you under the MIT license.
|
|||
// See the LICENSE file in the project root for more information.
|
|||
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
|
|||
namespace Microsoft.Tye |
|||
{ |
|||
public sealed class Service |
|||
{ |
|||
public Service(string name) |
|||
{ |
|||
if (name is null) |
|||
{ |
|||
throw new ArgumentNullException(nameof(name)); |
|||
} |
|||
|
|||
Name = name; |
|||
} |
|||
|
|||
public string Name { get; } |
|||
|
|||
public GeneratedAssets GeneratedAssets { get; } = new GeneratedAssets(); |
|||
|
|||
public Source? Source { get; set; } |
|||
|
|||
public Dictionary<string, object> Environment { get; set; } = new Dictionary<string, object>(); |
|||
|
|||
// Represents bindings *published* by this service
|
|||
// See GeneratedAssets for bindings consumed by the service
|
|||
public List<ServiceBinding> Bindings { get; } = new List<ServiceBinding>(); |
|||
|
|||
public int Replicas { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,67 @@ |
|||
// Licensed to the .NET Foundation under one or more agreements.
|
|||
// The .NET Foundation licenses this file to you under the MIT license.
|
|||
// See the LICENSE file in the project root for more information.
|
|||
|
|||
using System; |
|||
using System.Net; |
|||
using System.Net.Http; |
|||
using System.Net.Sockets; |
|||
using System.Runtime.ExceptionServices; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace Microsoft.Tye.Hosting |
|||
{ |
|||
internal class ConnectionRetryHandler : DelegatingHandler |
|||
{ |
|||
private static readonly int MaxRetries = 3; |
|||
private static readonly TimeSpan InitialRetryDelay = TimeSpan.FromMilliseconds(1000); |
|||
|
|||
public ConnectionRetryHandler(HttpMessageHandler innerHandler) |
|||
: base(innerHandler) |
|||
{ |
|||
} |
|||
|
|||
protected override async Task<HttpResponseMessage> SendAsync( |
|||
HttpRequestMessage request, |
|||
CancellationToken cancellationToken) |
|||
{ |
|||
HttpResponseMessage? response = null; |
|||
var delay = InitialRetryDelay; |
|||
Exception? exception = null; |
|||
|
|||
for (var i = 0; i < MaxRetries; i++) |
|||
{ |
|||
try |
|||
{ |
|||
response = await base.SendAsync(request, cancellationToken); |
|||
} |
|||
catch (HttpRequestException ex) when (ex.InnerException is SocketException) |
|||
{ |
|||
if (i == MaxRetries - 1) |
|||
{ |
|||
throw; |
|||
} |
|||
|
|||
exception = ex; |
|||
} |
|||
|
|||
if (response != null && |
|||
(response.IsSuccessStatusCode || response.StatusCode != HttpStatusCode.ServiceUnavailable)) |
|||
{ |
|||
return response; |
|||
} |
|||
|
|||
await Task.Delay(delay, cancellationToken); |
|||
delay *= 2; |
|||
} |
|||
|
|||
if (exception != null) |
|||
{ |
|||
ExceptionDispatchInfo.Throw(exception); |
|||
} |
|||
|
|||
throw new TimeoutException(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,61 @@ |
|||
// Licensed to the .NET Foundation under one or more agreements.
|
|||
// The .NET Foundation licenses this file to you under the MIT license.
|
|||
// See the LICENSE file in the project root for more information.
|
|||
|
|||
using System; |
|||
using System.Reactive.Subjects; |
|||
using Microsoft.Extensions.Logging; |
|||
|
|||
namespace Microsoft.Tye.Hosting |
|||
{ |
|||
internal class ServiceLoggerProvider : ILoggerProvider |
|||
{ |
|||
private readonly Subject<string> _logs; |
|||
|
|||
public ServiceLoggerProvider(Subject<string> logs) |
|||
{ |
|||
_logs = logs; |
|||
} |
|||
|
|||
public ILogger CreateLogger(string categoryName) |
|||
{ |
|||
return new ServiceLogger(categoryName, _logs); |
|||
} |
|||
|
|||
public void Dispose() |
|||
{ |
|||
} |
|||
|
|||
private class ServiceLogger : ILogger |
|||
{ |
|||
private readonly string _categoryName; |
|||
private readonly Subject<string> _logs; |
|||
|
|||
public ServiceLogger(string categoryName, Subject<string> logs) |
|||
{ |
|||
_categoryName = categoryName; |
|||
_logs = logs; |
|||
} |
|||
|
|||
public IDisposable? BeginScope<TState>(TState state) |
|||
{ |
|||
return null; |
|||
} |
|||
|
|||
public bool IsEnabled(LogLevel logLevel) |
|||
{ |
|||
return true; |
|||
} |
|||
|
|||
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter) |
|||
{ |
|||
_logs.OnNext($"[{logLevel}]: {formatter(state, exception)}"); |
|||
|
|||
if (exception != null) |
|||
{ |
|||
_logs.OnNext(exception.ToString()); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -1,15 +0,0 @@ |
|||
// Licensed to the .NET Foundation under one or more agreements.
|
|||
// The .NET Foundation licenses this file to you under the MIT license.
|
|||
// See the LICENSE file in the project root for more information.
|
|||
|
|||
using System.Collections.Generic; |
|||
|
|||
namespace Microsoft.Tye.Hosting.Model |
|||
{ |
|||
public class PortMapping |
|||
{ |
|||
public int ExternalPort { get; set; } |
|||
|
|||
public List<int> InternalPorts { get; set; } = new List<int>(); |
|||
} |
|||
} |
|||
@ -1,14 +0,0 @@ |
|||
// Licensed to the .NET Foundation under one or more agreements.
|
|||
// The .NET Foundation licenses this file to you under the MIT license.
|
|||
// See the LICENSE file in the project root for more information.
|
|||
|
|||
namespace Microsoft.Tye.Hosting.Model |
|||
{ |
|||
public enum ServiceState |
|||
{ |
|||
Starting, |
|||
Running, |
|||
NotRunning, |
|||
Stopped |
|||
} |
|||
} |
|||
Loading…
Reference in new issue