use of com.ctrip.framework.apollo.common.entity.AppNamespace in project apollo by ctripcorp.
the class ConfigControllerTest method testQueryConfigWithAppOwnNamespace.
@Test
public void testQueryConfigWithAppOwnNamespace() throws Exception {
String someClientSideReleaseKey = "1";
String someServerSideReleaseKey = "2";
String someAppOwnNamespaceName = "someAppOwn";
HttpServletResponse someResponse = mock(HttpServletResponse.class);
AppNamespace someAppOwnNamespace = assemblePublicAppNamespace(someAppId, someAppOwnNamespaceName);
when(configService.loadConfig(someAppId, someClientIp, someAppId, someClusterName, someAppOwnNamespaceName, someDataCenter, someNotificationMessages)).thenReturn(someRelease);
when(appNamespaceService.findPublicNamespaceByName(someAppOwnNamespaceName)).thenReturn(someAppOwnNamespace);
when(someRelease.getReleaseKey()).thenReturn(someServerSideReleaseKey);
when(namespaceUtil.filterNamespaceName(someAppOwnNamespaceName)).thenReturn(someAppOwnNamespaceName);
when(namespaceUtil.normalizeNamespace(someAppId, someAppOwnNamespaceName)).thenReturn(someAppOwnNamespaceName);
ApolloConfig result = configController.queryConfig(someAppId, someClusterName, someAppOwnNamespaceName, someDataCenter, someClientSideReleaseKey, someClientIp, someMessagesAsString, someRequest, someResponse);
assertEquals(someServerSideReleaseKey, result.getReleaseKey());
assertEquals(someAppId, result.getAppId());
assertEquals(someClusterName, result.getCluster());
assertEquals(someAppOwnNamespaceName, result.getNamespaceName());
assertEquals("foo", result.getConfigurations().get("apollo.bar"));
}
use of com.ctrip.framework.apollo.common.entity.AppNamespace in project apollo by ctripcorp.
the class ConfigController method findPublicConfig.
/**
* @param clientAppId the application which uses public config
* @param namespace the namespace
* @param dataCenter the datacenter
*/
private Release findPublicConfig(String clientAppId, String clientIp, String clusterName, String namespace, String dataCenter, ApolloNotificationMessages clientMessages) {
AppNamespace appNamespace = appNamespaceService.findPublicNamespaceByName(namespace);
// check whether the namespace's appId equals to current one
if (Objects.isNull(appNamespace) || Objects.equals(clientAppId, appNamespace.getAppId())) {
return null;
}
String publicConfigAppId = appNamespace.getAppId();
return configService.loadConfig(clientAppId, clientIp, publicConfigAppId, clusterName, namespace, dataCenter, clientMessages);
}
use of com.ctrip.framework.apollo.common.entity.AppNamespace in project apollo by ctripcorp.
the class AppNamespaceServiceWithCache method handleDeletedAppNamespaces.
// for those deleted app namespaces
private void handleDeletedAppNamespaces(Set<Long> deletedIds) {
if (CollectionUtils.isEmpty(deletedIds)) {
return;
}
for (Long deletedId : deletedIds) {
AppNamespace deleted = appNamespaceIdCache.remove(deletedId);
if (deleted == null) {
continue;
}
appNamespaceCache.remove(assembleAppNamespaceKey(deleted));
if (deleted.isPublic()) {
publicAppNamespaceCache.remove(deleted.getName());
}
logger.info("Found AppNamespace deleted, {}", deleted);
}
}
use of com.ctrip.framework.apollo.common.entity.AppNamespace in project apollo by ctripcorp.
the class AppNamespaceServiceWithCache method mergeAppNamespaces.
private void mergeAppNamespaces(List<AppNamespace> appNamespaces) {
for (AppNamespace appNamespace : appNamespaces) {
appNamespaceCache.put(assembleAppNamespaceKey(appNamespace), appNamespace);
appNamespaceIdCache.put(appNamespace.getId(), appNamespace);
if (appNamespace.isPublic()) {
publicAppNamespaceCache.put(appNamespace.getName(), appNamespace);
}
}
}
use of com.ctrip.framework.apollo.common.entity.AppNamespace in project apollo by ctripcorp.
the class NamespaceUtil method normalizeNamespace.
public String normalizeNamespace(String appId, String namespaceName) {
AppNamespace appNamespace = appNamespaceServiceWithCache.findByAppIdAndNamespace(appId, namespaceName);
if (appNamespace != null) {
return appNamespace.getName();
}
appNamespace = appNamespaceServiceWithCache.findPublicNamespaceByName(namespaceName);
if (appNamespace != null) {
return appNamespace.getName();
}
return namespaceName;
}
Aggregations