You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@inlong.apache.org by "justinwwhuang (via GitHub)" <gi...@apache.org> on 2024/03/15 11:43:59 UTC

[PR] [INLONG-9831][Agent] Increase configuration acquisition capability [inlong]

justinwwhuang opened a new pull request, #9832:
URL: https://github.com/apache/inlong/pull/9832

   [INLONG-9831][Agent] Increase configuration acquisition capability
   - Fixes #9831 
   
   ### Motivation
   
   Increase configuration acquisition capability
   ### Modifications
   Increase configuration acquisition capability
   ### Verifying this change
   
   *(Please pick either of the following options)*
   
   - [ ] This change is a trivial rework/code cleanup without any test coverage.
   
   - [ ] This change is already covered by existing tests, such as:
     *(please describe tests)*
   
   - [ ] 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 follow-up 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


Re: [PR] [INLONG-9831][Agent] Increase configuration acquisition capability [inlong]

Posted by "justinwwhuang (via GitHub)" <gi...@apache.org>.
justinwwhuang commented on code in PR #9832:
URL: https://github.com/apache/inlong/pull/9832#discussion_r1527400968


##########
inlong-agent/agent-installer/src/main/java/org/apache/inlong/agent/installer/ModuleManager.java:
##########
@@ -0,0 +1,119 @@
+/*
+ * 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.installer;
+
+import org.apache.inlong.agent.common.AbstractDaemon;
+import org.apache.inlong.agent.installer.conf.InstallerConfiguration;
+import org.apache.inlong.agent.metrics.audit.AuditUtils;
+import org.apache.inlong.agent.utils.AgentUtils;
+import org.apache.inlong.agent.utils.ThreadUtils;
+import org.apache.inlong.common.pojo.agent.installer.ConfigResult;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
+
+/**
+ * Installer Manager, the bridge for job manager, task manager, db e.t.c it manages agent level operations and
+ * communicates with outside system.
+ */
+public class ModuleManager extends AbstractDaemon {
+
+    public static final int CONFIG_QUEUE_CAPACITY = 1;
+    public static final int CORE_THREAD_SLEEP_TIME = 1000;
+    private static final Logger LOGGER = LoggerFactory.getLogger(ModuleManager.class);
+    private final InstallerConfiguration conf;
+    private final BlockingQueue<ConfigResult> configQueue;
+
+    private String curMd5;
+
+    public ModuleManager() {
+        conf = InstallerConfiguration.getInstallerConf();

Review Comment:
   This code is not complete yet, we will use it later



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


Re: [PR] [INLONG-9831][Agent] Increase configuration acquisition capability [inlong]

Posted by "aloyszhang (via GitHub)" <gi...@apache.org>.
aloyszhang commented on code in PR #9832:
URL: https://github.com/apache/inlong/pull/9832#discussion_r1527128840


##########
inlong-agent/agent-installer/src/main/java/org/apache/inlong/agent/installer/ManagerResultFormatter.java:
##########
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.inlong.agent.installer;
+
+import com.google.gson.Gson;
+import com.google.gson.JsonObject;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * check manager interface result with json formatter.
+ */
+public class ManagerResultFormatter {
+
+    public static final String SUCCESS_CODE = "true";
+    private static final Logger LOGGER = LoggerFactory.getLogger(ManagerResultFormatter.class);
+    private static final String RESULT_CODE = "success";
+    private static final String RESULT_DATA = "data";
+    private static final Gson GSON = new Gson();
+
+    /**
+     * get json result
+     *
+     * @return json object
+     */
+    public static JsonObject getResultData(String jsonStr) {
+        JsonObject object = GSON.fromJson(jsonStr, JsonObject.class);
+        if (object == null || !object.has(RESULT_CODE) || !object.has(RESULT_DATA)
+                || !SUCCESS_CODE.equals(object.get(RESULT_CODE).getAsString())) {
+            LOGGER.error("cannot get result data, please check manager status, return str is {}", jsonStr);

Review Comment:
   All these conditions' purpose is to print the error log, besides the log, they have no effect.
   So, IMO, the `warn` level for the log is enough, WDYT?



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


Re: [PR] [INLONG-9831][Agent] Increase configuration acquisition capability [inlong]

Posted by "aloyszhang (via GitHub)" <gi...@apache.org>.
aloyszhang commented on code in PR #9832:
URL: https://github.com/apache/inlong/pull/9832#discussion_r1527132059


##########
inlong-agent/agent-installer/src/main/java/org/apache/inlong/agent/installer/ManagerFetcher.java:
##########
@@ -0,0 +1,223 @@
+/*
+ * 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.installer;
+
+import org.apache.inlong.agent.common.AbstractDaemon;
+import org.apache.inlong.agent.conf.ProfileFetcher;
+import org.apache.inlong.agent.installer.conf.InstallerConfiguration;
+import org.apache.inlong.agent.utils.AgentUtils;
+import org.apache.inlong.agent.utils.HttpManager;
+import org.apache.inlong.agent.utils.ThreadUtils;
+import org.apache.inlong.common.db.CommandEntity;
+import org.apache.inlong.common.enums.PullJobTypeEnum;
+import org.apache.inlong.common.pojo.agent.TaskRequest;
+import org.apache.inlong.common.pojo.agent.installer.ConfigResult;
+import org.apache.inlong.common.pojo.agent.installer.ModuleConfig;
+import org.apache.inlong.common.pojo.agent.installer.PackageConfig;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+
+import static org.apache.inlong.agent.constant.FetcherConstants.AGENT_FETCHER_INTERVAL;
+import static org.apache.inlong.agent.constant.FetcherConstants.AGENT_MANAGER_REQUEST_TIMEOUT;
+import static org.apache.inlong.agent.constant.FetcherConstants.AGENT_MANAGER_RETURN_PARAM_DATA;
+import static org.apache.inlong.agent.constant.FetcherConstants.AGENT_MANAGER_VIP_HTTP_PREFIX_PATH;
+import static org.apache.inlong.agent.constant.FetcherConstants.DEFAULT_AGENT_FETCHER_INTERVAL;
+import static org.apache.inlong.agent.constant.FetcherConstants.DEFAULT_AGENT_MANAGER_REQUEST_TIMEOUT;
+import static org.apache.inlong.agent.constant.FetcherConstants.DEFAULT_AGENT_MANAGER_VIP_HTTP_PREFIX_PATH;
+import static org.apache.inlong.agent.constant.FetcherConstants.DEFAULT_INSTALLER_MANAGER_CONFIG_HTTP_PATH;
+import static org.apache.inlong.agent.constant.FetcherConstants.INSTALLER_MANAGER_CONFIG_HTTP_PATH;
+import static org.apache.inlong.agent.installer.ManagerResultFormatter.getResultData;
+import static org.apache.inlong.agent.utils.AgentUtils.fetchLocalIp;
+import static org.apache.inlong.agent.utils.AgentUtils.fetchLocalUuid;
+
+/**
+ * Fetch command from Inlong-Manager
+ */
+public class ManagerFetcher extends AbstractDaemon implements ProfileFetcher {
+
+    public static final String MANAGER_ADDR = "manager.addr";
+    public static final String MANAGER_AUTH_SECRET_ID = "manager.auth.secretId";
+    public static final String MANAGER_AUTH_SECRET_KEY = "manager.auth.secretKey";
+    public static final String CLUSTER_NAME = "cluster.name";
+    public static final String CLUSTER_TAG = "cluster.tag";
+    private static final Logger LOGGER = LoggerFactory.getLogger(ManagerFetcher.class);
+    private static final GsonBuilder gsonBuilder = new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss");
+    private static final Gson GSON = gsonBuilder.create();
+    private final String baseManagerUrl;
+    private final String staticConfigUrl;
+    private final InstallerConfiguration conf;
+    private final HttpManager httpManager;
+    private final Manager manager;
+    private String localIp;
+    private String uuid;
+    private String clusterName;
+
+    public ManagerFetcher(Manager manager) {
+        this.manager = manager;
+        this.conf = InstallerConfiguration.getInstallerConf();
+        if (requiredKeys(conf)) {
+            String managerAddr = conf.get(MANAGER_ADDR);
+            String managerHttpPrefixPath = conf.get(AGENT_MANAGER_VIP_HTTP_PREFIX_PATH,
+                    DEFAULT_AGENT_MANAGER_VIP_HTTP_PREFIX_PATH);
+            int timeout = conf.getInt(AGENT_MANAGER_REQUEST_TIMEOUT,
+                    DEFAULT_AGENT_MANAGER_REQUEST_TIMEOUT);
+            String secretId = conf.get(MANAGER_AUTH_SECRET_ID);
+            String secretKey = conf.get(MANAGER_AUTH_SECRET_KEY);
+            httpManager = new HttpManager(managerAddr, managerHttpPrefixPath, timeout, secretId, secretKey);
+            baseManagerUrl = httpManager.getBaseUrl();
+            staticConfigUrl = buildStaticConfigUrl(baseManagerUrl);
+            clusterName = conf.get(CLUSTER_NAME);
+        } else {
+            throw new RuntimeException("init manager error, cannot find required key");
+        }
+    }
+
+    private boolean requiredKeys(InstallerConfiguration conf) {
+        return conf.hasKey(MANAGER_ADDR);
+    }
+
+    /**
+     * build config url for manager according to config
+     *
+     * example - http://127.0.0.1:8080/inlong/manager/openapi/installer/getConfig
+     */
+    private String buildStaticConfigUrl(String baseUrl) {
+        return baseUrl + conf.get(INSTALLER_MANAGER_CONFIG_HTTP_PATH, DEFAULT_INSTALLER_MANAGER_CONFIG_HTTP_PATH);
+    }
+
+    /**
+     * request manager to get commands, make sure it is not throwing exceptions
+     */
+    public ConfigResult getConfig() {
+        LOGGER.info("getConfig start");
+        String resultStr = httpManager.doSentPost(staticConfigUrl, getFetchRequest(null));
+        LOGGER.info("ConfigUrl {}", staticConfigUrl);
+        JsonObject resultData = getResultData(resultStr);
+        JsonElement dataElement = resultData.get(AGENT_MANAGER_RETURN_PARAM_DATA);
+        LOGGER.info("getConfig end");
+        if (dataElement != null) {
+            LOGGER.info("getConfig not null {}", resultData);
+            return GSON.fromJson(dataElement.getAsJsonObject(), ConfigResult.class);
+        } else {
+            LOGGER.error("getConfig result does not contain the data field ");
+            return null;
+        }
+    }
+
+    /**
+     * form file command fetch request
+     */
+    public TaskRequest getFetchRequest(List<CommandEntity> unackedCommands) {
+        TaskRequest request = new TaskRequest();
+        request.setAgentIp(localIp);
+        request.setUuid(uuid);
+        request.setClusterName(clusterName);
+        request.setPullJobType(PullJobTypeEnum.NEW.getType());
+        request.setCommandInfo(unackedCommands);
+        return request;
+    }
+
+    /**
+     * thread for config fetcher.
+     *
+     * @return runnable profile.
+     */
+    private Runnable configFetchThread() {
+        return () -> {
+            Thread.currentThread().setName("ManagerFetcher");
+            while (isRunnable()) {
+                try {
+                    int configSleepTime = conf.getInt(AGENT_FETCHER_INTERVAL, DEFAULT_AGENT_FETCHER_INTERVAL);
+                    ConfigResult config = getTestConfig();

Review Comment:
   ```suggestion
         int configSleepTime = conf.getInt(AGENT_FETCHER_INTERVAL, DEFAULT_AGENT_FETCHER_INTERVAL);
         ConfigResult config = getTestConfig();
               while (isRunnable()) {
                   try {
                       
   ```



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


Re: [PR] [INLONG-9831][Agent] Increase configuration acquisition capability [inlong]

Posted by "justinwwhuang (via GitHub)" <gi...@apache.org>.
justinwwhuang commented on code in PR #9832:
URL: https://github.com/apache/inlong/pull/9832#discussion_r1527718035


##########
inlong-agent/agent-installer/src/main/java/org/apache/inlong/agent/installer/ModuleManager.java:
##########
@@ -0,0 +1,131 @@
+/*
+ * 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.installer;
+
+import org.apache.inlong.agent.common.AbstractDaemon;
+import org.apache.inlong.agent.installer.conf.InstallerConfiguration;
+import org.apache.inlong.agent.metrics.audit.AuditUtils;
+import org.apache.inlong.agent.utils.AgentUtils;
+import org.apache.inlong.agent.utils.ThreadUtils;
+import org.apache.inlong.common.pojo.agent.installer.ConfigResult;
+import org.apache.inlong.common.pojo.agent.installer.ModuleConfig;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.List;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
+
+/**
+ * Installer Manager, the bridge for job manager, task manager, db e.t.c it manages agent level operations and
+ * communicates with outside system.
+ */
+public class ModuleManager extends AbstractDaemon {
+
+    public static final int CONFIG_QUEUE_CAPACITY = 1;
+    public static final int CORE_THREAD_SLEEP_TIME = 1000;
+    private static final Logger LOGGER = LoggerFactory.getLogger(ModuleManager.class);
+    private final InstallerConfiguration conf;
+    private final BlockingQueue<ConfigResult> configQueue;
+
+    private String curMd5;
+
+    public ModuleManager() {
+        conf = InstallerConfiguration.getInstallerConf();
+        configQueue = new LinkedBlockingQueue<>(CONFIG_QUEUE_CAPACITY);
+    }
+
+    public void submitConfig(ConfigResult config) {
+        if (config == null) {
+            return;
+        }
+        configQueue.clear();
+        for (int i = 0; i < config.getModuleList().size(); i++) {
+            LOGGER.info("submitModules index {} total {} {}", i, config.getModuleList().size(),
+                    config.getModuleList().get(i));
+        }
+        configQueue.add(config);
+    }
+
+    /**
+     * thread for core thread.
+     *
+     * @return runnable profile.
+     */
+    private Runnable coreThread() {
+        return () -> {
+            Thread.currentThread().setName("task-manager-core");
+            while (isRunnable()) {
+                try {
+                    AgentUtils.silenceSleepInMs(CORE_THREAD_SLEEP_TIME);
+                    dealWithConfigQueue(configQueue);
+                    AuditUtils.add(AuditUtils.AUDIT_ID_AGENT_TASK_MGR_HEARTBEAT, "", "",
+                            AgentUtils.getCurrentTime(), 1, 1);
+                } catch (Throwable ex) {
+                    LOGGER.error("exception caught", ex);
+                    ThreadUtils.threadThrowableHandler(Thread.currentThread(), ex);
+                }
+            }
+        };
+    }
+
+    private void dealWithConfigQueue(BlockingQueue<ConfigResult> queue) {
+        ConfigResult config = queue.poll();
+        if (config == null) {
+            return;
+        }
+        LOGGER.info("Deal with config {}", config);
+        if (curMd5.compareTo(config.getMd5()) == 0) {
+            LOGGER.info("md5 no change {}, skip update", curMd5);
+            return;
+        }
+        if (updateModules(config.getModuleList())) {
+            curMd5 = config.getMd5();
+        } else {
+            LOGGER.error("Update modules failed!");
+        }
+    }
+
+    private boolean updateModules(List<ModuleConfig> modules) {
+        return true;

Review Comment:
   Will use it next issue



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


Re: [PR] [INLONG-9831][Agent] Increase configuration acquisition capability [inlong]

Posted by "aloyszhang (via GitHub)" <gi...@apache.org>.
aloyszhang commented on code in PR #9832:
URL: https://github.com/apache/inlong/pull/9832#discussion_r1527131483


##########
inlong-agent/agent-installer/src/main/java/org/apache/inlong/agent/installer/ManagerFetcher.java:
##########
@@ -0,0 +1,223 @@
+/*
+ * 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.installer;
+
+import org.apache.inlong.agent.common.AbstractDaemon;
+import org.apache.inlong.agent.conf.ProfileFetcher;
+import org.apache.inlong.agent.installer.conf.InstallerConfiguration;
+import org.apache.inlong.agent.utils.AgentUtils;
+import org.apache.inlong.agent.utils.HttpManager;
+import org.apache.inlong.agent.utils.ThreadUtils;
+import org.apache.inlong.common.db.CommandEntity;
+import org.apache.inlong.common.enums.PullJobTypeEnum;
+import org.apache.inlong.common.pojo.agent.TaskRequest;
+import org.apache.inlong.common.pojo.agent.installer.ConfigResult;
+import org.apache.inlong.common.pojo.agent.installer.ModuleConfig;
+import org.apache.inlong.common.pojo.agent.installer.PackageConfig;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+
+import static org.apache.inlong.agent.constant.FetcherConstants.AGENT_FETCHER_INTERVAL;
+import static org.apache.inlong.agent.constant.FetcherConstants.AGENT_MANAGER_REQUEST_TIMEOUT;
+import static org.apache.inlong.agent.constant.FetcherConstants.AGENT_MANAGER_RETURN_PARAM_DATA;
+import static org.apache.inlong.agent.constant.FetcherConstants.AGENT_MANAGER_VIP_HTTP_PREFIX_PATH;
+import static org.apache.inlong.agent.constant.FetcherConstants.DEFAULT_AGENT_FETCHER_INTERVAL;
+import static org.apache.inlong.agent.constant.FetcherConstants.DEFAULT_AGENT_MANAGER_REQUEST_TIMEOUT;
+import static org.apache.inlong.agent.constant.FetcherConstants.DEFAULT_AGENT_MANAGER_VIP_HTTP_PREFIX_PATH;
+import static org.apache.inlong.agent.constant.FetcherConstants.DEFAULT_INSTALLER_MANAGER_CONFIG_HTTP_PATH;
+import static org.apache.inlong.agent.constant.FetcherConstants.INSTALLER_MANAGER_CONFIG_HTTP_PATH;
+import static org.apache.inlong.agent.installer.ManagerResultFormatter.getResultData;
+import static org.apache.inlong.agent.utils.AgentUtils.fetchLocalIp;
+import static org.apache.inlong.agent.utils.AgentUtils.fetchLocalUuid;
+
+/**
+ * Fetch command from Inlong-Manager
+ */
+public class ManagerFetcher extends AbstractDaemon implements ProfileFetcher {
+
+    public static final String MANAGER_ADDR = "manager.addr";
+    public static final String MANAGER_AUTH_SECRET_ID = "manager.auth.secretId";
+    public static final String MANAGER_AUTH_SECRET_KEY = "manager.auth.secretKey";
+    public static final String CLUSTER_NAME = "cluster.name";
+    public static final String CLUSTER_TAG = "cluster.tag";

Review Comment:
   remove this line



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


Re: [PR] [INLONG-9831][Agent] Increase configuration acquisition capability [inlong]

Posted by "justinwwhuang (via GitHub)" <gi...@apache.org>.
justinwwhuang commented on code in PR #9832:
URL: https://github.com/apache/inlong/pull/9832#discussion_r1527401057


##########
inlong-agent/agent-installer/src/main/java/org/apache/inlong/agent/installer/ManagerFetcher.java:
##########
@@ -0,0 +1,223 @@
+/*
+ * 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.installer;
+
+import org.apache.inlong.agent.common.AbstractDaemon;
+import org.apache.inlong.agent.conf.ProfileFetcher;
+import org.apache.inlong.agent.installer.conf.InstallerConfiguration;
+import org.apache.inlong.agent.utils.AgentUtils;
+import org.apache.inlong.agent.utils.HttpManager;
+import org.apache.inlong.agent.utils.ThreadUtils;
+import org.apache.inlong.common.db.CommandEntity;
+import org.apache.inlong.common.enums.PullJobTypeEnum;
+import org.apache.inlong.common.pojo.agent.TaskRequest;
+import org.apache.inlong.common.pojo.agent.installer.ConfigResult;
+import org.apache.inlong.common.pojo.agent.installer.ModuleConfig;
+import org.apache.inlong.common.pojo.agent.installer.PackageConfig;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+
+import static org.apache.inlong.agent.constant.FetcherConstants.AGENT_FETCHER_INTERVAL;
+import static org.apache.inlong.agent.constant.FetcherConstants.AGENT_MANAGER_REQUEST_TIMEOUT;
+import static org.apache.inlong.agent.constant.FetcherConstants.AGENT_MANAGER_RETURN_PARAM_DATA;
+import static org.apache.inlong.agent.constant.FetcherConstants.AGENT_MANAGER_VIP_HTTP_PREFIX_PATH;
+import static org.apache.inlong.agent.constant.FetcherConstants.DEFAULT_AGENT_FETCHER_INTERVAL;
+import static org.apache.inlong.agent.constant.FetcherConstants.DEFAULT_AGENT_MANAGER_REQUEST_TIMEOUT;
+import static org.apache.inlong.agent.constant.FetcherConstants.DEFAULT_AGENT_MANAGER_VIP_HTTP_PREFIX_PATH;
+import static org.apache.inlong.agent.constant.FetcherConstants.DEFAULT_INSTALLER_MANAGER_CONFIG_HTTP_PATH;
+import static org.apache.inlong.agent.constant.FetcherConstants.INSTALLER_MANAGER_CONFIG_HTTP_PATH;
+import static org.apache.inlong.agent.installer.ManagerResultFormatter.getResultData;
+import static org.apache.inlong.agent.utils.AgentUtils.fetchLocalIp;
+import static org.apache.inlong.agent.utils.AgentUtils.fetchLocalUuid;
+
+/**
+ * Fetch command from Inlong-Manager
+ */
+public class ManagerFetcher extends AbstractDaemon implements ProfileFetcher {
+
+    public static final String MANAGER_ADDR = "manager.addr";
+    public static final String MANAGER_AUTH_SECRET_ID = "manager.auth.secretId";
+    public static final String MANAGER_AUTH_SECRET_KEY = "manager.auth.secretKey";
+    public static final String CLUSTER_NAME = "cluster.name";
+    public static final String CLUSTER_TAG = "cluster.tag";
+    private static final Logger LOGGER = LoggerFactory.getLogger(ManagerFetcher.class);
+    private static final GsonBuilder gsonBuilder = new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss");
+    private static final Gson GSON = gsonBuilder.create();
+    private final String baseManagerUrl;
+    private final String staticConfigUrl;
+    private final InstallerConfiguration conf;
+    private final HttpManager httpManager;
+    private final Manager manager;
+    private String localIp;
+    private String uuid;
+    private String clusterName;
+
+    public ManagerFetcher(Manager manager) {
+        this.manager = manager;
+        this.conf = InstallerConfiguration.getInstallerConf();
+        if (requiredKeys(conf)) {
+            String managerAddr = conf.get(MANAGER_ADDR);
+            String managerHttpPrefixPath = conf.get(AGENT_MANAGER_VIP_HTTP_PREFIX_PATH,
+                    DEFAULT_AGENT_MANAGER_VIP_HTTP_PREFIX_PATH);
+            int timeout = conf.getInt(AGENT_MANAGER_REQUEST_TIMEOUT,
+                    DEFAULT_AGENT_MANAGER_REQUEST_TIMEOUT);
+            String secretId = conf.get(MANAGER_AUTH_SECRET_ID);
+            String secretKey = conf.get(MANAGER_AUTH_SECRET_KEY);
+            httpManager = new HttpManager(managerAddr, managerHttpPrefixPath, timeout, secretId, secretKey);
+            baseManagerUrl = httpManager.getBaseUrl();
+            staticConfigUrl = buildStaticConfigUrl(baseManagerUrl);
+            clusterName = conf.get(CLUSTER_NAME);
+        } else {
+            throw new RuntimeException("init manager error, cannot find required key");
+        }
+    }
+
+    private boolean requiredKeys(InstallerConfiguration conf) {
+        return conf.hasKey(MANAGER_ADDR);
+    }
+
+    /**
+     * build config url for manager according to config
+     *
+     * example - http://127.0.0.1:8080/inlong/manager/openapi/installer/getConfig
+     */
+    private String buildStaticConfigUrl(String baseUrl) {
+        return baseUrl + conf.get(INSTALLER_MANAGER_CONFIG_HTTP_PATH, DEFAULT_INSTALLER_MANAGER_CONFIG_HTTP_PATH);
+    }
+
+    /**
+     * request manager to get commands, make sure it is not throwing exceptions
+     */
+    public ConfigResult getConfig() {

Review Comment:
   This code is not complete yet



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


Re: [PR] [INLONG-9831][Agent] Increase configuration acquisition capability [inlong]

Posted by "justinwwhuang (via GitHub)" <gi...@apache.org>.
justinwwhuang commented on code in PR #9832:
URL: https://github.com/apache/inlong/pull/9832#discussion_r1527400983


##########
inlong-agent/agent-installer/src/main/java/org/apache/inlong/agent/installer/ModuleManager.java:
##########
@@ -0,0 +1,119 @@
+/*
+ * 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.installer;
+
+import org.apache.inlong.agent.common.AbstractDaemon;
+import org.apache.inlong.agent.installer.conf.InstallerConfiguration;
+import org.apache.inlong.agent.metrics.audit.AuditUtils;
+import org.apache.inlong.agent.utils.AgentUtils;
+import org.apache.inlong.agent.utils.ThreadUtils;
+import org.apache.inlong.common.pojo.agent.installer.ConfigResult;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
+
+/**
+ * Installer Manager, the bridge for job manager, task manager, db e.t.c it manages agent level operations and
+ * communicates with outside system.
+ */
+public class ModuleManager extends AbstractDaemon {
+
+    public static final int CONFIG_QUEUE_CAPACITY = 1;
+    public static final int CORE_THREAD_SLEEP_TIME = 1000;
+    private static final Logger LOGGER = LoggerFactory.getLogger(ModuleManager.class);
+    private final InstallerConfiguration conf;
+    private final BlockingQueue<ConfigResult> configQueue;
+
+    private String curMd5;
+
+    public ModuleManager() {
+        conf = InstallerConfiguration.getInstallerConf();
+        configQueue = new LinkedBlockingQueue<>(CONFIG_QUEUE_CAPACITY);
+    }
+
+    public void submitConfig(ConfigResult config) {
+        if (config == null) {
+            return;
+        }
+        while (configQueue.size() != 0) {
+            configQueue.poll();
+        }
+        for (int i = 0; i < config.getModuleList().size(); i++) {
+            LOGGER.info("submitModules index {} total {} {}", i, config.getModuleList().size(),
+                    config.getModuleList().get(i));
+        }
+        configQueue.add(config);
+    }
+
+    /**
+     * thread for core thread.
+     *
+     * @return runnable profile.
+     */
+    private Runnable coreThread() {
+        return () -> {
+            Thread.currentThread().setName("task-manager-core");
+            while (isRunnable()) {
+                try {
+                    AgentUtils.silenceSleepInMs(CORE_THREAD_SLEEP_TIME);
+                    dealWithConfigQueue(configQueue);
+                    AuditUtils.add(AuditUtils.AUDIT_ID_AGENT_TASK_MGR_HEARTBEAT, "", "",
+                            AgentUtils.getCurrentTime(), 1, 1);
+                } catch (Throwable ex) {
+                    LOGGER.error("exception caught", ex);
+                    ThreadUtils.threadThrowableHandler(Thread.currentThread(), ex);
+                }
+            }
+        };
+    }
+
+    private void dealWithConfigQueue(BlockingQueue<ConfigResult> queue) {

Review Comment:
   This code is not complete yet, we will use it later



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


Re: [PR] [INLONG-9831][Agent] Increase configuration acquisition capability [inlong]

Posted by "aloyszhang (via GitHub)" <gi...@apache.org>.
aloyszhang commented on code in PR #9832:
URL: https://github.com/apache/inlong/pull/9832#discussion_r1527130044


##########
inlong-agent/agent-installer/src/main/java/org/apache/inlong/agent/installer/ManagerFetcher.java:
##########
@@ -0,0 +1,223 @@
+/*
+ * 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.installer;
+
+import org.apache.inlong.agent.common.AbstractDaemon;
+import org.apache.inlong.agent.conf.ProfileFetcher;
+import org.apache.inlong.agent.installer.conf.InstallerConfiguration;
+import org.apache.inlong.agent.utils.AgentUtils;
+import org.apache.inlong.agent.utils.HttpManager;
+import org.apache.inlong.agent.utils.ThreadUtils;
+import org.apache.inlong.common.db.CommandEntity;
+import org.apache.inlong.common.enums.PullJobTypeEnum;
+import org.apache.inlong.common.pojo.agent.TaskRequest;
+import org.apache.inlong.common.pojo.agent.installer.ConfigResult;
+import org.apache.inlong.common.pojo.agent.installer.ModuleConfig;
+import org.apache.inlong.common.pojo.agent.installer.PackageConfig;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+
+import static org.apache.inlong.agent.constant.FetcherConstants.AGENT_FETCHER_INTERVAL;
+import static org.apache.inlong.agent.constant.FetcherConstants.AGENT_MANAGER_REQUEST_TIMEOUT;
+import static org.apache.inlong.agent.constant.FetcherConstants.AGENT_MANAGER_RETURN_PARAM_DATA;
+import static org.apache.inlong.agent.constant.FetcherConstants.AGENT_MANAGER_VIP_HTTP_PREFIX_PATH;
+import static org.apache.inlong.agent.constant.FetcherConstants.DEFAULT_AGENT_FETCHER_INTERVAL;
+import static org.apache.inlong.agent.constant.FetcherConstants.DEFAULT_AGENT_MANAGER_REQUEST_TIMEOUT;
+import static org.apache.inlong.agent.constant.FetcherConstants.DEFAULT_AGENT_MANAGER_VIP_HTTP_PREFIX_PATH;
+import static org.apache.inlong.agent.constant.FetcherConstants.DEFAULT_INSTALLER_MANAGER_CONFIG_HTTP_PATH;
+import static org.apache.inlong.agent.constant.FetcherConstants.INSTALLER_MANAGER_CONFIG_HTTP_PATH;
+import static org.apache.inlong.agent.installer.ManagerResultFormatter.getResultData;
+import static org.apache.inlong.agent.utils.AgentUtils.fetchLocalIp;
+import static org.apache.inlong.agent.utils.AgentUtils.fetchLocalUuid;
+
+/**
+ * Fetch command from Inlong-Manager
+ */
+public class ManagerFetcher extends AbstractDaemon implements ProfileFetcher {
+
+    public static final String MANAGER_ADDR = "manager.addr";
+    public static final String MANAGER_AUTH_SECRET_ID = "manager.auth.secretId";
+    public static final String MANAGER_AUTH_SECRET_KEY = "manager.auth.secretKey";
+    public static final String CLUSTER_NAME = "cluster.name";
+    public static final String CLUSTER_TAG = "cluster.tag";
+    private static final Logger LOGGER = LoggerFactory.getLogger(ManagerFetcher.class);
+    private static final GsonBuilder gsonBuilder = new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss");
+    private static final Gson GSON = gsonBuilder.create();
+    private final String baseManagerUrl;
+    private final String staticConfigUrl;
+    private final InstallerConfiguration conf;
+    private final HttpManager httpManager;
+    private final Manager manager;
+    private String localIp;
+    private String uuid;
+    private String clusterName;
+
+    public ManagerFetcher(Manager manager) {
+        this.manager = manager;
+        this.conf = InstallerConfiguration.getInstallerConf();
+        if (requiredKeys(conf)) {
+            String managerAddr = conf.get(MANAGER_ADDR);
+            String managerHttpPrefixPath = conf.get(AGENT_MANAGER_VIP_HTTP_PREFIX_PATH,
+                    DEFAULT_AGENT_MANAGER_VIP_HTTP_PREFIX_PATH);
+            int timeout = conf.getInt(AGENT_MANAGER_REQUEST_TIMEOUT,
+                    DEFAULT_AGENT_MANAGER_REQUEST_TIMEOUT);
+            String secretId = conf.get(MANAGER_AUTH_SECRET_ID);
+            String secretKey = conf.get(MANAGER_AUTH_SECRET_KEY);
+            httpManager = new HttpManager(managerAddr, managerHttpPrefixPath, timeout, secretId, secretKey);
+            baseManagerUrl = httpManager.getBaseUrl();
+            staticConfigUrl = buildStaticConfigUrl(baseManagerUrl);
+            clusterName = conf.get(CLUSTER_NAME);
+        } else {
+            throw new RuntimeException("init manager error, cannot find required key");
+        }
+    }
+
+    private boolean requiredKeys(InstallerConfiguration conf) {
+        return conf.hasKey(MANAGER_ADDR);
+    }
+
+    /**
+     * build config url for manager according to config

Review Comment:
   Plz capitalize the first letter, and so do all remaining methods.



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


Re: [PR] [INLONG-9831][Agent] Increase configuration acquisition capability [inlong]

Posted by "aloyszhang (via GitHub)" <gi...@apache.org>.
aloyszhang commented on code in PR #9832:
URL: https://github.com/apache/inlong/pull/9832#discussion_r1527131725


##########
inlong-agent/agent-installer/src/main/java/org/apache/inlong/agent/installer/ManagerFetcher.java:
##########
@@ -0,0 +1,223 @@
+/*
+ * 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.installer;
+
+import org.apache.inlong.agent.common.AbstractDaemon;
+import org.apache.inlong.agent.conf.ProfileFetcher;
+import org.apache.inlong.agent.installer.conf.InstallerConfiguration;
+import org.apache.inlong.agent.utils.AgentUtils;
+import org.apache.inlong.agent.utils.HttpManager;
+import org.apache.inlong.agent.utils.ThreadUtils;
+import org.apache.inlong.common.db.CommandEntity;
+import org.apache.inlong.common.enums.PullJobTypeEnum;
+import org.apache.inlong.common.pojo.agent.TaskRequest;
+import org.apache.inlong.common.pojo.agent.installer.ConfigResult;
+import org.apache.inlong.common.pojo.agent.installer.ModuleConfig;
+import org.apache.inlong.common.pojo.agent.installer.PackageConfig;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+
+import static org.apache.inlong.agent.constant.FetcherConstants.AGENT_FETCHER_INTERVAL;
+import static org.apache.inlong.agent.constant.FetcherConstants.AGENT_MANAGER_REQUEST_TIMEOUT;
+import static org.apache.inlong.agent.constant.FetcherConstants.AGENT_MANAGER_RETURN_PARAM_DATA;
+import static org.apache.inlong.agent.constant.FetcherConstants.AGENT_MANAGER_VIP_HTTP_PREFIX_PATH;
+import static org.apache.inlong.agent.constant.FetcherConstants.DEFAULT_AGENT_FETCHER_INTERVAL;
+import static org.apache.inlong.agent.constant.FetcherConstants.DEFAULT_AGENT_MANAGER_REQUEST_TIMEOUT;
+import static org.apache.inlong.agent.constant.FetcherConstants.DEFAULT_AGENT_MANAGER_VIP_HTTP_PREFIX_PATH;
+import static org.apache.inlong.agent.constant.FetcherConstants.DEFAULT_INSTALLER_MANAGER_CONFIG_HTTP_PATH;
+import static org.apache.inlong.agent.constant.FetcherConstants.INSTALLER_MANAGER_CONFIG_HTTP_PATH;
+import static org.apache.inlong.agent.installer.ManagerResultFormatter.getResultData;
+import static org.apache.inlong.agent.utils.AgentUtils.fetchLocalIp;
+import static org.apache.inlong.agent.utils.AgentUtils.fetchLocalUuid;
+
+/**
+ * Fetch command from Inlong-Manager
+ */
+public class ManagerFetcher extends AbstractDaemon implements ProfileFetcher {
+
+    public static final String MANAGER_ADDR = "manager.addr";
+    public static final String MANAGER_AUTH_SECRET_ID = "manager.auth.secretId";
+    public static final String MANAGER_AUTH_SECRET_KEY = "manager.auth.secretKey";
+    public static final String CLUSTER_NAME = "cluster.name";
+    public static final String CLUSTER_TAG = "cluster.tag";
+    private static final Logger LOGGER = LoggerFactory.getLogger(ManagerFetcher.class);
+    private static final GsonBuilder gsonBuilder = new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss");
+    private static final Gson GSON = gsonBuilder.create();
+    private final String baseManagerUrl;
+    private final String staticConfigUrl;
+    private final InstallerConfiguration conf;
+    private final HttpManager httpManager;
+    private final Manager manager;
+    private String localIp;
+    private String uuid;
+    private String clusterName;
+
+    public ManagerFetcher(Manager manager) {
+        this.manager = manager;
+        this.conf = InstallerConfiguration.getInstallerConf();
+        if (requiredKeys(conf)) {
+            String managerAddr = conf.get(MANAGER_ADDR);
+            String managerHttpPrefixPath = conf.get(AGENT_MANAGER_VIP_HTTP_PREFIX_PATH,
+                    DEFAULT_AGENT_MANAGER_VIP_HTTP_PREFIX_PATH);
+            int timeout = conf.getInt(AGENT_MANAGER_REQUEST_TIMEOUT,
+                    DEFAULT_AGENT_MANAGER_REQUEST_TIMEOUT);
+            String secretId = conf.get(MANAGER_AUTH_SECRET_ID);
+            String secretKey = conf.get(MANAGER_AUTH_SECRET_KEY);
+            httpManager = new HttpManager(managerAddr, managerHttpPrefixPath, timeout, secretId, secretKey);
+            baseManagerUrl = httpManager.getBaseUrl();
+            staticConfigUrl = buildStaticConfigUrl(baseManagerUrl);
+            clusterName = conf.get(CLUSTER_NAME);
+        } else {
+            throw new RuntimeException("init manager error, cannot find required key");
+        }
+    }
+
+    private boolean requiredKeys(InstallerConfiguration conf) {
+        return conf.hasKey(MANAGER_ADDR);
+    }
+
+    /**
+     * build config url for manager according to config
+     *
+     * example - http://127.0.0.1:8080/inlong/manager/openapi/installer/getConfig
+     */
+    private String buildStaticConfigUrl(String baseUrl) {
+        return baseUrl + conf.get(INSTALLER_MANAGER_CONFIG_HTTP_PATH, DEFAULT_INSTALLER_MANAGER_CONFIG_HTTP_PATH);
+    }
+
+    /**
+     * request manager to get commands, make sure it is not throwing exceptions
+     */
+    public ConfigResult getConfig() {

Review Comment:
   Is this method needed?



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


Re: [PR] [INLONG-9831][Agent] Increase configuration acquisition capability [inlong]

Posted by "aloyszhang (via GitHub)" <gi...@apache.org>.
aloyszhang commented on code in PR #9832:
URL: https://github.com/apache/inlong/pull/9832#discussion_r1527130823


##########
inlong-agent/agent-installer/src/main/java/org/apache/inlong/agent/installer/ModuleManager.java:
##########
@@ -0,0 +1,119 @@
+/*
+ * 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.installer;
+
+import org.apache.inlong.agent.common.AbstractDaemon;
+import org.apache.inlong.agent.installer.conf.InstallerConfiguration;
+import org.apache.inlong.agent.metrics.audit.AuditUtils;
+import org.apache.inlong.agent.utils.AgentUtils;
+import org.apache.inlong.agent.utils.ThreadUtils;
+import org.apache.inlong.common.pojo.agent.installer.ConfigResult;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
+
+/**
+ * Installer Manager, the bridge for job manager, task manager, db e.t.c it manages agent level operations and
+ * communicates with outside system.
+ */
+public class ModuleManager extends AbstractDaemon {
+
+    public static final int CONFIG_QUEUE_CAPACITY = 1;
+    public static final int CORE_THREAD_SLEEP_TIME = 1000;
+    private static final Logger LOGGER = LoggerFactory.getLogger(ModuleManager.class);
+    private final InstallerConfiguration conf;
+    private final BlockingQueue<ConfigResult> configQueue;
+
+    private String curMd5;
+
+    public ModuleManager() {
+        conf = InstallerConfiguration.getInstallerConf();

Review Comment:
   conf is never used



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


Re: [PR] [INLONG-9831][Agent] Increase configuration acquisition capability [inlong]

Posted by "aloyszhang (via GitHub)" <gi...@apache.org>.
aloyszhang commented on PR #9832:
URL: https://github.com/apache/inlong/pull/9832#issuecomment-2001903072

   Left some comments, PTAL. 


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


Re: [PR] [INLONG-9831][Agent] Increase configuration acquisition capability [inlong]

Posted by "aloyszhang (via GitHub)" <gi...@apache.org>.
aloyszhang commented on code in PR #9832:
URL: https://github.com/apache/inlong/pull/9832#discussion_r1527132059


##########
inlong-agent/agent-installer/src/main/java/org/apache/inlong/agent/installer/ManagerFetcher.java:
##########
@@ -0,0 +1,223 @@
+/*
+ * 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.installer;
+
+import org.apache.inlong.agent.common.AbstractDaemon;
+import org.apache.inlong.agent.conf.ProfileFetcher;
+import org.apache.inlong.agent.installer.conf.InstallerConfiguration;
+import org.apache.inlong.agent.utils.AgentUtils;
+import org.apache.inlong.agent.utils.HttpManager;
+import org.apache.inlong.agent.utils.ThreadUtils;
+import org.apache.inlong.common.db.CommandEntity;
+import org.apache.inlong.common.enums.PullJobTypeEnum;
+import org.apache.inlong.common.pojo.agent.TaskRequest;
+import org.apache.inlong.common.pojo.agent.installer.ConfigResult;
+import org.apache.inlong.common.pojo.agent.installer.ModuleConfig;
+import org.apache.inlong.common.pojo.agent.installer.PackageConfig;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+
+import static org.apache.inlong.agent.constant.FetcherConstants.AGENT_FETCHER_INTERVAL;
+import static org.apache.inlong.agent.constant.FetcherConstants.AGENT_MANAGER_REQUEST_TIMEOUT;
+import static org.apache.inlong.agent.constant.FetcherConstants.AGENT_MANAGER_RETURN_PARAM_DATA;
+import static org.apache.inlong.agent.constant.FetcherConstants.AGENT_MANAGER_VIP_HTTP_PREFIX_PATH;
+import static org.apache.inlong.agent.constant.FetcherConstants.DEFAULT_AGENT_FETCHER_INTERVAL;
+import static org.apache.inlong.agent.constant.FetcherConstants.DEFAULT_AGENT_MANAGER_REQUEST_TIMEOUT;
+import static org.apache.inlong.agent.constant.FetcherConstants.DEFAULT_AGENT_MANAGER_VIP_HTTP_PREFIX_PATH;
+import static org.apache.inlong.agent.constant.FetcherConstants.DEFAULT_INSTALLER_MANAGER_CONFIG_HTTP_PATH;
+import static org.apache.inlong.agent.constant.FetcherConstants.INSTALLER_MANAGER_CONFIG_HTTP_PATH;
+import static org.apache.inlong.agent.installer.ManagerResultFormatter.getResultData;
+import static org.apache.inlong.agent.utils.AgentUtils.fetchLocalIp;
+import static org.apache.inlong.agent.utils.AgentUtils.fetchLocalUuid;
+
+/**
+ * Fetch command from Inlong-Manager
+ */
+public class ManagerFetcher extends AbstractDaemon implements ProfileFetcher {
+
+    public static final String MANAGER_ADDR = "manager.addr";
+    public static final String MANAGER_AUTH_SECRET_ID = "manager.auth.secretId";
+    public static final String MANAGER_AUTH_SECRET_KEY = "manager.auth.secretKey";
+    public static final String CLUSTER_NAME = "cluster.name";
+    public static final String CLUSTER_TAG = "cluster.tag";
+    private static final Logger LOGGER = LoggerFactory.getLogger(ManagerFetcher.class);
+    private static final GsonBuilder gsonBuilder = new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss");
+    private static final Gson GSON = gsonBuilder.create();
+    private final String baseManagerUrl;
+    private final String staticConfigUrl;
+    private final InstallerConfiguration conf;
+    private final HttpManager httpManager;
+    private final Manager manager;
+    private String localIp;
+    private String uuid;
+    private String clusterName;
+
+    public ManagerFetcher(Manager manager) {
+        this.manager = manager;
+        this.conf = InstallerConfiguration.getInstallerConf();
+        if (requiredKeys(conf)) {
+            String managerAddr = conf.get(MANAGER_ADDR);
+            String managerHttpPrefixPath = conf.get(AGENT_MANAGER_VIP_HTTP_PREFIX_PATH,
+                    DEFAULT_AGENT_MANAGER_VIP_HTTP_PREFIX_PATH);
+            int timeout = conf.getInt(AGENT_MANAGER_REQUEST_TIMEOUT,
+                    DEFAULT_AGENT_MANAGER_REQUEST_TIMEOUT);
+            String secretId = conf.get(MANAGER_AUTH_SECRET_ID);
+            String secretKey = conf.get(MANAGER_AUTH_SECRET_KEY);
+            httpManager = new HttpManager(managerAddr, managerHttpPrefixPath, timeout, secretId, secretKey);
+            baseManagerUrl = httpManager.getBaseUrl();
+            staticConfigUrl = buildStaticConfigUrl(baseManagerUrl);
+            clusterName = conf.get(CLUSTER_NAME);
+        } else {
+            throw new RuntimeException("init manager error, cannot find required key");
+        }
+    }
+
+    private boolean requiredKeys(InstallerConfiguration conf) {
+        return conf.hasKey(MANAGER_ADDR);
+    }
+
+    /**
+     * build config url for manager according to config
+     *
+     * example - http://127.0.0.1:8080/inlong/manager/openapi/installer/getConfig
+     */
+    private String buildStaticConfigUrl(String baseUrl) {
+        return baseUrl + conf.get(INSTALLER_MANAGER_CONFIG_HTTP_PATH, DEFAULT_INSTALLER_MANAGER_CONFIG_HTTP_PATH);
+    }
+
+    /**
+     * request manager to get commands, make sure it is not throwing exceptions
+     */
+    public ConfigResult getConfig() {
+        LOGGER.info("getConfig start");
+        String resultStr = httpManager.doSentPost(staticConfigUrl, getFetchRequest(null));
+        LOGGER.info("ConfigUrl {}", staticConfigUrl);
+        JsonObject resultData = getResultData(resultStr);
+        JsonElement dataElement = resultData.get(AGENT_MANAGER_RETURN_PARAM_DATA);
+        LOGGER.info("getConfig end");
+        if (dataElement != null) {
+            LOGGER.info("getConfig not null {}", resultData);
+            return GSON.fromJson(dataElement.getAsJsonObject(), ConfigResult.class);
+        } else {
+            LOGGER.error("getConfig result does not contain the data field ");
+            return null;
+        }
+    }
+
+    /**
+     * form file command fetch request
+     */
+    public TaskRequest getFetchRequest(List<CommandEntity> unackedCommands) {
+        TaskRequest request = new TaskRequest();
+        request.setAgentIp(localIp);
+        request.setUuid(uuid);
+        request.setClusterName(clusterName);
+        request.setPullJobType(PullJobTypeEnum.NEW.getType());
+        request.setCommandInfo(unackedCommands);
+        return request;
+    }
+
+    /**
+     * thread for config fetcher.
+     *
+     * @return runnable profile.
+     */
+    private Runnable configFetchThread() {
+        return () -> {
+            Thread.currentThread().setName("ManagerFetcher");
+            while (isRunnable()) {
+                try {
+                    int configSleepTime = conf.getInt(AGENT_FETCHER_INTERVAL, DEFAULT_AGENT_FETCHER_INTERVAL);
+                    ConfigResult config = getTestConfig();

Review Comment:
   ```suggestion
               int configSleepTime = conf.getInt(AGENT_FETCHER_INTERVAL, DEFAULT_AGENT_FETCHER_INTERVAL);
                       ConfigResult config = getTestConfig();
               while (isRunnable()) {
                   try {
                       
   ```



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


Re: [PR] [INLONG-9831][Agent] Increase configuration acquisition capability [inlong]

Posted by "aloyszhang (via GitHub)" <gi...@apache.org>.
aloyszhang commented on code in PR #9832:
URL: https://github.com/apache/inlong/pull/9832#discussion_r1527130552


##########
inlong-agent/agent-installer/src/main/java/org/apache/inlong/agent/installer/ModuleManager.java:
##########
@@ -0,0 +1,119 @@
+/*
+ * 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.installer;
+
+import org.apache.inlong.agent.common.AbstractDaemon;
+import org.apache.inlong.agent.installer.conf.InstallerConfiguration;
+import org.apache.inlong.agent.metrics.audit.AuditUtils;
+import org.apache.inlong.agent.utils.AgentUtils;
+import org.apache.inlong.agent.utils.ThreadUtils;
+import org.apache.inlong.common.pojo.agent.installer.ConfigResult;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
+
+/**
+ * Installer Manager, the bridge for job manager, task manager, db e.t.c it manages agent level operations and
+ * communicates with outside system.
+ */
+public class ModuleManager extends AbstractDaemon {
+
+    public static final int CONFIG_QUEUE_CAPACITY = 1;
+    public static final int CORE_THREAD_SLEEP_TIME = 1000;
+    private static final Logger LOGGER = LoggerFactory.getLogger(ModuleManager.class);
+    private final InstallerConfiguration conf;
+    private final BlockingQueue<ConfigResult> configQueue;
+
+    private String curMd5;
+
+    public ModuleManager() {
+        conf = InstallerConfiguration.getInstallerConf();
+        configQueue = new LinkedBlockingQueue<>(CONFIG_QUEUE_CAPACITY);
+    }
+
+    public void submitConfig(ConfigResult config) {
+        if (config == null) {
+            return;
+        }
+        while (configQueue.size() != 0) {
+            configQueue.poll();
+        }
+        for (int i = 0; i < config.getModuleList().size(); i++) {
+            LOGGER.info("submitModules index {} total {} {}", i, config.getModuleList().size(),
+                    config.getModuleList().get(i));
+        }
+        configQueue.add(config);
+    }
+
+    /**
+     * thread for core thread.
+     *
+     * @return runnable profile.
+     */
+    private Runnable coreThread() {
+        return () -> {
+            Thread.currentThread().setName("task-manager-core");
+            while (isRunnable()) {
+                try {
+                    AgentUtils.silenceSleepInMs(CORE_THREAD_SLEEP_TIME);
+                    dealWithConfigQueue(configQueue);
+                    AuditUtils.add(AuditUtils.AUDIT_ID_AGENT_TASK_MGR_HEARTBEAT, "", "",
+                            AgentUtils.getCurrentTime(), 1, 1);
+                } catch (Throwable ex) {
+                    LOGGER.error("exception caught", ex);
+                    ThreadUtils.threadThrowableHandler(Thread.currentThread(), ex);
+                }
+            }
+        };
+    }
+
+    private void dealWithConfigQueue(BlockingQueue<ConfigResult> queue) {
+        LOGGER.info("starting dealWithConfigQueue");
+        ConfigResult config = queue.poll();
+        if (config == null) {
+            return;
+        }
+
+    }
+
+    @Override
+    public void start() throws Exception {
+        LOGGER.info("starting installer manager");
+        submitWorker(coreThread());
+        LOGGER.info("starting agent manager end");

Review Comment:
   ```suggestion
           LOGGER.info("started agent manager");
   ```



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


Re: [PR] [INLONG-9831][Agent] Increase configuration acquisition capability [inlong]

Posted by "aloyszhang (via GitHub)" <gi...@apache.org>.
aloyszhang commented on code in PR #9832:
URL: https://github.com/apache/inlong/pull/9832#discussion_r1527131032


##########
inlong-agent/agent-installer/src/main/java/org/apache/inlong/agent/installer/ModuleManager.java:
##########
@@ -0,0 +1,119 @@
+/*
+ * 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.installer;
+
+import org.apache.inlong.agent.common.AbstractDaemon;
+import org.apache.inlong.agent.installer.conf.InstallerConfiguration;
+import org.apache.inlong.agent.metrics.audit.AuditUtils;
+import org.apache.inlong.agent.utils.AgentUtils;
+import org.apache.inlong.agent.utils.ThreadUtils;
+import org.apache.inlong.common.pojo.agent.installer.ConfigResult;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
+
+/**
+ * Installer Manager, the bridge for job manager, task manager, db e.t.c it manages agent level operations and
+ * communicates with outside system.
+ */
+public class ModuleManager extends AbstractDaemon {
+
+    public static final int CONFIG_QUEUE_CAPACITY = 1;
+    public static final int CORE_THREAD_SLEEP_TIME = 1000;
+    private static final Logger LOGGER = LoggerFactory.getLogger(ModuleManager.class);
+    private final InstallerConfiguration conf;
+    private final BlockingQueue<ConfigResult> configQueue;
+
+    private String curMd5;
+
+    public ModuleManager() {
+        conf = InstallerConfiguration.getInstallerConf();
+        configQueue = new LinkedBlockingQueue<>(CONFIG_QUEUE_CAPACITY);
+    }
+
+    public void submitConfig(ConfigResult config) {
+        if (config == null) {
+            return;
+        }
+        while (configQueue.size() != 0) {
+            configQueue.poll();
+        }
+        for (int i = 0; i < config.getModuleList().size(); i++) {
+            LOGGER.info("submitModules index {} total {} {}", i, config.getModuleList().size(),
+                    config.getModuleList().get(i));
+        }
+        configQueue.add(config);
+    }
+
+    /**
+     * thread for core thread.
+     *
+     * @return runnable profile.
+     */
+    private Runnable coreThread() {
+        return () -> {
+            Thread.currentThread().setName("task-manager-core");
+            while (isRunnable()) {
+                try {
+                    AgentUtils.silenceSleepInMs(CORE_THREAD_SLEEP_TIME);
+                    dealWithConfigQueue(configQueue);
+                    AuditUtils.add(AuditUtils.AUDIT_ID_AGENT_TASK_MGR_HEARTBEAT, "", "",
+                            AgentUtils.getCurrentTime(), 1, 1);
+                } catch (Throwable ex) {
+                    LOGGER.error("exception caught", ex);
+                    ThreadUtils.threadThrowableHandler(Thread.currentThread(), ex);
+                }
+            }
+        };
+    }
+
+    private void dealWithConfigQueue(BlockingQueue<ConfigResult> queue) {

Review Comment:
   Is there missing some processing logic for the ConfigResult polled from the queue?



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


Re: [PR] [INLONG-9831][Agent] Increase configuration acquisition capability [inlong]

Posted by "justinwwhuang (via GitHub)" <gi...@apache.org>.
justinwwhuang commented on code in PR #9832:
URL: https://github.com/apache/inlong/pull/9832#discussion_r1527400983


##########
inlong-agent/agent-installer/src/main/java/org/apache/inlong/agent/installer/ModuleManager.java:
##########
@@ -0,0 +1,119 @@
+/*
+ * 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.installer;
+
+import org.apache.inlong.agent.common.AbstractDaemon;
+import org.apache.inlong.agent.installer.conf.InstallerConfiguration;
+import org.apache.inlong.agent.metrics.audit.AuditUtils;
+import org.apache.inlong.agent.utils.AgentUtils;
+import org.apache.inlong.agent.utils.ThreadUtils;
+import org.apache.inlong.common.pojo.agent.installer.ConfigResult;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
+
+/**
+ * Installer Manager, the bridge for job manager, task manager, db e.t.c it manages agent level operations and
+ * communicates with outside system.
+ */
+public class ModuleManager extends AbstractDaemon {
+
+    public static final int CONFIG_QUEUE_CAPACITY = 1;
+    public static final int CORE_THREAD_SLEEP_TIME = 1000;
+    private static final Logger LOGGER = LoggerFactory.getLogger(ModuleManager.class);
+    private final InstallerConfiguration conf;
+    private final BlockingQueue<ConfigResult> configQueue;
+
+    private String curMd5;
+
+    public ModuleManager() {
+        conf = InstallerConfiguration.getInstallerConf();
+        configQueue = new LinkedBlockingQueue<>(CONFIG_QUEUE_CAPACITY);
+    }
+
+    public void submitConfig(ConfigResult config) {
+        if (config == null) {
+            return;
+        }
+        while (configQueue.size() != 0) {
+            configQueue.poll();
+        }
+        for (int i = 0; i < config.getModuleList().size(); i++) {
+            LOGGER.info("submitModules index {} total {} {}", i, config.getModuleList().size(),
+                    config.getModuleList().get(i));
+        }
+        configQueue.add(config);
+    }
+
+    /**
+     * thread for core thread.
+     *
+     * @return runnable profile.
+     */
+    private Runnable coreThread() {
+        return () -> {
+            Thread.currentThread().setName("task-manager-core");
+            while (isRunnable()) {
+                try {
+                    AgentUtils.silenceSleepInMs(CORE_THREAD_SLEEP_TIME);
+                    dealWithConfigQueue(configQueue);
+                    AuditUtils.add(AuditUtils.AUDIT_ID_AGENT_TASK_MGR_HEARTBEAT, "", "",
+                            AgentUtils.getCurrentTime(), 1, 1);
+                } catch (Throwable ex) {
+                    LOGGER.error("exception caught", ex);
+                    ThreadUtils.threadThrowableHandler(Thread.currentThread(), ex);
+                }
+            }
+        };
+    }
+
+    private void dealWithConfigQueue(BlockingQueue<ConfigResult> queue) {

Review Comment:
   This code is not complete yet.



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


Re: [PR] [INLONG-9831][Agent] Increase configuration acquisition capability [inlong]

Posted by "aloyszhang (via GitHub)" <gi...@apache.org>.
aloyszhang commented on code in PR #9832:
URL: https://github.com/apache/inlong/pull/9832#discussion_r1527130823


##########
inlong-agent/agent-installer/src/main/java/org/apache/inlong/agent/installer/ModuleManager.java:
##########
@@ -0,0 +1,119 @@
+/*
+ * 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.installer;
+
+import org.apache.inlong.agent.common.AbstractDaemon;
+import org.apache.inlong.agent.installer.conf.InstallerConfiguration;
+import org.apache.inlong.agent.metrics.audit.AuditUtils;
+import org.apache.inlong.agent.utils.AgentUtils;
+import org.apache.inlong.agent.utils.ThreadUtils;
+import org.apache.inlong.common.pojo.agent.installer.ConfigResult;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
+
+/**
+ * Installer Manager, the bridge for job manager, task manager, db e.t.c it manages agent level operations and
+ * communicates with outside system.
+ */
+public class ModuleManager extends AbstractDaemon {
+
+    public static final int CONFIG_QUEUE_CAPACITY = 1;
+    public static final int CORE_THREAD_SLEEP_TIME = 1000;
+    private static final Logger LOGGER = LoggerFactory.getLogger(ModuleManager.class);
+    private final InstallerConfiguration conf;
+    private final BlockingQueue<ConfigResult> configQueue;
+
+    private String curMd5;
+
+    public ModuleManager() {
+        conf = InstallerConfiguration.getInstallerConf();

Review Comment:
   `conf` is never used



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


Re: [PR] [INLONG-9831][Agent] Increase configuration acquisition capability [inlong]

Posted by "aloyszhang (via GitHub)" <gi...@apache.org>.
aloyszhang commented on code in PR #9832:
URL: https://github.com/apache/inlong/pull/9832#discussion_r1527131428


##########
inlong-agent/agent-installer/src/main/java/org/apache/inlong/agent/installer/ModuleManager.java:
##########
@@ -0,0 +1,119 @@
+/*
+ * 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.installer;
+
+import org.apache.inlong.agent.common.AbstractDaemon;
+import org.apache.inlong.agent.installer.conf.InstallerConfiguration;
+import org.apache.inlong.agent.metrics.audit.AuditUtils;
+import org.apache.inlong.agent.utils.AgentUtils;
+import org.apache.inlong.agent.utils.ThreadUtils;
+import org.apache.inlong.common.pojo.agent.installer.ConfigResult;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
+
+/**
+ * Installer Manager, the bridge for job manager, task manager, db e.t.c it manages agent level operations and
+ * communicates with outside system.
+ */
+public class ModuleManager extends AbstractDaemon {
+
+    public static final int CONFIG_QUEUE_CAPACITY = 1;
+    public static final int CORE_THREAD_SLEEP_TIME = 1000;
+    private static final Logger LOGGER = LoggerFactory.getLogger(ModuleManager.class);
+    private final InstallerConfiguration conf;
+    private final BlockingQueue<ConfigResult> configQueue;
+
+    private String curMd5;

Review Comment:
   remove this line



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


Re: [PR] [INLONG-9831][Agent] Increase configuration acquisition capability [inlong]

Posted by "dockerzhang (via GitHub)" <gi...@apache.org>.
dockerzhang commented on code in PR #9832:
URL: https://github.com/apache/inlong/pull/9832#discussion_r1527690012


##########
inlong-agent/agent-plugins/src/main/java/org/apache/inlong/agent/plugin/fetcher/ManagerFetcher.java:
##########
@@ -141,12 +141,12 @@ public TaskResult fetchTaskConfig() {
     public TaskResult getStaticConfig() {
         LOGGER.info("getStaticConfig start");
         String resultStr = httpManager.doSentPost(staticConfigUrl, getFetchRequest(null));
-        LOGGER.info("test123 staticConfigUrl {}", staticConfigUrl);
+        LOGGER.info("staticConfigUrl {}", staticConfigUrl);

Review Comment:
   Add a more readable description.



##########
inlong-agent/agent-plugins/src/main/java/org/apache/inlong/agent/plugin/fetcher/ManagerFetcher.java:
##########
@@ -141,12 +141,12 @@ public TaskResult fetchTaskConfig() {
     public TaskResult getStaticConfig() {
         LOGGER.info("getStaticConfig start");
         String resultStr = httpManager.doSentPost(staticConfigUrl, getFetchRequest(null));
-        LOGGER.info("test123 staticConfigUrl {}", staticConfigUrl);
+        LOGGER.info("staticConfigUrl {}", staticConfigUrl);
         JsonObject resultData = getResultData(resultStr);
         JsonElement element = resultData.get(AGENT_MANAGER_RETURN_PARAM_DATA);
         LOGGER.info("getStaticConfig end");
         if (element != null) {
-            LOGGER.info("test123 getStaticConfig not null {}", resultData);
+            LOGGER.info("getStaticConfig not null {}", resultData);

Review Comment:
   ditto



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


Re: [PR] [INLONG-9831][Agent] Increase configuration acquisition capability [inlong]

Posted by "EMsnap (via GitHub)" <gi...@apache.org>.
EMsnap commented on code in PR #9832:
URL: https://github.com/apache/inlong/pull/9832#discussion_r1527698155


##########
inlong-agent/agent-installer/src/main/java/org/apache/inlong/agent/installer/ModuleManager.java:
##########
@@ -0,0 +1,131 @@
+/*
+ * 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.installer;
+
+import org.apache.inlong.agent.common.AbstractDaemon;
+import org.apache.inlong.agent.installer.conf.InstallerConfiguration;
+import org.apache.inlong.agent.metrics.audit.AuditUtils;
+import org.apache.inlong.agent.utils.AgentUtils;
+import org.apache.inlong.agent.utils.ThreadUtils;
+import org.apache.inlong.common.pojo.agent.installer.ConfigResult;
+import org.apache.inlong.common.pojo.agent.installer.ModuleConfig;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.List;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
+
+/**
+ * Installer Manager, the bridge for job manager, task manager, db e.t.c it manages agent level operations and
+ * communicates with outside system.
+ */
+public class ModuleManager extends AbstractDaemon {
+
+    public static final int CONFIG_QUEUE_CAPACITY = 1;
+    public static final int CORE_THREAD_SLEEP_TIME = 1000;
+    private static final Logger LOGGER = LoggerFactory.getLogger(ModuleManager.class);
+    private final InstallerConfiguration conf;
+    private final BlockingQueue<ConfigResult> configQueue;
+
+    private String curMd5;
+
+    public ModuleManager() {
+        conf = InstallerConfiguration.getInstallerConf();
+        configQueue = new LinkedBlockingQueue<>(CONFIG_QUEUE_CAPACITY);
+    }
+
+    public void submitConfig(ConfigResult config) {
+        if (config == null) {
+            return;
+        }
+        configQueue.clear();
+        for (int i = 0; i < config.getModuleList().size(); i++) {
+            LOGGER.info("submitModules index {} total {} {}", i, config.getModuleList().size(),
+                    config.getModuleList().get(i));
+        }
+        configQueue.add(config);
+    }
+
+    /**
+     * thread for core thread.
+     *
+     * @return runnable profile.
+     */
+    private Runnable coreThread() {
+        return () -> {
+            Thread.currentThread().setName("task-manager-core");
+            while (isRunnable()) {
+                try {
+                    AgentUtils.silenceSleepInMs(CORE_THREAD_SLEEP_TIME);
+                    dealWithConfigQueue(configQueue);
+                    AuditUtils.add(AuditUtils.AUDIT_ID_AGENT_TASK_MGR_HEARTBEAT, "", "",
+                            AgentUtils.getCurrentTime(), 1, 1);
+                } catch (Throwable ex) {
+                    LOGGER.error("exception caught", ex);
+                    ThreadUtils.threadThrowableHandler(Thread.currentThread(), ex);
+                }
+            }
+        };
+    }
+
+    private void dealWithConfigQueue(BlockingQueue<ConfigResult> queue) {
+        ConfigResult config = queue.poll();
+        if (config == null) {
+            return;
+        }
+        LOGGER.info("Deal with config {}", config);
+        if (curMd5.compareTo(config.getMd5()) == 0) {
+            LOGGER.info("md5 no change {}, skip update", curMd5);
+            return;
+        }
+        if (updateModules(config.getModuleList())) {
+            curMd5 = config.getMd5();
+        } else {
+            LOGGER.error("Update modules failed!");
+        }
+    }
+
+    private boolean updateModules(List<ModuleConfig> modules) {
+        return true;

Review Comment:
   always return true, what does this method for if it always returns true 



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


Re: [PR] [INLONG-9831][Agent] Increase configuration acquisition capability [inlong]

Posted by "justinwwhuang (via GitHub)" <gi...@apache.org>.
justinwwhuang commented on code in PR #9832:
URL: https://github.com/apache/inlong/pull/9832#discussion_r1527717153


##########
inlong-agent/agent-installer/src/main/java/org/apache/inlong/agent/installer/ManagerFetcher.java:
##########
@@ -0,0 +1,223 @@
+/*
+ * 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.installer;
+
+import org.apache.inlong.agent.common.AbstractDaemon;
+import org.apache.inlong.agent.conf.ProfileFetcher;
+import org.apache.inlong.agent.installer.conf.InstallerConfiguration;
+import org.apache.inlong.agent.utils.AgentUtils;
+import org.apache.inlong.agent.utils.HttpManager;
+import org.apache.inlong.agent.utils.ThreadUtils;
+import org.apache.inlong.common.db.CommandEntity;
+import org.apache.inlong.common.enums.PullJobTypeEnum;
+import org.apache.inlong.common.pojo.agent.TaskRequest;
+import org.apache.inlong.common.pojo.agent.installer.ConfigResult;
+import org.apache.inlong.common.pojo.agent.installer.ModuleConfig;
+import org.apache.inlong.common.pojo.agent.installer.PackageConfig;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+
+import static org.apache.inlong.agent.constant.FetcherConstants.AGENT_FETCHER_INTERVAL;
+import static org.apache.inlong.agent.constant.FetcherConstants.AGENT_MANAGER_REQUEST_TIMEOUT;
+import static org.apache.inlong.agent.constant.FetcherConstants.AGENT_MANAGER_RETURN_PARAM_DATA;
+import static org.apache.inlong.agent.constant.FetcherConstants.AGENT_MANAGER_VIP_HTTP_PREFIX_PATH;
+import static org.apache.inlong.agent.constant.FetcherConstants.DEFAULT_AGENT_FETCHER_INTERVAL;
+import static org.apache.inlong.agent.constant.FetcherConstants.DEFAULT_AGENT_MANAGER_REQUEST_TIMEOUT;
+import static org.apache.inlong.agent.constant.FetcherConstants.DEFAULT_AGENT_MANAGER_VIP_HTTP_PREFIX_PATH;
+import static org.apache.inlong.agent.constant.FetcherConstants.DEFAULT_INSTALLER_MANAGER_CONFIG_HTTP_PATH;
+import static org.apache.inlong.agent.constant.FetcherConstants.INSTALLER_MANAGER_CONFIG_HTTP_PATH;
+import static org.apache.inlong.agent.installer.ManagerResultFormatter.getResultData;
+import static org.apache.inlong.agent.utils.AgentUtils.fetchLocalIp;
+import static org.apache.inlong.agent.utils.AgentUtils.fetchLocalUuid;
+
+/**
+ * Fetch command from Inlong-Manager
+ */
+public class ManagerFetcher extends AbstractDaemon implements ProfileFetcher {
+
+    public static final String MANAGER_ADDR = "manager.addr";
+    public static final String MANAGER_AUTH_SECRET_ID = "manager.auth.secretId";
+    public static final String MANAGER_AUTH_SECRET_KEY = "manager.auth.secretKey";
+    public static final String CLUSTER_NAME = "cluster.name";
+    public static final String CLUSTER_TAG = "cluster.tag";

Review Comment:
   Will use it next issue



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


Re: [PR] [INLONG-9831][Agent] Increase configuration acquisition capability [inlong]

Posted by "justinwwhuang (via GitHub)" <gi...@apache.org>.
justinwwhuang commented on code in PR #9832:
URL: https://github.com/apache/inlong/pull/9832#discussion_r1527401185


##########
inlong-agent/agent-installer/src/main/java/org/apache/inlong/agent/installer/ManagerFetcher.java:
##########
@@ -0,0 +1,223 @@
+/*
+ * 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.installer;
+
+import org.apache.inlong.agent.common.AbstractDaemon;
+import org.apache.inlong.agent.conf.ProfileFetcher;
+import org.apache.inlong.agent.installer.conf.InstallerConfiguration;
+import org.apache.inlong.agent.utils.AgentUtils;
+import org.apache.inlong.agent.utils.HttpManager;
+import org.apache.inlong.agent.utils.ThreadUtils;
+import org.apache.inlong.common.db.CommandEntity;
+import org.apache.inlong.common.enums.PullJobTypeEnum;
+import org.apache.inlong.common.pojo.agent.TaskRequest;
+import org.apache.inlong.common.pojo.agent.installer.ConfigResult;
+import org.apache.inlong.common.pojo.agent.installer.ModuleConfig;
+import org.apache.inlong.common.pojo.agent.installer.PackageConfig;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+
+import static org.apache.inlong.agent.constant.FetcherConstants.AGENT_FETCHER_INTERVAL;
+import static org.apache.inlong.agent.constant.FetcherConstants.AGENT_MANAGER_REQUEST_TIMEOUT;
+import static org.apache.inlong.agent.constant.FetcherConstants.AGENT_MANAGER_RETURN_PARAM_DATA;
+import static org.apache.inlong.agent.constant.FetcherConstants.AGENT_MANAGER_VIP_HTTP_PREFIX_PATH;
+import static org.apache.inlong.agent.constant.FetcherConstants.DEFAULT_AGENT_FETCHER_INTERVAL;
+import static org.apache.inlong.agent.constant.FetcherConstants.DEFAULT_AGENT_MANAGER_REQUEST_TIMEOUT;
+import static org.apache.inlong.agent.constant.FetcherConstants.DEFAULT_AGENT_MANAGER_VIP_HTTP_PREFIX_PATH;
+import static org.apache.inlong.agent.constant.FetcherConstants.DEFAULT_INSTALLER_MANAGER_CONFIG_HTTP_PATH;
+import static org.apache.inlong.agent.constant.FetcherConstants.INSTALLER_MANAGER_CONFIG_HTTP_PATH;
+import static org.apache.inlong.agent.installer.ManagerResultFormatter.getResultData;
+import static org.apache.inlong.agent.utils.AgentUtils.fetchLocalIp;
+import static org.apache.inlong.agent.utils.AgentUtils.fetchLocalUuid;
+
+/**
+ * Fetch command from Inlong-Manager
+ */
+public class ManagerFetcher extends AbstractDaemon implements ProfileFetcher {
+
+    public static final String MANAGER_ADDR = "manager.addr";
+    public static final String MANAGER_AUTH_SECRET_ID = "manager.auth.secretId";
+    public static final String MANAGER_AUTH_SECRET_KEY = "manager.auth.secretKey";
+    public static final String CLUSTER_NAME = "cluster.name";
+    public static final String CLUSTER_TAG = "cluster.tag";
+    private static final Logger LOGGER = LoggerFactory.getLogger(ManagerFetcher.class);
+    private static final GsonBuilder gsonBuilder = new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss");
+    private static final Gson GSON = gsonBuilder.create();
+    private final String baseManagerUrl;
+    private final String staticConfigUrl;
+    private final InstallerConfiguration conf;
+    private final HttpManager httpManager;
+    private final Manager manager;
+    private String localIp;
+    private String uuid;
+    private String clusterName;
+
+    public ManagerFetcher(Manager manager) {
+        this.manager = manager;
+        this.conf = InstallerConfiguration.getInstallerConf();
+        if (requiredKeys(conf)) {
+            String managerAddr = conf.get(MANAGER_ADDR);
+            String managerHttpPrefixPath = conf.get(AGENT_MANAGER_VIP_HTTP_PREFIX_PATH,
+                    DEFAULT_AGENT_MANAGER_VIP_HTTP_PREFIX_PATH);
+            int timeout = conf.getInt(AGENT_MANAGER_REQUEST_TIMEOUT,
+                    DEFAULT_AGENT_MANAGER_REQUEST_TIMEOUT);
+            String secretId = conf.get(MANAGER_AUTH_SECRET_ID);
+            String secretKey = conf.get(MANAGER_AUTH_SECRET_KEY);
+            httpManager = new HttpManager(managerAddr, managerHttpPrefixPath, timeout, secretId, secretKey);
+            baseManagerUrl = httpManager.getBaseUrl();
+            staticConfigUrl = buildStaticConfigUrl(baseManagerUrl);
+            clusterName = conf.get(CLUSTER_NAME);
+        } else {
+            throw new RuntimeException("init manager error, cannot find required key");
+        }
+    }
+
+    private boolean requiredKeys(InstallerConfiguration conf) {
+        return conf.hasKey(MANAGER_ADDR);
+    }
+
+    /**
+     * build config url for manager according to config
+     *
+     * example - http://127.0.0.1:8080/inlong/manager/openapi/installer/getConfig
+     */
+    private String buildStaticConfigUrl(String baseUrl) {
+        return baseUrl + conf.get(INSTALLER_MANAGER_CONFIG_HTTP_PATH, DEFAULT_INSTALLER_MANAGER_CONFIG_HTTP_PATH);
+    }
+
+    /**
+     * request manager to get commands, make sure it is not throwing exceptions
+     */
+    public ConfigResult getConfig() {
+        LOGGER.info("getConfig start");
+        String resultStr = httpManager.doSentPost(staticConfigUrl, getFetchRequest(null));
+        LOGGER.info("ConfigUrl {}", staticConfigUrl);
+        JsonObject resultData = getResultData(resultStr);
+        JsonElement dataElement = resultData.get(AGENT_MANAGER_RETURN_PARAM_DATA);
+        LOGGER.info("getConfig end");
+        if (dataElement != null) {
+            LOGGER.info("getConfig not null {}", resultData);
+            return GSON.fromJson(dataElement.getAsJsonObject(), ConfigResult.class);
+        } else {
+            LOGGER.error("getConfig result does not contain the data field ");
+            return null;
+        }
+    }
+
+    /**
+     * form file command fetch request
+     */
+    public TaskRequest getFetchRequest(List<CommandEntity> unackedCommands) {
+        TaskRequest request = new TaskRequest();
+        request.setAgentIp(localIp);
+        request.setUuid(uuid);
+        request.setClusterName(clusterName);
+        request.setPullJobType(PullJobTypeEnum.NEW.getType());
+        request.setCommandInfo(unackedCommands);
+        return request;
+    }
+
+    /**
+     * thread for config fetcher.
+     *
+     * @return runnable profile.
+     */
+    private Runnable configFetchThread() {
+        return () -> {
+            Thread.currentThread().setName("ManagerFetcher");
+            while (isRunnable()) {
+                try {
+                    int configSleepTime = conf.getInt(AGENT_FETCHER_INTERVAL, DEFAULT_AGENT_FETCHER_INTERVAL);
+                    ConfigResult config = getTestConfig();

Review Comment:
   This configuration needs to be dynamically updated



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


Re: [PR] [INLONG-9831][Agent] Increase configuration acquisition capability [inlong]

Posted by "EMsnap (via GitHub)" <gi...@apache.org>.
EMsnap commented on code in PR #9832:
URL: https://github.com/apache/inlong/pull/9832#discussion_r1527698155


##########
inlong-agent/agent-installer/src/main/java/org/apache/inlong/agent/installer/ModuleManager.java:
##########
@@ -0,0 +1,131 @@
+/*
+ * 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.installer;
+
+import org.apache.inlong.agent.common.AbstractDaemon;
+import org.apache.inlong.agent.installer.conf.InstallerConfiguration;
+import org.apache.inlong.agent.metrics.audit.AuditUtils;
+import org.apache.inlong.agent.utils.AgentUtils;
+import org.apache.inlong.agent.utils.ThreadUtils;
+import org.apache.inlong.common.pojo.agent.installer.ConfigResult;
+import org.apache.inlong.common.pojo.agent.installer.ModuleConfig;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.List;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
+
+/**
+ * Installer Manager, the bridge for job manager, task manager, db e.t.c it manages agent level operations and
+ * communicates with outside system.
+ */
+public class ModuleManager extends AbstractDaemon {
+
+    public static final int CONFIG_QUEUE_CAPACITY = 1;
+    public static final int CORE_THREAD_SLEEP_TIME = 1000;
+    private static final Logger LOGGER = LoggerFactory.getLogger(ModuleManager.class);
+    private final InstallerConfiguration conf;
+    private final BlockingQueue<ConfigResult> configQueue;
+
+    private String curMd5;
+
+    public ModuleManager() {
+        conf = InstallerConfiguration.getInstallerConf();
+        configQueue = new LinkedBlockingQueue<>(CONFIG_QUEUE_CAPACITY);
+    }
+
+    public void submitConfig(ConfigResult config) {
+        if (config == null) {
+            return;
+        }
+        configQueue.clear();
+        for (int i = 0; i < config.getModuleList().size(); i++) {
+            LOGGER.info("submitModules index {} total {} {}", i, config.getModuleList().size(),
+                    config.getModuleList().get(i));
+        }
+        configQueue.add(config);
+    }
+
+    /**
+     * thread for core thread.
+     *
+     * @return runnable profile.
+     */
+    private Runnable coreThread() {
+        return () -> {
+            Thread.currentThread().setName("task-manager-core");
+            while (isRunnable()) {
+                try {
+                    AgentUtils.silenceSleepInMs(CORE_THREAD_SLEEP_TIME);
+                    dealWithConfigQueue(configQueue);
+                    AuditUtils.add(AuditUtils.AUDIT_ID_AGENT_TASK_MGR_HEARTBEAT, "", "",
+                            AgentUtils.getCurrentTime(), 1, 1);
+                } catch (Throwable ex) {
+                    LOGGER.error("exception caught", ex);
+                    ThreadUtils.threadThrowableHandler(Thread.currentThread(), ex);
+                }
+            }
+        };
+    }
+
+    private void dealWithConfigQueue(BlockingQueue<ConfigResult> queue) {
+        ConfigResult config = queue.poll();
+        if (config == null) {
+            return;
+        }
+        LOGGER.info("Deal with config {}", config);
+        if (curMd5.compareTo(config.getMd5()) == 0) {
+            LOGGER.info("md5 no change {}, skip update", curMd5);
+            return;
+        }
+        if (updateModules(config.getModuleList())) {
+            curMd5 = config.getMd5();
+        } else {
+            LOGGER.error("Update modules failed!");
+        }
+    }
+
+    private boolean updateModules(List<ModuleConfig> modules) {
+        return true;

Review Comment:
   what does this method for if it always returns true ?



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


Re: [PR] [INLONG-9831][Agent] Increase configuration acquisition capability [inlong]

Posted by "justinwwhuang (via GitHub)" <gi...@apache.org>.
justinwwhuang commented on code in PR #9832:
URL: https://github.com/apache/inlong/pull/9832#discussion_r1527716864


##########
inlong-agent/agent-installer/src/main/java/org/apache/inlong/agent/installer/ModuleManager.java:
##########
@@ -0,0 +1,119 @@
+/*
+ * 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.installer;
+
+import org.apache.inlong.agent.common.AbstractDaemon;
+import org.apache.inlong.agent.installer.conf.InstallerConfiguration;
+import org.apache.inlong.agent.metrics.audit.AuditUtils;
+import org.apache.inlong.agent.utils.AgentUtils;
+import org.apache.inlong.agent.utils.ThreadUtils;
+import org.apache.inlong.common.pojo.agent.installer.ConfigResult;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
+
+/**
+ * Installer Manager, the bridge for job manager, task manager, db e.t.c it manages agent level operations and
+ * communicates with outside system.
+ */
+public class ModuleManager extends AbstractDaemon {
+
+    public static final int CONFIG_QUEUE_CAPACITY = 1;
+    public static final int CORE_THREAD_SLEEP_TIME = 1000;
+    private static final Logger LOGGER = LoggerFactory.getLogger(ModuleManager.class);
+    private final InstallerConfiguration conf;
+    private final BlockingQueue<ConfigResult> configQueue;
+
+    private String curMd5;

Review Comment:
   will use it next issue



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


Re: [PR] [INLONG-9831][Agent] Increase configuration acquisition capability [inlong]

Posted by "dockerzhang (via GitHub)" <gi...@apache.org>.
dockerzhang merged PR #9832:
URL: https://github.com/apache/inlong/pull/9832


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


Re: [PR] [INLONG-9831][Agent] Increase configuration acquisition capability [inlong]

Posted by "aloyszhang (via GitHub)" <gi...@apache.org>.
aloyszhang commented on code in PR #9832:
URL: https://github.com/apache/inlong/pull/9832#discussion_r1527130910


##########
inlong-agent/agent-installer/src/main/java/org/apache/inlong/agent/installer/ModuleManager.java:
##########
@@ -0,0 +1,119 @@
+/*
+ * 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.installer;
+
+import org.apache.inlong.agent.common.AbstractDaemon;
+import org.apache.inlong.agent.installer.conf.InstallerConfiguration;
+import org.apache.inlong.agent.metrics.audit.AuditUtils;
+import org.apache.inlong.agent.utils.AgentUtils;
+import org.apache.inlong.agent.utils.ThreadUtils;
+import org.apache.inlong.common.pojo.agent.installer.ConfigResult;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
+
+/**
+ * Installer Manager, the bridge for job manager, task manager, db e.t.c it manages agent level operations and
+ * communicates with outside system.
+ */
+public class ModuleManager extends AbstractDaemon {
+
+    public static final int CONFIG_QUEUE_CAPACITY = 1;
+    public static final int CORE_THREAD_SLEEP_TIME = 1000;
+    private static final Logger LOGGER = LoggerFactory.getLogger(ModuleManager.class);
+    private final InstallerConfiguration conf;
+    private final BlockingQueue<ConfigResult> configQueue;
+
+    private String curMd5;
+
+    public ModuleManager() {
+        conf = InstallerConfiguration.getInstallerConf();
+        configQueue = new LinkedBlockingQueue<>(CONFIG_QUEUE_CAPACITY);
+    }
+
+    public void submitConfig(ConfigResult config) {
+        if (config == null) {
+            return;
+        }
+        while (configQueue.size() != 0) {
+            configQueue.poll();
+        }

Review Comment:
   ```suggestion
            configQueue.clear();
   ```



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