use of com.ctrip.framework.apollo.biz.entity.Namespace in project apollo by ctripcorp.
the class ReleaseCreationTest method testModifyMasterNamespaceItemsAndBranchAlsoModify.
/**
* Master | Branch
* ------------------------------ Master | Branch
* Items k1=v1 | k1=v1-2 ----------------------------
* k2=v2-2 | publish master k1=v1 | k1=v1-1
* ------------------------------ ===========>> Result k2=v2-2 | k2=v2-2
* Release k1=v1 | k1=v1-1 |
* k2=v2 | k2=v3
* k3=v3 | k3=v3
*/
@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 testModifyMasterNamespaceItemsAndBranchAlsoModify() {
long parentNamespaceId = 105;
String parentClusterName = "default3";
long childNamespaceId = 106;
String childClusterName = "child-cluster3";
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(2, parentNamespaceConfiguration.size());
Assert.assertEquals("v1", parentNamespaceConfiguration.get("k1"));
Assert.assertEquals("v2-2", parentNamespaceConfiguration.get("k2"));
// assert child namespace
Namespace childNamespace = instanceNamespace(childNamespaceId, childClusterName);
Release latestChildNamespaceRelease = releaseService.findLatestActiveRelease(childNamespace);
Assert.assertNotNull(latestChildNamespaceRelease);
Map<String, String> childNamespaceConfiguration = parseConfiguration(latestChildNamespaceRelease.getConfigurations());
Assert.assertEquals(2, childNamespaceConfiguration.size());
Assert.assertEquals("v1-1", childNamespaceConfiguration.get("k1"));
Assert.assertEquals("v2-2", childNamespaceConfiguration.get("k2"));
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(1, masterReleaseHistory.getPreviousReleaseId());
Assert.assertEquals(ReleaseOperation.MASTER_NORMAL_RELEASE_MERGE_TO_GRAY, branchReleaseHistory.getOperation());
Assert.assertEquals(latestChildNamespaceRelease.getId(), branchReleaseHistory.getReleaseId());
Assert.assertEquals(2, branchReleaseHistory.getPreviousReleaseId());
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.Namespace in project apollo by ctripcorp.
the class ReleaseCreationTest method testPublishBranchAtFirstTime.
/**
* Master | Branch
* ------------------------------ Master | Branch
* Items k1=v1 | k1=v1-2 ----------------------------
* k2=v2-2 | k4=v4 publish branch k1=v1 | k1=v1-2
* ------------------------------ ===========>> Result k2=v2 | k2=v2
* Release k1=v1 | k3=v3 | k3=v3
* k2=v2 | | k4=v4
* k3=v3 |
*/
@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 testPublishBranchAtFirstTime() {
long parentNamespaceId = 107;
String parentClusterName = "default4";
long childNamespaceId = 108;
String childClusterName = "child-cluster4";
// assert child namespace
Namespace childNamespace = instanceNamespace(childNamespaceId, childClusterName);
releaseService.publish(childNamespace, "", "", operator, false);
Release latestChildNamespaceRelease = releaseService.findLatestActiveRelease(childNamespace);
Assert.assertNotNull(latestChildNamespaceRelease);
Map<String, String> childNamespaceConfiguration = parseConfiguration(latestChildNamespaceRelease.getConfigurations());
Assert.assertEquals(4, childNamespaceConfiguration.size());
Assert.assertEquals("v1-2", childNamespaceConfiguration.get("k1"));
Assert.assertEquals("v2", childNamespaceConfiguration.get("k2"));
Assert.assertEquals("v3", childNamespaceConfiguration.get("k3"));
Assert.assertEquals("v4", childNamespaceConfiguration.get("k4"));
Namespace parentNamespace = instanceNamespace(parentNamespaceId, parentClusterName);
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"));
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 branchReleaseHistory = releaseHistories.getContent().get(0);
Assert.assertEquals(1, releaseHistories.getTotalElements());
Assert.assertEquals(ReleaseOperation.GRAY_RELEASE, branchReleaseHistory.getOperation());
Assert.assertEquals(latestChildNamespaceRelease.getId(), branchReleaseHistory.getReleaseId());
Assert.assertEquals(0, branchReleaseHistory.getPreviousReleaseId());
Assert.assertTrue(branchReleaseHistory.getOperationContext().contains("\"baseReleaseId\":3"));
Assert.assertTrue(branchReleaseHistory.getOperationContext().contains(rule.getRules()));
}
use of com.ctrip.framework.apollo.biz.entity.Namespace in project apollo by ctripcorp.
the class ReleaseCreationTest method testPublishNormalNamespace.
@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 testPublishNormalNamespace() {
long namespaceId = 100;
String clusterName = "only-master";
Namespace namespace = instanceNamespace(namespaceId, clusterName);
releaseService.publish(namespace, "", "", operator, false);
Release latestRelease = releaseService.findLatestActiveRelease(namespace);
Assert.assertNotNull(latestRelease);
Map<String, String> configuration = parseConfiguration(latestRelease.getConfigurations());
Assert.assertEquals(3, configuration.size());
Assert.assertEquals("v1", configuration.get("k1"));
Assert.assertEquals("v2", configuration.get("k2"));
Assert.assertEquals("v3", configuration.get("k3"));
Page<ReleaseHistory> releaseHistories = releaseHistoryService.findReleaseHistoriesByNamespace(testApp, clusterName, testNamespace, pageable);
ReleaseHistory releaseHistory = releaseHistories.getContent().get(0);
Assert.assertEquals(1, releaseHistories.getTotalElements());
Assert.assertEquals(ReleaseOperation.NORMAL_RELEASE, releaseHistory.getOperation());
Assert.assertEquals(latestRelease.getId(), releaseHistory.getReleaseId());
Assert.assertEquals(0, releaseHistory.getPreviousReleaseId());
}
use of com.ctrip.framework.apollo.biz.entity.Namespace in project apollo by ctripcorp.
the class NamespaceService method update.
@Transactional
public Namespace update(Namespace namespace) {
Namespace managedNamespace = namespaceRepository.findByAppIdAndClusterNameAndNamespaceName(namespace.getAppId(), namespace.getClusterName(), namespace.getNamespaceName());
BeanUtils.copyEntityProperties(namespace, managedNamespace);
managedNamespace = namespaceRepository.save(managedNamespace);
auditService.audit(Namespace.class.getSimpleName(), managedNamespace.getId(), Audit.OP.UPDATE, managedNamespace.getDataChangeLastModifiedBy());
return managedNamespace;
}
use of com.ctrip.framework.apollo.biz.entity.Namespace in project apollo by ctripcorp.
the class NamespaceService method namespacePublishInfo.
public Map<String, Boolean> namespacePublishInfo(String appId) {
List<Cluster> clusters = clusterService.findParentClusters(appId);
if (CollectionUtils.isEmpty(clusters)) {
throw new BadRequestException("app not exist");
}
Map<String, Boolean> clusterHasNotPublishedItems = Maps.newHashMap();
for (Cluster cluster : clusters) {
String clusterName = cluster.getName();
List<Namespace> namespaces = findNamespaces(appId, clusterName);
for (Namespace namespace : namespaces) {
boolean isNamespaceNotPublished = isNamespaceNotPublished(namespace);
if (isNamespaceNotPublished) {
clusterHasNotPublishedItems.put(clusterName, true);
break;
}
}
clusterHasNotPublishedItems.putIfAbsent(clusterName, false);
}
return clusterHasNotPublishedItems;
}
Aggregations