use of org.apache.pulsar.common.policies.data.ClusterData 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);
mockConfigCache = mock(ConfigurationCacheService.class);
clustersListCache = mock(ZooKeeperChildrenCache.class);
clustersCache = mock(ZooKeeperDataCache.class);
policiesCache = mock(ZooKeeperDataCache.class);
config = spy(new ServiceConfiguration());
config.setClusterName("use");
clusters = new TreeSet<String>();
clusters.add("use");
clusters.add("usc");
clusters.add("usw");
ClusterData useData = new ClusterData("http://broker.messaging.use.example.com:8080");
ClusterData uscData = new ClusterData("http://broker.messaging.usc.example.com:8080");
ClusterData uswData = new ClusterData("http://broker.messaging.usw.example.com:8080");
doReturn(config).when(pulsar).getConfiguration();
doReturn(mockConfigCache).when(pulsar).getConfigurationCache();
doReturn(clustersListCache).when(mockConfigCache).clustersListCache();
doReturn(clustersCache).when(mockConfigCache).clustersCache();
doReturn(policiesCache).when(mockConfigCache).policiesCache();
doReturn(Optional.of(useData)).when(clustersCache).get(AdminResource.path("clusters", "use"));
doReturn(Optional.of(uscData)).when(clustersCache).get(AdminResource.path("clusters", "usc"));
doReturn(Optional.of(uswData)).when(clustersCache).get(AdminResource.path("clusters", "usw"));
doReturn(CompletableFuture.completedFuture(Optional.of(useData))).when(clustersCache).getAsync(AdminResource.path("clusters", "use"));
doReturn(CompletableFuture.completedFuture(Optional.of(uscData))).when(clustersCache).getAsync(AdminResource.path("clusters", "usc"));
doReturn(CompletableFuture.completedFuture(Optional.of(uswData))).when(clustersCache).getAsync(AdminResource.path("clusters", "usw"));
doReturn(clusters).when(clustersListCache).get();
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.common.policies.data.ClusterData in project incubator-pulsar by apache.
the class BrokerBkEnsemblesTests method setup.
@BeforeMethod
void setup() throws Exception {
try {
// start local bookie and zookeeper
bkEnsemble = new LocalBookkeeperEnsemble(3, ZOOKEEPER_PORT, 5001);
bkEnsemble.start();
// start pulsar service
config = new ServiceConfiguration();
config.setZookeeperServers("127.0.0.1" + ":" + ZOOKEEPER_PORT);
config.setAdvertisedAddress("localhost");
config.setWebServicePort(BROKER_WEBSERVICE_PORT);
config.setClusterName("usc");
config.setBrokerServicePort(BROKER_SERVICE_PORT);
config.setAuthorizationEnabled(false);
config.setAuthenticationEnabled(false);
config.setManagedLedgerMaxEntriesPerLedger(5);
config.setManagedLedgerMinLedgerRolloverTimeMinutes(0);
config.setAdvertisedAddress("127.0.0.1");
pulsar = new PulsarService(config);
pulsar.start();
adminUrl = new URL("http://127.0.0.1" + ":" + BROKER_WEBSERVICE_PORT);
admin = new PulsarAdmin(adminUrl, (Authentication) null);
admin.clusters().createCluster("usc", new ClusterData(adminUrl.toString()));
admin.properties().createProperty("prop", new PropertyAdmin(Lists.newArrayList("appid1"), Sets.newHashSet("usc")));
} catch (Throwable t) {
LOG.error("Error setting up broker test", t);
Assert.fail("Broker test setup failed");
}
}
use of org.apache.pulsar.common.policies.data.ClusterData in project incubator-pulsar by apache.
the class WebServiceTest method setupEnv.
private void setupEnv(boolean enableFilter, String minApiVersion, boolean allowUnversionedClients, boolean enableTls, boolean enableAuth, boolean allowInsecure) throws Exception {
Set<String> providers = new HashSet<>();
providers.add("org.apache.pulsar.broker.authentication.AuthenticationProviderTls");
Set<String> roles = new HashSet<>();
roles.add("client");
ServiceConfiguration config = new ServiceConfiguration();
config.setAdvertisedAddress("localhost");
config.setWebServicePort(BROKER_WEBSERVICE_PORT);
config.setWebServicePortTls(BROKER_WEBSERVICE_PORT_TLS);
config.setClientLibraryVersionCheckEnabled(enableFilter);
config.setAuthenticationEnabled(enableAuth);
config.setAuthenticationProviders(providers);
config.setAuthorizationEnabled(false);
config.setSuperUserRoles(roles);
config.setTlsEnabled(enableTls);
config.setTlsCertificateFilePath(TLS_SERVER_CERT_FILE_PATH);
config.setTlsKeyFilePath(TLS_SERVER_KEY_FILE_PATH);
config.setTlsAllowInsecureConnection(allowInsecure);
config.setTlsTrustCertsFilePath(allowInsecure ? "" : TLS_CLIENT_CERT_FILE_PATH);
config.setClusterName("local");
// TLS certificate expects localhost
config.setAdvertisedAddress("localhost");
config.setZookeeperServers("localhost:2181");
pulsar = spy(new PulsarService(config));
doReturn(new MockedZooKeeperClientFactoryImpl()).when(pulsar).getZooKeeperClientFactory();
doReturn(new MockedBookKeeperClientFactory()).when(pulsar).getBookKeeperClientFactory();
pulsar.start();
try {
pulsar.getZkClient().delete("/minApiVersion", -1);
} catch (Exception ex) {
}
pulsar.getZkClient().create("/minApiVersion", minApiVersion.getBytes(), null, CreateMode.PERSISTENT);
String serviceUrl = BROKER_URL_BASE;
ClientConfiguration clientConfig = new ClientConfiguration();
if (enableTls && enableAuth) {
serviceUrl = BROKER_URL_BASE_TLS;
Map<String, String> authParams = new HashMap<>();
authParams.put("tlsCertFile", TLS_CLIENT_CERT_FILE_PATH);
authParams.put("tlsKeyFile", TLS_CLIENT_KEY_FILE_PATH);
Authentication auth = new AuthenticationTls();
auth.configure(authParams);
clientConfig.setAuthentication(auth);
clientConfig.setUseTls(true);
clientConfig.setTlsAllowInsecureConnection(true);
}
PulsarAdmin pulsarAdmin = new PulsarAdmin(new URL(serviceUrl), clientConfig);
try {
pulsarAdmin.clusters().createCluster(config.getClusterName(), new ClusterData(pulsar.getWebServiceAddress()));
} catch (ConflictException ce) {
// This is OK.
} finally {
pulsarAdmin.close();
}
}
use of org.apache.pulsar.common.policies.data.ClusterData in project incubator-pulsar by apache.
the class ZooKeeperSessionExpireRecoveryTest method testSessionExpired.
/**
* Verify we are able to recover when receiving a SessionExpired event on global ZK session
*/
@Test
public void testSessionExpired() throws Exception {
admin.clusters().createCluster("my-cluster", new ClusterData("test-url"));
assertTrue(Sets.newHashSet(admin.clusters().getClusters()).contains("my-cluster"));
mockZookKeeper.failNow(Code.SESSIONEXPIRED);
assertTrue(Sets.newHashSet(admin.clusters().getClusters()).contains("my-cluster"));
try {
admin.clusters().createCluster("my-cluster-2", new ClusterData("test-url"));
fail("Should have failed, because global zk is down");
} catch (PulsarAdminException e) {
// Ok
}
admin.clusters().createCluster("cluster-2", new ClusterData("test-url"));
}
use of org.apache.pulsar.common.policies.data.ClusterData in project incubator-pulsar by apache.
the class AdminApiTest method setup.
@BeforeMethod
@Override
public void setup() throws Exception {
conf.setLoadBalancerEnabled(true);
conf.setTlsEnabled(true);
conf.setTlsCertificateFilePath(TLS_SERVER_CERT_FILE_PATH);
conf.setTlsKeyFilePath(TLS_SERVER_KEY_FILE_PATH);
super.internalSetup();
bundleFactory = new NamespaceBundleFactory(pulsar, Hashing.crc32());
ClientConfiguration clientConf = new ClientConfiguration();
clientConf.setUseTls(true);
clientConf.setTlsTrustCertsFilePath(TLS_SERVER_CERT_FILE_PATH);
adminTls = spy(new PulsarAdmin(brokerUrlTls, clientConf));
// create otherbroker to test redirect on calls that need
// namespace ownership
mockPulsarSetup = new MockedPulsarService(this.conf);
mockPulsarSetup.setup();
otherPulsar = mockPulsarSetup.getPulsar();
otheradmin = mockPulsarSetup.getAdmin();
// Setup namespaces
admin.clusters().createCluster("use", new ClusterData("http://127.0.0.1" + ":" + BROKER_WEBSERVICE_PORT));
PropertyAdmin propertyAdmin = new PropertyAdmin(Lists.newArrayList("role1", "role2"), Sets.newHashSet("use"));
admin.properties().createProperty("prop-xyz", propertyAdmin);
admin.namespaces().createNamespace("prop-xyz/use/ns1");
}
Aggregations