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

new features #3

Closed
wants to merge 2 commits into from
Closed
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
6 changes: 2 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ THE SOFTWARE.
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>1.399</version>
<version>1.477</version>
</parent>

<artifactId>throttle-concurrents</artifactId>
Expand Down Expand Up @@ -99,13 +99,11 @@ THE SOFTWARE.
<developerConnection>scm:git:[email protected]:jenkinsci/throttle-concurrent-builds-plugin.git</developerConnection>
<url>http://github.com/jenkinsci/throttle-concurrents-plugin</url>
</scm>


<pluginRepositories>
<pluginRepository>
<id>repo.jenkins-ci.org</id>
<url>http://repo.jenkins-ci.org/public/</url>
</pluginRepository>
</pluginRepositories>
</project>
</project>

Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
package hudson.plugins.throttleconcurrents;

import hudson.Extension;
import hudson.matrix.MatrixConfiguration;
import hudson.model.AbstractProject;
import hudson.model.Hudson;
import hudson.model.Node;
import hudson.model.Queue;
import hudson.model.queue.CauseOfBlockage;

import java.util.List;
import java.util.logging.Logger;

/**
* Created with IntelliJ IDEA.
* User: psamoshkin
* Date: 11/9/12
* Time: 5:04 PM
* To change this template use File | Settings | File Templates.
*/
@Extension
public class CategoryTaskDispatcher extends ThrottleQueueTaskDispatcher {
@Override
public CauseOfBlockage canTake(Node node, Queue.Task task, ThrottleJobProperty tjp) {
if (tjp.getThrottleCategory()) {
if (tjp.getCategories() != null && !tjp.getCategories().isEmpty()) {
for (String catNm : tjp.getCategories()) {
ThrottleJobProperty.ThrottleCategory category =
((ThrottleJobProperty.DescriptorImpl) tjp.getDescriptor()).getCategoryByName(catNm);
if (category != null) {
synchronized (category) {
int maxConcurrentPerNode = category.getMaxConcurrentPerNode().intValue();
long startIntervalPerNode = category.getInterval();
if (maxConcurrentPerNode > 0 || startIntervalPerNode > 0) {
List<AbstractProject<?,?>> categoryProjects = category.getProjects();
int runCount = 0;
long minElapsedTime = 4294967296L;
long elapsedTime = minElapsedTime;

for (AbstractProject<?,?> catProj : categoryProjects) {
if (Hudson.getInstance().getQueue().isPending(catProj)) {
return CauseOfBlockage.fromMessage(Messages._ThrottleQueueTaskDispatcher_BuildPending());
}
runCount += buildsOfProjectOnNode(node, catProj);
elapsedTime = buildsOfProjectOnNodeMinimalElapsedTime(node, catProj);
if(elapsedTime < minElapsedTime){
minElapsedTime = elapsedTime;
}
}
// This would mean that there are as many or more builds currently running than are allowed.
if (maxConcurrentPerNode > 0 && runCount >= maxConcurrentPerNode) {
return CauseOfBlockage.fromMessage(Messages._ThrottleQueueTaskDispatcher_MaxCapacityOnNode(runCount));
}
else if(runCount > 0 && startIntervalPerNode > 0
&& minElapsedTime != LONG_MAX && startIntervalPerNode > minElapsedTime){
return CauseOfBlockage.fromMessage(Messages._ThrottleQueueTaskDispatcher_IntervalOnNode(runCount));
}
}
}
}
}
}
}
return null;
}

@Override
public CauseOfBlockage canRun(Queue.Task task, ThrottleJobProperty tjp) {
if (tjp.getThrottleCategory()) {
if (tjp.getCategories() != null && !tjp.getCategories().isEmpty()) {
for (String catNm : tjp.getCategories()) {
ThrottleJobProperty.ThrottleCategory category;

category = ((ThrottleJobProperty.DescriptorImpl) tjp.getDescriptor()).getCategoryByName(catNm);

if (category != null) {
synchronized (category){
List<AbstractProject<?,?>> categoryProjects = category.getProjects();

int maxConcurrentTotal = category.getMaxConcurrentTotal().intValue();
if (maxConcurrentTotal > 0) {
int totalRunCount = 0;

for (AbstractProject<?,?> catProj : categoryProjects) {
if (Hudson.getInstance().getQueue().isPending(catProj)) {
return CauseOfBlockage.fromMessage(Messages._ThrottleQueueTaskDispatcher_BuildPending());
}
totalRunCount += buildsOfProjectOnAllNodes(catProj);
}

if (totalRunCount >= maxConcurrentTotal) {
return CauseOfBlockage.fromMessage(Messages._ThrottleQueueTaskDispatcher_MaxCapacityTotal(totalRunCount));
}
}
}
}
}
}
}

return null;
}

private static final Logger LOGGER = Logger.getLogger(CategoryTaskDispatcher.class.getName());
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package hudson.plugins.throttleconcurrents;

import hudson.Extension;
import hudson.model.Node;
import hudson.model.Queue;
import hudson.model.queue.CauseOfBlockage;

import java.util.logging.Logger;

/**
* Created with IntelliJ IDEA.
* User: psamoshkin
* Date: 11/9/12
* Time: 5:04 PM
* To change this template use File | Settings | File Templates.
*/
@Extension
public class ProjectTaskDispatcher extends ThrottleQueueTaskDispatcher {

@Override
public CauseOfBlockage canTake(Node node, Queue.Task task, ThrottleJobProperty tjp) {
if (tjp.getThrottleProjectAlone()) {
if (tjp.getMaxConcurrentPerNode().intValue() > 0) {
int maxConcurrentPerNode = tjp.getMaxConcurrentPerNode().intValue();
long interval= tjp.getInterval().intValue();
int runCount = buildsOfProjectOnNode(node, task);

long minElapsedTime = buildsOfProjectOnNodeMinimalElapsedTime(node, task);

// This would mean that there are as many or more builds currently running than are allowed.
if (runCount >= maxConcurrentPerNode) {
return CauseOfBlockage.fromMessage(Messages._ThrottleQueueTaskDispatcher_MaxCapacityOnNode(runCount));
} else if(runCount>0 && interval > 0
&& minElapsedTime != LONG_MAX && interval > minElapsedTime){
return CauseOfBlockage.fromMessage(Messages._ThrottleQueueTaskDispatcher_IntervalOnNode(runCount));
}
}
}

return null;
}

public CauseOfBlockage canRun(Queue.Task task, ThrottleJobProperty tjp) {

if (tjp.getThrottleProjectAlone()) {
if (tjp.getMaxConcurrentTotal().intValue() > 0) {
int maxConcurrentTotal = tjp.getMaxConcurrentTotal().intValue();
int totalRunCount = buildsOfProjectOnAllNodes(task);

if (totalRunCount >= maxConcurrentTotal) {
return CauseOfBlockage.fromMessage(Messages._ThrottleQueueTaskDispatcher_MaxCapacityTotal(totalRunCount));
}
}
}

return null;
}

private static final Logger LOGGER = Logger.getLogger(ProjectTaskDispatcher.class.getName());
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package hudson.plugins.throttleconcurrents;

import hudson.model.Action;

/**
* Created with IntelliJ IDEA.
* User: psamoshkin
* Date: 10/25/12
* Time: 12:07 PM
* To change this template use File | Settings | File Templates.
*/
public class ReleaseThrottleLockAction implements Action {
@Override
public String getIconFileName() {
return null;
}

@Override
public String getDisplayName() {
return null;
}

@Override
public String getUrlName() {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package hudson.plugins.throttleconcurrents;

import hudson.Extension;
import hudson.Launcher;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.BuildListener;
import hudson.tasks.BuildStepDescriptor;
import hudson.tasks.BuildStepMonitor;
import hudson.tasks.Builder;
import hudson.tasks.Publisher;
import net.sf.json.JSONObject;
import org.kohsuke.stapler.StaplerRequest;

import java.io.IOException;

/**
* Created with IntelliJ IDEA.
* User: psamoshkin
* Date: 10/24/12
* Time: 5:09 PM
* To change this template use File | Settings | File Templates.
*/
public class ReleaseThrottleLockBuilder extends Builder {

@Extension
public static final DescriptorImpl DESCRIPTOR = new DescriptorImpl();

@Override
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
build.addAction(new ReleaseThrottleLockAction());
return true;
}

@Override
public BuildStepMonitor getRequiredMonitorService() {
return BuildStepMonitor.NONE;
}

@Override
public BuildStepDescriptor<Builder> getDescriptor() {
return DESCRIPTOR;
}

private static class DescriptorImpl extends BuildStepDescriptor<Builder> {
protected DescriptorImpl() {
super(ReleaseThrottleLockBuilder.class);
}

@Override
public String getDisplayName() {
return "Release throttle-concurrent lock";
}

@Override
public String getHelpFile() {
return null;
}

@Override
public boolean isApplicable(Class<? extends AbstractProject> jobType) {
return true;
}

@Override
public Builder newInstance(StaplerRequest req, JSONObject formData) throws FormException {
return new ReleaseThrottleLockBuilder();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package hudson.plugins.throttleconcurrents;

import hudson.Extension;
import hudson.Launcher;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.BuildListener;
import hudson.tasks.BuildStepDescriptor;
import hudson.tasks.BuildStepMonitor;
import hudson.tasks.Publisher;
import net.sf.json.JSONObject;
import org.kohsuke.stapler.StaplerRequest;

import java.io.IOException;

/**
* Created with IntelliJ IDEA.
* User: psamoshkin
* Date: 10/24/12
* Time: 5:09 PM
* To change this template use File | Settings | File Templates.
*/
public class ReleaseThrottleLockPublisher extends Publisher {

@Extension
public static final DescriptorImpl DESCRIPTOR = new DescriptorImpl();

@Override
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
build.addAction(new ReleaseThrottleLockAction());
return true;
}

@Override
public BuildStepMonitor getRequiredMonitorService() {
return BuildStepMonitor.NONE;
}

@Override
public BuildStepDescriptor<Publisher> getDescriptor() {
return DESCRIPTOR;
}

private static class DescriptorImpl extends BuildStepDescriptor<Publisher> {
protected DescriptorImpl() {
super(ReleaseThrottleLockPublisher.class);
}

@Override
public String getDisplayName() {
return "Release throttle-concurrent lock";
}

@Override
public String getHelpFile() {
return null;
}

@Override
public boolean isApplicable(Class<? extends AbstractProject> jobType) {
return true;
}

@Override
public Publisher newInstance(StaplerRequest req, JSONObject formData) throws FormException {
return new ReleaseThrottleLockPublisher();
}
}

}
Loading