Search in sources :

Example 1 with KVEntity

use of com.ctrip.framework.apollo.portal.entity.bo.KVEntity in project apollo by ctripcorp.

the class ReleaseService method findAllReleases.

public List<ReleaseBO> findAllReleases(String appId, Env env, String clusterName, String namespaceName, int page, int size) {
    List<ReleaseDTO> releaseDTOs = releaseAPI.findAllReleases(appId, env, clusterName, namespaceName, page, size);
    if (CollectionUtils.isEmpty(releaseDTOs)) {
        return Collections.emptyList();
    }
    List<ReleaseBO> releases = new LinkedList<>();
    for (ReleaseDTO releaseDTO : releaseDTOs) {
        ReleaseBO release = new ReleaseBO();
        release.setBaseInfo(releaseDTO);
        Set<KVEntity> kvEntities = new LinkedHashSet<>();
        Map<String, String> configurations = GSON.fromJson(releaseDTO.getConfigurations(), GsonType.CONFIG);
        Set<Map.Entry<String, String>> entries = configurations.entrySet();
        for (Map.Entry<String, String> entry : entries) {
            kvEntities.add(new KVEntity(entry.getKey(), entry.getValue()));
        }
        release.setItems(kvEntities);
        // 为了减少数据量
        releaseDTO.setConfigurations("");
        releases.add(release);
    }
    return releases;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) LinkedList(java.util.LinkedList) ReleaseDTO(com.ctrip.framework.apollo.common.dto.ReleaseDTO) KVEntity(com.ctrip.framework.apollo.portal.entity.bo.KVEntity) ReleaseBO(com.ctrip.framework.apollo.portal.entity.bo.ReleaseBO) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with KVEntity

use of com.ctrip.framework.apollo.portal.entity.bo.KVEntity in project apollo by ctripcorp.

the class ReleaseService method compare.

public ReleaseCompareResult compare(ReleaseDTO baseRelease, ReleaseDTO toCompareRelease) {
    Map<String, String> baseReleaseConfiguration = baseRelease == null ? new HashMap<>() : GSON.fromJson(baseRelease.getConfigurations(), GsonType.CONFIG);
    Map<String, String> toCompareReleaseConfiguration = toCompareRelease == null ? new HashMap<>() : GSON.fromJson(toCompareRelease.getConfigurations(), GsonType.CONFIG);
    ReleaseCompareResult compareResult = new ReleaseCompareResult();
    // added and modified in firstRelease
    for (Map.Entry<String, String> entry : baseReleaseConfiguration.entrySet()) {
        String key = entry.getKey();
        String firstValue = entry.getValue();
        String secondValue = toCompareReleaseConfiguration.get(key);
        // added
        if (secondValue == null) {
            compareResult.addEntityPair(ChangeType.DELETED, new KVEntity(key, firstValue), new KVEntity(key, null));
        } else if (!Objects.equal(firstValue, secondValue)) {
            compareResult.addEntityPair(ChangeType.MODIFIED, new KVEntity(key, firstValue), new KVEntity(key, secondValue));
        }
    }
    // deleted in firstRelease
    for (Map.Entry<String, String> entry : toCompareReleaseConfiguration.entrySet()) {
        String key = entry.getKey();
        String value = entry.getValue();
        if (baseReleaseConfiguration.get(key) == null) {
            compareResult.addEntityPair(ChangeType.ADDED, new KVEntity(key, ""), new KVEntity(key, value));
        }
    }
    return compareResult;
}
Also used : KVEntity(com.ctrip.framework.apollo.portal.entity.bo.KVEntity) HashMap(java.util.HashMap) Map(java.util.Map) ReleaseCompareResult(com.ctrip.framework.apollo.portal.entity.vo.ReleaseCompareResult)

Aggregations

KVEntity (com.ctrip.framework.apollo.portal.entity.bo.KVEntity)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ReleaseDTO (com.ctrip.framework.apollo.common.dto.ReleaseDTO)1 ReleaseBO (com.ctrip.framework.apollo.portal.entity.bo.ReleaseBO)1 ReleaseCompareResult (com.ctrip.framework.apollo.portal.entity.vo.ReleaseCompareResult)1 LinkedHashSet (java.util.LinkedHashSet)1 LinkedList (java.util.LinkedList)1