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; ...@@ -9,6 +9,7 @@ import org.springframework.transaction.annotation.Transactional;
import com.ctrip.apollo.biz.entity.AppNamespace; import com.ctrip.apollo.biz.entity.AppNamespace;
import com.ctrip.apollo.biz.entity.Audit; import com.ctrip.apollo.biz.entity.Audit;
import com.ctrip.apollo.biz.repository.AppNamespaceRepository; import com.ctrip.apollo.biz.repository.AppNamespaceRepository;
import com.ctrip.apollo.core.ConfigConsts;
import com.ctrip.apollo.core.exception.ServiceException; import com.ctrip.apollo.core.exception.ServiceException;
@Service @Service
...@@ -33,7 +34,7 @@ public class AppNamespaceService { ...@@ -33,7 +34,7 @@ public class AppNamespaceService {
} }
AppNamespace appNs = new AppNamespace(); AppNamespace appNs = new AppNamespace();
appNs.setAppId(appId); appNs.setAppId(appId);
appNs.setName(appId); appNs.setName(ConfigConsts.NAMESPACE_DEFAULT);
appNs.setComment("default app namespace"); appNs.setComment("default app namespace");
appNs.setDataChangeCreatedBy(createBy); appNs.setDataChangeCreatedBy(createBy);
appNs.setDataChangeLastModifiedBy(createBy); appNs.setDataChangeLastModifiedBy(createBy);
......
...@@ -91,7 +91,7 @@ public class NamespaceService { ...@@ -91,7 +91,7 @@ public class NamespaceService {
Namespace ns = new Namespace(); Namespace ns = new Namespace();
ns.setAppId(appId); ns.setAppId(appId);
ns.setClusterName(ConfigConsts.CLUSTER_NAME_DEFAULT); ns.setClusterName(ConfigConsts.CLUSTER_NAME_DEFAULT);
ns.setNamespaceName(appId); ns.setNamespaceName(ConfigConsts.NAMESPACE_DEFAULT);
ns.setDataChangeCreatedBy(createBy); ns.setDataChangeCreatedBy(createBy);
ns.setDataChangeLastModifiedBy(createBy); ns.setDataChangeLastModifiedBy(createBy);
namespaceRepository.save(ns); namespaceRepository.save(ns);
......
...@@ -64,7 +64,7 @@ public class AdminServiceTest { ...@@ -64,7 +64,7 @@ public class AdminServiceTest {
List<Namespace> namespaces = namespaceService.findNamespaces(appId, clusters.get(0).getName()); List<Namespace> namespaces = namespaceService.findNamespaces(appId, clusters.get(0).getName());
Assert.assertEquals(1, namespaces.size()); 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); List<Audit> audits = auditService.findByOwner(owner);
Assert.assertEquals(4, audits.size()); Assert.assertEquals(4, audits.size());
......
...@@ -41,18 +41,18 @@ public class ServiceLocator { ...@@ -41,18 +41,18 @@ public class ServiceLocator {
public ServiceDTO getAdminService(Env env) throws ServiceException { public ServiceDTO getAdminService(Env env) throws ServiceException {
List<ServiceDTO> services = getServices(env, "admin"); List<ServiceDTO> services = getServices(env, "admin");
if (services.size() == 0) { if (services == null || services.size() == 0) {
throw new ServiceException("No available admin service"); 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 { public ServiceDTO getConfigService(Env env) throws ServiceException {
List<ServiceDTO> services = getServices(env, "config"); List<ServiceDTO> services = getServices(env, "config");
if (services.size() == 0) { if (services == null || services.size() == 0) {
throw new ServiceException("No available config service"); 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) { 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