|
|
|
|
@ -1,14 +1,13 @@ |
|
|
|
|
using System; |
|
|
|
|
using System.Collections.Generic; |
|
|
|
|
using System.Diagnostics.SymbolStore; |
|
|
|
|
using System.IO; |
|
|
|
|
using System.Linq; |
|
|
|
|
using System.Net.Http; |
|
|
|
|
using System.Net.Http.Headers; |
|
|
|
|
using System.Threading.Tasks; |
|
|
|
|
using Hessian; |
|
|
|
|
using DotXxlJob.Core.Config; |
|
|
|
|
using DotXxlJob.Core.Model; |
|
|
|
|
using Hessian; |
|
|
|
|
using Microsoft.Extensions.Logging; |
|
|
|
|
using Microsoft.Extensions.Options; |
|
|
|
|
|
|
|
|
|
@ -16,7 +15,7 @@ namespace DotXxlJob.Core |
|
|
|
|
{ |
|
|
|
|
public class AdminClient |
|
|
|
|
{ |
|
|
|
|
static readonly string MAPPING = "/api"; |
|
|
|
|
private static readonly string MAPPING = "/api"; |
|
|
|
|
private readonly XxlJobExecutorOptions _options; |
|
|
|
|
private readonly IHttpClientFactory _clientFactory; |
|
|
|
|
private readonly ILogger<AdminClient> _logger; |
|
|
|
|
@ -26,10 +25,9 @@ namespace DotXxlJob.Core |
|
|
|
|
private int _currentIndex; |
|
|
|
|
|
|
|
|
|
public AdminClient(IOptions<XxlJobExecutorOptions> optionsAccessor |
|
|
|
|
,IHttpClientFactory clientFactory |
|
|
|
|
,ILogger<AdminClient> logger) |
|
|
|
|
, IHttpClientFactory clientFactory |
|
|
|
|
, ILogger<AdminClient> logger) |
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
Preconditions.CheckNotNull(optionsAccessor?.Value, "XxlJobExecutorOptions"); |
|
|
|
|
|
|
|
|
|
this._options = optionsAccessor?.Value; |
|
|
|
|
@ -56,39 +54,37 @@ namespace DotXxlJob.Core |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Task<ReturnT> Callback(List<HandleCallbackParam> callbackParamList) |
|
|
|
|
{ |
|
|
|
|
return InvokeRpcService("callback", new List<object> {new JavaClass {Name = Constants.JavaListFulName}}, callbackParamList); |
|
|
|
|
return InvokeRpcService("callback", new List<object> { new JavaClass { Name = Constants.JavaListFulName } }, callbackParamList); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Task<ReturnT> Registry(RegistryParam registryParam) |
|
|
|
|
{ |
|
|
|
|
return InvokeRpcService("registry", new List<object> {new JavaClass {Name = "com.xxl.job.core.biz.model.RegistryParam"}}, registryParam,true); |
|
|
|
|
return InvokeRpcService("registry", new List<object> { new JavaClass { Name = "com.xxl.job.core.biz.model.RegistryParam" } }, registryParam, true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public Task<ReturnT> RegistryRemove(RegistryParam registryParam) |
|
|
|
|
{ |
|
|
|
|
return InvokeRpcService("registryRemove", new List<object> {new JavaClass {Name = "com.xxl.job.core.biz.model.RegistryParam"}}, registryParam,true); |
|
|
|
|
return InvokeRpcService("registryRemove", new List<object> { new JavaClass { Name = "com.xxl.job.core.biz.model.RegistryParam" } }, registryParam, true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private async Task<ReturnT> InvokeRpcService(string methodName, List<object> parameterTypes, |
|
|
|
|
object parameters,bool polling=false) |
|
|
|
|
object parameters, bool polling = false) |
|
|
|
|
{ |
|
|
|
|
var request = new RpcRequest { |
|
|
|
|
RequestId = Guid.NewGuid().ToString("N"), |
|
|
|
|
CreateMillisTime = DateTime.Now.GetTotalMilliseconds(), |
|
|
|
|
AccessToken = this._options.AccessToken, |
|
|
|
|
AccessToken = _options.AccessToken, |
|
|
|
|
ClassName = "com.xxl.job.core.biz.AdminBiz", |
|
|
|
|
MethodName = methodName, |
|
|
|
|
ParameterTypes = parameterTypes, |
|
|
|
|
Parameters = new List<object> {parameters} |
|
|
|
|
Parameters = new List<object> { parameters } |
|
|
|
|
}; |
|
|
|
|
byte[] postBuf; |
|
|
|
|
using (var stream = new MemoryStream()) |
|
|
|
|
{ |
|
|
|
|
HessianSerializer.SerializeRequest(stream,request); |
|
|
|
|
HessianSerializer.SerializeRequest(stream, request); |
|
|
|
|
|
|
|
|
|
postBuf = stream.ToArray(); |
|
|
|
|
} |
|
|
|
|
@ -113,7 +109,7 @@ namespace DotXxlJob.Core |
|
|
|
|
} |
|
|
|
|
catch (Exception ex) |
|
|
|
|
{ |
|
|
|
|
this._logger.LogError(ex, "request admin error.{0}",ex.Message); |
|
|
|
|
this._logger.LogError(ex, "request admin error.{0}", ex.Message); |
|
|
|
|
address.SetFail(); |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
@ -130,13 +126,10 @@ namespace DotXxlJob.Core |
|
|
|
|
} |
|
|
|
|
*/ |
|
|
|
|
res = HessianSerializer.DeserializeResponse(resStream); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
catch (Exception ex) |
|
|
|
|
{ |
|
|
|
|
this._logger.LogError(ex,"DeserializeResponse error:{errorMessage}",ex.Message); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this._logger.LogError(ex, "DeserializeResponse error:{errorMessage}", ex.Message); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (res == null) |
|
|
|
|
@ -147,7 +140,7 @@ namespace DotXxlJob.Core |
|
|
|
|
{ |
|
|
|
|
retList.Add(ReturnT.Failed(res.ErrorMsg)); |
|
|
|
|
} |
|
|
|
|
else if(res.Result is ReturnT ret) |
|
|
|
|
else if (res.Result is ReturnT ret) |
|
|
|
|
{ |
|
|
|
|
retList.Add(ret); |
|
|
|
|
} |
|
|
|
|
@ -160,7 +153,6 @@ namespace DotXxlJob.Core |
|
|
|
|
{ |
|
|
|
|
return retList[0]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (retList.Count > 0) |
|
|
|
|
@ -169,10 +161,9 @@ namespace DotXxlJob.Core |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
throw new Exception("xxl-rpc server address not accessible."); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private async Task<Stream> DoPost(HttpClient client,AddressEntry address, byte[] postBuf) |
|
|
|
|
private async Task<Stream> DoPost(HttpClient client, AddressEntry address, byte[] postBuf) |
|
|
|
|
{ |
|
|
|
|
var content = new ByteArrayContent(postBuf); |
|
|
|
|
content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); |
|
|
|
|
@ -181,7 +172,5 @@ namespace DotXxlJob.Core |
|
|
|
|
responseMessage.EnsureSuccessStatusCode(); |
|
|
|
|
return await responseMessage.Content.ReadAsStreamAsync(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |