You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@inlong.apache.org by GitBox <gi...@apache.org> on 2022/03/02 08:06:59 UTC

[GitHub] [incubator-inlong] EMsnap commented on a change in pull request #2778: [INLONG-2654][Agent] Report heartbeat to manager

EMsnap commented on a change in pull request #2778:
URL: https://github.com/apache/incubator-inlong/pull/2778#discussion_r817433626



##########
File path: inlong-agent/agent-common/src/main/java/org/apache/inlong/agent/constant/FetcherConstants.java
##########
@@ -36,15 +36,18 @@
     public static final String AGENT_MANAGER_VIP_HTTP_PREFIX_PATH = "agent.manager.vip.http.prefix.path";
     public static final String DEFAULT_AGENT_MANAGER_VIP_HTTP_PREFIX_PATH = "/api/inlong/manager/openapi";
 
-    public static final String AGENT_MANAGER_TASK_HTTP_PATH = "agent.manager.vip.http.task.path";
-    public static final String DEFAULT_AGENT_MANAGER_TASK_HTTP_PATH = "/fileAgent/getTaskConf";
+    public static final String AGENT_MANAGER_TASK_HTTP_PATH = "agent.manager.task.path";
+    public static final String DEFAULT_AGENT_MANAGER_TASK_HTTP_PATH = "/agent/getTask";

Review comment:
       pls change conf about this param

##########
File path: inlong-agent/agent-core/src/main/java/org/apache/inlong/agent/core/HeartbeatManager.java
##########
@@ -0,0 +1,163 @@
+/**
+ * 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.agent.core;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.inlong.agent.common.AbstractDaemon;
+import org.apache.inlong.agent.conf.AgentConfiguration;
+import org.apache.inlong.agent.core.job.JobManager;
+import org.apache.inlong.agent.core.job.JobWrapper;
+import org.apache.inlong.agent.utils.ExcuteLinux;
+import org.apache.inlong.agent.utils.HttpManager;
+import org.apache.inlong.common.pojo.agent.TaskSnapshotMessage;
+import org.apache.inlong.common.pojo.agent.TaskSnapshotRequest;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+
+import static org.apache.inlong.agent.constant.AgentConstants.AGENT_LOCAL_IP;
+import static org.apache.inlong.agent.constant.AgentConstants.AGENT_LOCAL_UUID;
+import static org.apache.inlong.agent.constant.FetcherConstants.AGENT_MANAGER_REPORTSNAPSHOT_HTTP_PATH;
+import static org.apache.inlong.agent.constant.FetcherConstants.AGENT_MANAGER_VIP_HTTP_HOST;
+import static org.apache.inlong.agent.constant.FetcherConstants.AGENT_MANAGER_VIP_HTTP_PORT;
+import static org.apache.inlong.agent.constant.FetcherConstants.AGENT_MANAGER_VIP_HTTP_PREFIX_PATH;
+import static org.apache.inlong.agent.constant.FetcherConstants.DEFAULT_AGENT_MANAGER_REPORTSNAPSHOT_HTTP_PATH;
+import static org.apache.inlong.agent.constant.FetcherConstants.DEFAULT_AGENT_MANAGER_VIP_HTTP_PREFIX_PATH;
+import static org.apache.inlong.agent.constant.FetcherConstants.DEFAULT_LOCAL_IP;
+
+public class HeartbeatManager  extends AbstractDaemon {
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(HeartbeatManager.class);
+
+    private final AgentManager agentManager;
+    private final JobManager jobmanager;
+    private final AgentConfiguration conf;
+    private final HttpManager httpManager;
+    private final String baseManagerUrl;
+    private final String reportSnapshotUrl;
+
+    /**
+     * Init heartbeat manager.
+     */
+    public HeartbeatManager(AgentManager agentManager) {
+        this.agentManager = agentManager;
+        jobmanager = agentManager.getJobManager();
+        conf = AgentConfiguration.getAgentConf();
+        httpManager = new HttpManager(conf);
+        baseManagerUrl = buildBaseUrl();
+        reportSnapshotUrl = builReportSnapShotUrl(baseManagerUrl);
+    }
+
+    /**
+     * fetch heartbeat of job
+     * @return
+     */
+    private TaskSnapshotRequest getHeartBeat() {
+        AgentManager agentManager = new AgentManager();
+        HeartbeatManager heartbeatManager = new HeartbeatManager(agentManager);
+        JobManager jobManager = agentManager.getJobManager();
+        Map<String, JobWrapper> jobWrapperMap = jobManager.getJobs();
+
+        List<TaskSnapshotMessage> taskSnapshotMessageList = new ArrayList<>();
+        TaskSnapshotRequest taskSnapshotRequest = new TaskSnapshotRequest();
+        TaskSnapshotMessage snapshotMessage = new TaskSnapshotMessage();
+
+        Date date = new Date(System.currentTimeMillis());
+
+        for (Map.Entry<String, JobWrapper> entry:jobWrapperMap.entrySet()) {
+            if (StringUtils.isBlank(entry.getKey()) || entry.getValue() == null) {
+                LOGGER.info(" key : {} , value : {} exits null",entry.getKey(),entry.getValue());
+                continue;
+            }
+            String offset = entry.getValue().getSnapshot();
+            String jobId = entry.getKey();
+            snapshotMessage.setSnapshot(offset);
+            snapshotMessage.setJobId(Integer.valueOf(jobId));
+            taskSnapshotMessageList.add(snapshotMessage);
+
+        }
+        taskSnapshotRequest.setSnapshotList(taskSnapshotMessageList);
+        taskSnapshotRequest.setReportTime(date);
+        taskSnapshotRequest.setAgentIp(fetchLocalIp());
+        taskSnapshotRequest.setUuid(fetchLocalUuid());
+        return taskSnapshotRequest;
+    }
+
+    /**
+     * check agent ip from manager
+     */
+    private String fetchLocalIp() {

Review comment:
       extract to utils

##########
File path: inlong-agent/agent-common/src/main/java/org/apache/inlong/agent/constant/FetcherConstants.java
##########
@@ -36,15 +36,18 @@
     public static final String AGENT_MANAGER_VIP_HTTP_PREFIX_PATH = "agent.manager.vip.http.prefix.path";
     public static final String DEFAULT_AGENT_MANAGER_VIP_HTTP_PREFIX_PATH = "/api/inlong/manager/openapi";
 
-    public static final String AGENT_MANAGER_TASK_HTTP_PATH = "agent.manager.vip.http.task.path";
-    public static final String DEFAULT_AGENT_MANAGER_TASK_HTTP_PATH = "/fileAgent/getTaskConf";
+    public static final String AGENT_MANAGER_TASK_HTTP_PATH = "agent.manager.task.path";
+    public static final String DEFAULT_AGENT_MANAGER_TASK_HTTP_PATH = "/agent/getTask";
 
     public static final String AGENT_MANAGER_IP_CHECK_HTTP_PATH = "agent.manager.vip.http.checkIP.path";
     public static final String DEFAULT_AGENT_TDM_IP_CHECK_HTTP_PATH = "/fileAgent/confirmAgentIp";
 
     public static final String AGENT_MANAGER_DBCOLLECT_GETTASK_HTTP_PATH = "agent.manager.dbcollect.gettask.http.path";
     public static final String DEFAULT_AGENT_MANAGER_DBCOLLECTOR_GETTASK_HTTP_PATH = "/dbCollector/getTask";
 
+    public static final String AGENT_MANAGER_REPORTSNAPSHOT_HTTP_PATH = "agent.manager.reportsnapshot.http.path";
+    public static final String DEFAULT_AGENT_MANAGER_REPORTSNAPSHOT_HTTP_PATH = "/agent/reportSnapshot";
+

Review comment:
       add this param to agent conf

##########
File path: inlong-agent/agent-common/src/test/resources/agent.properties
##########
@@ -20,6 +20,6 @@ agent.maxSize=10
 agent.maxBuff=200
 agent.conf.resource=manager
 job.thread.running.core=10
-agent.manager.vip.http.host=
-agent.manager.vip.http.port=
+agent.manager.vip.http.host=127.0.0.1
+agent.manager.vip.http.port=8083

Review comment:
       should change params in the agent.properties corresponding to the code  pls

##########
File path: inlong-agent/agent-core/src/main/java/org/apache/inlong/agent/core/HeartbeatManager.java
##########
@@ -0,0 +1,163 @@
+/**
+ * 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.agent.core;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.inlong.agent.common.AbstractDaemon;
+import org.apache.inlong.agent.conf.AgentConfiguration;
+import org.apache.inlong.agent.core.job.JobManager;
+import org.apache.inlong.agent.core.job.JobWrapper;
+import org.apache.inlong.agent.utils.ExcuteLinux;
+import org.apache.inlong.agent.utils.HttpManager;
+import org.apache.inlong.common.pojo.agent.TaskSnapshotMessage;
+import org.apache.inlong.common.pojo.agent.TaskSnapshotRequest;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+
+import static org.apache.inlong.agent.constant.AgentConstants.AGENT_LOCAL_IP;
+import static org.apache.inlong.agent.constant.AgentConstants.AGENT_LOCAL_UUID;
+import static org.apache.inlong.agent.constant.FetcherConstants.AGENT_MANAGER_REPORTSNAPSHOT_HTTP_PATH;
+import static org.apache.inlong.agent.constant.FetcherConstants.AGENT_MANAGER_VIP_HTTP_HOST;
+import static org.apache.inlong.agent.constant.FetcherConstants.AGENT_MANAGER_VIP_HTTP_PORT;
+import static org.apache.inlong.agent.constant.FetcherConstants.AGENT_MANAGER_VIP_HTTP_PREFIX_PATH;
+import static org.apache.inlong.agent.constant.FetcherConstants.DEFAULT_AGENT_MANAGER_REPORTSNAPSHOT_HTTP_PATH;
+import static org.apache.inlong.agent.constant.FetcherConstants.DEFAULT_AGENT_MANAGER_VIP_HTTP_PREFIX_PATH;
+import static org.apache.inlong.agent.constant.FetcherConstants.DEFAULT_LOCAL_IP;
+
+public class HeartbeatManager  extends AbstractDaemon {
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(HeartbeatManager.class);
+
+    private final AgentManager agentManager;
+    private final JobManager jobmanager;
+    private final AgentConfiguration conf;
+    private final HttpManager httpManager;
+    private final String baseManagerUrl;
+    private final String reportSnapshotUrl;
+
+    /**
+     * Init heartbeat manager.
+     */
+    public HeartbeatManager(AgentManager agentManager) {
+        this.agentManager = agentManager;
+        jobmanager = agentManager.getJobManager();
+        conf = AgentConfiguration.getAgentConf();
+        httpManager = new HttpManager(conf);
+        baseManagerUrl = buildBaseUrl();
+        reportSnapshotUrl = builReportSnapShotUrl(baseManagerUrl);
+    }
+
+    /**
+     * fetch heartbeat of job
+     * @return
+     */
+    private TaskSnapshotRequest getHeartBeat() {
+        AgentManager agentManager = new AgentManager();
+        HeartbeatManager heartbeatManager = new HeartbeatManager(agentManager);
+        JobManager jobManager = agentManager.getJobManager();
+        Map<String, JobWrapper> jobWrapperMap = jobManager.getJobs();
+
+        List<TaskSnapshotMessage> taskSnapshotMessageList = new ArrayList<>();
+        TaskSnapshotRequest taskSnapshotRequest = new TaskSnapshotRequest();
+        TaskSnapshotMessage snapshotMessage = new TaskSnapshotMessage();
+
+        Date date = new Date(System.currentTimeMillis());
+
+        for (Map.Entry<String, JobWrapper> entry:jobWrapperMap.entrySet()) {
+            if (StringUtils.isBlank(entry.getKey()) || entry.getValue() == null) {
+                LOGGER.info(" key : {} , value : {} exits null",entry.getKey(),entry.getValue());
+                continue;
+            }
+            String offset = entry.getValue().getSnapshot();
+            String jobId = entry.getKey();
+            snapshotMessage.setSnapshot(offset);
+            snapshotMessage.setJobId(Integer.valueOf(jobId));
+            taskSnapshotMessageList.add(snapshotMessage);
+
+        }
+        taskSnapshotRequest.setSnapshotList(taskSnapshotMessageList);
+        taskSnapshotRequest.setReportTime(date);
+        taskSnapshotRequest.setAgentIp(fetchLocalIp());
+        taskSnapshotRequest.setUuid(fetchLocalUuid());
+        return taskSnapshotRequest;
+    }
+
+    /**
+     * check agent ip from manager
+     */
+    private String fetchLocalIp() {
+        String localIp = AgentConfiguration.getAgentConf().get(AGENT_LOCAL_IP, DEFAULT_LOCAL_IP);
+        return localIp;
+    }
+
+    /**
+     * check agent uuid from manager
+     */
+    private String  fetchLocalUuid() {

Review comment:
       this method is in utils




-- 
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: commits-unsubscribe@inlong.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org