You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2022/08/18 08:42:12 UTC

[camel] branch main updated (69843edfe04 -> 7a63e10c5a6)

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a change to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


    from 69843edfe04 Update hadoop3 version to 3.3.4 (#8172)
     new 3fd87499ec3 CAMEL-18389: camel-jbang - camel ps til list running camel applications.
     new 7a63e10c5a6 CAMEL-18389: camel-jbang - camel ps til list running camel applications.

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../modules/ROOT/pages/camel-jbang.adoc            | 18 +++++
 .../dsl/jbang/core/commands/CamelJBangMain.java    |  1 +
 .../camel/dsl/jbang/core/commands/ListProcess.java | 84 ++++++++++++++++++++++
 3 files changed, 103 insertions(+)
 create mode 100644 dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ListProcess.java


[camel] 01/02: CAMEL-18389: camel-jbang - camel ps til list running camel applications.

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 3fd87499ec364633f4b856f3547e2e050dcc41f7
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu Aug 18 10:08:09 2022 +0200

    CAMEL-18389: camel-jbang - camel ps til list running camel applications.
---
 .../dsl/jbang/core/commands/CamelJBangMain.java    |  1 +
 .../camel/dsl/jbang/core/commands/ListProcess.java | 84 ++++++++++++++++++++++
 2 files changed, 85 insertions(+)

diff --git a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/CamelJBangMain.java b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/CamelJBangMain.java
index 05f370032d7..1f97191f857 100644
--- a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/CamelJBangMain.java
+++ b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/CamelJBangMain.java
@@ -31,6 +31,7 @@ public class CamelJBangMain implements Callable<Integer> {
         CamelJBangMain main = new CamelJBangMain();
         commandLine = new CommandLine(main)
                 .addSubcommand("run", new CommandLine(new Run(main)))
+                .addSubcommand("ps", new CommandLine(new ListProcess(main)))
                 .addSubcommand("init", new CommandLine(new Init(main)))
                 .addSubcommand("bind", new CommandLine(new Bind(main)))
                 .addSubcommand("pipe", new CommandLine(new Pipe(main)))
diff --git a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ListProcess.java b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ListProcess.java
new file mode 100644
index 00000000000..97aa43f0ae9
--- /dev/null
+++ b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ListProcess.java
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.dsl.jbang.core.commands;
+
+import org.apache.camel.util.ObjectHelper;
+import org.apache.camel.util.StringHelper;
+import org.apache.camel.util.TimeUtils;
+import picocli.CommandLine;
+import picocli.CommandLine.Command;
+
+@Command(name = "ps", description = "List running Camel applications")
+class ListProcess extends CamelCommand {
+
+    @CommandLine.Option(names = { "--sort" },
+            description = "Sort by pid, name or age", defaultValue = "pid")
+    private String sort;
+
+    public ListProcess(CamelJBangMain main) {
+        super(main);
+    }
+
+    @Override
+    public Integer call() throws Exception {
+        ProcessHandle.allProcesses()
+                .sorted((o1, o2) -> {
+                    int answer = 0;
+                    switch (sort) {
+                        case "pid":
+                            answer = Long.compare(o1.pid(), o2.pid());
+                            break;
+                        case "name":
+                            answer = extractName(o1).compareTo(extractName(o2));
+                            break;
+                        case "age":
+                            // we want newest in top
+                            answer = Long.compare(extractSince(o1), extractSince(o2)) * -1;
+                            break;
+                    }
+                    return answer;
+                })
+                .forEach(ph -> {
+            String name = extractName(ph);
+            if (ObjectHelper.isNotEmpty(name)) {
+                String ago = TimeUtils.printSince(extractSince(ph));
+                System.out.println(ph.pid() + " camel run " + name + " (age: " + ago + ")");
+            }
+        });
+        return 0;
+    }
+
+    private static String extractName(ProcessHandle ph) {
+        String cl = ph.info().commandLine().orElse("");
+        String name = StringHelper.after(cl, "main.CamelJBang run");
+        if (name != null) {
+            name = name.trim();
+        } else {
+            name = "";
+        }
+        return name;
+    }
+
+    private static long extractSince(ProcessHandle ph) {
+        long since = 0;
+        if (ph.info().startInstant().isPresent()) {
+            since = ph.info().startInstant().get().toEpochMilli();
+        }
+        return since;
+    }
+
+}


[camel] 02/02: CAMEL-18389: camel-jbang - camel ps til list running camel applications.

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 7a63e10c5a66572189dc89531377768e4e19aed4
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu Aug 18 10:41:59 2022 +0200

    CAMEL-18389: camel-jbang - camel ps til list running camel applications.
---
 docs/user-manual/modules/ROOT/pages/camel-jbang.adoc | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/docs/user-manual/modules/ROOT/pages/camel-jbang.adoc b/docs/user-manual/modules/ROOT/pages/camel-jbang.adoc
index da896f15d95..a3b974818d7 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-jbang.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-jbang.adoc
@@ -441,6 +441,9 @@ You can specify which Camel version to run as shown:
 jbang run -Dcamel.jbang.version=3.17.0 camel@apache/camel [command]
 ----
 
+NOTE: Older versions of Camel may not work as well with Camel JBang as the newest versions.
+Starting from Camel 3.18 onwards is the versions that are recommended to be used onwards.
+
 And you can also try bleeding edge development by using SNAPSHOT such as:
 
 [source,bash]
@@ -515,6 +518,21 @@ For example. you can copy this to your clipboard and then run it afterwards:
 camel run clipboard.xml
 ----
 
+=== Controlling local Camel applications
+
+To list the currently running Camel JBang applications you use the `ps` command:
+
+[source,bash]
+----
+camel ps
+37928 camel run foo.yaml (age: 20h18m)
+44805 camel run dude.java (age: 58s)
+----
+
+This lists the PID, the name and age of the application.
+
+NOTE: Additional commands are in the works.
+
 === Scripting from terminal using pipes
 
 You can also execute a Camel JBang file as a script that can be used for terminal scripting with pipes and filters.