From 36e13800ce5750bf1a665cffec23f0c50df732d4 Mon Sep 17 00:00:00 2001 From: Zhiguo Wu Date: Fri, 20 Dec 2024 15:02:42 +0800 Subject: [PATCH 1/2] BIGTOP-4307: Add task for cluster jdk setup --- .../executor/SetupJdkCommandExecutor.java | 87 +++++++++++++++++++ .../src/main/resources/proto/command.proto | 1 + .../server/command/job/ClusterAddJob.java | 2 + .../server/command/stage/SetupJdkStage.java | 58 +++++++++++++ .../server/command/task/SetupJdkTask.java | 52 +++++++++++ .../hadoop/configuration/mapred-env.xml | 1 - .../hadoop/configuration/yarn-env.xml | 1 - .../bigtop/3.3.0/services/hbase/metainfo.xml | 1 - .../bigtop/v3_3_0/flink/FlinkParams.java | 3 +- .../bigtop/v3_3_0/hadoop/HadoopParams.java | 3 +- .../bigtop/v3_3_0/hbase/HBaseParams.java | 3 +- .../bigtop/v3_3_0/kafka/KafkaParams.java | 3 +- .../stack/bigtop/v3_3_0/solr/SolrParams.java | 3 +- .../stack/bigtop/v3_3_0/tez/TezParams.java | 3 +- .../v3_3_0/zookeeper/ZookeeperParams.java | 3 +- .../stack/core/spi/param/BaseParams.java | 6 ++ .../manager/stack/core/spi/param/Params.java | 4 +- .../stack/infra/param/InfraParams.java | 26 ++++-- .../infra/v1_0_0/mysql/MySQLServerScript.java | 18 +++- 19 files changed, 248 insertions(+), 30 deletions(-) create mode 100644 bigtop-manager-agent/src/main/java/org/apache/bigtop/manager/agent/executor/SetupJdkCommandExecutor.java create mode 100644 bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/command/stage/SetupJdkStage.java create mode 100644 bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/command/task/SetupJdkTask.java diff --git a/bigtop-manager-agent/src/main/java/org/apache/bigtop/manager/agent/executor/SetupJdkCommandExecutor.java b/bigtop-manager-agent/src/main/java/org/apache/bigtop/manager/agent/executor/SetupJdkCommandExecutor.java new file mode 100644 index 00000000..d649d784 --- /dev/null +++ b/bigtop-manager-agent/src/main/java/org/apache/bigtop/manager/agent/executor/SetupJdkCommandExecutor.java @@ -0,0 +1,87 @@ +/* + * 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.agent.executor; + +import org.apache.bigtop.manager.common.constants.Constants; +import org.apache.bigtop.manager.common.message.entity.pojo.ClusterInfo; +import org.apache.bigtop.manager.common.message.entity.pojo.PackageInfo; +import org.apache.bigtop.manager.common.message.entity.pojo.RepoInfo; +import org.apache.bigtop.manager.common.utils.os.OSDetection; +import org.apache.bigtop.manager.grpc.generated.CommandType; +import org.apache.bigtop.manager.stack.core.utils.LocalSettings; +import org.apache.bigtop.manager.stack.core.utils.TarballUtils; +import org.apache.bigtop.manager.stack.core.utils.linux.LinuxFileUtils; + +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; + +import lombok.extern.slf4j.Slf4j; + +import java.text.MessageFormat; + +@Slf4j +@Component +@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) +public class SetupJdkCommandExecutor extends AbstractCommandExecutor { + + @Override + public CommandType getCommandType() { + return CommandType.SETUP_JDK; + } + + /** + * TODO JDK info currently is hardcoded, need to improve and make it configurable. + */ + @Override + public void doExecute() { + log.info("Setting up cluster jdk..."); + String arch = OSDetection.getArch(); + String pkgName = getPkgName(arch); + String checksum = getChecksum(arch); + PackageInfo packageInfo = new PackageInfo(pkgName, checksum); + ClusterInfo clusterInfo = LocalSettings.cluster(); + RepoInfo repoInfo = LocalSettings.repos().stream() + .filter(r -> arch.equals(r.getArch()) && r.getType() == 2) + .findFirst() + .orElseThrow(() -> new RuntimeException( + "Cannot find repo for os: [" + OSDetection.getOS() + "] and arch: [" + arch + "]")); + String toolsHome = clusterInfo.getRootDir() + "/tools"; + String user = System.getProperty("user.name"); + LinuxFileUtils.createDirectories(toolsHome, user, user, Constants.PERMISSION_755, true); + + String jdkHome = toolsHome + "/jdk"; + TarballUtils.installPackage(repoInfo.getBaseUrl(), toolsHome, jdkHome, packageInfo, 1); + LinuxFileUtils.createDirectories(jdkHome, user, user, Constants.PERMISSION_755, true); + } + + private String getPkgName(String arch) { + String replacedArch = arch.equals("x86_64") ? "x64" : arch; + replacedArch = replacedArch.equals("arm64") ? "aarch64" : arch; + return MessageFormat.format("jdk-8u431-linux-{0}.tar.gz", replacedArch); + } + + private String getChecksum(String arch) { + return switch (arch) { + case "x64", "x86_64" -> "SHA-256:b396978a716b7d23ccccabfe5c47c3b75d2434d7f8f7af690bc648172382720d"; + case "arm64", "aarch64" -> "SHA-256:e68d3e31ffcf7f05a4de65d04974843073bdff238bb6524adb272de9e616be7c"; + default -> throw new RuntimeException("Unknown arch for jdk: " + arch); + }; + } +} diff --git a/bigtop-manager-grpc/src/main/resources/proto/command.proto b/bigtop-manager-grpc/src/main/resources/proto/command.proto index e1c1b747..2caa03e3 100644 --- a/bigtop-manager-grpc/src/main/resources/proto/command.proto +++ b/bigtop-manager-grpc/src/main/resources/proto/command.proto @@ -30,6 +30,7 @@ enum CommandType { COMPONENT = 0; HOST_CHECK = 1; UPDATE_CACHE_FILES = 2; + SETUP_JDK = 3; } message CommandRequest { diff --git a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/command/job/ClusterAddJob.java b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/command/job/ClusterAddJob.java index 99f1e55b..cad25f8f 100644 --- a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/command/job/ClusterAddJob.java +++ b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/command/job/ClusterAddJob.java @@ -25,6 +25,7 @@ import org.apache.bigtop.manager.dao.repository.HostDao; import org.apache.bigtop.manager.server.command.stage.CacheFileUpdateStage; import org.apache.bigtop.manager.server.command.stage.HostCheckStage; +import org.apache.bigtop.manager.server.command.stage.SetupJdkStage; import org.apache.bigtop.manager.server.command.stage.Stage; import org.apache.bigtop.manager.server.command.stage.StageContext; import org.apache.bigtop.manager.server.command.task.Task; @@ -57,6 +58,7 @@ protected void createStages() { StageContext stageContext = StageContext.fromCommandDTO(jobContext.getCommandDTO()); stages.add(new HostCheckStage(stageContext)); stages.add(new CacheFileUpdateStage(stageContext)); + stages.add(new SetupJdkStage(stageContext)); } @Override diff --git a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/command/stage/SetupJdkStage.java b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/command/stage/SetupJdkStage.java new file mode 100644 index 00000000..023a5bd9 --- /dev/null +++ b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/command/stage/SetupJdkStage.java @@ -0,0 +1,58 @@ +/* + * 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.server.command.stage; + +import org.apache.bigtop.manager.server.command.task.SetupJdkTask; +import org.apache.bigtop.manager.server.command.task.Task; +import org.apache.bigtop.manager.server.command.task.TaskContext; +import org.apache.bigtop.manager.server.model.dto.HostDTO; + +public class SetupJdkStage extends AbstractStage { + + public SetupJdkStage(StageContext stageContext) { + super(stageContext); + } + + @Override + protected void injectBeans() { + super.injectBeans(); + } + + @Override + protected void beforeCreateTasks() {} + + @Override + protected Task createTask(HostDTO hostDTO) { + TaskContext taskContext = new TaskContext(); + taskContext.setHostDTO(hostDTO); + taskContext.setClusterId(stageContext.getClusterId()); + taskContext.setClusterName(stageContext.getClusterName()); + taskContext.setServiceName("cluster"); + taskContext.setServiceUser("root"); + taskContext.setComponentName("agent"); + taskContext.setComponentDisplayName("Agent"); + + return new SetupJdkTask(taskContext); + } + + @Override + public String getName() { + return "Setup JDK"; + } +} diff --git a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/command/task/SetupJdkTask.java b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/command/task/SetupJdkTask.java new file mode 100644 index 00000000..acc275e6 --- /dev/null +++ b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/command/task/SetupJdkTask.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.server.command.task; + +import org.apache.bigtop.manager.common.enums.Command; +import org.apache.bigtop.manager.grpc.generated.CommandRequest; +import org.apache.bigtop.manager.grpc.generated.CommandType; + +public class SetupJdkTask extends AbstractTask { + + public SetupJdkTask(TaskContext taskContext) { + super(taskContext); + } + + @Override + protected Command getCommand() { + return Command.CUSTOM; + } + + @Override + protected String getCustomCommand() { + return "setup_jdk"; + } + + @Override + protected CommandRequest getCommandRequest() { + CommandRequest.Builder builder = CommandRequest.newBuilder(); + builder.setType(CommandType.SETUP_JDK); + return builder.build(); + } + + @Override + public String getName() { + return "Check host " + taskContext.getHostDTO().getHostname(); + } +} diff --git a/bigtop-manager-server/src/main/resources/stacks/bigtop/3.3.0/services/hadoop/configuration/mapred-env.xml b/bigtop-manager-server/src/main/resources/stacks/bigtop/3.3.0/services/hadoop/configuration/mapred-env.xml index 99be3204..095de495 100644 --- a/bigtop-manager-server/src/main/resources/stacks/bigtop/3.3.0/services/hadoop/configuration/mapred-env.xml +++ b/bigtop-manager-server/src/main/resources/stacks/bigtop/3.3.0/services/hadoop/configuration/mapred-env.xml @@ -39,7 +39,6 @@ export HADOOP_HOME=${hadoop_home} # Could be enabled from deployment option if necessary export MAPRED_HISTORYSERVER_OPTS="$MAPRED_HISTORYSERVER_OPTS -Dhadoop.log.dir=$HADOOP_LOG_DIR" export HADOOP_LIBEXEC_DIR=${hadoop_libexec_dir} -export HADOOP_OPTS="$HADOOP_OPTS --add-opens java.base/java.lang=ALL-UNNAMED" export JAVA_HOME=${java_home} ]]> diff --git a/bigtop-manager-server/src/main/resources/stacks/bigtop/3.3.0/services/hadoop/configuration/yarn-env.xml b/bigtop-manager-server/src/main/resources/stacks/bigtop/3.3.0/services/hadoop/configuration/yarn-env.xml index 176f18bd..2c7627ca 100644 --- a/bigtop-manager-server/src/main/resources/stacks/bigtop/3.3.0/services/hadoop/configuration/yarn-env.xml +++ b/bigtop-manager-server/src/main/resources/stacks/bigtop/3.3.0/services/hadoop/configuration/yarn-env.xml @@ -166,7 +166,6 @@ HADOOP_OPTS="$HADOOP_OPTS -Djava.library.path=$JAVA_LIBRARY_PATH" fi HADOOP_OPTS="$HADOOP_OPTS -Dyarn.policy.file=$YARN_POLICYFILE" -HADOOP_OPTS="$HADOOP_OPTS --add-opens java.base/java.lang=ALL-UNNAMED" ]]> diff --git a/bigtop-manager-server/src/main/resources/stacks/bigtop/3.3.0/services/hbase/metainfo.xml b/bigtop-manager-server/src/main/resources/stacks/bigtop/3.3.0/services/hbase/metainfo.xml index 3c03ab67..13e94521 100644 --- a/bigtop-manager-server/src/main/resources/stacks/bigtop/3.3.0/services/hbase/metainfo.xml +++ b/bigtop-manager-server/src/main/resources/stacks/bigtop/3.3.0/services/hbase/metainfo.xml @@ -77,7 +77,6 @@ - zookeeper hadoop diff --git a/bigtop-manager-stack/bigtop-manager-stack-bigtop/src/main/java/org/apache/bigtop/manager/stack/bigtop/v3_3_0/flink/FlinkParams.java b/bigtop-manager-stack/bigtop-manager-stack-bigtop/src/main/java/org/apache/bigtop/manager/stack/bigtop/v3_3_0/flink/FlinkParams.java index f7c04857..ba49a582 100644 --- a/bigtop-manager-stack/bigtop-manager-stack-bigtop/src/main/java/org/apache/bigtop/manager/stack/bigtop/v3_3_0/flink/FlinkParams.java +++ b/bigtop-manager-stack/bigtop-manager-stack-bigtop/src/main/java/org/apache/bigtop/manager/stack/bigtop/v3_3_0/flink/FlinkParams.java @@ -19,7 +19,6 @@ package org.apache.bigtop.manager.stack.bigtop.v3_3_0.flink; import org.apache.bigtop.manager.common.message.entity.payload.CommandPayload; -import org.apache.bigtop.manager.common.utils.Environments; import org.apache.bigtop.manager.stack.bigtop.param.BigtopParams; import org.apache.bigtop.manager.stack.core.annotations.GlobalParams; import org.apache.bigtop.manager.stack.core.spi.param.Params; @@ -57,7 +56,7 @@ public FlinkParams(CommandPayload commandPayload) { super(commandPayload); globalParamsMap.put("flink_user", user()); globalParamsMap.put("flink_group", group()); - globalParamsMap.put("java_home", Environments.getJavaHome()); + globalParamsMap.put("java_home", javaHome()); globalParamsMap.put("hadoop_home", hadoopHome()); globalParamsMap.put("hadoop_conf_dir", hadoopConfDir()); diff --git a/bigtop-manager-stack/bigtop-manager-stack-bigtop/src/main/java/org/apache/bigtop/manager/stack/bigtop/v3_3_0/hadoop/HadoopParams.java b/bigtop-manager-stack/bigtop-manager-stack-bigtop/src/main/java/org/apache/bigtop/manager/stack/bigtop/v3_3_0/hadoop/HadoopParams.java index 142d28af..8e344d75 100644 --- a/bigtop-manager-stack/bigtop-manager-stack-bigtop/src/main/java/org/apache/bigtop/manager/stack/bigtop/v3_3_0/hadoop/HadoopParams.java +++ b/bigtop-manager-stack/bigtop-manager-stack-bigtop/src/main/java/org/apache/bigtop/manager/stack/bigtop/v3_3_0/hadoop/HadoopParams.java @@ -19,7 +19,6 @@ package org.apache.bigtop.manager.stack.bigtop.v3_3_0.hadoop; import org.apache.bigtop.manager.common.message.entity.payload.CommandPayload; -import org.apache.bigtop.manager.common.utils.Environments; import org.apache.bigtop.manager.stack.bigtop.param.BigtopParams; import org.apache.bigtop.manager.stack.core.annotations.GlobalParams; import org.apache.bigtop.manager.stack.core.spi.param.Params; @@ -72,7 +71,7 @@ public HadoopParams(CommandPayload commandPayload) { globalParamsMap.put("hdfs_user", user()); globalParamsMap.put("hdfs_group", group()); globalParamsMap.put("datanode_hosts", LocalSettings.hosts("datanode")); - globalParamsMap.put("java_home", Environments.getJavaHome()); + globalParamsMap.put("java_home", javaHome()); globalParamsMap.put("hadoop_home", serviceHome()); globalParamsMap.put("hadoop_conf_dir", confDir()); globalParamsMap.put("hadoop_libexec_dir", serviceHome() + "/libexec"); diff --git a/bigtop-manager-stack/bigtop-manager-stack-bigtop/src/main/java/org/apache/bigtop/manager/stack/bigtop/v3_3_0/hbase/HBaseParams.java b/bigtop-manager-stack/bigtop-manager-stack-bigtop/src/main/java/org/apache/bigtop/manager/stack/bigtop/v3_3_0/hbase/HBaseParams.java index 630cdd01..887b05c4 100644 --- a/bigtop-manager-stack/bigtop-manager-stack-bigtop/src/main/java/org/apache/bigtop/manager/stack/bigtop/v3_3_0/hbase/HBaseParams.java +++ b/bigtop-manager-stack/bigtop-manager-stack-bigtop/src/main/java/org/apache/bigtop/manager/stack/bigtop/v3_3_0/hbase/HBaseParams.java @@ -19,7 +19,6 @@ package org.apache.bigtop.manager.stack.bigtop.v3_3_0.hbase; import org.apache.bigtop.manager.common.message.entity.payload.CommandPayload; -import org.apache.bigtop.manager.common.utils.Environments; import org.apache.bigtop.manager.stack.bigtop.param.BigtopParams; import org.apache.bigtop.manager.stack.core.annotations.GlobalParams; import org.apache.bigtop.manager.stack.core.spi.param.Params; @@ -51,7 +50,7 @@ public class HBaseParams extends BigtopParams { public HBaseParams(CommandPayload commandPayload) { super(commandPayload); - globalParamsMap.put("java_home", Environments.getJavaHome()); + globalParamsMap.put("java_home", javaHome()); globalParamsMap.put("hbase_home", serviceHome()); globalParamsMap.put("hbase_conf_dir", confDir()); globalParamsMap.put("security_enabled", false); diff --git a/bigtop-manager-stack/bigtop-manager-stack-bigtop/src/main/java/org/apache/bigtop/manager/stack/bigtop/v3_3_0/kafka/KafkaParams.java b/bigtop-manager-stack/bigtop-manager-stack-bigtop/src/main/java/org/apache/bigtop/manager/stack/bigtop/v3_3_0/kafka/KafkaParams.java index ce126a59..397ed40c 100644 --- a/bigtop-manager-stack/bigtop-manager-stack-bigtop/src/main/java/org/apache/bigtop/manager/stack/bigtop/v3_3_0/kafka/KafkaParams.java +++ b/bigtop-manager-stack/bigtop-manager-stack-bigtop/src/main/java/org/apache/bigtop/manager/stack/bigtop/v3_3_0/kafka/KafkaParams.java @@ -19,7 +19,6 @@ package org.apache.bigtop.manager.stack.bigtop.v3_3_0.kafka; import org.apache.bigtop.manager.common.message.entity.payload.CommandPayload; -import org.apache.bigtop.manager.common.utils.Environments; import org.apache.bigtop.manager.stack.bigtop.param.BigtopParams; import org.apache.bigtop.manager.stack.core.annotations.GlobalParams; import org.apache.bigtop.manager.stack.core.spi.param.Params; @@ -47,7 +46,7 @@ public KafkaParams(CommandPayload commandPayload) { super(commandPayload); globalParamsMap.put("kafka_user", user()); globalParamsMap.put("kafka_group", group()); - globalParamsMap.put("java_home", Environments.getJavaHome()); + globalParamsMap.put("java_home", javaHome()); globalParamsMap.put("kafka_conf_dir", confDir()); globalParamsMap.put("security_enabled", false); } diff --git a/bigtop-manager-stack/bigtop-manager-stack-bigtop/src/main/java/org/apache/bigtop/manager/stack/bigtop/v3_3_0/solr/SolrParams.java b/bigtop-manager-stack/bigtop-manager-stack-bigtop/src/main/java/org/apache/bigtop/manager/stack/bigtop/v3_3_0/solr/SolrParams.java index 1beb8653..5b6df94a 100644 --- a/bigtop-manager-stack/bigtop-manager-stack-bigtop/src/main/java/org/apache/bigtop/manager/stack/bigtop/v3_3_0/solr/SolrParams.java +++ b/bigtop-manager-stack/bigtop-manager-stack-bigtop/src/main/java/org/apache/bigtop/manager/stack/bigtop/v3_3_0/solr/SolrParams.java @@ -19,7 +19,6 @@ package org.apache.bigtop.manager.stack.bigtop.v3_3_0.solr; import org.apache.bigtop.manager.common.message.entity.payload.CommandPayload; -import org.apache.bigtop.manager.common.utils.Environments; import org.apache.bigtop.manager.stack.bigtop.param.BigtopParams; import org.apache.bigtop.manager.stack.core.annotations.GlobalParams; import org.apache.bigtop.manager.stack.core.spi.param.Params; @@ -51,7 +50,7 @@ public class SolrParams extends BigtopParams { public SolrParams(CommandPayload commandPayload) { super(commandPayload); - globalParamsMap.put("java_home", Environments.getJavaHome()); + globalParamsMap.put("java_home", javaHome()); globalParamsMap.put("solr_home", serviceHome()); globalParamsMap.put("security_enabled", false); globalParamsMap.put("solr_pid_file", solrPidFile); diff --git a/bigtop-manager-stack/bigtop-manager-stack-bigtop/src/main/java/org/apache/bigtop/manager/stack/bigtop/v3_3_0/tez/TezParams.java b/bigtop-manager-stack/bigtop-manager-stack-bigtop/src/main/java/org/apache/bigtop/manager/stack/bigtop/v3_3_0/tez/TezParams.java index 3d2c8784..0586507e 100644 --- a/bigtop-manager-stack/bigtop-manager-stack-bigtop/src/main/java/org/apache/bigtop/manager/stack/bigtop/v3_3_0/tez/TezParams.java +++ b/bigtop-manager-stack/bigtop-manager-stack-bigtop/src/main/java/org/apache/bigtop/manager/stack/bigtop/v3_3_0/tez/TezParams.java @@ -19,7 +19,6 @@ package org.apache.bigtop.manager.stack.bigtop.v3_3_0.tez; import org.apache.bigtop.manager.common.message.entity.payload.CommandPayload; -import org.apache.bigtop.manager.common.utils.Environments; import org.apache.bigtop.manager.stack.bigtop.param.BigtopParams; import org.apache.bigtop.manager.stack.core.annotations.GlobalParams; import org.apache.bigtop.manager.stack.core.spi.param.Params; @@ -48,7 +47,7 @@ public TezParams(CommandPayload commandPayload) { super(commandPayload); globalParamsMap.put("tez_user", user()); globalParamsMap.put("tez_group", group()); - globalParamsMap.put("java_home", Environments.getJavaHome()); + globalParamsMap.put("java_home", javaHome()); globalParamsMap.put("hadoop_home", hadoopHome()); globalParamsMap.put("hadoop_conf_dir", hadoopConfDir()); globalParamsMap.put("tez_home", serviceHome()); diff --git a/bigtop-manager-stack/bigtop-manager-stack-bigtop/src/main/java/org/apache/bigtop/manager/stack/bigtop/v3_3_0/zookeeper/ZookeeperParams.java b/bigtop-manager-stack/bigtop-manager-stack-bigtop/src/main/java/org/apache/bigtop/manager/stack/bigtop/v3_3_0/zookeeper/ZookeeperParams.java index c7f82b3b..85497397 100644 --- a/bigtop-manager-stack/bigtop-manager-stack-bigtop/src/main/java/org/apache/bigtop/manager/stack/bigtop/v3_3_0/zookeeper/ZookeeperParams.java +++ b/bigtop-manager-stack/bigtop-manager-stack-bigtop/src/main/java/org/apache/bigtop/manager/stack/bigtop/v3_3_0/zookeeper/ZookeeperParams.java @@ -19,7 +19,6 @@ package org.apache.bigtop.manager.stack.bigtop.v3_3_0.zookeeper; import org.apache.bigtop.manager.common.message.entity.payload.CommandPayload; -import org.apache.bigtop.manager.common.utils.Environments; import org.apache.bigtop.manager.stack.bigtop.param.BigtopParams; import org.apache.bigtop.manager.stack.core.annotations.GlobalParams; import org.apache.bigtop.manager.stack.core.spi.param.Params; @@ -44,7 +43,7 @@ public class ZookeeperParams extends BigtopParams { public ZookeeperParams(CommandPayload commandPayload) { super(commandPayload); - globalParamsMap.put("java_home", Environments.getJavaHome()); + globalParamsMap.put("java_home", javaHome()); globalParamsMap.put("zookeeper_home", serviceHome()); globalParamsMap.put("security_enabled", false); globalParamsMap.put("zookeeper_pid_file", zookeeperPidFile); 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 58f761ff..c064f502 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 @@ -116,6 +116,12 @@ public List packages() { return packageInfoList; } + @Override + public String javaHome() { + String root = LocalSettings.cluster().getRootDir(); + return MessageFormat.format("{0}/tools/jdk", root); + } + @Override public String stackHome() { String root = LocalSettings.cluster().getRootDir(); diff --git a/bigtop-manager-stack/bigtop-manager-stack-core/src/main/java/org/apache/bigtop/manager/stack/core/spi/param/Params.java b/bigtop-manager-stack/bigtop-manager-stack-core/src/main/java/org/apache/bigtop/manager/stack/core/spi/param/Params.java index cc60f35b..2aa7dfef 100644 --- a/bigtop-manager-stack/bigtop-manager-stack-core/src/main/java/org/apache/bigtop/manager/stack/core/spi/param/Params.java +++ b/bigtop-manager-stack/bigtop-manager-stack-core/src/main/java/org/apache/bigtop/manager/stack/core/spi/param/Params.java @@ -36,10 +36,12 @@ public interface Params extends PrioritySPI { List packages(); - String serviceHome(); + String javaHome(); String stackHome(); + String serviceHome(); + String getServiceName(); @Override 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 a5bf3798..94934abb 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 @@ -19,8 +19,11 @@ package org.apache.bigtop.manager.stack.infra.param; import org.apache.bigtop.manager.common.message.entity.payload.CommandPayload; +import org.apache.bigtop.manager.common.utils.Environments; import org.apache.bigtop.manager.stack.core.spi.param.BaseParams; +import org.apache.commons.lang3.SystemUtils; + import lombok.NoArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -52,15 +55,20 @@ public String group() { @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(); + String parentPath; + if (Environments.isDevMode()) { + return SystemUtils.getUserDir().getParentFile().getPath(); + } else { + 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/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 index bc8724c1..7cfcdbd7 100644 --- 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 @@ -46,15 +46,27 @@ public ShellResult add(Params params) { // Initialize server after added log.info("Initializing MySQL root user"); + MySQLParams mysqlParams = (MySQLParams) params; String user = params.user(); String binDir = params.serviceHome() + "/bin"; + String password = mysqlParams.getRootPassword(); 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;\"", + MessageFormat.format( + "{0}/mysql -u root -e \"ALTER USER 'root'@'localhost' IDENTIFIED BY ''{1}'';\"", + binDir, password), + user); + runCommand( + MessageFormat.format( + "{0}/mysql -u root -p''{1}'' -e \"CREATE USER ''root''@''%'' IDENTIFIED BY ''{1}'';\"", + binDir, password), + user); + runCommand( + MessageFormat.format( + "{0}/mysql -u root -p''{1}'' -e \"GRANT ALL PRIVILEGES ON *.* TO ''root''@''%'' WITH GRANT OPTION;\"", + binDir, password), user); stop(params); From f4419b6614d7165693425de60574c9eba286f7d2 Mon Sep 17 00:00:00 2001 From: Zhiguo Wu Date: Fri, 20 Dec 2024 15:06:15 +0800 Subject: [PATCH 2/2] taskname --- .../apache/bigtop/manager/server/command/task/SetupJdkTask.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/command/task/SetupJdkTask.java b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/command/task/SetupJdkTask.java index acc275e6..179171bd 100644 --- a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/command/task/SetupJdkTask.java +++ b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/command/task/SetupJdkTask.java @@ -47,6 +47,6 @@ protected CommandRequest getCommandRequest() { @Override public String getName() { - return "Check host " + taskContext.getHostDTO().getHostname(); + return "Setup jdk for " + taskContext.getHostDTO().getHostname(); } }