Search in sources :

Example 1 with BrokerInfo

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;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) WebTarget(javax.ws.rs.client.WebTarget) BrokerInfo(org.apache.pulsar.common.policies.data.BrokerInfo)

Example 2 with BrokerInfo

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());
}
Also used : NamespaceOwnershipStatus(org.apache.pulsar.common.policies.data.NamespaceOwnershipStatus) LeaderBroker(org.apache.pulsar.broker.loadbalance.LeaderBroker) BrokerInfo(org.apache.pulsar.common.policies.data.BrokerInfo) Test(org.testng.annotations.Test) MockedPulsarServiceBaseTest(org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest)

Example 3 with BrokerInfo

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());
}
Also used : Field(java.lang.reflect.Field) Set(java.util.Set) LeaderBroker(org.apache.pulsar.broker.loadbalance.LeaderBroker) URI(java.net.URI) UriInfo(javax.ws.rs.core.UriInfo) BrokerInfo(org.apache.pulsar.common.policies.data.BrokerInfo) Test(org.testng.annotations.Test) MockedPulsarServiceBaseTest(org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest)

Example 4 with BrokerInfo

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;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) WebTarget(javax.ws.rs.client.WebTarget) BrokerInfo(org.apache.pulsar.common.policies.data.BrokerInfo)

Example 5 with BrokerInfo

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());
}
Also used : NamespaceOwnershipStatus(org.apache.pulsar.common.policies.data.NamespaceOwnershipStatus) LeaderBroker(org.apache.pulsar.broker.loadbalance.LeaderBroker) BrokerInfo(org.apache.pulsar.common.policies.data.BrokerInfo) Test(org.testng.annotations.Test) MockedPulsarServiceBaseTest(org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest)

Aggregations

BrokerInfo (org.apache.pulsar.common.policies.data.BrokerInfo)9 MockedPulsarServiceBaseTest (org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest)6 LeaderBroker (org.apache.pulsar.broker.loadbalance.LeaderBroker)6 Test (org.testng.annotations.Test)6 Field (java.lang.reflect.Field)3 URI (java.net.URI)3 Set (java.util.Set)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 WebTarget (javax.ws.rs.client.WebTarget)3 UriInfo (javax.ws.rs.core.UriInfo)3 NamespaceOwnershipStatus (org.apache.pulsar.common.policies.data.NamespaceOwnershipStatus)3