-
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-9960][Manager] Support to config kafka data node (#10005)
Co-authored-by: castorqin <qhj00725@qq.com> Co-authored-by: Charles Zhang <dockerzhang@apache.org>
- Loading branch information
1 parent
27d5777
commit fbf1ffc
Showing
9 changed files
with
331 additions
and
2 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
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
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
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
78 changes: 78 additions & 0 deletions
78
...anager-pojo/src/main/java/org/apache/inlong/manager/pojo/node/kafka/KafkaDataNodeDTO.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,78 @@ | ||
/* | ||
* 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.kafka; | ||
|
||
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 io.swagger.annotations.ApiModelProperty; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
import org.apache.commons.lang3.StringUtils; | ||
|
||
import javax.validation.constraints.NotNull; | ||
|
||
/** | ||
* Kafka data node info | ||
*/ | ||
@Data | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@ApiModel("Kafka data node info") | ||
public class KafkaDataNodeDTO { | ||
|
||
@ApiModelProperty("kafka bootstrapServers") | ||
private String bootstrapServers; | ||
|
||
@ApiModelProperty("kafka client id") | ||
private String clientId; | ||
|
||
@ApiModelProperty(value = "kafka produce confirmation mechanism") | ||
private String ack; | ||
|
||
@ApiModelProperty("audit set name") | ||
private String auditSetName; | ||
|
||
/** | ||
* Get the dto instance from the request | ||
*/ | ||
public static KafkaDataNodeDTO getFromRequest(KafkaDataNodeRequest request, String extParams) { | ||
KafkaDataNodeDTO dto = StringUtils.isNotBlank(extParams) | ||
? KafkaDataNodeDTO.getFromJson(extParams) | ||
: new KafkaDataNodeDTO(); | ||
return CommonBeanUtils.copyProperties(request, dto, true); | ||
} | ||
|
||
/** | ||
* Get the dto instance from the JSON string. | ||
*/ | ||
public static KafkaDataNodeDTO getFromJson(@NotNull String extParams) { | ||
try { | ||
return JsonUtils.parseObject(extParams, KafkaDataNodeDTO.class); | ||
} catch (Exception e) { | ||
throw new BusinessException(ErrorCodeEnum.DATA_NODE_INFO_INCORRECT, | ||
String.format("Failed to parse extParams for kafka node: %s", e.getMessage())); | ||
} | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
...nager-pojo/src/main/java/org/apache/inlong/manager/pojo/node/kafka/KafkaDataNodeInfo.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,61 @@ | ||
/* | ||
* 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.kafka; | ||
|
||
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 io.swagger.annotations.ApiModelProperty; | ||
import lombok.Data; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.ToString; | ||
|
||
/** | ||
* Kafka data node info | ||
*/ | ||
@Data | ||
@ToString(callSuper = true) | ||
@EqualsAndHashCode(callSuper = true) | ||
@JsonTypeDefine(value = DataNodeType.KAFKA) | ||
@ApiModel("Kafka data node info") | ||
public class KafkaDataNodeInfo extends DataNodeInfo { | ||
|
||
@ApiModelProperty("kafka bootstrapServers") | ||
private String bootstrapServers; | ||
|
||
@ApiModelProperty("kafka client id") | ||
private String clientId; | ||
|
||
@ApiModelProperty(value = "kafka produce confirmation mechanism") | ||
private String ack; | ||
|
||
@ApiModelProperty("audit set name") | ||
private String auditSetName; | ||
|
||
public KafkaDataNodeInfo() { | ||
this.setType(DataNodeType.KAFKA); | ||
} | ||
|
||
@Override | ||
public KafkaDataNodeRequest genRequest() { | ||
return CommonBeanUtils.copyProperties(this, KafkaDataNodeRequest::new); | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
...er-pojo/src/main/java/org/apache/inlong/manager/pojo/node/kafka/KafkaDataNodeRequest.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,55 @@ | ||
/* | ||
* 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.kafka; | ||
|
||
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 io.swagger.annotations.ApiModelProperty; | ||
import lombok.Data; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.ToString; | ||
|
||
/** | ||
* Kafka data node request | ||
*/ | ||
@Data | ||
@ToString(callSuper = true) | ||
@EqualsAndHashCode(callSuper = true) | ||
@JsonTypeDefine(value = DataNodeType.KAFKA) | ||
@ApiModel("Kafka data node request") | ||
public class KafkaDataNodeRequest extends DataNodeRequest { | ||
|
||
@ApiModelProperty("kafka bootstrapServers") | ||
private String bootstrapServers; | ||
|
||
@ApiModelProperty("kafka client id") | ||
private String clientId; | ||
|
||
@ApiModelProperty(value = "kafka produce confirmation mechanism") | ||
private String ack; | ||
|
||
@ApiModelProperty("audit set name") | ||
private String auditSetName; | ||
|
||
public KafkaDataNodeRequest() { | ||
this.setType(DataNodeType.KAFKA); | ||
} | ||
} |
122 changes: 122 additions & 0 deletions
122
...ice/src/main/java/org/apache/inlong/manager/service/node/kafka/KafkaDataNodeOperator.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,122 @@ | ||
/* | ||
* 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.kafka; | ||
|
||
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.common.util.Preconditions; | ||
import org.apache.inlong.manager.dao.entity.DataNodeEntity; | ||
import org.apache.inlong.manager.pojo.cluster.kafka.KafkaClusterInfo; | ||
import org.apache.inlong.manager.pojo.node.DataNodeInfo; | ||
import org.apache.inlong.manager.pojo.node.DataNodeRequest; | ||
import org.apache.inlong.manager.pojo.node.kafka.KafkaDataNodeDTO; | ||
import org.apache.inlong.manager.pojo.node.kafka.KafkaDataNodeInfo; | ||
import org.apache.inlong.manager.pojo.node.kafka.KafkaDataNodeRequest; | ||
import org.apache.inlong.manager.service.node.AbstractDataNodeOperator; | ||
import org.apache.inlong.manager.service.resource.queue.kafka.KafkaUtils; | ||
|
||
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; | ||
import org.springframework.web.client.RestTemplate; | ||
|
||
/** | ||
* Kafka data node operator | ||
*/ | ||
@Service | ||
public class KafkaDataNodeOperator extends AbstractDataNodeOperator { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(KafkaDataNodeOperator.class); | ||
|
||
@Autowired | ||
private ObjectMapper objectMapper; | ||
|
||
@Autowired | ||
private RestTemplate restTemplate; | ||
|
||
@Override | ||
public Boolean accept(String dataNodeType) { | ||
return getDataNodeType().equals(dataNodeType); | ||
} | ||
|
||
@Override | ||
public String getDataNodeType() { | ||
return DataNodeType.KAFKA; | ||
} | ||
|
||
@Override | ||
public DataNodeInfo getFromEntity(DataNodeEntity entity) { | ||
if (entity == null) { | ||
throw new BusinessException(ErrorCodeEnum.DATA_NODE_NOT_FOUND); | ||
} | ||
|
||
KafkaDataNodeInfo kafkaDataNodeInfo = new KafkaDataNodeInfo(); | ||
CommonBeanUtils.copyProperties(entity, kafkaDataNodeInfo); | ||
if (StringUtils.isNotBlank(entity.getExtParams())) { | ||
KafkaDataNodeDTO dto = KafkaDataNodeDTO.getFromJson(entity.getExtParams()); | ||
CommonBeanUtils.copyProperties(dto, kafkaDataNodeInfo); | ||
} | ||
return kafkaDataNodeInfo; | ||
} | ||
|
||
@Override | ||
protected void setTargetEntity(DataNodeRequest request, DataNodeEntity targetEntity) { | ||
KafkaDataNodeRequest nodeRequest = (KafkaDataNodeRequest) request; | ||
CommonBeanUtils.copyProperties(nodeRequest, targetEntity, true); | ||
try { | ||
KafkaDataNodeDTO dto = KafkaDataNodeDTO.getFromRequest(nodeRequest, targetEntity.getExtParams()); | ||
targetEntity.setExtParams(objectMapper.writeValueAsString(dto)); | ||
} catch (Exception e) { | ||
throw new BusinessException(ErrorCodeEnum.DATA_NODE_INFO_INCORRECT, | ||
String.format("Failed to build extParams for kafka node: %s", e.getMessage())); | ||
} | ||
} | ||
|
||
@Override | ||
public Boolean testConnection(DataNodeRequest request) { | ||
KafkaDataNodeRequest kafkaDataNodeRequest = (KafkaDataNodeRequest) request; | ||
String bootstrapServers = kafkaDataNodeRequest.getBootstrapServers(); | ||
Preconditions.expectNotBlank(bootstrapServers, ErrorCodeEnum.INVALID_PARAMETER, | ||
"connection bootstrapServers cannot be empty"); | ||
if (getKafkaConnection(bootstrapServers)) { | ||
LOGGER.info("kafka connection success for bootstrapServers={}", | ||
bootstrapServers); | ||
} | ||
return true; | ||
} | ||
|
||
private boolean getKafkaConnection(String bootstrapServers) { | ||
KafkaClusterInfo kafkaClusterInfo = KafkaClusterInfo.builder().bootstrapServers(bootstrapServers).build(); | ||
try { | ||
|
||
// test connect for kafka adminUrl | ||
KafkaUtils.getAdminClient(kafkaClusterInfo); | ||
return true; | ||
} catch (Exception e) { | ||
String errMsg = String.format("Kafka connection failed for bootstrapServers=%s", | ||
kafkaClusterInfo.getBootstrapServers()); | ||
LOGGER.error(errMsg, e); | ||
throw new BusinessException(errMsg); | ||
} | ||
} | ||
} |
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