use of com.ctrip.framework.apollo.biz.entity.ReleaseHistory 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()));
}
use of com.ctrip.framework.apollo.biz.entity.ReleaseHistory 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()));
}
use of com.ctrip.framework.apollo.biz.entity.ReleaseHistory in project apollo by ctripcorp.
the class ReleaseCreationTest method testPublishMasterNamespaceAndBranchHasNotItems.
/**
* Master | Branch
* ------------------------------ Master | Branch
* Items k1=v1 | ----------------------------
* k2=v2 | k1=v1 | k1=v1
* k3=v3 publish master k2=v2 | k2=v2
* ------------------------------ ===========>> Result k3=v3 | k3=v3
* Release |
* |
* |
*/
@Test
@Sql(scripts = "/sql/release-creation-test.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/sql/clean.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testPublishMasterNamespaceAndBranchHasNotItems() {
long parentNamespaceId = 101;
String parentClusterName = "default1";
long childNamespaceId = 102;
String childClusterName = "child-cluster1";
Namespace parentNamespace = instanceNamespace(parentNamespaceId, parentClusterName);
releaseService.publish(parentNamespace, "", "", operator, false);
Release latestParentNamespaceRelease = releaseService.findLatestActiveRelease(parentNamespace);
// assert parent namespace
Assert.assertNotNull(latestParentNamespaceRelease);
Map<String, String> parentNamespaceConfiguration = parseConfiguration(latestParentNamespaceRelease.getConfigurations());
Assert.assertEquals(3, parentNamespaceConfiguration.size());
Assert.assertEquals("v1", parentNamespaceConfiguration.get("k1"));
Assert.assertEquals("v2", parentNamespaceConfiguration.get("k2"));
Assert.assertEquals("v3", parentNamespaceConfiguration.get("k3"));
// assert child namespace
Namespace childNamespace = instanceNamespace(childNamespaceId, childClusterName);
Release latestChildNamespaceRelease = releaseService.findLatestActiveRelease(childNamespace);
// assert parent namespace
Assert.assertNotNull(latestChildNamespaceRelease);
Map<String, String> childNamespaceConfiguration = parseConfiguration(latestChildNamespaceRelease.getConfigurations());
Assert.assertEquals(3, childNamespaceConfiguration.size());
Assert.assertEquals("v1", childNamespaceConfiguration.get("k1"));
Assert.assertEquals("v2", childNamespaceConfiguration.get("k2"));
Assert.assertEquals("v3", childNamespaceConfiguration.get("k3"));
GrayReleaseRule rule = namespaceBranchService.findBranchGrayRules(testApp, parentClusterName, testNamespace, childClusterName);
Assert.assertNotNull(rule);
Assert.assertEquals(1, rule.getBranchStatus());
Assert.assertEquals(Long.valueOf(latestChildNamespaceRelease.getId()), rule.getReleaseId());
// assert release history
Page<ReleaseHistory> releaseHistories = releaseHistoryService.findReleaseHistoriesByNamespace(testApp, parentClusterName, testNamespace, pageable);
ReleaseHistory masterReleaseHistory = releaseHistories.getContent().get(1);
ReleaseHistory branchReleaseHistory = releaseHistories.getContent().get(0);
Assert.assertEquals(2, releaseHistories.getTotalElements());
Assert.assertEquals(ReleaseOperation.NORMAL_RELEASE, masterReleaseHistory.getOperation());
Assert.assertEquals(latestParentNamespaceRelease.getId(), masterReleaseHistory.getReleaseId());
Assert.assertEquals(0, masterReleaseHistory.getPreviousReleaseId());
Assert.assertEquals(ReleaseOperation.MASTER_NORMAL_RELEASE_MERGE_TO_GRAY, branchReleaseHistory.getOperation());
Assert.assertEquals(latestChildNamespaceRelease.getId(), branchReleaseHistory.getReleaseId());
Assert.assertTrue(branchReleaseHistory.getOperationContext().contains(String.format("\"baseReleaseId\":%d", latestParentNamespaceRelease.getId())));
Assert.assertTrue(branchReleaseHistory.getOperationContext().contains(rule.getRules()));
}
use of com.ctrip.framework.apollo.biz.entity.ReleaseHistory in project apollo by ctripcorp.
the class ReleaseHistoryService method createReleaseHistory.
@Transactional
public ReleaseHistory createReleaseHistory(String appId, String clusterName, String namespaceName, String branchName, long releaseId, long previousReleaseId, int operation, Map<String, Object> operationContext, String operator) {
ReleaseHistory releaseHistory = new ReleaseHistory();
releaseHistory.setAppId(appId);
releaseHistory.setClusterName(clusterName);
releaseHistory.setNamespaceName(namespaceName);
releaseHistory.setBranchName(branchName);
releaseHistory.setReleaseId(releaseId);
releaseHistory.setPreviousReleaseId(previousReleaseId);
releaseHistory.setOperation(operation);
if (operationContext == null) {
// default empty object
releaseHistory.setOperationContext("{}");
} else {
releaseHistory.setOperationContext(GSON.toJson(operationContext));
}
releaseHistory.setDataChangeCreatedTime(new Date());
releaseHistory.setDataChangeCreatedBy(operator);
releaseHistory.setDataChangeLastModifiedBy(operator);
releaseHistoryRepository.save(releaseHistory);
auditService.audit(ReleaseHistory.class.getSimpleName(), releaseHistory.getId(), Audit.OP.INSERT, releaseHistory.getDataChangeCreatedBy());
return releaseHistory;
}
use of com.ctrip.framework.apollo.biz.entity.ReleaseHistory in project apollo by ctripcorp.
the class NamespaceBranchServiceTest method testDeleteBranch.
@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 testDeleteBranch() {
GrayReleaseRule rule = instanceGrayReleaseRule();
namespaceBranchService.updateBranchGrayRules(testApp, testCluster, testNamespace, testBranchName, rule);
namespaceBranchService.deleteBranch(testApp, testCluster, testNamespace, testBranchName, NamespaceBranchStatus.DELETED, operator);
Namespace branch = namespaceBranchService.findBranch(testApp, testCluster, testNamespace);
Assert.assertNull(branch);
GrayReleaseRule latestRule = namespaceBranchService.findBranchGrayRules(testApp, testCluster, testNamespace, testBranchName);
Assert.assertNotNull(latestRule);
Assert.assertEquals(NamespaceBranchStatus.DELETED, latestRule.getBranchStatus());
Assert.assertEquals("[]", latestRule.getRules());
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.ABANDON_GRAY_RELEASE, secondReleaseHistory.getOperation());
}
Aggregations