-
Notifications
You must be signed in to change notification settings - Fork 533
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[INLONG-9510][Manager] Supports doris database synchronization (#9511)
- Loading branch information
Showing
7 changed files
with
292 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
...anager-pojo/src/main/java/org/apache/inlong/manager/pojo/node/doris/DorisDataNodeDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* 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.pojo.node.doris; | ||
|
||
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.common.util.JsonUtils; | ||
|
||
import io.swagger.annotations.ApiModel; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import javax.validation.constraints.NotNull; | ||
|
||
/** | ||
* Doris data node info | ||
*/ | ||
@Data | ||
@Builder | ||
@NoArgsConstructor | ||
@ApiModel("Doris data node info") | ||
public class DorisDataNodeDTO { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(DorisDataNodeDTO.class); | ||
|
||
/** | ||
* Get the dto instance from the request | ||
*/ | ||
public static DorisDataNodeDTO getFromRequest(DorisDataNodeRequest request, String extParams) throws Exception { | ||
DorisDataNodeDTO dto = StringUtils.isNotBlank(extParams) | ||
? DorisDataNodeDTO.getFromJson(extParams) | ||
: new DorisDataNodeDTO(); | ||
return CommonBeanUtils.copyProperties(request, dto, true); | ||
} | ||
|
||
/** | ||
* Get the dto instance from the JSON string. | ||
*/ | ||
public static DorisDataNodeDTO getFromJson(@NotNull String extParams) { | ||
try { | ||
return JsonUtils.parseObject(extParams, DorisDataNodeDTO.class); | ||
} catch (Exception e) { | ||
throw new BusinessException(ErrorCodeEnum.GROUP_INFO_INCORRECT, | ||
String.format("Failed to parse extParams for Doris node: %s", e.getMessage())); | ||
} | ||
} | ||
|
||
} |
49 changes: 49 additions & 0 deletions
49
...nager-pojo/src/main/java/org/apache/inlong/manager/pojo/node/doris/DorisDataNodeInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* 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.pojo.node.doris; | ||
|
||
import org.apache.inlong.manager.common.consts.DataNodeType; | ||
import org.apache.inlong.manager.common.util.CommonBeanUtils; | ||
import org.apache.inlong.manager.common.util.JsonTypeDefine; | ||
import org.apache.inlong.manager.pojo.node.DataNodeInfo; | ||
|
||
import io.swagger.annotations.ApiModel; | ||
import lombok.Data; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.ToString; | ||
|
||
/** | ||
* Doris data node info | ||
*/ | ||
@Data | ||
@ToString(callSuper = true) | ||
@EqualsAndHashCode(callSuper = true) | ||
@JsonTypeDefine(value = DataNodeType.DORIS) | ||
@ApiModel("Doris data node info") | ||
public class DorisDataNodeInfo extends DataNodeInfo { | ||
|
||
public DorisDataNodeInfo() { | ||
this.setType(DataNodeType.DORIS); | ||
} | ||
|
||
@Override | ||
public DorisDataNodeRequest genRequest() { | ||
return CommonBeanUtils.copyProperties(this, DorisDataNodeRequest::new); | ||
} | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
...er-pojo/src/main/java/org/apache/inlong/manager/pojo/node/doris/DorisDataNodeRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* 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.pojo.node.doris; | ||
|
||
import org.apache.inlong.manager.common.consts.DataNodeType; | ||
import org.apache.inlong.manager.common.util.JsonTypeDefine; | ||
import org.apache.inlong.manager.pojo.node.DataNodeRequest; | ||
|
||
import io.swagger.annotations.ApiModel; | ||
import lombok.Data; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.ToString; | ||
|
||
/** | ||
* Doris data node request | ||
*/ | ||
@Data | ||
@ToString(callSuper = true) | ||
@EqualsAndHashCode(callSuper = true) | ||
@JsonTypeDefine(value = DataNodeType.DORIS) | ||
@ApiModel("Doris data node request") | ||
public class DorisDataNodeRequest extends DataNodeRequest { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
...ice/src/main/java/org/apache/inlong/manager/service/node/doris/DorisDataNodeOperator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* 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.node.doris; | ||
|
||
import org.apache.inlong.manager.common.consts.DataNodeType; | ||
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.DataNodeEntity; | ||
import org.apache.inlong.manager.pojo.node.DataNodeInfo; | ||
import org.apache.inlong.manager.pojo.node.DataNodeRequest; | ||
import org.apache.inlong.manager.pojo.node.doris.DorisDataNodeDTO; | ||
import org.apache.inlong.manager.pojo.node.doris.DorisDataNodeInfo; | ||
import org.apache.inlong.manager.pojo.node.doris.DorisDataNodeRequest; | ||
import org.apache.inlong.manager.service.node.AbstractDataNodeOperator; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class DorisDataNodeOperator extends AbstractDataNodeOperator { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(DorisDataNodeOperator.class); | ||
|
||
@Autowired | ||
private ObjectMapper objectMapper; | ||
|
||
@Override | ||
public Boolean accept(String dataNodeType) { | ||
LOGGER.info("test data type {}, actual type={}", dataNodeType, getDataNodeType()); | ||
return getDataNodeType().equals(dataNodeType); | ||
} | ||
|
||
@Override | ||
public String getDataNodeType() { | ||
return DataNodeType.DORIS; | ||
} | ||
|
||
@Override | ||
public DataNodeInfo getFromEntity(DataNodeEntity entity) { | ||
if (entity == null) { | ||
throw new BusinessException(ErrorCodeEnum.DATA_NODE_NOT_FOUND); | ||
} | ||
DorisDataNodeInfo dorisDataNodeInfo = new DorisDataNodeInfo(); | ||
CommonBeanUtils.copyProperties(entity, dorisDataNodeInfo); | ||
if (StringUtils.isNotBlank(entity.getExtParams())) { | ||
DorisDataNodeDTO dto = DorisDataNodeDTO.getFromJson(entity.getExtParams()); | ||
CommonBeanUtils.copyProperties(dto, dorisDataNodeInfo); | ||
} | ||
return dorisDataNodeInfo; | ||
} | ||
|
||
@Override | ||
protected void setTargetEntity(DataNodeRequest request, DataNodeEntity targetEntity) { | ||
DorisDataNodeRequest nodeRequest = (DorisDataNodeRequest) request; | ||
CommonBeanUtils.copyProperties(nodeRequest, targetEntity, true); | ||
try { | ||
DorisDataNodeDTO dto = DorisDataNodeDTO.getFromRequest(nodeRequest, targetEntity.getExtParams()); | ||
targetEntity.setExtParams(objectMapper.writeValueAsString(dto)); | ||
} catch (Exception e) { | ||
throw new BusinessException(ErrorCodeEnum.SOURCE_INFO_INCORRECT, | ||
String.format("Failed to build extParams for Doris node: %s", e.getMessage())); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters