refactor(api、client): modify MaintainService to NamingMaintainService

This commit is contained in:
chuntaojun 2019-05-09 10:07:09 +08:00
parent 141f8a19ea
commit ac36a41d86
6 changed files with 38 additions and 39 deletions

View File

@ -20,8 +20,8 @@ import java.util.Properties;
import com.alibaba.nacos.api.config.ConfigFactory;
import com.alibaba.nacos.api.config.ConfigService;
import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.api.naming.MaintainFactory;
import com.alibaba.nacos.api.naming.MaintainService;
import com.alibaba.nacos.api.naming.NamingMaintainFactory;
import com.alibaba.nacos.api.naming.NamingMaintainService;
import com.alibaba.nacos.api.naming.NamingFactory;
import com.alibaba.nacos.api.naming.NamingService;
@ -80,22 +80,22 @@ public class NacosFactory {
* Create maintain service
*
* @param serverAddr
* @return MaintainService
* @return NamingMaintainService
* @throws NacosException Exception
*/
public static MaintainService createMaintainService(String serverAddr) throws NacosException {
return MaintainFactory.createMaintainService(serverAddr);
public static NamingMaintainService createMaintainService(String serverAddr) throws NacosException {
return NamingMaintainFactory.createMaintainService(serverAddr);
}
/**
* Create maintain service
*
* @param properties
* @return MaintainService
* @return NamingMaintainService
* @throws NacosException Exception
*/
public static MaintainService createMaintainService(Properties properties) throws NacosException {
return MaintainFactory.createMaintainService(properties);
public static NamingMaintainService createMaintainService(Properties properties) throws NacosException {
return NamingMaintainFactory.createMaintainService(properties);
}
}

View File

@ -25,24 +25,24 @@ import java.util.Properties;
* @author liaochuntao
* @since 1.0.1
*/
public class MaintainFactory {
public class NamingMaintainFactory {
public static MaintainService createMaintainService(String serverList) throws NacosException {
public static NamingMaintainService createMaintainService(String serverList) throws NacosException {
try {
Class<?> driverImplClass = Class.forName("com.alibaba.nacos.client.naming.NacosMaintainService");
Constructor constructor = driverImplClass.getConstructor(String.class);
MaintainService vendorImpl = (MaintainService)constructor.newInstance(serverList);
NamingMaintainService vendorImpl = (NamingMaintainService)constructor.newInstance(serverList);
return vendorImpl;
} catch (Throwable e) {
throw new NacosException(-400, e.getMessage());
}
}
public static MaintainService createMaintainService(Properties properties) throws NacosException {
public static NamingMaintainService createMaintainService(Properties properties) throws NacosException {
try {
Class<?> driverImplClass = Class.forName("com.alibaba.nacos.client.naming.NacosMaintainService");
Constructor constructor = driverImplClass.getConstructor(Properties.class);
MaintainService vendorImpl = (MaintainService)constructor.newInstance(properties);
NamingMaintainService vendorImpl = (NamingMaintainService)constructor.newInstance(properties);
return vendorImpl;
} catch (Throwable e) {
throw new NacosException(-400, e.getMessage());

View File

@ -29,7 +29,7 @@ import java.util.Map;
* @author liaochuntao
* @since 1.0.1
*/
public interface MaintainService {
public interface NamingMaintainService {
/**
* update instance info

View File

@ -19,7 +19,7 @@ package com.alibaba.nacos.client.naming;
import com.alibaba.nacos.api.PropertyKeyConst;
import com.alibaba.nacos.api.common.Constants;
import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.api.naming.MaintainService;
import com.alibaba.nacos.api.naming.NamingMaintainService;
import com.alibaba.nacos.api.naming.pojo.Instance;
import com.alibaba.nacos.api.naming.pojo.Service;
import com.alibaba.nacos.api.selector.AbstractSelector;
@ -37,7 +37,7 @@ import java.util.Properties;
* @since 1.0.1
*/
@SuppressWarnings("PMD.ServiceOrDaoClassShouldEndWithImplRule")
public class NacosMaintainService implements MaintainService {
public class NacosNamingMaintainService implements NamingMaintainService {
private String namespace;
@ -47,14 +47,14 @@ public class NacosMaintainService implements MaintainService {
private NamingProxy serverProxy;
public NacosMaintainService(String serverList) {
public NacosNamingMaintainService(String serverList) {
Properties properties = new Properties();
properties.setProperty(PropertyKeyConst.SERVER_ADDR, serverList);
init(properties);
}
public NacosMaintainService(Properties properties) {
public NacosNamingMaintainService(Properties properties) {
init(properties);
}

View File

@ -4,7 +4,7 @@ import com.alibaba.nacos.api.NacosFactory;
import com.alibaba.nacos.api.PropertyKeyConst;
import com.alibaba.nacos.api.common.Constants;
import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.api.naming.MaintainService;
import com.alibaba.nacos.api.naming.NamingMaintainService;
import com.alibaba.nacos.api.naming.NamingService;
import com.alibaba.nacos.api.naming.pojo.Service;
import com.alibaba.nacos.api.selector.ExpressionSelector;
@ -20,12 +20,11 @@ import java.util.Map;
import java.util.Properties;
import static com.alibaba.nacos.client.utils.LogUtils.NAMING_LOGGER;
import static org.junit.Assert.*;
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class NacosMaintainServiceTest {
public class NacosNamingMaintainServiceTest {
private MaintainService maintainService;
private NamingMaintainService namingMaintainService;
private NamingService namingService;
@Before
@ -33,7 +32,7 @@ public class NacosMaintainServiceTest {
Properties properties = new Properties();
properties.put(PropertyKeyConst.SERVER_ADDR, "127.0.0.1:8848");
maintainService = NacosFactory.createMaintainService(properties);
namingMaintainService = NacosFactory.createMaintainService(properties);
}
@Test
@ -50,7 +49,7 @@ public class NacosMaintainServiceTest {
selector.setExpression("CONSUMER.label.A=PROVIDER.label.A &CONSUMER.label.B=PROVIDER.label.B");
try {
maintainService.createService(service, new NoneSelector());
namingMaintainService.createService(service, new NoneSelector());
} catch (NacosException e) {
NAMING_LOGGER.error(e.getErrMsg());
}
@ -67,7 +66,7 @@ public class NacosMaintainServiceTest {
service.setMetadata(metadata);
try {
maintainService.updateService(service, new NoneSelector());
namingMaintainService.updateService(service, new NoneSelector());
} catch (NacosException e) {
NAMING_LOGGER.error(e.getErrMsg());
}
@ -76,7 +75,7 @@ public class NacosMaintainServiceTest {
@Test
public void test3selectOneService() {
try {
Service service = maintainService.queryService("nacos-api");
Service service = namingMaintainService.queryService("nacos-api");
System.out.println("service : " + service.toString());
} catch (NacosException e) {
NAMING_LOGGER.error(e.getErrMsg());
@ -86,7 +85,7 @@ public class NacosMaintainServiceTest {
@Test
public void test4deleteService() {
try {
Assert.assertTrue(maintainService.deleteService("nacos-api"));
Assert.assertTrue(namingMaintainService.deleteService("nacos-api"));
} catch (NacosException e) {
NAMING_LOGGER.error(e.getErrMsg());
}

View File

@ -18,8 +18,8 @@ package com.alibaba.nacos.test.naming;
import com.alibaba.nacos.api.common.Constants;
import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.api.naming.MaintainFactory;
import com.alibaba.nacos.api.naming.MaintainService;
import com.alibaba.nacos.api.naming.NamingMaintainFactory;
import com.alibaba.nacos.api.naming.NamingMaintainService;
import com.alibaba.nacos.api.naming.NamingFactory;
import com.alibaba.nacos.api.naming.NamingService;
import com.alibaba.nacos.api.naming.pojo.Instance;
@ -47,9 +47,9 @@ import java.util.concurrent.TimeUnit;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = NamingApp.class, properties = {"server.servlet.context-path=/nacos"},
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class MaintainService_ITCase {
public class NamingMaintainService_ITCase {
private MaintainService maintainService;
private NamingMaintainService namingMaintainService;
private NamingService namingService;
private Instance instance;
private Service service;
@ -62,9 +62,9 @@ public class MaintainService_ITCase {
NamingBase.prepareServer(port);
if (maintainService == null) {
if (namingMaintainService == null) {
TimeUnit.SECONDS.sleep(10);
maintainService = MaintainFactory.createMaintainService("127.0.0.1" + ":" + port);
namingMaintainService = NamingMaintainFactory.createMaintainService("127.0.0.1" + ":" + port);
}
if (namingService == null) {
@ -98,7 +98,7 @@ public class MaintainService_ITCase {
map.put("version", "2.0");
instance.setMetadata(map);
namingService.registerInstance("nacos-api", instance);
maintainService.updateInstance("nacos-api", instance);
namingMaintainService.updateInstance("nacos-api", instance);
List<Instance> instances = namingService.getAllInstances("nacos-api", true);
Assert.assertEquals(instances.size(), 1);
@ -112,8 +112,8 @@ public class MaintainService_ITCase {
selector.setExpression("CONSUMER.label.A=PROVIDER.label.A &CONSUMER.label.B=PROVIDER.label.B");
System.out.println("service info : " + service);
maintainService.createService(service, selector);
Service remoteService = maintainService.queryService("nacos-api");
namingMaintainService.createService(service, selector);
Service remoteService = namingMaintainService.queryService("nacos-api");
System.out.println("remote service info : " + remoteService);
Assert.assertEquals(service.toString(), remoteService.toString());
}
@ -128,15 +128,15 @@ public class MaintainService_ITCase {
metadata.put("nacos-1", "nacos-3-update");
service.setMetadata(metadata);
maintainService.updateService(service, new NoneSelector());
Service remoteService = maintainService.queryService("nacos-api");
namingMaintainService.updateService(service, new NoneSelector());
Service remoteService = namingMaintainService.queryService("nacos-api");
System.out.println("remote service info : " + remoteService);
Assert.assertEquals(service.toString(), remoteService.toString());
}
@Test
public void deleteService() throws NacosException {
Assert.assertTrue(maintainService.deleteService("nacos-api"));
Assert.assertTrue(namingMaintainService.deleteService("nacos-api"));
}
@Test