use of com.ctrip.framework.apollo.biz.entity.Release in project apollo by ctripcorp.
the class InstanceConfigController method getByReleasesNotIn.
@GetMapping("/by-namespace-and-releases-not-in")
public List<InstanceDTO> getByReleasesNotIn(@RequestParam("appId") String appId, @RequestParam("clusterName") String clusterName, @RequestParam("namespaceName") String namespaceName, @RequestParam("releaseIds") String releaseIds) {
Set<Long> releaseIdSet = RELEASES_SPLITTER.splitToList(releaseIds).stream().map(Long::parseLong).collect(Collectors.toSet());
List<Release> releases = releaseService.findByReleaseIds(releaseIdSet);
if (CollectionUtils.isEmpty(releases)) {
throw new NotFoundException("releases not found for %s", releaseIds);
}
Set<String> releaseKeys = releases.stream().map(Release::getReleaseKey).collect(Collectors.toSet());
List<InstanceConfig> instanceConfigs = instanceService.findInstanceConfigsByNamespaceWithReleaseKeysNotIn(appId, clusterName, namespaceName, releaseKeys);
Multimap<Long, InstanceConfig> instanceConfigMap = HashMultimap.create();
Set<String> otherReleaseKeys = Sets.newHashSet();
for (InstanceConfig instanceConfig : instanceConfigs) {
instanceConfigMap.put(instanceConfig.getInstanceId(), instanceConfig);
otherReleaseKeys.add(instanceConfig.getReleaseKey());
}
List<Instance> instances = instanceService.findInstancesByIds(instanceConfigMap.keySet());
if (CollectionUtils.isEmpty(instances)) {
return Collections.emptyList();
}
List<InstanceDTO> instanceDTOs = BeanUtils.batchTransform(InstanceDTO.class, instances);
List<Release> otherReleases = releaseService.findByReleaseKeys(otherReleaseKeys);
Map<String, ReleaseDTO> releaseMap = Maps.newHashMap();
for (Release release : otherReleases) {
// unset configurations to save space
release.setConfigurations(null);
ReleaseDTO releaseDTO = BeanUtils.transform(ReleaseDTO.class, release);
releaseMap.put(release.getReleaseKey(), releaseDTO);
}
for (InstanceDTO instanceDTO : instanceDTOs) {
Collection<InstanceConfig> configs = instanceConfigMap.get(instanceDTO.getId());
List<InstanceConfigDTO> configDTOs = configs.stream().map(instanceConfig -> {
InstanceConfigDTO instanceConfigDTO = new InstanceConfigDTO();
instanceConfigDTO.setRelease(releaseMap.get(instanceConfig.getReleaseKey()));
instanceConfigDTO.setReleaseDeliveryTime(instanceConfig.getReleaseDeliveryTime());
instanceConfigDTO.setDataChangeLastModifiedTime(instanceConfig.getDataChangeLastModifiedTime());
return instanceConfigDTO;
}).collect(Collectors.toList());
instanceDTO.setConfigs(configDTOs);
}
return instanceDTOs;
}
use of com.ctrip.framework.apollo.biz.entity.Release in project apollo by ctripcorp.
the class InstanceConfigController method getByRelease.
@GetMapping("/by-release")
public PageDTO<InstanceDTO> getByRelease(@RequestParam("releaseId") long releaseId, Pageable pageable) {
Release release = releaseService.findOne(releaseId);
if (release == null) {
throw new NotFoundException(String.format("release not found for %s", releaseId));
}
Page<InstanceConfig> instanceConfigsPage = instanceService.findActiveInstanceConfigsByReleaseKey(release.getReleaseKey(), pageable);
List<InstanceDTO> instanceDTOs = Collections.emptyList();
if (instanceConfigsPage.hasContent()) {
Multimap<Long, InstanceConfig> instanceConfigMap = HashMultimap.create();
Set<String> otherReleaseKeys = Sets.newHashSet();
for (InstanceConfig instanceConfig : instanceConfigsPage.getContent()) {
instanceConfigMap.put(instanceConfig.getInstanceId(), instanceConfig);
otherReleaseKeys.add(instanceConfig.getReleaseKey());
}
Set<Long> instanceIds = instanceConfigMap.keySet();
List<Instance> instances = instanceService.findInstancesByIds(instanceIds);
if (!CollectionUtils.isEmpty(instances)) {
instanceDTOs = BeanUtils.batchTransform(InstanceDTO.class, instances);
}
for (InstanceDTO instanceDTO : instanceDTOs) {
Collection<InstanceConfig> configs = instanceConfigMap.get(instanceDTO.getId());
List<InstanceConfigDTO> configDTOs = configs.stream().map(instanceConfig -> {
InstanceConfigDTO instanceConfigDTO = new InstanceConfigDTO();
// to save some space
instanceConfigDTO.setRelease(null);
instanceConfigDTO.setReleaseDeliveryTime(instanceConfig.getReleaseDeliveryTime());
instanceConfigDTO.setDataChangeLastModifiedTime(instanceConfig.getDataChangeLastModifiedTime());
return instanceConfigDTO;
}).collect(Collectors.toList());
instanceDTO.setConfigs(configDTOs);
}
}
return new PageDTO<>(instanceDTOs, pageable, instanceConfigsPage.getTotalElements());
}
use of com.ctrip.framework.apollo.biz.entity.Release in project apollo by ctripcorp.
the class ReleaseController method updateAndPublish.
/**
* merge branch items to master and publish master
*
* @return published result
*/
@Transactional
@PostMapping("/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/updateAndPublish")
public ReleaseDTO updateAndPublish(@PathVariable("appId") String appId, @PathVariable("clusterName") String clusterName, @PathVariable("namespaceName") String namespaceName, @RequestParam("releaseName") String releaseName, @RequestParam("branchName") String branchName, @RequestParam(value = "deleteBranch", defaultValue = "true") boolean deleteBranch, @RequestParam(name = "releaseComment", required = false) String releaseComment, @RequestParam(name = "isEmergencyPublish", defaultValue = "false") boolean isEmergencyPublish, @RequestBody ItemChangeSets changeSets) {
Namespace namespace = namespaceService.findOne(appId, clusterName, namespaceName);
if (namespace == null) {
throw new NotFoundException("Could not find namespace for %s %s %s", appId, clusterName, namespaceName);
}
Release release = releaseService.mergeBranchChangeSetsAndRelease(namespace, branchName, releaseName, releaseComment, isEmergencyPublish, changeSets);
if (deleteBranch) {
namespaceBranchService.deleteBranch(appId, clusterName, namespaceName, branchName, NamespaceBranchStatus.MERGED, changeSets.getDataChangeLastModifiedBy());
}
messageSender.sendMessage(ReleaseMessageKeyGenerator.generate(appId, clusterName, namespaceName), Topics.APOLLO_RELEASE_TOPIC);
return BeanUtils.transform(ReleaseDTO.class, release);
}
use of com.ctrip.framework.apollo.biz.entity.Release in project apollo by ctripcorp.
the class ReleaseController method publish.
@Transactional
@PostMapping("/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/releases")
public ReleaseDTO publish(@PathVariable("appId") String appId, @PathVariable("clusterName") String clusterName, @PathVariable("namespaceName") String namespaceName, @RequestParam("name") String releaseName, @RequestParam(name = "comment", required = false) String releaseComment, @RequestParam("operator") String operator, @RequestParam(name = "isEmergencyPublish", defaultValue = "false") boolean isEmergencyPublish) {
Namespace namespace = namespaceService.findOne(appId, clusterName, namespaceName);
if (namespace == null) {
throw new NotFoundException("Could not find namespace for %s %s %s", appId, clusterName, namespaceName);
}
Release release = releaseService.publish(namespace, releaseName, releaseComment, operator, isEmergencyPublish);
// send release message
Namespace parentNamespace = namespaceService.findParentNamespace(namespace);
String messageCluster;
if (parentNamespace != null) {
messageCluster = parentNamespace.getClusterName();
} else {
messageCluster = clusterName;
}
messageSender.sendMessage(ReleaseMessageKeyGenerator.generate(appId, messageCluster, namespaceName), Topics.APOLLO_RELEASE_TOPIC);
return BeanUtils.transform(ReleaseDTO.class, release);
}
use of com.ctrip.framework.apollo.biz.entity.Release in project apollo by ctripcorp.
the class ReleaseController method rollback.
@Transactional
@PutMapping("/releases/{releaseId}/rollback")
public void rollback(@PathVariable("releaseId") long releaseId, @RequestParam(name = "toReleaseId", defaultValue = "-1") long toReleaseId, @RequestParam("operator") String operator) {
Release release;
if (toReleaseId > -1) {
release = releaseService.rollbackTo(releaseId, toReleaseId, operator);
} else {
release = releaseService.rollback(releaseId, operator);
}
String appId = release.getAppId();
String clusterName = release.getClusterName();
String namespaceName = release.getNamespaceName();
// send release message
messageSender.sendMessage(ReleaseMessageKeyGenerator.generate(appId, clusterName, namespaceName), Topics.APOLLO_RELEASE_TOPIC);
}
Aggregations