Skip to content

[Pulsar Functions] Add support for multiple sinks/sources in a single NAR file. - #3678

Closed
david-streamlio wants to merge 4 commits into
apache:masterfrom
david-streamlio:connector-classpath-fix
Closed

david-streamlio wants to merge 4 commits into
apache:masterfrom
david-streamlio:connector-classpath-fix

Conversation

@david-streamlio

@david-streamlio david-streamlio commented Feb 25, 2019 •

Copy link
Copy Markdown
Contributor

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: file
description: Reads data from local filesystem
sourceClass: org.apache.pulsar.io.file.FileSource

and

connectors:
hdfs:
description: The HDFS connector
sourceClass: org.apache.pulsar.io.hdfs.SoruceClassImpl
sinkClass: org.apache.pulsar.io.hdfs.SinkClassImpl
redis:
description: The Redis connector
sourceClass: org.apache.pulsar.io.redis.SoruceClassImpl
sinkClass: org.apache.pulsar.io.redis.SinkClassImpl

Verifying this change

  • Make sure that the change passes the CI checks.

This change is already covered by existing tests, such as

  • org.apache.pulsar.functions.worker.rest.api.v3.SinkApiV3ResourceTest
  • org.apache.pulsar.functions.worker.rest.api.v3.SourceApiV3ResourceTest

Does this pull request potentially affect one of the following parts:

  • Dependencies (does it add or upgrade a dependency): No
  • The public API: No
  • The schema: No
  • The default values of configurations: No
  • The wire protocol: No
  • The rest endpoints: No (Fixes existing broken usage of archive/className params)
  • The admin cli options: No (Fixes existing broken usage of archive/className params)
  • Anything that affects deployment: No

Documentation

  • Does this pull request introduce a new feature? No
  • If yes, how is the feature documented? not applicable
  • If a feature is not applicable for documentation, explain why? It's already documented

Comment thread conf/pulsar_tools_env.sh Outdated
# 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"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this change necessary?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I had to add that in order to be able to submit the NAR I was testing with.

@jerrypeng

jerrypeng commented Feb 25, 2019 •

Copy link
Copy Markdown
Contributor

@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.

./bin/pulsar-admin source create --name test --destinationTopicName output --archive foo.nar --classname my.source

Currently this can already be done with a JAR file, but this change is to add that support for NARs as well?

@david-streamlio

Copy link
Copy Markdown
Contributor Author

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.

@jerrypeng

Copy link
Copy Markdown
Contributor

@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.

@david-streamlio

david-streamlio commented Feb 25, 2019 •

Copy link
Copy Markdown
Contributor Author

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.

bin/pulsar-admin source create --classname org.apache.pulsar.io.aws.sqs.SqsSource --archive /Users/david/clone-zone/streamlio/pulsar-connectors/pulsar-nar-bundles/pulsar-aws-connector-bundle/pulsar-aws-nar/target/pulsar-aws-nar-0.0.1.nar --className org.apache.pulsar.io.aws.s3.source.AwsS3Source --name s3-source --destination-topic-name s3_data --source-config-file /Users/david/Desktop/s3-config.yaml

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.

@jerrypeng

Copy link
Copy Markdown
Contributor

@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?

@sijie

sijie commented Feb 25, 2019

Copy link
Copy Markdown
Member

@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.

@david-streamlio

Copy link
Copy Markdown
Contributor Author

@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.

@jerrypeng

Copy link
Copy Markdown
Contributor

@david-streamlio ok that sounds good to me. Just making sure all code paths are covered.

@jerrypeng

Copy link
Copy Markdown
Contributor

@david-streamlio please revert back the change in pulsar_tools_env.sh and I think we are good to go. Thanks!

jerrypeng
jerrypeng previously approved these changes Feb 25, 2019
@jiazhai

jiazhai commented Feb 26, 2019

Copy link
Copy Markdown
Member

rerun java8 tests

@jerrypeng
jerrypeng self-requested a review March 2, 2019 21:12
@sijie sijie removed this from the 2.4.0 milestone Jun 9, 2019

@eolivelli eolivelli left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@tisonkun

tisonkun commented Dec 6, 2022

Copy link
Copy Markdown
Member

Closed as stale.

@tisonkun tisonkun closed this Dec 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants