use of org.apache.pulsar.functions.worker.PulsarWorkerService in project pulsar by apache.
the class AbstractPulsarE2ETest method createPulsarFunctionWorker.
private PulsarWorkerService createPulsarFunctionWorker(ServiceConfiguration config) throws IOException {
System.setProperty(JAVA_INSTANCE_JAR_PROPERTY, FutureUtil.class.getProtectionDomain().getCodeSource().getLocation().getPath());
workerConfig = new WorkerConfig();
tempDirectory = PulsarFunctionTestTemporaryDirectory.create(getClass().getSimpleName());
tempDirectory.useTemporaryDirectoriesForWorkerConfig(workerConfig);
workerConfig.setPulsarFunctionsNamespace(pulsarFunctionsNamespace);
workerConfig.setSchedulerClassName(org.apache.pulsar.functions.worker.scheduler.RoundRobinScheduler.class.getName());
workerConfig.setFunctionRuntimeFactoryClassName(ThreadRuntimeFactory.class.getName());
workerConfig.setFunctionRuntimeFactoryConfigs(// worker talks to local broker
ObjectMapperFactory.getThreadLocal().convertValue(new ThreadRuntimeFactoryConfig().setThreadGroupName("use"), Map.class));
workerConfig.setFailureCheckFreqMs(100);
workerConfig.setNumFunctionPackageReplicas(1);
workerConfig.setClusterCoordinationTopicName("coordinate");
workerConfig.setFunctionAssignmentTopicName("assignment");
workerConfig.setFunctionMetadataTopicName("metadata");
workerConfig.setInstanceLivenessCheckFreqMs(100);
workerConfig.setWorkerPort(0);
workerConfig.setPulsarFunctionsCluster(config.getClusterName());
String hostname = ServiceConfigurationUtils.getDefaultOrConfiguredAddress(config.getAdvertisedAddress());
this.workerId = "c-" + config.getClusterName() + "-fw-" + hostname + "-" + workerConfig.getWorkerPort();
workerConfig.setWorkerHostname(hostname);
workerConfig.setWorkerId(workerId);
workerConfig.setBrokerClientAuthenticationPlugin(AuthenticationTls.class.getName());
workerConfig.setBrokerClientAuthenticationParameters(String.format("tlsCertFile:%s,tlsKeyFile:%s", TLS_CLIENT_CERT_FILE_PATH, TLS_CLIENT_KEY_FILE_PATH));
workerConfig.setUseTls(true);
workerConfig.setTlsAllowInsecureConnection(true);
workerConfig.setTlsTrustCertsFilePath(TLS_TRUST_CERT_FILE_PATH);
workerConfig.setAuthenticationEnabled(true);
workerConfig.setAuthorizationEnabled(true);
PulsarWorkerService workerService = new PulsarWorkerService();
workerService.init(workerConfig, null, false);
return workerService;
}
use of org.apache.pulsar.functions.worker.PulsarWorkerService in project pulsar by apache.
the class PulsarFunctionAdminTest method createPulsarFunctionWorker.
private PulsarWorkerService createPulsarFunctionWorker(ServiceConfiguration config) {
workerConfig = new WorkerConfig();
workerConfig.setPulsarFunctionsNamespace(pulsarFunctionsNamespace);
workerConfig.setSchedulerClassName(org.apache.pulsar.functions.worker.scheduler.RoundRobinScheduler.class.getName());
workerConfig.setFunctionRuntimeFactoryClassName(ThreadRuntimeFactory.class.getName());
workerConfig.setFunctionRuntimeFactoryConfigs(ObjectMapperFactory.getThreadLocal().convertValue(new ThreadRuntimeFactoryConfig().setThreadGroupName("use"), Map.class));
// worker talks to local broker
workerConfig.setPulsarServiceUrl("pulsar://127.0.0.1:" + config.getBrokerServicePortTls().get());
workerConfig.setPulsarWebServiceUrl("https://127.0.0.1:" + config.getWebServicePortTls().get());
workerConfig.setFailureCheckFreqMs(100);
workerConfig.setNumFunctionPackageReplicas(1);
workerConfig.setClusterCoordinationTopicName("coordinate");
workerConfig.setFunctionAssignmentTopicName("assignment");
workerConfig.setFunctionMetadataTopicName("metadata");
workerConfig.setInstanceLivenessCheckFreqMs(100);
workerConfig.setWorkerPort(0);
workerConfig.setPulsarFunctionsCluster(config.getClusterName());
String hostname = ServiceConfigurationUtils.getDefaultOrConfiguredAddress(config.getAdvertisedAddress());
workerConfig.setWorkerHostname(hostname);
workerConfig.setWorkerId("c-" + config.getClusterName() + "-fw-" + hostname + "-" + workerConfig.getWorkerPort());
workerConfig.setBrokerClientAuthenticationPlugin(AuthenticationTls.class.getName());
workerConfig.setBrokerClientAuthenticationParameters(String.format("tlsCertFile:%s,tlsKeyFile:%s", TLS_CLIENT_CERT_FILE_PATH, TLS_CLIENT_KEY_FILE_PATH));
workerConfig.setUseTls(true);
workerConfig.setTlsAllowInsecureConnection(true);
workerConfig.setTlsTrustCertsFilePath(TLS_CLIENT_CERT_FILE_PATH);
PulsarWorkerService workerService = new PulsarWorkerService();
workerService.init(workerConfig, null, false);
return workerService;
}
use of org.apache.pulsar.functions.worker.PulsarWorkerService in project pulsar by apache.
the class FunctionApiV3ResourceTest method testDownloadFunctionHttpUrl.
@Test
public void testDownloadFunctionHttpUrl() throws Exception {
String jarHttpUrl = "https://repo1.maven.org/maven2/org/apache/pulsar/pulsar-common/2.4.2/pulsar-common-2.4.2.jar";
String testDir = FunctionApiV3ResourceTest.class.getProtectionDomain().getCodeSource().getLocation().getPath();
PulsarWorkerService worker = mock(PulsarWorkerService.class);
doReturn(true).when(worker).isInitialized();
WorkerConfig config = mock(WorkerConfig.class);
when(config.isAuthorizationEnabled()).thenReturn(false);
when(worker.getWorkerConfig()).thenReturn(config);
FunctionsImpl function = new FunctionsImpl(() -> worker);
StreamingOutput streamOutput = function.downloadFunction(jarHttpUrl, null, null);
File pkgFile = new File(testDir, UUID.randomUUID().toString());
OutputStream output = new FileOutputStream(pkgFile);
streamOutput.write(output);
Assert.assertTrue(pkgFile.exists());
if (pkgFile.exists()) {
pkgFile.delete();
}
}
use of org.apache.pulsar.functions.worker.PulsarWorkerService in project pulsar by apache.
the class WorkerServiceLoader method load.
/**
* Load the worker services for the given <tt>protocol</tt> list.
*
* @param wsNarPackage worker service nar package
* @param narExtractionDirectory the directory to extract nar directory
* @return the worker service
*/
static WorkerService load(String wsNarPackage, String narExtractionDirectory) {
if (isEmpty(wsNarPackage)) {
return new PulsarWorkerService();
}
WorkerServiceDefinition definition;
try {
definition = getWorkerServiceDefinition(wsNarPackage, narExtractionDirectory);
} catch (IOException ioe) {
log.error("Failed to get the worker service definition from {}", wsNarPackage, ioe);
throw new RuntimeException("Failed to get the worker service definition from " + wsNarPackage, ioe);
}
WorkerServiceMetadata metadata = new WorkerServiceMetadata();
Path narPath = Paths.get(wsNarPackage);
metadata.setArchivePath(narPath);
metadata.setDefinition(definition);
WorkerServiceWithClassLoader service;
try {
service = load(metadata, narExtractionDirectory);
} catch (IOException e) {
log.error("Failed to load the worker service {}", metadata, e);
throw new RuntimeException("Failed to load the worker service " + metadata, e);
}
log.info("Successfully loaded worker service {}", metadata);
return service;
}
use of org.apache.pulsar.functions.worker.PulsarWorkerService in project pulsar by yahoo.
the class WorkerServiceLoader method load.
/**
* Load the worker services for the given <tt>protocol</tt> list.
*
* @param wsNarPackage worker service nar package
* @param narExtractionDirectory the directory to extract nar directory
* @return the worker service
*/
static WorkerService load(String wsNarPackage, String narExtractionDirectory) {
if (isEmpty(wsNarPackage)) {
return new PulsarWorkerService();
}
WorkerServiceDefinition definition;
try {
definition = getWorkerServiceDefinition(wsNarPackage, narExtractionDirectory);
} catch (IOException ioe) {
log.error("Failed to get the worker service definition from {}", wsNarPackage, ioe);
throw new RuntimeException("Failed to get the worker service definition from " + wsNarPackage, ioe);
}
WorkerServiceMetadata metadata = new WorkerServiceMetadata();
Path narPath = Paths.get(wsNarPackage);
metadata.setArchivePath(narPath);
metadata.setDefinition(definition);
WorkerServiceWithClassLoader service;
try {
service = load(metadata, narExtractionDirectory);
} catch (IOException e) {
log.error("Failed to load the worker service {}", metadata, e);
throw new RuntimeException("Failed to load the worker service " + metadata, e);
}
log.info("Successfully loaded worker service {}", metadata);
return service;
}
Aggregations