Search in sources :

Example 1 with ClusterResources

use of org.apache.pulsar.broker.resources.ClusterResources in project pulsar by yahoo.

the class PulsarStandalone method createNameSpace.

@VisibleForTesting
void createNameSpace(String cluster, String publicTenant, NamespaceName ns) throws Exception {
    ClusterResources cr = broker.getPulsarResources().getClusterResources();
    TenantResources tr = broker.getPulsarResources().getTenantResources();
    NamespaceResources nsr = broker.getPulsarResources().getNamespaceResources();
    if (!cr.clusterExists(cluster)) {
        cr.createCluster(cluster, ClusterData.builder().serviceUrl(broker.getWebServiceAddress()).serviceUrlTls(broker.getWebServiceAddressTls()).brokerServiceUrl(broker.getBrokerServiceUrl()).brokerServiceUrlTls(broker.getBrokerServiceUrlTls()).build());
    }
    if (!tr.tenantExists(publicTenant)) {
        tr.createTenant(publicTenant, TenantInfo.builder().adminRoles(Sets.newHashSet(config.getSuperUserRoles())).allowedClusters(Sets.newHashSet(cluster)).build());
    }
    if (!nsr.namespaceExists(ns)) {
        Policies nsp = new Policies();
        nsp.replication_clusters = Collections.singleton(config.getClusterName());
        nsr.createPolicies(ns, nsp);
    }
}
Also used : NamespaceResources(org.apache.pulsar.broker.resources.NamespaceResources) Policies(org.apache.pulsar.common.policies.data.Policies) ClusterResources(org.apache.pulsar.broker.resources.ClusterResources) TenantResources(org.apache.pulsar.broker.resources.TenantResources) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 2 with ClusterResources

use of org.apache.pulsar.broker.resources.ClusterResources in project pulsar by yahoo.

the class PulsarStandaloneTest method testCreateNameSpace.

@Test
public void testCreateNameSpace() throws Exception {
    final String cluster = "cluster1";
    final String tenant = "tenant1";
    final NamespaceName ns = NamespaceName.get(tenant, "ns1");
    ClusterResources cr = mock(ClusterResources.class);
    when(cr.clusterExists(cluster)).thenReturn(false).thenReturn(true);
    doNothing().when(cr).createCluster(eq(cluster), any());
    TenantResources tr = mock(TenantResources.class);
    when(tr.tenantExists(tenant)).thenReturn(false).thenReturn(true);
    doNothing().when(tr).createTenant(eq(tenant), any());
    NamespaceResources nsr = mock(NamespaceResources.class);
    when(nsr.namespaceExists(ns)).thenReturn(false).thenReturn(true);
    doNothing().when(nsr).createPolicies(eq(ns), any());
    PulsarResources resources = mock(PulsarResources.class);
    when(resources.getClusterResources()).thenReturn(cr);
    when(resources.getTenantResources()).thenReturn(tr);
    when(resources.getNamespaceResources()).thenReturn(nsr);
    PulsarService broker = mock(PulsarService.class);
    when(broker.getPulsarResources()).thenReturn(resources);
    when(broker.getWebServiceAddress()).thenReturn("pulsar://localhost:8080");
    when(broker.getWebServiceAddressTls()).thenReturn(null);
    when(broker.getBrokerServiceUrl()).thenReturn("pulsar://localhost:6650");
    when(broker.getBrokerServiceUrlTls()).thenReturn(null);
    ServiceConfiguration config = new ServiceConfiguration();
    config.setClusterName(cluster);
    PulsarStandalone standalone = new PulsarStandalone();
    standalone.setBroker(broker);
    standalone.setConfig(config);
    standalone.createNameSpace(cluster, tenant, ns);
    standalone.createNameSpace(cluster, tenant, ns);
    verify(cr, times(1)).createCluster(eq(cluster), any());
    verify(tr, times(1)).createTenant(eq(tenant), any());
    verify(nsr, times(1)).createPolicies(eq(ns), any());
}
Also used : NamespaceResources(org.apache.pulsar.broker.resources.NamespaceResources) NamespaceName(org.apache.pulsar.common.naming.NamespaceName) PulsarService(org.apache.pulsar.broker.PulsarService) ServiceConfiguration(org.apache.pulsar.broker.ServiceConfiguration) PulsarResources(org.apache.pulsar.broker.resources.PulsarResources) ClusterResources(org.apache.pulsar.broker.resources.ClusterResources) TenantResources(org.apache.pulsar.broker.resources.TenantResources) Test(org.testng.annotations.Test)

Example 3 with ClusterResources

use of org.apache.pulsar.broker.resources.ClusterResources in project incubator-pulsar by apache.

the class HttpTopicLookupv2Test method setUp.

@SuppressWarnings("unchecked")
@BeforeMethod
public void setUp() throws Exception {
    pulsar = mock(PulsarService.class);
    ns = mock(NamespaceService.class);
    auth = mock(AuthorizationService.class);
    config = spy(ServiceConfiguration.class);
    config.setClusterName("use");
    clusters = new TreeSet<>();
    clusters.add("use");
    clusters.add("usc");
    clusters.add("usw");
    ClusterData useData = ClusterData.builder().serviceUrl("http://broker.messaging.use.example.com:8080").build();
    ClusterData uscData = ClusterData.builder().serviceUrl("http://broker.messaging.usc.example.com:8080").build();
    ClusterData uswData = ClusterData.builder().serviceUrl("http://broker.messaging.usw.example.com:8080").build();
    doReturn(config).when(pulsar).getConfiguration();
    ClusterResources clusters = mock(ClusterResources.class);
    when(clusters.getClusterAsync("use")).thenReturn(CompletableFuture.completedFuture(Optional.of(useData)));
    when(clusters.getClusterAsync("usc")).thenReturn(CompletableFuture.completedFuture(Optional.of(uscData)));
    when(clusters.getClusterAsync("usw")).thenReturn(CompletableFuture.completedFuture(Optional.of(uswData)));
    PulsarResources resources = mock(PulsarResources.class);
    namespaceResources = mock(NamespaceResources.class);
    when(resources.getClusterResources()).thenReturn(clusters);
    when(pulsar.getPulsarResources()).thenReturn(resources);
    when(resources.getNamespaceResources()).thenReturn(namespaceResources);
    doReturn(ns).when(pulsar).getNamespaceService();
    BrokerService brokerService = mock(BrokerService.class);
    doReturn(brokerService).when(pulsar).getBrokerService();
    doReturn(auth).when(brokerService).getAuthorizationService();
    doReturn(new Semaphore(1000)).when(brokerService).getLookupRequestSemaphore();
}
Also used : NamespaceResources(org.apache.pulsar.broker.resources.NamespaceResources) ClusterData(org.apache.pulsar.common.policies.data.ClusterData) PulsarService(org.apache.pulsar.broker.PulsarService) NamespaceService(org.apache.pulsar.broker.namespace.NamespaceService) ServiceConfiguration(org.apache.pulsar.broker.ServiceConfiguration) AuthorizationService(org.apache.pulsar.broker.authorization.AuthorizationService) PulsarResources(org.apache.pulsar.broker.resources.PulsarResources) ClusterResources(org.apache.pulsar.broker.resources.ClusterResources) Semaphore(java.util.concurrent.Semaphore) BrokerService(org.apache.pulsar.broker.service.BrokerService) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 4 with ClusterResources

use of org.apache.pulsar.broker.resources.ClusterResources in project incubator-pulsar by apache.

the class PulsarStandalone method createNameSpace.

@VisibleForTesting
void createNameSpace(String cluster, String publicTenant, NamespaceName ns) throws Exception {
    ClusterResources cr = broker.getPulsarResources().getClusterResources();
    TenantResources tr = broker.getPulsarResources().getTenantResources();
    NamespaceResources nsr = broker.getPulsarResources().getNamespaceResources();
    if (!cr.clusterExists(cluster)) {
        cr.createCluster(cluster, ClusterData.builder().serviceUrl(broker.getWebServiceAddress()).serviceUrlTls(broker.getWebServiceAddressTls()).brokerServiceUrl(broker.getBrokerServiceUrl()).brokerServiceUrlTls(broker.getBrokerServiceUrlTls()).build());
    }
    if (!tr.tenantExists(publicTenant)) {
        tr.createTenant(publicTenant, TenantInfo.builder().adminRoles(Sets.newHashSet(config.getSuperUserRoles())).allowedClusters(Sets.newHashSet(cluster)).build());
    }
    if (!nsr.namespaceExists(ns)) {
        Policies nsp = new Policies();
        nsp.replication_clusters = Collections.singleton(config.getClusterName());
        nsr.createPolicies(ns, nsp);
    }
}
Also used : NamespaceResources(org.apache.pulsar.broker.resources.NamespaceResources) Policies(org.apache.pulsar.common.policies.data.Policies) ClusterResources(org.apache.pulsar.broker.resources.ClusterResources) TenantResources(org.apache.pulsar.broker.resources.TenantResources) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 5 with ClusterResources

use of org.apache.pulsar.broker.resources.ClusterResources in project incubator-pulsar by apache.

the class PulsarStandaloneTest method testCreateNameSpace.

@Test
public void testCreateNameSpace() throws Exception {
    final String cluster = "cluster1";
    final String tenant = "tenant1";
    final NamespaceName ns = NamespaceName.get(tenant, "ns1");
    ClusterResources cr = mock(ClusterResources.class);
    when(cr.clusterExists(cluster)).thenReturn(false).thenReturn(true);
    doNothing().when(cr).createCluster(eq(cluster), any());
    TenantResources tr = mock(TenantResources.class);
    when(tr.tenantExists(tenant)).thenReturn(false).thenReturn(true);
    doNothing().when(tr).createTenant(eq(tenant), any());
    NamespaceResources nsr = mock(NamespaceResources.class);
    when(nsr.namespaceExists(ns)).thenReturn(false).thenReturn(true);
    doNothing().when(nsr).createPolicies(eq(ns), any());
    PulsarResources resources = mock(PulsarResources.class);
    when(resources.getClusterResources()).thenReturn(cr);
    when(resources.getTenantResources()).thenReturn(tr);
    when(resources.getNamespaceResources()).thenReturn(nsr);
    PulsarService broker = mock(PulsarService.class);
    when(broker.getPulsarResources()).thenReturn(resources);
    when(broker.getWebServiceAddress()).thenReturn("pulsar://localhost:8080");
    when(broker.getWebServiceAddressTls()).thenReturn(null);
    when(broker.getBrokerServiceUrl()).thenReturn("pulsar://localhost:6650");
    when(broker.getBrokerServiceUrlTls()).thenReturn(null);
    ServiceConfiguration config = new ServiceConfiguration();
    config.setClusterName(cluster);
    PulsarStandalone standalone = new PulsarStandalone();
    standalone.setBroker(broker);
    standalone.setConfig(config);
    standalone.createNameSpace(cluster, tenant, ns);
    standalone.createNameSpace(cluster, tenant, ns);
    verify(cr, times(1)).createCluster(eq(cluster), any());
    verify(tr, times(1)).createTenant(eq(tenant), any());
    verify(nsr, times(1)).createPolicies(eq(ns), any());
}
Also used : NamespaceResources(org.apache.pulsar.broker.resources.NamespaceResources) NamespaceName(org.apache.pulsar.common.naming.NamespaceName) PulsarService(org.apache.pulsar.broker.PulsarService) ServiceConfiguration(org.apache.pulsar.broker.ServiceConfiguration) PulsarResources(org.apache.pulsar.broker.resources.PulsarResources) ClusterResources(org.apache.pulsar.broker.resources.ClusterResources) TenantResources(org.apache.pulsar.broker.resources.TenantResources) Test(org.testng.annotations.Test)

Aggregations

ClusterResources (org.apache.pulsar.broker.resources.ClusterResources)7 NamespaceResources (org.apache.pulsar.broker.resources.NamespaceResources)6 PulsarService (org.apache.pulsar.broker.PulsarService)5 ServiceConfiguration (org.apache.pulsar.broker.ServiceConfiguration)5 PulsarResources (org.apache.pulsar.broker.resources.PulsarResources)5 TenantResources (org.apache.pulsar.broker.resources.TenantResources)4 Semaphore (java.util.concurrent.Semaphore)3 AuthorizationService (org.apache.pulsar.broker.authorization.AuthorizationService)3 NamespaceService (org.apache.pulsar.broker.namespace.NamespaceService)3 BrokerService (org.apache.pulsar.broker.service.BrokerService)3 ClusterData (org.apache.pulsar.common.policies.data.ClusterData)3 BeforeMethod (org.testng.annotations.BeforeMethod)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 NamespaceName (org.apache.pulsar.common.naming.NamespaceName)2 Policies (org.apache.pulsar.common.policies.data.Policies)2 Test (org.testng.annotations.Test)2