forked from apolloconfig/apollo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
152 additions
and
192 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,4 +27,5 @@ target | |
dev | ||
fat | ||
uat | ||
prd | ||
prd | ||
apollo-env.properties |
11 changes: 6 additions & 5 deletions
11
...adminservice/src/main/java/com/ctrip/apollo/adminservice/controller/ConfigController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 43 additions & 13 deletions
56
apollo-biz/src/main/java/com/ctrip/apollo/biz/service/AdminConfigService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,55 @@ | ||
package com.ctrip.apollo.biz.service; | ||
|
||
import com.google.common.base.Strings; | ||
|
||
import com.ctrip.apollo.biz.entity.Cluster; | ||
import com.ctrip.apollo.biz.entity.ConfigItem; | ||
import com.ctrip.apollo.biz.repository.ClusterRepository; | ||
import com.ctrip.apollo.biz.repository.ConfigItemRepository; | ||
import com.ctrip.apollo.biz.utils.ApolloBeanUtils; | ||
import com.ctrip.apollo.core.dto.ClusterDTO; | ||
import com.ctrip.apollo.core.dto.ConfigItemDTO; | ||
import com.ctrip.apollo.core.dto.ReleaseSnapshotDTO; | ||
import com.ctrip.apollo.core.dto.VersionDTO; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
/** | ||
* config service for admin | ||
*/ | ||
public interface AdminConfigService { | ||
|
||
List<ReleaseSnapshotDTO> findReleaseSnapshotByReleaseId(long releaseId); | ||
|
||
List<VersionDTO> findVersionsByApp(String appId); | ||
|
||
VersionDTO loadVersionById(long versionId); | ||
|
||
List<ClusterDTO> findClustersByApp(String appId); | ||
|
||
List<ConfigItemDTO> findConfigItemsByClusters(List<Long> clusterIds); | ||
@Service("adminConfigService") | ||
public class AdminConfigService { | ||
|
||
@Autowired | ||
private ClusterRepository clusterRepository; | ||
@Autowired | ||
private ConfigItemRepository configItemRepository; | ||
|
||
|
||
public List<ClusterDTO> findClustersByApp(String appId) { | ||
if (Strings.isNullOrEmpty(appId)) { | ||
return Collections.EMPTY_LIST; | ||
} | ||
List<Cluster> clusters = clusterRepository.findByAppId(appId); | ||
if (clusters == null || clusters.size() == 0) { | ||
return Collections.EMPTY_LIST; | ||
} | ||
|
||
return ApolloBeanUtils.batchTransform(ClusterDTO.class, clusters); | ||
} | ||
|
||
public List<ConfigItemDTO> findConfigItemsByClusters(List<Long> clusterIds) { | ||
if (clusterIds == null || clusterIds.size() == 0) { | ||
return Collections.EMPTY_LIST; | ||
} | ||
List<ConfigItem> configItems = configItemRepository.findByClusterIdIsIn(clusterIds); | ||
if (configItems == null || configItems.size() == 0) { | ||
return Collections.EMPTY_LIST; | ||
} | ||
|
||
return ApolloBeanUtils.batchTransform(ConfigItemDTO.class, configItems); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,12 @@ | ||
package com.ctrip.apollo.biz.service.impl; | ||
package com.ctrip.apollo.biz.service; | ||
|
||
import com.google.common.base.Strings; | ||
|
||
import com.ctrip.apollo.biz.entity.Cluster; | ||
import com.ctrip.apollo.biz.entity.ConfigItem; | ||
import com.ctrip.apollo.biz.entity.ReleaseSnapshot; | ||
import com.ctrip.apollo.biz.entity.Version; | ||
import com.ctrip.apollo.biz.repository.ClusterRepository; | ||
import com.ctrip.apollo.biz.repository.ConfigItemRepository; | ||
import com.ctrip.apollo.biz.repository.ReleaseSnapShotRepository; | ||
import com.ctrip.apollo.biz.repository.VersionRepository; | ||
import com.ctrip.apollo.biz.service.AdminConfigService; | ||
import com.ctrip.apollo.biz.utils.ApolloBeanUtils; | ||
import com.ctrip.apollo.core.dto.ClusterDTO; | ||
import com.ctrip.apollo.core.dto.ConfigItemDTO; | ||
import com.ctrip.apollo.core.dto.ReleaseSnapshotDTO; | ||
import com.ctrip.apollo.core.dto.VersionDTO; | ||
|
||
|
@@ -23,19 +16,16 @@ | |
import java.util.Collections; | ||
import java.util.List; | ||
|
||
@Service("adminConfigService") | ||
public class AdminConfigServiceImpl implements AdminConfigService { | ||
|
||
@Autowired | ||
private VersionRepository versionRepository; | ||
/** | ||
* @author Jason Song([email protected]) | ||
*/ | ||
@Service("adminReleaseService") | ||
public class AdminReleaseService { | ||
@Autowired | ||
private ReleaseSnapShotRepository releaseSnapShotRepository; | ||
@Autowired | ||
private ClusterRepository clusterRepository; | ||
@Autowired | ||
private ConfigItemRepository configItemRepository; | ||
private VersionRepository versionRepository; | ||
|
||
@Override | ||
public List<ReleaseSnapshotDTO> findReleaseSnapshotByReleaseId(long releaseId) { | ||
if (releaseId <= 0) { | ||
return Collections.EMPTY_LIST; | ||
|
@@ -50,8 +40,6 @@ public List<ReleaseSnapshotDTO> findReleaseSnapshotByReleaseId(long releaseId) { | |
return ApolloBeanUtils.batchTransform(ReleaseSnapshotDTO.class, releaseSnapShots); | ||
} | ||
|
||
|
||
@Override | ||
public List<VersionDTO> findVersionsByApp(String appId) { | ||
if (Strings.isNullOrEmpty(appId)) { | ||
return Collections.EMPTY_LIST; | ||
|
@@ -65,43 +53,15 @@ public List<VersionDTO> findVersionsByApp(String appId) { | |
return ApolloBeanUtils.batchTransform(VersionDTO.class, versions); | ||
} | ||
|
||
@Override | ||
public VersionDTO loadVersionById(long versionId) { | ||
if (versionId <= 0) { | ||
return null; | ||
} | ||
Version version = versionRepository.findById(versionId); | ||
if (version == null){ | ||
if (version == null) { | ||
return null; | ||
} | ||
VersionDTO dto = ApolloBeanUtils.transfrom(VersionDTO.class, version); | ||
return dto; | ||
} | ||
|
||
@Override | ||
public List<ClusterDTO> findClustersByApp(String appId) { | ||
if (Strings.isNullOrEmpty(appId)) { | ||
return Collections.EMPTY_LIST; | ||
} | ||
List<Cluster> clusters = clusterRepository.findByAppId(appId); | ||
if (clusters == null || clusters.size() == 0) { | ||
return Collections.EMPTY_LIST; | ||
} | ||
|
||
return ApolloBeanUtils.batchTransform(ClusterDTO.class, clusters); | ||
} | ||
|
||
@Override | ||
public List<ConfigItemDTO> findConfigItemsByClusters(List<Long> clusterIds) { | ||
if (clusterIds == null || clusterIds.size() == 0) { | ||
return Collections.EMPTY_LIST; | ||
} | ||
List<ConfigItem> configItems = configItemRepository.findByClusterIdIsIn(clusterIds); | ||
if (configItems == null || configItems.size() == 0) { | ||
return Collections.EMPTY_LIST; | ||
} | ||
|
||
return ApolloBeanUtils.batchTransform(ConfigItemDTO.class, configItems); | ||
} | ||
|
||
} |
68 changes: 64 additions & 4 deletions
68
apollo-biz/src/main/java/com/ctrip/apollo/biz/service/ConfigService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,86 @@ | ||
package com.ctrip.apollo.biz.service; | ||
|
||
import com.google.common.collect.Maps; | ||
|
||
import com.ctrip.apollo.biz.entity.ReleaseSnapshot; | ||
import com.ctrip.apollo.biz.entity.Version; | ||
import com.ctrip.apollo.biz.repository.ReleaseSnapShotRepository; | ||
import com.ctrip.apollo.biz.repository.VersionRepository; | ||
import com.ctrip.apollo.core.dto.ApolloConfig; | ||
import com.fasterxml.jackson.core.type.TypeReference; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.io.IOException; | ||
import java.util.Map; | ||
|
||
/** | ||
* Config Service | ||
* | ||
* @author Jason Song([email protected]) | ||
*/ | ||
public interface ConfigService { | ||
@Service("configService") | ||
public class ConfigService { | ||
@Autowired | ||
private VersionRepository versionRepository; | ||
@Autowired | ||
private ReleaseSnapShotRepository releaseSnapShotRepository; | ||
@Autowired | ||
private ObjectMapper objectMapper; | ||
private TypeReference<Map<String, Object>> configurationTypeReference = | ||
new TypeReference<Map<String, Object>>() { | ||
}; | ||
|
||
/** | ||
* Load configuration from database | ||
*/ | ||
ApolloConfig loadConfig(String appId, String clusterName, String versionName); | ||
public ApolloConfig loadConfig(String appId, String clusterName, String versionName) { | ||
Version version = loadVersionByAppIdAndVersionName(appId, versionName); | ||
if (version == null) { | ||
return null; | ||
} | ||
|
||
return loadConfigByVersionAndClusterName(version, clusterName); | ||
} | ||
|
||
/** | ||
* Load Version by appId and versionName from database | ||
*/ | ||
Version loadVersionByAppIdAndVersionName(String appId, String versionName); | ||
public Version loadVersionByAppIdAndVersionName(String appId, String versionName) { | ||
return versionRepository.findByAppIdAndName(appId, versionName); | ||
} | ||
|
||
/** | ||
* Load Config by version and clusterName from database | ||
*/ | ||
ApolloConfig loadConfigByVersionAndClusterName(Version version, String clusterName); | ||
public ApolloConfig loadConfigByVersionAndClusterName(Version version, String clusterName) { | ||
ReleaseSnapshot releaseSnapShot = | ||
releaseSnapShotRepository | ||
.findByReleaseIdAndClusterName(version.getReleaseId(), clusterName); | ||
if (releaseSnapShot == null) { | ||
return null; | ||
} | ||
|
||
return assembleConfig(version, releaseSnapShot); | ||
} | ||
|
||
private ApolloConfig assembleConfig(Version version, ReleaseSnapshot releaseSnapShot) { | ||
ApolloConfig config = | ||
new ApolloConfig(version.getAppId(), releaseSnapShot.getClusterName(), version.getName(), | ||
version.getReleaseId()); | ||
config.setConfigurations(transformConfigurationToMap(releaseSnapShot.getConfigurations())); | ||
|
||
return config; | ||
} | ||
|
||
Map<String, Object> transformConfigurationToMap(String configurations) { | ||
try { | ||
return objectMapper.readValue(configurations, configurationTypeReference); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
return Maps.newHashMap(); | ||
} | ||
} | ||
} |
Oops, something went wrong.