diff --git a/common/src/main/java/cn/vbill/middleware/porter/common/client/impl/FileClient.java b/common/src/main/java/cn/vbill/middleware/porter/common/client/impl/FileClient.java index e6040bc9..162e4a5c 100644 --- a/common/src/main/java/cn/vbill/middleware/porter/common/client/impl/FileClient.java +++ b/common/src/main/java/cn/vbill/middleware/porter/common/client/impl/FileClient.java @@ -34,6 +34,7 @@ import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; +import java.util.stream.Stream; /** * @author: zhangkewei[zhang_kw@suixingpay.com] @@ -79,8 +80,8 @@ public List getChildren(String path) { @Override public Pair getData(String path) { String content = null; - try (Stream stream = Files.lines(Paths.get(getRealPath(path)))){ - content = stream.reduce((p, n) -> p + n).orElse(""); + try (Stream stream = Files.lines(Paths.get(getRealPath(path)))) { + content = stream.reduce((p, n) -> p + n).orElse(""); } catch (IOException e) { LOGGER.warn("getData {} fail.", path, e); } diff --git a/common/src/main/java/cn/vbill/middleware/porter/common/statistics/StatisticData.java b/common/src/main/java/cn/vbill/middleware/porter/common/statistics/StatisticData.java index 26bb8387..3a7aacae 100644 --- a/common/src/main/java/cn/vbill/middleware/porter/common/statistics/StatisticData.java +++ b/common/src/main/java/cn/vbill/middleware/porter/common/statistics/StatisticData.java @@ -21,10 +21,9 @@ import com.alibaba.fastjson.annotation.JSONField; import lombok.Getter; import lombok.Setter; +import org.apache.commons.lang3.time.FastDateFormat; import org.slf4j.LoggerFactory; -import java.text.DateFormat; -import java.text.SimpleDateFormat; import java.util.Date; import java.util.UUID; @@ -44,7 +43,7 @@ public class StatisticData { @JSONField(serialize = false, deserialize = false) protected static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(StatisticData.class); @JSONField(serialize = false, deserialize = false) - private final DateFormat idDateFormat = new SimpleDateFormat("yyyyMMddHHmmssSSS"); + private final FastDateFormat idDateFormat = FastDateFormat.getInstance("yyyyMMddHHmmssSSS"); // 节点ID @Setter @Getter diff --git a/porter/porter-boot/src/main/java/cn/vbill/middleware/porter/boot/config/SourcesConfig.java b/porter/porter-boot/src/main/java/cn/vbill/middleware/porter/boot/config/SourcesConfig.java index 052a78f7..87634b7b 100644 --- a/porter/porter-boot/src/main/java/cn/vbill/middleware/porter/boot/config/SourcesConfig.java +++ b/porter/porter-boot/src/main/java/cn/vbill/middleware/porter/boot/config/SourcesConfig.java @@ -36,7 +36,7 @@ * @review: zhangkewei[zhang_kw@suixingpay.com]/2017年12月19日 13:59 */ -@ConfigurationProperties(prefix = "node") +@ConfigurationProperties(prefix = "porter") @Component public class SourcesConfig { private Map> source; diff --git a/porter/porter-core/src/main/java/cn/vbill/middleware/porter/core/event/s/converter/OggJsonConverter.java b/porter/porter-core/src/main/java/cn/vbill/middleware/porter/core/event/s/converter/OggJsonConverter.java index a27ad3b3..969306ac 100644 --- a/porter/porter-core/src/main/java/cn/vbill/middleware/porter/core/event/s/converter/OggJsonConverter.java +++ b/porter/porter-core/src/main/java/cn/vbill/middleware/porter/core/event/s/converter/OggJsonConverter.java @@ -25,11 +25,11 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.time.FastDateFormat; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.text.DateFormat; -import java.text.SimpleDateFormat; import java.util.Map; /** @@ -43,8 +43,8 @@ public class OggJsonConverter implements EventConverter { private static final Logger LOGGER = LoggerFactory.getLogger(OggJsonConverter.class); - private DateFormat opTsF = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss.SSS"); - private DateFormat ctsf = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss.SSS"); + private FastDateFormat opTsF = FastDateFormat.getInstance("yyyy-MM-dd hh:mm:ss.SSS"); + private FastDateFormat ctsf = FastDateFormat.getInstance("yyyy-MM-dd'T'hh:mm:ss.SSS"); @Override public String getName() { @@ -72,15 +72,15 @@ public MessageEvent convert(Object... params) { } event.setOpType(eventType); try { - String poTS = obj.getString("op_ts"); - event.setOpTs(opTsF.parse(poTS.substring(0, poTS.length() - 3))); + String poTS = obj.containsKey("op_ts") ? obj.getString("op_ts") : null; + if (StringUtils.isNotEmpty(poTS)) event.setOpTs(opTsF.parse(poTS.substring(0, poTS.length() - 3))); } catch (Exception e) { LOGGER.error("op_ts", e); } try { - String currentTS = obj.getString("current_ts"); - event.setCurrentTs(ctsf.parse(currentTS.substring(0, currentTS.length() - 3))); + String currentTS = obj.containsKey("current_ts") ? obj.getString("current_ts") : null; + if (StringUtils.isNotEmpty(currentTS)) event.setCurrentTs(ctsf.parse(currentTS.substring(0, currentTS.length() - 3))); } catch (Exception e) { LOGGER.error("解析current_ts出错", e); } diff --git a/porter/porter-plugin/kafka-loader/src/main/java/cn/vbill/middleware/porter/plugin/loader/kafka/KafkaLoader.java b/porter/porter-plugin/kafka-loader/src/main/java/cn/vbill/middleware/porter/plugin/loader/kafka/KafkaLoader.java index 19a27b81..6c149b98 100644 --- a/porter/porter-plugin/kafka-loader/src/main/java/cn/vbill/middleware/porter/plugin/loader/kafka/KafkaLoader.java +++ b/porter/porter-plugin/kafka-loader/src/main/java/cn/vbill/middleware/porter/plugin/loader/kafka/KafkaLoader.java @@ -29,6 +29,7 @@ import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import cn.vbill.middleware.porter.core.event.etl.ETLRow; +import org.apache.commons.lang.time.FastDateFormat; import org.apache.commons.lang3.tuple.ImmutablePair; import org.apache.commons.lang3.tuple.ImmutableTriple; import org.apache.commons.lang3.tuple.Pair; @@ -36,8 +37,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.text.DateFormat; -import java.text.SimpleDateFormat; import java.util.*; import java.util.stream.Stream; @@ -52,8 +51,8 @@ public class KafkaLoader extends AbstractDataLoader { private static final Logger LOGGER = LoggerFactory.getLogger(KafkaLoader.class); - private static final DateFormat OP_TS_F = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss.SSS"); - private static final DateFormat C_TS_F = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss.SSS000"); + private static final FastDateFormat OP_TS_F = FastDateFormat.getInstance("yyyy-MM-dd hh:mm:ss.SSS"); + private static final FastDateFormat C_TS_F = FastDateFormat.getInstance("yyyy-MM-dd'T'hh:mm:ss.SSS000"); @Override protected String getPluginName() { return LoaderPlugin.KAFKA_SYNC.getCode();