This is an automated email from the ASF dual-hosted git repository.
dockerzhang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/inlong.git
The following commit(s) were added to refs/heads/master by this push:
new 3ae27abb3f [INLONG-9802][Agent] Add an agent installer module for
agent installation (#9803)
3ae27abb3f is described below
commit 3ae27abb3f5d739ed3b34eed8fb79d79049e81c8
Author: justinwwhuang <[email protected]>
AuthorDate: Wed Mar 13 14:37:58 2024 +0800
[INLONG-9802][Agent] Add an agent installer module for agent installation
(#9803)
Co-authored-by: Charles Zhang <[email protected]>
Co-authored-by: AloysZhang <[email protected]>
---
.../inlong/agent/conf/AbstractConfiguration.java | 2 +-
.../inlong/agent/constant/FetcherConstants.java | 20 +---
inlong-agent/{ => agent-installer}/pom.xml | 31 ++---
.../org/apache/inlong/agent/installer/Main.java | 127 +++++++++++++++++++++
.../org/apache/inlong/agent/installer/Manager.java | 103 +++++++++++++++++
.../installer/conf/InstallerConfiguration.java | 67 +++++++++++
inlong-agent/pom.xml | 1 +
7 files changed, 318 insertions(+), 33 deletions(-)
diff --git
a/inlong-agent/agent-common/src/main/java/org/apache/inlong/agent/conf/AbstractConfiguration.java
b/inlong-agent/agent-common/src/main/java/org/apache/inlong/agent/conf/AbstractConfiguration.java
index ec7fcf1151..f323386bfd 100644
---
a/inlong-agent/agent-common/src/main/java/org/apache/inlong/agent/conf/AbstractConfiguration.java
+++
b/inlong-agent/agent-common/src/main/java/org/apache/inlong/agent/conf/AbstractConfiguration.java
@@ -116,7 +116,7 @@ public abstract class AbstractConfiguration {
loadResource(fileName, true);
}
- void loadPropertiesResource(String fileName) {
+ public void loadPropertiesResource(String fileName) {
loadResource(fileName, false);
}
diff --git
a/inlong-agent/agent-common/src/main/java/org/apache/inlong/agent/constant/FetcherConstants.java
b/inlong-agent/agent-common/src/main/java/org/apache/inlong/agent/constant/FetcherConstants.java
index 2214db1fbb..8540676d39 100644
---
a/inlong-agent/agent-common/src/main/java/org/apache/inlong/agent/constant/FetcherConstants.java
+++
b/inlong-agent/agent-common/src/main/java/org/apache/inlong/agent/constant/FetcherConstants.java
@@ -31,16 +31,9 @@ public class FetcherConstants {
// default is 30s
public static final int DEFAULT_AGENT_MANAGER_REQUEST_TIMEOUT = 30;
- // enable https
- public static final String ENABLE_HTTPS = "enable.https";
- public static final boolean DEFAULT_ENABLE_HTTPS = false;
-
// required config
public static final String AGENT_MANAGER_ADDR = "agent.manager.addr";
- public static final String AGENT_MANAGER_VIP_HTTP_PATH =
"agent.manager.vip.http.managerIp.path";
- public static final String DEFAULT_AGENT_TDM_VIP_HTTP_PATH =
"/agent/getManagerIpList";
-
public static final String AGENT_MANAGER_VIP_HTTP_PREFIX_PATH =
"agent.manager.vip.http.prefix.path";
public static final String DEFAULT_AGENT_MANAGER_VIP_HTTP_PREFIX_PATH =
"/inlong/manager/openapi";
@@ -48,16 +41,7 @@ public class FetcherConstants {
public static final String DEFAULT_AGENT_MANAGER_TASK_HTTP_PATH =
"/agent/reportAndGetTask";
public static final String DEFAULT_AGENT_MANAGER_CONFIG_HTTP_PATH =
"/agent/getExistTaskConfig";
- public static final String AGENT_MANAGER_IP_CHECK_HTTP_PATH =
"agent.manager.vip.http.checkIP.path";
- public static final String DEFAULT_AGENT_TDM_IP_CHECK_HTTP_PATH =
"/fileAgent/confirmAgentIp";
-
- public static final String AGENT_MANAGER_DBCOLLECT_GETTASK_HTTP_PATH =
"agent.manager.dbcollect.gettask.http.path";
- public static final String
DEFAULT_AGENT_MANAGER_DBCOLLECTOR_GETTASK_HTTP_PATH = "/dbCollector/getTask";
-
- public static final String AGENT_MANAGER_REPORTSNAPSHOT_HTTP_PATH =
"agent.manager.reportsnapshot.http.path";
- public static final String DEFAULT_AGENT_MANAGER_REPORTSNAPSHOT_HTTP_PATH
= "/agent/reportSnapshot";
-
- public static final String AGENT_MANAGER_HEARTBEAT_HTTP_PATH =
"agent.manager.heartbeat.http.path";
+ public static final String AGENT_MANAGER_HEARTBEAT_HTTP_PATH =
"heartbeat.http.path";
public static final String DEFAULT_AGENT_MANAGER_HEARTBEAT_HTTP_PATH =
"/heartbeat/report";
public static final String AGENT_HTTP_APPLICATION_JSON =
"application/json";
@@ -67,8 +51,6 @@ public class FetcherConstants {
public static final String AGENT_MANAGER_RETURN_PARAM_IP = "ip";
public static final String AGENT_MANAGER_RETURN_PARAM_DATA = "data";
- public static final String VERSION = "1.0";
-
public static final String AGENT_MANAGER_AUTH_SECRET_ID =
"agent.manager.auth.secretId";
public static final String AGENT_MANAGER_AUTH_SECRET_KEY =
"agent.manager.auth.secretKey";
diff --git a/inlong-agent/pom.xml b/inlong-agent/agent-installer/pom.xml
similarity index 64%
copy from inlong-agent/pom.xml
copy to inlong-agent/agent-installer/pom.xml
index b3658102e3..fc7b4191a0 100644
--- a/inlong-agent/pom.xml
+++ b/inlong-agent/agent-installer/pom.xml
@@ -22,24 +22,29 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.inlong</groupId>
- <artifactId>inlong</artifactId>
+ <artifactId>inlong-agent</artifactId>
<version>1.12.0-SNAPSHOT</version>
</parent>
- <artifactId>inlong-agent</artifactId>
- <packaging>pom</packaging>
- <name>Apache InLong - Agent</name>
-
- <modules>
- <module>agent-common</module>
- <module>agent-core</module>
- <module>agent-plugins</module>
- <module>agent-release</module>
- <module>agent-docker</module>
- </modules>
+ <artifactId>agent-installer</artifactId>
+ <name>Apache InLong - Agent Installer</name>
<properties>
- <inlong.root.dir>${project.parent.basedir}</inlong.root.dir>
+ <inlong.root.dir>${project.parent.parent.basedir}</inlong.root.dir>
</properties>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.inlong</groupId>
+ <artifactId>agent-common</artifactId>
+ <version>${project.version}</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.inlong</groupId>
+ <artifactId>agent-core</artifactId>
+ <version>${project.version}</version>
+ <scope>compile</scope>
+ </dependency>
+ </dependencies>
</project>
diff --git
a/inlong-agent/agent-installer/src/main/java/org/apache/inlong/agent/installer/Main.java
b/inlong-agent/agent-installer/src/main/java/org/apache/inlong/agent/installer/Main.java
new file mode 100644
index 0000000000..f03739b3d3
--- /dev/null
+++
b/inlong-agent/agent-installer/src/main/java/org/apache/inlong/agent/installer/Main.java
@@ -0,0 +1,127 @@
+/*
+ * 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.installer.conf.InstallerConfiguration;
+import org.apache.inlong.agent.metrics.audit.AuditUtils;
+import org.apache.inlong.common.metric.MetricObserver;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.CommandLineParser;
+import org.apache.commons.cli.DefaultParser;
+import org.apache.commons.cli.HelpFormatter;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.Options;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Iterator;
+
+/**
+ * Agent installer entrance class
+ */
+public class Main {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(Main.class);
+
+ /**
+ * Print help information
+ *
+ * @param opts options
+ */
+ private static void help(Options opts) {
+ HelpFormatter formatter = new HelpFormatter();
+ formatter.printHelp("inlong-agent", opts);
+ System.exit(0);
+ }
+
+ /**
+ * Init options
+ *
+ * @param args argument
+ * @return command line
+ */
+ public static CommandLine initOptions(String[] args) {
+ CommandLineParser parser = new DefaultParser();
+ Options options = new Options();
+ options.addOption("h", "help", false, "show help");
+ try {
+ return parser.parse(options, args);
+ } catch (Exception ex) {
+ help(options);
+ }
+ return null;
+ }
+
+ /**
+ * Init agent conf
+ *
+ * @param cl commandline
+ */
+ public static void initAgentConf(CommandLine cl) {
+ InstallerConfiguration conf =
InstallerConfiguration.getInstallerConf();
+ Iterator<Option> iterator = cl.iterator();
+ while (iterator != null && iterator.hasNext()) {
+ Option opt = iterator.next();
+ if (opt != null && opt.getLongOpt() != null
+ && opt.getValue() != null &&
conf.hasKey(opt.getLongOpt())) {
+ conf.set(opt.getLongOpt(), opt.getValue().trim());
+ }
+ }
+ }
+
+ /**
+ * Stopping installer manager gracefully if it was killed.
+ *
+ * @param manager installer manager
+ */
+ private static void stopInstallerIfKilled(Manager manager) {
+ Runtime.getRuntime().addShutdownHook(new Thread(() -> {
+ try {
+ LOGGER.info("stopping installer gracefully");
+ manager.stop();
+ AuditUtils.send();
+ } catch (Exception ex) {
+ LOGGER.error("stop installer manager error: ", ex);
+ }
+ }));
+ }
+
+ /**
+ * Main entrance.
+ */
+ public static void main(String[] args) throws Exception {
+ Thread.currentThread().setName("main-thread");
+ CommandLine cl = initOptions(args);
+ assert cl != null;
+ initAgentConf(cl);
+ AuditUtils.initAudit();
+ Manager manager = new Manager();
+ try {
+ manager.start();
+ stopInstallerIfKilled(manager);
+ // metrics
+
MetricObserver.init(InstallerConfiguration.getInstallerConf().getConfigProperties());
+ manager.join();
+ } catch (Exception ex) {
+ LOGGER.error("installer running exception: ", ex);
+ } finally {
+ manager.stop();
+ }
+ }
+}
diff --git
a/inlong-agent/agent-installer/src/main/java/org/apache/inlong/agent/installer/Manager.java
b/inlong-agent/agent-installer/src/main/java/org/apache/inlong/agent/installer/Manager.java
new file mode 100755
index 0000000000..973e0bdd57
--- /dev/null
+++
b/inlong-agent/agent-installer/src/main/java/org/apache/inlong/agent/installer/Manager.java
@@ -0,0 +1,103 @@
+/*
+ * 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.constant.AgentConstants;
+import org.apache.inlong.agent.core.task.TaskManager;
+import org.apache.inlong.agent.installer.conf.InstallerConfiguration;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.lang.reflect.Constructor;
+
+/**
+ * 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 Manager extends AbstractDaemon {
+
+ private static final Logger LOGGER =
LoggerFactory.getLogger(Manager.class);
+ private final TaskManager taskManager;
+ private final ProfileFetcher fetcher;
+ private final InstallerConfiguration conf;
+
+ public Manager() {
+ conf = InstallerConfiguration.getInstallerConf();
+ taskManager = new TaskManager();
+ fetcher = initFetcher(this);
+ }
+
+ /**
+ * Init fetch by class name
+ */
+ private ProfileFetcher initFetcher(Manager manager) {
+ try {
+ Constructor<?> constructor =
+
Class.forName(conf.get(AgentConstants.AGENT_FETCHER_CLASSNAME))
+ .getDeclaredConstructor(Manager.class);
+ constructor.setAccessible(true);
+ return (ProfileFetcher) constructor.newInstance(manager);
+ } catch (Exception ex) {
+ LOGGER.warn("cannot find fetcher: ", ex);
+ }
+ return null;
+ }
+
+ public ProfileFetcher getFetcher() {
+ return fetcher;
+ }
+
+ public TaskManager getTaskManager() {
+ return taskManager;
+ }
+
+ @Override
+ public void join() {
+ super.join();
+ taskManager.join();
+ }
+
+ @Override
+ public void start() throws Exception {
+ LOGGER.info("starting installer manager");
+ taskManager.start();
+ LOGGER.info("starting fetcher");
+ if (fetcher != null) {
+ fetcher.start();
+ }
+ LOGGER.info("starting agent manager end");
+ }
+
+ /**
+ * It should guarantee thread-safe, and can be invoked many times.
+ *
+ * @throws Exception exceptions
+ */
+ @Override
+ public void stop() throws Exception {
+ if (fetcher != null) {
+ fetcher.stop();
+ }
+ // TODO: change job state which is in running state.
+ LOGGER.info("stopping installer manager");
+ taskManager.stop();
+ }
+}
diff --git
a/inlong-agent/agent-installer/src/main/java/org/apache/inlong/agent/installer/conf/InstallerConfiguration.java
b/inlong-agent/agent-installer/src/main/java/org/apache/inlong/agent/installer/conf/InstallerConfiguration.java
new file mode 100644
index 0000000000..a9b3fa9bf8
--- /dev/null
+++
b/inlong-agent/agent-installer/src/main/java/org/apache/inlong/agent/installer/conf/InstallerConfiguration.java
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.inlong.agent.installer.conf;
+
+import org.apache.inlong.agent.conf.AbstractConfiguration;
+
+import java.util.ArrayList;
+
+/**
+ * Installer configuration. Only one instance in the process.
+ * Basically it use properties file to store configurations.
+ */
+public class InstallerConfiguration extends AbstractConfiguration {
+
+ public static final String DEFAULT_CONFIG_FILE = "installer.properties";
+ private static final ArrayList<String> LOCAL_RESOURCES = new ArrayList<>();
+ private static volatile InstallerConfiguration installerConf = null;
+
+ static {
+ LOCAL_RESOURCES.add(DEFAULT_CONFIG_FILE);
+ }
+
+ /**
+ * Load config from file.
+ */
+ private InstallerConfiguration() {
+ for (String fileName : LOCAL_RESOURCES) {
+ super.loadPropertiesResource(fileName);
+ }
+ }
+
+ /**
+ * Singleton for agent configuration.
+ *
+ * @return static instance of InstallerConfiguration
+ */
+ public static InstallerConfiguration getInstallerConf() {
+ if (installerConf == null) {
+ synchronized (InstallerConfiguration.class) {
+ if (installerConf == null) {
+ installerConf = new InstallerConfiguration();
+ }
+ }
+ }
+ return installerConf;
+ }
+
+ @Override
+ public boolean allRequiredKeyExist() {
+ return true;
+ }
+}
diff --git a/inlong-agent/pom.xml b/inlong-agent/pom.xml
index b3658102e3..5ea1957b85 100644
--- a/inlong-agent/pom.xml
+++ b/inlong-agent/pom.xml
@@ -34,6 +34,7 @@
<module>agent-common</module>
<module>agent-core</module>
<module>agent-plugins</module>
+ <module>agent-installer</module>
<module>agent-release</module>
<module>agent-docker</module>
</modules>