-
Notifications
You must be signed in to change notification settings - Fork 338
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CDAP-4957 et al: Fix Third-Party Plugin Documentation and JDBC examples #5589
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
591810c
Add ability to append arbitrary text to the end of the downloaded the…
d854621
Merge branch 'release/3.4' into docs/3.4_4957_Hydrator
07c4521
Move version to end of file.
f9d34da
Update database-batchsink-append.txt
70a7672
Update database-batchsource-append.txt
3e2c324
Merge branch 'release/3.4' into docs/3.4_4957_Hydrator
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
cdap-docs/cdap-apps/source/_includes/hydrator-plugins/database-batchsink-append.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
Using Third-Party JARs | ||
---------------------- | ||
For information on how to use the JDBC jar to talk to the database sink, see | ||
[Using Third-Party JARs](../third-party.html). |
5 changes: 5 additions & 0 deletions
5
cdap-docs/cdap-apps/source/_includes/hydrator-plugins/database-batchsource-append.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
Using Third-Party JARs | ||
---------------------- | ||
For information on how to use the JDBC jar to talk to the database source, see | ||
[Using Third-Party JARs](../third-party.html). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -121,11 +121,42 @@ Sometimes there is a need to use classes in a third-party JAR as plugins. For ex | |
a JDBC driver as a plugin. In these situations, you have no control over the code, which means you cannot | ||
annotate the relevant class with the ``@Plugin`` annotation. If this is the case, you can explicitly specify | ||
the plugins when deploying the artifact. For example, if you are using the RESTful API, you set the | ||
``Artifact-Plugins`` and ``Artifact-Version`` headers when deploying the artifact:: | ||
``Artifact-Plugins``, ``Artifact-Version``, and ``Artifact-Extends`` headers when deploying the artifact: | ||
|
||
.. tabbed-parsed-literal:: | ||
|
||
$ curl -w"\n" -X POST "localhost:10000/v3/namespaces/default/artifacts/mysql-connector-java" \ | ||
-H "Artifact-Plugins: [ { 'name': 'mysql', 'type': 'jdbc', 'className': 'com.mysql.jdbc.Driver' } ]" \ | ||
-H "Artifact-Version: 5.1.35" \ | ||
-H "Artifact-Extends: system:cdap-etl-batch[|version|, |version|]/system:cdap-etl-realtime[|version|, |version|]" \ | ||
--data-binary @mysql-connector-java-5.1.35.jar | ||
|
||
Or, using the CDAP CLI: | ||
|
||
.. tabbed-parsed-literal:: | ||
:tabs: "CDAP CLI" | ||
|
||
|cdap >| load artifact /path/to/mysql-connector-java-5.1.35.jar config-file /path/to/config.json | ||
|
||
|
||
where ``config.json`` contains: | ||
|
||
.. highlight:: xml | ||
|
||
.. container:: highlight | ||
|
||
.. parsed-literal:: | ||
{ | ||
"parents": [ "system:cdap-etl-batch\[|version|,\ |version|]", "system:cdap-etl-realtime[|version|,\ |version|]" ], | ||
"plugins": [ | ||
{ | ||
"name": "mysql", | ||
"type": "jdbc", | ||
"className": "com.mysql.jdbc.Driver" | ||
} | ||
] | ||
} | ||
|
||
$ curl -w'\n' localhost:10000/v3/namespaces/default/artifacts/mysql-connector-java \ | ||
-H 'Artifact-Plugins: [ { "name": "mysql", "type": "jdbc", "className": "com.mysql.jdbc.Driver" } ]' \ | ||
-H 'Artifact-Version: 5.1.35' --data-binary @mysql-connector-java-5.1.35.jar | ||
|
||
.. _plugins-deployment: | ||
|
||
|
@@ -265,21 +296,18 @@ When using the CLI, a configuration file exactly like the one described in the | |
|
||
For example, to deploy ``custom-transforms-1.0.0.jar`` using the RESTful API: | ||
|
||
.. highlight:: console | ||
|
||
.. container:: highlight | ||
.. tabbed-parsed-literal:: | ||
|
||
.. parsed-literal:: | ||
|$| curl -w'\\n' localhost:10000/v3/namespaces/default/artifacts/custom-transforms \\ | ||
-H 'Artifact-Extends: system:cdap-etl-batch[|version|, |version|]/system:cdap-etl-realtime[|version|, |version|]' \\ | ||
--data-binary @/path/to/custom-transforms-1.0.0.jar | ||
$ curl -w"\n" -X POST "localhost:10000/v3/namespaces/default/artifacts/custom-transforms" \ | ||
-H "Artifact-Extends: system:cdap-etl-batch[|version|, |version|]/system:cdap-etl-realtime[|version|, |version|]" \ | ||
--data-binary @/path/to/custom-transforms-1.0.0.jar | ||
|
||
Using the CLI: | ||
|
||
.. container:: highlight | ||
|
||
.. parsed-literal:: | ||
|$| cdap-cli.sh load artifact /path/to/custom-transforms-1.0.0.jar config-file /path/to/config.json | ||
.. tabbed-parsed-literal:: | ||
:tabs: "CDAP CLI" | ||
|
||
|cdap >| load artifact /path/to/custom-transforms-1.0.0.jar config-file /path/to/config.json | ||
|
||
where ``config.json`` contains: | ||
|
||
|
@@ -305,22 +333,20 @@ first be deleted. | |
Using the RESTful API (note that if the artifact version is not in the JAR manifest file, | ||
it needs to be set explicitly, as the JAR contents are uploaded without the filename): | ||
|
||
.. highlight:: console | ||
|
||
.. container:: highlight | ||
.. tabbed-parsed-literal:: | ||
|
||
.. parsed-literal:: | ||
|$| curl -w'\\n' localhost:10000/v3/namespaces/default/artifacts/mysql-connector-java \\ | ||
-H 'Artifact-Extends: system:cdap-etl-batch[|version|,\ |version|]/system:cdap-etl-realtime[|version|,\ |version|]' \\ | ||
-H 'Artifact-Plugins: [ { "name": "mysql", "type": "jdbc", "className": "com.mysql.jdbc.Driver" } ]' \\ | ||
-H 'Artifact-Version: 5.1.35' --data-binary @/path/to/mysql-connector-java-5.1.35.jar | ||
$ curl -w"\n" -X POST "localhost:10000/v3/namespaces/default/artifacts/mysql-connector-java" \ | ||
-H "Artifact-Plugins: [ { 'name': 'mysql', 'type': 'jdbc', 'className': 'com.mysql.jdbc.Driver' } ]" \ | ||
-H "Artifact-Version: 5.1.35" \ | ||
-H "Artifact-Extends: system:cdap-etl-batch[|version|, |version|]/system:cdap-etl-realtime[|version|, |version|]" \ | ||
--data-binary @mysql-connector-java-5.1.35.jar | ||
|
||
Using the CLI (note that the artifact version, if not explicitly set, is derived from the JAR filename): | ||
|
||
.. container:: highlight | ||
|
||
.. parsed-literal:: | ||
|$| cdap-cli.sh load artifact /path/to/mysql-connector-java-5.1.35.jar config-file /path/to/config.json | ||
.. tabbed-parsed-literal:: | ||
:tabs: "CDAP CLI" | ||
|
||
|cdap >| load artifact /path/to/mysql-connector-java-5.1.35.jar config-file /path/to/config.json | ||
|
||
where ``config.json`` contains: | ||
|
||
|
@@ -348,12 +374,9 @@ You can verify that a plugin artifact was added successfully by using the | |
:ref:`RESTful Artifact API <http-restful-api-artifact-detail>` to retrieve artifact details. | ||
For example, to retrieve detail about our ``custom-transforms`` artifact: | ||
|
||
.. highlight:: console | ||
.. tabbed-parsed-literal:: | ||
|
||
.. container:: highlight | ||
|
||
.. parsed-literal:: | ||
|$| curl -w'\\n' localhost:10000/v3/namespaces/default/artifacts/custom-transforms/versions/1.0.0?scope=[system | user] | ||
$ curl -w"\n" -X POST "localhost:10000/v3/namespaces/default/artifacts/custom-transforms/versions/1.0.0?scope=[system | user] | ||
|
||
If you deployed the ``custom-transforms`` artifact as a system artifact, the scope is ``system``. | ||
If you deployed the ``custom-transforms`` artifact as a user artifact, the scope is ``user``. | ||
|
@@ -363,10 +386,9 @@ You can verify that the plugins in your newly-added artifact are available to it | |
specific type. For example, to check if ``cdap-etl-batch`` can access the plugins in the | ||
``custom-transforms`` artifact: | ||
|
||
.. container:: highlight | ||
.. tabbed-parsed-literal:: | ||
|
||
.. parsed-literal:: | ||
|$| curl -w'\\n' localhost:10000/v3/namespaces/default/artifacts/cdap-etl-batch/versions/|version|/extensions/transform?scope=system | ||
$ curl -w"\n" -X POST "localhost:10000/v3/namespaces/default/artifacts/cdap-etl-batch/versions/|version|/extensions/transform?scope=system" | ||
|
||
You can then check the list returned to see if your transforms are in the list. Note that | ||
the scope here refers to the scope of the parent artifact. In this example it is the ``system`` | ||
|
@@ -437,40 +459,40 @@ in those files into words, and then counts how many times each word appears. The | |
|
||
.. highlight:: console | ||
|
||
We package our code into a JAR file named ``wordcount-1.0.0.jar`` and add it to CDAP:: | ||
We package our code into a JAR file named ``wordcount-1.0.0.jar`` and add it to CDAP: | ||
|
||
.. tabbed-parsed-literal:: | ||
|
||
$ curl -w'\n' localhost:10000/v3/namespaces/default/artifacts/wordcount --data-binary @wordcount-1.0.0.jar | ||
$ curl -w"\n" -X POST "localhost:10000/v3/namespaces/default/artifacts/wordcount" --data-binary @wordcount-1.0.0.jar | ||
|
||
We then create an application from that artifact:: | ||
We then create an application from that artifact: | ||
|
||
$ curl -w'\n' -X PUT localhost:10000/v3/namespaces/default/apps/basicwordcount -H 'Content-Type: application/json' \ | ||
-d '{ | ||
"artifact": { "name": "wordcount", "version": "1.0.0", "scope": "user" } | ||
}' | ||
.. tabbed-parsed-literal:: | ||
|
||
$ curl -w"\n" -X PUT "localhost:10000/v3/namespaces/default/apps/basicwordcount" -H "Content-Type: application/json" \ | ||
-d "{ 'artifact': { 'name': 'wordcount', 'version': '1.0.0', 'scope': 'user' } }" | ||
|
||
This program runs just fine. It counts all words in the input. However, what if we want to count phrases | ||
instead of words? Or what if we want to filter out common words such as 'the' and 'a'? We would not want | ||
instead of words? Or what if we want to filter out common words such as ``'the'`` and ``'a'``? We would not want | ||
to copy and paste our application class and then make just small tweaks. | ||
|
||
.. rubric:: A Configurable Application | ||
|
||
Instead, we would like to be able to create applications that | ||
are configured to tokenize the line in different ways. That is, if we want an application that filters | ||
stopwords, we want to be able to create it through a configuration:: | ||
stopwords, we want to be able to create it through a configuration: | ||
|
||
$ curl -w'\n' -X PUT localhost:10000/v3/namespaces/default/apps/stopwordcount -H 'Content-Type: application/json' \ | ||
-d '{ | ||
"artifact": { "name": "wordcount", "version": "1.0.0", "scope": "user" }, | ||
"config": { "tokenizer": "stopword" } | ||
}' | ||
.. tabbed-parsed-literal:: | ||
|
||
Similarly, we want to be able to create an application that counts phrases through a configuration:: | ||
$ curl -w"\n" -X PUT "localhost:10000/v3/namespaces/default/apps/stopwordcount" -H "Content-Type: application/json" \ | ||
-d "{ 'artifact': { 'name': 'wordcount', 'version': '1.0.0', 'scope': 'user' }, 'config': { 'tokenizer': 'stopword' } }" | ||
|
||
Similarly, we want to be able to create an application that counts phrases through a configuration: | ||
|
||
$ curl -w'\n' -X PUT localhost:10000/v3/namespaces/default/apps/phrasecount -H 'Content-Type: application/json' \ | ||
-d '{ | ||
"artifact": { "name": "wordcount", "version": "1.0.0", "scope": "user" }, | ||
"config": { "tokenizer": "phrase" } | ||
}' | ||
.. tabbed-parsed-literal:: | ||
|
||
$ curl -w"\n" -X PUT "localhost:10000/v3/namespaces/default/apps/phrasecount" -H "Content-Type: application/json" \ | ||
-d "{ 'artifact': { 'name': 'wordcount', 'version': '1.0.0', 'scope': 'user' }, 'config': { 'tokenizer': 'phrase' } }" | ||
|
||
.. highlight:: java | ||
|
||
|
@@ -575,9 +597,9 @@ package in our pom.xml: | |
|
||
We then package the code in a new version of the artifact ``wordcount-1.1.0.jar`` and deploy it: | ||
|
||
.. code-block:: console | ||
.. tabbed-parsed-literal:: | ||
|
||
$ curl -w'\n' localhost:10000/v3/namespaces/default/artifacts/wordcount --data-binary @wordcount-1.1.0.jar | ||
$ curl -w"\n" -X POST "localhost:10000/v3/namespaces/default/artifacts/wordcount" --data-binary @wordcount-1.1.0.jar | ||
|
||
.. rubric:: Implementing Tokenizer Plugins | ||
|
||
|
@@ -665,19 +687,20 @@ we need to expose the ``com.example.tokenizer`` package in our pom.xml: | |
.. highlight:: console | ||
|
||
When deploying this artifact, we tell CDAP that the artifact extends the ``wordcount`` artifact, versions | ||
``1.1.0`` inclusive to ``2.0.0`` exclusive:: | ||
``1.1.0`` inclusive to ``2.0.0`` exclusive: | ||
|
||
.. tabbed-parsed-literal:: | ||
|
||
$ curl -w'\n' localhost:10000/v3/namespaces/default/artifacts/tokenizers --data-binary @tokenizers-1.0.0.jar \ | ||
-H 'Artifact-Extends:wordcount[1.1.0,2.0.0)' | ||
$ curl -w"\n" "localhost:10000/v3/namespaces/default/artifacts/tokenizers" --data-binary @tokenizers-1.0.0.jar \ | ||
-H "Artifact-Extends:wordcount[1.1.0,2.0.0)" | ||
|
||
This will make the plugins available to those versions of the ``wordcount`` artifact. We can now create | ||
applications that use the tokenizer we want:: | ||
applications that use the tokenizer we want: | ||
|
||
.. tabbed-parsed-literal:: | ||
|
||
$ curl -w'\n' -X PUT localhost:10000/v3/namespaces/default/apps/phrasecount -H 'Content-Type: application/json' \ | ||
-d '{ | ||
"artifact": { "name": "wordcount", "version": "1.1.0", "scope": "user" }, | ||
"config": { "tokenizer": "phrase" } | ||
}' | ||
$ curl -w"\n" -X PUT localhost:10000/v3/namespaces/default/apps/phrasecount -H "Content-Type: application/json" \ | ||
-d "{ 'artifact': { 'name': 'wordcount', 'version': '1.1.0', 'scope': 'user' }, 'config': { 'tokenizer': 'phrase' } }" | ||
|
||
.. rubric:: Adding a Plugin Configuration to the Application | ||
|
||
|
@@ -734,14 +757,13 @@ property must be given when registering the plugin:: | |
|
||
.. highlight:: console | ||
|
||
Now we can create an application that uses a comma instead of a space to split text:: | ||
Now we can create an application that uses a comma instead of a space to split text (re-formatted for display): | ||
|
||
$ curl -w'\n' -X PUT localhost:10000/v3/namespaces/default/apps/wordcount2 -H 'Content-Type: application/json' \ | ||
-d '{ | ||
"artifact": { "name": "wordcount", "version": "1.2.0", "scope": "user" }, | ||
"config": { | ||
"tokenizer": "default", | ||
"tokenizerProperties": { "delimiter": "," } | ||
} | ||
}' | ||
.. tabbed-parsed-literal:: | ||
|
||
$ curl -w"\n" -X PUT "localhost:10000/v3/namespaces/default/apps/wordcount2" -H "Content-Type: application/json" \ | ||
-d "{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can't change quotes, this is no longer valid json There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same comment about other similar changes in this commit |
||
'artifact': { 'name': 'wordcount', 'version': '1.2.0', 'scope': 'user' }, | ||
'config': { 'tokenizer': 'default', 'tokenizerProperties': { 'delimiter': ',' } | ||
} | ||
}" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can't swap the quotes, this is no longer valid json.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have had to do this in the examples (swap quotes) otherwise they don't work under Windows.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See http://docs.cask.co/cdap/3.4.0-SNAPSHOT/en/examples-manual/examples/log-analysis.html#running-the-example under "Querying the Results":
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This means all our Windows examples will need to change, as they require the double-quotes on the outside, to
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
o i guess it is fine then. Don't know why the linter I tried choked on it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, when I went and looked up the spec, it does say double-quotes, so I think you are correct there. See http://www.json.org