Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[INLONG-8392][Manager] Optimize the HeartbeatMsg class #9512

Merged
merged 3 commits into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* 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.common.heartbeat;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class AddressInfo {

/**
* Ip of component
*/
private String ip;

/**
* Port of component
*/
private String port;

/**
* Report source type of component
*/
private String reportSourceType;

private String protocolType;

}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ public class HeartbeatMsg {
*/
private String port;

private List<AddressInfo> addressInfos;

/**
* ProtocolType of component
*/
Expand All @@ -60,6 +62,11 @@ public class HeartbeatMsg {
*/
private String componentType;

/**
* Type of report source
*/
private String reportSourceType;

/**
* Report time millis of component
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* 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.common.heartbeat;

/**
* Constants of reportResource
*/
public class ReportResourceType {

public static final String INLONG = "INLONG";

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public class DataProxyNodeResponse {
@Deprecated
private Integer clusterId;

private String reportSourceType;

/**
* Is the DataProxy cluster an intranet? 0: no, 1: yes
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* 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.cluster.dataproxy;

import org.apache.inlong.common.heartbeat.ReportResourceType;
import org.apache.inlong.manager.common.enums.ErrorCodeEnum;
import org.apache.inlong.manager.common.exceptions.BusinessException;
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 javax.validation.constraints.NotNull;

/**
* DataProxy cluster node info
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@ApiModel("DataProxy cluster node info")
public class DataProxyClusterNodeDTO {

@ApiModelProperty("Report source type")
private String reportSourceType = ReportResourceType.INLONG;

/**
* Get the dto instance from the request
*/
public static DataProxyClusterNodeDTO getFromRequest(DataProxyClusterNodeRequest request) {
return DataProxyClusterNodeDTO.builder()
.reportSourceType(request.getReportSourceType())
.build();
}

/**
* Get the dto instance from the JSON string.
*/
public static DataProxyClusterNodeDTO getFromJson(@NotNull String extParams) {
try {
return JsonUtils.parseObject(extParams, DataProxyClusterNodeDTO.class);
} catch (Exception e) {
throw new BusinessException(ErrorCodeEnum.CLUSTER_INFO_INCORRECT.getMessage() + ": " + e.getMessage());
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* 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.cluster.dataproxy;

import org.apache.inlong.manager.common.enums.ClusterType;
import org.apache.inlong.manager.common.util.JsonTypeDefine;
import org.apache.inlong.manager.pojo.cluster.ClusterNodeRequest;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;

/**
* Inlong cluster node request for Agent
*/
@Data
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
@JsonTypeDefine(value = ClusterType.DATAPROXY)
@ApiModel("Inlong cluster node request for dataproxy")
public class DataProxyClusterNodeRequest extends ClusterNodeRequest {

@ApiModelProperty("Report source type")
private String reportSourceType;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* 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.cluster.dataproxy;

import org.apache.inlong.manager.common.enums.ClusterType;
import org.apache.inlong.manager.common.util.JsonTypeDefine;
import org.apache.inlong.manager.pojo.cluster.ClusterNodeResponse;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;

/**
* Dataproxy cluster node response
*/
@Data
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
@JsonTypeDefine(value = ClusterType.DATAPROXY)
@ApiModel("Inlong cluster node response for dataproxy")
public class DataProxyClusterNodeResponse extends ClusterNodeResponse {

@ApiModelProperty("Report source type")
private String reportSourceType;

}
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,16 @@ List<ClusterNodeResponse> listNodeByGroupId(
*/
DataProxyNodeResponse getDataProxyNodes(String inlongGroupId, String protocolType);

/**
* Query data proxy nodes by the given inlong group id and protocol type
*
* @param clusterName inlong cluster name
* @param protocolType protocol type
* @param reportSourceType report source type
* @return data proxy node response
*/
DataProxyNodeResponse getDataProxyNodesByCluster(String clusterName, String protocolType, String reportSourceType);

/**
* Get the configuration of DataProxy through the cluster name to which DataProxy belongs.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import org.apache.inlong.common.constant.Constants;
import org.apache.inlong.common.constant.MQType;
import org.apache.inlong.common.heartbeat.ReportResourceType;
import org.apache.inlong.common.pojo.audit.AuditConfig;
import org.apache.inlong.common.pojo.audit.MQInfo;
import org.apache.inlong.common.pojo.dataproxy.DataProxyCluster;
Expand Down Expand Up @@ -60,6 +61,7 @@
import org.apache.inlong.manager.pojo.cluster.TenantClusterTagInfo;
import org.apache.inlong.manager.pojo.cluster.TenantClusterTagPageRequest;
import org.apache.inlong.manager.pojo.cluster.TenantClusterTagRequest;
import org.apache.inlong.manager.pojo.cluster.dataproxy.DataProxyClusterNodeDTO;
import org.apache.inlong.manager.pojo.cluster.pulsar.PulsarClusterDTO;
import org.apache.inlong.manager.pojo.common.PageResult;
import org.apache.inlong.manager.pojo.common.UpdateResult;
Expand Down Expand Up @@ -1178,6 +1180,60 @@ public DataProxyNodeResponse getDataProxyNodes(String groupId, String protocolTy
return response;
}

@Override
public DataProxyNodeResponse getDataProxyNodesByCluster(String clusterName, String protocolType,
String reportSourceType) {
LOGGER.debug("begin to get data proxy nodes for clusterName={}, protocol={}", clusterName, protocolType);
InlongClusterEntity clusterEntity = clusterMapper.selectByNameAndType(clusterName, ClusterType.DATAPROXY);
DataProxyNodeResponse response = new DataProxyNodeResponse();
if (clusterEntity == null) {
LOGGER.debug("not any dataproxy cluster for clusterName={}, protocol={}", clusterName, protocolType);
return response;
}
List<InlongClusterNodeEntity> nodeEntities =
clusterNodeMapper.selectByParentId(clusterEntity.getId(), protocolType);
if (CollectionUtils.isEmpty(nodeEntities)) {
LOGGER.debug("not any data proxy node for clusterName={}, protocol={}", clusterName, protocolType);
return response;
}
// all cluster nodes belong to the same clusterId
response.setClusterId(clusterEntity.getId());
// TODO consider the data proxy load and re-balance
List<DataProxyNodeInfo> nodeList = new ArrayList<>();
for (InlongClusterNodeEntity nodeEntity : nodeEntities) {
if (Objects.equals(nodeEntity.getStatus(), NodeStatus.HEARTBEAT_TIMEOUT.getStatus())) {
LOGGER.debug("dataproxy node was timeout, parentId={} ip={} port={}", nodeEntity.getParentId(),
nodeEntity.getIp(), nodeEntity.getPort());
continue;
}
if (StringUtils.isNotBlank(nodeEntity.getExtParams())) {
DataProxyClusterNodeDTO dataProxyClusterNodeDTO = DataProxyClusterNodeDTO.getFromJson(
nodeEntity.getExtParams());
if (StringUtils.isBlank(dataProxyClusterNodeDTO.getReportSourceType())) {
dataProxyClusterNodeDTO.setReportSourceType(ReportResourceType.INLONG);
}
if (StringUtils.isNotBlank(reportSourceType) && !Objects.equals(
dataProxyClusterNodeDTO.getReportSourceType(), reportSourceType)) {
continue;
}
}
DataProxyNodeInfo nodeInfo = new DataProxyNodeInfo();
nodeInfo.setId(nodeEntity.getId());
nodeInfo.setIp(nodeEntity.getIp());
nodeInfo.setPort(nodeEntity.getPort());
nodeInfo.setProtocolType(nodeEntity.getProtocolType());
nodeInfo.setNodeLoad(nodeEntity.getNodeLoad());
nodeList.add(nodeInfo);
}
response.setNodeList(nodeList);

if (LOGGER.isDebugEnabled()) {
LOGGER.debug("success to get dp nodes for clusterName={}, protocol={}, result={}",
clusterName, protocolType, response);
}
return response;
}

private List<InlongClusterNodeEntity> getClusterNodes(String groupId, String clusterType, String protocolType) {
InlongGroupEntity groupEntity = groupMapper.selectByGroupId(groupId);
if (groupEntity == null) {
Expand Down
Loading