Search in sources :

Example 1 with AppNamespace

use of com.ctrip.framework.apollo.common.entity.AppNamespace in project apollo by ctripcorp.

the class AppNamespaceController method create.

@RequestMapping(value = "/apps/{appId}/appnamespaces", method = RequestMethod.POST)
public AppNamespaceDTO create(@RequestBody AppNamespaceDTO appNamespace) {
    AppNamespace entity = BeanUtils.transfrom(AppNamespace.class, appNamespace);
    AppNamespace managedEntity = appNamespaceService.findOne(entity.getAppId(), entity.getName());
    if (managedEntity != null) {
        throw new BadRequestException("app namespaces already exist.");
    }
    if (StringUtils.isEmpty(entity.getFormat())) {
        entity.setFormat(ConfigFileFormat.Properties.getValue());
    }
    entity = appNamespaceService.createAppNamespace(entity);
    return BeanUtils.transfrom(AppNamespaceDTO.class, entity);
}
Also used : BadRequestException(com.ctrip.framework.apollo.common.exception.BadRequestException) AppNamespace(com.ctrip.framework.apollo.common.entity.AppNamespace) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with AppNamespace

use of com.ctrip.framework.apollo.common.entity.AppNamespace in project apollo by ctripcorp.

the class AppNamespaceRepositoryTest method testFindByNameAndNoPublicNamespace.

@Test
public void testFindByNameAndNoPublicNamespace() throws Exception {
    AppNamespace appNamespace = repository.findByNameAndIsPublicTrue("application");
    assertNull(appNamespace);
}
Also used : AppNamespace(com.ctrip.framework.apollo.common.entity.AppNamespace) AbstractIntegrationTest(com.ctrip.framework.apollo.biz.AbstractIntegrationTest) Test(org.junit.Test)

Example 3 with AppNamespace

use of com.ctrip.framework.apollo.common.entity.AppNamespace in project apollo by ctripcorp.

the class AppNamespaceRepositoryTest method testFindByNameAndIsPublicTrue.

@Test
public void testFindByNameAndIsPublicTrue() throws Exception {
    AppNamespace appNamespace = repository.findByNameAndIsPublicTrue("fx.apollo.config");
    assertEquals("100003171", appNamespace.getAppId());
}
Also used : AppNamespace(com.ctrip.framework.apollo.common.entity.AppNamespace) AbstractIntegrationTest(com.ctrip.framework.apollo.biz.AbstractIntegrationTest) Test(org.junit.Test)

Example 4 with AppNamespace

use of com.ctrip.framework.apollo.common.entity.AppNamespace in project apollo by ctripcorp.

the class NamespaceService method findPublicNamespaceForAssociatedNamespace.

public Namespace findPublicNamespaceForAssociatedNamespace(String clusterName, String namespaceName) {
    AppNamespace appNamespace = appNamespaceService.findPublicNamespaceByName(namespaceName);
    if (appNamespace == null) {
        throw new BadRequestException("namespace not exist");
    }
    String appId = appNamespace.getAppId();
    Namespace namespace = findOne(appId, clusterName, namespaceName);
    // default cluster's namespace
    if (Objects.equals(clusterName, ConfigConsts.CLUSTER_NAME_DEFAULT)) {
        return namespace;
    }
    // return default cluster's namespace
    if (namespace == null) {
        return findOne(appId, ConfigConsts.CLUSTER_NAME_DEFAULT, namespaceName);
    }
    // custom cluster's namespace exist and has published.
    // return custom cluster's namespace
    Release latestActiveRelease = releaseService.findLatestActiveRelease(namespace);
    if (latestActiveRelease != null) {
        return namespace;
    }
    Namespace defaultNamespace = findOne(appId, ConfigConsts.CLUSTER_NAME_DEFAULT, namespaceName);
    // return custom cluster's namespace
    if (defaultNamespace == null) {
        return namespace;
    }
    // custom cluster's namespace exist but never published.
    // and default cluster's namespace exist and has published.
    // return default cluster's namespace
    Release defaultNamespaceLatestActiveRelease = releaseService.findLatestActiveRelease(defaultNamespace);
    if (defaultNamespaceLatestActiveRelease != null) {
        return defaultNamespace;
    }
    // return custom cluster's namespace
    return namespace;
}
Also used : BadRequestException(com.ctrip.framework.apollo.common.exception.BadRequestException) AppNamespace(com.ctrip.framework.apollo.common.entity.AppNamespace) Namespace(com.ctrip.framework.apollo.biz.entity.Namespace) AppNamespace(com.ctrip.framework.apollo.common.entity.AppNamespace) Release(com.ctrip.framework.apollo.biz.entity.Release)

Example 5 with AppNamespace

use of com.ctrip.framework.apollo.common.entity.AppNamespace in project apollo by ctripcorp.

the class NamespaceService method findPublicAppNamespaceAllNamespaces.

public List<Namespace> findPublicAppNamespaceAllNamespaces(String namespaceName, Pageable page) {
    AppNamespace publicAppNamespace = appNamespaceService.findPublicNamespaceByName(namespaceName);
    if (publicAppNamespace == null) {
        throw new BadRequestException(String.format("Public appNamespace not exists. NamespaceName = %s", namespaceName));
    }
    List<Namespace> namespaces = namespaceRepository.findByNamespaceName(namespaceName, page);
    return filterChildNamespace(namespaces);
}
Also used : BadRequestException(com.ctrip.framework.apollo.common.exception.BadRequestException) AppNamespace(com.ctrip.framework.apollo.common.entity.AppNamespace) Namespace(com.ctrip.framework.apollo.biz.entity.Namespace) 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