Skip to content
Permalink
Browse files
[FIXED JENKINS-24545] Allow loading node list from file
  • Loading branch information
vjuranek committed Sep 2, 2014
1 parent 396f2e3 commit 8cbef4365d2a87dcd12e4c8e466c7ae49cd7a9d0
@@ -25,28 +25,28 @@

import net.sf.json.JSONObject;

import org.jenkinsci.plugins.radargun.config.NodeSource;
import org.jenkinsci.plugins.radargun.config.ScenarioSource;
import org.jenkinsci.plugins.radargun.config.ScriptSource;
import org.jenkinsci.plugins.radargun.model.Node;
import org.jenkinsci.plugins.radargun.model.NodeList;
import org.jenkinsci.plugins.radargun.util.ParseUtils;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.StaplerRequest;

public class RadarGunBuilder extends Builder {

private final String radarGunName;
private final ScenarioSource scenarioSource;
private final String nodeListString;
private final NodeSource nodeSource;
private final ScriptSource scriptSource;
private final String defaultJvmArgs;

@DataBoundConstructor
public RadarGunBuilder(String radarGunName, ScenarioSource scenarioSource, String nodeListString,
public RadarGunBuilder(String radarGunName, ScenarioSource scenarioSource, NodeSource nodeSource,
ScriptSource scriptSource, String defaultJvmArgs) {
this.radarGunName = radarGunName;
this.scenarioSource = scenarioSource;
this.nodeListString = nodeListString;
this.nodeSource = nodeSource;
this.scriptSource = scriptSource;
this.defaultJvmArgs = defaultJvmArgs;
}
@@ -59,8 +59,8 @@ public ScenarioSource getScenarioSource() {
return scenarioSource;
}

public String getNodeListString() {
return nodeListString;
public NodeSource getNodeSource() {
return nodeSource;
}

public ScriptSource getScriptSource() {
@@ -79,7 +79,7 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen
String rgMasterScript = rgInstall.getExecutable(RadarGunExecutable.MASTER, launcher.getChannel());
String rgSlaveScript = rgInstall.getExecutable(RadarGunExecutable.SLAVE, launcher.getChannel());

NodeList nodes = ParseUtils.parseNodeList(nodeListString);
NodeList nodes = nodeSource.getNodesList();
List<NodeRunner> nodeRunners = new ArrayList<NodeRunner>();

// master start script
@@ -202,6 +202,10 @@ public ListBoxModel doFillRadarGunNameItems() {
return ScenarioSource.all();
}

public static DescriptorExtensionList<NodeSource, Descriptor<NodeSource>> getNodeSources() {
return NodeSource.all();
}

public static DescriptorExtensionList<ScriptSource, Descriptor<ScriptSource>> getScriptSources() {
return ScriptSource.all();
}
@@ -0,0 +1,41 @@
package org.jenkinsci.plugins.radargun.config;

import hudson.Extension;
import hudson.FilePath;

import java.io.File;
import java.io.IOException;

import org.jenkinsci.plugins.radargun.model.NodeList;
import org.jenkinsci.plugins.radargun.util.ParseUtils;
import org.kohsuke.stapler.DataBoundConstructor;

public class FileNodeSource extends NodeSource {

private final String nodeListPath;

@DataBoundConstructor
public FileNodeSource(String nodeListPath) {
this.nodeListPath = nodeListPath;
}

public String getNodeListPath() {
return nodeListPath;
}

@Override
public NodeList getNodesList() throws IOException {
//String path = Resolver.buildVar(build, nodeListPath); //TODO resolve build variables in path
FilePath fp = new FilePath(new File(nodeListPath));
String nodes = fp.readToString();
return ParseUtils.parseNodeList(nodes);
}

@Extension
public static class DescriptorImpl extends NodeSourceDescriptor {
public String getDisplayName() {
return "Node list from file";
}
}

}
@@ -0,0 +1,29 @@
package org.jenkinsci.plugins.radargun.config;

import java.io.IOException;

import hudson.DescriptorExtensionList;
import hudson.model.Describable;
import hudson.model.Descriptor;
import jenkins.model.Jenkins;

import org.jenkinsci.plugins.radargun.model.NodeList;

public abstract class NodeSource implements Describable<NodeSource> {

public abstract NodeList getNodesList() throws IOException;

@Override
@SuppressWarnings("unchecked")
public Descriptor<NodeSource> getDescriptor() {
return Jenkins.getInstance().getDescriptorOrDie(getClass());
}

public static final DescriptorExtensionList<NodeSource, Descriptor<NodeSource>> all() {
return Jenkins.getInstance().getDescriptorList(NodeSource.class);
}

public static abstract class NodeSourceDescriptor extends Descriptor<NodeSource> {
}

}
@@ -0,0 +1,34 @@
package org.jenkinsci.plugins.radargun.config;

import hudson.Extension;

import org.jenkinsci.plugins.radargun.model.NodeList;
import org.jenkinsci.plugins.radargun.util.ParseUtils;
import org.kohsuke.stapler.DataBoundConstructor;

public class TextNodeSource extends NodeSource {

private final String nodes;

@DataBoundConstructor
public TextNodeSource(String nodes) {
this.nodes = nodes;
}

public String getNodes() {
return nodes;
}

@Override
public NodeList getNodesList() {
return ParseUtils.parseNodeList(nodes);
}

@Extension
public static class DescriptorImpl extends NodeSourceDescriptor {
public String getDisplayName() {
return "Text node list";
}
}

}
@@ -15,10 +15,18 @@
</f:dropdownListBlock>
</j:forEach>
</f:dropdownList>

<f:entry title="Node list" field="nodeListString" description="List of nodes the scenario will be executed. First is master node.">
<f:textarea />
</f:entry>

<j:set var="currNode" value="${instance.nodeSource}" />
<f:dropdownList name="nodeSource" title="Node list"
description="List of the nodes where RadarGun will run">
<j:forEach var="desc" items="${descriptor.nodeSources}" varStatus="loop">
<f:dropdownListBlock title="${desc.displayName}" value="${loop.index}" selected="${desc==currNode.descriptor}"
staplerClass="${desc.clazz.name}">
<j:set var="instance" value="${currNode}" />
<st:include page="${desc.configPage}" from="${desc}" />
</f:dropdownListBlock>
</j:forEach>
</f:dropdownList>

<j:set var="currScript" value="${instance.scriptSource}" />
<f:dropdownList name="scriptSource" title="Start script"
@@ -0,0 +1,8 @@
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson"
xmlns:f="/lib/form">

<f:entry field="nodeListPath">
<f:textbox />
</f:entry>

</j:jelly>
@@ -0,0 +1,8 @@
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson"
xmlns:f="/lib/form">

<f:entry field="nodes">
<f:textarea />
</f:entry>

</j:jelly>

0 comments on commit 8cbef43

Please sign in to comment.