Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,21 @@
*/
package org.apache.bigtop.manager.agent.executor;

import org.apache.bigtop.manager.common.constants.Constants;
import org.apache.bigtop.manager.common.constants.MessageConstants;
import org.apache.bigtop.manager.common.message.entity.payload.CacheMessagePayload;
import org.apache.bigtop.manager.common.utils.JsonUtils;
import org.apache.bigtop.manager.common.utils.ProjectPathUtils;
import org.apache.bigtop.manager.grpc.generated.CommandType;
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.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.text.MessageFormat;

import static org.apache.bigtop.manager.common.constants.CacheFiles.CLUSTER_INFO;
Expand All @@ -55,9 +57,19 @@ public CommandType getCommandType() {
public void doExecute() {
CacheMessagePayload cacheMessagePayload =
JsonUtils.readFromString(commandRequest.getPayload(), CacheMessagePayload.class);
String cacheDir = Constants.STACK_CACHE_DIR;

LinuxFileUtils.createDirectories(cacheDir, "root", "root", "rwxr-xr-x", false);
String cacheDir = ProjectPathUtils.getAgentCachePath();
Path p = Paths.get(cacheDir);
if (!Files.exists(p)) {
try {
Files.createDirectories(p);
} catch (Exception e) {
log.error("Create directory failed: {}", cacheDir, e);
commandReplyBuilder.setCode(MessageConstants.FAIL_CODE);
commandReplyBuilder.setResult(
MessageFormat.format("Create directory {0}, failed: {1}", cacheDir, e.getMessage()));
return;
}
}

JsonUtils.writeToFile(cacheDir + SETTINGS_INFO, cacheMessagePayload.getSettings());
JsonUtils.writeToFile(cacheDir + CONFIGURATIONS_INFO, cacheMessagePayload.getConfigurations());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,12 @@
*/
package org.apache.bigtop.manager.common.constants;

import java.io.File;

public final class Constants {

private Constants() {
throw new UnsupportedOperationException("Construct Constants");
}

/**
* stack cache dir
*/
public static final String STACK_CACHE_DIR =
new File(Constants.class
.getProtectionDomain()
.getCodeSource()
.getLocation()
.getPath())
.getParent() + "/../cache";

/**
* host key for all hosts
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ public static String getKeyStorePath() {
return getProjectStoreDir() + File.separator + "keys";
}

public static String getAgentCachePath() {
return getProjectStoreDir() + File.separator + "agent-caches";
}

private static String getProjectBaseDir() {
if (Environments.isDevMode()) {
return SystemUtils.getUserDir().getPath();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
package org.apache.bigtop.manager.stack.core.utils;

import org.apache.bigtop.manager.common.constants.CacheFiles;
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.ComponentInfo;
import org.apache.bigtop.manager.common.message.entity.pojo.RepoInfo;
import org.apache.bigtop.manager.common.utils.JsonUtils;
import org.apache.bigtop.manager.common.utils.ProjectPathUtils;

import com.fasterxml.jackson.core.type.TypeReference;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -45,7 +45,7 @@ public static Object configurations(String service, String type, String key, Obj
public static Map<String, Object> configurations(String service, String type) {

Map<String, Object> configDataMap = new HashMap<>();
File file = new File(Constants.STACK_CACHE_DIR + CacheFiles.CONFIGURATIONS_INFO);
File file = new File(ProjectPathUtils.getAgentCachePath() + CacheFiles.CONFIGURATIONS_INFO);
try {
if (file.exists()) {
Map<String, Map<String, Object>> configJson = JsonUtils.readFromFile(file, new TypeReference<>() {});
Expand All @@ -69,7 +69,7 @@ public static List<String> hosts(String componentName) {
public static Map<String, List<String>> hosts() {

Map<String, List<String>> hostJson = new HashMap<>();
File file = new File(Constants.STACK_CACHE_DIR + CacheFiles.HOSTS_INFO);
File file = new File(ProjectPathUtils.getAgentCachePath() + CacheFiles.HOSTS_INFO);
if (file.exists()) {
hostJson = JsonUtils.readFromFile(file, new TypeReference<>() {});
}
Expand All @@ -79,7 +79,7 @@ public static Map<String, List<String>> hosts() {
public static Map<String, Object> basicInfo() {

Map<String, Object> settings = new HashMap<>();
File file = new File(Constants.STACK_CACHE_DIR + CacheFiles.SETTINGS_INFO);
File file = new File(ProjectPathUtils.getAgentCachePath() + CacheFiles.SETTINGS_INFO);
if (file.exists()) {
settings = JsonUtils.readFromFile(file, new TypeReference<>() {});
}
Expand All @@ -89,7 +89,7 @@ public static Map<String, Object> basicInfo() {
public static Map<String, String> users() {

Map<String, String> userMap = new HashMap<>();
File file = new File(Constants.STACK_CACHE_DIR + CacheFiles.USERS_INFO);
File file = new File(ProjectPathUtils.getAgentCachePath() + CacheFiles.USERS_INFO);
if (file.exists()) {
userMap = JsonUtils.readFromFile(file, new TypeReference<>() {});
}
Expand All @@ -104,7 +104,7 @@ public static List<String> packages() {
public static List<RepoInfo> repos() {

List<RepoInfo> repoInfoList = List.of();
File file = new File(Constants.STACK_CACHE_DIR + CacheFiles.REPOS_INFO);
File file = new File(ProjectPathUtils.getAgentCachePath() + CacheFiles.REPOS_INFO);
if (file.exists()) {
repoInfoList = JsonUtils.readFromFile(file, new TypeReference<>() {});
}
Expand All @@ -114,7 +114,7 @@ public static List<RepoInfo> repos() {
public static ClusterInfo cluster() {

ClusterInfo clusterInfo = new ClusterInfo();
File file = new File(Constants.STACK_CACHE_DIR + CacheFiles.CLUSTER_INFO);
File file = new File(ProjectPathUtils.getAgentCachePath() + CacheFiles.CLUSTER_INFO);
if (file.exists()) {
clusterInfo = JsonUtils.readFromFile(file, new TypeReference<>() {});
}
Expand All @@ -124,7 +124,7 @@ public static ClusterInfo cluster() {
public static Map<String, ComponentInfo> components() {

Map<String, ComponentInfo> componentInfo = new HashMap<>();
File file = new File(Constants.STACK_CACHE_DIR + CacheFiles.COMPONENTS_INFO);
File file = new File(ProjectPathUtils.getAgentCachePath() + CacheFiles.COMPONENTS_INFO);
if (file.exists()) {
componentInfo = JsonUtils.readFromFile(file, new TypeReference<>() {});
}
Expand Down