Skip to content

Commit

Permalink
Mostly working
Browse files Browse the repository at this point in the history
  • Loading branch information
timja committed May 15, 2019
1 parent 1b28a47 commit 5027aa6
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 123 deletions.
15 changes: 15 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<powermock.version>1.6.6</powermock.version>
<checkstyle.version>2.13</checkstyle.version>
<configuration-as-code.version>1.15</configuration-as-code.version>
</properties>

<licenses>
Expand Down Expand Up @@ -166,6 +167,20 @@
<version>3.6</version>
</dependency>

<dependency>
<groupId>io.jenkins</groupId>
<artifactId>configuration-as-code</artifactId>
<version>${configuration-as-code.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.jenkins</groupId>
<artifactId>configuration-as-code</artifactId>
<version>${configuration-as-code.version}</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>structs</artifactId>
Expand Down
154 changes: 65 additions & 89 deletions src/main/java/com/sonyericsson/jenkins/plugins/bfa/PluginImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
import jenkins.model.Jenkins;
import net.sf.json.JSONObject;
import org.jenkinsci.Symbol;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.DataBoundSetter;
import org.kohsuke.stapler.StaplerRequest;

import javax.annotation.Nonnull;
Expand Down Expand Up @@ -151,15 +153,28 @@ public class PluginImpl extends GlobalConfiguration {
*/
private ScanOnDemandVariables sodVariables;

/**
* Default constructor.
*/
@DataBoundConstructor
public PluginImpl() {
load();
}

/**
* {@inheritDoc}
*/
@Override
protected XmlFile getConfigFile() {
return new XmlFile(XSTREAM, new File(Jenkins.getInstance().getRootDir(),"build-failure-analyzer.xml")); // for backward compatibility
return new XmlFile(
XSTREAM,
new File(Jenkins.getInstance().getRootDir(), "build-failure-analyzer.xml")
); // for backward compatibility
}

/**
* Starts the knowledge base.
*/
@Initializer(after = InitMilestone.EXTENSIONS_AUGMENTED)
public void start() {
logger.finer("[BFA] Starting...");
Expand All @@ -173,27 +188,6 @@ public void start() {
if (nrOfScanThreads < 1) {
nrOfScanThreads = DEFAULT_NR_OF_SCAN_THREADS;
}
sodVariables = new ScanOnDemandVariables();
if (sodVariables.getMinimumSodWorkerThreads() < 1) {
sodVariables.setMinimumSodWorkerThreads(ScanOnDemandVariables.
DEFAULT_MINIMUM_SOD_WORKER_THREADS);
}
if (sodVariables.getMaximumSodWorkerThreads() < 1) {
sodVariables.setMaximumSodWorkerThreads(ScanOnDemandVariables.
DEFAULT_MAXIMUM_SOD_WORKER_THREADS);
}
if (sodVariables.getSodThreadKeepAliveTime() < 1) {
sodVariables.setSodThreadKeepAliveTime(ScanOnDemandVariables.
DEFAULT_SOD_THREADS_KEEP_ALIVE_TIME);
}
if (sodVariables.getSodWaitForJobShutdownTimeout() < 1) {
sodVariables.setSodWaitForJobShutdownTimeout(ScanOnDemandVariables.
DEFAULT_SOD_WAIT_FOR_JOBS_SHUTDOWN_TIMEOUT);
}
if (sodVariables.getSodCorePoolNumberOfThreads() < 1) {
sodVariables.setSodCorePoolNumberOfThreads(ScanOnDemandVariables.
DEFAULT_SOD_COREPOOL_THREADS);
}

if (knowledgeBase == null) {
if (causes == null) {
Expand All @@ -214,6 +208,9 @@ public void start() {
}
}

/**
* Run on Jenkins shutdown.
*/
@Terminator
public void stop() {
ScanOnDemandQueue.shutdown();
Expand Down Expand Up @@ -365,6 +362,42 @@ public boolean isGraphsEnabled() {
}
}

/**
* Sets if graphs are enabled.
* @param graphsEnabled the graph flag
*/
@DataBoundSetter
public void setGraphsEnabled(Boolean graphsEnabled) {
this.graphsEnabled = graphsEnabled;
}

/**
* Sets the no causes message.
* @param noCausesMessage the no causes message
*/
@DataBoundSetter
public void setNoCausesMessage(String noCausesMessage) {
this.noCausesMessage = noCausesMessage;
}

/**
* Sets the knowledge base.
* @param knowledgeBase the knowledge base
*/
@DataBoundSetter
public void setKnowledgeBase(KnowledgeBase knowledgeBase) {
this.knowledgeBase = knowledgeBase;
}

/**
* Sets the scan on demand variables.
* @param sodVariables the variables
*/
@DataBoundSetter
public void setSodVariables(ScanOnDemandVariables sodVariables) {
this.sodVariables = sodVariables;
}

/**
* If failed test cases should be represented as failure causes.
*
Expand Down Expand Up @@ -487,6 +520,10 @@ public void setMaxLogSize(int maxLogSize) {
* @return value
*/
public int getMaxLogSize() {
if (maxLogSize < 0) {
return DEFAULT_MAX_LOG_SIZE;
}

return maxLogSize;
}

Expand Down Expand Up @@ -583,80 +620,19 @@ public KnowledgeBase.KnowledgeBaseDescriptor getKnowledgeBaseDescriptor(String d

@Override
public boolean configure(StaplerRequest req, JSONObject o) {
noCausesMessage = o.getString("noCausesMessage");
globalEnabled = o.getBoolean("globalEnabled");
doNotAnalyzeAbortedJob = o.optBoolean("doNotAnalyzeAbortedJob", false);
gerritTriggerEnabled = o.getBoolean("gerritTriggerEnabled");
graphsEnabled = o.getBoolean("graphsEnabled");
testResultParsingEnabled = o.getBoolean("testResultParsingEnabled");
testResultCategories = o.getString("testResultCategories");
maxLogSize = o.optInt("maxLogSize");
int scanThreads = o.getInt("nrOfScanThreads");
int minSodWorkerThreads = o.getInt("minimumNumberOfWorkerThreads");
int maxSodWorkerThreads = o.getInt("maximumNumberOfWorkerThreads");
int thrkeepAliveTime = o.getInt("threadKeepAliveTime");
int jobShutdownTimeWait = o.getInt("waitForJobShutdownTime");
int corePoolNumberOfThreads = o.getInt("corePoolNumberOfThreads");
if (scanThreads < MINIMUM_NR_OF_SCAN_THREADS) {
nrOfScanThreads = DEFAULT_NR_OF_SCAN_THREADS;
} else {
nrOfScanThreads = scanThreads;
}

if (maxLogSize < 0) {
maxLogSize = DEFAULT_MAX_LOG_SIZE;
}

if (corePoolNumberOfThreads < ScanOnDemandVariables.DEFAULT_SOD_COREPOOL_THREADS) {
sodVariables.setSodCorePoolNumberOfThreads(ScanOnDemandVariables.DEFAULT_SOD_COREPOOL_THREADS);
} else {
sodVariables.setSodCorePoolNumberOfThreads(corePoolNumberOfThreads);
}
req.bindJSON(this, o);

if (jobShutdownTimeWait < ScanOnDemandVariables.DEFAULT_SOD_WAIT_FOR_JOBS_SHUTDOWN_TIMEOUT) {
sodVariables.setSodWaitForJobShutdownTimeout(ScanOnDemandVariables.
DEFAULT_SOD_WAIT_FOR_JOBS_SHUTDOWN_TIMEOUT);
} else {
sodVariables.setSodWaitForJobShutdownTimeout(jobShutdownTimeWait);
}
if (thrkeepAliveTime < ScanOnDemandVariables.DEFAULT_SOD_THREADS_KEEP_ALIVE_TIME) {
sodVariables.setSodThreadKeepAliveTime(ScanOnDemandVariables.DEFAULT_SOD_THREADS_KEEP_ALIVE_TIME);
} else {
sodVariables.setSodThreadKeepAliveTime(thrkeepAliveTime);
}
if (minSodWorkerThreads < ScanOnDemandVariables.DEFAULT_MINIMUM_SOD_WORKER_THREADS) {
sodVariables.setMinimumSodWorkerThreads(ScanOnDemandVariables.DEFAULT_MINIMUM_SOD_WORKER_THREADS);
} else {
sodVariables.setMinimumSodWorkerThreads(minSodWorkerThreads);
}
if (maxSodWorkerThreads < ScanOnDemandVariables.DEFAULT_MAXIMUM_SOD_WORKER_THREADS) {
sodVariables.setMaximumSodWorkerThreads(ScanOnDemandVariables.DEFAULT_MAXIMUM_SOD_WORKER_THREADS);
} else {
sodVariables.setMaximumSodWorkerThreads(maxSodWorkerThreads);
}
if (maxSodWorkerThreads < ScanOnDemandVariables.DEFAULT_MAXIMUM_SOD_WORKER_THREADS) {
sodVariables.setMaximumSodWorkerThreads(ScanOnDemandVariables.DEFAULT_MAXIMUM_SOD_WORKER_THREADS);
} else {
sodVariables.setMaximumSodWorkerThreads(maxSodWorkerThreads);
}
KnowledgeBase base = req.bindJSON(KnowledgeBase.class, o.getJSONObject("knowledgeBase"));
if (base != null && !knowledgeBase.equals(base)) {
try {
base.start();
} catch (Exception e) {
logger.log(Level.SEVERE, "Could not start new knowledge base, reverting ", e);
save();
return true;
}
KnowledgeBase existingKb = this.knowledgeBase;
if (existingKb != null && !existingKb.equals(knowledgeBase)) {
if (o.getBoolean("convertOldKb")) {
try {
base.convertFrom(knowledgeBase);
knowledgeBase.start();
knowledgeBase.convertFrom(existingKb);
} catch (Exception e) {
logger.log(Level.SEVERE, "Could not convert knowledge base ", e);
}
knowledgeBase.stop();
}
knowledgeBase.stop();
knowledgeBase = base;
}

save();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
*/
package com.sonyericsson.jenkins.plugins.bfa.sod;

import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.DataBoundSetter;

/**
* Scan on demand feature settings.
*
Expand Down Expand Up @@ -59,19 +62,27 @@ public class ScanOnDemandVariables {
private int sodThreadKeepAliveTime;
private int sodWaitForJobShutdownTimeout;
private int sodCorePoolNumberOfThreads;
/**

@DataBoundConstructor
public ScanOnDemandVariables() {
}

/**
* Set maximum numbers of sod worker threads.
*
* @param maximumSodWorkerThreads value.
*/
public void setMaximumSodWorkerThreads(int maximumSodWorkerThreads) {
this.maximumSodWorkerThreads = maximumSodWorkerThreads;
}
@DataBoundSetter
public void setMaximumSodWorkerThreads(int maximumSodWorkerThreads) {
this.maximumSodWorkerThreads = maximumSodWorkerThreads;
}

/**
* Set minimum numbers of sod worker threads.
*
* @param minimumSodWorkerThreads value.
*/
@DataBoundSetter
public void setMinimumSodWorkerThreads(int minimumSodWorkerThreads) {
this.minimumSodWorkerThreads = minimumSodWorkerThreads;
}
Expand All @@ -80,6 +91,7 @@ public void setMinimumSodWorkerThreads(int minimumSodWorkerThreads) {
*
* @param sodCorePoolNumberOfThreads value.
*/
@DataBoundSetter
public void setSodCorePoolNumberOfThreads(int sodCorePoolNumberOfThreads) {
this.sodCorePoolNumberOfThreads = sodCorePoolNumberOfThreads;
}
Expand All @@ -88,6 +100,7 @@ public void setSodCorePoolNumberOfThreads(int sodCorePoolNumberOfThreads) {
*
* @param sodThreadKeepAliveTime value.
*/
@DataBoundSetter
public void setSodThreadKeepAliveTime(int sodThreadKeepAliveTime) {
this.sodThreadKeepAliveTime = sodThreadKeepAliveTime;
}
Expand All @@ -96,6 +109,7 @@ public void setSodThreadKeepAliveTime(int sodThreadKeepAliveTime) {
*
* @param sodWaitForJobShutdownTimeout value.
*/
@DataBoundSetter
public void setSodWaitForJobShutdownTimeout(int sodWaitForJobShutdownTimeout) {
this.sodWaitForJobShutdownTimeout = sodWaitForJobShutdownTimeout;
}
Expand All @@ -105,16 +119,24 @@ public void setSodWaitForJobShutdownTimeout(int sodWaitForJobShutdownTimeout) {
*
* @return int value.
*/
public int getSodCorePoolNumberOfThreads() {
return sodCorePoolNumberOfThreads;
}
public int getSodCorePoolNumberOfThreads() {
if (sodCorePoolNumberOfThreads < ScanOnDemandVariables.DEFAULT_SOD_COREPOOL_THREADS) {
return ScanOnDemandVariables.DEFAULT_SOD_COREPOOL_THREADS;
}

return sodCorePoolNumberOfThreads;
}

/**
* Returns the maximum number of sod threads.
*
* @return int value.
*/
public int getMaximumSodWorkerThreads() {
if (maximumSodWorkerThreads < ScanOnDemandVariables.DEFAULT_MAXIMUM_SOD_WORKER_THREADS) {
return ScanOnDemandVariables.DEFAULT_MAXIMUM_SOD_WORKER_THREADS;
}

return maximumSodWorkerThreads;
}

Expand All @@ -124,6 +146,10 @@ public int getMaximumSodWorkerThreads() {
* @return int value.
*/
public int getMinimumSodWorkerThreads() {
if (minimumSodWorkerThreads < ScanOnDemandVariables.DEFAULT_MINIMUM_SOD_WORKER_THREADS) {
return ScanOnDemandVariables.DEFAULT_MINIMUM_SOD_WORKER_THREADS;
}

return minimumSodWorkerThreads;
}

Expand All @@ -133,6 +159,10 @@ public int getMinimumSodWorkerThreads() {
* @return int value.
*/
public int getSodThreadKeepAliveTime() {
if (sodThreadKeepAliveTime < ScanOnDemandVariables.DEFAULT_SOD_THREADS_KEEP_ALIVE_TIME) {
return ScanOnDemandVariables.DEFAULT_SOD_THREADS_KEEP_ALIVE_TIME;
}

return sodThreadKeepAliveTime;
}

Expand All @@ -142,6 +172,10 @@ public int getSodThreadKeepAliveTime() {
* @return the int value.
*/
public int getSodWaitForJobShutdownTimeout() {
if (sodWaitForJobShutdownTimeout < ScanOnDemandVariables.DEFAULT_SOD_WAIT_FOR_JOBS_SHUTDOWN_TIMEOUT) {
return DEFAULT_SOD_WAIT_FOR_JOBS_SHUTDOWN_TIMEOUT;
}

return sodWaitForJobShutdownTimeout;
}

Expand Down

0 comments on commit 5027aa6

Please sign in to comment.