healchow commented on code in PR #4211:
URL: https://github.com/apache/incubator-inlong/pull/4211#discussion_r874978338
##########
inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/sort/util/LoadNodeUtils.java:
##########
@@ -161,6 +165,44 @@ public static HiveLoadNode createLoadNode(HiveSinkResponse
hiveSinkResponse) {
);
}
+ public static HbaseLoadNode createLoadNode(HbaseSinkResponse
hbaseSinkResponse) {
Review Comment:
Please add Java doc for the static method, thanks.
##########
inlong-manager/manager-common/src/main/java/org/apache/inlong/manager/common/pojo/sink/hbase/HbaseSinkDTO.java:
##########
@@ -0,0 +1,97 @@
+/*
+ * 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.hbase;
+
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import io.swagger.annotations.ApiModelProperty;
+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;
+
+import javax.validation.constraints.NotNull;
+import java.util.Map;
+
+/**
+ * Hbase sink info
+ */
+@Data
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
+public class HbaseSinkDTO {
+
+ private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
+
+ @ApiModelProperty("Target table name")
+ private String tableName;
+
+ @ApiModelProperty("Namespace")
+ private String nameSpace;
+
+ @ApiModelProperty("Row key")
+ private String rowKey;
+
+ @ApiModelProperty("Zookeeper quorm")
+ private String zookeeperQuorum;
+
+ @ApiModelProperty("Sink buffer flush maxsize")
+ private String sinkBufferFlushMaxSize;
+
+ @ApiModelProperty("Zookeeper znode parent")
+ private String zookeeperZnodeParent;
+
+ @ApiModelProperty("Sink buffer flush max rows")
+ private String sinkBufferFlushMaxRows;
+
+ @ApiModelProperty("Sink buffer flush interval")
+ private String sinkBufferFlushInterval;
+
+ @ApiModelProperty("Properties for hbase")
+ private Map<String, Object> properties;
+
+ /**
+ * Get the dto instance from the request
+ */
+ public static HbaseSinkDTO getFromRequest(HbaseSinkRequest request) {
+ return HbaseSinkDTO.builder()
+ .tableName(request.getTableName())
+ .nameSpace(request.getNameSpace())
+ .rowKey(request.getRowKey())
+ .zookeeperQuorum(request.getZookeeperQuorum())
+ .sinkBufferFlushMaxSize(request.getSinkBufferFlushMaxSize())
+ .zookeeperZnodeParent(request.getZookeeperZnodeParent())
+ .sinkBufferFlushMaxRows(request.getSinkBufferFlushMaxRows())
+ .sinkBufferFlushInterval(request.getSinkBufferFlushInterval())
+ .properties(request.getProperties())
+ .build();
+ }
+
+ public static HbaseSinkDTO getFromJson(@NotNull String extParams) {
Review Comment:
Please add Java doc for the static method, thanks.
##########
inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/util/InlongStreamSinkTransfer.java:
##########
@@ -207,6 +212,65 @@ private static StreamSink parseKafkaSink(KafkaSinkResponse
sinkResponse, StreamS
return kafkaSink;
}
+ private static SinkRequest createHbaseRequest(StreamSink streamSink,
InlongStreamInfo streamInfo) {
Review Comment:
Please add Java doc for the static method, thanks.
##########
inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/util/InlongStreamSinkTransfer.java:
##########
@@ -207,6 +212,65 @@ private static StreamSink parseKafkaSink(KafkaSinkResponse
sinkResponse, StreamS
return kafkaSink;
}
+ private static SinkRequest createHbaseRequest(StreamSink streamSink,
InlongStreamInfo streamInfo) {
+ HbaseSinkRequest hbaseSinkRequest = new HbaseSinkRequest();
+ HbaseSink hbaseSink = (HbaseSink) streamSink;
+ hbaseSinkRequest.setInlongGroupId(streamInfo.getInlongGroupId());
+ hbaseSinkRequest.setInlongStreamId(streamInfo.getInlongStreamId());
+ hbaseSinkRequest.setNameSpace(hbaseSink.getNameSpace());
+ hbaseSinkRequest.setTableName(hbaseSink.getTableName());
+ hbaseSinkRequest.setRowKey(hbaseSink.getRowKey());
+ hbaseSinkRequest.setZookeeperQuorum(hbaseSink.getZookeeperQuorum());
+
hbaseSinkRequest.setZookeeperZnodeParent(hbaseSink.getZookeeperZnodeParent());
+
hbaseSinkRequest.setSinkBufferFlushInterval(hbaseSink.getSinkBufferFlushInterval());
+
hbaseSinkRequest.setSinkBufferFlushMaxRows(hbaseSink.getSinkBufferFlushMaxRows());
+
hbaseSinkRequest.setSinkBufferFlushMaxSize(hbaseSink.getSinkBufferFlushMaxSize());
+ hbaseSinkRequest.setSinkType(hbaseSink.getSinkType().name());
+ hbaseSinkRequest.setEnableCreateResource(hbaseSink.isNeedCreated() ? 1
: 0);
+ hbaseSinkRequest.setProperties(hbaseSink.getProperties());
+ if (CollectionUtils.isNotEmpty(hbaseSink.getSinkFields())) {
+ List<SinkFieldRequest> fieldRequests =
createSinkFieldRequests(hbaseSink.getSinkFields());
+ hbaseSinkRequest.setFieldList(fieldRequests);
+ }
+ return hbaseSinkRequest;
+
+ }
+
+ private static StreamSink parseHbaseSink(HbaseSinkResponse sinkResponse,
StreamSink sink) {
Review Comment:
Please add Java doc for the static method, thanks.
##########
inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/sink/hbase/HbaseSinkOperation.java:
##########
@@ -0,0 +1,233 @@
+/*
+ * 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.hbase;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.github.pagehelper.Page;
+import com.github.pagehelper.PageInfo;
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.inlong.manager.common.enums.ErrorCodeEnum;
+import org.apache.inlong.manager.common.enums.GlobalConstants;
+import org.apache.inlong.manager.common.enums.SinkStatus;
+import org.apache.inlong.manager.common.enums.SinkType;
+import org.apache.inlong.manager.common.exceptions.BusinessException;
+import org.apache.inlong.manager.common.pojo.sink.SinkFieldRequest;
+import org.apache.inlong.manager.common.pojo.sink.SinkFieldResponse;
+import org.apache.inlong.manager.common.pojo.sink.SinkListResponse;
+import org.apache.inlong.manager.common.pojo.sink.SinkRequest;
+import org.apache.inlong.manager.common.pojo.sink.SinkResponse;
+import org.apache.inlong.manager.common.pojo.sink.hbase.HbaseSinkDTO;
+import org.apache.inlong.manager.common.pojo.sink.hbase.HbaseSinkListResponse;
+import org.apache.inlong.manager.common.pojo.sink.hbase.HbaseSinkRequest;
+import org.apache.inlong.manager.common.pojo.sink.hbase.HbaseSinkResponse;
+import org.apache.inlong.manager.common.util.CommonBeanUtils;
+import org.apache.inlong.manager.common.util.Preconditions;
+import org.apache.inlong.manager.dao.entity.StreamSinkEntity;
+import org.apache.inlong.manager.dao.entity.StreamSinkFieldEntity;
+import org.apache.inlong.manager.dao.mapper.StreamSinkEntityMapper;
+import org.apache.inlong.manager.dao.mapper.StreamSinkFieldEntityMapper;
+import org.apache.inlong.manager.service.sink.StreamSinkOperation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.function.Supplier;
+
+/**
+ * Hbase sink operation
+ */
+@Service
+public class HbaseSinkOperation implements StreamSinkOperation {
+
+ private static final Logger LOGGER =
LoggerFactory.getLogger(HbaseSinkOperation.class);
+
+ @Autowired
+ private ObjectMapper objectMapper;
+ @Autowired
+ private StreamSinkEntityMapper sinkMapper;
+ @Autowired
+ private StreamSinkFieldEntityMapper sinkFieldMapper;
+
+ @Override
+ public Boolean accept(SinkType sinkType) {
+ return SinkType.HBASE.equals(sinkType);
+ }
+
+ @Override
+ public Integer saveOpt(SinkRequest request, String operator) {
+ String sinkType = request.getSinkType();
+ Preconditions.checkTrue(SinkType.SINK_HBASE.equals(sinkType),
+ ErrorCodeEnum.SINK_TYPE_NOT_SUPPORT.getMessage() + ": " +
sinkType);
+
+ HbaseSinkRequest hbaseSinkRequest = (HbaseSinkRequest) request;
+ StreamSinkEntity entity =
CommonBeanUtils.copyProperties(hbaseSinkRequest, StreamSinkEntity::new);
+ entity.setStatus(SinkStatus.NEW.getCode());
+ entity.setIsDeleted(GlobalConstants.UN_DELETED);
+ entity.setCreator(operator);
+ entity.setModifier(operator);
+ Date now = new Date();
+ entity.setCreateTime(now);
+ entity.setModifyTime(now);
+
+ // get the ext params
+ HbaseSinkDTO dto = HbaseSinkDTO.getFromRequest(hbaseSinkRequest);
+ try {
+ entity.setExtParams(objectMapper.writeValueAsString(dto));
+ } catch (Exception e) {
+ throw new BusinessException(ErrorCodeEnum.SINK_SAVE_FAILED);
+ }
+ sinkMapper.insert(entity);
+ Integer sinkId = entity.getId();
+ request.setId(sinkId);
+ this.saveFieldOpt(request);
+ return sinkId;
+ }
+
+ @Override
+ public void saveFieldOpt(SinkRequest request) {
+ List<SinkFieldRequest> fieldList = request.getFieldList();
+ LOGGER.info("begin to save hbase field={}", fieldList);
+ if (CollectionUtils.isEmpty(fieldList)) {
+ return;
+ }
+ int size = fieldList.size();
+ List<StreamSinkFieldEntity> entityList = new ArrayList<>(size);
+ String groupId = request.getInlongGroupId();
+ String streamId = request.getInlongStreamId();
+ String sinkType = request.getSinkType();
+ Integer sinkId = request.getId();
+ for (SinkFieldRequest fieldInfo : fieldList) {
+ StreamSinkFieldEntity fieldEntity =
CommonBeanUtils.copyProperties(fieldInfo, StreamSinkFieldEntity::new);
+ if (StringUtils.isEmpty(fieldEntity.getFieldComment())) {
+ fieldEntity.setFieldComment(fieldEntity.getFieldName());
+ }
+ fieldEntity.setInlongGroupId(groupId);
+ fieldEntity.setInlongStreamId(streamId);
+ fieldEntity.setSinkType(sinkType);
+ fieldEntity.setSinkId(sinkId);
+ fieldEntity.setIsDeleted(GlobalConstants.UN_DELETED);
+ entityList.add(fieldEntity);
+ }
+
+ sinkFieldMapper.insertAll(entityList);
+ LOGGER.info("success to save hive field");
+ }
+
+ @Override
+ public SinkResponse getByEntity(StreamSinkEntity entity) {
+ Preconditions.checkNotNull(entity,
ErrorCodeEnum.SINK_INFO_NOT_FOUND.getMessage());
+ String existType = entity.getSinkType();
+ Preconditions.checkTrue(SinkType.SINK_HBASE.equals(existType),
+ String.format(ErrorCodeEnum.SINK_TYPE_NOT_SAME.getMessage(),
SinkType.SINK_HBASE, existType));
+
+ SinkResponse response = this.getFromEntity(entity,
HbaseSinkResponse::new);
+ List<StreamSinkFieldEntity> entities =
sinkFieldMapper.selectBySinkId(entity.getId());
+ List<SinkFieldResponse> infos =
CommonBeanUtils.copyListProperties(entities,
+ SinkFieldResponse::new);
+ response.setFieldList(infos);
+
+ return response;
+ }
+
+ @Override
+ public <T> T getFromEntity(StreamSinkEntity entity, Supplier<T> target) {
+ T result = target.get();
+ if (entity == null) {
+ return result;
+ }
+
+ String existType = entity.getSinkType();
+ Preconditions.checkTrue(SinkType.SINK_HBASE.equals(existType),
+ String.format(ErrorCodeEnum.SINK_TYPE_NOT_SAME.getMessage(),
SinkType.SINK_HBASE, existType));
+
+ HbaseSinkDTO dto = HbaseSinkDTO.getFromJson(entity.getExtParams());
+ CommonBeanUtils.copyProperties(entity, result, true);
+ CommonBeanUtils.copyProperties(dto, result, true);
+
+ return result;
+ }
+
+ @Override
+ public PageInfo<? extends SinkListResponse>
getPageInfo(Page<StreamSinkEntity> entityPage) {
+ if (CollectionUtils.isEmpty(entityPage)) {
+ return new PageInfo<>();
+ }
+ return entityPage.toPageInfo(entity -> this.getFromEntity(entity,
HbaseSinkListResponse::new));
+ }
+
+ @Override
+ public void updateOpt(SinkRequest request, String operator) {
+ String sinkType = request.getSinkType();
+ Preconditions.checkTrue(SinkType.SINK_HBASE.equals(sinkType),
+ String.format(ErrorCodeEnum.SINK_TYPE_NOT_SAME.getMessage(),
SinkType.SINK_HBASE, sinkType));
+
+ StreamSinkEntity entity =
sinkMapper.selectByPrimaryKey(request.getId());
+ Preconditions.checkNotNull(entity,
ErrorCodeEnum.SINK_INFO_NOT_FOUND.getMessage());
+ HbaseSinkRequest hbaseSinkRequest = (HbaseSinkRequest) request;
+ CommonBeanUtils.copyProperties(hbaseSinkRequest, entity, true);
+ try {
+ HbaseSinkDTO dto = HbaseSinkDTO.getFromRequest(hbaseSinkRequest);
+ entity.setExtParams(objectMapper.writeValueAsString(dto));
+ } catch (Exception e) {
+ throw new
BusinessException(ErrorCodeEnum.SINK_INFO_INCORRECT.getMessage());
+ }
+
+ entity.setPreviousStatus(entity.getStatus());
+ entity.setStatus(SinkStatus.CONFIG_ING.getCode());
+ entity.setModifier(operator);
+ entity.setModifyTime(new Date());
+ sinkMapper.updateByPrimaryKeySelective(entity);
+
+ boolean onlyAdd =
SinkStatus.CONFIG_SUCCESSFUL.getCode().equals(entity.getPreviousStatus());
+ this.updateFieldOpt(onlyAdd, hbaseSinkRequest);
+
+ LOGGER.info("success to update sink of type={}", sinkType);
+
Review Comment:
Remove the last unused line, thanks.
--
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]