Skip to content

Commit

Permalink
Add support for multiple SF build steps in one job
Browse files Browse the repository at this point in the history
  • Loading branch information
vjuranek committed Jun 17, 2013
1 parent 8ddb605 commit 376f6cf
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 29 deletions.
39 changes: 28 additions & 11 deletions src/main/java/builder/smartfrog/SmartFrogAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public class SmartFrogAction implements Action, Runnable {
private final String host;
private State state;
private AbstractBuild<?, ?> build;
private String prefixId;

private transient SmartFrogBuilder builder;
private transient Proc proc;
Expand All @@ -77,24 +78,32 @@ public class SmartFrogAction implements Action, Runnable {
private transient Launcher launcher;
private transient ConsoleLogger console;
private transient BuildListener log;
private final transient int logNum;
private transient String readableLogSize;

public SmartFrogAction(SmartFrogBuilder builder, String host, int logNum) {
public SmartFrogAction(SmartFrogBuilder builder, String host) {
this.builder = builder;
this.host = host;
this.state = State.STARTING;
this.logNum = logNum;
this.prefixId = "";
}

public SmartFrogAction(SmartFrogBuilder builder, String host, String prefixId) {
this.builder = builder;
this.host = host;
this.state = State.STARTING;
this.prefixId = prefixId;
}

protected Object readResolve(){
if(prefixId == null)
prefixId = "";
return this;
}

public String getHost() {
return host;
}

public int getLogNum(){
return logNum;
}

public String getReadableLogSize() {
if(readableLogSize == null)
readableLogSize = hudson.Functions.humanReadableByteSize(getLogFile().length());
Expand Down Expand Up @@ -189,10 +198,14 @@ public void doProgressiveLog(StaplerRequest req, StaplerResponse rsp) throws IOE
}

public File getLogFile() {
File gzipLogFile = new File(build.getRootDir(), host + "_" + logNum + ".log.gz");
String logFileName = host;
if(!prefixId.isEmpty())
logFileName = prefixId + "_" +logFileName;

File gzipLogFile = new File(build.getRootDir(), logFileName + ".log.gz");
if(gzipLogFile.isFile())
return gzipLogFile;
return new File(build.getRootDir(), host + "_" + logNum + ".log");
return new File(build.getRootDir(), logFileName + ".log");
}

private void logUpstream(String message){
Expand All @@ -209,11 +222,15 @@ public String getIconFileName() {
}

public String getDisplayName() {
return "sfDaemon - " + host + " #" + logNum;
if(prefixId.isEmpty())
return "sfDaemon - " + host;
return "sfDaemon - " + host + " (" + prefixId + ")" ;
}

public String getUrlName() {
return "console-" + Util.rawEncode(host) + "-" + logNum;
if(prefixId.isEmpty())
return "console-" + Util.rawEncode(host);
return prefixId + "-console-" + Util.rawEncode(host);
}

// required by index.jelly
Expand Down
25 changes: 8 additions & 17 deletions src/main/java/builder/smartfrog/SmartFrogBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public class SmartFrogBuilder extends Builder implements SmartFrogActionListener
private String sfUserHome3;
private String sfUserHome4;
private String sfOpts;
private String builderId;
private String sfIni;
private boolean useAltIni;
private ScriptSource sfScriptSource;
Expand All @@ -95,7 +96,7 @@ public class SmartFrogBuilder extends Builder implements SmartFrogActionListener

@DataBoundConstructor
public SmartFrogBuilder(String smartFrogName, String deployHost, String hosts, String sfUserHome,
String sfUserHome2, String sfUserHome3, String sfUserHome4, String sfOpts, boolean useAltIni, String sfIni,
String sfUserHome2, String sfUserHome3, String sfUserHome4, String sfOpts, String builderId, boolean useAltIni, String sfIni,
ScriptSource sfScriptSource) {
this.smartFrogName = smartFrogName;
this.deployHost = deployHost;
Expand All @@ -105,6 +106,7 @@ public SmartFrogBuilder(String smartFrogName, String deployHost, String hosts, S
this.sfUserHome3 = sfUserHome3;
this.sfUserHome4 = sfUserHome4;
this.sfOpts = sfOpts;
this.builderId = builderId;
this.useAltIni = useAltIni;
this.sfIni = sfIni;
this.sfScriptSource = sfScriptSource;
Expand Down Expand Up @@ -162,6 +164,10 @@ public String getSfIni() {
return sfIni;
}

public String getBuilderId() {
return builderId;
}

public boolean isUseAltIni() {
return useAltIni;
}
Expand Down Expand Up @@ -274,8 +280,7 @@ private SmartFrogAction[] createDaemons(AbstractBuild<?, ?> build, Launcher laun
// start daemons
for (int k = 0; k < hostList.length; k++) {
String host = hostList[k];
int logNum = getNextActionNumber(build, host);
SmartFrogAction a = new SmartFrogAction(this, host, logNum);
SmartFrogAction a = new SmartFrogAction(this, host, builderId);
build.addAction(a);
a.addStateListener(this);
sfActions[k] = a;
Expand Down Expand Up @@ -377,20 +382,6 @@ private void failBuild(AbstractBuild<?, ?> build, SmartFrogAction[] sfActions) {
killAllDaemons(sfActions);
}

private int getNextActionNumber(AbstractBuild<?, ?> build, String host){
List<SmartFrogAction> existingActions = build.getActions(SmartFrogAction.class);
if(existingActions.size() == 0)
return 1;
int maxNum = 0;
for(SmartFrogAction a : existingActions){
if(a.getHost().equals(host)){
if(a.getLogNum() > maxNum)
maxNum = a.getLogNum();
}
}
return ++maxNum;
}

protected String[] buildDaemonCommandLine(String host, String workspace) {
String iniPath = useAltIni ? sfIni : sfInstance.getPath() + "/bin/default.ini";
return new String[] { "bash", "-xe", sfInstance.getSupport() + "/runSF.sh", host, sfInstance.getPath(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
<f:entry title="SF_OPTS" field="sfOpts" description="Arguments passed to JVM (since 3.17.014 and higher).">
<f:textbox />
</f:entry>

<f:entry title="Unique build step ID" field="builderId" description="Unique ID which identifies this build step. Usefull when you run multiple SF build steps in on jobs.">
<f:textbox />
</f:entry>

<f:block>
<table>
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/builder/smartfrog/SmartFrogActionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class SmartFrogActionTest {

@Test
public void encodeIPv6Hostname() {
SmartFrogAction sfa = new SmartFrogAction(null, "::1", 0);
SmartFrogAction sfa = new SmartFrogAction(null, "::1");
assertEquals("console-%3A%3A1-0", sfa.getUrlName());
}

Expand Down

0 comments on commit 376f6cf

Please sign in to comment.