use of org.apache.pulsar.functions.worker.WorkerService 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 ---");
}
use of org.apache.pulsar.functions.worker.WorkerService in project incubator-pulsar by apache.
the class FunctionsMetricsResource method getMetrics.
@Path("metrics")
@GET
@Produces(MediaType.TEXT_PLAIN)
public Response getMetrics() throws JsonProcessingException {
WorkerService workerService = get();
ByteBuf buf = ByteBufAllocator.DEFAULT.heapBuffer();
try {
SimpleTextOutputStream stream = new SimpleTextOutputStream(buf);
FunctionsStatsGenerator.generate(workerService, "default", stream);
byte[] payload = buf.array();
int arrayOffset = buf.arrayOffset();
int readableBytes = buf.readableBytes();
StreamingOutput streamOut = out -> {
out.write(payload, arrayOffset, readableBytes);
out.flush();
};
return Response.ok(streamOut).build();
} finally {
buf.release();
}
}
Aggregations