use of com.ctrip.framework.apollo.common.entity.AppNamespace in project apollo by ctripcorp.
the class AppNamespaceService method createDefaultAppNamespace.
@Transactional
public void createDefaultAppNamespace(String appId, String createBy) {
if (!isAppNamespaceNameUnique(appId, ConfigConsts.NAMESPACE_APPLICATION)) {
throw new ServiceException("appnamespace not unique");
}
AppNamespace appNs = new AppNamespace();
appNs.setAppId(appId);
appNs.setName(ConfigConsts.NAMESPACE_APPLICATION);
appNs.setComment("default app namespace");
appNs.setFormat(ConfigFileFormat.Properties.getValue());
appNs.setDataChangeCreatedBy(createBy);
appNs.setDataChangeLastModifiedBy(createBy);
appNamespaceRepository.save(appNs);
auditService.audit(AppNamespace.class.getSimpleName(), appNs.getId(), Audit.OP.INSERT, createBy);
}
use of com.ctrip.framework.apollo.common.entity.AppNamespace in project apollo by ctripcorp.
the class AppNamespaceService method update.
public AppNamespace update(AppNamespace appNamespace) {
AppNamespace managedNs = appNamespaceRepository.findByAppIdAndName(appNamespace.getAppId(), appNamespace.getName());
BeanUtils.copyEntityProperties(appNamespace, managedNs);
managedNs = appNamespaceRepository.save(managedNs);
auditService.audit(AppNamespace.class.getSimpleName(), managedNs.getId(), Audit.OP.UPDATE, managedNs.getDataChangeLastModifiedBy());
return managedNs;
}
use of com.ctrip.framework.apollo.common.entity.AppNamespace in project apollo by ctripcorp.
the class AppNamespaceServiceWithCacheTest method testAppNamespace.
@Test
public void testAppNamespace() throws Exception {
String someAppId = "someAppId";
String somePrivateNamespace = "somePrivateNamespace";
String somePrivateNamespaceWithIncorrectCase = somePrivateNamespace.toUpperCase();
long somePrivateNamespaceId = 1;
String yetAnotherPrivateNamespace = "anotherPrivateNamespace";
long yetAnotherPrivateNamespaceId = 4;
String anotherPublicNamespace = "anotherPublicNamespace";
long anotherPublicNamespaceId = 5;
String somePublicAppId = "somePublicAppId";
String somePublicNamespace = "somePublicNamespace";
String somePublicNamespaceWithIncorrectCase = somePublicNamespace.toUpperCase();
long somePublicNamespaceId = 2;
String anotherPrivateNamespace = "anotherPrivateNamespace";
long anotherPrivateNamespaceId = 3;
int sleepInterval = scanInterval * 10;
AppNamespace somePrivateAppNamespace = assembleAppNamespace(somePrivateNamespaceId, someAppId, somePrivateNamespace, false);
AppNamespace somePublicAppNamespace = assembleAppNamespace(somePublicNamespaceId, somePublicAppId, somePublicNamespace, true);
AppNamespace anotherPrivateAppNamespace = assembleAppNamespace(anotherPrivateNamespaceId, somePublicAppId, anotherPrivateNamespace, false);
AppNamespace yetAnotherPrivateAppNamespace = assembleAppNamespace(yetAnotherPrivateNamespaceId, someAppId, yetAnotherPrivateNamespace, false);
AppNamespace anotherPublicAppNamespace = assembleAppNamespace(anotherPublicNamespaceId, someAppId, anotherPublicNamespace, true);
Set<String> someAppIdNamespaces = Sets.newHashSet(somePrivateNamespace, yetAnotherPrivateNamespace, anotherPublicNamespace);
Set<String> someAppIdNamespacesWithIncorrectCase = Sets.newHashSet(somePrivateNamespaceWithIncorrectCase, yetAnotherPrivateNamespace, anotherPublicNamespace);
Set<String> somePublicAppIdNamespaces = Sets.newHashSet(somePublicNamespace, anotherPrivateNamespace);
Set<String> publicNamespaces = Sets.newHashSet(somePublicNamespace, anotherPublicNamespace);
Set<String> publicNamespacesWithIncorrectCase = Sets.newHashSet(somePublicNamespaceWithIncorrectCase, anotherPublicNamespace);
List<Long> appNamespaceIds = Lists.newArrayList(somePrivateNamespaceId, somePublicNamespaceId, anotherPrivateNamespaceId, yetAnotherPrivateNamespaceId, anotherPublicNamespaceId);
List<AppNamespace> allAppNamespaces = Lists.newArrayList(somePrivateAppNamespace, somePublicAppNamespace, anotherPrivateAppNamespace, yetAnotherPrivateAppNamespace, anotherPublicAppNamespace);
// Test init
appNamespaceServiceWithCache.afterPropertiesSet();
// Should have no record now
assertNull(appNamespaceServiceWithCache.findByAppIdAndNamespace(someAppId, somePrivateNamespace));
assertNull(appNamespaceServiceWithCache.findByAppIdAndNamespace(someAppId, somePrivateNamespaceWithIncorrectCase));
assertNull(appNamespaceServiceWithCache.findByAppIdAndNamespace(someAppId, yetAnotherPrivateNamespace));
assertNull(appNamespaceServiceWithCache.findByAppIdAndNamespace(someAppId, anotherPublicNamespace));
assertTrue(appNamespaceServiceWithCache.findByAppIdAndNamespaces(someAppId, someAppIdNamespaces).isEmpty());
assertTrue(appNamespaceServiceWithCache.findByAppIdAndNamespaces(someAppId, someAppIdNamespacesWithIncorrectCase).isEmpty());
assertNull(appNamespaceServiceWithCache.findByAppIdAndNamespace(somePublicAppId, somePublicNamespace));
assertNull(appNamespaceServiceWithCache.findByAppIdAndNamespace(somePublicAppId, somePublicNamespaceWithIncorrectCase));
assertNull(appNamespaceServiceWithCache.findByAppIdAndNamespace(somePublicAppId, anotherPrivateNamespace));
assertTrue(appNamespaceServiceWithCache.findByAppIdAndNamespaces(somePublicAppId, somePublicAppIdNamespaces).isEmpty());
assertNull(appNamespaceServiceWithCache.findPublicNamespaceByName(somePublicNamespace));
assertNull(appNamespaceServiceWithCache.findPublicNamespaceByName(somePublicNamespaceWithIncorrectCase));
assertNull(appNamespaceServiceWithCache.findPublicNamespaceByName(anotherPublicNamespace));
assertTrue(appNamespaceServiceWithCache.findPublicNamespacesByNames(publicNamespaces).isEmpty());
assertTrue(appNamespaceServiceWithCache.findPublicNamespacesByNames(publicNamespacesWithIncorrectCase).isEmpty());
// Add 1 private namespace and 1 public namespace
when(appNamespaceRepository.findFirst500ByIdGreaterThanOrderByIdAsc(0)).thenReturn(Lists.newArrayList(somePrivateAppNamespace, somePublicAppNamespace));
when(appNamespaceRepository.findAll(Lists.newArrayList(somePrivateNamespaceId, somePublicNamespaceId))).thenReturn(Lists.newArrayList(somePrivateAppNamespace, somePublicAppNamespace));
scanIntervalTimeUnit.sleep(sleepInterval);
assertEquals(somePrivateAppNamespace, appNamespaceServiceWithCache.findByAppIdAndNamespace(someAppId, somePrivateNamespace));
assertEquals(somePrivateAppNamespace, appNamespaceServiceWithCache.findByAppIdAndNamespace(someAppId, somePrivateNamespaceWithIncorrectCase));
check(Lists.newArrayList(somePrivateAppNamespace), appNamespaceServiceWithCache.findByAppIdAndNamespaces(someAppId, someAppIdNamespaces));
check(Lists.newArrayList(somePrivateAppNamespace), appNamespaceServiceWithCache.findByAppIdAndNamespaces(someAppId, someAppIdNamespacesWithIncorrectCase));
assertEquals(somePublicAppNamespace, appNamespaceServiceWithCache.findByAppIdAndNamespace(somePublicAppId, somePublicNamespace));
assertEquals(somePublicAppNamespace, appNamespaceServiceWithCache.findByAppIdAndNamespace(somePublicAppId, somePublicNamespaceWithIncorrectCase));
check(Lists.newArrayList(somePublicAppNamespace), appNamespaceServiceWithCache.findByAppIdAndNamespaces(somePublicAppId, somePublicAppIdNamespaces));
assertEquals(somePublicAppNamespace, appNamespaceServiceWithCache.findPublicNamespaceByName(somePublicNamespace));
assertEquals(somePublicAppNamespace, appNamespaceServiceWithCache.findPublicNamespaceByName(somePublicNamespaceWithIncorrectCase));
check(Lists.newArrayList(somePublicAppNamespace), appNamespaceServiceWithCache.findPublicNamespacesByNames(publicNamespaces));
check(Lists.newArrayList(somePublicAppNamespace), appNamespaceServiceWithCache.findPublicNamespacesByNames(publicNamespacesWithIncorrectCase));
// Add 2 private namespaces and 1 public namespace
when(appNamespaceRepository.findFirst500ByIdGreaterThanOrderByIdAsc(somePublicNamespaceId)).thenReturn(Lists.newArrayList(anotherPrivateAppNamespace, yetAnotherPrivateAppNamespace, anotherPublicAppNamespace));
when(appNamespaceRepository.findAll(appNamespaceIds)).thenReturn(allAppNamespaces);
scanIntervalTimeUnit.sleep(sleepInterval);
check(Lists.newArrayList(somePrivateAppNamespace, yetAnotherPrivateAppNamespace, anotherPublicAppNamespace), Lists.newArrayList(appNamespaceServiceWithCache.findByAppIdAndNamespace(someAppId, somePrivateNamespace), appNamespaceServiceWithCache.findByAppIdAndNamespace(someAppId, yetAnotherPrivateNamespace), appNamespaceServiceWithCache.findByAppIdAndNamespace(someAppId, anotherPublicNamespace)));
check(Lists.newArrayList(somePrivateAppNamespace, yetAnotherPrivateAppNamespace, anotherPublicAppNamespace), appNamespaceServiceWithCache.findByAppIdAndNamespaces(someAppId, someAppIdNamespaces));
check(Lists.newArrayList(somePublicAppNamespace, anotherPrivateAppNamespace), Lists.newArrayList(appNamespaceServiceWithCache.findByAppIdAndNamespace(somePublicAppId, somePublicNamespace), appNamespaceServiceWithCache.findByAppIdAndNamespace(somePublicAppId, anotherPrivateNamespace)));
check(Lists.newArrayList(somePublicAppNamespace, anotherPrivateAppNamespace), appNamespaceServiceWithCache.findByAppIdAndNamespaces(somePublicAppId, somePublicAppIdNamespaces));
check(Lists.newArrayList(somePublicAppNamespace, anotherPublicAppNamespace), Lists.newArrayList(appNamespaceServiceWithCache.findPublicNamespaceByName(somePublicNamespace), appNamespaceServiceWithCache.findPublicNamespaceByName(anotherPublicNamespace)));
check(Lists.newArrayList(somePublicAppNamespace, anotherPublicAppNamespace), appNamespaceServiceWithCache.findPublicNamespacesByNames(publicNamespaces));
// Update name
String somePrivateNamespaceNew = "somePrivateNamespaceNew";
AppNamespace somePrivateAppNamespaceNew = assembleAppNamespace(somePrivateAppNamespace.getId(), somePrivateAppNamespace.getAppId(), somePrivateNamespaceNew, somePrivateAppNamespace.isPublic());
somePrivateAppNamespaceNew.setDataChangeLastModifiedTime(newDateWithDelta(somePrivateAppNamespace.getDataChangeLastModifiedTime(), 1));
// Update appId
String someAppIdNew = "someAppIdNew";
AppNamespace yetAnotherPrivateAppNamespaceNew = assembleAppNamespace(yetAnotherPrivateAppNamespace.getId(), someAppIdNew, yetAnotherPrivateAppNamespace.getName(), false);
yetAnotherPrivateAppNamespaceNew.setDataChangeLastModifiedTime(newDateWithDelta(yetAnotherPrivateAppNamespace.getDataChangeLastModifiedTime(), 1));
// Update isPublic
AppNamespace somePublicAppNamespaceNew = assembleAppNamespace(somePublicAppNamespace.getId(), somePublicAppNamespace.getAppId(), somePublicAppNamespace.getName(), !somePublicAppNamespace.isPublic());
somePublicAppNamespaceNew.setDataChangeLastModifiedTime(newDateWithDelta(somePublicAppNamespace.getDataChangeLastModifiedTime(), 1));
// Delete 1 private and 1 public
when(appNamespaceRepository.findAll(appNamespaceIds)).thenReturn(Lists.newArrayList(somePrivateAppNamespaceNew, yetAnotherPrivateAppNamespaceNew, somePublicAppNamespaceNew));
scanIntervalTimeUnit.sleep(sleepInterval);
assertNull(appNamespaceServiceWithCache.findByAppIdAndNamespace(someAppId, somePrivateNamespace));
assertNull(appNamespaceServiceWithCache.findByAppIdAndNamespace(someAppId, yetAnotherPrivateNamespace));
assertNull(appNamespaceServiceWithCache.findByAppIdAndNamespace(someAppId, anotherPublicNamespace));
check(Collections.emptyList(), appNamespaceServiceWithCache.findByAppIdAndNamespaces(someAppId, someAppIdNamespaces));
assertEquals(somePublicAppNamespaceNew, appNamespaceServiceWithCache.findByAppIdAndNamespace(somePublicAppId, somePublicNamespace));
check(Lists.newArrayList(somePublicAppNamespaceNew), appNamespaceServiceWithCache.findByAppIdAndNamespaces(somePublicAppId, somePublicAppIdNamespaces));
assertNull(appNamespaceServiceWithCache.findPublicNamespaceByName(somePublicNamespace));
assertNull(appNamespaceServiceWithCache.findPublicNamespaceByName(anotherPublicNamespace));
check(Collections.emptyList(), appNamespaceServiceWithCache.findPublicNamespacesByNames(publicNamespaces));
assertEquals(somePrivateAppNamespaceNew, appNamespaceServiceWithCache.findByAppIdAndNamespace(someAppId, somePrivateNamespaceNew));
check(Lists.newArrayList(somePrivateAppNamespaceNew), appNamespaceServiceWithCache.findByAppIdAndNamespaces(someAppId, Sets.newHashSet(somePrivateNamespaceNew)));
assertEquals(yetAnotherPrivateAppNamespaceNew, appNamespaceServiceWithCache.findByAppIdAndNamespace(someAppIdNew, yetAnotherPrivateNamespace));
check(Lists.newArrayList(yetAnotherPrivateAppNamespaceNew), appNamespaceServiceWithCache.findByAppIdAndNamespaces(someAppIdNew, Sets.newHashSet(yetAnotherPrivateNamespace)));
}
use of com.ctrip.framework.apollo.common.entity.AppNamespace in project apollo by ctripcorp.
the class ConfigControllerTest method testQueryConfigFileWithPublicNamespaceAndNoAppOverride.
@Test
public void testQueryConfigFileWithPublicNamespaceAndNoAppOverride() throws Exception {
String someClientSideReleaseKey = "1";
String someServerSideReleaseKey = "2";
HttpServletResponse someResponse = mock(HttpServletResponse.class);
String somePublicAppId = "somePublicAppId";
String someNamespace = String.format("%s.%s", somePublicNamespaceName, "properties");
AppNamespace somePublicAppNamespace = assemblePublicAppNamespace(somePublicAppId, somePublicNamespaceName);
when(configService.loadConfig(someAppId, someClientIp, someAppId, someClusterName, somePublicNamespaceName, someDataCenter, someNotificationMessages)).thenReturn(null);
when(appNamespaceService.findPublicNamespaceByName(somePublicNamespaceName)).thenReturn(somePublicAppNamespace);
when(configService.loadConfig(someAppId, someClientIp, somePublicAppId, someClusterName, somePublicNamespaceName, someDataCenter, someNotificationMessages)).thenReturn(somePublicRelease);
when(somePublicRelease.getReleaseKey()).thenReturn(someServerSideReleaseKey);
when(namespaceUtil.filterNamespaceName(someNamespace)).thenReturn(somePublicNamespaceName);
when(namespaceUtil.normalizeNamespace(someAppId, someNamespace)).thenReturn(somePublicNamespaceName);
when(appNamespaceService.findByAppIdAndNamespace(someAppId, somePublicNamespaceName)).thenReturn(null);
ApolloConfig result = configController.queryConfig(someAppId, someClusterName, someNamespace, someDataCenter, someClientSideReleaseKey, someClientIp, someMessagesAsString, someRequest, someResponse);
assertEquals(someServerSideReleaseKey, result.getReleaseKey());
assertEquals(someAppId, result.getAppId());
assertEquals(someClusterName, result.getCluster());
assertEquals(someNamespace, result.getNamespaceName());
assertEquals("foo", result.getConfigurations().get("apollo.public.bar"));
}
use of com.ctrip.framework.apollo.common.entity.AppNamespace in project apollo by ctripcorp.
the class ConfigControllerTest method assembleAppNamespace.
private AppNamespace assembleAppNamespace(String appId, String namespace, boolean isPublic) {
AppNamespace appNamespace = new AppNamespace();
appNamespace.setAppId(appId);
appNamespace.setName(namespace);
appNamespace.setPublic(isPublic);
return appNamespace;
}
Aggregations