use of com.alibaba.nacos.naming.pojo.Subscriber in project nacos by alibaba.
the class NamingSubscriberServiceAggregationImplTest method setUp.
@Before
public void setUp() throws Exception {
aggregation = new NamingSubscriberServiceAggregationImpl(local, memberManager);
Subscriber subscriber = new Subscriber("local", "", "", "", namespace, serviceName, 0);
when(local.getSubscribers(namespace, serviceName)).thenReturn(Collections.singletonList(subscriber));
when(local.getSubscribers(service)).thenReturn(Collections.singletonList(subscriber));
when(local.getFuzzySubscribers(namespace, serviceName)).thenReturn(Collections.singletonList(subscriber));
when(local.getFuzzySubscribers(service)).thenReturn(Collections.singletonList(subscriber));
members = new HashMap<>();
members.put("1", Mockito.mock(Member.class));
when(memberManager.getServerList()).thenReturn(members);
}
use of com.alibaba.nacos.naming.pojo.Subscriber in project nacos by alibaba.
the class ServiceController method subscribers.
/**
* get subscriber list.
*
* @param request http request
* @return Jackson object node
*/
@GetMapping("/subscribers")
@Secured(action = ActionTypes.READ)
public ObjectNode subscribers(HttpServletRequest request) {
int pageNo = NumberUtils.toInt(WebUtils.optional(request, "pageNo", "1"));
int pageSize = NumberUtils.toInt(WebUtils.optional(request, "pageSize", "1000"));
String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID, Constants.DEFAULT_NAMESPACE_ID);
String serviceName = WebUtils.required(request, CommonParams.SERVICE_NAME);
boolean aggregation = Boolean.parseBoolean(WebUtils.optional(request, "aggregation", String.valueOf(Boolean.TRUE)));
ObjectNode result = JacksonUtils.createEmptyJsonNode();
int count = 0;
try {
List<Subscriber> subscribers = subscribeManager.getSubscribers(serviceName, namespaceId, aggregation);
int start = (pageNo - 1) * pageSize;
if (start < 0) {
start = 0;
}
int end = start + pageSize;
count = subscribers.size();
if (end > count) {
end = count;
}
result.replace("subscribers", JacksonUtils.transferToJsonNode(subscribers.subList(start, end)));
result.put("count", count);
return result;
} catch (Exception e) {
Loggers.SRV_LOG.warn("query subscribers failed!", e);
result.replace("subscribers", JacksonUtils.createEmptyArrayNode());
result.put("count", count);
return result;
}
}
use of com.alibaba.nacos.naming.pojo.Subscriber in project nacos by alibaba.
the class UpgradeOpsController method listInstance.
/**
* Get all instance of input service.
*
* @param request http request
* @return list of instance
* @throws Exception any error during list
*/
@GetMapping("/instance/list")
@Secured(action = ActionTypes.READ)
public Object listInstance(@RequestParam(defaultValue = "v2", required = false) String ver, 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"));
boolean isCheck = Boolean.parseBoolean(WebUtils.optional(request, "isCheck", "false"));
String app = WebUtils.optional(request, "app", StringUtils.EMPTY);
String env = WebUtils.optional(request, "env", StringUtils.EMPTY);
String tenant = WebUtils.optional(request, "tid", StringUtils.EMPTY);
Subscriber subscriber = new Subscriber(clientIP + ":" + udpPort, agent, app, clientIP, namespaceId, serviceName, udpPort, clusters);
return getInstanceOperator(ver).listInstance(namespaceId, serviceName, subscriber, clusters, healthyOnly);
}
use of com.alibaba.nacos.naming.pojo.Subscriber in project nacos by alibaba.
the class SubscribeManagerTest method getSubscribersWithFalse.
@Test
public void getSubscribersWithFalse() {
String serviceName = "test";
String namespaceId = "public";
boolean aggregation = Boolean.FALSE;
try {
List<Subscriber> clients = new ArrayList<Subscriber>();
Subscriber subscriber = new Subscriber("127.0.0.1:8080", "test", "app", "127.0.0.1", namespaceId, serviceName, 0);
clients.add(subscriber);
Mockito.when(this.local.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("public", list.get(0).getNamespaceId());
} catch (Exception ignored) {
}
}
use of com.alibaba.nacos.naming.pojo.Subscriber in project nacos by alibaba.
the class SubscribeManagerTest method testGetSubscribersFuzzy.
@Test
public void testGetSubscribersFuzzy() {
String serviceName = "test";
String namespaceId = "public";
boolean aggregation = Boolean.TRUE;
try {
List<Subscriber> clients = new ArrayList<Subscriber>();
Subscriber subscriber = new Subscriber("127.0.0.1:8080", "test", "app", "127.0.0.1", namespaceId, "testGroupName@@test_subscriber", 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());
} catch (Exception ignored) {
}
}
Aggregations