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