use of com.alibaba.nacos.naming.pojo.Subscriber in project nacos by alibaba.
the class NamingSubscriberServiceV1ImplTest method testGetSubscribersWithServiceParam.
@Test
public void testGetSubscribersWithServiceParam() {
Service service = Service.newService("1", "G1", "S1");
Collection<Subscriber> actual = namingSubscriberService.getSubscribers(service);
assertEquals(1, actual.size());
assertSubscriber("1", "G1@@S1", actual.iterator().next());
}
use of com.alibaba.nacos.naming.pojo.Subscriber in project nacos by alibaba.
the class NamingSubscriberServiceV1ImplTest method testGetFuzzySubscribersWithServiceParam.
@Test
public void testGetFuzzySubscribersWithServiceParam() {
Service service = Service.newService("1", "G", "S");
Collection<Subscriber> actual = namingSubscriberService.getFuzzySubscribers(service);
assertEquals(2, actual.size());
assertSubscriber("1", "DEFAULT_GROUP@@S2", actual.iterator().next());
}
use of com.alibaba.nacos.naming.pojo.Subscriber in project nacos by alibaba.
the class InstanceController method list.
/**
* Get all instance of input service.
*
* @param request http request
* @return list of instance
* @throws Exception any error during list
*/
@GetMapping("/list")
@Secured(action = ActionTypes.READ)
public Object list(HttpServletRequest request) throws Exception {
String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID, Constants.DEFAULT_NAMESPACE_ID);
String serviceName = WebUtils.required(request, CommonParams.SERVICE_NAME);
NamingUtils.checkServiceNameFormat(serviceName);
String agent = WebUtils.getUserAgent(request);
String clusters = WebUtils.optional(request, "clusters", StringUtils.EMPTY);
String clientIP = WebUtils.optional(request, "clientIP", StringUtils.EMPTY);
int udpPort = Integer.parseInt(WebUtils.optional(request, "udpPort", "0"));
boolean healthyOnly = Boolean.parseBoolean(WebUtils.optional(request, "healthyOnly", "false"));
String app = WebUtils.optional(request, "app", StringUtils.EMPTY);
Subscriber subscriber = new Subscriber(clientIP + ":" + udpPort, agent, app, clientIP, namespaceId, serviceName, udpPort, clusters);
return getInstanceOperator().listInstance(namespaceId, serviceName, subscriber, clusters, healthyOnly);
}
use of com.alibaba.nacos.naming.pojo.Subscriber in project nacos by alibaba.
the class NamingSubscriberServiceV1Impl method getFuzzySubscribers.
@Override
public Collection<Subscriber> getFuzzySubscribers(String namespaceId, String serviceName) {
Collection<Subscriber> result = new ArrayList<>();
clientMap.forEach((outKey, clientConcurrentMap) -> {
// get groupedName from key
String serviceFullName = outKey.split(UtilsAndCommons.NAMESPACE_SERVICE_CONNECTOR)[1];
// get groupName
String groupName = NamingUtils.getGroupName(serviceFullName);
// get serviceName
String name = NamingUtils.getServiceName(serviceFullName);
// fuzzy match
if (outKey.startsWith(namespaceId) && name.indexOf(NamingUtils.getServiceName(serviceName)) >= 0 && groupName.indexOf(NamingUtils.getGroupName(serviceName)) >= 0) {
clientConcurrentMap.forEach((key, client) -> {
result.add(new Subscriber(client.getAddrStr(), client.getAgent(), client.getApp(), client.getIp(), namespaceId, serviceFullName, client.getPort()));
});
}
});
return result;
}
use of com.alibaba.nacos.naming.pojo.Subscriber in project nacos by alibaba.
the class SubscribeManagerTest method getSubscribersWithTrue.
@Test
public void getSubscribersWithTrue() {
String serviceName = "testGroupName@@test_subscriber";
String namespaceId = "public";
boolean aggregation = Boolean.TRUE;
try {
List<Subscriber> clients = new ArrayList<>();
Subscriber subscriber = new Subscriber("127.0.0.1:8080", "test", "app", "127.0.0.1", namespaceId, serviceName, 0);
clients.add(subscriber);
Mockito.when(this.aggregation.getFuzzySubscribers(Mockito.anyString(), Mockito.anyString())).thenReturn(clients);
List<Subscriber> list = subscribeManager.getSubscribers(serviceName, namespaceId, aggregation);
Assert.assertNotNull(list);
Assert.assertEquals(1, list.size());
Assert.assertEquals("testGroupName@@test_subscriber", list.get(0).getServiceName());
Assert.assertEquals("public", list.get(0).getNamespaceId());
} catch (Exception ignored) {
}
}
Aggregations