|
|
@ -11,6 +11,7 @@ using ZKLT.Quartz.Model;
|
|
|
|
using ZKLT.Hadoop.Interface;
|
|
|
|
using ZKLT.Hadoop.Interface;
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
using ZKLT.Hadoop.Model;
|
|
|
|
using ZKLT.Hadoop.Model;
|
|
|
|
|
|
|
|
using System.Dynamic;
|
|
|
|
namespace ZKLT.Quartz.Job
|
|
|
|
namespace ZKLT.Quartz.Job
|
|
|
|
{
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
@ -18,29 +19,29 @@ namespace ZKLT.Quartz.Job
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
public class HttpJob : IJob
|
|
|
|
public class HttpJob : IJob
|
|
|
|
{
|
|
|
|
{
|
|
|
|
private IHadoopService HadoopService;
|
|
|
|
|
|
|
|
public HttpJob(IHadoopService _hadoopService)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
HadoopService = _hadoopService;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public async Task Execute(IJobExecutionContext context)
|
|
|
|
public async Task Execute(IJobExecutionContext context)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
JobDataMap dataMap = context.JobDetail.JobDataMap;
|
|
|
|
JobDataMap dataMap = context.JobDetail.JobDataMap;
|
|
|
|
string taskId = dataMap.Get("TaskId").ToString();
|
|
|
|
IHadoopService _HadoopService = (IHadoopService)dataMap.Get("hadoop");
|
|
|
|
Console.WriteLine(taskId);
|
|
|
|
// 任务配置项
|
|
|
|
|
|
|
|
|
|
|
|
List<QZ_JobConfig> configs = (List<QZ_JobConfig>)dataMap.Get("Params");
|
|
|
|
List<QZ_JobConfig> configs = (List<QZ_JobConfig>)dataMap.Get("Params");
|
|
|
|
|
|
|
|
// 任务Id
|
|
|
|
|
|
|
|
string taskId = dataMap.Get("TaskId").ToString();
|
|
|
|
|
|
|
|
// 是否开启日志
|
|
|
|
|
|
|
|
int isLog = (int)dataMap.Get("IsLog");
|
|
|
|
|
|
|
|
// 请求地址
|
|
|
|
string url = configs.Find(_item => _item.Key == "Url").Value;
|
|
|
|
string url = configs.Find(_item => _item.Key == "Url").Value;
|
|
|
|
HttpMethod httpMethod = configs.Find(_item => _item.Key == "Method").Value == "Get" ? HttpMethod.Get : HttpMethod.Post;
|
|
|
|
// 请求类型
|
|
|
|
|
|
|
|
HttpMethod httpMethod = configs.Find(_item => _item.Key == "Method").Value == "GET" ? HttpMethod.Get : HttpMethod.Post;
|
|
|
|
|
|
|
|
// 返回数据储存表
|
|
|
|
string bindDatabase = configs.Find(_item => _item.Key == "BindDatabse").Value;
|
|
|
|
string bindDatabase = configs.Find(_item => _item.Key == "BindDatabse").Value;
|
|
|
|
|
|
|
|
// 返回数据集合名
|
|
|
|
|
|
|
|
string resultSet = configs.Find(_item => _item.Key == "ResultSet").Value;
|
|
|
|
using (HttpClient client = new HttpClient())
|
|
|
|
using (HttpClient client = new HttpClient())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
try
|
|
|
|
try
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var resultColumnConfigs = new List<QZ_JobConfig>();
|
|
|
|
var resultColumnConfigs = new List<QZ_JobConfig>();
|
|
|
|
|
|
|
|
|
|
|
|
HttpRequestMessage request = new HttpRequestMessage(httpMethod, url);
|
|
|
|
HttpRequestMessage request = new HttpRequestMessage(httpMethod, url);
|
|
|
|
foreach (var _item in configs)
|
|
|
|
foreach (var _item in configs)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -57,11 +58,29 @@ namespace ZKLT.Quartz.Job
|
|
|
|
HttpResponseMessage response = await client.SendAsync(request);
|
|
|
|
HttpResponseMessage response = await client.SendAsync(request);
|
|
|
|
response.EnsureSuccessStatusCode();
|
|
|
|
response.EnsureSuccessStatusCode();
|
|
|
|
string responseBody = await response.Content.ReadAsStringAsync();
|
|
|
|
string responseBody = await response.Content.ReadAsStringAsync();
|
|
|
|
var responseList = JsonConvert.DeserializeObject<List<JObject>>(responseBody);
|
|
|
|
var responseObject = JsonConvert.DeserializeObject<JObject>(responseBody);
|
|
|
|
if(bindDatabase != null)
|
|
|
|
JArray responseList = (JArray)responseObject.GetValue(resultSet);
|
|
|
|
|
|
|
|
// 如果设定了绑定表 插入表中
|
|
|
|
|
|
|
|
if (bindDatabase != null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
HDP_Command[] commands = makeCommand(bindDatabase, responseList, resultColumnConfigs);
|
|
|
|
HDP_Command[] commands = makeCommand(bindDatabase, responseList, resultColumnConfigs);
|
|
|
|
HadoopService.PatchCommand(commands);
|
|
|
|
_HadoopService.PatchCommand(commands);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// 日志开启,插入日志
|
|
|
|
|
|
|
|
if (isLog == HDP_Task.LOGOPEN)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var data = new HDP_TaskLog()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Id = "TL" + DateTime.Now.ToUniversalTime(),
|
|
|
|
|
|
|
|
TaskId = taskId,
|
|
|
|
|
|
|
|
Content = responseBody
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
var logCommand = new HDP_Command()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
TableId = HDP_TaskLog.TABLEID,
|
|
|
|
|
|
|
|
Data = JToken.FromObject(data)
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
_HadoopService.Insert(logCommand);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (HttpRequestException e)
|
|
|
|
catch (HttpRequestException e)
|
|
|
@ -70,10 +89,11 @@ namespace ZKLT.Quartz.Job
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await Task.CompletedTask;
|
|
|
|
await Task.CompletedTask;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public HDP_Command[] makeCommand(string bindDatabase,List<JObject> responseList,List<QZ_JobConfig> configList)
|
|
|
|
public HDP_Command[] makeCommand(string bindDatabase,JArray responseList,List<QZ_JobConfig> configList)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
HDP_Command[] commands = new HDP_Command?[responseList.Count];
|
|
|
|
HDP_Command[] commands = new HDP_Command?[responseList.Count];
|
|
|
|
foreach (var _item in responseList)
|
|
|
|
foreach (var _item in responseList)
|
|
|
@ -81,10 +101,14 @@ namespace ZKLT.Quartz.Job
|
|
|
|
var command = new HDP_Command();
|
|
|
|
var command = new HDP_Command();
|
|
|
|
command.TableId = bindDatabase;
|
|
|
|
command.TableId = bindDatabase;
|
|
|
|
command.Type = HDP_CommandType.INSERT;
|
|
|
|
command.Type = HDP_CommandType.INSERT;
|
|
|
|
|
|
|
|
var data = new JObject();
|
|
|
|
foreach (var _config in configList)
|
|
|
|
foreach (var _config in configList)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
command.Data[_config.Value] = _item[_config.Key];
|
|
|
|
data[_config.Value] = _item[_config.Key];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
command.Data = data;
|
|
|
|
|
|
|
|
int _index = responseList.IndexOf(_item);
|
|
|
|
|
|
|
|
commands[_index] = command;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return commands;
|
|
|
|
return commands;
|
|
|
|
}
|
|
|
|
}
|
|
|
|