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 @@
32.1.1-jre
4.4
1.26.2
+ 1.9
4.4.0
3.0.16
4.0.4
@@ -124,6 +125,12 @@
${commons-compress.version}
+
+ org.tukaani
+ xz
+ ${xz.version}
+
+
com.google.guava
guava
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 @@ protected void injectBeans() {
@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 @@
+
+
+
+
+
+ root_password
+ root
+ Root Password
+ Password for MySQL root user.
+
+
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 @@
+
+
+
+
+
+ mysql_log_dir
+ /var/log/mysql
+ MySQL Log Dir
+ MySQL Log Dir
+
+
+ mysql_pid_dir
+ /var/run/mysql
+ MySQL PID Dir
+ MySQL Pid Dir
+
+
+
+ content
+ my.cnf template
+ This is the freemarker template for my.cnf file
+
+
+
+ longtext
+
+
+
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 @@
+
+
+
+
+
+ mysql
+ MySQL
+
+ 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.
+
+ 8.0.40
+ mysql
+
+
+
+ mysql_server
+ MySQL Server
+ server
+ 1
+
+
+
+ mysql_client
+ MySQL Client
+ client
+ 1+
+
+
+
+
+
+
+ x86_64
+
+
+
+ mysql-8.0.40-linux-glibc2.28-x86_64.tar.xz
+ MD5:dcf2702f953d1969be44083f4f063f18
+
+
+
+
+
+ aarch64
+
+
+
+ mysql-8.0.40-linux-glibc2.28-aarch64.tar.xz
+ MD5:a79f41ce62784a1a0e081c76116008de
+
+
+
+
+
+
\ 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 @@
org.apache.commons
commons-compress
+
+
+ org.tukaani
+ xz
+
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 @@ private static Boolean downloadFile(String fileUrl, String saveDir) {
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.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 static void extractTarball(String source, String dest, Integer skipLevels
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 @@ private static void extractTarGz(File tarball, Function 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 static void moveFile(String source, String dest) {
}
}
+ public static String readFile(String source) {
+ if (StringUtils.isBlank(source)) {
+ throw new StackException("source must not be empty");
+ }
+
+ List 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 @@
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 static ShellResult checkProcess(String filepath) {
}
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 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 ShellResult start(Params 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);
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 common() {
+ Map common = LocalSettings.configurations(getServiceName(), "common");
+ rootPassword = common.get("root_password").toString();
+ return common;
+ }
+
+ @GlobalParams
+ public Map myCnf() {
+ Map 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/mysql/MySQLServerScript.java b/bigtop-manager-stack/bigtop-manager-stack-infra/src/main/java/org/apache/bigtop/manager/stack/infra/v1_0_0/mysql/MySQLServerScript.java
new file mode 100644
index 00000000..bc8724c1
--- /dev/null
+++ b/bigtop-manager-stack/bigtop-manager-stack-infra/src/main/java/org/apache/bigtop/manager/stack/infra/v1_0_0/mysql/MySQLServerScript.java
@@ -0,0 +1,141 @@
+/*
+ * 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.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;
+import org.apache.bigtop.manager.stack.core.spi.script.AbstractServerScript;
+import org.apache.bigtop.manager.stack.core.spi.script.Script;
+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;
+
+@Slf4j
+@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");
+
+ 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 MySQLSetup.configure(params);
+ }
+
+ @Override
+ public ShellResult start(Params params) {
+ configure(params);
+ MySQLParams mysqlParams = (MySQLParams) params;
+
+ String cmd = getStartCommand(params);
+ try {
+ ShellResult shellResult = LinuxOSUtils.sudoExecCmd(cmd, mysqlParams.user());
+ if (shellResult.getExitCode() != 0) {
+ throw new StackException("Failed to start MySQL: {0}", shellResult.getErrMsg());
+ }
+ long startTime = System.currentTimeMillis();
+ long maxWaitTime = 5000;
+ long pollInterval = 500;
+
+ while (System.currentTimeMillis() - startTime < maxWaitTime) {
+ ShellResult statusResult = status(params);
+ if (statusResult.getExitCode() == 0) {
+ return statusResult;
+ }
+ Thread.sleep(pollInterval);
+ }
+ return status(params);
+ } catch (Exception e) {
+ throw new StackException(e);
+ }
+ }
+
+ @Override
+ public ShellResult stop(Params params) {
+ MySQLParams mysqlParams = (MySQLParams) params;
+ String cmd = getStopCommand(params);
+ try {
+ return LinuxOSUtils.sudoExecCmd(cmd, mysqlParams.user());
+ } catch (IOException e) {
+ throw new StackException(e);
+ }
+ }
+
+ @Override
+ public ShellResult status(Params params) {
+ 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 shellResult = LinuxOSUtils.sudoExecCmd(cmd, user);
+ if (shellResult.getExitCode() != MessageConstants.SUCCESS_CODE) {
+ throw new StackException(shellResult.getErrMsg());
+ }
+ } catch (IOException e) {
+ throw new StackException(e);
+ }
+ }
+
+ @Override
+ public String getComponentName() {
+ 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();
+ }
+}