Repository navigation
[Pulsar Functions] Add support for multiple sinks/sources in a single NAR file. - #3678
david-streamlio wants to merge 4 commits into
Conversation
| # Extra options to be passed to the jvm | ||
| PULSAR_MEM="-Xmx128m -XX:MaxDirectMemorySize=128m" | ||
| # PULSAR_MEM="-Xmx128m -XX:MaxDirectMemorySize=128m" | ||
| PULSAR_MEM="-Xmx4g -XX:MaxDirectMemorySize=128m" |
There was a problem hiding this comment.
is this change necessary?
There was a problem hiding this comment.
No, I had to add that in order to be able to submit the NAR I was testing with.
|
@david-streamlio so which multiple sources/sinks packaged in a single NAR I would use the specify the classname to run a particular one? e.g. Currently this can already be done with a JAR file, but this change is to add that support for NARs as well? |
|
Most connectors require multiple supporting jars to be bundled with them. This allows you to submit either an Uber jar or a NAR file. I used the pulsar-aws-nar-0.0.1.nar file for testing, which has 3 sink and 3 source connectors. |
|
@david-streamlio this PR looks good to me, but I am unclear how the changes in the PR makes submitting a uber JAR with multiple sources/sinks different from submitting a NAR. Do we need to support submitting with a NAR with multiple sources/sinks if submitting a uber JAR already covers the use cases of multiple sources/sinks in one package? I guess it doesn't hurt, however my concern is that we have always submitted NARs without specifying a classname since there is the a yaml file under META-INF that specifies the default source/sink classname as well as the name of the source/sink. How does that work here? with multiple sources and sinks. |
|
There wouldn't be a difference between submitting an uber jar and a NAR. They would both be submitted in the exact same way. Each would require the user to specify an archive AND a classname.
If no classname is specified, then the NAR is deployed as normal, i.e. the classes defined in the pulsar-io.yaml file will be used instead. |
|
@david-streamlio so for this NAR you built, pulsar-aws-nar-0.0.1.nar, with multiple sources and sinks, what happens if I submit this NAR without a classname? what happens? I ask since currently submitting a NAR without specifying the classname is supported and the de factor way to submit a NAR. Does it contain a yaml file under META-INF that specifies the default source/sink classname like the rest of the sources and sinks that we currently have? |
|
@jerrypeng @david-streamlio - did you have any conclusions in #3576? It would be worth that you guys can conclude an approach in #3576 , so that everyone is aligned with the approach and other committers can also review it based on that approach. |
|
@jerrypeng If you submit the pulsar-aws-nar-0.0.1.nar without specifying a classname, then the sink/source configured in the pulsar-io.yaml file will be used. You can think of that as the "default" connectors, that can be overridden by the className property. |
|
@david-streamlio ok that sounds good to me. Just making sure all code paths are covered. |
|
@david-streamlio please revert back the change in pulsar_tools_env.sh and I think we are good to go. Thanks! |
|
rerun java8 tests |
eolivelli
left a comment
There was a problem hiding this comment.
@david-streamlio this is a very nice an useful feature.
I left a few little comments, can you please take a look and address the comments from the others ?
it would be great to see this land in 2.8.0
| classLoader = Utils.extractClassLoader(archivePath, functionPkgUrl, uploadedInputStreamAsFile); | ||
| String ext = null; | ||
| if (!isEmpty(functionPkgUrl)) { | ||
| File file = Utils.extractFileFromPkg(functionPkgUrl); |
There was a problem hiding this comment.
this file is only a temporary file, we need it only for the extension.
can we remove the file as soon as we do not need it anymore ?
it would be also better to not extract the file but only to scan for the file name
| private static final int parallelism = 1; | ||
| private static final String JAR_FILE_NAME = "pulsar-io-twitter.nar"; | ||
| private static final String INVALID_JAR_FILE_NAME = "pulsar-io-cassandra.nar"; | ||
| private static final String INVALID_JAR_FILE_NAME = "pulsar-io-cassandra-2.3.0-SNAPSHOT.nar"; |
There was a problem hiding this comment.
why are you changing this line ? does the version make a difference to us ?
| doReturn(String.class).when(org.apache.pulsar.functions.utils.Utils.class); | ||
| org.apache.pulsar.functions.utils.Utils.getSourceType(anyString(), any(NarClassLoader.class)); | ||
|
|
||
| File mockedFile = mock(File.class); |
There was a problem hiding this comment.
usually it is not a good practice to mock Java classes, it would be likely to break with future Java version, in this case you can create a dummy temporary file with the wanted file extension
|
Closed as stale. |
Contribution Checklist
Address #3576
Motivation
Added logic to use the proper class loader when a Source or Sink is created from the command line and an "archive" and "className" are provided. Prior to this change, it was always assumed the the archive file specified was a standard "JAR" file.
Now, we check the file extension of the archive and choose the appropriate class loader based on that. This allows user to submit Pulsar connectors that are bundled inside a NAR file
Also added support for multiple sink/source definitions in NAR files, while also being 100% fully-backward complaint. Added test classes to validate that
Modifications
Modified both the
pulsar-functions/utils/src/main/java/org/apache/pulsar/functions/utils/SinkConfigUtils.java
pulsar-functions/utils/src/main/java/org/apache/pulsar/functions/utils/SourceConfigUtils.java
classes to check the file extension of the archive, and use the correct class loader
Modified the org.apache.pulsar.functions.utils.io.ConnectorUtils class to read both the old and new pulsar-io.yaml formats as shown below. Therefore this is NOT a breaking change
name: filedescription: Reads data from local filesystemsourceClass: org.apache.pulsar.io.file.FileSourceand
connectors:hdfs:description: The HDFS connectorsourceClass: org.apache.pulsar.io.hdfs.SoruceClassImplsinkClass: org.apache.pulsar.io.hdfs.SinkClassImplredis:description: The Redis connectorsourceClass: org.apache.pulsar.io.redis.SoruceClassImplsinkClass: org.apache.pulsar.io.redis.SinkClassImplVerifying this change
This change is already covered by existing tests, such as
Does this pull request potentially affect one of the following parts:
Documentation