@@ -1,7 +1,6 @@ | |||
using System; | |||
using DotNetCore.CAP; | |||
using DotNetCore.CAP.Dashboard.GatewayProxy.Request.Middleware; | |||
using DotNetCore.CAP.Dashboard.GatewayProxy.Requester.Middleware; | |||
using DotNetCore.CAP.Dashboard.GatewayProxy; | |||
using Microsoft.AspNetCore.Http; | |||
using Microsoft.Extensions.DependencyInjection; | |||
@@ -53,10 +52,8 @@ namespace Microsoft.AspNetCore.Builder | |||
app.Map(new PathString(pathMatch), x => | |||
{ | |||
x.UseDownstreamRequestInitialiser(); | |||
x.UseHttpRequestBuilderMiddleware(); | |||
x.UseHttpRequesterMiddleware(); | |||
x.UseMiddleware<DashboardMiddleware>(); | |||
x.UseMiddleware<GatewayProxyMiddleware>(); | |||
}); | |||
return app; | |||
@@ -1,6 +1,4 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Text; | |||
namespace DotNetCore.CAP | |||
{ | |||
@@ -26,7 +24,8 @@ namespace DotNetCore.CAP | |||
services.AddSingleton(DashboardRoutes.Routes); | |||
services.AddSingleton<IHttpRequester, HttpClientHttpRequester>(); | |||
services.AddSingleton<IHttpClientCache, MemoryHttpClientCache>(); | |||
services.AddSingleton<IRequestMapper, RequestMapper>(); | |||
//services.AddScoped<IRequestScopedDataRepository, ScopedDataRepository>(); | |||
services.AddScoped<IRequestScopedDataRepository, HttpDataRepository>(); | |||
} | |||
} | |||
@@ -25,6 +25,8 @@ namespace DotNetCore.CAP.Dashboard | |||
public DashboardResponse Response { get; protected set; } | |||
public ISession Session { get; protected set; } | |||
public IServiceProvider RequestServices { get; protected set; } | |||
} | |||
@@ -42,6 +44,7 @@ namespace DotNetCore.CAP.Dashboard | |||
Request = new CapDashboardRequest(httpContext); | |||
Response = new CapDashboardResponse(httpContext); | |||
RequestServices = httpContext.RequestServices; | |||
Session = httpContext.Session; | |||
} | |||
public HttpContext HttpContext { get; } | |||
@@ -34,8 +34,8 @@ namespace DotNetCore.CAP.Dashboard | |||
public override string PathBase => _context.Request.PathBase.Value; | |||
public override string LocalIpAddress => _context.Connection.LocalIpAddress.ToString(); | |||
public override string RemoteIpAddress => _context.Connection.RemoteIpAddress.ToString(); | |||
public override string GetQuery(string key) => _context.Request.Query[key]; | |||
public override string GetQuery(string key) => _context.Request.Query[key]; | |||
public override async Task<IList<string>> GetFormValuesAsync(string key) | |||
{ | |||
@@ -107,7 +107,8 @@ namespace DotNetCore.CAP.Dashboard | |||
Routes.AddRazorPage("/subscribers", x => new SubscriberPage()); | |||
Routes.AddRazorPage("/nodes", x => new NodePage()); | |||
Routes.AddRazorPage("/nodes/node/(?<Id>.+)", x => new NodePage(x.Groups["Id"].Value)); | |||
#endregion Razor pages and commands | |||
} | |||
@@ -190,6 +190,12 @@ namespace DotNetCore.CAP.Dashboard | |||
$"<span class=\"labe label-defult text-uppercase\" title=\"{serverId}\">{shortenedId}</span>"); | |||
} | |||
public NonEscapedString NodeSwitchLink(string id) | |||
{ | |||
return Raw($"<a class=\"job-method\" href=\"{_page.Url.NodeSwitch(id)}\">{Strings.NodePage_Switch}</a>"); | |||
} | |||
#region MethodEscaped | |||
public NonEscapedString MethodEscaped(MethodInfo method) | |||
{ | |||
var outputString = string.Empty; | |||
@@ -288,7 +294,8 @@ namespace DotNetCore.CAP.Dashboard | |||
private string Span(string @class, string value) | |||
{ | |||
return $"<span class=\"{@class}\">{value}</span>"; | |||
} | |||
} | |||
#endregion | |||
public NonEscapedString StackTrace(string stackTrace) | |||
{ | |||
@@ -8,6 +8,19 @@ namespace DotNetCore.CAP.Dashboard.Pages | |||
partial class NodePage | |||
{ | |||
private IList<Node> _nodes = null; | |||
private INodeDiscoveryProvider _discoveryProvider; | |||
public NodePage() | |||
{ | |||
} | |||
public NodePage(string id) | |||
{ | |||
CurrentNodeId = id; | |||
} | |||
public string CurrentNodeId { get; set; } | |||
public IList<Node> Nodes | |||
{ | |||
@@ -15,13 +28,8 @@ namespace DotNetCore.CAP.Dashboard.Pages | |||
{ | |||
if (_nodes == null) | |||
{ | |||
var configOptions = RequestServices.GetService<DiscoveryOptions>(); | |||
var factory = RequestServices.GetService<IDiscoveryProviderFactory>(); | |||
var discoryProvider = factory.Create(configOptions); | |||
_nodes = discoryProvider.GetNodes().GetAwaiter().GetResult(); | |||
_discoveryProvider = RequestServices.GetService<INodeDiscoveryProvider>(); | |||
_nodes = _discoveryProvider.GetNodes().GetAwaiter().GetResult(); | |||
} | |||
return _nodes; | |||
} | |||
@@ -5,23 +5,28 @@ | |||
@inherits RazorPage | |||
@{ | |||
Layout = new LayoutPage(Strings.NodePage_Title); | |||
if (CurrentNodeId != null) | |||
{ | |||
Session.Set("cap_current_node",System.Text.Encoding.Default.GetBytes(CurrentNodeId)); | |||
} | |||
} | |||
<div class="row"> | |||
<div class="col-md-12"> | |||
<h1 class="page-header">@Strings.NodePage_Title</h1> | |||
@if (Nodes == null || Nodes.Count==0) | |||
@if (Nodes == null || Nodes.Count == 0) | |||
{ | |||
<div class="alert alert-warning"> | |||
@Strings.NodePage_NoNodes | |||
</div> | |||
} | |||
else | |||
{ | |||
{ | |||
<div class="table-responsive"> | |||
<table class="table"> | |||
<thead> | |||
<tr> | |||
<th width="10%">编号</th> | |||
<th width="20%">节点名称</th> | |||
<th width="20%">IP地址</th> | |||
<th width="7%">端口号</th> | |||
@@ -32,12 +37,15 @@ | |||
<tbody> | |||
@foreach (var node in Nodes) | |||
{ | |||
<tr> | |||
<tr class="@(CurrentNodeId == node.Id? "active":null )"> | |||
<td>@node.Id</td> | |||
<td>@node.Name</td> | |||
<td>@node.Address</td> | |||
<td>@node.Port</td> | |||
<td>@node.Tags</td> | |||
<td><a href="javascript:;" class="btn-link">切换到</a></td> | |||
<td> | |||
@Html.NodeSwitchLink(node.Id) | |||
</td> | |||
</tr> | |||
} | |||
</tbody> | |||
@@ -54,6 +54,10 @@ WriteLiteral("\r\n"); | |||
#line 6 "..\..\Dashboard\Pages\NodePage.cshtml" | |||
Layout = new LayoutPage(Strings.NodePage_Title); | |||
if (CurrentNodeId != null) | |||
{ | |||
Session.Set("cap_current_node",System.Text.Encoding.Default.GetBytes(CurrentNodeId)); | |||
} | |||
@@ -63,7 +67,7 @@ WriteLiteral("<div class=\"row\">\r\n <div class=\"col-md-12\">\r\n <h | |||
#line 11 "..\..\Dashboard\Pages\NodePage.cshtml" | |||
#line 15 "..\..\Dashboard\Pages\NodePage.cshtml" | |||
Write(Strings.NodePage_Title); | |||
@@ -73,8 +77,8 @@ WriteLiteral("</h1>\r\n\r\n"); | |||
#line 13 "..\..\Dashboard\Pages\NodePage.cshtml" | |||
if (Nodes == null || Nodes.Count==0) | |||
#line 17 "..\..\Dashboard\Pages\NodePage.cshtml" | |||
if (Nodes == null || Nodes.Count == 0) | |||
{ | |||
@@ -84,7 +88,7 @@ WriteLiteral(" <div class=\"alert alert-warning\">\r\n | |||
#line 16 "..\..\Dashboard\Pages\NodePage.cshtml" | |||
#line 20 "..\..\Dashboard\Pages\NodePage.cshtml" | |||
Write(Strings.NodePage_NoNodes); | |||
@@ -94,10 +98,10 @@ WriteLiteral("\r\n </div>\r\n"); | |||
#line 18 "..\..\Dashboard\Pages\NodePage.cshtml" | |||
#line 22 "..\..\Dashboard\Pages\NodePage.cshtml" | |||
} | |||
else | |||
{ | |||
{ | |||
#line default | |||
@@ -106,6 +110,7 @@ WriteLiteral(@" <div class=""table-responsive""> | |||
<table class=""table""> | |||
<thead> | |||
<tr> | |||
<th width=""10%"">编号</th> | |||
<th width=""20%"">节点名称</th> | |||
<th width=""20%"">IP地址</th> | |||
<th width=""7%"">端口号</th> | |||
@@ -118,18 +123,38 @@ WriteLiteral(@" <div class=""table-responsive""> | |||
#line 33 "..\..\Dashboard\Pages\NodePage.cshtml" | |||
#line 38 "..\..\Dashboard\Pages\NodePage.cshtml" | |||
foreach (var node in Nodes) | |||
{ | |||
#line default | |||
#line hidden | |||
WriteLiteral(" <tr>\r\n <td>"); | |||
WriteLiteral(" <tr class=\""); | |||
#line 36 "..\..\Dashboard\Pages\NodePage.cshtml" | |||
#line 40 "..\..\Dashboard\Pages\NodePage.cshtml" | |||
Write(CurrentNodeId == node.Id? "active":null ); | |||
#line default | |||
#line hidden | |||
WriteLiteral("\">\r\n <td>"); | |||
#line 41 "..\..\Dashboard\Pages\NodePage.cshtml" | |||
Write(node.Id); | |||
#line default | |||
#line hidden | |||
WriteLiteral("</td>\r\n <td>"); | |||
#line 42 "..\..\Dashboard\Pages\NodePage.cshtml" | |||
Write(node.Name); | |||
@@ -139,7 +164,7 @@ WriteLiteral("</td>\r\n <td>"); | |||
#line 37 "..\..\Dashboard\Pages\NodePage.cshtml" | |||
#line 43 "..\..\Dashboard\Pages\NodePage.cshtml" | |||
Write(node.Address); | |||
@@ -149,7 +174,7 @@ WriteLiteral("</td>\r\n <td>"); | |||
#line 38 "..\..\Dashboard\Pages\NodePage.cshtml" | |||
#line 44 "..\..\Dashboard\Pages\NodePage.cshtml" | |||
Write(node.Port); | |||
@@ -159,18 +184,28 @@ WriteLiteral("</td>\r\n <td>"); | |||
#line 39 "..\..\Dashboard\Pages\NodePage.cshtml" | |||
#line 45 "..\..\Dashboard\Pages\NodePage.cshtml" | |||
Write(node.Tags); | |||
#line default | |||
#line hidden | |||
WriteLiteral("</td>\r\n <td><a class=\"btn\">切换到</a></td>\r\n " + | |||
" </tr>\r\n"); | |||
WriteLiteral("</td>\r\n <td>\r\n " + | |||
""); | |||
#line 42 "..\..\Dashboard\Pages\NodePage.cshtml" | |||
#line 47 "..\..\Dashboard\Pages\NodePage.cshtml" | |||
Write(Html.NodeSwitchLink(node.Id)); | |||
#line default | |||
#line hidden | |||
WriteLiteral("\r\n </td>\r\n </tr>\r\n"); | |||
#line 50 "..\..\Dashboard\Pages\NodePage.cshtml" | |||
} | |||
@@ -180,7 +215,7 @@ WriteLiteral(" </tbody>\r\n </table>\r\n | |||
#line 46 "..\..\Dashboard\Pages\NodePage.cshtml" | |||
#line 54 "..\..\Dashboard\Pages\NodePage.cshtml" | |||
} | |||
@@ -3,6 +3,7 @@ using System.Diagnostics; | |||
using System.Net; | |||
using System.Text; | |||
using DotNetCore.CAP.Dashboard.Monitoring; | |||
using Microsoft.AspNetCore.Http; | |||
namespace DotNetCore.CAP.Dashboard | |||
{ | |||
@@ -37,9 +38,9 @@ namespace DotNetCore.CAP.Dashboard | |||
} | |||
} | |||
internal DashboardRequest Request { private get; set; } | |||
internal DashboardResponse Response { private get; set; } | |||
protected DashboardRequest Request { private get; set; } | |||
protected DashboardResponse Response { private get; set; } | |||
internal ISession Session { get; private set; } | |||
internal IServiceProvider RequestServices { get; private set; } | |||
public string RequestPath => Request.Path; | |||
@@ -67,6 +68,7 @@ namespace DotNetCore.CAP.Dashboard | |||
StatsPollingInterval = parentPage.StatsPollingInterval; | |||
Url = parentPage.Url; | |||
RequestServices = parentPage.RequestServices; | |||
Session = parentPage.Session; | |||
GenerationTime = parentPage.GenerationTime; | |||
_statisticsLazy = parentPage._statisticsLazy; | |||
@@ -77,7 +79,7 @@ namespace DotNetCore.CAP.Dashboard | |||
Request = context.Request; | |||
Response = context.Response; | |||
RequestServices = context.RequestServices; | |||
Session = context.Session; | |||
Storage = context.Storage; | |||
AppPath = context.Options.AppPath; | |||
StatsPollingInterval = context.Options.StatsPollingInterval; | |||
@@ -29,6 +29,11 @@ namespace DotNetCore.CAP.Dashboard | |||
return To("/jobs/details/" + jobId); | |||
} | |||
public string NodeSwitch(string id) | |||
{ | |||
return To("/nodes/node/" + id); | |||
} | |||
public string LinkToPublished() | |||
{ | |||
return To("/published/succeeded"); | |||
@@ -21,10 +21,16 @@ namespace DotNetCore.CAP | |||
var discoveryOptions = new DiscoveryOptions(); | |||
_options?.Invoke(discoveryOptions); | |||
services.AddSingleton(discoveryOptions); | |||
services.AddSingleton(discoveryOptions); | |||
services.AddSingleton<IDiscoveryProviderFactory, DiscoveryProviderFactory>(); | |||
services.AddSingleton<IProcessingServer, ConsulProcessingNodeServer>(); | |||
services.AddSingleton<INodeDiscoveryProvider>(x => | |||
{ | |||
var configOptions = x.GetService<DiscoveryOptions>(); | |||
var factory = x.GetService<IDiscoveryProviderFactory>(); | |||
return factory.Create(configOptions); | |||
}); | |||
} | |||
} | |||
} | |||
@@ -37,7 +43,7 @@ namespace Microsoft.Extensions.DependencyInjection | |||
{ | |||
public static CapOptions UseDiscovery(this CapOptions capOptions) | |||
{ | |||
return capOptions.UseDiscovery(opt => {}); | |||
return capOptions.UseDiscovery(opt => { }); | |||
} | |||
public static CapOptions UseDiscovery(this CapOptions capOptions, Action<DiscoveryOptions> options) | |||
@@ -4,6 +4,7 @@ using System.Collections.Generic; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
using Consul; | |||
using System.Security.Cryptography; | |||
namespace DotNetCore.CAP.NodeDiscovery | |||
{ | |||
@@ -33,7 +34,7 @@ namespace DotNetCore.CAP.NodeDiscovery | |||
var nodes = services.Response.Select(x => new Node | |||
{ | |||
Name = x.Key, | |||
Name = x.Value.Service, | |||
Address = x.Value.Address, | |||
Port = x.Value.Port, | |||
Tags = string.Join(", ", x.Value.Tags) | |||
@@ -6,6 +6,8 @@ namespace DotNetCore.CAP.NodeDiscovery | |||
{ | |||
class Node | |||
{ | |||
public string Id { get; set; } | |||
public string Name { get; set; } | |||
public string Address { get; set; } | |||