Search in sources :

Example 1 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) {
    Release previousRelease = findLatestActiveRelease(childNamespace.getAppId(), childNamespace.getClusterName(), childNamespace.getNamespaceName());
    long previousReleaseId = previousRelease == null ? 0 : previousRelease.getId();
    Map<String, Object> releaseOperationContext = Maps.newHashMap();
    releaseOperationContext.put(ReleaseOperationContext.BASE_RELEASE_ID, baseReleaseId);
    releaseOperationContext.put(ReleaseOperationContext.IS_EMERGENCY_PUBLISH, isEmergencyPublish);
    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 2 with GrayReleaseRule

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

the class NamespaceBranchServiceTest method testUpdateBranchGrayRulesWithUpdateTwice.

@Test
@Sql(scripts = "/sql/namespace-branch-test.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/sql/clean.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testUpdateBranchGrayRulesWithUpdateTwice() {
    GrayReleaseRule firstRule = instanceGrayReleaseRule();
    namespaceBranchService.updateBranchGrayRules(testApp, testCluster, testNamespace, testBranchName, firstRule);
    GrayReleaseRule secondRule = instanceGrayReleaseRule();
    secondRule.setRules("[{\"clientAppId\":\"branch-test\",\"clientIpList\":[\"10.38.57.112\"]}]");
    namespaceBranchService.updateBranchGrayRules(testApp, testCluster, testNamespace, testBranchName, secondRule);
    GrayReleaseRule activeRule = namespaceBranchService.findBranchGrayRules(testApp, testCluster, testNamespace, testBranchName);
    Assert.assertNotNull(secondRule);
    Assert.assertEquals(secondRule.getAppId(), activeRule.getAppId());
    Assert.assertEquals(secondRule.getRules(), activeRule.getRules());
    Assert.assertEquals(Long.valueOf(0), activeRule.getReleaseId());
    Page<ReleaseHistory> releaseHistories = releaseHistoryService.findReleaseHistoriesByNamespace(testApp, testCluster, testNamespace, pageable);
    ReleaseHistory firstReleaseHistory = releaseHistories.getContent().get(1);
    ReleaseHistory secondReleaseHistory = releaseHistories.getContent().get(0);
    Assert.assertEquals(2, releaseHistories.getTotalElements());
    Assert.assertEquals(ReleaseOperation.APPLY_GRAY_RULES, firstReleaseHistory.getOperation());
    Assert.assertEquals(ReleaseOperation.APPLY_GRAY_RULES, secondReleaseHistory.getOperation());
    Assert.assertTrue(firstReleaseHistory.getOperationContext().contains(firstRule.getRules()));
    Assert.assertFalse(firstReleaseHistory.getOperationContext().contains(secondRule.getRules()));
    Assert.assertTrue(secondReleaseHistory.getOperationContext().contains(firstRule.getRules()));
    Assert.assertTrue(secondReleaseHistory.getOperationContext().contains(secondRule.getRules()));
}
Also used : ReleaseHistory(com.ctrip.framework.apollo.biz.entity.ReleaseHistory) GrayReleaseRule(com.ctrip.framework.apollo.biz.entity.GrayReleaseRule) Test(org.junit.Test) AbstractIntegrationTest(com.ctrip.framework.apollo.biz.AbstractIntegrationTest) Sql(org.springframework.test.context.jdbc.Sql)

Example 3 with GrayReleaseRule

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

the class NamespaceBranchServiceTest method testUpdateRulesReleaseIdWithOldRuleNotExist.

@Test
@Sql(scripts = "/sql/namespace-branch-test.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/sql/clean.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testUpdateRulesReleaseIdWithOldRuleNotExist() {
    long latestReleaseId = 100;
    namespaceBranchService.updateRulesReleaseId(testApp, testCluster, testNamespace, testBranchName, latestReleaseId, operator);
    GrayReleaseRule activeRule = namespaceBranchService.findBranchGrayRules(testApp, testCluster, testNamespace, testBranchName);
    Assert.assertNull(activeRule);
}
Also used : GrayReleaseRule(com.ctrip.framework.apollo.biz.entity.GrayReleaseRule) Test(org.junit.Test) AbstractIntegrationTest(com.ctrip.framework.apollo.biz.AbstractIntegrationTest) Sql(org.springframework.test.context.jdbc.Sql)

Example 4 with GrayReleaseRule

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

the class NamespaceBranchServiceTest method testUpdateRulesReleaseIdWithOldRuleExist.

@Test
@Sql(scripts = "/sql/namespace-branch-test.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/sql/clean.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testUpdateRulesReleaseIdWithOldRuleExist() {
    GrayReleaseRule rule = instanceGrayReleaseRule();
    namespaceBranchService.updateBranchGrayRules(testApp, testCluster, testNamespace, testBranchName, rule);
    long latestReleaseId = 100;
    namespaceBranchService.updateRulesReleaseId(testApp, testCluster, testNamespace, testBranchName, latestReleaseId, operator);
    GrayReleaseRule activeRule = namespaceBranchService.findBranchGrayRules(testApp, testCluster, testNamespace, testBranchName);
    Assert.assertNotNull(activeRule);
    Assert.assertEquals(Long.valueOf(latestReleaseId), activeRule.getReleaseId());
    Assert.assertEquals(rule.getRules(), activeRule.getRules());
    Assert.assertEquals(NamespaceBranchStatus.ACTIVE, activeRule.getBranchStatus());
}
Also used : GrayReleaseRule(com.ctrip.framework.apollo.biz.entity.GrayReleaseRule) Test(org.junit.Test) AbstractIntegrationTest(com.ctrip.framework.apollo.biz.AbstractIntegrationTest) Sql(org.springframework.test.context.jdbc.Sql)

Example 5 with GrayReleaseRule

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

the class NamespaceBranchServiceTest method testUpdateBranchGrayRulesWithUpdateOnce.

@Test
@Sql(scripts = "/sql/namespace-branch-test.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/sql/clean.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testUpdateBranchGrayRulesWithUpdateOnce() {
    GrayReleaseRule rule = instanceGrayReleaseRule();
    namespaceBranchService.updateBranchGrayRules(testApp, testCluster, testNamespace, testBranchName, rule);
    GrayReleaseRule activeRule = namespaceBranchService.findBranchGrayRules(testApp, testCluster, testNamespace, testBranchName);
    Assert.assertNotNull(activeRule);
    Assert.assertEquals(rule.getAppId(), activeRule.getAppId());
    Assert.assertEquals(rule.getRules(), activeRule.getRules());
    Assert.assertEquals(Long.valueOf(0), activeRule.getReleaseId());
    Page<ReleaseHistory> releaseHistories = releaseHistoryService.findReleaseHistoriesByNamespace(testApp, testCluster, testNamespace, pageable);
    ReleaseHistory releaseHistory = releaseHistories.getContent().get(0);
    Assert.assertEquals(1, releaseHistories.getTotalElements());
    Assert.assertEquals(ReleaseOperation.APPLY_GRAY_RULES, releaseHistory.getOperation());
    Assert.assertEquals(0, releaseHistory.getReleaseId());
    Assert.assertEquals(0, releaseHistory.getPreviousReleaseId());
    Assert.assertTrue(releaseHistory.getOperationContext().contains(rule.getRules()));
}
Also used : ReleaseHistory(com.ctrip.framework.apollo.biz.entity.ReleaseHistory) GrayReleaseRule(com.ctrip.framework.apollo.biz.entity.GrayReleaseRule) Test(org.junit.Test) AbstractIntegrationTest(com.ctrip.framework.apollo.biz.AbstractIntegrationTest) Sql(org.springframework.test.context.jdbc.Sql)

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