You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by he...@apache.org on 2021/08/10 11:12:53 UTC

[brooklyn-server] branch master updated (1becadb -> 462e246)

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

heneveld pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/brooklyn-server.git.


    from 1becadb  This closes #1218
     new 5cab8a3  correctly handle multiple private keys supplied (including as default)
     new 462e246  skip redundant and possibly deadlocking tasks on shutdown

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:
 .../apache/brooklyn/core/mgmt/ha/OsgiManager.java  |  5 +++
 .../util/core/internal/ssh/SshAbstractTool.java    | 38 +++++++++++++++++-----
 2 files changed, 34 insertions(+), 9 deletions(-)

[brooklyn-server] 02/02: skip redundant and possibly deadlocking tasks on shutdown

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

heneveld pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/brooklyn-server.git

commit 462e246a056451308eaf51282beb6060d92b4db3
Author: Alex Heneveld <al...@cloudsoftcorp.com>
AuthorDate: Tue Aug 10 12:12:32 2021 +0100

    skip redundant and possibly deadlocking tasks on shutdown
---
 core/src/main/java/org/apache/brooklyn/core/mgmt/ha/OsgiManager.java | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/core/src/main/java/org/apache/brooklyn/core/mgmt/ha/OsgiManager.java b/core/src/main/java/org/apache/brooklyn/core/mgmt/ha/OsgiManager.java
index 79b8174..5fe3eec 100644
--- a/core/src/main/java/org/apache/brooklyn/core/mgmt/ha/OsgiManager.java
+++ b/core/src/main/java/org/apache/brooklyn/core/mgmt/ha/OsgiManager.java
@@ -302,6 +302,7 @@ public class OsgiManager {
         
         if (!reuseFramework || !REUSED_FRAMEWORKS_ARE_KEPT_RUNNING) {
             try {
+                /* if not re-using, don't do this, because we might be being called _from_ the osgi shutdown process (can cause deadlock on karaf shutdown)
                 for (Bundle b: framework.getBundleContext().getBundles()) {
                     if ((bundlesAtStartup==null || !bundlesAtStartup.contains(b)) && (b!=framework)) {
                         try {
@@ -317,6 +318,10 @@ public class OsgiManager {
                 framework.stop();
                 final FrameworkEvent fe = framework.waitForStop(Duration.seconds(30).toMilliseconds());
                 log.debug("Stopped OSGi framework: "+fe);
+                 */
+
+                framework.stop();
+
             } catch (Exception e) {
                 throw Exceptions.propagate(e);
             }

[brooklyn-server] 01/02: correctly handle multiple private keys supplied (including as default)

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

heneveld pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/brooklyn-server.git

commit 5cab8a38b60d6e3dfa6ec59bc13bfa030943c49b
Author: Alex Heneveld <al...@cloudsoftcorp.com>
AuthorDate: Tue Aug 10 12:08:42 2021 +0100

    correctly handle multiple private keys supplied (including as default)
---
 .../util/core/internal/ssh/SshAbstractTool.java    | 38 +++++++++++++++++-----
 1 file changed, 29 insertions(+), 9 deletions(-)

diff --git a/core/src/main/java/org/apache/brooklyn/util/core/internal/ssh/SshAbstractTool.java b/core/src/main/java/org/apache/brooklyn/util/core/internal/ssh/SshAbstractTool.java
index 612ccff..f65a622 100644
--- a/core/src/main/java/org/apache/brooklyn/util/core/internal/ssh/SshAbstractTool.java
+++ b/core/src/main/java/org/apache/brooklyn/util/core/internal/ssh/SshAbstractTool.java
@@ -20,6 +20,7 @@ package org.apache.brooklyn.util.core.internal.ssh;
 
 import static com.google.common.base.Preconditions.checkArgument;
 import static com.google.common.base.Preconditions.checkNotNull;
+import java.util.Arrays;
 import static org.apache.brooklyn.util.net.Networking.checkPortValid;
 
 import java.io.File;
@@ -31,9 +32,13 @@ import org.apache.brooklyn.util.os.Os;
 
 import com.google.common.collect.Iterables;
 import com.google.common.collect.Sets;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public abstract class SshAbstractTool extends ShellAbstractTool implements SshTool {
 
+    private static final Logger LOG = LoggerFactory.getLogger(SshAbstractTool.class);
+
     protected final String toString;
 
     protected final String host;
@@ -83,7 +88,9 @@ public abstract class SshAbstractTool extends ShellAbstractTool implements SshTo
             // but sshj accepts only a single privateKeyFile; leave blank to use defaults (i.e. ~/.ssh/id_rsa and id_dsa)
             warnOnDeprecated(props, "keyFiles", null);
             String privateKeyFile = getOptionalVal(props, PROP_PRIVATE_KEY_FILE);
-            if (privateKeyFile != null) privateKeyFiles.add(privateKeyFile);
+            if (privateKeyFile != null) {
+                privateKeyFiles.addAll(Arrays.asList(privateKeyFile.split(File.pathSeparator)));
+            }
             
             strictHostKeyChecking = getOptionalVal(props, PROP_STRICT_HOST_KEY_CHECKING);
             allocatePTY = getOptionalVal(props, PROP_ALLOCATE_PTY);
@@ -136,14 +143,27 @@ public abstract class SshAbstractTool extends ShellAbstractTool implements SshTo
         allocatePTY = builder.allocatePTY;
         privateKeyPassphrase = builder.privateKeyPassphrase;
         privateKeyData = builder.privateKeyData;
-        
-        if (builder.privateKeyFiles.size() > 1) {
-            throw new IllegalArgumentException("sshj supports only a single private key-file; " +
-                    "for defaults of ~/.ssh/id_rsa and ~/.ssh/id_dsa leave blank");
-        } else if (builder.privateKeyFiles.size() == 1) {
-            String privateKeyFileStr = Iterables.get(builder.privateKeyFiles, 0);
-            String amendedKeyFile = privateKeyFileStr.startsWith("~") ? (System.getProperty("user.home")+privateKeyFileStr.substring(1)) : privateKeyFileStr;
-            privateKeyFile = new File(amendedKeyFile);
+
+        String keyFile = null;
+        String lastCandidate = null;
+
+        for (String candidate: builder.privateKeyFiles) {
+            lastCandidate = candidate.startsWith("~") ? (System.getProperty("user.home")+candidate.substring(1)) : candidate;
+            if (new File(lastCandidate).exists()) {
+                keyFile = lastCandidate;
+                break;
+            }
+        }
+        if (keyFile==null) {
+            if (builder.privateKeyFiles.size()==1) {
+                // probably won't work, but use a single file if specified
+                keyFile = lastCandidate;
+            } else if (builder.privateKeyFiles.size()>1 && privateKeyData==null) {
+                LOG.trace("None of the key files exist; unlikely for SSH to succeed");
+            }
+        }
+        if (keyFile!=null) {
+            privateKeyFile = new File(keyFile);
         } else {
             privateKeyFile = null;
         }