use of org.apache.pulsar.common.policies.data.BrokerInfo in project pulsar by apache.
the class BrokersImpl method getLeaderBrokerAsync.
@Override
public CompletableFuture<BrokerInfo> getLeaderBrokerAsync() {
WebTarget path = adminBrokers.path("leaderBroker");
final CompletableFuture<BrokerInfo> future = new CompletableFuture<>();
asyncGetRequest(path, new InvocationCallback<BrokerInfo>() {
@Override
public void completed(BrokerInfo leaderBroker) {
future.complete(leaderBroker);
}
@Override
public void failed(Throwable throwable) {
future.completeExceptionally(getApiException(throwable.getCause()));
}
});
return future;
}
use of org.apache.pulsar.common.policies.data.BrokerInfo in project pulsar by yahoo.
the class AdminApiTest method brokers.
@Test
public void brokers() throws Exception {
List<String> list = admin.brokers().getActiveBrokers("test");
Assert.assertNotNull(list);
Assert.assertEquals(list.size(), 1);
List<String> list2 = otheradmin.brokers().getActiveBrokers("test");
Assert.assertNotNull(list2);
Assert.assertEquals(list2.size(), 1);
BrokerInfo leaderBroker = admin.brokers().getLeaderBroker();
Assert.assertEquals(leaderBroker.getServiceUrl(), pulsar.getLeaderElectionService().getCurrentLeader().map(LeaderBroker::getServiceUrl).get());
Map<String, NamespaceOwnershipStatus> nsMap = admin.brokers().getOwnedNamespaces("test", list.get(0));
// since sla-monitor ns is not created nsMap.size() == 1 (for HeartBeat Namespace)
Assert.assertEquals(nsMap.size(), 2);
for (String ns : nsMap.keySet()) {
NamespaceOwnershipStatus nsStatus = nsMap.get(ns);
if (ns.equals(NamespaceService.getHeartbeatNamespace(pulsar.getAdvertisedAddress(), pulsar.getConfiguration()) + "/0x00000000_0xffffffff")) {
assertEquals(nsStatus.broker_assignment, BrokerAssignment.shared);
assertFalse(nsStatus.is_controlled);
assertTrue(nsStatus.is_active);
}
}
String[] parts = list.get(0).split(":");
Assert.assertEquals(parts.length, 2);
Map<String, NamespaceOwnershipStatus> nsMap2 = adminTls.brokers().getOwnedNamespaces("test", String.format("%s:%d", parts[0], pulsar.getListenPortHTTPS().get()));
Assert.assertEquals(nsMap2.size(), 2);
admin.namespaces().deleteNamespace("prop-xyz/ns1");
admin.clusters().deleteCluster("test");
assertEquals(admin.clusters().getClusters(), Lists.newArrayList());
}
use of org.apache.pulsar.common.policies.data.BrokerInfo in project pulsar by yahoo.
the class AdminTest method brokers.
@Test
@SuppressWarnings("unchecked")
public void brokers() throws Exception {
asyncRequests(ctx -> clusters.createCluster(ctx, "use", ClusterDataImpl.builder().serviceUrl("http://broker.messaging.use.example.com").serviceUrlTls("https://broker.messaging.use.example.com:4443").build()));
URI requestUri = new URI("http://broker.messaging.use.example.com:8080/admin/brokers/use");
UriInfo mockUri = mock(UriInfo.class);
doReturn(requestUri).when(mockUri).getRequestUri();
Field uriField = PulsarWebResource.class.getDeclaredField("uri");
uriField.setAccessible(true);
uriField.set(brokers, mockUri);
Object res = asyncRequests(ctx -> brokers.getActiveBrokers(ctx, "use"));
assertTrue(res instanceof Set);
Set<String> activeBrokers = (Set<String>) res;
assertEquals(activeBrokers.size(), 1);
assertEquals(activeBrokers, Sets.newHashSet(pulsar.getAdvertisedAddress() + ":" + pulsar.getListenPortHTTP().get()));
Object leaderBrokerRes = asyncRequests(ctx -> brokers.getLeaderBroker(ctx));
assertTrue(leaderBrokerRes instanceof BrokerInfo);
BrokerInfo leaderBroker = (BrokerInfo) leaderBrokerRes;
assertEquals(leaderBroker.getServiceUrl(), pulsar.getLeaderElectionService().getCurrentLeader().map(LeaderBroker::getServiceUrl).get());
}
use of org.apache.pulsar.common.policies.data.BrokerInfo in project pulsar by yahoo.
the class BrokersImpl method getLeaderBrokerAsync.
@Override
public CompletableFuture<BrokerInfo> getLeaderBrokerAsync() {
WebTarget path = adminBrokers.path("leaderBroker");
final CompletableFuture<BrokerInfo> future = new CompletableFuture<>();
asyncGetRequest(path, new InvocationCallback<BrokerInfo>() {
@Override
public void completed(BrokerInfo leaderBroker) {
future.complete(leaderBroker);
}
@Override
public void failed(Throwable throwable) {
future.completeExceptionally(getApiException(throwable.getCause()));
}
});
return future;
}
use of org.apache.pulsar.common.policies.data.BrokerInfo in project incubator-pulsar by apache.
the class AdminApiTest method brokers.
@Test
public void brokers() throws Exception {
List<String> list = admin.brokers().getActiveBrokers("test");
Assert.assertNotNull(list);
Assert.assertEquals(list.size(), 1);
List<String> list2 = otheradmin.brokers().getActiveBrokers("test");
Assert.assertNotNull(list2);
Assert.assertEquals(list2.size(), 1);
BrokerInfo leaderBroker = admin.brokers().getLeaderBroker();
Assert.assertEquals(leaderBroker.getServiceUrl(), pulsar.getLeaderElectionService().getCurrentLeader().map(LeaderBroker::getServiceUrl).get());
Map<String, NamespaceOwnershipStatus> nsMap = admin.brokers().getOwnedNamespaces("test", list.get(0));
// since sla-monitor ns is not created nsMap.size() == 1 (for HeartBeat Namespace)
Assert.assertEquals(nsMap.size(), 2);
for (String ns : nsMap.keySet()) {
NamespaceOwnershipStatus nsStatus = nsMap.get(ns);
if (ns.equals(NamespaceService.getHeartbeatNamespace(pulsar.getAdvertisedAddress(), pulsar.getConfiguration()) + "/0x00000000_0xffffffff")) {
assertEquals(nsStatus.broker_assignment, BrokerAssignment.shared);
assertFalse(nsStatus.is_controlled);
assertTrue(nsStatus.is_active);
}
}
String[] parts = list.get(0).split(":");
Assert.assertEquals(parts.length, 2);
Map<String, NamespaceOwnershipStatus> nsMap2 = adminTls.brokers().getOwnedNamespaces("test", String.format("%s:%d", parts[0], pulsar.getListenPortHTTPS().get()));
Assert.assertEquals(nsMap2.size(), 2);
admin.namespaces().deleteNamespace("prop-xyz/ns1");
admin.clusters().deleteCluster("test");
assertEquals(admin.clusters().getClusters(), Lists.newArrayList());
}
Aggregations