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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to