Commit 536eb044 by Yiming Liu

Merge pull request #144 from lepdou/bugfix_servicelocator

Bugfix service locator & change default namespace name to application
parents 6f611a78 31cf3311
......@@ -9,6 +9,7 @@ import org.springframework.transaction.annotation.Transactional;
import com.ctrip.apollo.biz.entity.AppNamespace;
import com.ctrip.apollo.biz.entity.Audit;
import com.ctrip.apollo.biz.repository.AppNamespaceRepository;
import com.ctrip.apollo.core.ConfigConsts;
import com.ctrip.apollo.core.exception.ServiceException;
@Service
......@@ -33,7 +34,7 @@ public class AppNamespaceService {
}
AppNamespace appNs = new AppNamespace();
appNs.setAppId(appId);
appNs.setName(appId);
appNs.setName(ConfigConsts.NAMESPACE_DEFAULT);
appNs.setComment("default app namespace");
appNs.setDataChangeCreatedBy(createBy);
appNs.setDataChangeLastModifiedBy(createBy);
......
......@@ -91,7 +91,7 @@ public class NamespaceService {
Namespace ns = new Namespace();
ns.setAppId(appId);
ns.setClusterName(ConfigConsts.CLUSTER_NAME_DEFAULT);
ns.setNamespaceName(appId);
ns.setNamespaceName(ConfigConsts.NAMESPACE_DEFAULT);
ns.setDataChangeCreatedBy(createBy);
ns.setDataChangeLastModifiedBy(createBy);
namespaceRepository.save(ns);
......
......@@ -64,7 +64,7 @@ public class AdminServiceTest {
List<Namespace> namespaces = namespaceService.findNamespaces(appId, clusters.get(0).getName());
Assert.assertEquals(1, namespaces.size());
Assert.assertEquals(appId, namespaces.get(0).getNamespaceName());
Assert.assertEquals(ConfigConsts.NAMESPACE_DEFAULT, namespaces.get(0).getNamespaceName());
List<Audit> audits = auditService.findByOwner(owner);
Assert.assertEquals(4, audits.size());
......
......@@ -41,18 +41,18 @@ public class ServiceLocator {
public ServiceDTO getAdminService(Env env) throws ServiceException {
List<ServiceDTO> services = getServices(env, "admin");
if (services.size() == 0) {
if (services == null || services.size() == 0) {
throw new ServiceException("No available admin service");
}
return services.get(adminCallCounts.getAndIncrement() % services.size());
return services.get(Math.abs(adminCallCounts.getAndIncrement()) % services.size());
}
public ServiceDTO getConfigService(Env env) throws ServiceException {
List<ServiceDTO> services = getServices(env, "config");
if (services.size() == 0) {
if (services == null || services.size() == 0) {
throw new ServiceException("No available config service");
}
return services.get(configCallCounts.getAndIncrement() % services.size());
return services.get(Math.abs(configCallCounts.getAndIncrement()) % services.size());
}
private List<ServiceDTO> getServices(Env env, String serviceUrl) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment