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()) {
this.resourceSets = resourceSets;
}
+ public List<ResourceSet> getResourceSets() {
+ return resourceSets;
+ }
+
}
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
// 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;
}
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;
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;
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();
--- /dev/null
+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;
+ }
+
+}
--- /dev/null
+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;
+ }
+
+}
--- /dev/null
+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;
+ }
+
+}
--- /dev/null
+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;
+ }
+
+}