This is an automated email from the ASF dual-hosted git repository.
wuzhiguo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/bigtop-manager.git
The following commit(s) were added to refs/heads/main by this push:
new afc7f355 BIGTOP-4305: Add MySQL to infra stack (#128)
afc7f355 is described below
commit afc7f3551073f514f15c06142d0e22cd154a514d
Author: Zhiguo Wu <[email protected]>
AuthorDate: Thu Dec 19 09:46:19 2024 +0800
BIGTOP-4305: Add MySQL to infra stack (#128)
---
bigtop-manager-bom/pom.xml | 7 ++
.../manager/server/command/job/ServiceAddJob.java | 6 +-
.../1.0.0/services/mysql/configuration/common.xml | 28 ++++++++
.../1.0.0/services/mysql/configuration/my.cnf.xml | 56 ++++++++++++++++
.../stacks/infra/1.0.0/services/mysql/metainfo.xml | 73 ++++++++++++++++++++
.../stacks/infra/1.0.0/services/mysql/order.json | 1 +
.../bigtop-manager-stack-core/pom.xml | 5 ++
.../manager/stack/core/spi/param/BaseParams.java | 5 --
.../stack/core/tarball/TarballDownloader.java | 4 +-
.../stack/core/tarball/TarballExtractor.java | 28 ++++++--
.../stack/core/utils/linux/LinuxFileUtils.java | 21 ++++++
.../stack/core/utils/linux/LinuxOSUtils.java | 3 +-
.../manager/stack/infra/param/InfraParams.java | 33 +++++++++
.../infra/v1_0_0/grafana/GrafanaServerScript.java | 1 -
.../infra/v1_0_0/mysql/MySQLClientScript.java | 52 +++++++++++++++
.../stack/infra/v1_0_0/mysql/MySQLParams.java | 76 +++++++++++++++++++++
.../MySQLServerScript.java} | 78 +++++++++++++++-------
.../stack/infra/v1_0_0/mysql/MySQLSetup.java | 59 ++++++++++++++++
18 files changed, 494 insertions(+), 42 deletions(-)
diff --git a/bigtop-manager-bom/pom.xml b/bigtop-manager-bom/pom.xml
index 726e8444..ce8f88b8 100644
--- a/bigtop-manager-bom/pom.xml
+++ b/bigtop-manager-bom/pom.xml
@@ -40,6 +40,7 @@
<guava.version>32.1.1-jre</guava.version>
<commons-collections4.version>4.4</commons-collections4.version>
<commons-compress.version>1.26.2</commons-compress.version>
+ <xz.version>1.9</xz.version>
<jwt.version>4.4.0</jwt.version>
<janino.version>3.0.16</janino.version>
<jaxb-runtime.version>4.0.4</jaxb-runtime.version>
@@ -124,6 +125,12 @@
<version>${commons-compress.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.tukaani</groupId>
+ <artifactId>xz</artifactId>
+ <version>${xz.version}</version>
+ </dependency>
+
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
diff --git
a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/command/job/ServiceAddJob.java
b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/command/job/ServiceAddJob.java
index 2d6d8907..3c708bca 100644
---
a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/command/job/ServiceAddJob.java
+++
b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/command/job/ServiceAddJob.java
@@ -55,12 +55,12 @@ public class ServiceAddJob extends AbstractServiceJob {
@Override
protected void createStages() {
+ // Update cache files
+ super.createCacheStage();
+
// Install components
super.createAddStages();
- // Update cache files after installed
- super.createCacheStage();
-
// Configure services
super.createConfigureStages();
diff --git
a/bigtop-manager-server/src/main/resources/stacks/infra/1.0.0/services/mysql/configuration/common.xml
b/bigtop-manager-server/src/main/resources/stacks/infra/1.0.0/services/mysql/configuration/common.xml
new file mode 100644
index 00000000..62773e21
--- /dev/null
+++
b/bigtop-manager-server/src/main/resources/stacks/infra/1.0.0/services/mysql/configuration/common.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0"?>
+<!--
+ ~ 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.
+-->
+
+<configuration>
+ <property>
+ <name>root_password</name>
+ <value>root</value>
+ <display-name>Root Password</display-name>
+ <description>Password for MySQL root user.</description>
+ </property>
+</configuration>
diff --git
a/bigtop-manager-server/src/main/resources/stacks/infra/1.0.0/services/mysql/configuration/my.cnf.xml
b/bigtop-manager-server/src/main/resources/stacks/infra/1.0.0/services/mysql/configuration/my.cnf.xml
new file mode 100644
index 00000000..b38af8b5
--- /dev/null
+++
b/bigtop-manager-server/src/main/resources/stacks/infra/1.0.0/services/mysql/configuration/my.cnf.xml
@@ -0,0 +1,56 @@
+<?xml version="1.0"?>
+<!--
+ ~ 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.
+-->
+
+<configuration>
+ <property>
+ <name>mysql_log_dir</name>
+ <value>/var/log/mysql</value>
+ <display-name>MySQL Log Dir</display-name>
+ <description>MySQL Log Dir</description>
+ </property>
+ <property>
+ <name>mysql_pid_dir</name>
+ <value>/var/run/mysql</value>
+ <display-name>MySQL PID Dir</display-name>
+ <description>MySQL Pid Dir</description>
+ </property>
+ <!-- my.cnf -->
+ <property>
+ <name>content</name>
+ <display-name>my.cnf template</display-name>
+ <description>This is the freemarker template for my.cnf
file</description>
+ <value><![CDATA[
+[mysqld]
+port=3306
+basedir=${mysql_home}
+datadir=${mysql_home}/data
+pid-file = ${mysql_pid_dir}/mysqld.pid
+log-error = ${mysql_log_dir}/error.log
+general-log-file = ${mysql_log_dir}/general.log
+slow-query-log-file = ${mysql_log_dir}/slow.log
+log-bin = ${mysql_log_dir}/mysql-bin.log
+default-storage-engine=INNODB
+]]>
+ </value>
+ <attrs>
+ <type>longtext</type>
+ </attrs>
+ </property>
+</configuration>
diff --git
a/bigtop-manager-server/src/main/resources/stacks/infra/1.0.0/services/mysql/metainfo.xml
b/bigtop-manager-server/src/main/resources/stacks/infra/1.0.0/services/mysql/metainfo.xml
new file mode 100644
index 00000000..4d9243af
--- /dev/null
+++
b/bigtop-manager-server/src/main/resources/stacks/infra/1.0.0/services/mysql/metainfo.xml
@@ -0,0 +1,73 @@
+<?xml version="1.0"?>
+<!--
+ ~ 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
+ ~
+ ~ https://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.
+-->
+
+<metainfo>
+ <service>
+ <name>mysql</name>
+ <display-name>MySQL</display-name>
+ <desc>
+ MySQL is an open source relational database management system
(RDBMS) that’s used to store and manage data.
+ Its reliability, performance, scalability, and ease of use make
MySQL a popular choice for developers.
+ </desc>
+ <version>8.0.40</version>
+ <user>mysql</user>
+
+ <components>
+ <component>
+ <name>mysql_server</name>
+ <display-name>MySQL Server</display-name>
+ <category>server</category>
+ <cardinality>1</cardinality>
+ </component>
+
+ <component>
+ <name>mysql_client</name>
+ <display-name>MySQL Client</display-name>
+ <category>client</category>
+ <cardinality>1+</cardinality>
+ </component>
+ </components>
+
+ <package-specifics>
+ <package-specific>
+ <architectures>
+ <arch>x86_64</arch>
+ </architectures>
+ <packages>
+ <package>
+ <name>mysql-8.0.40-linux-glibc2.28-x86_64.tar.xz</name>
+
<checksum>MD5:dcf2702f953d1969be44083f4f063f18</checksum>
+ </package>
+ </packages>
+ </package-specific>
+ <package-specific>
+ <architectures>
+ <arch>aarch64</arch>
+ </architectures>
+ <packages>
+ <package>
+
<name>mysql-8.0.40-linux-glibc2.28-aarch64.tar.xz</name>
+
<checksum>MD5:a79f41ce62784a1a0e081c76116008de</checksum>
+ </package>
+ </packages>
+ </package-specific>
+ </package-specifics>
+ </service>
+</metainfo>
\ No newline at end of file
diff --git
a/bigtop-manager-server/src/main/resources/stacks/infra/1.0.0/services/mysql/order.json
b/bigtop-manager-server/src/main/resources/stacks/infra/1.0.0/services/mysql/order.json
new file mode 100644
index 00000000..9e26dfee
--- /dev/null
+++
b/bigtop-manager-server/src/main/resources/stacks/infra/1.0.0/services/mysql/order.json
@@ -0,0 +1 @@
+{}
\ No newline at end of file
diff --git a/bigtop-manager-stack/bigtop-manager-stack-core/pom.xml
b/bigtop-manager-stack/bigtop-manager-stack-core/pom.xml
index d9591a6b..48fb9816 100644
--- a/bigtop-manager-stack/bigtop-manager-stack-core/pom.xml
+++ b/bigtop-manager-stack/bigtop-manager-stack-core/pom.xml
@@ -54,5 +54,10 @@
<groupId>org.apache.commons</groupId>
<artifactId>commons-compress</artifactId>
</dependency>
+
+ <dependency>
+ <groupId>org.tukaani</groupId>
+ <artifactId>xz</artifactId>
+ </dependency>
</dependencies>
</project>
diff --git
a/bigtop-manager-stack/bigtop-manager-stack-core/src/main/java/org/apache/bigtop/manager/stack/core/spi/param/BaseParams.java
b/bigtop-manager-stack/bigtop-manager-stack-core/src/main/java/org/apache/bigtop/manager/stack/core/spi/param/BaseParams.java
index 83279901..58f761ff 100644
---
a/bigtop-manager-stack/bigtop-manager-stack-core/src/main/java/org/apache/bigtop/manager/stack/core/spi/param/BaseParams.java
+++
b/bigtop-manager-stack/bigtop-manager-stack-core/src/main/java/org/apache/bigtop/manager/stack/core/spi/param/BaseParams.java
@@ -18,7 +18,6 @@
*/
package org.apache.bigtop.manager.stack.core.spi.param;
-import org.apache.bigtop.manager.common.enums.Command;
import org.apache.bigtop.manager.common.message.entity.payload.CommandPayload;
import org.apache.bigtop.manager.common.message.entity.pojo.PackageInfo;
import
org.apache.bigtop.manager.common.message.entity.pojo.PackageSpecificInfo;
@@ -55,10 +54,6 @@ public abstract class BaseParams implements Params {
protected BaseParams(CommandPayload commandPayload) {
this.commandPayload = commandPayload;
- Command command = commandPayload.getCommand();
- if (command == Command.ADD) {
- return;
- }
// Global Parameters Injection
Method[] declaredMethods = this.getClass().getDeclaredMethods();
for (Method declaredMethod : declaredMethods) {
diff --git
a/bigtop-manager-stack/bigtop-manager-stack-core/src/main/java/org/apache/bigtop/manager/stack/core/tarball/TarballDownloader.java
b/bigtop-manager-stack/bigtop-manager-stack-core/src/main/java/org/apache/bigtop/manager/stack/core/tarball/TarballDownloader.java
index b0ca3d53..363ce53e 100644
---
a/bigtop-manager-stack/bigtop-manager-stack-core/src/main/java/org/apache/bigtop/manager/stack/core/tarball/TarballDownloader.java
+++
b/bigtop-manager-stack/bigtop-manager-stack-core/src/main/java/org/apache/bigtop/manager/stack/core/tarball/TarballDownloader.java
@@ -108,10 +108,10 @@ public class TarballDownloader {
outputStream.close();
inputStream.close();
- log.info("File downloaded: {}", saveFilePath);
+ log.info("File downloaded: [{}]", saveFilePath);
return true;
} else {
- log.info("No file to download. Server replied HTTP code: {}",
responseCode);
+ log.info("No file to download. Server replied HTTP code:
[{}]", responseCode);
return false;
}
} catch (Exception e) {
diff --git
a/bigtop-manager-stack/bigtop-manager-stack-core/src/main/java/org/apache/bigtop/manager/stack/core/tarball/TarballExtractor.java
b/bigtop-manager-stack/bigtop-manager-stack-core/src/main/java/org/apache/bigtop/manager/stack/core/tarball/TarballExtractor.java
index f0d99c50..c9231bfa 100644
---
a/bigtop-manager-stack/bigtop-manager-stack-core/src/main/java/org/apache/bigtop/manager/stack/core/tarball/TarballExtractor.java
+++
b/bigtop-manager-stack/bigtop-manager-stack-core/src/main/java/org/apache/bigtop/manager/stack/core/tarball/TarballExtractor.java
@@ -23,6 +23,7 @@ import
org.apache.bigtop.manager.stack.core.exception.StackException;
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream;
+import org.apache.commons.compress.compressors.xz.XZCompressorInputStream;
import lombok.extern.slf4j.Slf4j;
@@ -45,10 +46,12 @@ public class TarballExtractor {
File tarball = new File(source);
File destDir = new File(dest);
- if (isTarGz(source)) {
- extractTarGz(tarball, tis -> extract(tis, destDir, skipLevels));
- } else if (isTar(source)) {
+ if (isTar(source)) {
extractTar(tarball, tis -> extract(tis, destDir, skipLevels));
+ } else if (isTarGz(source)) {
+ extractTarGz(tarball, tis -> extract(tis, destDir, skipLevels));
+ } else if (isTarXz(source)) {
+ extractTarXz(tarball, tis -> extract(tis, destDir, skipLevels));
} else {
log.info("Unsupported file type: {}", source);
}
@@ -125,11 +128,26 @@ public class TarballExtractor {
}
}
- private static boolean isTarGz(String filePath) {
- return filePath.endsWith(".tar.gz") || filePath.endsWith(".tgz");
+ private static void extractTarXz(File tarball,
Function<TarArchiveInputStream, Boolean> func) {
+ try (InputStream fis = Files.newInputStream(tarball.toPath());
+ XZCompressorInputStream xzis = new
XZCompressorInputStream(fis);
+ TarArchiveInputStream tis = new TarArchiveInputStream(xzis)) {
+ func.apply(tis);
+ } catch (Exception e) {
+ log.error("Error extracting tarball", e);
+ throw new StackException(e);
+ }
}
private static boolean isTar(String filePath) {
return filePath.endsWith(".tar");
}
+
+ private static boolean isTarGz(String filePath) {
+ return filePath.endsWith(".tar.gz") || filePath.endsWith(".tgz");
+ }
+
+ private static boolean isTarXz(String filePath) {
+ return filePath.endsWith(".tar.xz");
+ }
}
diff --git
a/bigtop-manager-stack/bigtop-manager-stack-core/src/main/java/org/apache/bigtop/manager/stack/core/utils/linux/LinuxFileUtils.java
b/bigtop-manager-stack/bigtop-manager-stack-core/src/main/java/org/apache/bigtop/manager/stack/core/utils/linux/LinuxFileUtils.java
index 50858db8..c0912fc9 100644
---
a/bigtop-manager-stack/bigtop-manager-stack-core/src/main/java/org/apache/bigtop/manager/stack/core/utils/linux/LinuxFileUtils.java
+++
b/bigtop-manager-stack/bigtop-manager-stack-core/src/main/java/org/apache/bigtop/manager/stack/core/utils/linux/LinuxFileUtils.java
@@ -254,6 +254,27 @@ public class LinuxFileUtils {
}
}
+ public static String readFile(String source) {
+ if (StringUtils.isBlank(source)) {
+ throw new StackException("source must not be empty");
+ }
+
+ List<String> builderParameters = new ArrayList<>();
+ builderParameters.add("cat");
+ builderParameters.add(source);
+
+ try {
+ ShellResult shellResult = sudoExecCmd(builderParameters);
+ if (shellResult.getExitCode() != MessageConstants.SUCCESS_CODE) {
+ throw new StackException(shellResult.getErrMsg());
+ }
+
+ return shellResult.getOutput();
+ } catch (IOException e) {
+ throw new StackException(e);
+ }
+ }
+
/**
* create symbolic link
*
diff --git
a/bigtop-manager-stack/bigtop-manager-stack-core/src/main/java/org/apache/bigtop/manager/stack/core/utils/linux/LinuxOSUtils.java
b/bigtop-manager-stack/bigtop-manager-stack-core/src/main/java/org/apache/bigtop/manager/stack/core/utils/linux/LinuxOSUtils.java
index d123b097..e3cf4726 100644
---
a/bigtop-manager-stack/bigtop-manager-stack-core/src/main/java/org/apache/bigtop/manager/stack/core/utils/linux/LinuxOSUtils.java
+++
b/bigtop-manager-stack/bigtop-manager-stack-core/src/main/java/org/apache/bigtop/manager/stack/core/utils/linux/LinuxOSUtils.java
@@ -20,7 +20,6 @@ package org.apache.bigtop.manager.stack.core.utils.linux;
import org.apache.bigtop.manager.common.shell.ShellExecutor;
import org.apache.bigtop.manager.common.shell.ShellResult;
-import org.apache.bigtop.manager.common.utils.FileUtils;
import org.apache.commons.lang3.StringUtils;
@@ -104,7 +103,7 @@ public class LinuxOSUtils {
}
int pid;
try {
- pid =
Integer.parseInt(FileUtils.readFile2Str(file).replaceAll("\r|\n", ""));
+ pid =
Integer.parseInt(LinuxFileUtils.readFile(filepath).replaceAll("\r|\n", ""));
} catch (Exception e) {
log.warn("Pid file {} does not exist or does not contain a process
id number, error", filepath, e);
return new ShellResult(-1, "", "Component is not running");
diff --git
a/bigtop-manager-stack/bigtop-manager-stack-infra/src/main/java/org/apache/bigtop/manager/stack/infra/param/InfraParams.java
b/bigtop-manager-stack/bigtop-manager-stack-infra/src/main/java/org/apache/bigtop/manager/stack/infra/param/InfraParams.java
index 0b7b68c0..a5bf3798 100644
---
a/bigtop-manager-stack/bigtop-manager-stack-infra/src/main/java/org/apache/bigtop/manager/stack/infra/param/InfraParams.java
+++
b/bigtop-manager-stack/bigtop-manager-stack-infra/src/main/java/org/apache/bigtop/manager/stack/infra/param/InfraParams.java
@@ -24,6 +24,8 @@ import
org.apache.bigtop.manager.stack.core.spi.param.BaseParams;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
+import java.io.File;
+
@Slf4j
@NoArgsConstructor
public abstract class InfraParams extends BaseParams {
@@ -31,4 +33,35 @@ public abstract class InfraParams extends BaseParams {
protected InfraParams(CommandPayload commandPayload) {
super(commandPayload);
}
+
+ /**
+ * Infra stack do not belong to any cluster, so we need to override this
and provide a group name
+ *
+ * @return group name
+ */
+ @Override
+ public String group() {
+ return "infra";
+ }
+
+ /**
+ * Infra stack do not belong to any cluster, we cannot use stack home of
cluster
+ *
+ * @return group name
+ */
+ @Override
+ public String stackHome() {
+ // Parent path of agent dir, which is bigtop-manager-agent/../
+ String parentPath = new File(InfraParams.class
+ .getProtectionDomain()
+ .getCodeSource()
+ .getLocation()
+ .getPath())
+ .getParentFile()
+ .getParentFile()
+ .getParentFile()
+ .getPath();
+
+ return parentPath + "/infras";
+ }
}
diff --git
a/bigtop-manager-stack/bigtop-manager-stack-infra/src/main/java/org/apache/bigtop/manager/stack/infra/v1_0_0/grafana/GrafanaServerScript.java
b/bigtop-manager-stack/bigtop-manager-stack-infra/src/main/java/org/apache/bigtop/manager/stack/infra/v1_0_0/grafana/GrafanaServerScript.java
index 23209b8d..b575a436 100644
---
a/bigtop-manager-stack/bigtop-manager-stack-infra/src/main/java/org/apache/bigtop/manager/stack/infra/v1_0_0/grafana/GrafanaServerScript.java
+++
b/bigtop-manager-stack/bigtop-manager-stack-infra/src/main/java/org/apache/bigtop/manager/stack/infra/v1_0_0/grafana/GrafanaServerScript.java
@@ -54,7 +54,6 @@ public class GrafanaServerScript extends AbstractServerScript
{
GrafanaParams grafanaParams = (GrafanaParams) params;
String cmd = MessageFormat.format(
"nohup {0}/bin/grafana server --homepath {0} > {0}/nohup.out
2>&1 &", grafanaParams.serviceHome());
- log.info(cmd);
try {
ShellResult shellResult = LinuxOSUtils.sudoExecCmd(cmd,
grafanaParams.user());
if (shellResult.getExitCode() != 0) {
diff --git
a/bigtop-manager-stack/bigtop-manager-stack-infra/src/main/java/org/apache/bigtop/manager/stack/infra/v1_0_0/mysql/MySQLClientScript.java
b/bigtop-manager-stack/bigtop-manager-stack-infra/src/main/java/org/apache/bigtop/manager/stack/infra/v1_0_0/mysql/MySQLClientScript.java
new file mode 100644
index 00000000..a6ff2973
--- /dev/null
+++
b/bigtop-manager-stack/bigtop-manager-stack-infra/src/main/java/org/apache/bigtop/manager/stack/infra/v1_0_0/mysql/MySQLClientScript.java
@@ -0,0 +1,52 @@
+/*
+ * 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
+ *
+ * https://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.bigtop.manager.stack.infra.v1_0_0.mysql;
+
+import org.apache.bigtop.manager.common.shell.ShellResult;
+import org.apache.bigtop.manager.stack.core.spi.param.Params;
+import org.apache.bigtop.manager.stack.core.spi.script.AbstractClientScript;
+import org.apache.bigtop.manager.stack.core.spi.script.Script;
+
+import com.google.auto.service.AutoService;
+import lombok.extern.slf4j.Slf4j;
+
+import java.util.Properties;
+
+@Slf4j
+@AutoService(Script.class)
+public class MySQLClientScript extends AbstractClientScript {
+
+ @Override
+ public ShellResult add(Params params) {
+ Properties properties = new Properties();
+ properties.setProperty(PROPERTY_KEY_SKIP_LEVELS, "1");
+
+ return super.add(params, properties);
+ }
+
+ @Override
+ public ShellResult configure(Params params) {
+ return MySQLSetup.configure(params);
+ }
+
+ @Override
+ public String getComponentName() {
+ return "mysql_client";
+ }
+}
diff --git
a/bigtop-manager-stack/bigtop-manager-stack-infra/src/main/java/org/apache/bigtop/manager/stack/infra/v1_0_0/mysql/MySQLParams.java
b/bigtop-manager-stack/bigtop-manager-stack-infra/src/main/java/org/apache/bigtop/manager/stack/infra/v1_0_0/mysql/MySQLParams.java
new file mode 100644
index 00000000..7a7cf7dd
--- /dev/null
+++
b/bigtop-manager-stack/bigtop-manager-stack-infra/src/main/java/org/apache/bigtop/manager/stack/infra/v1_0_0/mysql/MySQLParams.java
@@ -0,0 +1,76 @@
+/*
+ * 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
+ *
+ * https://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.bigtop.manager.stack.infra.v1_0_0.mysql;
+
+import org.apache.bigtop.manager.common.message.entity.payload.CommandPayload;
+import org.apache.bigtop.manager.stack.core.annotations.GlobalParams;
+import org.apache.bigtop.manager.stack.core.spi.param.Params;
+import org.apache.bigtop.manager.stack.core.utils.LocalSettings;
+import org.apache.bigtop.manager.stack.infra.param.InfraParams;
+
+import com.google.auto.service.AutoService;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+
+import java.util.Map;
+
+@Getter
+@Slf4j
+@AutoService(Params.class)
+@NoArgsConstructor
+public class MySQLParams extends InfraParams {
+
+ private String mysqlLogDir = "/var/log/mysql";
+ private String mysqlPidDir = "/var/run/mysql";
+
+ private String rootPassword;
+ private String myCnfContent;
+
+ public MySQLParams(CommandPayload commandPayload) {
+ super(commandPayload);
+
+ globalParamsMap.put("mysql_home", serviceHome());
+ globalParamsMap.put("mysql_conf_dir", confDir());
+ globalParamsMap.put("mysql_user", user());
+ globalParamsMap.put("mysql_group", group());
+
+ common();
+ }
+
+ public Map<String, Object> common() {
+ Map<String, Object> common =
LocalSettings.configurations(getServiceName(), "common");
+ rootPassword = common.get("root_password").toString();
+ return common;
+ }
+
+ @GlobalParams
+ public Map<String, Object> myCnf() {
+ Map<String, Object> myCnf =
LocalSettings.configurations(getServiceName(), "my.cnf");
+ mysqlPidDir = myCnf.get("mysql_pid_dir").toString();
+ mysqlLogDir = myCnf.get("mysql_log_dir").toString();
+ myCnfContent = myCnf.get("content").toString();
+ return myCnf;
+ }
+
+ @Override
+ public String getServiceName() {
+ return "mysql";
+ }
+}
diff --git
a/bigtop-manager-stack/bigtop-manager-stack-infra/src/main/java/org/apache/bigtop/manager/stack/infra/v1_0_0/grafana/GrafanaServerScript.java
b/bigtop-manager-stack/bigtop-manager-stack-infra/src/main/java/org/apache/bigtop/manager/stack/infra/v1_0_0/mysql/MySQLServerScript.java
similarity index 52%
copy from
bigtop-manager-stack/bigtop-manager-stack-infra/src/main/java/org/apache/bigtop/manager/stack/infra/v1_0_0/grafana/GrafanaServerScript.java
copy to
bigtop-manager-stack/bigtop-manager-stack-infra/src/main/java/org/apache/bigtop/manager/stack/infra/v1_0_0/mysql/MySQLServerScript.java
index 23209b8d..bc8724c1 100644
---
a/bigtop-manager-stack/bigtop-manager-stack-infra/src/main/java/org/apache/bigtop/manager/stack/infra/v1_0_0/grafana/GrafanaServerScript.java
+++
b/bigtop-manager-stack/bigtop-manager-stack-infra/src/main/java/org/apache/bigtop/manager/stack/infra/v1_0_0/mysql/MySQLServerScript.java
@@ -16,8 +16,9 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.bigtop.manager.stack.infra.v1_0_0.grafana;
+package org.apache.bigtop.manager.stack.infra.v1_0_0.mysql;
+import org.apache.bigtop.manager.common.constants.MessageConstants;
import org.apache.bigtop.manager.common.shell.ShellResult;
import org.apache.bigtop.manager.stack.core.exception.StackException;
import org.apache.bigtop.manager.stack.core.spi.param.Params;
@@ -28,37 +29,53 @@ import
org.apache.bigtop.manager.stack.core.utils.linux.LinuxOSUtils;
import com.google.auto.service.AutoService;
import lombok.extern.slf4j.Slf4j;
+import java.io.IOException;
import java.text.MessageFormat;
import java.util.Properties;
-@AutoService(Script.class)
@Slf4j
-public class GrafanaServerScript extends AbstractServerScript {
+@AutoService(Script.class)
+public class MySQLServerScript extends AbstractServerScript {
@Override
public ShellResult add(Params params) {
Properties properties = new Properties();
properties.setProperty(PROPERTY_KEY_SKIP_LEVELS, "1");
- return super.add(params, properties);
+ super.add(params, properties);
+
+ // Initialize server after added
+ log.info("Initializing MySQL root user");
+ String user = params.user();
+ String binDir = params.serviceHome() + "/bin";
+ configure(params);
+ runCommand(binDir + "/mysqld --initialize-insecure", user);
+ start(params);
+ runCommand(binDir + "/mysql -u root -e \"ALTER USER 'root'@'localhost'
IDENTIFIED BY 'root';\"", user);
+ runCommand(binDir + "/mysql -u root -p'root' -e\"CREATE USER
'root'@'%' IDENTIFIED BY 'root';\"", user);
+ runCommand(
+ binDir + "/mysql -u root -p'root' -e \"GRANT ALL PRIVILEGES ON
*.* TO 'root'@'%' WITH GRANT OPTION;\"",
+ user);
+ stop(params);
+
+ return ShellResult.success();
}
@Override
public ShellResult configure(Params params) {
- return GrafanaSetup.config(params);
+ return MySQLSetup.configure(params);
}
@Override
public ShellResult start(Params params) {
configure(params);
- GrafanaParams grafanaParams = (GrafanaParams) params;
- String cmd = MessageFormat.format(
- "nohup {0}/bin/grafana server --homepath {0} > {0}/nohup.out
2>&1 &", grafanaParams.serviceHome());
- log.info(cmd);
+ MySQLParams mysqlParams = (MySQLParams) params;
+
+ String cmd = getStartCommand(params);
try {
- ShellResult shellResult = LinuxOSUtils.sudoExecCmd(cmd,
grafanaParams.user());
+ ShellResult shellResult = LinuxOSUtils.sudoExecCmd(cmd,
mysqlParams.user());
if (shellResult.getExitCode() != 0) {
- throw new StackException("Failed to start Grafana: {0}",
shellResult.getErrMsg());
+ throw new StackException("Failed to start MySQL: {0}",
shellResult.getErrMsg());
}
long startTime = System.currentTimeMillis();
long maxWaitTime = 5000;
@@ -79,33 +96,46 @@ public class GrafanaServerScript extends
AbstractServerScript {
@Override
public ShellResult stop(Params params) {
- GrafanaParams grafanaParams = (GrafanaParams) params;
- String cmd = MessageFormat.format("pkill -f {0}/bin/grafana",
grafanaParams.serviceHome());
+ MySQLParams mysqlParams = (MySQLParams) params;
+ String cmd = getStopCommand(params);
try {
- return LinuxOSUtils.sudoExecCmd(cmd, grafanaParams.user());
- } catch (Exception e) {
+ return LinuxOSUtils.sudoExecCmd(cmd, mysqlParams.user());
+ } catch (IOException e) {
throw new StackException(e);
}
}
@Override
public ShellResult status(Params params) {
- GrafanaParams grafanaParams = (GrafanaParams) params;
- String cmd = MessageFormat.format("pgrep -f {0}/bin/grafana",
grafanaParams.serviceHome());
+ MySQLParams mysqlParams = (MySQLParams) params;
+ return LinuxOSUtils.checkProcess(mysqlParams.getMysqlPidDir() +
"/mysqld.pid");
+ }
+
+ private String getStartCommand(Params params) {
+ MySQLParams mysqlParams = (MySQLParams) params;
+ return MessageFormat.format("nohup {0}/bin/mysqld_safe > /dev/null
2>&1 &", mysqlParams.serviceHome());
+ }
+
+ private String getStopCommand(Params params) {
+ MySQLParams mysqlParams = (MySQLParams) params;
+ return MessageFormat.format(
+ "{0}/bin/mysqladmin -u root -p''{1}'' shutdown",
+ mysqlParams.serviceHome(), mysqlParams.getRootPassword());
+ }
+
+ private void runCommand(String cmd, String user) {
try {
- ShellResult result = LinuxOSUtils.execCmd(cmd);
- if (result.getExitCode() == 0) {
- return ShellResult.success();
- } else {
- return new ShellResult(-1, "", "Grafana is not running");
+ ShellResult shellResult = LinuxOSUtils.sudoExecCmd(cmd, user);
+ if (shellResult.getExitCode() != MessageConstants.SUCCESS_CODE) {
+ throw new StackException(shellResult.getErrMsg());
}
- } catch (Exception e) {
+ } catch (IOException e) {
throw new StackException(e);
}
}
@Override
public String getComponentName() {
- return "grafana_server";
+ return "mysql_server";
}
}
diff --git
a/bigtop-manager-stack/bigtop-manager-stack-infra/src/main/java/org/apache/bigtop/manager/stack/infra/v1_0_0/mysql/MySQLSetup.java
b/bigtop-manager-stack/bigtop-manager-stack-infra/src/main/java/org/apache/bigtop/manager/stack/infra/v1_0_0/mysql/MySQLSetup.java
new file mode 100644
index 00000000..097b4c41
--- /dev/null
+++
b/bigtop-manager-stack/bigtop-manager-stack-infra/src/main/java/org/apache/bigtop/manager/stack/infra/v1_0_0/mysql/MySQLSetup.java
@@ -0,0 +1,59 @@
+/*
+ * 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
+ *
+ * https://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.bigtop.manager.stack.infra.v1_0_0.mysql;
+
+import org.apache.bigtop.manager.common.constants.Constants;
+import org.apache.bigtop.manager.common.shell.ShellResult;
+import org.apache.bigtop.manager.stack.core.spi.param.Params;
+import org.apache.bigtop.manager.stack.core.utils.linux.LinuxFileUtils;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+
+import java.text.MessageFormat;
+
+import static
org.apache.bigtop.manager.common.constants.Constants.PERMISSION_755;
+
+@Slf4j
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public class MySQLSetup {
+
+ public static ShellResult configure(Params params) {
+ log.info("Configuring MySQL");
+ MySQLParams mysqlParams = (MySQLParams) params;
+
+ String mysqlUser = mysqlParams.user();
+ String mysqlGroup = mysqlParams.group();
+
+ LinuxFileUtils.createDirectories(mysqlParams.getMysqlLogDir(),
mysqlUser, mysqlGroup, PERMISSION_755, true);
+ LinuxFileUtils.createDirectories(mysqlParams.getMysqlPidDir(),
mysqlUser, mysqlGroup, PERMISSION_755, true);
+
+ LinuxFileUtils.toFileByTemplate(
+ mysqlParams.getMyCnfContent(),
+ MessageFormat.format("{0}/my.cnf", mysqlParams.serviceHome()),
+ mysqlUser,
+ mysqlGroup,
+ Constants.PERMISSION_644,
+ mysqlParams.getGlobalParamsMap());
+
+ log.info("Successfully configured MySQL");
+ return ShellResult.success();
+ }
+}