Search in sources :

Example 16 with Service

use of com.alibaba.nacos.api.naming.pojo.Service in project nacos by alibaba.

the class NacosNamingMaintainService method updateService.

@Override
public void updateService(String serviceName, String groupName, float protectThreshold) throws NacosException {
    Service service = new Service();
    service.setName(serviceName);
    service.setGroupName(groupName);
    service.setProtectThreshold(protectThreshold);
    updateService(service, new NoneSelector());
}
Also used : NamingMaintainService(com.alibaba.nacos.api.naming.NamingMaintainService) Service(com.alibaba.nacos.api.naming.pojo.Service) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) NoneSelector(com.alibaba.nacos.api.selector.NoneSelector)

Example 17 with Service

use of com.alibaba.nacos.api.naming.pojo.Service in project nacos by alibaba.

the class AbstractNamingClientProxyTest method testGetSecurityHeaders.

@Test
public void testGetSecurityHeaders() {
    SecurityProxy sc = Mockito.mock(SecurityProxy.class);
    Properties props = new Properties();
    AbstractNamingClientProxy proxy = new AbstractNamingClientProxy(sc, props) {

        @Override
        public void onEvent(ServerListChangedEvent event) {
        }

        @Override
        public Class<? extends Event> subscribeType() {
            return ServerListChangedEvent.class;
        }

        @Override
        public void registerService(String serviceName, String groupName, Instance instance) throws NacosException {
        }

        @Override
        public void deregisterService(String serviceName, String groupName, Instance instance) throws NacosException {
        }

        @Override
        public void updateInstance(String serviceName, String groupName, Instance instance) throws NacosException {
        }

        @Override
        public ServiceInfo queryInstancesOfService(String serviceName, String groupName, String clusters, int udpPort, boolean healthyOnly) throws NacosException {
            return null;
        }

        @Override
        public Service queryService(String serviceName, String groupName) throws NacosException {
            return null;
        }

        @Override
        public void createService(Service service, AbstractSelector selector) throws NacosException {
        }

        @Override
        public boolean deleteService(String serviceName, String groupName) throws NacosException {
            return false;
        }

        @Override
        public void updateService(Service service, AbstractSelector selector) throws NacosException {
        }

        @Override
        public ListView<String> getServiceList(int pageNo, int pageSize, String groupName, AbstractSelector selector) throws NacosException {
            return null;
        }

        @Override
        public ServiceInfo subscribe(String serviceName, String groupName, String clusters) throws NacosException {
            return null;
        }

        @Override
        public void unsubscribe(String serviceName, String groupName, String clusters) throws NacosException {
        }

        @Override
        public boolean isSubscribed(String serviceName, String groupName, String clusters) throws NacosException {
            return false;
        }

        @Override
        public void updateBeatInfo(Set<Instance> modifiedInstances) {
        }

        @Override
        public boolean serverHealthy() {
            return false;
        }

        @Override
        public void shutdown() throws NacosException {
        }
    };
    String token = "aa";
    Mockito.when(sc.getAccessToken()).thenReturn(token);
    Map<String, String> securityHeaders = proxy.getSecurityHeaders();
    Assert.assertEquals(1, securityHeaders.size());
    Assert.assertEquals(token, securityHeaders.get(Constants.ACCESS_TOKEN));
}
Also used : ServerListChangedEvent(com.alibaba.nacos.client.naming.event.ServerListChangedEvent) Set(java.util.Set) AbstractSelector(com.alibaba.nacos.api.selector.AbstractSelector) Instance(com.alibaba.nacos.api.naming.pojo.Instance) Service(com.alibaba.nacos.api.naming.pojo.Service) SecurityProxy(com.alibaba.nacos.client.security.SecurityProxy) Properties(java.util.Properties) Test(org.junit.Test)

Example 18 with Service

use of com.alibaba.nacos.api.naming.pojo.Service in project nacos by alibaba.

the class AbstractNamingClientProxyTest method testGetSpasHeaders.

@Test
public void testGetSpasHeaders() throws Exception {
    SecurityProxy sc = Mockito.mock(SecurityProxy.class);
    Properties props = new Properties();
    String ak = "aa";
    String sk = "bb";
    props.put(PropertyKeyConst.ACCESS_KEY, ak);
    props.put(PropertyKeyConst.SECRET_KEY, sk);
    AbstractNamingClientProxy proxy = new AbstractNamingClientProxy(sc, props) {

        @Override
        public void onEvent(ServerListChangedEvent event) {
        }

        @Override
        public Class<? extends Event> subscribeType() {
            return ServerListChangedEvent.class;
        }

        @Override
        public void registerService(String serviceName, String groupName, Instance instance) throws NacosException {
        }

        @Override
        public void deregisterService(String serviceName, String groupName, Instance instance) throws NacosException {
        }

        @Override
        public void updateInstance(String serviceName, String groupName, Instance instance) throws NacosException {
        }

        @Override
        public ServiceInfo queryInstancesOfService(String serviceName, String groupName, String clusters, int udpPort, boolean healthyOnly) throws NacosException {
            return null;
        }

        @Override
        public Service queryService(String serviceName, String groupName) throws NacosException {
            return null;
        }

        @Override
        public void createService(Service service, AbstractSelector selector) throws NacosException {
        }

        @Override
        public boolean deleteService(String serviceName, String groupName) throws NacosException {
            return false;
        }

        @Override
        public void updateService(Service service, AbstractSelector selector) throws NacosException {
        }

        @Override
        public ListView<String> getServiceList(int pageNo, int pageSize, String groupName, AbstractSelector selector) throws NacosException {
            return null;
        }

        @Override
        public ServiceInfo subscribe(String serviceName, String groupName, String clusters) throws NacosException {
            return null;
        }

        @Override
        public void unsubscribe(String serviceName, String groupName, String clusters) throws NacosException {
        }

        @Override
        public boolean isSubscribed(String serviceName, String groupName, String clusters) throws NacosException {
            return false;
        }

        @Override
        public void updateBeatInfo(Set<Instance> modifiedInstances) {
        }

        @Override
        public boolean serverHealthy() {
            return false;
        }

        @Override
        public void shutdown() throws NacosException {
        }
    };
    String serviceName = "aaa";
    Map<String, String> spasHeaders = proxy.getSpasHeaders(serviceName);
    Assert.assertEquals(4, spasHeaders.size());
    Assert.assertEquals(AppNameUtils.getAppName(), spasHeaders.get("app"));
    Assert.assertEquals(ak, spasHeaders.get("ak"));
    Assert.assertTrue(spasHeaders.get("data").endsWith("@@" + serviceName));
    String expectSign = SignUtil.sign(spasHeaders.get("data"), sk);
    Assert.assertEquals(expectSign, spasHeaders.get("signature"));
}
Also used : ServerListChangedEvent(com.alibaba.nacos.client.naming.event.ServerListChangedEvent) Set(java.util.Set) AbstractSelector(com.alibaba.nacos.api.selector.AbstractSelector) Instance(com.alibaba.nacos.api.naming.pojo.Instance) Service(com.alibaba.nacos.api.naming.pojo.Service) SecurityProxy(com.alibaba.nacos.client.security.SecurityProxy) Properties(java.util.Properties) Test(org.junit.Test)

Aggregations

Service (com.alibaba.nacos.api.naming.pojo.Service)18 Test (org.junit.Test)15 NoneSelector (com.alibaba.nacos.api.selector.NoneSelector)11 Properties (java.util.Properties)8 AbstractSelector (com.alibaba.nacos.api.selector.AbstractSelector)6 ServiceInfoHolder (com.alibaba.nacos.client.naming.cache.ServiceInfoHolder)6 NamingMaintainService (com.alibaba.nacos.api.naming.NamingMaintainService)5 SecurityProxy (com.alibaba.nacos.client.security.SecurityProxy)5 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)5 ExpressionSelector (com.alibaba.nacos.api.selector.ExpressionSelector)3 ServerListManager (com.alibaba.nacos.client.naming.core.ServerListManager)3 InstancesChangeNotifier (com.alibaba.nacos.client.naming.event.InstancesChangeNotifier)3 NamingGrpcRedoService (com.alibaba.nacos.client.naming.remote.gprc.redo.NamingGrpcRedoService)3 HttpRestResult (com.alibaba.nacos.common.http.HttpRestResult)3 NacosRestTemplate (com.alibaba.nacos.common.http.client.NacosRestTemplate)3 Field (java.lang.reflect.Field)3 NacosException (com.alibaba.nacos.api.exception.NacosException)2 NamingService (com.alibaba.nacos.api.naming.NamingService)2 Instance (com.alibaba.nacos.api.naming.pojo.Instance)2 ServerListChangedEvent (com.alibaba.nacos.client.naming.event.ServerListChangedEvent)2