[monitor-collector-scheduler] 监控探测接口,一次性临时任务调度编码
This commit is contained in:
@@ -43,5 +43,10 @@
|
||||
<artifactId>gson</artifactId>
|
||||
<version>2.8.8</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.protobuf</groupId>
|
||||
<artifactId>protobuf-java-util</artifactId>
|
||||
<version>3.19.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.usthe.common.entity.job;
|
||||
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.usthe.common.entity.message.CollectRep;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
@@ -67,6 +69,7 @@ public class Job {
|
||||
/**
|
||||
* collector使用 - 任务版本,此字段不存储于etcd
|
||||
*/
|
||||
@JsonIgnore
|
||||
private transient long version;
|
||||
/**
|
||||
* collector使用 - 指标组任务执行优先级视图
|
||||
@@ -78,10 +81,17 @@ public class Job {
|
||||
* 126 - otherMetrics
|
||||
* 127 - lastPriorMetrics
|
||||
*/
|
||||
@JsonIgnore
|
||||
private transient List<Set<Metrics>> priorMetrics;
|
||||
|
||||
/**
|
||||
* collector使用 - 构造初始化指标组
|
||||
* collector使用 - 临时存储一次性任务指标组响应数据
|
||||
*/
|
||||
@JsonIgnore
|
||||
private transient List<CollectRep.MetricsData> metricsDataTemps;
|
||||
|
||||
/**
|
||||
* collector使用 - 构造初始化指标组执行视图
|
||||
*/
|
||||
public synchronized void constructPriorMetrics() {
|
||||
Map<Byte, List<Metrics>> map = metrics.stream()
|
||||
@@ -155,4 +165,11 @@ public class Job {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
}
|
||||
|
||||
public void addCollectMetricsData(CollectRep.MetricsData metricsData) {
|
||||
if (metricsDataTemps == null) {
|
||||
metricsDataTemps = new LinkedList<>();
|
||||
}
|
||||
metricsDataTemps.add(metricsData);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.usthe.common.util;
|
||||
|
||||
import com.google.protobuf.Message;
|
||||
import com.google.protobuf.MessageOrBuilder;
|
||||
import com.google.protobuf.util.JsonFormat;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* protobuf json相互转换工具类
|
||||
* @author tomsun28
|
||||
* @date 2021/11/16 12:16
|
||||
*/
|
||||
@Slf4j
|
||||
public class ProtoJsonUtil {
|
||||
|
||||
/**
|
||||
* protobuf 转 json
|
||||
* @param proto protobuf
|
||||
* @return json
|
||||
*/
|
||||
public static String toJsonStr(Message proto) {
|
||||
try {
|
||||
return JsonFormat.printer().print(proto);
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* json转protobuf
|
||||
* @param json json str
|
||||
* @param builder proto instance builder
|
||||
* @return protobuf
|
||||
*/
|
||||
public static Message toProtobuf(String json, Message.Builder builder) {
|
||||
try {
|
||||
JsonFormat.parser().merge(json, builder);
|
||||
return builder.build();
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user