Search in sources :

Example 1 with WorkerConfig

use of org.apache.pulsar.functions.worker.WorkerConfig in project incubator-pulsar by apache.

the class PulsarStandaloneStarter method start.

void start() throws Exception {
    if (config == null) {
        System.exit(1);
    }
    log.debug("--- setup PulsarStandaloneStarter ---");
    if (!onlyBroker) {
        // Start LocalBookKeeper
        bkEnsemble = new LocalBookkeeperEnsemble(numOfBk, zkPort, bkPort, zkDir, bkDir, wipeData, config.getAdvertisedAddress());
        bkEnsemble.startStandalone();
    }
    if (noBroker) {
        return;
    }
    // load aspectj-weaver agent for instrumentation
    AgentLoader.loadAgentClass(Agent.class.getName(), null);
    // initialize the functions worker
    if (!noFunctionsWorker) {
        WorkerConfig workerConfig;
        if (isBlank(fnWorkerConfigFile)) {
            workerConfig = new WorkerConfig();
        } else {
            workerConfig = WorkerConfig.load(fnWorkerConfigFile);
        }
        // worker talks to local broker
        workerConfig.setPulsarServiceUrl("pulsar://127.0.0.1:" + config.getBrokerServicePort());
        workerConfig.setPulsarWebServiceUrl("http://127.0.0.1:" + config.getWebServicePort());
        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();
    // Create a sample namespace
    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 = new PulsarAdmin(webServiceUrl, config.getBrokerClientAuthenticationPlugin(), config.getBrokerClientAuthenticationParameters());
    final String property = "sample";
    final String cluster = config.getClusterName();
    final String globalCluster = "global";
    final String namespace = property + "/" + cluster + "/ns1";
    try {
        ClusterData clusterData = new ClusterData(webServiceUrl.toString(), null, /* serviceUrlTls */
        brokerServiceUrl, null);
        if (!admin.clusters().getClusters().contains(cluster)) {
            admin.clusters().createCluster(cluster, clusterData);
        } else {
            admin.clusters().updateCluster(cluster, clusterData);
        }
        // Create marker for "global" cluster
        if (!admin.clusters().getClusters().contains(globalCluster)) {
            admin.clusters().createCluster(globalCluster, new ClusterData(null, null));
        }
        if (!admin.properties().getProperties().contains(property)) {
            admin.properties().createProperty(property, new PropertyAdmin(Lists.newArrayList(config.getSuperUserRoles()), Sets.newHashSet(cluster)));
        }
        if (!admin.namespaces().getNamespaces(property).contains(namespace)) {
            admin.namespaces().createNamespace(namespace);
        }
    } catch (PulsarAdminException e) {
        log.info(e.getMessage());
    }
    if (null != fnWorkerService) {
        fnWorkerService.start();
    }
    log.debug("--- setup completed ---");
}
Also used : Agent(org.aspectj.weaver.loadtime.Agent) ClusterData(org.apache.pulsar.common.policies.data.ClusterData) PulsarService(org.apache.pulsar.broker.PulsarService) PulsarAdmin(org.apache.pulsar.client.admin.PulsarAdmin) PropertyAdmin(org.apache.pulsar.common.policies.data.PropertyAdmin) WorkerConfig(org.apache.pulsar.functions.worker.WorkerConfig) PulsarAdminException(org.apache.pulsar.client.admin.PulsarAdminException) LocalBookkeeperEnsemble(org.apache.pulsar.zookeeper.LocalBookkeeperEnsemble) WorkerService(org.apache.pulsar.functions.worker.WorkerService) URL(java.net.URL)

Example 2 with WorkerConfig

use of org.apache.pulsar.functions.worker.WorkerConfig in project incubator-pulsar by apache.

the class FunctionApiV2ResourceTest method setup.

@BeforeMethod
public void setup() {
    this.mockedManager = mock(FunctionMetaDataManager.class);
    this.mockedInputStream = mock(InputStream.class);
    this.mockedFormData = mock(FormDataContentDisposition.class);
    this.mockedNamespace = mock(Namespace.class);
    this.mockedWorkerService = mock(WorkerService.class);
    when(mockedWorkerService.getFunctionMetaDataManager()).thenReturn(mockedManager);
    when(mockedWorkerService.getDlogNamespace()).thenReturn(mockedNamespace);
    // worker config
    WorkerConfig workerConfig = new WorkerConfig().setWorkerId("test").setWorkerPort(8080).setDownloadDirectory("/tmp/pulsar/functions").setFunctionMetadataTopicName("pulsar/functions").setNumFunctionPackageReplicas(3).setPulsarServiceUrl("pulsar://localhost:6650/");
    when(mockedWorkerService.getWorkerConfig()).thenReturn(workerConfig);
    this.resource = spy(new FunctionsImpl(() -> mockedWorkerService));
}
Also used : FunctionMetaDataManager(org.apache.pulsar.functions.worker.FunctionMetaDataManager) InputStream(java.io.InputStream) FunctionsImpl(org.apache.pulsar.functions.worker.rest.api.FunctionsImpl) WorkerConfig(org.apache.pulsar.functions.worker.WorkerConfig) FormDataContentDisposition(org.glassfish.jersey.media.multipart.FormDataContentDisposition) Namespace(org.apache.distributedlog.api.namespace.Namespace) WorkerService(org.apache.pulsar.functions.worker.WorkerService) BeforeMethod(org.testng.annotations.BeforeMethod)

Aggregations

WorkerConfig (org.apache.pulsar.functions.worker.WorkerConfig)2 WorkerService (org.apache.pulsar.functions.worker.WorkerService)2 InputStream (java.io.InputStream)1 URL (java.net.URL)1 Namespace (org.apache.distributedlog.api.namespace.Namespace)1 PulsarService (org.apache.pulsar.broker.PulsarService)1 PulsarAdmin (org.apache.pulsar.client.admin.PulsarAdmin)1 PulsarAdminException (org.apache.pulsar.client.admin.PulsarAdminException)1 ClusterData (org.apache.pulsar.common.policies.data.ClusterData)1 PropertyAdmin (org.apache.pulsar.common.policies.data.PropertyAdmin)1 FunctionMetaDataManager (org.apache.pulsar.functions.worker.FunctionMetaDataManager)1 FunctionsImpl (org.apache.pulsar.functions.worker.rest.api.FunctionsImpl)1 LocalBookkeeperEnsemble (org.apache.pulsar.zookeeper.LocalBookkeeperEnsemble)1 Agent (org.aspectj.weaver.loadtime.Agent)1 FormDataContentDisposition (org.glassfish.jersey.media.multipart.FormDataContentDisposition)1 BeforeMethod (org.testng.annotations.BeforeMethod)1