支持应用系统送服务地址给StarAgent
This commit is contained in:
parent
bb51d6d504
commit
7f133a24ea
|
@ -54,8 +54,8 @@ namespace StarAgent
|
|||
{
|
||||
ThreadPoolX.QueueUserWorkItem(() =>
|
||||
{
|
||||
svc.StartClient();
|
||||
svc.StartFactory();
|
||||
svc.StartClient();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -95,8 +95,8 @@
|
|||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="NewLife.Core" Version="8.11.2021.1109" />
|
||||
<PackageReference Include="NewLife.XCode" Version="10.3.2021.1109" />
|
||||
<PackageReference Include="NewLife.Core" Version="8.11.2021.1124-beta1" />
|
||||
<PackageReference Include="NewLife.XCode" Version="10.3.2021.1124-beta1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
@ -47,7 +47,7 @@
|
|||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="NewLife.Cube.Core" Version="4.1.2021.1109" />
|
||||
<PackageReference Include="NewLife.Cube.Core" Version="4.1.2021.1125-beta1" />
|
||||
<PackageReference Include="NewLife.Redis" Version="3.9.2021.1001" />
|
||||
</ItemGroup>
|
||||
|
||||
|
|
|
@ -25,6 +25,9 @@ namespace Stardust
|
|||
/// <summary>代理信息</summary>
|
||||
public AgentInfo Info { get; private set; }
|
||||
|
||||
/// <summary>本地服务端地址</summary>
|
||||
public String Server { get => _local?.Server; set => _local.Server = value; }
|
||||
|
||||
private AgentInfo _local;
|
||||
private ApiClient _client;
|
||||
#endregion
|
||||
|
@ -71,10 +74,6 @@ namespace Stardust
|
|||
/// <returns></returns>
|
||||
public AgentInfo GetInfo()
|
||||
{
|
||||
//Init();
|
||||
|
||||
//return Info = _client.Invoke<AgentInfo>("Info", _local);
|
||||
|
||||
var task = GetInfoAsync();
|
||||
if (task.Wait(500)) return task.Result;
|
||||
|
||||
|
@ -130,12 +129,15 @@ namespace Stardust
|
|||
if (url.IsNullOrEmpty())
|
||||
{
|
||||
var set = NewLife.Setting.Current;
|
||||
if (Environment.Version.Major >= 5)
|
||||
url = set.PluginServer.CombinePath("staragent50.zip");
|
||||
url = set.PluginServer.CombinePath("star");
|
||||
if (Environment.Version.Major >= 6)
|
||||
url = url.CombinePath("staragent60.zip");
|
||||
else if (Environment.Version.Major >= 5)
|
||||
url = url.CombinePath("staragent50.zip");
|
||||
else if (Environment.Version.Major >= 4)
|
||||
url = set.PluginServer.CombinePath("staragent45.zip");
|
||||
url = url.CombinePath("staragent45.zip");
|
||||
else
|
||||
url = set.PluginServer.CombinePath("staragent31.zip");
|
||||
url = url.CombinePath("staragent31.zip");
|
||||
}
|
||||
|
||||
// 尝试连接,获取版本
|
||||
|
|
|
@ -15,7 +15,7 @@ namespace Stardust.Monitors
|
|||
/// <summary>追踪器</summary>
|
||||
public ITracer Tracer { get; set; }
|
||||
|
||||
private readonly Dictionary<String, TraceDiagnosticListener> _listeners = new Dictionary<String, TraceDiagnosticListener>();
|
||||
private readonly Dictionary<String, TraceDiagnosticListener> _listeners = new();
|
||||
|
||||
private Int32 _inited;
|
||||
private void Init()
|
||||
|
|
|
@ -26,9 +26,6 @@ namespace Stardust.Monitors
|
|||
/// <summary>应用名</summary>
|
||||
public String AppName { get; set; }
|
||||
|
||||
///// <summary>应用密钥</summary>
|
||||
//public String Secret { get; set; }
|
||||
|
||||
/// <summary>实例。应用可能多实例部署,ip@proccessid</summary>
|
||||
public String ClientId { get; set; }
|
||||
|
||||
|
@ -43,7 +40,7 @@ namespace Stardust.Monitors
|
|||
|
||||
private readonly String _version;
|
||||
private readonly Process _process = Process.GetCurrentProcess();
|
||||
private readonly Queue<TraceModel> _fails = new Queue<TraceModel>();
|
||||
private readonly Queue<TraceModel> _fails = new();
|
||||
private AppInfo _appInfo;
|
||||
#endregion
|
||||
|
||||
|
@ -93,56 +90,13 @@ namespace Stardust.Monitors
|
|||
#endregion
|
||||
|
||||
#region 核心业务
|
||||
//private TokenModel _token;
|
||||
//private DateTime _expire;
|
||||
//private void CheckAuthorize()
|
||||
//{
|
||||
// if (_token == null || Client.Token.IsNullOrEmpty())
|
||||
// {
|
||||
// // 申请令牌
|
||||
// _token = Client.Invoke<TokenModel>("OAuth/Token", new
|
||||
// {
|
||||
// grant_type = "password",
|
||||
// username = AppId,
|
||||
// password = Secret
|
||||
// });
|
||||
// Client.Token = _token.AccessToken;
|
||||
|
||||
// WriteLog("申请令牌:{0}", _token.AccessToken);
|
||||
|
||||
// // 提前一分钟过期
|
||||
// _expire = DateTime.Now.AddSeconds(_token.ExpireIn - 600);
|
||||
// }
|
||||
// else if (_token != null && DateTime.Now > _expire)
|
||||
// {
|
||||
// // 刷新令牌
|
||||
// _token = Client.Invoke<TokenModel>("OAuth/Token", new
|
||||
// {
|
||||
// grant_type = "refresh_token",
|
||||
// refresh_token = _token.RefreshToken,
|
||||
// });
|
||||
// Client.Token = _token.AccessToken;
|
||||
|
||||
// WriteLog("刷新令牌:{0}", _token.AccessToken);
|
||||
// }
|
||||
//}
|
||||
|
||||
private Boolean _inited;
|
||||
private void Init()
|
||||
{
|
||||
if (_inited) return;
|
||||
|
||||
// 自动从本地星尘代理获取地址
|
||||
if (Client == null)
|
||||
{
|
||||
try
|
||||
{
|
||||
var client = new LocalStarClient();
|
||||
var inf = client.GetInfo();
|
||||
if (!inf.Server.IsNullOrEmpty()) Client = new ApiHttpClient(inf.Server);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
if (Client == null) throw new ArgumentNullException(nameof(Client));
|
||||
|
||||
var server = Client is ApiHttpClient http ? http.Services.Join(",", e => e.Address) : (Client + "");
|
||||
WriteLog("星尘监控中心 Server={0} AppId={1} ClientId={2}", server, AppId, ClientId);
|
||||
|
@ -182,9 +136,6 @@ namespace Stardust.Monitors
|
|||
};
|
||||
try
|
||||
{
|
||||
//// 检查令牌
|
||||
//if (!Secret.IsNullOrEmpty()) CheckAuthorize();
|
||||
|
||||
var rs = Client.Invoke<TraceResponse>("Trace/Report", model);
|
||||
// 处理响应参数
|
||||
if (rs != null)
|
||||
|
@ -208,18 +159,14 @@ namespace Stardust.Monitors
|
|||
}
|
||||
catch (ApiException ex)
|
||||
{
|
||||
//if (ex.Code == 401 || ex.Code == 403) _token = null;
|
||||
|
||||
Log?.Error(ex + "");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//if (ex is ApiException ae && (ae.Code == 401 || ae.Code == 403)) _token = null;
|
||||
|
||||
var ex2 = ex is AggregateException aex ? aex.InnerException : ex;
|
||||
if (ex2 is TaskCanceledException ||
|
||||
if (ex2 is TaskCanceledException ||
|
||||
ex2 is HttpRequestException ||
|
||||
ex2 is SocketException)
|
||||
ex2 is SocketException)
|
||||
Log?.Error("无法连接服务端:{0}", (Client as ApiHttpClient)?.Source);
|
||||
|
||||
if (ex2 is not HttpRequestException)
|
||||
|
@ -304,8 +251,8 @@ namespace Stardust.Monitors
|
|||
}
|
||||
if (server.IsNullOrEmpty())
|
||||
{
|
||||
var local = new LocalStarClient();
|
||||
var inf = local.GetInfo();
|
||||
var client = new LocalStarClient();
|
||||
var inf = client.GetInfo();
|
||||
server = inf?.Server;
|
||||
|
||||
if (!server.IsNullOrEmpty()) XTrace.WriteLine("星尘探测:{0}", server);
|
||||
|
|
|
@ -22,7 +22,7 @@ namespace Stardust
|
|||
public ServiceInfo[] Services { get; set; }
|
||||
|
||||
private CsvDb<ProcessInfo> _services;
|
||||
private readonly Dictionary<String, Process> _processes = new Dictionary<String, Process>();
|
||||
private readonly Dictionary<String, Process> _processes = new();
|
||||
#endregion
|
||||
|
||||
#region 构造
|
||||
|
|
|
@ -126,24 +126,22 @@ namespace Stardust
|
|||
Server = json["StarServer"];
|
||||
}
|
||||
|
||||
if (Server.IsNullOrEmpty())
|
||||
if (!Server.IsNullOrEmpty() && Local.Server.IsNullOrEmpty()) Local.Server = Server;
|
||||
|
||||
try
|
||||
{
|
||||
try
|
||||
var inf = Local.GetInfo();
|
||||
var server = inf?.Server;
|
||||
if (!server.IsNullOrEmpty())
|
||||
{
|
||||
var inf = Local.GetInfo();
|
||||
var server = inf?.Server;
|
||||
if (!server.IsNullOrEmpty())
|
||||
{
|
||||
Server = server;
|
||||
XTrace.WriteLine("星尘探测:{0}", server);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//XTrace.WriteException(ex);
|
||||
XTrace.Log.Error("星尘探测失败!{0}", ex.Message);
|
||||
if (Server.IsNullOrEmpty()) Server = server;
|
||||
XTrace.WriteLine("星尘探测:{0}", server);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
XTrace.Log.Error("星尘探测失败!{0}", ex.Message);
|
||||
}
|
||||
|
||||
// 如果探测不到本地应用,则使用配置
|
||||
var set = Setting.Current;
|
||||
|
|
|
@ -52,7 +52,7 @@
|
|||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="NewLife.Core" Version="8.11.2021.1109" />
|
||||
<PackageReference Include="NewLife.Core" Version="8.11.2021.1124-beta1" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="NewLife.Core" Version="8.11.2021.1109" />
|
||||
<PackageReference Include="NewLife.Core" Version="8.11.2021.1124-beta1" />
|
||||
<PackageReference Include="SSH.NET" Version="2020.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
|
|
Loading…
Reference in New Issue