pulsar-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] merlimat commented on a change in pull request #2080: Extract out common code from standalone and build Embedded Pulsar
Date Mon, 09 Jul 2018 22:22:41 GMT
merlimat commented on a change in pull request #2080: Extract out common code from standalone
and build Embedded Pulsar
URL: https://github.com/apache/incubator-pulsar/pull/2080#discussion_r201165169
 
 

 ##########
 File path: pulsar-broker/src/main/java/org/apache/pulsar/PulsarStandalone.java
 ##########
 @@ -0,0 +1,391 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pulsar;
+
+import com.beust.jcommander.Parameter;
+import com.ea.agentloader.AgentLoader;
+import com.google.common.collect.Sets;
+import org.apache.pulsar.broker.PulsarService;
+import org.apache.pulsar.broker.ServiceConfiguration;
+import org.apache.pulsar.broker.ServiceConfigurationUtils;
+import org.apache.pulsar.client.admin.PulsarAdmin;
+import org.apache.pulsar.client.admin.PulsarAdminException;
+import org.apache.pulsar.common.naming.TopicName;
+import org.apache.pulsar.common.policies.data.ClusterData;
+import org.apache.pulsar.common.policies.data.TenantInfo;
+import org.apache.pulsar.functions.worker.WorkerConfig;
+import org.apache.pulsar.functions.worker.WorkerService;
+import org.apache.pulsar.zookeeper.LocalBookkeeperEnsemble;
+import org.aspectj.weaver.loadtime.Agent;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.net.URL;
+import java.nio.file.Paths;
+import java.util.Optional;
+
+import static org.apache.commons.lang3.StringUtils.isBlank;
+
+public class PulsarStandalone {
+
+    private static final Logger log = LoggerFactory.getLogger(PulsarStandalone.class);
+
+    PulsarService broker;
+    PulsarAdmin admin;
+    LocalBookkeeperEnsemble bkEnsemble;
+    ServiceConfiguration config;
+    WorkerService fnWorkerService;
+
+    public void setBroker(PulsarService broker) {
+        this.broker = broker;
+    }
+
+    public void setAdmin(PulsarAdmin admin) {
+        this.admin = admin;
+    }
+
+    public void setBkEnsemble(LocalBookkeeperEnsemble bkEnsemble) {
+        this.bkEnsemble = bkEnsemble;
+    }
+
+    public void setBkPort(int bkPort) {
+        this.bkPort = bkPort;
+    }
+
+    public void setBkDir(String bkDir) {
+        this.bkDir = bkDir;
+    }
+
+    public void setAdvertisedAddress(String advertisedAddress) {
+        this.advertisedAddress = advertisedAddress;
+    }
+
+    public void setConfig(ServiceConfiguration config) {
+
+        this.config = config;
+    }
+
+    public void setFnWorkerService(WorkerService fnWorkerService) {
+        this.fnWorkerService = fnWorkerService;
+    }
+
+    public void setConfigFile(String configFile) {
+        this.configFile = configFile;
+    }
+
+    public void setWipeData(boolean wipeData) {
+        this.wipeData = wipeData;
+    }
+
+    public void setNumOfBk(int numOfBk) {
+        this.numOfBk = numOfBk;
+    }
+
+    public void setZkPort(int zkPort) {
+        this.zkPort = zkPort;
+    }
+
+    public void setZkDir(String zkDir) {
+        this.zkDir = zkDir;
+    }
+
+    public void setNoBroker(boolean noBroker) {
+        this.noBroker = noBroker;
+    }
+
+    public void setOnlyBroker(boolean onlyBroker) {
+        this.onlyBroker = onlyBroker;
+    }
+
+    public void setNoFunctionsWorker(boolean noFunctionsWorker) {
+        this.noFunctionsWorker = noFunctionsWorker;
+    }
+
+    public void setFnWorkerConfigFile(String fnWorkerConfigFile) {
+        this.fnWorkerConfigFile = fnWorkerConfigFile;
+    }
+
+    public void setNoStreamStorage(boolean noStreamStorage) {
+        this.noStreamStorage = noStreamStorage;
+    }
+
+    public void setStreamStoragePort(int streamStoragePort) {
+        this.streamStoragePort = streamStoragePort;
+    }
+
+    public void setHelp(boolean help) {
+        this.help = help;
+    }
+
+    public ServiceConfiguration getConfig() {
+        return config;
+    }
+
+    public String getConfigFile() {
+        return configFile;
+    }
+
+    public boolean isWipeData() {
+        return wipeData;
+    }
+
+    public int getNumOfBk() {
+        return numOfBk;
+    }
+
+    public int getZkPort() {
+        return zkPort;
+    }
+
+    public int getBkPort() {
+        return bkPort;
+    }
+
+    public String getZkDir() {
+        return zkDir;
+    }
+
+    public String getBkDir() {
+        return bkDir;
+    }
+
+    public boolean isNoBroker() {
+        return noBroker;
+    }
+
+    public boolean isOnlyBroker() {
+        return onlyBroker;
+    }
+
+    public boolean isNoFunctionsWorker() {
+        return noFunctionsWorker;
+    }
+
+    public String getFnWorkerConfigFile() {
+        return fnWorkerConfigFile;
+    }
+
+    public boolean isNoStreamStorage() {
+        return noStreamStorage;
+    }
+
+    public int getStreamStoragePort() {
+        return streamStoragePort;
+    }
+
+    public String getAdvertisedAddress() {
+        return advertisedAddress;
+    }
+
+    public boolean isHelp() {
+        return help;
+    }
+
+    @Parameter(names = { "-c", "--config" }, description = "Configuration file path", required
= true)
+    private String configFile;
+
+    @Parameter(names = { "--wipe-data" }, description = "Clean up previous ZK/BK data")
+    private boolean wipeData = false;
+
+    @Parameter(names = { "--num-bookies" }, description = "Number of local Bookies")
+    private int numOfBk = 1;
+
+    @Parameter(names = { "--zookeeper-port" }, description = "Local zookeeper's port")
+    private int zkPort = 2181;
+
+    @Parameter(names = { "--bookkeeper-port" }, description = "Local bookies base port")
+    private int bkPort = 3181;
+
+    @Parameter(names = { "--zookeeper-dir" }, description = "Local zooKeeper's data directory")
+    private String zkDir = "data/standalone/zookeeper";
+
+    @Parameter(names = { "--bookkeeper-dir" }, description = "Local bookies base data directory")
+    private String bkDir = "data/standalone/bookkeeper";
+
+    @Parameter(names = { "--no-broker" }, description = "Only start ZK and BK services, no
broker")
+    private boolean noBroker = false;
+
+    @Parameter(names = { "--only-broker" }, description = "Only start Pulsar broker service
(no ZK, BK)")
+    private boolean onlyBroker = false;
+
+    @Parameter(names = {"-nfw", "--no-functions-worker"}, description = "Run functions worker
with Broker")
+    private boolean noFunctionsWorker = false;
+
+    @Parameter(names = {"-fwc", "--functions-worker-conf"}, description = "Configuration
file for Functions Worker")
+    private String fnWorkerConfigFile = Paths.get("").toAbsolutePath().normalize().toString()
+ "/conf/functions_worker.yml";
+
+    @Parameter(names = {"-nss", "--no-stream-storage"}, description = "Disable stream storage")
+    private boolean noStreamStorage = false;
+
+    @Parameter(names = { "--stream-storage-port" }, description = "Local bookies stream storage
port")
+    private int streamStoragePort = 4181;
+
+    @Parameter(names = { "-a", "--advertised-address" }, description = "Standalone broker
advertised address")
+    private String advertisedAddress = null;
+
+    @Parameter(names = { "-h", "--help" }, description = "Show this help message")
+    private boolean help = false;
+
+    void start() throws Exception {
+
+        if (config == null) {
+            System.exit(1);
+        }
+
+        log.debug("--- setup PulsarStandaloneStarter ---");
+
+        // load aspectj-weaver agent for instrumentation
+        AgentLoader.loadAgentClass(Agent.class.getName(), null);
+
+        if (!this.isOnlyBroker()) {
+            // Start LocalBookKeeper
+            bkEnsemble = new LocalBookkeeperEnsemble(
+                this.getNumOfBk(), this.getZkPort(), this.getBkPort(), this.getStreamStoragePort(),
this.getZkDir(), this.getBkDir(), this.isWipeData(), config.getAdvertisedAddress());
+            bkEnsemble.startStandalone(!this.isNoStreamStorage());
+        }
+
+        if (this.isNoBroker()) {
+            return;
+        }
+
+        // initialize the functions worker
+        if (!this.isNoFunctionsWorker()) {
+            WorkerConfig workerConfig;
+            if (isBlank(this.getFnWorkerConfigFile())) {
+                workerConfig = new WorkerConfig();
+            } else {
+                workerConfig = WorkerConfig.load(this.getFnWorkerConfigFile());
+            }
+            // worker talks to local broker
+            workerConfig.setPulsarServiceUrl("pulsar://127.0.0.1:" + config.getBrokerServicePort());
+            workerConfig.setPulsarWebServiceUrl("http://127.0.0.1:" + config.getWebServicePort());
+            workerConfig.setStateStorageServiceUrl("bk://127.0.0.1:" + this.getStreamStoragePort());
+            String hostname = ServiceConfigurationUtils.getDefaultOrConfiguredAddress(
+                config.getAdvertisedAddress());
+            workerConfig.setWorkerHostname(hostname);
+            workerConfig.setWorkerId(
+                "c-" + config.getClusterName()
+                    + "-fw-" + hostname
+                    + "-" + workerConfig.getWorkerPort());
+            fnWorkerService = new WorkerService(workerConfig);
+        }
+
+        // Start Broker
+        broker = new PulsarService(config, Optional.ofNullable(fnWorkerService));
+        broker.start();
+
+        URL webServiceUrl = new URL(
+                String.format("http://%s:%d", config.getAdvertisedAddress(), config.getWebServicePort()));
+        final String brokerServiceUrl = String.format("pulsar://%s:%d", config.getAdvertisedAddress(),
+                config.getBrokerServicePort());
+        admin = PulsarAdmin.builder().serviceHttpUrl(webServiceUrl.toString()).authentication(
+                config.getBrokerClientAuthenticationPlugin(), config.getBrokerClientAuthenticationParameters()).build();
+
+        final String cluster = config.getClusterName();
+
+        createSampleNameSpace(webServiceUrl, brokerServiceUrl, cluster);
+        createDeafultNameSpace(cluster);
+
+        log.debug("--- setup completed ---");
+    }
+
+    void stop() {
 
 Review comment:
   We could use `close()` and implement `AutoClosable`

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message