Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display job queue and if time exceeds estimated duration #307

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,15 @@ public BuildMonitorInstallation getInstallation() {
public boolean collectAnonymousUsageStatistics() {
return descriptor.getPermissionToCollectAnonymousUsageStatistics();
}
@SuppressWarnings("unused") // used in .jelly
public double getOvertimeFactor() {
return currentConfig().getOvertimeFactor();
}

@SuppressWarnings("unused") // used in .jelly
public String getFilterRegex() {
return currentConfig().getFilterRegex();
}

@Override
protected void submit(StaplerRequest req) throws ServletException, IOException, FormException {
Expand All @@ -113,7 +122,12 @@ protected void submit(StaplerRequest req) throws ServletException, IOException,

String requestedOrdering = req.getParameter("order");
title = req.getParameter("title");

String filterRegex = req.getParameter("filterRegex");
float overtimeFactor = Float.parseFloat(req.getParameter("overtimeFactor"));//needs parsing into config as input is string.
currentConfig().setOvertimeFactor(overtimeFactor);
currentConfig().setStripCommonPrefix(json.optBoolean("stripPrefix",false));
currentConfig().setStripCommonSuffix(json.optBoolean("stripSuffix",false));
currentConfig().setFilterRegex(filterRegex);
currentConfig().setDisplayCommitters(json.optBoolean("displayCommitters", true));

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,38 @@

public class Config {

private boolean displayCommitters;
private boolean displayCommitters,shouldStripCommonPrefix,shouldStripCommonSuffix;
private String filterRegex;
private double overtimeFactor;

public void setStripCommonPrefix(boolean strip){
this.shouldStripCommonPrefix = strip;
}

public void setStripCommonSuffix(boolean strip){
this.shouldStripCommonSuffix = strip;
}
public Boolean ShouldStripCommonPrefix(){
return getOrElse(shouldStripCommonPrefix,false);
}
public Boolean ShouldStripCommonSuffix(){
return getOrElse(shouldStripCommonSuffix,false);
}
public void setOvertimeFactor(double overtimeFactor){
this.overtimeFactor = overtimeFactor;
}

public double getOvertimeFactor() {
return getOrElse(this.overtimeFactor, 1.0);
}

public void setFilterRegex(String filterRegex) {
this.filterRegex = filterRegex;
}

public String getFilterRegex() {
return getOrElse(this.filterRegex,"");
}

public static Config defaultConfig() {
return new Config();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,7 @@ private BuildViewModel buildViewOf(Run<?, ?> build) {

return BuildView.of(build, relative, systemTime);
}
public boolean hasQueuedItem() {
return job.getQueueItem() != null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public void serialize(JobView job, JsonGenerator jgen, SerializerProvider provid
jgen.writeObjectField("hashCode", job.hashCode());
jgen.writeObjectField("progress", job.progress());
jgen.writeObjectField("estimatedDuration", job.estimatedDuration());
/*jgen.writeObjectField("buildExceedsEstimatedDuration", job.buildExceedsEstimatedDuration());*/
jgen.writeObjectField("hasQueuedItem", job.hasQueuedItem());

for (Feature<?> feature : job.features()) {
Object serialised = feature.asJson();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

import com.smartcodeltd.jenkinsci.plugins.buildmonitor.facade.StaticJenkinsAPIs;
import com.smartcodeltd.jenkinsci.plugins.buildmonitor.viewmodel.features.*;
import com.smartcodeltd.jenkinsci.plugins.buildmonitor.viewmodel.features.StripMostCommons.StripMostCommonPrefixConfig;
import com.smartcodeltd.jenkinsci.plugins.buildmonitor.viewmodel.features.StripMostCommons.StripMostCommonSuffixConfig;
import com.smartcodeltd.jenkinsci.plugins.buildmonitor.viewmodel.features.headline.HeadlineConfig;
import com.smartcodeltd.jenkinsci.plugins.buildmonitor.viewmodel.features.jobNameFilter.JobNameFilterConfig;
import hudson.model.Job;

import java.util.List;
Expand Down Expand Up @@ -30,8 +33,12 @@ public JobView viewOf(Job<?, ?> job) {

// todo: a more elegant way of assembling the features would be nice
viewFeatures.add(new HasHeadline(new HeadlineConfig(config.shouldDisplayCommitters())));
viewFeatures.add(new shouldStripMostCommonPrefix(new StripMostCommonPrefixConfig(config.ShouldStripCommonPrefix())));
viewFeatures.add(new shouldStripMostCommonSuffix(new StripMostCommonSuffixConfig(config.ShouldStripCommonSuffix())));
viewFeatures.add(new KnowsLastCompletedBuildDetails());
viewFeatures.add(new KnowsCurrentBuildsDetails());
viewFeatures.add(new BuildExceedsEstimatedDuration(config.getOvertimeFactor()));
viewFeatures.add(new HasNameFilter(new JobNameFilterConfig(config.getFilterRegex())));

if (jenkins.hasPlugin(Claim)) {
viewFeatures.add(new CanBeClaimed());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public boolean greaterThan(Duration otherDuration) {
return duration > otherDuration.toLong();
}

private long toLong() {
public long toLong() {
return duration;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.smartcodeltd.jenkinsci.plugins.buildmonitor.viewmodel.features;

import org.codehaus.jackson.annotate.JsonValue;

/**
* @author Vincent & Robert
*/
public class BuildExceeds {
private final boolean value;

public BuildExceeds(boolean value) {
this.value = value;
}

@JsonValue
public boolean value() {
return value;
}

public BuildExceeds asJson() {
return this;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.smartcodeltd.jenkinsci.plugins.buildmonitor.viewmodel.features;

import com.smartcodeltd.jenkinsci.plugins.buildmonitor.viewmodel.JobView;
import com.smartcodeltd.jenkinsci.plugins.buildmonitor.viewmodel.NullBuildView;
import com.smartcodeltd.jenkinsci.plugins.buildmonitor.viewmodel.duration.Duration;
import com.smartcodeltd.jenkinsci.plugins.buildmonitor.viewmodel.duration.DurationInMilliseconds;

public class BuildExceedsEstimatedDuration implements Feature<BuildExceeds> {
private JobView job;
private double config;

public BuildExceedsEstimatedDuration(double config) {
this.config = config;
}

@Override
public BuildExceedsEstimatedDuration of(JobView jobView) {
this.job = jobView;
return this;
}

public boolean buildExceedsEstimatedDuration() {
double overTimeFactor = this.config;

if (job.lastBuild() instanceof NullBuildView) {
return false;
}

Duration tooLongDuration = new DurationInMilliseconds((long) ((double) job.lastBuild().estimatedDuration().toLong() * overTimeFactor));

return job.isRunning() && job.lastBuild().elapsedTime().greaterThan(tooLongDuration);
}

@Override
public BuildExceeds asJson() {
return new BuildExceeds(buildExceedsEstimatedDuration());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.smartcodeltd.jenkinsci.plugins.buildmonitor.viewmodel.features;

import com.smartcodeltd.jenkinsci.plugins.buildmonitor.viewmodel.JobView;
import com.smartcodeltd.jenkinsci.plugins.buildmonitor.viewmodel.features.jobNameFilter.*;

public class HasNameFilter implements Feature<JobNameFiltered> {
private JobView job;
private JobNameFilterConfig config;

public HasNameFilter(JobNameFilterConfig config) {
this.config = config;
}

@Override
public HasNameFilter of(JobView jobView) {
this.job = jobView;

return this;
}

@Override
public JobNameFiltered asJson() {
JobNameFilterer nameFilterer = new JobNameFilterer(job.name());

nameFilterer = nameFilterer.filterRegex(config.regex);

return new JobNameFiltered(nameFilterer.getJobName());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.smartcodeltd.jenkinsci.plugins.buildmonitor.viewmodel.features.StripMostCommons;

/**
* Contains methods used to filter the job name with specified prefix, suffix and regex
*/
public class StripMostCommonPrefix {
private StripMostCommonPrefixConfig conf;

public StripMostCommonPrefix(StripMostCommonPrefixConfig conf) {
this.conf = conf;
}

public boolean getPrefix(){
//Boolean.toString(conf.prefix)
return conf.prefix;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.smartcodeltd.jenkinsci.plugins.buildmonitor.viewmodel.features.StripMostCommons;

/**
* @author Vincent & Robert
*/
public class StripMostCommonPrefixConfig {
public final Boolean prefix;

public StripMostCommonPrefixConfig(Boolean prefix) {
this.prefix = prefix;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.smartcodeltd.jenkinsci.plugins.buildmonitor.viewmodel.features.StripMostCommons;

/**
* Contains methods used to filter the job name with specified prefix, suffix and regex
*/
public class StripMostCommonSuffix {
private StripMostCommonSuffixConfig conf;

public StripMostCommonSuffix(StripMostCommonSuffixConfig conf) {
this.conf = conf;
}


public boolean getSuffix(){
return conf.suffix;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.smartcodeltd.jenkinsci.plugins.buildmonitor.viewmodel.features.StripMostCommons;

/**
* @author Vincent & Robert
*/
public class StripMostCommonSuffixConfig {
public final Boolean suffix;

public StripMostCommonSuffixConfig(Boolean suffix) {
this.suffix = suffix;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.smartcodeltd.jenkinsci.plugins.buildmonitor.viewmodel.features.StripMostCommons;

import org.codehaus.jackson.annotate.JsonValue;

/**
* @author Vincent & Robert
*/
public class StrippedMostCommonPrefix {
private final boolean value;

public StrippedMostCommonPrefix(boolean value) {
this.value = value;
}

@JsonValue
public boolean value() {
return value;
}

public StrippedMostCommonPrefix asJson() {
return this;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.smartcodeltd.jenkinsci.plugins.buildmonitor.viewmodel.features.StripMostCommons;

import org.codehaus.jackson.annotate.JsonValue;

/**
* @author Vincent & Robert
*/
public class StrippedMostCommonSuffix {
private final boolean value;

public StrippedMostCommonSuffix(boolean value) {
this.value = value;
}

@JsonValue
public boolean value() {
return value;
}

public StrippedMostCommonSuffix asJson() {
return this;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.smartcodeltd.jenkinsci.plugins.buildmonitor.viewmodel.features.jobNameFilter;

/**
* @author Vincent & Robert
*/
public class JobNameFilterConfig {
public final String regex;

public JobNameFilterConfig( String regex) {
this.regex = regex;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.smartcodeltd.jenkinsci.plugins.buildmonitor.viewmodel.features.jobNameFilter;

import org.codehaus.jackson.annotate.JsonValue;

/**
* @author Vincent & Robert
*/
public class JobNameFiltered {
private final String value;

public JobNameFiltered(String value) {
this.value = value;
}

@JsonValue
public String value() {
return value;
}

public JobNameFiltered asJson() {
return this;
}
}
Loading