/
RootController.cs
167 lines (155 loc) · 6.34 KB
/
RootController.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
namespace ServiceControl.Infrastructure.WebApi
{
using System;
using System.Linq;
using System.Net.Http;
using System.Text.Json.Nodes;
using System.Threading.Tasks;
using Configuration;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Extensions;
using Microsoft.AspNetCore.Mvc;
using Particular.ServiceControl.Licensing;
using ServiceBus.Management.Infrastructure.Settings;
[ApiController]
[Route("api")]
public class RootController(
ActiveLicense license,
LoggingSettings loggingSettings,
Settings settings,
IHttpClientFactory httpClientFactory)
: ControllerBase
{
[Route("")]
[HttpGet]
public RootUrls Urls()
{
var baseUrl = Request.GetDisplayUrl() + "/";
var model = new RootUrls
{
EndpointsUrl = baseUrl + "endpoints",
KnownEndpointsUrl = "/endpoints/known", // relative URI to allow proxying
SagasUrl = baseUrl + "sagas",
ErrorsUrl = baseUrl + "errors/{?page,per_page,direction,sort}",
EndpointsErrorUrl = baseUrl + "endpoints/{name}/errors/{?page,per_page,direction,sort}",
MessageSearchUrl =
baseUrl + "messages/search/{keyword}/{?page,per_page,direction,sort}",
EndpointsMessageSearchUrl =
baseUrl +
"endpoints/{name}/messages/search/{keyword}/{?page,per_page,direction,sort}",
EndpointsMessagesUrl =
baseUrl + "endpoints/{name}/messages/{?page,per_page,direction,sort}",
AuditCountUrl = baseUrl + "endpoints/{name}/audit-count",
Name = SettingsReader.Read(Settings.SettingsRootNamespace, "Name", "ServiceControl"),
Description = SettingsReader.Read(Settings.SettingsRootNamespace, "Description", "The management backend for the Particular Service Platform"),
LicenseStatus = license.IsValid ? "valid" : "invalid",
LicenseDetails = baseUrl + "license",
Configuration = baseUrl + "configuration",
RemoteConfiguration = baseUrl + "configuration/remotes",
EventLogItems = baseUrl + "eventlogitems",
ArchivedGroupsUrl = baseUrl + "errors/groups/{classifier?}",
GetArchiveGroup = baseUrl + "archive/groups/id/{groupId}",
};
return model;
}
[Route("instance-info")]
[Route("configuration")]
[HttpGet]
public object Config()
{
object content = new
{
Host = new
{
settings.ServiceName,
Logging = new
{
loggingSettings.LogPath,
LoggingLevel = loggingSettings.LoggingLevel.Name,
}
},
DataRetention = new
{
settings.AuditRetentionPeriod,
settings.ErrorRetentionPeriod
},
PerformanceTunning = new
{
settings.ExternalIntegrationsDispatchingBatchSize
},
PersistenceSettings = settings.PersisterSpecificSettings,
Transport = new
{
settings.TransportType,
settings.ErrorLogQueue,
settings.ErrorQueue,
settings.ForwardErrorMessages
},
Plugins = new
{
settings.HeartbeatGracePeriod
}
};
return content;
}
[Route("configuration/remotes")]
[HttpGet]
public async Task<IActionResult> RemoteConfig()
{
var remotes = settings.RemoteInstances;
var tasks = remotes
.Select(async remote =>
{
var status = remote.TemporarilyUnavailable ? "unavailable" : "online";
var version = "Unknown";
var httpClient = httpClientFactory.CreateClient(remote.InstanceId);
JsonNode config = null;
try
{
var response = await httpClient.GetAsync("/api/configuration");
if (response.Headers.TryGetValues("X-Particular-Version", out var values))
{
version = values.FirstOrDefault() ?? "Missing";
}
await using var stream = await response.Content.ReadAsStreamAsync();
config = await JsonNode.ParseAsync(stream);
}
catch (Exception)
{
status = "error";
}
return new
{
ApiUri = remote.BaseAddress,
Version = version,
Status = status,
Configuration = config
};
})
.ToArray();
var results = await Task.WhenAll(tasks);
return Ok(results);
}
public class RootUrls
{
public string Description { get; set; }
public string EndpointsErrorUrl { get; set; }
public string KnownEndpointsUrl { get; set; }
public string EndpointsMessageSearchUrl { get; set; }
public string EndpointsMessagesUrl { get; set; }
public string AuditCountUrl { get; set; }
public string EndpointsUrl { get; set; }
public string ErrorsUrl { get; set; }
public string Configuration { get; set; }
public string RemoteConfiguration { get; set; }
public string MessageSearchUrl { get; set; }
public string LicenseStatus { get; set; }
public string LicenseDetails { get; set; }
public string Name { get; set; }
public string SagasUrl { get; set; }
public string EventLogItems { get; set; }
public string ArchivedGroupsUrl { get; set; }
public string GetArchiveGroup { get; set; }
}
}
}