Search in sources :

Example 11 with AppNamespace

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"));
}
Also used : ApolloConfig(com.ctrip.framework.apollo.core.dto.ApolloConfig) HttpServletResponse(javax.servlet.http.HttpServletResponse) AppNamespace(com.ctrip.framework.apollo.common.entity.AppNamespace) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 12 with AppNamespace

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);
}
Also used : AppNamespace(com.ctrip.framework.apollo.common.entity.AppNamespace)

Example 13 with AppNamespace

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);
    }
}
Also used : AppNamespace(com.ctrip.framework.apollo.common.entity.AppNamespace)

Example 14 with AppNamespace

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);
        }
    }
}
Also used : AppNamespace(com.ctrip.framework.apollo.common.entity.AppNamespace)

Example 15 with 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;
}
Also used : AppNamespace(com.ctrip.framework.apollo.common.entity.AppNamespace)

Aggregations

AppNamespace (com.ctrip.framework.apollo.common.entity.AppNamespace)50 Test (org.junit.Test)25 BadRequestException (com.ctrip.framework.apollo.common.exception.BadRequestException)8 Sql (org.springframework.test.context.jdbc.Sql)7 NamespaceDTO (com.ctrip.framework.apollo.common.dto.NamespaceDTO)6 ApolloConfig (com.ctrip.framework.apollo.core.dto.ApolloConfig)6 AbstractUnitTest (com.ctrip.framework.apollo.portal.AbstractUnitTest)6 HttpServletResponse (javax.servlet.http.HttpServletResponse)6 Matchers.anyString (org.mockito.Matchers.anyString)6 Namespace (com.ctrip.framework.apollo.biz.entity.Namespace)5 AbstractIntegrationTest (com.ctrip.framework.apollo.portal.AbstractIntegrationTest)5 Transactional (org.springframework.transaction.annotation.Transactional)5 AbstractIntegrationTest (com.ctrip.framework.apollo.biz.AbstractIntegrationTest)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 Release (com.ctrip.framework.apollo.biz.entity.Release)2 AppNamespaceCreationEvent (com.ctrip.framework.apollo.portal.listener.AppNamespaceCreationEvent)2 PageRequest (org.springframework.data.domain.PageRequest)2 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)2 AbstractUnitTest (com.ctrip.framework.apollo.biz.AbstractUnitTest)1 Cluster (com.ctrip.framework.apollo.biz.entity.Cluster)1