Search in sources :

Example 1 with WebSocketService

use of com.yahoo.pulsar.websocket.WebSocketService in project pulsar by yahoo.

the class ProxyAuthenticationTest method setup.

@BeforeClass
public void setup() throws Exception {
    super.internalSetup();
    super.producerBaseSetup();
    WebSocketProxyConfiguration config = new WebSocketProxyConfiguration();
    config.setWebServicePort(TEST_PORT);
    config.setClusterName("use");
    config.setAuthenticationEnabled(true);
    config.setAuthenticationProviders(Sets.newHashSet("com.yahoo.pulsar.websocket.proxy.MockAuthenticationProvider"));
    service = spy(new WebSocketService(config));
    doReturn(mockZooKeeperClientFactory).when(service).getZooKeeperClientFactory();
    proxyServer = new ProxyServer(config);
    WebSocketServiceStarter.start(proxyServer, service);
    log.info("Proxy Server Started");
}
Also used : WebSocketProxyConfiguration(com.yahoo.pulsar.websocket.service.WebSocketProxyConfiguration) WebSocketService(com.yahoo.pulsar.websocket.WebSocketService) ProxyServer(com.yahoo.pulsar.websocket.service.ProxyServer) BeforeClass(org.testng.annotations.BeforeClass)

Example 2 with WebSocketService

use of com.yahoo.pulsar.websocket.WebSocketService in project pulsar by yahoo.

the class PulsarService method start.

/**
     * Start the pulsar service instance.
     */
public void start() throws PulsarServerException {
    mutex.lock();
    try {
        if (state != State.Init) {
            throw new PulsarServerException("Cannot start the service once it was stopped");
        }
        // Now we are ready to start services
        localZooKeeperConnectionProvider = new LocalZooKeeperConnectionService(getZooKeeperClientFactory(), config.getZookeeperServers(), config.getZooKeeperSessionTimeoutMillis());
        localZooKeeperConnectionProvider.start(shutdownService);
        // Initialize and start service to access configuration repository.
        this.startZkCacheService();
        managedLedgerClientFactory = new ManagedLedgerClientFactory(config, getZkClient(), getBookKeeperClientFactory());
        this.brokerService = new BrokerService(this);
        // Start load management service (even if load balancing is disabled)
        this.loadManager = new SimpleLoadManagerImpl(this);
        this.startLoadManagementService();
        // needs load management service
        this.startNamespaceService();
        LOG.info("Starting Pulsar Broker service");
        brokerService.start();
        this.webService = new WebService(this);
        this.webService.addRestResources("/", "com.yahoo.pulsar.broker.web", false);
        this.webService.addRestResources("/admin", "com.yahoo.pulsar.broker.admin", true);
        this.webService.addRestResources("/lookup", "com.yahoo.pulsar.broker.lookup", true);
        if (config.isWebSocketServiceEnabled()) {
            // Use local broker address to avoid different IP address when using a VIP for service discovery
            this.webSocketService = new WebSocketService(new ClusterData(webServiceAddress, webServiceAddressTls), config);
            this.webSocketService.start();
            this.webService.addServlet(WebSocketProducerServlet.SERVLET_PATH, new ServletHolder(new WebSocketProducerServlet(webSocketService)), true);
            this.webService.addServlet(WebSocketConsumerServlet.SERVLET_PATH, new ServletHolder(new WebSocketConsumerServlet(webSocketService)), true);
        }
        if (LOG.isDebugEnabled()) {
            LOG.debug("Attempting to add static directory");
        }
        this.webService.addStaticResources("/static", "/static");
        // Register heartbeat and bootstrap namespaces.
        this.nsservice.registerBootstrapNamespaces();
        // Start the leader election service
        this.leaderElectionService = new LeaderElectionService(this, new LeaderListener() {

            @Override
            public synchronized void brokerIsTheLeaderNow() {
                if (getConfiguration().isLoadBalancerEnabled()) {
                    long loadSheddingInterval = TimeUnit.MINUTES.toMillis(getConfiguration().getLoadBalancerSheddingIntervalMinutes());
                    long resourceQuotaUpdateInterval = TimeUnit.MINUTES.toMillis(getConfiguration().getLoadBalancerResourceQuotaUpdateIntervalMinutes());
                    loadSheddingTask = loadManagerExecutor.scheduleAtFixedRate(new LoadSheddingTask(loadManager), loadSheddingInterval, loadSheddingInterval, TimeUnit.MILLISECONDS);
                    loadResourceQuotaTask = loadManagerExecutor.scheduleAtFixedRate(new LoadResourceQuotaUpdaterTask(loadManager), resourceQuotaUpdateInterval, resourceQuotaUpdateInterval, TimeUnit.MILLISECONDS);
                }
            }

            @Override
            public synchronized void brokerIsAFollowerNow() {
                if (loadSheddingTask != null) {
                    loadSheddingTask.cancel(false);
                    loadSheddingTask = null;
                }
                if (loadResourceQuotaTask != null) {
                    loadResourceQuotaTask.cancel(false);
                    loadResourceQuotaTask = null;
                }
            }
        });
        leaderElectionService.start();
        webService.start();
        this.metricsGenerator = new MetricsGenerator(this);
        state = State.Started;
        acquireSLANamespace();
        LOG.info("messaging service is ready, bootstrap service on port={}, broker url={}, cluster={}, configs={}", config.getWebServicePort(), brokerServiceUrl, config.getClusterName(), config);
    } catch (Exception e) {
        LOG.error(e.getMessage(), e);
        throw new PulsarServerException(e);
    } finally {
        mutex.unlock();
    }
}
Also used : LeaderListener(com.yahoo.pulsar.broker.loadbalance.LeaderElectionService.LeaderListener) WebService(com.yahoo.pulsar.broker.web.WebService) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) WebSocketProducerServlet(com.yahoo.pulsar.websocket.WebSocketProducerServlet) LoadResourceQuotaUpdaterTask(com.yahoo.pulsar.broker.loadbalance.LoadResourceQuotaUpdaterTask) WebSocketConsumerServlet(com.yahoo.pulsar.websocket.WebSocketConsumerServlet) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) MetricsGenerator(com.yahoo.pulsar.broker.stats.MetricsGenerator) ClusterData(com.yahoo.pulsar.common.policies.data.ClusterData) SimpleLoadManagerImpl(com.yahoo.pulsar.broker.loadbalance.impl.SimpleLoadManagerImpl) LocalZooKeeperConnectionService(com.yahoo.pulsar.zookeeper.LocalZooKeeperConnectionService) LoadSheddingTask(com.yahoo.pulsar.broker.loadbalance.LoadSheddingTask) LeaderElectionService(com.yahoo.pulsar.broker.loadbalance.LeaderElectionService) WebSocketService(com.yahoo.pulsar.websocket.WebSocketService) BrokerService(com.yahoo.pulsar.broker.service.BrokerService)

Example 3 with WebSocketService

use of com.yahoo.pulsar.websocket.WebSocketService in project pulsar by yahoo.

the class ProxyAuthorizationTest method setup.

@BeforeClass
@Override
protected void setup() throws Exception {
    conf.setClusterName("c1");
    internalSetup();
    WebSocketProxyConfiguration config = new WebSocketProxyConfiguration();
    Set<String> superUser = Sets.newHashSet("");
    config.setAuthorizationEnabled(true);
    config.setGlobalZookeeperServers("dummy-zk-servers");
    config.setSuperUserRoles(superUser);
    config.setClusterName("c1");
    config.setWebServicePort(TEST_PORT);
    service = spy(new WebSocketService(config));
    doReturn(mockZooKeeperClientFactory).when(service).getZooKeeperClientFactory();
    service.start();
}
Also used : WebSocketProxyConfiguration(com.yahoo.pulsar.websocket.service.WebSocketProxyConfiguration) WebSocketService(com.yahoo.pulsar.websocket.WebSocketService) BeforeClass(org.testng.annotations.BeforeClass)

Example 4 with WebSocketService

use of com.yahoo.pulsar.websocket.WebSocketService in project pulsar by yahoo.

the class ProxyPublishConsumeTest method setup.

@BeforeClass
public void setup() throws Exception {
    super.internalSetup();
    super.producerBaseSetup();
    WebSocketProxyConfiguration config = new WebSocketProxyConfiguration();
    config.setWebServicePort(TEST_PORT);
    config.setClusterName("use");
    config.setGlobalZookeeperServers("dummy-zk-servers");
    service = spy(new WebSocketService(config));
    doReturn(mockZooKeeperClientFactory).when(service).getZooKeeperClientFactory();
    proxyServer = new ProxyServer(config);
    WebSocketServiceStarter.start(proxyServer, service);
    log.info("Proxy Server Started");
}
Also used : WebSocketProxyConfiguration(com.yahoo.pulsar.websocket.service.WebSocketProxyConfiguration) WebSocketService(com.yahoo.pulsar.websocket.WebSocketService) ProxyServer(com.yahoo.pulsar.websocket.service.ProxyServer) BeforeClass(org.testng.annotations.BeforeClass)

Example 5 with WebSocketService

use of com.yahoo.pulsar.websocket.WebSocketService in project pulsar by yahoo.

the class ProxyPublishConsumeTls method setup.

@BeforeClass
public void setup() throws Exception {
    super.internalSetup();
    super.producerBaseSetup();
    WebSocketProxyConfiguration config = new WebSocketProxyConfiguration();
    config.setWebServicePort(TEST_PORT);
    config.setWebServicePortTls(TLS_TEST_PORT);
    config.setTlsEnabled(true);
    config.setTlsKeyFilePath(TLS_SERVER_KEY_FILE_PATH);
    config.setTlsCertificateFilePath(TLS_SERVER_CERT_FILE_PATH);
    config.setClusterName("use");
    config.setGlobalZookeeperServers("dummy-zk-servers");
    service = spy(new WebSocketService(config));
    doReturn(mockZooKeeperClientFactory).when(service).getZooKeeperClientFactory();
    proxyServer = new ProxyServer(config);
    WebSocketServiceStarter.start(proxyServer, service);
    log.info("Proxy Server Started");
}
Also used : WebSocketProxyConfiguration(com.yahoo.pulsar.websocket.service.WebSocketProxyConfiguration) WebSocketService(com.yahoo.pulsar.websocket.WebSocketService) ProxyServer(com.yahoo.pulsar.websocket.service.ProxyServer) BeforeClass(org.testng.annotations.BeforeClass)

Aggregations

WebSocketService (com.yahoo.pulsar.websocket.WebSocketService)7 WebSocketProxyConfiguration (com.yahoo.pulsar.websocket.service.WebSocketProxyConfiguration)5 BeforeClass (org.testng.annotations.BeforeClass)5 ProxyServer (com.yahoo.pulsar.websocket.service.ProxyServer)4 LeaderElectionService (com.yahoo.pulsar.broker.loadbalance.LeaderElectionService)1 LeaderListener (com.yahoo.pulsar.broker.loadbalance.LeaderElectionService.LeaderListener)1 LoadResourceQuotaUpdaterTask (com.yahoo.pulsar.broker.loadbalance.LoadResourceQuotaUpdaterTask)1 LoadSheddingTask (com.yahoo.pulsar.broker.loadbalance.LoadSheddingTask)1 SimpleLoadManagerImpl (com.yahoo.pulsar.broker.loadbalance.impl.SimpleLoadManagerImpl)1 BrokerService (com.yahoo.pulsar.broker.service.BrokerService)1 MetricsGenerator (com.yahoo.pulsar.broker.stats.MetricsGenerator)1 WebService (com.yahoo.pulsar.broker.web.WebService)1 ClusterData (com.yahoo.pulsar.common.policies.data.ClusterData)1 WebSocketConsumerServlet (com.yahoo.pulsar.websocket.WebSocketConsumerServlet)1 WebSocketProducerServlet (com.yahoo.pulsar.websocket.WebSocketProducerServlet)1 LocalZooKeeperConnectionService (com.yahoo.pulsar.zookeeper.LocalZooKeeperConnectionService)1 IOException (java.io.IOException)1 ExecutionException (java.util.concurrent.ExecutionException)1 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)1