refactor(api、client): modify MaintainService to NamingMaintainService
This commit is contained in:
parent
141f8a19ea
commit
ac36a41d86
@ -20,8 +20,8 @@ import java.util.Properties;
|
|||||||
import com.alibaba.nacos.api.config.ConfigFactory;
|
import com.alibaba.nacos.api.config.ConfigFactory;
|
||||||
import com.alibaba.nacos.api.config.ConfigService;
|
import com.alibaba.nacos.api.config.ConfigService;
|
||||||
import com.alibaba.nacos.api.exception.NacosException;
|
import com.alibaba.nacos.api.exception.NacosException;
|
||||||
import com.alibaba.nacos.api.naming.MaintainFactory;
|
import com.alibaba.nacos.api.naming.NamingMaintainFactory;
|
||||||
import com.alibaba.nacos.api.naming.MaintainService;
|
import com.alibaba.nacos.api.naming.NamingMaintainService;
|
||||||
import com.alibaba.nacos.api.naming.NamingFactory;
|
import com.alibaba.nacos.api.naming.NamingFactory;
|
||||||
import com.alibaba.nacos.api.naming.NamingService;
|
import com.alibaba.nacos.api.naming.NamingService;
|
||||||
|
|
||||||
@ -80,22 +80,22 @@ public class NacosFactory {
|
|||||||
* Create maintain service
|
* Create maintain service
|
||||||
*
|
*
|
||||||
* @param serverAddr
|
* @param serverAddr
|
||||||
* @return MaintainService
|
* @return NamingMaintainService
|
||||||
* @throws NacosException Exception
|
* @throws NacosException Exception
|
||||||
*/
|
*/
|
||||||
public static MaintainService createMaintainService(String serverAddr) throws NacosException {
|
public static NamingMaintainService createMaintainService(String serverAddr) throws NacosException {
|
||||||
return MaintainFactory.createMaintainService(serverAddr);
|
return NamingMaintainFactory.createMaintainService(serverAddr);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create maintain service
|
* Create maintain service
|
||||||
*
|
*
|
||||||
* @param properties
|
* @param properties
|
||||||
* @return MaintainService
|
* @return NamingMaintainService
|
||||||
* @throws NacosException Exception
|
* @throws NacosException Exception
|
||||||
*/
|
*/
|
||||||
public static MaintainService createMaintainService(Properties properties) throws NacosException {
|
public static NamingMaintainService createMaintainService(Properties properties) throws NacosException {
|
||||||
return MaintainFactory.createMaintainService(properties);
|
return NamingMaintainFactory.createMaintainService(properties);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -25,24 +25,24 @@ import java.util.Properties;
|
|||||||
* @author liaochuntao
|
* @author liaochuntao
|
||||||
* @since 1.0.1
|
* @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 {
|
try {
|
||||||
Class<?> driverImplClass = Class.forName("com.alibaba.nacos.client.naming.NacosMaintainService");
|
Class<?> driverImplClass = Class.forName("com.alibaba.nacos.client.naming.NacosMaintainService");
|
||||||
Constructor constructor = driverImplClass.getConstructor(String.class);
|
Constructor constructor = driverImplClass.getConstructor(String.class);
|
||||||
MaintainService vendorImpl = (MaintainService)constructor.newInstance(serverList);
|
NamingMaintainService vendorImpl = (NamingMaintainService)constructor.newInstance(serverList);
|
||||||
return vendorImpl;
|
return vendorImpl;
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
throw new NacosException(-400, e.getMessage());
|
throw new NacosException(-400, e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MaintainService createMaintainService(Properties properties) throws NacosException {
|
public static NamingMaintainService createMaintainService(Properties properties) throws NacosException {
|
||||||
try {
|
try {
|
||||||
Class<?> driverImplClass = Class.forName("com.alibaba.nacos.client.naming.NacosMaintainService");
|
Class<?> driverImplClass = Class.forName("com.alibaba.nacos.client.naming.NacosMaintainService");
|
||||||
Constructor constructor = driverImplClass.getConstructor(Properties.class);
|
Constructor constructor = driverImplClass.getConstructor(Properties.class);
|
||||||
MaintainService vendorImpl = (MaintainService)constructor.newInstance(properties);
|
NamingMaintainService vendorImpl = (NamingMaintainService)constructor.newInstance(properties);
|
||||||
return vendorImpl;
|
return vendorImpl;
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
throw new NacosException(-400, e.getMessage());
|
throw new NacosException(-400, e.getMessage());
|
@ -29,7 +29,7 @@ import java.util.Map;
|
|||||||
* @author liaochuntao
|
* @author liaochuntao
|
||||||
* @since 1.0.1
|
* @since 1.0.1
|
||||||
*/
|
*/
|
||||||
public interface MaintainService {
|
public interface NamingMaintainService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* update instance info
|
* update instance info
|
@ -19,7 +19,7 @@ package com.alibaba.nacos.client.naming;
|
|||||||
import com.alibaba.nacos.api.PropertyKeyConst;
|
import com.alibaba.nacos.api.PropertyKeyConst;
|
||||||
import com.alibaba.nacos.api.common.Constants;
|
import com.alibaba.nacos.api.common.Constants;
|
||||||
import com.alibaba.nacos.api.exception.NacosException;
|
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.Instance;
|
||||||
import com.alibaba.nacos.api.naming.pojo.Service;
|
import com.alibaba.nacos.api.naming.pojo.Service;
|
||||||
import com.alibaba.nacos.api.selector.AbstractSelector;
|
import com.alibaba.nacos.api.selector.AbstractSelector;
|
||||||
@ -37,7 +37,7 @@ import java.util.Properties;
|
|||||||
* @since 1.0.1
|
* @since 1.0.1
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("PMD.ServiceOrDaoClassShouldEndWithImplRule")
|
@SuppressWarnings("PMD.ServiceOrDaoClassShouldEndWithImplRule")
|
||||||
public class NacosMaintainService implements MaintainService {
|
public class NacosNamingMaintainService implements NamingMaintainService {
|
||||||
|
|
||||||
private String namespace;
|
private String namespace;
|
||||||
|
|
||||||
@ -47,14 +47,14 @@ public class NacosMaintainService implements MaintainService {
|
|||||||
|
|
||||||
private NamingProxy serverProxy;
|
private NamingProxy serverProxy;
|
||||||
|
|
||||||
public NacosMaintainService(String serverList) {
|
public NacosNamingMaintainService(String serverList) {
|
||||||
Properties properties = new Properties();
|
Properties properties = new Properties();
|
||||||
properties.setProperty(PropertyKeyConst.SERVER_ADDR, serverList);
|
properties.setProperty(PropertyKeyConst.SERVER_ADDR, serverList);
|
||||||
|
|
||||||
init(properties);
|
init(properties);
|
||||||
}
|
}
|
||||||
|
|
||||||
public NacosMaintainService(Properties properties) {
|
public NacosNamingMaintainService(Properties properties) {
|
||||||
|
|
||||||
init(properties);
|
init(properties);
|
||||||
}
|
}
|
@ -4,7 +4,7 @@ import com.alibaba.nacos.api.NacosFactory;
|
|||||||
import com.alibaba.nacos.api.PropertyKeyConst;
|
import com.alibaba.nacos.api.PropertyKeyConst;
|
||||||
import com.alibaba.nacos.api.common.Constants;
|
import com.alibaba.nacos.api.common.Constants;
|
||||||
import com.alibaba.nacos.api.exception.NacosException;
|
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.NamingService;
|
||||||
import com.alibaba.nacos.api.naming.pojo.Service;
|
import com.alibaba.nacos.api.naming.pojo.Service;
|
||||||
import com.alibaba.nacos.api.selector.ExpressionSelector;
|
import com.alibaba.nacos.api.selector.ExpressionSelector;
|
||||||
@ -20,12 +20,11 @@ import java.util.Map;
|
|||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import static com.alibaba.nacos.client.utils.LogUtils.NAMING_LOGGER;
|
import static com.alibaba.nacos.client.utils.LogUtils.NAMING_LOGGER;
|
||||||
import static org.junit.Assert.*;
|
|
||||||
|
|
||||||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||||
public class NacosMaintainServiceTest {
|
public class NacosNamingMaintainServiceTest {
|
||||||
|
|
||||||
private MaintainService maintainService;
|
private NamingMaintainService namingMaintainService;
|
||||||
private NamingService namingService;
|
private NamingService namingService;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
@ -33,7 +32,7 @@ public class NacosMaintainServiceTest {
|
|||||||
Properties properties = new Properties();
|
Properties properties = new Properties();
|
||||||
properties.put(PropertyKeyConst.SERVER_ADDR, "127.0.0.1:8848");
|
properties.put(PropertyKeyConst.SERVER_ADDR, "127.0.0.1:8848");
|
||||||
|
|
||||||
maintainService = NacosFactory.createMaintainService(properties);
|
namingMaintainService = NacosFactory.createMaintainService(properties);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -50,7 +49,7 @@ public class NacosMaintainServiceTest {
|
|||||||
selector.setExpression("CONSUMER.label.A=PROVIDER.label.A &CONSUMER.label.B=PROVIDER.label.B");
|
selector.setExpression("CONSUMER.label.A=PROVIDER.label.A &CONSUMER.label.B=PROVIDER.label.B");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
maintainService.createService(service, new NoneSelector());
|
namingMaintainService.createService(service, new NoneSelector());
|
||||||
} catch (NacosException e) {
|
} catch (NacosException e) {
|
||||||
NAMING_LOGGER.error(e.getErrMsg());
|
NAMING_LOGGER.error(e.getErrMsg());
|
||||||
}
|
}
|
||||||
@ -67,7 +66,7 @@ public class NacosMaintainServiceTest {
|
|||||||
service.setMetadata(metadata);
|
service.setMetadata(metadata);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
maintainService.updateService(service, new NoneSelector());
|
namingMaintainService.updateService(service, new NoneSelector());
|
||||||
} catch (NacosException e) {
|
} catch (NacosException e) {
|
||||||
NAMING_LOGGER.error(e.getErrMsg());
|
NAMING_LOGGER.error(e.getErrMsg());
|
||||||
}
|
}
|
||||||
@ -76,7 +75,7 @@ public class NacosMaintainServiceTest {
|
|||||||
@Test
|
@Test
|
||||||
public void test3selectOneService() {
|
public void test3selectOneService() {
|
||||||
try {
|
try {
|
||||||
Service service = maintainService.queryService("nacos-api");
|
Service service = namingMaintainService.queryService("nacos-api");
|
||||||
System.out.println("service : " + service.toString());
|
System.out.println("service : " + service.toString());
|
||||||
} catch (NacosException e) {
|
} catch (NacosException e) {
|
||||||
NAMING_LOGGER.error(e.getErrMsg());
|
NAMING_LOGGER.error(e.getErrMsg());
|
||||||
@ -86,7 +85,7 @@ public class NacosMaintainServiceTest {
|
|||||||
@Test
|
@Test
|
||||||
public void test4deleteService() {
|
public void test4deleteService() {
|
||||||
try {
|
try {
|
||||||
Assert.assertTrue(maintainService.deleteService("nacos-api"));
|
Assert.assertTrue(namingMaintainService.deleteService("nacos-api"));
|
||||||
} catch (NacosException e) {
|
} catch (NacosException e) {
|
||||||
NAMING_LOGGER.error(e.getErrMsg());
|
NAMING_LOGGER.error(e.getErrMsg());
|
||||||
}
|
}
|
@ -18,8 +18,8 @@ package com.alibaba.nacos.test.naming;
|
|||||||
|
|
||||||
import com.alibaba.nacos.api.common.Constants;
|
import com.alibaba.nacos.api.common.Constants;
|
||||||
import com.alibaba.nacos.api.exception.NacosException;
|
import com.alibaba.nacos.api.exception.NacosException;
|
||||||
import com.alibaba.nacos.api.naming.MaintainFactory;
|
import com.alibaba.nacos.api.naming.NamingMaintainFactory;
|
||||||
import com.alibaba.nacos.api.naming.MaintainService;
|
import com.alibaba.nacos.api.naming.NamingMaintainService;
|
||||||
import com.alibaba.nacos.api.naming.NamingFactory;
|
import com.alibaba.nacos.api.naming.NamingFactory;
|
||||||
import com.alibaba.nacos.api.naming.NamingService;
|
import com.alibaba.nacos.api.naming.NamingService;
|
||||||
import com.alibaba.nacos.api.naming.pojo.Instance;
|
import com.alibaba.nacos.api.naming.pojo.Instance;
|
||||||
@ -47,9 +47,9 @@ import java.util.concurrent.TimeUnit;
|
|||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
@SpringBootTest(classes = NamingApp.class, properties = {"server.servlet.context-path=/nacos"},
|
@SpringBootTest(classes = NamingApp.class, properties = {"server.servlet.context-path=/nacos"},
|
||||||
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||||
public class MaintainService_ITCase {
|
public class NamingMaintainService_ITCase {
|
||||||
|
|
||||||
private MaintainService maintainService;
|
private NamingMaintainService namingMaintainService;
|
||||||
private NamingService namingService;
|
private NamingService namingService;
|
||||||
private Instance instance;
|
private Instance instance;
|
||||||
private Service service;
|
private Service service;
|
||||||
@ -62,9 +62,9 @@ public class MaintainService_ITCase {
|
|||||||
|
|
||||||
NamingBase.prepareServer(port);
|
NamingBase.prepareServer(port);
|
||||||
|
|
||||||
if (maintainService == null) {
|
if (namingMaintainService == null) {
|
||||||
TimeUnit.SECONDS.sleep(10);
|
TimeUnit.SECONDS.sleep(10);
|
||||||
maintainService = MaintainFactory.createMaintainService("127.0.0.1" + ":" + port);
|
namingMaintainService = NamingMaintainFactory.createMaintainService("127.0.0.1" + ":" + port);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (namingService == null) {
|
if (namingService == null) {
|
||||||
@ -98,7 +98,7 @@ public class MaintainService_ITCase {
|
|||||||
map.put("version", "2.0");
|
map.put("version", "2.0");
|
||||||
instance.setMetadata(map);
|
instance.setMetadata(map);
|
||||||
namingService.registerInstance("nacos-api", instance);
|
namingService.registerInstance("nacos-api", instance);
|
||||||
maintainService.updateInstance("nacos-api", instance);
|
namingMaintainService.updateInstance("nacos-api", instance);
|
||||||
List<Instance> instances = namingService.getAllInstances("nacos-api", true);
|
List<Instance> instances = namingService.getAllInstances("nacos-api", true);
|
||||||
|
|
||||||
Assert.assertEquals(instances.size(), 1);
|
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");
|
selector.setExpression("CONSUMER.label.A=PROVIDER.label.A &CONSUMER.label.B=PROVIDER.label.B");
|
||||||
|
|
||||||
System.out.println("service info : " + service);
|
System.out.println("service info : " + service);
|
||||||
maintainService.createService(service, selector);
|
namingMaintainService.createService(service, selector);
|
||||||
Service remoteService = maintainService.queryService("nacos-api");
|
Service remoteService = namingMaintainService.queryService("nacos-api");
|
||||||
System.out.println("remote service info : " + remoteService);
|
System.out.println("remote service info : " + remoteService);
|
||||||
Assert.assertEquals(service.toString(), remoteService.toString());
|
Assert.assertEquals(service.toString(), remoteService.toString());
|
||||||
}
|
}
|
||||||
@ -128,15 +128,15 @@ public class MaintainService_ITCase {
|
|||||||
metadata.put("nacos-1", "nacos-3-update");
|
metadata.put("nacos-1", "nacos-3-update");
|
||||||
service.setMetadata(metadata);
|
service.setMetadata(metadata);
|
||||||
|
|
||||||
maintainService.updateService(service, new NoneSelector());
|
namingMaintainService.updateService(service, new NoneSelector());
|
||||||
Service remoteService = maintainService.queryService("nacos-api");
|
Service remoteService = namingMaintainService.queryService("nacos-api");
|
||||||
System.out.println("remote service info : " + remoteService);
|
System.out.println("remote service info : " + remoteService);
|
||||||
Assert.assertEquals(service.toString(), remoteService.toString());
|
Assert.assertEquals(service.toString(), remoteService.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void deleteService() throws NacosException {
|
public void deleteService() throws NacosException {
|
||||||
Assert.assertTrue(maintainService.deleteService("nacos-api"));
|
Assert.assertTrue(namingMaintainService.deleteService("nacos-api"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
Loading…
Reference in New Issue
Block a user