Search in sources :

Example 26 with NamespaceDTO

use of com.ctrip.framework.apollo.common.dto.NamespaceDTO in project apollo by ctripcorp.

the class ItemService method createItem.

public ItemDTO createItem(String appId, Env env, String clusterName, String namespaceName, ItemDTO item) {
    NamespaceDTO namespace = namespaceAPI.loadNamespace(appId, env, clusterName, namespaceName);
    if (namespace == null) {
        throw new BadRequestException("namespace:" + namespaceName + " not exist in env:" + env + ", cluster:" + clusterName);
    }
    item.setNamespaceId(namespace.getId());
    ItemDTO itemDTO = itemAPI.createItem(appId, env, clusterName, namespaceName, item);
    Tracer.logEvent(TracerEventType.MODIFY_NAMESPACE, String.format("%s+%s+%s+%s", appId, env, clusterName, namespaceName));
    return itemDTO;
}
Also used : NamespaceDTO(com.ctrip.framework.apollo.common.dto.NamespaceDTO) ItemDTO(com.ctrip.framework.apollo.common.dto.ItemDTO) BadRequestException(com.ctrip.framework.apollo.common.exception.BadRequestException)

Example 27 with NamespaceDTO

use of com.ctrip.framework.apollo.common.dto.NamespaceDTO in project apollo by ctripcorp.

the class ItemService method getNamespaceId.

private long getNamespaceId(NamespaceIdentifier namespaceIdentifier) {
    String appId = namespaceIdentifier.getAppId();
    String clusterName = namespaceIdentifier.getClusterName();
    String namespaceName = namespaceIdentifier.getNamespaceName();
    Env env = namespaceIdentifier.getEnv();
    NamespaceDTO namespaceDTO;
    try {
        namespaceDTO = namespaceAPI.loadNamespace(appId, env, clusterName, namespaceName);
    } catch (HttpClientErrorException e) {
        if (e.getStatusCode() == HttpStatus.NOT_FOUND) {
            throw new BadRequestException(String.format("namespace not exist. appId:%s, env:%s, clusterName:%s, namespaceName:%s", appId, env, clusterName, namespaceName));
        }
        throw e;
    }
    return namespaceDTO.getId();
}
Also used : NamespaceDTO(com.ctrip.framework.apollo.common.dto.NamespaceDTO) HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) BadRequestException(com.ctrip.framework.apollo.common.exception.BadRequestException) Env(com.ctrip.framework.apollo.portal.environment.Env)

Example 28 with NamespaceDTO

use of com.ctrip.framework.apollo.common.dto.NamespaceDTO in project apollo by ctripcorp.

the class NamespaceServiceTest method testDeleteNamespaceBranchHasInstance.

@Test(expected = BadRequestException.class)
public void testDeleteNamespaceBranchHasInstance() {
    AppNamespace publicNamespace = createAppNamespace(testAppId, testNamespaceName, true);
    String branchName = "branch";
    NamespaceDTO branch = createNamespace(testAppId, branchName, testNamespaceName);
    when(appNamespaceService.findByAppIdAndName(testAppId, testNamespaceName)).thenReturn(publicNamespace);
    when(instanceService.getInstanceCountByNamespace(testAppId, testEnv, testClusterName, testNamespaceName)).thenReturn(0);
    when(branchService.findBranchBaseInfo(testAppId, testEnv, testClusterName, testNamespaceName)).thenReturn(branch);
    when(instanceService.getInstanceCountByNamespace(testAppId, testEnv, branchName, 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)

Example 29 with NamespaceDTO

use of com.ctrip.framework.apollo.common.dto.NamespaceDTO in project apollo by ctripcorp.

the class NamespaceServiceTest method createNamespace.

private NamespaceDTO createNamespace(String appId, String clusterName, String namespaceName) {
    NamespaceDTO instance = new NamespaceDTO();
    instance.setAppId(appId);
    instance.setClusterName(clusterName);
    instance.setNamespaceName(namespaceName);
    return instance;
}
Also used : NamespaceDTO(com.ctrip.framework.apollo.common.dto.NamespaceDTO)

Example 30 with NamespaceDTO

use of com.ctrip.framework.apollo.common.dto.NamespaceDTO 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.getInstanceCountByNamespace(testAppId, testEnv, testClusterName, testNamespaceName)).thenReturn(0);
    when(branchService.findBranchBaseInfo(testAppId, testEnv, testClusterName, testNamespaceName)).thenReturn(branch);
    when(instanceService.getInstanceCountByNamespace(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

NamespaceDTO (com.ctrip.framework.apollo.common.dto.NamespaceDTO)36 Test (org.junit.Test)13 ItemDTO (com.ctrip.framework.apollo.common.dto.ItemDTO)12 BadRequestException (com.ctrip.framework.apollo.common.exception.BadRequestException)10 ItemChangeSets (com.ctrip.framework.apollo.common.dto.ItemChangeSets)8 AppNamespace (com.ctrip.framework.apollo.common.entity.AppNamespace)7 AbstractUnitTest (com.ctrip.framework.apollo.portal.AbstractUnitTest)7 AppDTO (com.ctrip.framework.apollo.common.dto.AppDTO)4 ClusterDTO (com.ctrip.framework.apollo.common.dto.ClusterDTO)4 Sql (org.springframework.test.context.jdbc.Sql)4 Item (com.ctrip.framework.apollo.biz.entity.Item)3 PageDTO (com.ctrip.framework.apollo.common.dto.PageDTO)3 ReleaseDTO (com.ctrip.framework.apollo.common.dto.ReleaseDTO)3 OpenNamespaceDTO (com.ctrip.framework.apollo.openapi.dto.OpenNamespaceDTO)3 NamespaceBO (com.ctrip.framework.apollo.portal.entity.bo.NamespaceBO)3 UserInfo (com.ctrip.framework.apollo.portal.entity.bo.UserInfo)3 Env (com.ctrip.framework.apollo.portal.environment.Env)3 TestRestTemplate (org.springframework.boot.test.web.client.TestRestTemplate)3 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)3 RestTemplate (org.springframework.web.client.RestTemplate)3