Search in sources :

Example 16 with GrayReleaseRule

use of com.ctrip.framework.apollo.biz.entity.GrayReleaseRule in project apollo by ctripcorp.

the class NamespaceBranchController method findBranchGrayRules.

@GetMapping("/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/branches/{branchName}/rules")
public GrayReleaseRuleDTO findBranchGrayRules(@PathVariable String appId, @PathVariable String clusterName, @PathVariable String namespaceName, @PathVariable String branchName) {
    checkBranch(appId, clusterName, namespaceName, branchName);
    GrayReleaseRule rules = namespaceBranchService.findBranchGrayRules(appId, clusterName, namespaceName, branchName);
    if (rules == null) {
        return null;
    }
    GrayReleaseRuleDTO ruleDTO = new GrayReleaseRuleDTO(rules.getAppId(), rules.getClusterName(), rules.getNamespaceName(), rules.getBranchName());
    ruleDTO.setReleaseId(rules.getReleaseId());
    ruleDTO.setRuleItems(GrayReleaseRuleItemTransformer.batchTransformFromJSON(rules.getRules()));
    return ruleDTO;
}
Also used : GrayReleaseRuleDTO(com.ctrip.framework.apollo.common.dto.GrayReleaseRuleDTO) GrayReleaseRule(com.ctrip.framework.apollo.biz.entity.GrayReleaseRule) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 17 with GrayReleaseRule

use of com.ctrip.framework.apollo.biz.entity.GrayReleaseRule in project apollo by ctripcorp.

the class NamespaceBranchController method updateBranchGrayRules.

@Transactional
@PutMapping("/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/branches/{branchName}/rules")
public void updateBranchGrayRules(@PathVariable String appId, @PathVariable String clusterName, @PathVariable String namespaceName, @PathVariable String branchName, @RequestBody GrayReleaseRuleDTO newRuleDto) {
    checkBranch(appId, clusterName, namespaceName, branchName);
    GrayReleaseRule newRules = BeanUtils.transform(GrayReleaseRule.class, newRuleDto);
    newRules.setRules(GrayReleaseRuleItemTransformer.batchTransformToJSON(newRuleDto.getRuleItems()));
    newRules.setBranchStatus(NamespaceBranchStatus.ACTIVE);
    namespaceBranchService.updateBranchGrayRules(appId, clusterName, namespaceName, branchName, newRules);
    messageSender.sendMessage(ReleaseMessageKeyGenerator.generate(appId, clusterName, namespaceName), Topics.APOLLO_RELEASE_TOPIC);
}
Also used : GrayReleaseRule(com.ctrip.framework.apollo.biz.entity.GrayReleaseRule) PutMapping(org.springframework.web.bind.annotation.PutMapping) Transactional(org.springframework.transaction.annotation.Transactional)

Example 18 with GrayReleaseRule

use of com.ctrip.framework.apollo.biz.entity.GrayReleaseRule in project apollo by ctripcorp.

the class ReleaseService method branchRelease.

private Release branchRelease(Namespace parentNamespace, Namespace childNamespace, String releaseName, String releaseComment, Map<String, String> configurations, long baseReleaseId, String operator, int releaseOperation, boolean isEmergencyPublish, Collection<String> branchReleaseKeys) {
    Release previousRelease = findLatestActiveRelease(childNamespace.getAppId(), childNamespace.getClusterName(), childNamespace.getNamespaceName());
    long previousReleaseId = previousRelease == null ? 0 : previousRelease.getId();
    Map<String, Object> releaseOperationContext = Maps.newLinkedHashMap();
    releaseOperationContext.put(ReleaseOperationContext.BASE_RELEASE_ID, baseReleaseId);
    releaseOperationContext.put(ReleaseOperationContext.IS_EMERGENCY_PUBLISH, isEmergencyPublish);
    releaseOperationContext.put(ReleaseOperationContext.BRANCH_RELEASE_KEYS, branchReleaseKeys);
    Release release = createRelease(childNamespace, releaseName, releaseComment, configurations, operator);
    // update gray release rules
    GrayReleaseRule grayReleaseRule = namespaceBranchService.updateRulesReleaseId(childNamespace.getAppId(), parentNamespace.getClusterName(), childNamespace.getNamespaceName(), childNamespace.getClusterName(), release.getId(), operator);
    if (grayReleaseRule != null) {
        releaseOperationContext.put(ReleaseOperationContext.RULES, GrayReleaseRuleItemTransformer.batchTransformFromJSON(grayReleaseRule.getRules()));
    }
    releaseHistoryService.createReleaseHistory(parentNamespace.getAppId(), parentNamespace.getClusterName(), parentNamespace.getNamespaceName(), childNamespace.getClusterName(), release.getId(), previousReleaseId, releaseOperation, releaseOperationContext, operator);
    return release;
}
Also used : GrayReleaseRule(com.ctrip.framework.apollo.biz.entity.GrayReleaseRule) Release(com.ctrip.framework.apollo.biz.entity.Release)

Example 19 with GrayReleaseRule

use of com.ctrip.framework.apollo.biz.entity.GrayReleaseRule in project apollo by ctripcorp.

the class NamespaceBranchService method doUpdateBranchGrayRules.

private void doUpdateBranchGrayRules(String appId, String clusterName, String namespaceName, String branchName, GrayReleaseRule newRules, boolean recordReleaseHistory, int releaseOperation) {
    GrayReleaseRule oldRules = grayReleaseRuleRepository.findTopByAppIdAndClusterNameAndNamespaceNameAndBranchNameOrderByIdDesc(appId, clusterName, namespaceName, branchName);
    Release latestBranchRelease = releaseService.findLatestActiveRelease(appId, branchName, namespaceName);
    long latestBranchReleaseId = latestBranchRelease != null ? latestBranchRelease.getId() : 0;
    newRules.setReleaseId(latestBranchReleaseId);
    grayReleaseRuleRepository.save(newRules);
    // delete old rules
    if (oldRules != null) {
        grayReleaseRuleRepository.delete(oldRules);
    }
    if (recordReleaseHistory) {
        Map<String, Object> releaseOperationContext = Maps.newHashMap();
        releaseOperationContext.put(ReleaseOperationContext.RULES, GrayReleaseRuleItemTransformer.batchTransformFromJSON(newRules.getRules()));
        if (oldRules != null) {
            releaseOperationContext.put(ReleaseOperationContext.OLD_RULES, GrayReleaseRuleItemTransformer.batchTransformFromJSON(oldRules.getRules()));
        }
        releaseHistoryService.createReleaseHistory(appId, clusterName, namespaceName, branchName, latestBranchReleaseId, latestBranchReleaseId, releaseOperation, releaseOperationContext, newRules.getDataChangeLastModifiedBy());
    }
}
Also used : GrayReleaseRule(com.ctrip.framework.apollo.biz.entity.GrayReleaseRule) Release(com.ctrip.framework.apollo.biz.entity.Release)

Example 20 with GrayReleaseRule

use of com.ctrip.framework.apollo.biz.entity.GrayReleaseRule in project apollo by ctripcorp.

the class NamespaceBranchService method updateRulesReleaseId.

@Transactional
public GrayReleaseRule updateRulesReleaseId(String appId, String clusterName, String namespaceName, String branchName, long latestReleaseId, String operator) {
    GrayReleaseRule oldRules = grayReleaseRuleRepository.findTopByAppIdAndClusterNameAndNamespaceNameAndBranchNameOrderByIdDesc(appId, clusterName, namespaceName, branchName);
    if (oldRules == null) {
        return null;
    }
    GrayReleaseRule newRules = new GrayReleaseRule();
    newRules.setBranchStatus(NamespaceBranchStatus.ACTIVE);
    newRules.setReleaseId(latestReleaseId);
    newRules.setRules(oldRules.getRules());
    newRules.setAppId(oldRules.getAppId());
    newRules.setClusterName(oldRules.getClusterName());
    newRules.setNamespaceName(oldRules.getNamespaceName());
    newRules.setBranchName(oldRules.getBranchName());
    newRules.setDataChangeCreatedBy(operator);
    newRules.setDataChangeLastModifiedBy(operator);
    grayReleaseRuleRepository.save(newRules);
    grayReleaseRuleRepository.delete(oldRules);
    return newRules;
}
Also used : GrayReleaseRule(com.ctrip.framework.apollo.biz.entity.GrayReleaseRule) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

GrayReleaseRule (com.ctrip.framework.apollo.biz.entity.GrayReleaseRule)21 Test (org.junit.Test)11 AbstractIntegrationTest (com.ctrip.framework.apollo.biz.AbstractIntegrationTest)10 Sql (org.springframework.test.context.jdbc.Sql)10 Release (com.ctrip.framework.apollo.biz.entity.Release)9 ReleaseHistory (com.ctrip.framework.apollo.biz.entity.ReleaseHistory)8 Namespace (com.ctrip.framework.apollo.biz.entity.Namespace)6 Transactional (org.springframework.transaction.annotation.Transactional)3 Cluster (com.ctrip.framework.apollo.biz.entity.Cluster)1 GrayReleaseRuleDTO (com.ctrip.framework.apollo.common.dto.GrayReleaseRuleDTO)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1 PutMapping (org.springframework.web.bind.annotation.PutMapping)1