fuweng11 commented on code in PR #7243:
URL: https://github.com/apache/inlong/pull/7243#discussion_r1093108913


##########
inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/sink/redis/RedisSinkOperator.java:
##########
@@ -0,0 +1,159 @@
+/*
+ * 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.service.sink.redis;
+
+import static org.apache.inlong.manager.common.enums.ErrorCodeEnum.IP_EMPTY;
+import static org.apache.inlong.manager.common.enums.ErrorCodeEnum.PORT_EMPTY;
+import static 
org.apache.inlong.manager.common.enums.ErrorCodeEnum.SINK_SAVE_FAILED;
+import static 
org.apache.inlong.manager.common.enums.ErrorCodeEnum.SINK_TYPE_NOT_SUPPORT;
+import static 
org.apache.inlong.manager.common.util.Preconditions.expectNotBlank;
+import static 
org.apache.inlong.manager.common.util.Preconditions.expectNotEmpty;
+import static 
org.apache.inlong.manager.common.util.Preconditions.expectNotNull;
+import static org.apache.inlong.manager.common.util.Preconditions.expectTrue;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.inlong.manager.common.consts.SinkType;
+import org.apache.inlong.manager.common.enums.ErrorCodeEnum;
+import org.apache.inlong.manager.common.exceptions.BusinessException;
+import org.apache.inlong.manager.common.util.CommonBeanUtils;
+import org.apache.inlong.manager.dao.entity.StreamSinkEntity;
+import org.apache.inlong.manager.pojo.sink.SinkField;
+import org.apache.inlong.manager.pojo.sink.SinkRequest;
+import org.apache.inlong.manager.pojo.sink.StreamSink;
+import org.apache.inlong.manager.pojo.sink.redis.RedisClusterMode;
+import org.apache.inlong.manager.pojo.sink.redis.RedisDataType;
+import org.apache.inlong.manager.pojo.sink.redis.RedisSchemaMapMode;
+import org.apache.inlong.manager.pojo.sink.redis.RedisSink;
+import org.apache.inlong.manager.pojo.sink.redis.RedisSinkDTO;
+import org.apache.inlong.manager.pojo.sink.redis.RedisSinkRequest;
+import org.apache.inlong.manager.service.sink.AbstractSinkOperator;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * Redis sink operator, such as save or update redis field, etc.
+ */
+@Service
+public class RedisSinkOperator extends AbstractSinkOperator {
+
+    private static final Logger LOGGER = 
LoggerFactory.getLogger(RedisSinkOperator.class);
+    private static final int PORT_MAX_VALUE = 65535;
+
+    @Autowired
+    private ObjectMapper objectMapper;
+
+    @Override
+    public Boolean accept(String sinkType) {
+        return SinkType.REDIS.equals(sinkType);
+    }
+
+    @Override
+    protected String getSinkType() {
+        return SinkType.REDIS;
+    }
+
+    @Override
+    protected void setTargetEntity(SinkRequest request, StreamSinkEntity 
targetEntity) {
+
+        if (!this.getSinkType().equals(request.getSinkType())) {
+            throw new BusinessException(ErrorCodeEnum.SINK_SAVE_FAILED,
+                    SINK_TYPE_NOT_SUPPORT.getMessage() + ": " + getSinkType());
+        }
+
+        RedisSinkRequest sinkRequest = (RedisSinkRequest) request;
+
+        String clusterMode = sinkRequest.getClusterMode();
+        RedisClusterMode redisClusterMode = RedisClusterMode.of(clusterMode);
+
+        expectNotNull(redisClusterMode,
+                "Redis ClusterMode must in one of " + 
Arrays.toString(RedisClusterMode.values()) + " !");
+
+        switch (redisClusterMode) {
+            case CLUSTER:
+                String clusterNodes = sinkRequest.getClusterNodes();
+                checkClusterNodes(clusterNodes);
+                break;
+            case SENTINEL:
+                String sentinelMasterName = 
sinkRequest.getSentinelMasterName();
+                expectNotEmpty(sentinelMasterName, "Redis MasterName of 
Sentinel cluster must not null!");
+                String sentinelsInfo = sinkRequest.getSentinelsInfo();
+                expectNotEmpty(sentinelsInfo, "Redis sentinelsInfo of Sentinel 
cluster must not null!");
+                break;
+            case STANDALONE:
+                String host = sinkRequest.getHost();
+                Integer port = sinkRequest.getPort();
+
+                expectNotEmpty(host, "Redis server host must not null!");
+                expectTrue(
+                        port != null && port > 1 && port < PORT_MAX_VALUE,
+                        "The port of the redis server must be greater than 0 
and less than 65535!");
+                break;
+        }
+        RedisDataType dataType = 
RedisDataType.valueOf(sinkRequest.getDataType());
+        expectNotNull(dataType, "Redis DataType must not null");
+
+        RedisSchemaMapMode mapMode = 
RedisSchemaMapMode.valueOf(sinkRequest.getSchemaMapMode());
+        expectTrue(dataType.getMapModes().contains(mapMode),
+                "Redis schemaMapMode '" + mapMode + "' is not supported in '" 
+ dataType + "'");
+
+        try {
+            RedisSinkDTO dto = RedisSinkDTO.getFromRequest(sinkRequest);
+            targetEntity.setExtParams(objectMapper.writeValueAsString(dto));
+        } catch (Exception e) {
+            throw new BusinessException(SINK_SAVE_FAILED,
+                    String.format("serialize extParams of Redis SinkDTO 
failure: %s", e.getMessage()));
+        }
+    }
+
+    private void checkClusterNodes(String clusterNodes) {
+
+        expectTrue(clusterNodes != null && !clusterNodes.isEmpty(), "the nodes 
of Redis cluster must not null");

Review Comment:
   `expectNotBlank`



##########
inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/sink/redis/RedisSinkOperator.java:
##########
@@ -0,0 +1,159 @@
+/*
+ * 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.service.sink.redis;
+
+import static org.apache.inlong.manager.common.enums.ErrorCodeEnum.IP_EMPTY;
+import static org.apache.inlong.manager.common.enums.ErrorCodeEnum.PORT_EMPTY;
+import static 
org.apache.inlong.manager.common.enums.ErrorCodeEnum.SINK_SAVE_FAILED;
+import static 
org.apache.inlong.manager.common.enums.ErrorCodeEnum.SINK_TYPE_NOT_SUPPORT;
+import static 
org.apache.inlong.manager.common.util.Preconditions.expectNotBlank;
+import static 
org.apache.inlong.manager.common.util.Preconditions.expectNotEmpty;
+import static 
org.apache.inlong.manager.common.util.Preconditions.expectNotNull;
+import static org.apache.inlong.manager.common.util.Preconditions.expectTrue;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.inlong.manager.common.consts.SinkType;
+import org.apache.inlong.manager.common.enums.ErrorCodeEnum;
+import org.apache.inlong.manager.common.exceptions.BusinessException;
+import org.apache.inlong.manager.common.util.CommonBeanUtils;
+import org.apache.inlong.manager.dao.entity.StreamSinkEntity;
+import org.apache.inlong.manager.pojo.sink.SinkField;
+import org.apache.inlong.manager.pojo.sink.SinkRequest;
+import org.apache.inlong.manager.pojo.sink.StreamSink;
+import org.apache.inlong.manager.pojo.sink.redis.RedisClusterMode;
+import org.apache.inlong.manager.pojo.sink.redis.RedisDataType;
+import org.apache.inlong.manager.pojo.sink.redis.RedisSchemaMapMode;
+import org.apache.inlong.manager.pojo.sink.redis.RedisSink;
+import org.apache.inlong.manager.pojo.sink.redis.RedisSinkDTO;
+import org.apache.inlong.manager.pojo.sink.redis.RedisSinkRequest;
+import org.apache.inlong.manager.service.sink.AbstractSinkOperator;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * Redis sink operator, such as save or update redis field, etc.
+ */
+@Service
+public class RedisSinkOperator extends AbstractSinkOperator {
+
+    private static final Logger LOGGER = 
LoggerFactory.getLogger(RedisSinkOperator.class);
+    private static final int PORT_MAX_VALUE = 65535;
+
+    @Autowired
+    private ObjectMapper objectMapper;
+
+    @Override
+    public Boolean accept(String sinkType) {
+        return SinkType.REDIS.equals(sinkType);
+    }
+
+    @Override
+    protected String getSinkType() {
+        return SinkType.REDIS;
+    }
+
+    @Override
+    protected void setTargetEntity(SinkRequest request, StreamSinkEntity 
targetEntity) {
+
+        if (!this.getSinkType().equals(request.getSinkType())) {
+            throw new BusinessException(ErrorCodeEnum.SINK_SAVE_FAILED,
+                    SINK_TYPE_NOT_SUPPORT.getMessage() + ": " + getSinkType());
+        }
+
+        RedisSinkRequest sinkRequest = (RedisSinkRequest) request;
+
+        String clusterMode = sinkRequest.getClusterMode();
+        RedisClusterMode redisClusterMode = RedisClusterMode.of(clusterMode);
+
+        expectNotNull(redisClusterMode,
+                "Redis ClusterMode must in one of " + 
Arrays.toString(RedisClusterMode.values()) + " !");
+
+        switch (redisClusterMode) {
+            case CLUSTER:
+                String clusterNodes = sinkRequest.getClusterNodes();
+                checkClusterNodes(clusterNodes);
+                break;
+            case SENTINEL:
+                String sentinelMasterName = 
sinkRequest.getSentinelMasterName();
+                expectNotEmpty(sentinelMasterName, "Redis MasterName of 
Sentinel cluster must not null!");
+                String sentinelsInfo = sinkRequest.getSentinelsInfo();
+                expectNotEmpty(sentinelsInfo, "Redis sentinelsInfo of Sentinel 
cluster must not null!");
+                break;
+            case STANDALONE:
+                String host = sinkRequest.getHost();
+                Integer port = sinkRequest.getPort();
+
+                expectNotEmpty(host, "Redis server host must not null!");

Review Comment:
   `expectNotBlank`



##########
inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/sink/redis/RedisSinkOperator.java:
##########
@@ -0,0 +1,159 @@
+/*
+ * 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.service.sink.redis;
+
+import static org.apache.inlong.manager.common.enums.ErrorCodeEnum.IP_EMPTY;
+import static org.apache.inlong.manager.common.enums.ErrorCodeEnum.PORT_EMPTY;
+import static 
org.apache.inlong.manager.common.enums.ErrorCodeEnum.SINK_SAVE_FAILED;
+import static 
org.apache.inlong.manager.common.enums.ErrorCodeEnum.SINK_TYPE_NOT_SUPPORT;
+import static 
org.apache.inlong.manager.common.util.Preconditions.expectNotBlank;
+import static 
org.apache.inlong.manager.common.util.Preconditions.expectNotEmpty;
+import static 
org.apache.inlong.manager.common.util.Preconditions.expectNotNull;
+import static org.apache.inlong.manager.common.util.Preconditions.expectTrue;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.inlong.manager.common.consts.SinkType;
+import org.apache.inlong.manager.common.enums.ErrorCodeEnum;
+import org.apache.inlong.manager.common.exceptions.BusinessException;
+import org.apache.inlong.manager.common.util.CommonBeanUtils;
+import org.apache.inlong.manager.dao.entity.StreamSinkEntity;
+import org.apache.inlong.manager.pojo.sink.SinkField;
+import org.apache.inlong.manager.pojo.sink.SinkRequest;
+import org.apache.inlong.manager.pojo.sink.StreamSink;
+import org.apache.inlong.manager.pojo.sink.redis.RedisClusterMode;
+import org.apache.inlong.manager.pojo.sink.redis.RedisDataType;
+import org.apache.inlong.manager.pojo.sink.redis.RedisSchemaMapMode;
+import org.apache.inlong.manager.pojo.sink.redis.RedisSink;
+import org.apache.inlong.manager.pojo.sink.redis.RedisSinkDTO;
+import org.apache.inlong.manager.pojo.sink.redis.RedisSinkRequest;
+import org.apache.inlong.manager.service.sink.AbstractSinkOperator;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * Redis sink operator, such as save or update redis field, etc.
+ */
+@Service
+public class RedisSinkOperator extends AbstractSinkOperator {
+
+    private static final Logger LOGGER = 
LoggerFactory.getLogger(RedisSinkOperator.class);
+    private static final int PORT_MAX_VALUE = 65535;
+
+    @Autowired
+    private ObjectMapper objectMapper;
+
+    @Override
+    public Boolean accept(String sinkType) {
+        return SinkType.REDIS.equals(sinkType);
+    }
+
+    @Override
+    protected String getSinkType() {
+        return SinkType.REDIS;
+    }
+
+    @Override
+    protected void setTargetEntity(SinkRequest request, StreamSinkEntity 
targetEntity) {
+
+        if (!this.getSinkType().equals(request.getSinkType())) {
+            throw new BusinessException(ErrorCodeEnum.SINK_SAVE_FAILED,
+                    SINK_TYPE_NOT_SUPPORT.getMessage() + ": " + getSinkType());
+        }
+
+        RedisSinkRequest sinkRequest = (RedisSinkRequest) request;
+
+        String clusterMode = sinkRequest.getClusterMode();
+        RedisClusterMode redisClusterMode = RedisClusterMode.of(clusterMode);
+
+        expectNotNull(redisClusterMode,
+                "Redis ClusterMode must in one of " + 
Arrays.toString(RedisClusterMode.values()) + " !");
+
+        switch (redisClusterMode) {
+            case CLUSTER:
+                String clusterNodes = sinkRequest.getClusterNodes();
+                checkClusterNodes(clusterNodes);
+                break;
+            case SENTINEL:
+                String sentinelMasterName = 
sinkRequest.getSentinelMasterName();
+                expectNotEmpty(sentinelMasterName, "Redis MasterName of 
Sentinel cluster must not null!");
+                String sentinelsInfo = sinkRequest.getSentinelsInfo();
+                expectNotEmpty(sentinelsInfo, "Redis sentinelsInfo of Sentinel 
cluster must not null!");

Review Comment:
   `expectNotBlank`



##########
inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/sink/redis/RedisSinkOperator.java:
##########
@@ -0,0 +1,159 @@
+/*
+ * 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.service.sink.redis;
+
+import static org.apache.inlong.manager.common.enums.ErrorCodeEnum.IP_EMPTY;
+import static org.apache.inlong.manager.common.enums.ErrorCodeEnum.PORT_EMPTY;
+import static 
org.apache.inlong.manager.common.enums.ErrorCodeEnum.SINK_SAVE_FAILED;
+import static 
org.apache.inlong.manager.common.enums.ErrorCodeEnum.SINK_TYPE_NOT_SUPPORT;
+import static 
org.apache.inlong.manager.common.util.Preconditions.expectNotBlank;
+import static 
org.apache.inlong.manager.common.util.Preconditions.expectNotEmpty;
+import static 
org.apache.inlong.manager.common.util.Preconditions.expectNotNull;
+import static org.apache.inlong.manager.common.util.Preconditions.expectTrue;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.inlong.manager.common.consts.SinkType;
+import org.apache.inlong.manager.common.enums.ErrorCodeEnum;
+import org.apache.inlong.manager.common.exceptions.BusinessException;
+import org.apache.inlong.manager.common.util.CommonBeanUtils;
+import org.apache.inlong.manager.dao.entity.StreamSinkEntity;
+import org.apache.inlong.manager.pojo.sink.SinkField;
+import org.apache.inlong.manager.pojo.sink.SinkRequest;
+import org.apache.inlong.manager.pojo.sink.StreamSink;
+import org.apache.inlong.manager.pojo.sink.redis.RedisClusterMode;
+import org.apache.inlong.manager.pojo.sink.redis.RedisDataType;
+import org.apache.inlong.manager.pojo.sink.redis.RedisSchemaMapMode;
+import org.apache.inlong.manager.pojo.sink.redis.RedisSink;
+import org.apache.inlong.manager.pojo.sink.redis.RedisSinkDTO;
+import org.apache.inlong.manager.pojo.sink.redis.RedisSinkRequest;
+import org.apache.inlong.manager.service.sink.AbstractSinkOperator;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * Redis sink operator, such as save or update redis field, etc.
+ */
+@Service
+public class RedisSinkOperator extends AbstractSinkOperator {
+
+    private static final Logger LOGGER = 
LoggerFactory.getLogger(RedisSinkOperator.class);
+    private static final int PORT_MAX_VALUE = 65535;
+
+    @Autowired
+    private ObjectMapper objectMapper;
+
+    @Override
+    public Boolean accept(String sinkType) {
+        return SinkType.REDIS.equals(sinkType);
+    }
+
+    @Override
+    protected String getSinkType() {
+        return SinkType.REDIS;
+    }
+
+    @Override
+    protected void setTargetEntity(SinkRequest request, StreamSinkEntity 
targetEntity) {
+
+        if (!this.getSinkType().equals(request.getSinkType())) {
+            throw new BusinessException(ErrorCodeEnum.SINK_SAVE_FAILED,
+                    SINK_TYPE_NOT_SUPPORT.getMessage() + ": " + getSinkType());
+        }
+
+        RedisSinkRequest sinkRequest = (RedisSinkRequest) request;
+
+        String clusterMode = sinkRequest.getClusterMode();
+        RedisClusterMode redisClusterMode = RedisClusterMode.of(clusterMode);
+
+        expectNotNull(redisClusterMode,
+                "Redis ClusterMode must in one of " + 
Arrays.toString(RedisClusterMode.values()) + " !");
+
+        switch (redisClusterMode) {
+            case CLUSTER:
+                String clusterNodes = sinkRequest.getClusterNodes();
+                checkClusterNodes(clusterNodes);
+                break;
+            case SENTINEL:
+                String sentinelMasterName = 
sinkRequest.getSentinelMasterName();
+                expectNotEmpty(sentinelMasterName, "Redis MasterName of 
Sentinel cluster must not null!");

Review Comment:
   `expectNotBlank`



##########
inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/sink/redis/RedisSinkOperator.java:
##########
@@ -0,0 +1,159 @@
+/*
+ * 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.service.sink.redis;
+
+import static org.apache.inlong.manager.common.enums.ErrorCodeEnum.IP_EMPTY;
+import static org.apache.inlong.manager.common.enums.ErrorCodeEnum.PORT_EMPTY;
+import static 
org.apache.inlong.manager.common.enums.ErrorCodeEnum.SINK_SAVE_FAILED;
+import static 
org.apache.inlong.manager.common.enums.ErrorCodeEnum.SINK_TYPE_NOT_SUPPORT;
+import static 
org.apache.inlong.manager.common.util.Preconditions.expectNotBlank;
+import static 
org.apache.inlong.manager.common.util.Preconditions.expectNotEmpty;
+import static 
org.apache.inlong.manager.common.util.Preconditions.expectNotNull;
+import static org.apache.inlong.manager.common.util.Preconditions.expectTrue;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.inlong.manager.common.consts.SinkType;
+import org.apache.inlong.manager.common.enums.ErrorCodeEnum;
+import org.apache.inlong.manager.common.exceptions.BusinessException;
+import org.apache.inlong.manager.common.util.CommonBeanUtils;
+import org.apache.inlong.manager.dao.entity.StreamSinkEntity;
+import org.apache.inlong.manager.pojo.sink.SinkField;
+import org.apache.inlong.manager.pojo.sink.SinkRequest;
+import org.apache.inlong.manager.pojo.sink.StreamSink;
+import org.apache.inlong.manager.pojo.sink.redis.RedisClusterMode;
+import org.apache.inlong.manager.pojo.sink.redis.RedisDataType;
+import org.apache.inlong.manager.pojo.sink.redis.RedisSchemaMapMode;
+import org.apache.inlong.manager.pojo.sink.redis.RedisSink;
+import org.apache.inlong.manager.pojo.sink.redis.RedisSinkDTO;
+import org.apache.inlong.manager.pojo.sink.redis.RedisSinkRequest;
+import org.apache.inlong.manager.service.sink.AbstractSinkOperator;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * Redis sink operator, such as save or update redis field, etc.
+ */
+@Service
+public class RedisSinkOperator extends AbstractSinkOperator {
+
+    private static final Logger LOGGER = 
LoggerFactory.getLogger(RedisSinkOperator.class);
+    private static final int PORT_MAX_VALUE = 65535;
+
+    @Autowired
+    private ObjectMapper objectMapper;
+
+    @Override
+    public Boolean accept(String sinkType) {
+        return SinkType.REDIS.equals(sinkType);
+    }
+
+    @Override
+    protected String getSinkType() {
+        return SinkType.REDIS;
+    }
+
+    @Override
+    protected void setTargetEntity(SinkRequest request, StreamSinkEntity 
targetEntity) {
+
+        if (!this.getSinkType().equals(request.getSinkType())) {
+            throw new BusinessException(ErrorCodeEnum.SINK_SAVE_FAILED,
+                    SINK_TYPE_NOT_SUPPORT.getMessage() + ": " + getSinkType());
+        }
+
+        RedisSinkRequest sinkRequest = (RedisSinkRequest) request;
+
+        String clusterMode = sinkRequest.getClusterMode();
+        RedisClusterMode redisClusterMode = RedisClusterMode.of(clusterMode);
+
+        expectNotNull(redisClusterMode,
+                "Redis ClusterMode must in one of " + 
Arrays.toString(RedisClusterMode.values()) + " !");
+
+        switch (redisClusterMode) {
+            case CLUSTER:
+                String clusterNodes = sinkRequest.getClusterNodes();
+                checkClusterNodes(clusterNodes);
+                break;
+            case SENTINEL:
+                String sentinelMasterName = 
sinkRequest.getSentinelMasterName();
+                expectNotEmpty(sentinelMasterName, "Redis MasterName of 
Sentinel cluster must not null!");
+                String sentinelsInfo = sinkRequest.getSentinelsInfo();
+                expectNotEmpty(sentinelsInfo, "Redis sentinelsInfo of Sentinel 
cluster must not null!");
+                break;
+            case STANDALONE:
+                String host = sinkRequest.getHost();
+                Integer port = sinkRequest.getPort();
+
+                expectNotEmpty(host, "Redis server host must not null!");
+                expectTrue(
+                        port != null && port > 1 && port < PORT_MAX_VALUE,
+                        "The port of the redis server must be greater than 0 
and less than 65535!");
+                break;
+        }
+        RedisDataType dataType = 
RedisDataType.valueOf(sinkRequest.getDataType());
+        expectNotNull(dataType, "Redis DataType must not null");
+
+        RedisSchemaMapMode mapMode = 
RedisSchemaMapMode.valueOf(sinkRequest.getSchemaMapMode());
+        expectTrue(dataType.getMapModes().contains(mapMode),
+                "Redis schemaMapMode '" + mapMode + "' is not supported in '" 
+ dataType + "'");
+
+        try {
+            RedisSinkDTO dto = RedisSinkDTO.getFromRequest(sinkRequest);
+            targetEntity.setExtParams(objectMapper.writeValueAsString(dto));
+        } catch (Exception e) {
+            throw new BusinessException(SINK_SAVE_FAILED,
+                    String.format("serialize extParams of Redis SinkDTO 
failure: %s", e.getMessage()));
+        }
+    }
+
+    private void checkClusterNodes(String clusterNodes) {
+
+        expectTrue(clusterNodes != null && !clusterNodes.isEmpty(), "the nodes 
of Redis cluster must not null");
+        String[] nodeArray = clusterNodes.split(",");
+        expectNotEmpty(nodeArray, "the nodes of Redis cluster must not null");
+
+        for (String node : nodeArray) {
+            expectTrue(node != null && !node.isEmpty(), "Redis server host 
must not null!");

Review Comment:
   `expectNotBlank`



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to