Search in sources :

Example 21 with AppNamespace

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

the class AppNamespaceServiceTest method testCreatePrivateAppNamespaceExisted.

@Test(expected = BadRequestException.class)
@Sql(scripts = "/sql/appnamespaceservice/init-appnamespace.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/sql/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testCreatePrivateAppNamespaceExisted() {
    AppNamespace appNamespace = assmbleBaseAppNamespace();
    appNamespace.setPublic(false);
    appNamespace.setName("datasource.xml");
    appNamespace.setAppId("100003173");
    appNamespaceService.createAppNamespaceInLocal(appNamespace);
}
Also used : AppNamespace(com.ctrip.framework.apollo.common.entity.AppNamespace) AbstractIntegrationTest(com.ctrip.framework.apollo.portal.AbstractIntegrationTest) Test(org.junit.Test) Sql(org.springframework.test.context.jdbc.Sql)

Example 22 with AppNamespace

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

the class AppNamespaceServiceTest method testCreatePrivateAppNamespaceNotExisted.

@Test
@Sql(scripts = "/sql/appnamespaceservice/init-appnamespace.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/sql/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testCreatePrivateAppNamespaceNotExisted() {
    AppNamespace appNamespace = assmbleBaseAppNamespace();
    appNamespace.setPublic(false);
    appNamespaceService.createAppNamespaceInLocal(appNamespace);
    AppNamespace createdAppNamespace = appNamespaceService.findByAppIdAndName(appNamespace.getAppId(), appNamespace.getName());
    Assert.assertNotNull(createdAppNamespace);
    Assert.assertEquals(appNamespace.getName(), createdAppNamespace.getName());
}
Also used : AppNamespace(com.ctrip.framework.apollo.common.entity.AppNamespace) AbstractIntegrationTest(com.ctrip.framework.apollo.portal.AbstractIntegrationTest) Test(org.junit.Test) Sql(org.springframework.test.context.jdbc.Sql)

Example 23 with AppNamespace

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

the class NamespaceService method fillAppNamespaceProperties.

private void fillAppNamespaceProperties(NamespaceBO namespace) {
    NamespaceDTO namespaceDTO = namespace.getBaseInfo();
    // 先从当前appId下面找,包含私有的和公共的
    AppNamespace appNamespace = appNamespaceService.findByAppIdAndName(namespaceDTO.getAppId(), namespaceDTO.getNamespaceName());
    // 再从公共的app namespace里面找
    if (appNamespace == null) {
        appNamespace = appNamespaceService.findPublicAppNamespace(namespaceDTO.getNamespaceName());
    }
    String format;
    boolean isPublic;
    if (appNamespace == null) {
        format = ConfigFileFormat.Properties.getValue();
        isPublic = false;
    } else {
        format = appNamespace.getFormat();
        isPublic = appNamespace.isPublic();
        namespace.setParentAppId(appNamespace.getAppId());
        namespace.setComment(appNamespace.getComment());
    }
    namespace.setFormat(format);
    namespace.setPublic(isPublic);
}
Also used : NamespaceDTO(com.ctrip.framework.apollo.common.dto.NamespaceDTO) AppNamespace(com.ctrip.framework.apollo.common.entity.AppNamespace)

Example 24 with AppNamespace

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

the class NamespaceService method deleteNamespace.

@Transactional
public void deleteNamespace(String appId, Env env, String clusterName, String namespaceName) {
    // 1. check private namespace
    AppNamespace appNamespace = appNamespaceService.findByAppIdAndName(appId, namespaceName);
    if (appNamespace != null && !appNamespace.isPublic()) {
        throw new BadRequestException("Private namespace can not be deleted");
    }
    // 2. check parent namespace has not instances
    if (namespaceHasInstances(appId, env, clusterName, namespaceName)) {
        throw new BadRequestException("Can not delete namespace because namespace has active instances");
    }
    // 3. check child namespace has not instances
    NamespaceDTO childNamespace = branchService.findBranchBaseInfo(appId, env, clusterName, namespaceName);
    if (childNamespace != null && namespaceHasInstances(appId, env, childNamespace.getClusterName(), namespaceName)) {
        throw new BadRequestException("Can not delete namespace because namespace's branch has active instances");
    }
    // 4. check public namespace has not associated namespace
    if (appNamespace != null && publicAppNamespaceHasAssociatedNamespace(namespaceName, env)) {
        throw new BadRequestException("Can not delete public namespace which has associated namespaces");
    }
    String operator = userInfoHolder.getUser().getUserId();
    namespaceAPI.deleteNamespace(env, appId, clusterName, namespaceName, operator);
}
Also used : NamespaceDTO(com.ctrip.framework.apollo.common.dto.NamespaceDTO) BadRequestException(com.ctrip.framework.apollo.common.exception.BadRequestException) AppNamespace(com.ctrip.framework.apollo.common.entity.AppNamespace) Transactional(org.springframework.transaction.annotation.Transactional)

Example 25 with AppNamespace

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

the class NamespaceServiceTest method testDeleteNamespaceWithAssociatedNamespace.

@Test(expected = BadRequestException.class)
public void testDeleteNamespaceWithAssociatedNamespace() {
    AppNamespace publicNamespace = createAppNamespace(testAppId, testNamespaceName, true);
    String branchName = "branch";
    NamespaceDTO branch = createNamespace(testAppId, branchName, testNamespaceName);
    when(appNamespaceService.findByAppIdAndName(testAppId, testNamespaceName)).thenReturn(publicNamespace);
    when(instanceService.getInstanceCountByNamepsace(testAppId, testEnv, testClusterName, testNamespaceName)).thenReturn(0);
    when(branchService.findBranchBaseInfo(testAppId, testEnv, testClusterName, testNamespaceName)).thenReturn(branch);
    when(instanceService.getInstanceCountByNamepsace(testAppId, testEnv, branchName, testNamespaceName)).thenReturn(0);
    when(appNamespaceService.findPublicAppNamespace(testNamespaceName)).thenReturn(publicNamespace);
    when(namespaceAPI.countPublicAppNamespaceAssociatedNamespaces(testEnv, testNamespaceName)).thenReturn(10);
    namespaceService.deleteNamespace(testAppId, testEnv, testClusterName, testNamespaceName);
}
Also used : NamespaceDTO(com.ctrip.framework.apollo.common.dto.NamespaceDTO) AppNamespace(com.ctrip.framework.apollo.common.entity.AppNamespace) Test(org.junit.Test) AbstractUnitTest(com.ctrip.framework.apollo.portal.AbstractUnitTest)

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