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;
}
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();
}
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);
}
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;
}
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);
}
Aggregations