[scheduler] 初步完成周期任务调度器编码
This commit is contained in:
@@ -17,6 +17,7 @@ import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpUriRequest;
|
||||
import org.apache.http.client.methods.RequestBuilder;
|
||||
import org.apache.http.client.protocol.HttpClientContext;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.client.BasicCredentialsProvider;
|
||||
import org.apache.http.protocol.HttpContext;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
@@ -185,15 +186,16 @@ public class HttpCollectImpl extends AbstractCollect {
|
||||
private HttpUriRequest createHttpRequest(HttpProtocol httpProtocol) {
|
||||
RequestBuilder requestBuilder;
|
||||
// method
|
||||
if (HttpMethod.GET.matches(httpProtocol.getMethod())) {
|
||||
String httpMethod = httpProtocol.getMethod().toUpperCase();
|
||||
if (HttpMethod.GET.matches(httpMethod)) {
|
||||
requestBuilder = RequestBuilder.get();
|
||||
} else if (HttpMethod.POST.matches(httpProtocol.getMethod())) {
|
||||
} else if (HttpMethod.POST.matches(httpMethod)) {
|
||||
requestBuilder = RequestBuilder.post();
|
||||
} else if (HttpMethod.PUT.matches(httpProtocol.getMethod())) {
|
||||
} else if (HttpMethod.PUT.matches(httpMethod)) {
|
||||
requestBuilder = RequestBuilder.put();
|
||||
} else if (HttpMethod.DELETE.matches(httpProtocol.getMethod())) {
|
||||
} else if (HttpMethod.DELETE.matches(httpMethod)) {
|
||||
requestBuilder = RequestBuilder.delete();
|
||||
} else if (HttpMethod.PATCH.matches(httpProtocol.getMethod())) {
|
||||
} else if (HttpMethod.PATCH.matches(httpMethod)) {
|
||||
requestBuilder = RequestBuilder.patch();
|
||||
} else {
|
||||
// not support the method
|
||||
|
||||
@@ -68,7 +68,9 @@ public class CommonDispatcher implements MetricsTaskDispatch, CollectDataDispatc
|
||||
MetricsCollect metricsCollect = null;
|
||||
try {
|
||||
metricsCollect = jobRequestQueue.getJob();
|
||||
workerPool.executeJob(metricsCollect);
|
||||
if (metricsCollect != null) {
|
||||
workerPool.executeJob(metricsCollect);
|
||||
}
|
||||
} catch (RejectedExecutionException rejected) {
|
||||
log.info("[Dispatcher]-the worker pool is full, reject this metrics task, " +
|
||||
"sleep and put in queue again.");
|
||||
@@ -119,7 +121,7 @@ public class CommonDispatcher implements MetricsTaskDispatch, CollectDataDispatc
|
||||
// 将单个应用的采集任务根据其下的指标组拆分为对应的指标组采集任务 AbstractCollect
|
||||
// 将每个指标组放入线程池进行调度
|
||||
Job job = timerJob.getJob();
|
||||
job.constructMetrics();
|
||||
job.constructPriorMetrics();
|
||||
Set<Metrics> metricsSet = job.getNextCollectMetrics(null, true);
|
||||
metricsSet.forEach(metrics -> {
|
||||
MetricsCollect metricsCollect = new MetricsCollect(metrics, timerJob, this);
|
||||
@@ -143,6 +145,8 @@ public class CommonDispatcher implements MetricsTaskDispatch, CollectDataDispatc
|
||||
long spendTime = System.currentTimeMillis() - job.getTimestamp();
|
||||
long interval = job.getInterval() - spendTime / 1000;
|
||||
interval = interval <= 0 ? 0 : interval;
|
||||
// 重置构造执行指标组视图
|
||||
job.constructPriorMetrics();
|
||||
timerDispatch.cyclicJob(timerJob, interval, TimeUnit.SECONDS);
|
||||
} else if (!metricsSet.isEmpty()) {
|
||||
// 当前级别指标组执行完成,开始执行下一级别的指标组
|
||||
|
||||
@@ -155,7 +155,8 @@ public class MetricsCollect implements Runnable, Comparable<MetricsCollect> {
|
||||
}
|
||||
|
||||
private void setNewThreadName(WheelTimerJob timerJob, Metrics metrics) {
|
||||
String currentName = timerJob.getJob().getAppId() + timerJob.getJob().getApp() + metrics.getName() + timerJob.getJob().getId();
|
||||
String currentName = timerJob.getJob().getAppId() + "-" + timerJob.getJob().getApp()
|
||||
+ "-" + metrics.getName() + "-" + timerJob.getJob().getId();
|
||||
Thread.currentThread().setName(currentName);
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ public class KafkaDataExporter {
|
||||
properties.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, kafkaProperties.getServers());
|
||||
properties.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
|
||||
properties.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, KafkaMetricsDataSerializer.class);
|
||||
kafkaProducer = new KafkaProducer<>(properties);
|
||||
// kafkaProducer = new KafkaProducer<>(properties);
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
server:
|
||||
port: 8080
|
||||
port: 8081
|
||||
spring:
|
||||
application:
|
||||
name: ${HOSTNAME:@collecor@}${PID}
|
||||
|
||||
@@ -69,7 +69,7 @@
|
||||
|
||||
<!-- 开发环境配置 -->
|
||||
<springProfile name="dev">
|
||||
<root level="DEBUG">
|
||||
<root level="INFO">
|
||||
<appender-ref ref="ConsoleAppender"/>
|
||||
<appender-ref ref="SystemOutFileAppender"/>
|
||||
<appender-ref ref="ErrOutFileAppender"/>
|
||||
|
||||
Reference in New Issue
Block a user