Search in sources :

Example 1 with BrokerNamespaceIsolationDataImpl

use of org.apache.pulsar.common.policies.data.BrokerNamespaceIsolationDataImpl in project pulsar by apache.

the class ClustersImpl method getBrokersWithNamespaceIsolationPolicyAsync.

@Override
public CompletableFuture<List<BrokerNamespaceIsolationData>> getBrokersWithNamespaceIsolationPolicyAsync(String cluster) {
    WebTarget path = adminClusters.path(cluster).path("namespaceIsolationPolicies").path("brokers");
    final CompletableFuture<List<BrokerNamespaceIsolationData>> future = new CompletableFuture<>();
    asyncGetRequest(path, new InvocationCallback<List<BrokerNamespaceIsolationDataImpl>>() {

        @Override
        public void completed(List<BrokerNamespaceIsolationDataImpl> brokerNamespaceIsolationData) {
            List<BrokerNamespaceIsolationData> data = new ArrayList<>(brokerNamespaceIsolationData);
            future.complete(data);
        }

        @Override
        public void failed(Throwable throwable) {
            future.completeExceptionally(getApiException(throwable.getCause()));
        }
    });
    return future;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) BrokerNamespaceIsolationDataImpl(org.apache.pulsar.common.policies.data.BrokerNamespaceIsolationDataImpl) ArrayList(java.util.ArrayList) List(java.util.List) WebTarget(javax.ws.rs.client.WebTarget)

Example 2 with BrokerNamespaceIsolationDataImpl

use of org.apache.pulsar.common.policies.data.BrokerNamespaceIsolationDataImpl in project pulsar by apache.

the class ClustersImpl method getBrokerWithNamespaceIsolationPolicyAsync.

@Override
public CompletableFuture<BrokerNamespaceIsolationData> getBrokerWithNamespaceIsolationPolicyAsync(String cluster, String broker) {
    WebTarget path = adminClusters.path(cluster).path("namespaceIsolationPolicies").path("brokers").path(broker);
    final CompletableFuture<BrokerNamespaceIsolationData> future = new CompletableFuture<>();
    asyncGetRequest(path, new InvocationCallback<BrokerNamespaceIsolationDataImpl>() {

        @Override
        public void completed(BrokerNamespaceIsolationDataImpl brokerNamespaceIsolationData) {
            future.complete(brokerNamespaceIsolationData);
        }

        @Override
        public void failed(Throwable throwable) {
            future.completeExceptionally(getApiException(throwable.getCause()));
        }
    });
    return future;
}
Also used : BrokerNamespaceIsolationData(org.apache.pulsar.common.policies.data.BrokerNamespaceIsolationData) CompletableFuture(java.util.concurrent.CompletableFuture) BrokerNamespaceIsolationDataImpl(org.apache.pulsar.common.policies.data.BrokerNamespaceIsolationDataImpl) WebTarget(javax.ws.rs.client.WebTarget)

Example 3 with BrokerNamespaceIsolationDataImpl

use of org.apache.pulsar.common.policies.data.BrokerNamespaceIsolationDataImpl in project pulsar by yahoo.

the class ClustersImpl method getBrokerWithNamespaceIsolationPolicyAsync.

@Override
public CompletableFuture<BrokerNamespaceIsolationData> getBrokerWithNamespaceIsolationPolicyAsync(String cluster, String broker) {
    WebTarget path = adminClusters.path(cluster).path("namespaceIsolationPolicies").path("brokers").path(broker);
    final CompletableFuture<BrokerNamespaceIsolationData> future = new CompletableFuture<>();
    asyncGetRequest(path, new InvocationCallback<BrokerNamespaceIsolationDataImpl>() {

        @Override
        public void completed(BrokerNamespaceIsolationDataImpl brokerNamespaceIsolationData) {
            future.complete(brokerNamespaceIsolationData);
        }

        @Override
        public void failed(Throwable throwable) {
            future.completeExceptionally(getApiException(throwable.getCause()));
        }
    });
    return future;
}
Also used : BrokerNamespaceIsolationData(org.apache.pulsar.common.policies.data.BrokerNamespaceIsolationData) CompletableFuture(java.util.concurrent.CompletableFuture) BrokerNamespaceIsolationDataImpl(org.apache.pulsar.common.policies.data.BrokerNamespaceIsolationDataImpl) WebTarget(javax.ws.rs.client.WebTarget)

Example 4 with BrokerNamespaceIsolationDataImpl

use of org.apache.pulsar.common.policies.data.BrokerNamespaceIsolationDataImpl in project incubator-pulsar by apache.

the class AdminApi2Test method brokerNamespaceIsolationPolicies.

@Test
public void brokerNamespaceIsolationPolicies() throws Exception {
    // create
    String policyName1 = "policy-1";
    String cluster = pulsar.getConfiguration().getClusterName();
    String namespaceRegex = "other/" + cluster + "/other.*";
    String brokerName = pulsar.getAdvertisedAddress();
    String brokerAddress = brokerName + ":" + pulsar.getConfiguration().getWebServicePort().get();
    Map<String, String> parameters1 = new HashMap<>();
    parameters1.put("min_limit", "1");
    parameters1.put("usage_threshold", "100");
    NamespaceIsolationData nsPolicyData1 = NamespaceIsolationData.builder().namespaces(Collections.singletonList(namespaceRegex)).primary(Collections.singletonList(brokerName + ":[0-9]*")).secondary(Collections.singletonList(brokerName + ".*")).autoFailoverPolicy(AutoFailoverPolicyData.builder().policyType(AutoFailoverPolicyType.min_available).parameters(parameters1).build()).build();
    admin.clusters().createNamespaceIsolationPolicy(cluster, policyName1, nsPolicyData1);
    List<BrokerNamespaceIsolationData> brokerIsolationDataList = admin.clusters().getBrokersWithNamespaceIsolationPolicy(cluster);
    assertEquals(brokerIsolationDataList.size(), 1);
    assertEquals(brokerIsolationDataList.get(0).getBrokerName(), brokerAddress);
    assertEquals(brokerIsolationDataList.get(0).getNamespaceRegex().size(), 1);
    assertEquals(brokerIsolationDataList.get(0).getNamespaceRegex().get(0), namespaceRegex);
    assertEquals(brokerIsolationDataList.get(0).getPolicyName(), policyName1);
    BrokerNamespaceIsolationDataImpl brokerIsolationData = (BrokerNamespaceIsolationDataImpl) admin.clusters().getBrokerWithNamespaceIsolationPolicy(cluster, brokerAddress);
    assertEquals(brokerIsolationData.getBrokerName(), brokerAddress);
    assertEquals(brokerIsolationData.getNamespaceRegex().size(), 1);
    assertEquals(brokerIsolationData.getNamespaceRegex().get(0), namespaceRegex);
    BrokerNamespaceIsolationDataImpl isolationData = (BrokerNamespaceIsolationDataImpl) admin.clusters().getBrokerWithNamespaceIsolationPolicy(cluster, "invalid-broker");
    assertFalse(isolationData.isPrimary());
}
Also used : BrokerNamespaceIsolationData(org.apache.pulsar.common.policies.data.BrokerNamespaceIsolationData) BrokerNamespaceIsolationDataImpl(org.apache.pulsar.common.policies.data.BrokerNamespaceIsolationDataImpl) HashMap(java.util.HashMap) BrokerNamespaceIsolationData(org.apache.pulsar.common.policies.data.BrokerNamespaceIsolationData) NamespaceIsolationData(org.apache.pulsar.common.policies.data.NamespaceIsolationData) Test(org.testng.annotations.Test) MockedPulsarServiceBaseTest(org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest)

Example 5 with BrokerNamespaceIsolationDataImpl

use of org.apache.pulsar.common.policies.data.BrokerNamespaceIsolationDataImpl in project incubator-pulsar by apache.

the class ClustersImpl method getBrokerWithNamespaceIsolationPolicyAsync.

@Override
public CompletableFuture<BrokerNamespaceIsolationData> getBrokerWithNamespaceIsolationPolicyAsync(String cluster, String broker) {
    WebTarget path = adminClusters.path(cluster).path("namespaceIsolationPolicies").path("brokers").path(broker);
    final CompletableFuture<BrokerNamespaceIsolationData> future = new CompletableFuture<>();
    asyncGetRequest(path, new InvocationCallback<BrokerNamespaceIsolationDataImpl>() {

        @Override
        public void completed(BrokerNamespaceIsolationDataImpl brokerNamespaceIsolationData) {
            future.complete(brokerNamespaceIsolationData);
        }

        @Override
        public void failed(Throwable throwable) {
            future.completeExceptionally(getApiException(throwable.getCause()));
        }
    });
    return future;
}
Also used : BrokerNamespaceIsolationData(org.apache.pulsar.common.policies.data.BrokerNamespaceIsolationData) CompletableFuture(java.util.concurrent.CompletableFuture) BrokerNamespaceIsolationDataImpl(org.apache.pulsar.common.policies.data.BrokerNamespaceIsolationDataImpl) WebTarget(javax.ws.rs.client.WebTarget)

Aggregations

BrokerNamespaceIsolationDataImpl (org.apache.pulsar.common.policies.data.BrokerNamespaceIsolationDataImpl)9 CompletableFuture (java.util.concurrent.CompletableFuture)6 WebTarget (javax.ws.rs.client.WebTarget)6 BrokerNamespaceIsolationData (org.apache.pulsar.common.policies.data.BrokerNamespaceIsolationData)6 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 List (java.util.List)3 MockedPulsarServiceBaseTest (org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest)3 NamespaceIsolationData (org.apache.pulsar.common.policies.data.NamespaceIsolationData)3 Test (org.testng.annotations.Test)3