Improve deployment
authorMathieu Baudier <mbaudier@argeo.org>
Fri, 23 Apr 2010 12:34:06 +0000 (12:34 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Fri, 23 Apr 2010 12:34:06 +0000 (12:34 +0000)
git-svn-id: https://svn.argeo.org/slc/trunk@3495 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/deploy/LocalFilesDeployment.java
runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/deploy/MultiResourceSet.java
runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/FileExecutionResources.java
runtime/org.argeo.slc.support.osgi/src/main/java/org/argeo/slc/osgi/OsgiExecutionResources.java
runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/jsch/RemoteExec.java
runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/jsch/SshFilesDeployment.java
runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/lib/linux/RedhatDeploymentData.java [new file with mode: 0644]
runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/lib/linux/RedhatHostManager.java [new file with mode: 0644]
runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/lib/linux/RpmDistribution.java [new file with mode: 0644]
runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/lib/linux/SimpleLinuxHost.java [new file with mode: 0644]

index a2e372dde04c2b0e0b2501f8019537af3bbec94e..d339b94027aa0b6907acfe303cd7fa634b3200a3 100644 (file)
@@ -15,6 +15,13 @@ public class LocalFilesDeployment implements Runnable {
        private String targetBase = "";
        private ResourceSet resourceSet;
 
+       public LocalFilesDeployment() {
+       }
+
+       public LocalFilesDeployment(ResourceSet resourceSet) {
+               this.resourceSet = resourceSet;
+       }
+
        public void run() {
                Map<String, Resource> resources = resourceSet.listResources();
                for (String relPath : resources.keySet()) {
index d08e56ced053a261b9778bd95c64ae04dab730b0..20867128e8788bc6221431fa1cb2ac5ddca0afc6 100644 (file)
@@ -23,4 +23,8 @@ public class MultiResourceSet implements ResourceSet {
                this.resourceSets = resourceSets;
        }
 
+       public List<ResourceSet> getResourceSets() {
+               return resourceSets;
+       }
+
 }
index 0f3a8dc5841051cca98785f68c2967e8280ea66b..e1cd26b7a821367cbd068419f26747ed90330080 100644 (file)
@@ -83,6 +83,9 @@ public class FileExecutionResources implements ExecutionResources {
                File file = fileFromResource(resource);
                if (file != null)
                        try {
+                               if (log.isTraceEnabled())
+                                       log.debug("Directly interpret " + resource + " as OS file "
+                                                       + file);
                                return file.getCanonicalPath();
                        } catch (IOException e1) {
                                // silent
index 5582d9ca02f3df556f26e953e43ba4ed663352da..1d1cadb53b11d4a27114d1945960e8d7b0c7fd93 100644 (file)
@@ -46,13 +46,18 @@ public class OsgiExecutionResources extends FileExecutionResources implements
                        // TODO: Equinox specific?
                        String relPath = location.substring("initial@reference:file:"
                                        .length());
-                       if (relPath.startsWith("../"))// relative to the framework jar
-                               relPath = relPath.substring("../".length());
-                       String framework = System.getProperty("osgi.framework").substring(
-                                       "file:".length());
-                       int sepIndex = framework.lastIndexOf(File.separatorChar);
-                       framework = framework.substring(0, sepIndex);
-                       base = framework + '/' + relPath;
+//                     if (relPath.startsWith("../"))// relative to the framework jar
+//                             relPath = relPath.substring("../".length());
+//                     String framework = System.getProperty("osgi.framework").substring(
+//                                     "file:".length());
+//                     log.debug(framework);
+                       String installArea = System.getProperty("osgi.install.area")
+                                       .substring("file:".length());
+//                     log.debug(installArea);
+                       base = installArea + '/' + relPath;
+                       // int sepIndex = framework.lastIndexOf(File.separatorChar);
+                       // framework = framework.substring(0, sepIndex);
+                       // base = framework + '/' + relPath;
                } else {
                        return null;
                }
@@ -64,6 +69,12 @@ public class OsgiExecutionResources extends FileExecutionResources implements
                        throw new SlcException("Cannot determine canonical path for "
                                        + path, e);
                }
+
+               if (!file.exists())
+                       throw new SlcException(file
+                                       + " was retrieved in bundle located at '" + location
+                                       + "' for resource " + resource + " but it does not exist");
+
                if (log.isTraceEnabled())
                        log.debug("OSGi local resource: " + file + " from " + resource);
                return file;
index 39305fcc4760e9c3e55cb45c06cf2e68f91dab18..9569be35b31a3ab06d9fca5c0e854a6a5cab57de 100644 (file)
@@ -58,6 +58,14 @@ public class RemoteExec extends AbstractJschTask {
        private Boolean logEvenIfStdOutLines = false;
        private Boolean quiet = false;
 
+       public RemoteExec() {
+       }
+
+       public RemoteExec(SshTarget sshTarget, String cmd) {
+               setSshTarget(sshTarget);
+               setCommand(cmd);
+       }
+
        public void run(Session session) {
                List<String> commandsToUse = new ArrayList<String>(commands);
                String commandToUse = command;
index c4643935c10d6eaac9d96c31f29134a367d7238c..53670e14de95691b7f279c7e4c0ea71d979029f7 100644 (file)
@@ -26,6 +26,14 @@ public class SshFilesDeployment extends AbstractJschTask implements Runnable {
        private String checksum = "MD5";
        private int remoteChecksumsPerCall = 20;
 
+       public SshFilesDeployment() {
+       }
+
+       public SshFilesDeployment(SshTarget sshTarget, ResourceSet resourceSet) {
+               setSshTarget(sshTarget);
+               this.resourceSet = resourceSet;
+       }
+
        @Override
        void run(Session session) {
                JschMultiTasks multiTasks = new JschMultiTasks();
diff --git a/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/lib/linux/RedhatDeploymentData.java b/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/lib/linux/RedhatDeploymentData.java
new file mode 100644 (file)
index 0000000..8e1f29a
--- /dev/null
@@ -0,0 +1,55 @@
+package org.argeo.slc.lib.linux;
+
+import org.argeo.slc.core.deploy.MultiResourceSet;
+import org.argeo.slc.core.deploy.ResourceSet;
+import org.argeo.slc.deploy.DeploymentData;
+
+public class RedhatDeploymentData implements DeploymentData {
+       private ResourceSet configurationFiles;
+       private String runlevelsScript;
+       private String permissionsScript;
+
+       private RedhatDeploymentData parent;
+
+       public ResourceSet getConfigurationFiles() {
+               if (parent != null && parent.getConfigurationFiles() != null) {
+                       MultiResourceSet mrs = new MultiResourceSet();
+                       mrs.getResourceSets().add(parent.getConfigurationFiles());
+                       mrs.getResourceSets().add(configurationFiles);
+                       return mrs;
+               } else {
+                       return configurationFiles;
+               }
+       }
+
+       public String getRunlevelsScript() {
+               if (parent != null && parent.getRunlevelsScript() != null)
+                       return parent.getRunlevelsScript() + "\n" + runlevelsScript;
+               else
+                       return runlevelsScript;
+       }
+
+       public String getPermissionsScript() {
+               if (parent != null && parent.getPermissionsScript() != null)
+                       return parent.getPermissionsScript() + "\n" + permissionsScript;
+               else
+                       return permissionsScript;
+       }
+
+       public void setRunlevelsScript(String runlevelsScript) {
+               this.runlevelsScript = runlevelsScript;
+       }
+
+       public void setConfigurationFiles(ResourceSet configurationFiles) {
+               this.configurationFiles = configurationFiles;
+       }
+
+       public void setPermissionsScript(String permissionsScript) {
+               this.permissionsScript = permissionsScript;
+       }
+
+       public void setParent(RedhatDeploymentData parentDeploymentData) {
+               this.parent = parentDeploymentData;
+       }
+
+}
diff --git a/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/lib/linux/RedhatHostManager.java b/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/lib/linux/RedhatHostManager.java
new file mode 100644 (file)
index 0000000..a92a969
--- /dev/null
@@ -0,0 +1,73 @@
+package org.argeo.slc.lib.linux;
+
+import org.argeo.slc.SlcException;
+import org.argeo.slc.core.deploy.LocalFilesDeployment;
+import org.argeo.slc.core.deploy.ResourceSet;
+import org.argeo.slc.core.execution.tasks.SystemCall;
+import org.argeo.slc.jsch.RemoteExec;
+import org.argeo.slc.jsch.SshFilesDeployment;
+import org.argeo.slc.jsch.SshTarget;
+
+public class RedhatHostManager {
+
+       private SimpleLinuxHost host;
+
+       // SSH
+       private Boolean useSsh = true;
+       private SshTarget sshTarget = null;
+
+       public void installPackages() {
+               StringBuffer cmd = new StringBuffer("yum --nogpgcheck -y install");
+               for (String pkg : ((RpmDistribution) host.getDistribution())
+                               .getAdditionalPackages()) {
+                       cmd.append(' ').append(pkg);
+               }
+               executeCommand(cmd.toString());
+
+               RedhatDeploymentData rdd = (RedhatDeploymentData) host
+                               .getDeploymentData();
+               executeCommand(rdd.getRunlevelsScript());
+       }
+
+       public void deployConfig() {
+               RedhatDeploymentData rdd = (RedhatDeploymentData) host
+                               .getDeploymentData();
+               deploy(rdd.getConfigurationFiles());
+               executeCommand(rdd.getPermissionsScript());
+       }
+
+       // GENERIC?
+       protected void deploy(ResourceSet resourceSet) {
+               if (useSsh)
+                       new SshFilesDeployment(getSshTarget(), resourceSet).run();
+               else
+                       new LocalFilesDeployment(resourceSet).run();
+
+       }
+
+       protected void executeCommand(String command) {
+               if (useSsh)
+                       new RemoteExec(getSshTarget(), command).run();
+               else
+                       new SystemCall(command).run();
+       }
+
+       protected SshTarget getSshTarget() {
+               if (sshTarget == null)
+                       throw new SlcException("No SSH target defined");
+               return sshTarget;
+       }
+
+       public void setHost(SimpleLinuxHost host) {
+               this.host = host;
+       }
+
+       public void setUseSsh(Boolean useSsh) {
+               this.useSsh = useSsh;
+       }
+
+       public void setSshTarget(SshTarget sshTarget) {
+               this.sshTarget = sshTarget;
+       }
+
+}
diff --git a/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/lib/linux/RpmDistribution.java b/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/lib/linux/RpmDistribution.java
new file mode 100644 (file)
index 0000000..5214609
--- /dev/null
@@ -0,0 +1,23 @@
+package org.argeo.slc.lib.linux;
+
+import java.util.List;
+
+import org.argeo.slc.build.Distribution;
+
+public class RpmDistribution implements Distribution {
+       private List<String> additionalPackages;
+
+       public String getDistributionId() {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       public List<String> getAdditionalPackages() {
+               return additionalPackages;
+       }
+
+       public void setAdditionalPackages(List<String> additionalPackages) {
+               this.additionalPackages = additionalPackages;
+       }
+
+}
diff --git a/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/lib/linux/SimpleLinuxHost.java b/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/lib/linux/SimpleLinuxHost.java
new file mode 100644 (file)
index 0000000..d51497a
--- /dev/null
@@ -0,0 +1,42 @@
+package org.argeo.slc.lib.linux;
+
+import org.argeo.slc.build.Distribution;
+import org.argeo.slc.deploy.DeployedSystem;
+import org.argeo.slc.deploy.DeploymentData;
+import org.argeo.slc.deploy.TargetData;
+
+public class SimpleLinuxHost implements DeployedSystem {
+       private DeploymentData deploymentData;
+       private Distribution distribution;
+       private TargetData targetData;
+
+       public String getDeployedSystemId() {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       public DeploymentData getDeploymentData() {
+               return deploymentData;
+       }
+
+       public void setDeploymentData(DeploymentData deploymentData) {
+               this.deploymentData = deploymentData;
+       }
+
+       public Distribution getDistribution() {
+               return distribution;
+       }
+
+       public void setDistribution(Distribution distribution) {
+               this.distribution = distribution;
+       }
+
+       public TargetData getTargetData() {
+               return targetData;
+       }
+
+       public void setTargetData(TargetData targetData) {
+               this.targetData = targetData;
+       }
+
+}