Skip to content

Commit

Permalink
add nest parse
Browse files Browse the repository at this point in the history
  • Loading branch information
lhpqaq committed Dec 16, 2024
1 parent ca05ce0 commit d511e76
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
import org.apache.bigtop.manager.server.model.dto.StackDTO;
import org.apache.bigtop.manager.server.utils.StackUtils;

import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
Expand All @@ -53,6 +55,7 @@

import static org.apache.bigtop.manager.common.constants.Constants.ALL_HOST_KEY;

@Slf4j
public class CacheFileUpdateTask extends AbstractTask {

private ClusterDao clusterDao;
Expand Down Expand Up @@ -98,6 +101,18 @@ private void genCaches() {
}
}

private Map<String, Object> parseProperties(List<Map<String, Object>> properties) {
return properties.stream().collect(Collectors.toMap(property -> (String) property.get("name"), property -> {
if (property.containsKey("values")) {
@SuppressWarnings("unchecked")
List<Map<String, Object>> nestedProperties = (List<Map<String, Object>>) property.get("values");
return parseProperties(nestedProperties);
} else {
return property.get("value");
}
}));
}

@SuppressWarnings("unchecked")
private void genFullCaches() {
Long clusterId = taskContext.getClusterId();
Expand All @@ -119,10 +134,11 @@ private void genFullCaches() {
serviceConfigMap = new HashMap<>();
for (ServiceConfigPO serviceConfigPO : serviceConfigPOList) {
List<Map<String, Object>> properties = JsonUtils.readFromString(serviceConfigPO.getPropertiesJson());
Map<String, String> kvMap = properties.stream()
.collect(Collectors.toMap(
property -> (String) property.get("name"), property -> (String) property.get("value")));
log.info(properties.toString());
Map<String, Object> kvMap = parseProperties(properties);
log.info(kvMap.toString());
String kvString = JsonUtils.writeAsString(kvMap);
log.info(kvString);

if (serviceConfigMap.containsKey(serviceConfigPO.getServiceName())) {
serviceConfigMap.get(serviceConfigPO.getServiceName()).put(serviceConfigPO.getName(), kvString);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import lombok.Data;

import jakarta.validation.constraints.NotBlank;
import java.util.List;

@Data
public class PropertyReq {
Expand All @@ -35,4 +36,6 @@ public class PropertyReq {
private String desc;

private AttrsReq attrs;

private List<PropertyReq> values;
}

0 comments on commit d511e76

Please sign in to comment.