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


The following commit(s) were added to refs/heads/master by this push:
     new acdbee92cb minor tweaks to software process driver to allow running 
without a location
acdbee92cb is described below

commit acdbee92cb8224871220f6576230322e0344624b
Author: Alex Heneveld <[email protected]>
AuthorDate: Fri May 12 12:06:40 2023 +0100

    minor tweaks to software process driver to allow running without a location
---
 .../base/AbstractSoftwareProcessDriver.java        |  9 +++++----
 .../base/AbstractSoftwareProcessSshDriver.java     | 23 ++++++++++++++++------
 2 files changed, 22 insertions(+), 10 deletions(-)

diff --git 
a/software/base/src/main/java/org/apache/brooklyn/entity/software/base/AbstractSoftwareProcessDriver.java
 
b/software/base/src/main/java/org/apache/brooklyn/entity/software/base/AbstractSoftwareProcessDriver.java
index 9f0cca99ee..a1c74a3792 100644
--- 
a/software/base/src/main/java/org/apache/brooklyn/entity/software/base/AbstractSoftwareProcessDriver.java
+++ 
b/software/base/src/main/java/org/apache/brooklyn/entity/software/base/AbstractSoftwareProcessDriver.java
@@ -88,7 +88,7 @@ public abstract class AbstractSoftwareProcessDriver 
implements SoftwareProcessDr
 
     public AbstractSoftwareProcessDriver(EntityLocal entity, Location 
location) {
         this.entity = checkNotNull(entity, "entity");
-        this.location = checkNotNull(location, "location");
+        this.location = location;  // shouldn't normally be null, but useful 
in some cases where SSH driver is subclassed for other purposes
         this.resource = ResourceUtils.create(entity);
     }
 
@@ -124,7 +124,8 @@ public abstract class AbstractSoftwareProcessDriver 
implements SoftwareProcessDr
     @Override
     public void start() {
         boolean skipStart = false;
-        Optional<Boolean> locationRunning = 
Optional.fromNullable(getLocation().getConfig(BrooklynConfigKeys.SKIP_ENTITY_START_IF_RUNNING));
+        final Location l = getLocation();
+        Optional<Boolean> locationRunning = Optional.fromNullable(l==null ? 
null : l.getConfig(BrooklynConfigKeys.SKIP_ENTITY_START_IF_RUNNING));
         Optional<Boolean> entityRunning = 
Optional.fromNullable(entity.getConfig(BrooklynConfigKeys.SKIP_ENTITY_START_IF_RUNNING));
         Optional<Boolean> entityStarted = 
Optional.fromNullable(entity.getConfig(BrooklynConfigKeys.SKIP_ENTITY_START));
         if (locationRunning.or(entityRunning).or(false)) {
@@ -139,7 +140,7 @@ public abstract class AbstractSoftwareProcessDriver 
implements SoftwareProcessDr
 
         if (!skipStart) {
             DynamicTasks.queue("install", new Runnable() { @Override public 
void run() {
-                Optional<Boolean> locationInstalled = 
Optional.fromNullable(getLocation().getConfig(BrooklynConfigKeys.SKIP_ENTITY_INSTALLATION));
+                Optional<Boolean> locationInstalled = 
Optional.fromNullable(l==null ? null : 
l.getConfig(BrooklynConfigKeys.SKIP_ENTITY_INSTALLATION));
                 Optional<Boolean> entityInstalled = 
Optional.fromNullable(entity.getConfig(BrooklynConfigKeys.SKIP_ENTITY_INSTALLATION));
 
                 boolean skipInstall = 
locationInstalled.or(entityInstalled).or(false);
@@ -758,7 +759,7 @@ public abstract class AbstractSoftwareProcessDriver 
implements SoftwareProcessDr
     public void setExpandedInstallDir(String val) {
         String oldVal = 
getEntity().getAttribute(SoftwareProcess.EXPANDED_INSTALL_DIR);
         if (Strings.isNonBlank(oldVal) && !oldVal.equals(val)) {
-            log.info("Resetting expandedInstallDir (to "+val+" from 
"+oldVal+") for "+getEntity());
+            log.debug("Resetting expandedInstallDir (to "+val+" from 
"+oldVal+") for "+getEntity());
         }
 
         expandedInstallDir = val;
diff --git 
a/software/base/src/main/java/org/apache/brooklyn/entity/software/base/AbstractSoftwareProcessSshDriver.java
 
b/software/base/src/main/java/org/apache/brooklyn/entity/software/base/AbstractSoftwareProcessSshDriver.java
index 20c3dbc282..8d626c4db5 100644
--- 
a/software/base/src/main/java/org/apache/brooklyn/entity/software/base/AbstractSoftwareProcessSshDriver.java
+++ 
b/software/base/src/main/java/org/apache/brooklyn/entity/software/base/AbstractSoftwareProcessSshDriver.java
@@ -43,6 +43,7 @@ import org.apache.brooklyn.location.ssh.SshMachineLocation;
 import org.apache.brooklyn.util.core.file.BrooklynOsCommands;
 import org.apache.brooklyn.util.core.internal.ssh.SshTool;
 import org.apache.brooklyn.util.core.internal.ssh.sshj.SshjTool;
+import org.apache.brooklyn.util.core.mutex.MutexSupport;
 import org.apache.brooklyn.util.core.mutex.WithMutexes;
 import org.apache.brooklyn.util.core.task.DynamicTasks;
 import org.apache.brooklyn.util.core.task.Tasks;
@@ -107,7 +108,7 @@ public abstract class AbstractSoftwareProcessSshDriver 
extends AbstractSoftwareP
 
         // FIXME this assumes we own the location, and causes warnings about 
configuring location after deployment;
         // better would be to wrap the ssh-execution-provider to supply these 
flags
-        if (getSshFlags()!=null && !getSshFlags().isEmpty())
+        if (getSshFlags()!=null && !getSshFlags().isEmpty() && machine!=null)
             machine.configure(getSshFlags());
 
         // ensure these are set using the routines below, not a global 
ConfigToAttributes.apply()
@@ -186,13 +187,23 @@ public abstract class AbstractSoftwareProcessSshDriver 
extends AbstractSoftwareP
                 flags.put("err", stderr);
             }
         }
-        if (!flags.containsKey("logPrefix")) flags.put("logPrefix", 
""+entity.getId()+"@"+getLocation().getDisplayName());
+        if (!flags.containsKey("logPrefix")) {
+            SshMachineLocation l = getLocation();
+            flags.put("logPrefix", "" + entity.getId() + (l!=null ? "@" + 
l.getDisplayName() : ""));
+        }
         return getMachine().execScript(flags, summaryForLogging, script, 
environment);
     }
 
+    private transient WithMutexes defaultMutexes = new MutexSupport();
+    protected WithMutexes getMutexes() {
+        SshMachineLocation l = getLocation();
+        if (l!=null) return l.mutexes();
+        return defaultMutexes;
+    }
+
     @Override
     public void copyPreInstallResources() {
-        final WithMutexes mutexSupport = getLocation().mutexes();
+        final WithMutexes mutexSupport = getMutexes();
         String mutexId = "installation lock at host";
         mutexSupport.acquireMutex(mutexId, "pre-installation lock at host for 
files and templates");
         try {
@@ -207,7 +218,7 @@ public abstract class AbstractSoftwareProcessSshDriver 
extends AbstractSoftwareP
 
     @Override
     public void copyInstallResources() {
-        final WithMutexes mutexSupport = getLocation().mutexes();
+        final WithMutexes mutexSupport = getMutexes();
         String mutexId = "installation lock at host";
         mutexSupport.acquireMutex(mutexId, "installation lock at host for 
files and templates");
         try {
@@ -222,7 +233,7 @@ public abstract class AbstractSoftwareProcessSshDriver 
extends AbstractSoftwareP
 
     @Override
     public void copyCustomizeResources() {
-        final WithMutexes mutexSupport = getLocation().mutexes();
+        final WithMutexes mutexSupport = getMutexes();
         String mutexId = "installation lock at host";
         mutexSupport.acquireMutex(mutexId, "installation lock at host for 
files and templates");
         try {
@@ -478,7 +489,7 @@ public abstract class AbstractSoftwareProcessSshDriver 
extends AbstractSoftwareP
             if (INSTALLING.equals(phase)) {
                 // mutexId should be global because otherwise package managers 
will contend with each other
                 final String mutexId = "installation lock at host";
-                s.useMutex(getLocation().mutexes(), mutexId, "installing 
"+elvis(entity,this));
+                s.useMutex(getMutexes(), mutexId, "installing 
"+elvis(entity,this));
                 s.header.append(
                         "export 
"+INSTALL_DIR_ENV_VAR+"=\""+getInstallDir()+"\"",
                         "mkdir -p $"+INSTALL_DIR_ENV_VAR,

Reply via email to