Skip to content

Commit

Permalink
[FIXED JENKINS-24798] Implement Text script source
Browse files Browse the repository at this point in the history
  • Loading branch information
vjuranek committed Sep 23, 2014
1 parent 519fe8a commit 6203bc7
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 36 deletions.
Expand Up @@ -108,8 +108,8 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen
RadarGunNodeAction masterAction = new RadarGunNodeAction(build, nodes.getMaster().getHostname(),
"RadarGun master ");
build.addAction(masterAction);
String[] masterCmdLine = scriptSource.getMasterCmdLine(nodes.getMaster().getHostname(), rgMasterScript,
scenarioSource.getTmpScenarioPath(build), Integer.toString(nodes.getSlaveCount()),
String[] masterCmdLine = scriptSource.getMasterCmdLine(build.getWorkspace(), nodes.getMaster().getHostname(),
rgMasterScript, scenarioSource.getTmpScenarioPath(build), Integer.toString(nodes.getSlaveCount()),
buildJvmOptions(build, nodes.getMaster()));
ProcStarter masterProcStarter = buildProcStarter(build, launcher, masterCmdLine, masterAction.getLogFile());
nodeRunners.add(new NodeRunner(masterProcStarter, masterAction));
Expand All @@ -120,8 +120,8 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen
Node slave = slaves.get(i);
RadarGunNodeAction slaveAction = new RadarGunNodeAction(build, slave.getHostname());
build.addAction(slaveAction);
String[] slaveCmdLine = scriptSource.getSlaveCmdLine(slave.getHostname(), rgSlaveScript, String.valueOf(i),
buildJvmOptions(build, slave));
String[] slaveCmdLine = scriptSource.getSlaveCmdLine(build.getWorkspace(), slave.getHostname(),
rgSlaveScript, String.valueOf(i), buildJvmOptions(build, slave));
ProcStarter slaveProcStarter = buildProcStarter(build, launcher, slaveCmdLine, slaveAction.getLogFile());
nodeRunners.add(new NodeRunner(slaveProcStarter, slaveAction));
}
Expand Down
@@ -1,6 +1,7 @@
package org.jenkinsci.plugins.radargun.config;

import hudson.Extension;
import hudson.FilePath;

import java.io.File;

Expand All @@ -10,33 +11,37 @@
* BuildInScriptSource
*
* @author vjuranek
*
*
*/
public class BuildInScriptSource extends ScriptSource {

private static final String SCRIPT_DIR = "/scripts/";
private static final String MASTER_SCRIPT_NAME = "start_master.sh";
private static final String SLAVE_SCRIPT_NAME = "start_slave.sh";

private static final String MASTER_SCRIPT_PATH = BuildInScriptSource.class.getResource(SCRIPT_DIR + MASTER_SCRIPT_NAME).getPath();
private static final String SLAVE_SCRIPT_PATH = BuildInScriptSource.class.getResource(SCRIPT_DIR + SLAVE_SCRIPT_NAME).getPath();


private static final String MASTER_SCRIPT_PATH = BuildInScriptSource.class.getResource(
SCRIPT_DIR + MASTER_SCRIPT_NAME).getPath();
private static final String SLAVE_SCRIPT_PATH = BuildInScriptSource.class.getResource(
SCRIPT_DIR + SLAVE_SCRIPT_NAME).getPath();

static {
new File(MASTER_SCRIPT_PATH).setExecutable(true);
new File(SLAVE_SCRIPT_PATH).setExecutable(true);
}

@DataBoundConstructor
public BuildInScriptSource() {
//NO-OP
// NO-OP

}

public String getMasterScriptPath() {

@Override
public String getMasterScriptPath(FilePath workspace) {
return MASTER_SCRIPT_PATH;
}

public String getSlaveScriptPath() {

@Override
public String getSlaveScriptPath(FilePath workspace) {
return SLAVE_SCRIPT_PATH;
}

Expand All @@ -47,5 +52,4 @@ public String getDisplayName() {
}
}


}
@@ -1,6 +1,7 @@
package org.jenkinsci.plugins.radargun.config;

import hudson.Extension;
import hudson.FilePath;

import org.kohsuke.stapler.DataBoundConstructor;

Expand All @@ -24,16 +25,18 @@ public FileScriptSource(String masterPath, String slavePath) {
public String getMasterPath() {
return mastertPath;
}

public String getSlavePath() {
return slavePath;
}

public String getMasterScriptPath() {

@Override
public String getMasterScriptPath(FilePath workspace) {
return mastertPath;
}

public String getSlaveScriptPath() {

@Override
public String getSlaveScriptPath(FilePath workspace) {
return slavePath;
}

Expand Down
@@ -1,6 +1,9 @@
package org.jenkinsci.plugins.radargun.config;

import java.io.IOException;

import hudson.DescriptorExtensionList;
import hudson.FilePath;
import hudson.model.Describable;
import hudson.model.Descriptor;
import jenkins.model.Jenkins;
Expand All @@ -13,9 +16,9 @@
*/
public abstract class ScriptSource implements Describable<ScriptSource> {

public abstract String getMasterScriptPath();
public abstract String getMasterScriptPath(FilePath workspace) throws InterruptedException, IOException;

public abstract String getSlaveScriptPath();
public abstract String getSlaveScriptPath(FilePath workspace) throws InterruptedException, IOException;

/**
* Prepares command line which will be used to start master process
Expand All @@ -30,12 +33,12 @@ public abstract class ScriptSource implements Describable<ScriptSource> {
* additional JVM options for master process
*
*/
public String[] getMasterCmdLine(String hostname, String rgMasterScript, String scenarioPath, String slaveNumber,
String jvmOpts) {
public String[] getMasterCmdLine(FilePath workspace, String hostname, String rgMasterScript, String scenarioPath, String slaveNumber,
String jvmOpts) throws InterruptedException, IOException {
// Run with "tail" option ("-t") not to finish immediately once the RG process is started.
// Otherwise Jenkins finish the process and kill all background thread, i.e. kill RG master.
// And also to gather the log from master
return new String[] { getMasterScriptPath(), hostname, rgMasterScript , "-t", "-w", scenarioPath, slaveNumber, jvmOpts };
return new String[] { getMasterScriptPath(workspace), hostname, rgMasterScript , "-t", "-w", scenarioPath, slaveNumber, jvmOpts };
}

/**
Expand All @@ -51,9 +54,9 @@ public String[] getMasterCmdLine(String hostname, String rgMasterScript, String
* additional JVM options for master process
*
*/
public String[] getSlaveCmdLine(String hostname, String rgSlaveScript, String slaveIndex, String jvmOpts) {
public String[] getSlaveCmdLine(FilePath workspace, String hostname, String rgSlaveScript, String slaveIndex, String jvmOpts) throws InterruptedException, IOException {
// run with "tail" option ("-t") to gather the logs from slaves
return new String[] { getSlaveScriptPath(), hostname, rgSlaveScript, "-t", "-w", slaveIndex, jvmOpts };
return new String[] { getSlaveScriptPath(workspace), hostname, rgSlaveScript, "-t", "-w", slaveIndex, jvmOpts };
}

@Override
Expand Down
@@ -1,6 +1,9 @@
package org.jenkinsci.plugins.radargun.config;

import hudson.Extension;
import hudson.FilePath;

import java.io.IOException;

import org.kohsuke.stapler.DataBoundConstructor;

Expand Down Expand Up @@ -28,15 +31,19 @@ public String getMasterScript() {
public String getSlaveScript() {
return slaveScript;
}

public String getMasterScriptPath() {
return null;

@Override
public String getMasterScriptPath(FilePath workspace) throws InterruptedException, IOException {
FilePath master = workspace.createTextTempFile("radargun_master", ".sh", masterScript, true);
return master.getRemote();
}

public String getSlaveScriptPath() {
return null;

@Override
public String getSlaveScriptPath(FilePath workspace) throws InterruptedException, IOException {
FilePath slave = workspace.createTextTempFile("radargun_slave", ".sh", slaveScript, true);
return slave.getRemote();
}

@Extension
public static class DescriptorImpl extends ScriptSourceDescriptor {
public String getDisplayName() {
Expand Down

0 comments on commit 6203bc7

Please sign in to comment.