Search in sources :

Example 1 with ZKMetadataStore

use of org.apache.pulsar.metadata.impl.ZKMetadataStore in project pulsar by apache.

the class WebServiceTest method setupEnv.

private void setupEnv(boolean enableFilter, String minApiVersion, boolean allowUnversionedClients, boolean enableTls, boolean enableAuth, boolean allowInsecure, double rateLimit, boolean disableTrace) throws Exception {
    if (pulsar != null) {
        throw new Exception("broker already started");
    }
    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.setBrokerShutdownTimeoutMs(0L);
    config.setBrokerServicePort(Optional.of(0));
    config.setWebServicePort(Optional.of(0));
    if (enableTls) {
        config.setWebServicePortTls(Optional.of(0));
    }
    config.setClientLibraryVersionCheckEnabled(enableFilter);
    config.setAuthenticationEnabled(enableAuth);
    config.setAuthenticationProviders(providers);
    config.setAuthorizationEnabled(false);
    config.setSuperUserRoles(roles);
    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.setMetadataStoreUrl("zk:localhost:2181");
    config.setHttpMaxRequestSize(10 * 1024);
    config.setDisableHttpDebugMethods(disableTrace);
    if (rateLimit > 0) {
        config.setHttpRequestsLimitEnabled(true);
        config.setHttpRequestsMaxPerSecond(rateLimit);
    }
    pulsar = spyWithClassAndConstructorArgs(PulsarService.class, config);
    // mock zk
    MockZooKeeper mockZooKeeper = MockedPulsarServiceBaseTest.createMockZooKeeper();
    doReturn(new ZKMetadataStore(mockZooKeeper)).when(pulsar).createConfigurationMetadataStore();
    doReturn(new ZKMetadataStore(mockZooKeeper)).when(pulsar).createLocalMetadataStore();
    doReturn(new MockedBookKeeperClientFactory()).when(pulsar).newBookKeeperClientFactory();
    pulsar.start();
    try {
        pulsar.getLocalMetadataStore().delete("/minApiVersion", Optional.empty()).join();
    } catch (Exception ex) {
    }
    pulsar.getLocalMetadataStore().put("/minApiVersion", minApiVersion.getBytes(), Optional.of(-1L)).join();
    String BROKER_URL_BASE = "http://localhost:" + pulsar.getListenPortHTTP().get();
    String BROKER_URL_BASE_TLS = "https://localhost:" + pulsar.getListenPortHTTPS().orElse(-1);
    String serviceUrl = BROKER_URL_BASE;
    PulsarAdminBuilder adminBuilder = PulsarAdmin.builder();
    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);
        adminBuilder.authentication(AuthenticationTls.class.getName(), authParams).allowTlsInsecureConnection(true);
    }
    BROKER_LOOKUP_URL = BROKER_URL_BASE + "/lookup/v2/destination/persistent/my-property/local/my-namespace/my-topic";
    BROKER_LOOKUP_URL_TLS = BROKER_URL_BASE_TLS + "/lookup/v2/destination/persistent/my-property/local/my-namespace/my-topic";
    PulsarAdmin pulsarAdmin = adminBuilder.serviceHttpUrl(serviceUrl).build();
    try {
        pulsarAdmin.clusters().createCluster(config.getClusterName(), ClusterData.builder().serviceUrl(pulsar.getWebServiceAddress()).build());
    } catch (ConflictException ce) {
    // This is OK.
    } finally {
        pulsarAdmin.close();
    }
}
Also used : MockedBookKeeperClientFactory(org.apache.pulsar.broker.MockedBookKeeperClientFactory) PulsarAdmin(org.apache.pulsar.client.admin.PulsarAdmin) HashMap(java.util.HashMap) ConflictException(org.apache.pulsar.client.admin.PulsarAdminException.ConflictException) ConflictException(org.apache.pulsar.client.admin.PulsarAdminException.ConflictException) IOException(java.io.IOException) MockZooKeeper(org.apache.zookeeper.MockZooKeeper) PulsarAdminBuilder(org.apache.pulsar.client.admin.PulsarAdminBuilder) ServiceConfiguration(org.apache.pulsar.broker.ServiceConfiguration) PulsarService(org.apache.pulsar.broker.PulsarService) ZKMetadataStore(org.apache.pulsar.metadata.impl.ZKMetadataStore) HashSet(java.util.HashSet)

Example 2 with ZKMetadataStore

use of org.apache.pulsar.metadata.impl.ZKMetadataStore in project pulsar by apache.

the class OwnerShipForCurrentServerTestBase method setupBrokerMocks.

protected void setupBrokerMocks(PulsarService pulsar) throws Exception {
    // Override default providers with mocked ones
    doReturn(mockBookKeeperClientFactory).when(pulsar).newBookKeeperClientFactory();
    MockZooKeeperSession mockZooKeeperSession = MockZooKeeperSession.newInstance(mockZooKeeper);
    doReturn(new ZKMetadataStore(mockZooKeeperSession)).when(pulsar).createLocalMetadataStore();
    doReturn(new ZKMetadataStore(mockZooKeeperSession)).when(pulsar).createConfigurationMetadataStore();
    Supplier<NamespaceService> namespaceServiceSupplier = () -> spyWithClassAndConstructorArgs(NamespaceService.class, pulsar);
    doReturn(namespaceServiceSupplier).when(pulsar).getNamespaceServiceProvider();
    SameThreadOrderedSafeExecutor executor = new SameThreadOrderedSafeExecutor();
    orderedExecutorList.add(executor);
    doReturn(executor).when(pulsar).getOrderedExecutor();
    doReturn(new CounterBrokerInterceptor()).when(pulsar).getBrokerInterceptor();
    doAnswer((invocation) -> spy(invocation.callRealMethod())).when(pulsar).newCompactor();
}
Also used : CounterBrokerInterceptor(org.apache.pulsar.broker.intercept.CounterBrokerInterceptor) MockZooKeeperSession(org.apache.zookeeper.MockZooKeeperSession) SameThreadOrderedSafeExecutor(org.apache.pulsar.broker.auth.SameThreadOrderedSafeExecutor) ZKMetadataStore(org.apache.pulsar.metadata.impl.ZKMetadataStore)

Example 3 with ZKMetadataStore

use of org.apache.pulsar.metadata.impl.ZKMetadataStore in project pulsar by apache.

the class ProxyAuthorizationTest method setup.

@BeforeClass
@Override
protected void setup() throws Exception {
    conf.setClusterName(configClusterName);
    internalSetup();
    WebSocketProxyConfiguration config = new WebSocketProxyConfiguration();
    Set<String> superUser = Sets.newHashSet("");
    config.setAuthorizationEnabled(true);
    config.setSuperUserRoles(superUser);
    config.setClusterName("c1");
    config.setWebServicePort(Optional.of(0));
    config.setConfigurationMetadataStoreUrl(GLOBAL_DUMMY_VALUE);
    service = spyWithClassAndConstructorArgs(WebSocketService.class, config);
    doReturn(new ZKMetadataStore(mockZooKeeperGlobal)).when(service).createMetadataStore(anyString(), anyInt());
    service.start();
}
Also used : WebSocketProxyConfiguration(org.apache.pulsar.websocket.service.WebSocketProxyConfiguration) WebSocketService(org.apache.pulsar.websocket.WebSocketService) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ZKMetadataStore(org.apache.pulsar.metadata.impl.ZKMetadataStore) BeforeClass(org.testng.annotations.BeforeClass)

Example 4 with ZKMetadataStore

use of org.apache.pulsar.metadata.impl.ZKMetadataStore in project pulsar by apache.

the class ProxyPublishConsumeTest method setup.

@BeforeMethod
public void setup() throws Exception {
    conf.setBacklogQuotaCheckIntervalInSeconds(TIME_TO_CHECK_BACKLOG_QUOTA);
    super.internalSetup();
    super.producerBaseSetup();
    WebSocketProxyConfiguration config = new WebSocketProxyConfiguration();
    config.setWebServicePort(Optional.of(0));
    config.setClusterName("test");
    config.setConfigurationMetadataStoreUrl(GLOBAL_DUMMY_VALUE);
    service = spyWithClassAndConstructorArgs(WebSocketService.class, config);
    doReturn(new ZKMetadataStore(mockZooKeeperGlobal)).when(service).createMetadataStore(anyString(), anyInt());
    proxyServer = new ProxyServer(config);
    WebSocketServiceStarter.start(proxyServer, service);
    log.info("Proxy Server Started");
}
Also used : WebSocketProxyConfiguration(org.apache.pulsar.websocket.service.WebSocketProxyConfiguration) WebSocketService(org.apache.pulsar.websocket.WebSocketService) ZKMetadataStore(org.apache.pulsar.metadata.impl.ZKMetadataStore) ProxyServer(org.apache.pulsar.websocket.service.ProxyServer) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 5 with ZKMetadataStore

use of org.apache.pulsar.metadata.impl.ZKMetadataStore in project pulsar by apache.

the class ProxyAdditionalServletTest method setup.

@Override
@BeforeClass
protected void setup() throws Exception {
    internalSetup();
    proxyConfig.setServicePort(Optional.of(0));
    proxyConfig.setBrokerProxyAllowedTargetPorts("*");
    proxyConfig.setWebServicePort(Optional.of(0));
    proxyConfig.setMetadataStoreUrl(DUMMY_VALUE);
    proxyConfig.setConfigurationMetadataStoreUrl(GLOBAL_DUMMY_VALUE);
    // enable full parsing feature
    proxyConfig.setProxyLogLevel(Optional.of(2));
    // this is for nar package test
    // addServletNar();
    proxyService = Mockito.spy(new ProxyService(proxyConfig, new AuthenticationService(PulsarConfigurationLoader.convertFrom(proxyConfig))));
    doReturn(new ZKMetadataStore(mockZooKeeper)).when(proxyService).createLocalMetadataStore();
    doReturn(new ZKMetadataStore(mockZooKeeperGlobal)).when(proxyService).createConfigurationMetadataStore();
    Optional<Integer> proxyLogLevel = Optional.of(2);
    assertEquals(proxyLogLevel, proxyService.getConfiguration().getProxyLogLevel());
    proxyService.start();
    AuthenticationService authService = new AuthenticationService(PulsarConfigurationLoader.convertFrom(proxyConfig));
    mockAdditionalServlet();
    proxyWebServer = new WebServer(proxyConfig, authService);
    ProxyServiceStarter.addWebServerHandlers(proxyWebServer, proxyConfig, proxyService, null);
    proxyWebServer.start();
}
Also used : AuthenticationService(org.apache.pulsar.broker.authentication.AuthenticationService) ZKMetadataStore(org.apache.pulsar.metadata.impl.ZKMetadataStore) BeforeClass(org.testng.annotations.BeforeClass)

Aggregations

ZKMetadataStore (org.apache.pulsar.metadata.impl.ZKMetadataStore)35 AuthenticationService (org.apache.pulsar.broker.authentication.AuthenticationService)16 BeforeMethod (org.testng.annotations.BeforeMethod)14 BeforeClass (org.testng.annotations.BeforeClass)12 PulsarResources (org.apache.pulsar.broker.resources.PulsarResources)8 NamespaceService (org.apache.pulsar.broker.namespace.NamespaceService)7 WebSocketService (org.apache.pulsar.websocket.WebSocketService)7 WebSocketProxyConfiguration (org.apache.pulsar.websocket.service.WebSocketProxyConfiguration)6 ProxyServer (org.apache.pulsar.websocket.service.ProxyServer)5 HashSet (java.util.HashSet)4 PulsarService (org.apache.pulsar.broker.PulsarService)4 ServiceConfiguration (org.apache.pulsar.broker.ServiceConfiguration)4 AuthenticationTls (org.apache.pulsar.client.impl.auth.AuthenticationTls)4 MockZooKeeperSession (org.apache.zookeeper.MockZooKeeperSession)4 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)3 ManagedLedgerFactory (org.apache.bookkeeper.mledger.ManagedLedgerFactory)3 MockedPulsarServiceBaseTest.createMockZooKeeper (org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest.createMockZooKeeper)3 NamespaceResources (org.apache.pulsar.broker.resources.NamespaceResources)3 ZooKeeper (org.apache.zookeeper.ZooKeeper)3 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)3