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/02/28 06:32:51 UTC

[GitHub] [incubator-inlong] LvJiancheng opened a new pull request #2778: [INLONG-2654] heartbeat report to manager

LvJiancheng opened a new pull request #2778:
URL: https://github.com/apache/incubator-inlong/pull/2778


   ### Title Name: [INLONG-2654] report heartbeat to manager from agent
   
   where *XYZ* should be replaced by the actual issue number.
   
   Fixes #2654
   
   ### Motivation
   
   *Explain here the context, and why you're making that change. What is the problem you're trying to solve.*
   
   ### Modifications
   
   *Describe the modifications you've done.*
   
   ### Verifying this change
   
   - [ ] Make sure that the change passes the CI checks.
   
   *(Please pick either of the following options)*
   
   This change is a trivial rework / code cleanup without any test coverage.
   
   *(or)*
   
   This change is already covered by existing tests, such as *(please describe tests)*.
   
   *(or)*
   
   This change added tests and can be verified as follows:
   
   *(example:)*
     - *Added integration tests for end-to-end deployment with large payloads (10MB)*
     - *Extended integration test for recovery after broker failure*
   
   ### Documentation
   
     - Does this pull request introduce a new feature? (yes / no)
     - If yes, how is the feature documented? (not applicable / docs / JavaDocs / not documented)
     - If a feature is not applicable for documentation, explain why?
     - If a feature is not documented yet in this PR, please create a followup issue for adding the documentation
   


-- 
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



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

Posted by GitBox <gi...@apache.org>.
LvJiancheng commented on a change in pull request #2778:
URL: https://github.com/apache/incubator-inlong/pull/2778#discussion_r816628303



##########
File path: inlong-agent/agent-core/pom.xml
##########
@@ -84,5 +84,16 @@
             <groupId>io.prometheus</groupId>
             <artifactId>simpleclient_httpserver</artifactId>
         </dependency>
+        <dependency>
+            <groupId>com.typesafe.akka</groupId>
+            <artifactId>akka-stream_2.11</artifactId>
+            <scope>compile</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework</groupId>
+            <artifactId>spring-context</artifactId>
+            <version>5.3.13</version>

Review comment:
       done




-- 
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



[GitHub] [incubator-inlong] healchow merged pull request #2778: [INLONG-2654][Agent] Report heartbeat to manager

Posted by GitBox <gi...@apache.org>.
healchow merged pull request #2778:
URL: https://github.com/apache/incubator-inlong/pull/2778


   


-- 
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



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

Posted by GitBox <gi...@apache.org>.
healchow commented on a change in pull request #2778:
URL: https://github.com/apache/incubator-inlong/pull/2778#discussion_r815635890



##########
File path: inlong-common/src/main/java/org/apache/inlong/common/pojo/agent/TaskSnapshotRequest.java
##########
@@ -23,31 +23,29 @@
 import java.util.Date;
 import java.util.List;
 
-/**

Review comment:
       Why remove those Javadoc?

##########
File path: inlong-agent/agent-common/src/main/java/org/apache/inlong/agent/utils/HttpManager.java
##########
@@ -84,6 +86,13 @@ public String doSentPost(String url, Object dto) {
         return null;
     }
 
+    public static String toJsonStr(Object obj) {
+        GsonBuilder gsonBuilder = new GsonBuilder();

Review comment:
       The instance of `Gson` should be static and final, as it is a thread-safe class.

##########
File path: inlong-common/src/main/java/org/apache/inlong/common/pojo/agent/TaskSnapshotRequest.java
##########
@@ -23,31 +23,29 @@
 import java.util.Date;
 import java.util.List;
 
-/**
- * Request of the agent task snapshot
- */
 @Data
 public class TaskSnapshotRequest {
 
     /**
-     * The ip of agent

Review comment:
       Why use lower-case instead of upper-case?

##########
File path: inlong-agent/agent-core/pom.xml
##########
@@ -84,5 +84,17 @@
             <groupId>io.prometheus</groupId>
             <artifactId>simpleclient_httpserver</artifactId>
         </dependency>
+        <dependency>
+            <groupId>com.typesafe.akka</groupId>
+            <artifactId>akka-stream_2.11</artifactId>
+            <version>2.5.21</version>

Review comment:
       In the sub-module, just use the `${xxx.version}` instead of a specific version number.

##########
File path: inlong-agent/conf/agent.properties
##########
@@ -71,6 +71,7 @@ job.finish.checkInterval=6
 
 
 
+

Review comment:
       Do we need so much blank lines?




-- 
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



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

Posted by GitBox <gi...@apache.org>.
LvJiancheng commented on a change in pull request #2778:
URL: https://github.com/apache/incubator-inlong/pull/2778#discussion_r817712503



##########
File path: inlong-agent/agent-common/src/main/java/org/apache/inlong/agent/utils/AgentUtils.java
##########
@@ -328,6 +333,23 @@ public static String getmValue(String addictiveAttr) {
         return mValueAttrs.getLeft();
     }
 
+    /**
+     * check agent ip from manager
+     */
+    public static String fetchLocalIp() {

Review comment:
       done




-- 
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



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

Posted by GitBox <gi...@apache.org>.
LvJiancheng commented on a change in pull request #2778:
URL: https://github.com/apache/incubator-inlong/pull/2778#discussion_r817595129



##########
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:
       done




-- 
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



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

Posted by GitBox <gi...@apache.org>.
LvJiancheng commented on a change in pull request #2778:
URL: https://github.com/apache/incubator-inlong/pull/2778#discussion_r815801999



##########
File path: inlong-agent/conf/agent.properties
##########
@@ -71,6 +71,7 @@ job.finish.checkInterval=6
 
 
 
+

Review comment:
       done




-- 
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



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

Posted by GitBox <gi...@apache.org>.
LvJiancheng commented on a change in pull request #2778:
URL: https://github.com/apache/incubator-inlong/pull/2778#discussion_r815807761



##########
File path: inlong-agent/agent-core/pom.xml
##########
@@ -84,5 +84,17 @@
             <groupId>io.prometheus</groupId>
             <artifactId>simpleclient_httpserver</artifactId>
         </dependency>
+        <dependency>
+            <groupId>com.typesafe.akka</groupId>
+            <artifactId>akka-stream_2.11</artifactId>
+            <version>2.5.21</version>

Review comment:
       done




-- 
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



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

Posted by GitBox <gi...@apache.org>.
LvJiancheng commented on a change in pull request #2778:
URL: https://github.com/apache/incubator-inlong/pull/2778#discussion_r817709567



##########
File path: inlong-agent/agent-common/src/main/java/org/apache/inlong/agent/constant/JobConstants.java
##########
@@ -43,7 +43,7 @@
 
     //File job
     public static final String JOB_TRIGGER = "job.fileJob.trigger";
-    public static final String JOB_LINE_FILTER_PATTERN = "job.fileJob.dir.pattern";
+    public static final String JOB_LINE_FILTER_PATTERN = "job.fileJob.pattern";

Review comment:
       done




-- 
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



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

Posted by GitBox <gi...@apache.org>.
LvJiancheng commented on a change in pull request #2778:
URL: https://github.com/apache/incubator-inlong/pull/2778#discussion_r816676923



##########
File path: inlong-agent/agent-core/pom.xml
##########
@@ -84,5 +84,16 @@
             <groupId>io.prometheus</groupId>
             <artifactId>simpleclient_httpserver</artifactId>
         </dependency>
+        <dependency>
+            <groupId>com.typesafe.akka</groupId>
+            <artifactId>akka-stream_2.11</artifactId>
+            <scope>compile</scope>

Review comment:
       done

##########
File path: inlong-agent/agent-core/pom.xml
##########
@@ -84,5 +84,16 @@
             <groupId>io.prometheus</groupId>
             <artifactId>simpleclient_httpserver</artifactId>
         </dependency>
+        <dependency>
+            <groupId>com.typesafe.akka</groupId>
+            <artifactId>akka-stream_2.11</artifactId>
+            <scope>compile</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework</groupId>
+            <artifactId>spring-context</artifactId>
+            <version>5.3.13</version>

Review comment:
       done




-- 
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



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

Posted by GitBox <gi...@apache.org>.
LvJiancheng commented on a change in pull request #2778:
URL: https://github.com/apache/incubator-inlong/pull/2778#discussion_r816744988



##########
File path: inlong-agent/agent-core/pom.xml
##########
@@ -84,5 +84,16 @@
             <groupId>io.prometheus</groupId>
             <artifactId>simpleclient_httpserver</artifactId>
         </dependency>
+        <dependency>
+            <groupId>com.typesafe.akka</groupId>
+            <artifactId>akka-stream_2.11</artifactId>
+            <scope>compile</scope>

Review comment:
       done




-- 
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



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

Posted by GitBox <gi...@apache.org>.
LvJiancheng commented on a change in pull request #2778:
URL: https://github.com/apache/incubator-inlong/pull/2778#discussion_r815802291



##########
File path: inlong-common/src/main/java/org/apache/inlong/common/pojo/agent/TaskSnapshotRequest.java
##########
@@ -23,31 +23,29 @@
 import java.util.Date;
 import java.util.List;
 
-/**
- * Request of the agent task snapshot
- */
 @Data
 public class TaskSnapshotRequest {
 
     /**
-     * The ip of agent

Review comment:
       huve update the codes

##########
File path: inlong-common/src/main/java/org/apache/inlong/common/pojo/agent/TaskSnapshotRequest.java
##########
@@ -23,31 +23,29 @@
 import java.util.Date;
 import java.util.List;
 
-/**
- * Request of the agent task snapshot
- */
 @Data
 public class TaskSnapshotRequest {
 
     /**
-     * The ip of agent

Review comment:
       have update the codes




-- 
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



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

Posted by GitBox <gi...@apache.org>.
healchow commented on a change in pull request #2778:
URL: https://github.com/apache/incubator-inlong/pull/2778#discussion_r816598042



##########
File path: inlong-agent/agent-common/src/main/java/org/apache/inlong/agent/constant/FetcherConstants.java
##########
@@ -33,24 +33,30 @@
     public static final String AGENT_MANAGER_VIP_HTTP_PATH = "agent.manager.vip.http.managerIp.path";
     public static final String DEFAULT_AGENT_TDM_VIP_HTTP_PATH = "/agent/getInLongManagerIp";
 
-    public static final String AGENT_MANAGER_VIP_HTTP_PREFIX_PATH = "agent.manager.vip.http.prefix.path";
+    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";
+
     public static final String AGENT_HTTP_APPLICATION_JSON = "application/json";
 
     public static final int AGENT_HTTP_SUCCESS_CODE = 200;
 
     public static final String DEFAULT_LOCAL_IP = "127.0.0.1";
 
+    public static final String DEFAULT_AGENT_MANAGER_VIP_HTTP_HOST = "127.0.0.1";

Review comment:
       Why use a final IP and port? 
   Maybe getting from outer config is better.

##########
File path: inlong-agent/agent-core/pom.xml
##########
@@ -84,5 +84,16 @@
             <groupId>io.prometheus</groupId>
             <artifactId>simpleclient_httpserver</artifactId>
         </dependency>
+        <dependency>
+            <groupId>com.typesafe.akka</groupId>
+            <artifactId>akka-stream_2.11</artifactId>
+            <scope>compile</scope>

Review comment:
       The default scope is `compile`, so this line can be removed.

##########
File path: inlong-agent/agent-core/pom.xml
##########
@@ -84,5 +84,16 @@
             <groupId>io.prometheus</groupId>
             <artifactId>simpleclient_httpserver</artifactId>
         </dependency>
+        <dependency>
+            <groupId>com.typesafe.akka</groupId>
+            <artifactId>akka-stream_2.11</artifactId>
+            <scope>compile</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework</groupId>
+            <artifactId>spring-context</artifactId>
+            <version>5.3.13</version>

Review comment:
       Please use a `${xxx.version}` instead of a specified version number.




-- 
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



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

Posted by GitBox <gi...@apache.org>.
LvJiancheng commented on a change in pull request #2778:
URL: https://github.com/apache/incubator-inlong/pull/2778#discussion_r815826190



##########
File path: inlong-agent/agent-common/src/main/java/org/apache/inlong/agent/utils/HttpManager.java
##########
@@ -84,6 +86,13 @@ public String doSentPost(String url, Object dto) {
         return null;
     }
 
+    public static String toJsonStr(Object obj) {
+        GsonBuilder gsonBuilder = new GsonBuilder();

Review comment:
       done




-- 
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



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

Posted by GitBox <gi...@apache.org>.
LvJiancheng commented on a change in pull request #2778:
URL: https://github.com/apache/incubator-inlong/pull/2778#discussion_r816685736



##########
File path: inlong-agent/agent-common/src/main/java/org/apache/inlong/agent/constant/FetcherConstants.java
##########
@@ -33,24 +33,30 @@
     public static final String AGENT_MANAGER_VIP_HTTP_PATH = "agent.manager.vip.http.managerIp.path";
     public static final String DEFAULT_AGENT_TDM_VIP_HTTP_PATH = "/agent/getInLongManagerIp";
 
-    public static final String AGENT_MANAGER_VIP_HTTP_PREFIX_PATH = "agent.manager.vip.http.prefix.path";
+    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";
+
     public static final String AGENT_HTTP_APPLICATION_JSON = "application/json";
 
     public static final int AGENT_HTTP_SUCCESS_CODE = 200;
 
     public static final String DEFAULT_LOCAL_IP = "127.0.0.1";
 
+    public static final String DEFAULT_AGENT_MANAGER_VIP_HTTP_HOST = "127.0.0.1";

Review comment:
       ok ,good idea 




-- 
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



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

Posted by GitBox <gi...@apache.org>.
LvJiancheng commented on a change in pull request #2778:
URL: https://github.com/apache/incubator-inlong/pull/2778#discussion_r817594801



##########
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:
       done




-- 
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



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

Posted by GitBox <gi...@apache.org>.
healchow commented on a change in pull request #2778:
URL: https://github.com/apache/incubator-inlong/pull/2778#discussion_r817685275



##########
File path: inlong-agent/agent-core/src/main/java/org/apache/inlong/agent/core/HeartbeatManager.java
##########
@@ -0,0 +1,143 @@
+/**
+ * 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.AgentUtils;
+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.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;
+
+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(AgentUtils.fetchLocalIp());
+        taskSnapshotRequest.setUuid(AgentUtils.fetchLocalUuid());
+        return taskSnapshotRequest;
+    }
+
+    /**
+     * report heartbeat on time
+     */
+    @Scheduled(cron = "0 0/1 * * * ? *")

Review comment:
       Add a comment for this crontab expression.




-- 
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



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

Posted by GitBox <gi...@apache.org>.
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



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

Posted by GitBox <gi...@apache.org>.
LvJiancheng commented on a change in pull request #2778:
URL: https://github.com/apache/incubator-inlong/pull/2778#discussion_r817595248



##########
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:
       done




-- 
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



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

Posted by GitBox <gi...@apache.org>.
LvJiancheng commented on a change in pull request #2778:
URL: https://github.com/apache/incubator-inlong/pull/2778#discussion_r817594609



##########
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:
       done




-- 
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



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

Posted by GitBox <gi...@apache.org>.
LvJiancheng commented on a change in pull request #2778:
URL: https://github.com/apache/incubator-inlong/pull/2778#discussion_r815801666



##########
File path: inlong-common/src/main/java/org/apache/inlong/common/pojo/agent/TaskSnapshotRequest.java
##########
@@ -23,31 +23,29 @@
 import java.util.Date;
 import java.util.List;
 
-/**

Review comment:
       have updated the code 




-- 
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