in bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/service/impl/HostServiceImpl.java [254:323]
public void installDependencies(
Map<String, RepoPO> archRepoMap, HostDTO hostDTO, String hostname, InstalledStatusVO installedStatusVO) {
String path = hostDTO.getAgentDir();
// Get host arch
String arch =
execCommandOnRemoteHost(hostDTO, hostname, "arch").getOutput().trim();
arch = arch.equals("arm64") ? "aarch64" : arch;
// Download & Extract agent tarball
String repoUrl = archRepoMap.get(arch).getBaseUrl();
String tarballUrl = repoUrl + "/bigtop-manager-agent.tar.gz";
String command = "sudo mkdir -p " + path + " &&"
+ " sudo chown -R " + hostDTO.getSshUser() + ":" + hostDTO.getSshUser() + " " + path
+ " && curl -L " + tarballUrl + " | tar -xz -C " + path;
ShellResult result = execCommandOnRemoteHost(hostDTO, hostname, command);
if (result.getExitCode() != MessageConstants.SUCCESS_CODE) {
log.error(
"Unable to download & extract agent tarball, hostname: {}, msg: {}", hostname, result.getErrMsg());
installedStatusVO.setStatus(InstalledStatusEnum.FAILED);
installedStatusVO.setMessage(result.getErrMsg());
return;
}
// Update agent conf
// Current only grpc port needs to be updated if it's not default port
if (hostDTO.getGrpcPort() != 8835) {
command = "sed -i 's/port: 8835/port: " + hostDTO.getGrpcPort() + "/' " + path
+ "/bigtop-manager-agent/conf/application.yml";
result = execCommandOnRemoteHost(hostDTO, hostname, command);
if (result.getExitCode() != MessageConstants.SUCCESS_CODE) {
log.error("Unable to update agent config, hostname: {}, msg: {}", hostname, result.getErrMsg());
installedStatusVO.setStatus(InstalledStatusEnum.FAILED);
installedStatusVO.setMessage(result.getErrMsg());
return;
}
}
// Run agent in background
command = "nohup " + path + "/bigtop-manager-agent/bin/start.sh --debug > /dev/null 2>&1 &";
result = execCommandOnRemoteHost(hostDTO, hostname, command);
if (result.getExitCode() != MessageConstants.SUCCESS_CODE) {
log.error("Unable to start agent, hostname: {}, msg: {}", hostname, result.getErrMsg());
installedStatusVO.setStatus(InstalledStatusEnum.FAILED);
installedStatusVO.setMessage(result.getErrMsg());
return;
}
// Check the process, the agent may encounter some errors and exit when starting
// So we need to wait for a while before the check
try {
Thread.sleep(10 * 1000);
} catch (InterruptedException e) {
log.error("Thread sleep interrupted", e);
}
command = "ps -ef | grep bigtop-manager-agent | grep -v grep";
result = execCommandOnRemoteHost(hostDTO, hostname, command);
if (result.getExitCode() != MessageConstants.SUCCESS_CODE
|| !result.getOutput().contains("bigtop-manager-agent")) {
log.error("Unable to start agent process, hostname: {}", hostname);
installedStatusVO.setStatus(InstalledStatusEnum.FAILED);
installedStatusVO.setMessage("Unable to start agent, please check the log.");
return;
}
installedStatusVO.setStatus(InstalledStatusEnum.SUCCESS);
}