You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by or...@apache.org on 2021/08/23 09:37:49 UTC
[camel] branch main updated: Added support for initializing Kamelet
bindings from Camel JBang (#5969)
This is an automated email from the ASF dual-hosted git repository.
orpiske pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new b0ca162 Added support for initializing Kamelet bindings from Camel JBang (#5969)
b0ca162 is described below
commit b0ca162d2ffed49e640a03df70912864bf6b5642
Author: Otavio Rodolfo Piske <or...@users.noreply.github.com>
AuthorDate: Mon Aug 23 11:37:12 2021 +0200
Added support for initializing Kamelet bindings from Camel JBang (#5969)
---
.../modules/ROOT/pages/camel-jbang.adoc | 24 ++++++++++-
.../camel-jbang-main/dist/CamelJBang.java | 50 +++++++++++++++++++++-
.../src/main/jbang/main/CamelJBang.java | 50 +++++++++++++++++++++-
3 files changed, 121 insertions(+), 3 deletions(-)
diff --git a/docs/user-manual/modules/ROOT/pages/camel-jbang.adoc b/docs/user-manual/modules/ROOT/pages/camel-jbang.adoc
index cb7629a..79b6cc9 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-jbang.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-jbang.adoc
@@ -73,7 +73,7 @@ The same behavior also works for all the other search commands. The table below
[[CamelJBang-Init-Kamets]]
-== Search Init
+== Init Kamelets
The init sub-command can be used to simplify creating Kamelets. Through this command, it is possible to create new Kamelets through pre-configured templates. It works in two steps: first it is necessary to bootstrap the Kamelet by creating a properties file with the parameters necessary to create the Kamelet. Once the properties file is correctly set, then it is possible to create a pre-filled Kamelet by processing that properties file.
@@ -100,6 +100,28 @@ Running this command will create a new file in the `work` directory. The name of
After the file is generated, it may still need to require final adjustments, such as correctly setting the name, the icon and other requirements for official Kamelets. Please consult the Kamelet development documentation for updated details.
+[[CamelJBang-Init-Bindings]]
+== Init Bindings
+
+The init sub-command can also be used to simplify creating Kamelets bindings. Through this command, it is possible to create new bindings through pre-configured templates. Use the `--kamelet` option (you can list the available ones using the search command) to set the Kamelet to generate the binding for.
+
+To execute this feature run:
+
+[source,bash]
+----
+CamelJBang init binding --destination /path/to/destination/directory/ --kamelet sftp-source
+----
+
+This will create a new sample YAML binding file that can be modified and used in Camel K.
+
+You can also generate bindings that can be run by CamelJBang or Camel Core, but setting the `--project` option:
+
+[source,bash]
+----
+CamelJBang init binding --destination /path/to/destination/directory/ --kamelet sftp-source --project core
+----
+
+
[[CamelJBang-Running]]
== Running Routes
diff --git a/dsl/camel-jbang/camel-jbang-main/dist/CamelJBang.java b/dsl/camel-jbang/camel-jbang-main/dist/CamelJBang.java
index ff013fa..a705685 100755
--- a/dsl/camel-jbang/camel-jbang-main/dist/CamelJBang.java
+++ b/dsl/camel-jbang/camel-jbang-main/dist/CamelJBang.java
@@ -532,7 +532,54 @@ class InitKamelet extends AbstractInitKamelet implements Callable<Integer> {
return 1;
}
}
+}
+
+@Command(name = "binding", description = "Provide init templates for kamelet bindings")
+class InitBinding extends AbstractInitKamelet implements Callable<Integer> {
+ @Option(names = { "-h", "--help" }, usageHelp = true, description = "Display the help and sub-commands")
+ private boolean helpRequested = false;
+
+ @Option(names = { "--base-resource-location" }, defaultValue = "github:apache", hidden = true,
+ description = "Where to download the resources from (used for development/testing)")
+ private String baseResourceLocation;
+
+ @Option(names = { "--branch" }, defaultValue = "main", hidden = true,
+ description = "The branch to use when downloading resources from (used for development/testing)")
+ private String branch;
+
+ @Option(names = { "--destination" }, defaultValue = "work",
+ description = "The destination directory where to download the files")
+ private String destination;
+
+ @Option(names = { "--kamelet" }, defaultValue = "",
+ description = "The kamelet to create a binding for")
+ private String kamelet;
+ @Option(names = { "--project" }, defaultValue = "camel-k",
+ description = "The project to create a binding for (either camel-k or core)")
+ private String project;
+
+ private int downloadSample() throws IOException, CamelException {
+ setBranch(branch);
+
+ String resourcePath = String.format("camel-kamelets:templates/bindings/%s/%s-binding.yaml", project, kamelet);
+
+ setResourceLocation(baseResourceLocation, resourcePath);
+
+ try {
+ resolveResource(new File(destination));
+ } catch (ResourceAlreadyExists e) {
+ System.err.println(e.getMessage());
+ return 1;
+ }
+
+ return 0;
+ }
+
+ @Override
+ public Integer call() throws Exception {
+ return downloadSample();
+ }
}
@Command(name = "CamelJBang", mixinStandardHelpOptions = true, version = "CamelJBang 3.12.0-SNAPSHOT",
@@ -553,7 +600,8 @@ public class CamelJBang implements Callable<Integer> {
.addSubcommand("languages", new SearchLanguages())
.addSubcommand("others", new SearchOthers()))
.addSubcommand("init", new CommandLine(new Init())
- .addSubcommand("kamelet", new InitKamelet()));
+ .addSubcommand("kamelet", new InitKamelet())
+ .addSubcommand("binding", new InitBinding()));
int exitCode = commandLine.execute(args);
System.exit(exitCode);
diff --git a/dsl/camel-jbang/camel-jbang-main/src/main/jbang/main/CamelJBang.java b/dsl/camel-jbang/camel-jbang-main/src/main/jbang/main/CamelJBang.java
index f1d2989..6e61124 100755
--- a/dsl/camel-jbang/camel-jbang-main/src/main/jbang/main/CamelJBang.java
+++ b/dsl/camel-jbang/camel-jbang-main/src/main/jbang/main/CamelJBang.java
@@ -532,7 +532,54 @@ class InitKamelet extends AbstractInitKamelet implements Callable<Integer> {
return 1;
}
}
+}
+
+@Command(name = "binding", description = "Provide init templates for kamelet bindings")
+class InitBinding extends AbstractInitKamelet implements Callable<Integer> {
+ @Option(names = { "-h", "--help" }, usageHelp = true, description = "Display the help and sub-commands")
+ private boolean helpRequested = false;
+
+ @Option(names = { "--base-resource-location" }, defaultValue = "github:apache", hidden = true,
+ description = "Where to download the resources from (used for development/testing)")
+ private String baseResourceLocation;
+
+ @Option(names = { "--branch" }, defaultValue = "main", hidden = true,
+ description = "The branch to use when downloading resources from (used for development/testing)")
+ private String branch;
+
+ @Option(names = { "--destination" }, defaultValue = "work",
+ description = "The destination directory where to download the files")
+ private String destination;
+
+ @Option(names = { "--kamelet" }, defaultValue = "",
+ description = "The kamelet to create a binding for")
+ private String kamelet;
+ @Option(names = { "--project" }, defaultValue = "camel-k",
+ description = "The project to create a binding for (either camel-k or core)")
+ private String project;
+
+ private int downloadSample() throws IOException, CamelException {
+ setBranch(branch);
+
+ String resourcePath = String.format("camel-kamelets:templates/bindings/%s/%s-binding.yaml", project, kamelet);
+
+ setResourceLocation(baseResourceLocation, resourcePath);
+
+ try {
+ resolveResource(new File(destination));
+ } catch (ResourceAlreadyExists e) {
+ System.err.println(e.getMessage());
+ return 1;
+ }
+
+ return 0;
+ }
+
+ @Override
+ public Integer call() throws Exception {
+ return downloadSample();
+ }
}
@Command(name = "CamelJBang", mixinStandardHelpOptions = true, version = "CamelJBang ${camel.jbang.version}",
@@ -553,7 +600,8 @@ public class CamelJBang implements Callable<Integer> {
.addSubcommand("languages", new SearchLanguages())
.addSubcommand("others", new SearchOthers()))
.addSubcommand("init", new CommandLine(new Init())
- .addSubcommand("kamelet", new InitKamelet()));
+ .addSubcommand("kamelet", new InitKamelet())
+ .addSubcommand("binding", new InitBinding()));
int exitCode = commandLine.execute(args);
System.exit(exitCode);