You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@inlong.apache.org by GitBox <gi...@apache.org> on 2022/05/18 15:00:47 UTC

[GitHub] [incubator-inlong] healchow commented on a diff in pull request #4241: [INLONG-4240][Manager] Support postgres source and sink

healchow commented on code in PR #4241:
URL: https://github.com/apache/incubator-inlong/pull/4241#discussion_r876002410


##########
inlong-manager/manager-common/src/main/java/org/apache/inlong/manager/common/pojo/sink/postgres/PostgresSinkDTO.java:
##########
@@ -0,0 +1,88 @@
+/*
+ * 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.inlong.manager.common.pojo.sink.postgres;
+
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import io.swagger.annotations.ApiModelProperty;
+import java.util.Map;
+import javax.validation.constraints.NotNull;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import org.apache.inlong.manager.common.enums.ErrorCodeEnum;
+import org.apache.inlong.manager.common.exceptions.BusinessException;
+
+/**
+ * Postgres sink info
+ */
+@Data
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
+public class PostgresSinkDTO {
+
+    private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
+
+    @ApiModelProperty("postgres JDBC URL")
+    private String jdbcUrl;
+
+    @ApiModelProperty("Username for JDBC URL")
+    private String username;
+
+    @ApiModelProperty("User password")
+    private String password;
+
+    @ApiModelProperty("Target database name")
+    private String dbName;
+
+    @ApiModelProperty("Target table name")
+    private String tableName;
+
+    @ApiModelProperty("Primary key")
+    private String primaryKey;
+
+    @ApiModelProperty("Properties for postgres")
+    private Map<String, Object> properties;
+
+    /**
+     * Get the dto instance from the request
+     */
+    public static PostgresSinkDTO getFromRequest(PostgresSinkRequest request) {
+        return PostgresSinkDTO.builder()
+                .jdbcUrl(request.getJdbcUrl())
+                .username(request.getUsername())
+                .password(request.getPassword())
+                .dbName(request.getDbName())
+                .primaryKey(request.getPrimaryKey())
+                .tableName(request.getTableName())
+                .properties(request.getProperties())
+                .build();
+    }
+
+    public static PostgresSinkDTO getFromJson(@NotNull String extParams) {

Review Comment:
   Java doc, please.



##########
inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/sink/PostgresSink.java:
##########
@@ -0,0 +1,66 @@
+/*
+ * 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.inlong.manager.client.api.sink;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import java.util.List;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.NoArgsConstructor;
+import org.apache.inlong.manager.client.api.auth.DefaultAuthentication;
+import org.apache.inlong.manager.common.enums.DataFormat;
+import org.apache.inlong.manager.common.enums.SinkType;
+import org.apache.inlong.manager.common.pojo.stream.SinkField;
+import org.apache.inlong.manager.common.pojo.stream.StreamSink;
+
+/**
+ * Postgres sink.
+ */
+@Data
+@EqualsAndHashCode(callSuper = true)
+@NoArgsConstructor
+@AllArgsConstructor
+@ApiModel("Postgres sink configuration")
+public class PostgresSink extends StreamSink {
+
+    @ApiModelProperty(value = "Sink type", required = true)
+    private SinkType sinkType = SinkType.POSTGRES;
+
+    @ApiModelProperty("Postgres JDBC URL")
+    private String jdbcUrl;
+
+    @ApiModelProperty("Target database name")
+    private String dbName;
+
+    @ApiModelProperty("Authentication for postgres")
+    private DefaultAuthentication authentication;
+
+    @ApiModelProperty("Target table name")
+    private String tableName;
+
+    @ApiModelProperty("Data format type for stream sink")
+    private DataFormat dataFormat;

Review Comment:
   Maybe you can resolve like this:
   ```
       @Override
       public DataFormat getDataFormat() {
           return DataFormat.NONE;
       }
   ```



##########
inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/util/InlongStreamSinkTransfer.java:
##########
@@ -299,4 +306,59 @@ private static HiveSink parseHiveSink(HiveSinkResponse sinkResponse, StreamSink
         return hiveSink;
     }
 
+    private static SinkRequest createPostgresRequest(StreamSink streamSink, InlongStreamInfo streamInfo) {

Review Comment:
   Please add java docs for public or static methods, thanks.



##########
inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/util/InlongStreamSourceTransfer.java:
##########
@@ -158,6 +166,26 @@ private static AutoPushSource parseAutoPushSource(AutoPushSourceResponse respons
         return autoPushSource;
     }
 
+    private static PostgresSource parsePostgresSource(PostgresSourceResponse response) {

Review Comment:
   Java doc, please.



##########
inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/util/InlongStreamSourceTransfer.java:
##########
@@ -250,4 +278,28 @@ private static AutoPushSourceRequest createAutoPushSourceRequest(AutoPushSource
         sourceRequest.setFieldList(InlongStreamTransfer.createStreamFields(source.getFields(), streamInfo));
         return sourceRequest;
     }
+
+    private static PostgresSourceRequest createPostgresSourceRequest(PostgresSource source,

Review Comment:
   ditto.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@inlong.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org