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);
}
}
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());
}
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();
}
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);
}
}
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());
}
Aggregations