use of com.ctrip.framework.apollo.biz.entity.Namespace in project apollo by ctripcorp.
the class ItemService method findOne.
public Item findOne(String appId, String clusterName, String namespaceName, String key) {
Namespace namespace = namespaceService.findOne(appId, clusterName, namespaceName);
if (namespace == null) {
throw new NotFoundException(String.format("namespace not found for %s %s %s", appId, clusterName, namespaceName));
}
Item item = itemRepository.findByNamespaceIdAndKey(namespace.getId(), key);
return item;
}
use of com.ctrip.framework.apollo.biz.entity.Namespace in project apollo by ctripcorp.
the class AdminServiceTest method testCreateNewApp.
@Test
public void testCreateNewApp() {
String appId = "someAppId";
App app = new App();
app.setAppId(appId);
app.setName("someAppName");
String owner = "someOwnerName";
app.setOwnerName(owner);
app.setOwnerEmail("someOwnerName@ctrip.com");
app.setDataChangeCreatedBy(owner);
app.setDataChangeLastModifiedBy(owner);
app.setDataChangeCreatedTime(new Date());
app = adminService.createNewApp(app);
Assert.assertEquals(appId, app.getAppId());
List<Cluster> clusters = clusterService.findParentClusters(app.getAppId());
Assert.assertEquals(1, clusters.size());
Assert.assertEquals(ConfigConsts.CLUSTER_NAME_DEFAULT, clusters.get(0).getName());
List<Namespace> namespaces = namespaceService.findNamespaces(appId, clusters.get(0).getName());
Assert.assertEquals(1, namespaces.size());
Assert.assertEquals(ConfigConsts.NAMESPACE_APPLICATION, namespaces.get(0).getNamespaceName());
List<Audit> audits = auditService.findByOwner(owner);
Assert.assertEquals(4, audits.size());
}
use of com.ctrip.framework.apollo.biz.entity.Namespace in project apollo by ctripcorp.
the class NamespaceBranchServiceTest method testFindBranch.
@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 testFindBranch() {
Namespace branch = namespaceBranchService.findBranch(testApp, testCluster, testNamespace);
Assert.assertNotNull(branch);
Assert.assertEquals(testBranchName, branch.getClusterName());
}
use of com.ctrip.framework.apollo.biz.entity.Namespace in project apollo by ctripcorp.
the class ReleaseCreationTest method instanceNamespace.
private Namespace instanceNamespace(long id, String clusterName) {
Namespace namespace = new Namespace();
namespace.setAppId(testApp);
namespace.setNamespaceName(testNamespace);
namespace.setId(id);
namespace.setClusterName(clusterName);
return namespace;
}
use of com.ctrip.framework.apollo.biz.entity.Namespace 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()));
}
Aggregations