This is an automated email from the ASF dual-hosted git repository.

zhonghongsheng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new 7425d9b3835 Use jackson replace gson when generate pipeline id (#25538)
7425d9b3835 is described below

commit 7425d9b383528acb21ee96b73f5e8ac20e48d838
Author: Xinze Guo <[email protected]>
AuthorDate: Wed May 10 11:15:13 2023 +0800

    Use jackson replace gson when generate pipeline id (#25538)
    
    * Use jackson replace gson
    
    * improve cdc client connect
    
    * Add doc
    
    * Add readJson method
---
 .../data/pipeline/cdc/client/CDCClient.java        |  6 +-
 kernel/data-pipeline/core/pom.xml                  |  5 ++
 .../data/pipeline/core/util/JsonUtils.java         | 72 ++++++++++++++++++++++
 .../ingest/wal/decode/MppdbDecodingPlugin.java     | 18 +-----
 .../migration/api/impl/MigrationJobAPI.java        |  5 +-
 .../ral/queryable/ShowMigrationRuleExecutor.java   |  6 +-
 6 files changed, 87 insertions(+), 25 deletions(-)

diff --git 
a/kernel/data-pipeline/cdc/client/src/main/java/org/apache/shardingsphere/data/pipeline/cdc/client/CDCClient.java
 
b/kernel/data-pipeline/cdc/client/src/main/java/org/apache/shardingsphere/data/pipeline/cdc/client/CDCClient.java
index 459e6da6e4e..ef502c6c4ec 100644
--- 
a/kernel/data-pipeline/cdc/client/src/main/java/org/apache/shardingsphere/data/pipeline/cdc/client/CDCClient.java
+++ 
b/kernel/data-pipeline/cdc/client/src/main/java/org/apache/shardingsphere/data/pipeline/cdc/client/CDCClient.java
@@ -98,8 +98,10 @@ public final class CDCClient {
         try {
             ChannelFuture future = bootstrap.connect(address, port).sync();
             future.channel().closeFuture().sync();
-        } catch (final InterruptedException ex) {
-            log.warn("CDC client interrupted", ex);
+            // CHECKSTYLE:OFF
+        } catch (final Exception ex) {
+            // CHECKSTYLE:ON
+            log.warn("CDC connect failed", ex);
             group.shutdownGracefully();
         }
     }
diff --git a/kernel/data-pipeline/core/pom.xml 
b/kernel/data-pipeline/core/pom.xml
index de8ab5f62b2..ed35bad3ea4 100644
--- a/kernel/data-pipeline/core/pom.xml
+++ b/kernel/data-pipeline/core/pom.xml
@@ -78,6 +78,11 @@
             <artifactId>HikariCP</artifactId>
             <scope>compile</scope>
         </dependency>
+
+        <dependency>
+            <groupId>com.fasterxml.jackson.core</groupId>
+            <artifactId>jackson-databind</artifactId>
+        </dependency>
         
         <dependency>
             <groupId>org.apache.shardingsphere</groupId>
diff --git 
a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/util/JsonUtils.java
 
b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/util/JsonUtils.java
new file mode 100644
index 00000000000..7ca3dc737db
--- /dev/null
+++ 
b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/util/JsonUtils.java
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.data.pipeline.core.util;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import lombok.extern.slf4j.Slf4j;
+import 
org.apache.shardingsphere.data.pipeline.core.exception.PipelineInternalException;
+
+/**
+ * Json utils.
+ */
+@Slf4j
+public final class JsonUtils {
+    
+    private static final ObjectMapper OBJECT_MAPPER;
+    
+    static {
+        OBJECT_MAPPER = new ObjectMapper();
+        
OBJECT_MAPPER.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, 
false);
+    }
+    
+    /**
+     * To json string.
+     *
+     * @param value value
+     * @return json string
+     * @throws PipelineInternalException pipeline internal exception
+     */
+    public static String toJson(final Object value) {
+        try {
+            return OBJECT_MAPPER.writeValueAsString(value);
+        } catch (final JsonProcessingException ex) {
+            log.error("Convert to json failed, value={}", value, ex);
+            throw new PipelineInternalException(ex);
+        }
+    }
+    
+    /**
+     * Read json string.
+     *
+     * @param jsonString json string
+     * @param clazz class
+     * @param <T> type of class
+     * @return object from json
+     * @throws PipelineInternalException pipeline internal exception
+     */
+    public static <T> T readJson(final String jsonString, final Class<T> 
clazz) {
+        try {
+            return OBJECT_MAPPER.readValue(jsonString, clazz);
+        } catch (final JsonProcessingException ex) {
+            log.error("Parse json failed, jsonString={}", jsonString, ex);
+            throw new PipelineInternalException(ex);
+        }
+    }
+}
diff --git 
a/kernel/data-pipeline/dialect/opengauss/src/main/java/org/apache/shardingsphere/data/pipeline/opengauss/ingest/wal/decode/MppdbDecodingPlugin.java
 
b/kernel/data-pipeline/dialect/opengauss/src/main/java/org/apache/shardingsphere/data/pipeline/opengauss/ingest/wal/decode/MppdbDecodingPlugin.java
index 7a787084f58..980e2ff3c5b 100644
--- 
a/kernel/data-pipeline/dialect/opengauss/src/main/java/org/apache/shardingsphere/data/pipeline/opengauss/ingest/wal/decode/MppdbDecodingPlugin.java
+++ 
b/kernel/data-pipeline/dialect/opengauss/src/main/java/org/apache/shardingsphere/data/pipeline/opengauss/ingest/wal/decode/MppdbDecodingPlugin.java
@@ -17,14 +17,11 @@
 
 package org.apache.shardingsphere.data.pipeline.opengauss.ingest.wal.decode;
 
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.DeserializationFeature;
-import com.fasterxml.jackson.databind.ObjectMapper;
 import com.google.common.base.Preconditions;
 import lombok.AllArgsConstructor;
-import 
org.apache.shardingsphere.data.pipeline.core.exception.PipelineInternalException;
 import 
org.apache.shardingsphere.data.pipeline.core.ingest.IngestDataChangeType;
 import 
org.apache.shardingsphere.data.pipeline.core.ingest.exception.IngestException;
+import org.apache.shardingsphere.data.pipeline.core.util.JsonUtils;
 import 
org.apache.shardingsphere.data.pipeline.postgresql.ingest.wal.decode.BaseLogSequenceNumber;
 import 
org.apache.shardingsphere.data.pipeline.postgresql.ingest.wal.decode.BaseTimestampUtils;
 import 
org.apache.shardingsphere.data.pipeline.postgresql.ingest.wal.decode.DecodingException;
@@ -54,13 +51,6 @@ import java.util.List;
 @AllArgsConstructor
 public final class MppdbDecodingPlugin implements DecodingPlugin {
     
-    private static final ObjectMapper OBJECT_MAPPER;
-    
-    static {
-        OBJECT_MAPPER = new ObjectMapper();
-        
OBJECT_MAPPER.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, 
false);
-    }
-    
     private final BaseTimestampUtils timestampUtils;
     
     private final boolean decodeWithTX;
@@ -106,11 +96,7 @@ public final class MppdbDecodingPlugin implements 
DecodingPlugin {
     
     private AbstractRowEvent readTableEvent(final String mppData) {
         MppTableData mppTableData;
-        try {
-            mppTableData = OBJECT_MAPPER.readValue(mppData, 
MppTableData.class);
-        } catch (final JsonProcessingException ex) {
-            throw new PipelineInternalException(ex);
-        }
+        mppTableData = JsonUtils.readJson(mppData, MppTableData.class);
         AbstractRowEvent result;
         String rowEventType = mppTableData.getOpType();
         switch (rowEventType) {
diff --git 
a/kernel/data-pipeline/scenario/migration/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/migration/api/impl/MigrationJobAPI.java
 
b/kernel/data-pipeline/scenario/migration/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/migration/api/impl/MigrationJobAPI.java
index dc19ef8215e..bf95b49d6f6 100644
--- 
a/kernel/data-pipeline/scenario/migration/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/migration/api/impl/MigrationJobAPI.java
+++ 
b/kernel/data-pipeline/scenario/migration/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/migration/api/impl/MigrationJobAPI.java
@@ -62,6 +62,7 @@ import 
org.apache.shardingsphere.data.pipeline.core.job.PipelineJobIdUtils;
 import 
org.apache.shardingsphere.data.pipeline.core.metadata.loader.PipelineSchemaUtils;
 import 
org.apache.shardingsphere.data.pipeline.core.sharding.ShardingColumnsExtractor;
 import 
org.apache.shardingsphere.data.pipeline.core.util.JobDataNodeLineConvertUtils;
+import org.apache.shardingsphere.data.pipeline.core.util.JsonUtils;
 import org.apache.shardingsphere.data.pipeline.scenario.migration.MigrationJob;
 import 
org.apache.shardingsphere.data.pipeline.scenario.migration.MigrationJobId;
 import 
org.apache.shardingsphere.data.pipeline.scenario.migration.MigrationJobType;
@@ -118,8 +119,6 @@ import java.util.stream.Collectors;
 @Slf4j
 public final class MigrationJobAPI extends 
AbstractInventoryIncrementalJobAPIImpl {
     
-    private static final Gson GSON = new Gson();
-    
     private final PipelineDataSourcePersistService dataSourcePersistService = 
new PipelineDataSourcePersistService();
     
     /**
@@ -220,7 +219,7 @@ public final class MigrationJobAPI extends 
AbstractInventoryIncrementalJobAPIImp
     
     @Override
     protected String marshalJobIdLeftPart(final PipelineJobId pipelineJobId) {
-        String text = GSON.toJson(pipelineJobId);
+        String text = JsonUtils.toJson(pipelineJobId);
         return DigestUtils.md5Hex(text.getBytes(StandardCharsets.UTF_8));
     }
     
diff --git 
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowMigrationRuleExecutor.java
 
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowMigrationRuleExecutor.java
index 2907ed469a9..07ef1acb50f 100644
--- 
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowMigrationRuleExecutor.java
+++ 
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowMigrationRuleExecutor.java
@@ -17,11 +17,11 @@
 
 package org.apache.shardingsphere.proxy.backend.handler.distsql.ral.queryable;
 
-import com.google.gson.Gson;
 import 
org.apache.shardingsphere.data.pipeline.api.config.process.PipelineProcessConfiguration;
 import 
org.apache.shardingsphere.data.pipeline.core.api.InventoryIncrementalJobAPI;
 import org.apache.shardingsphere.data.pipeline.core.api.PipelineJobAPI;
 import org.apache.shardingsphere.data.pipeline.core.context.PipelineContextKey;
+import org.apache.shardingsphere.data.pipeline.core.util.JsonUtils;
 import 
org.apache.shardingsphere.distsql.handler.ral.query.QueryableRALExecutor;
 import 
org.apache.shardingsphere.distsql.parser.statement.ral.queryable.ShowMigrationRuleStatement;
 import 
org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
@@ -36,8 +36,6 @@ import java.util.LinkedList;
  */
 public final class ShowMigrationRuleExecutor implements 
QueryableRALExecutor<ShowMigrationRuleStatement> {
     
-    private static final Gson GSON = new Gson();
-    
     @Override
     public Collection<LocalDataQueryResultRow> getRows(final 
ShowMigrationRuleStatement sqlStatement) {
         PipelineProcessConfiguration processConfig = 
((InventoryIncrementalJobAPI) TypedSPILoader.getService(PipelineJobAPI.class, 
"MIGRATION"))
@@ -48,7 +46,7 @@ public final class ShowMigrationRuleExecutor implements 
QueryableRALExecutor<Sho
     }
     
     private String getString(final Object obj) {
-        return null == obj ? "" : GSON.toJson(obj);
+        return null == obj ? "" : JsonUtils.toJson(obj);
     }
     
     @Override

Reply via email to