Skip to content

Commit

Permalink
Merge pull request #4 from jenkinsci/feature/JENKINS-32445
Browse files Browse the repository at this point in the history
JENKINS 32445 basic support for clouds
  • Loading branch information
dominiquebrice committed May 8, 2016
2 parents 1842c5b + f91a8cb commit 2605635
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 5 deletions.
23 changes: 22 additions & 1 deletion pom.xml
Expand Up @@ -31,7 +31,7 @@ THE SOFTWARE.
</parent>

<artifactId>label-linked-jobs</artifactId>
<version>5.0-SNAPSHOT</version>
<version>5.0.1-SNAPSHOT</version>
<packaging>hpi</packaging>
<name>Label Linked Jobs Plugin</name>
<description>Gives the list of jobs associated to a given atomic label.</description>
Expand Down Expand Up @@ -91,5 +91,26 @@ THE SOFTWARE.
<url>http://repo.jenkins-ci.org/public/</url>
</pluginRepository>
</pluginRepositories>

<build>
<plugins>
<!-- section to avoid trouble while uploading -->
<!-- see http://jenkins-ci.361315.n4.nabble.com/Can-t-maven-release-my-plugin-401-on-upload-to-repo-jenkins-ci-org-td4796955.html -->
<!-- and https://issues.jenkins-ci.org/browse/INFRA-588 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.6</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-http</artifactId>
<version>2.10</version>
<type>jar</type>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>

</project>
Expand Up @@ -32,6 +32,7 @@
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import jenkins.model.Jenkins;
import jenkins.plugins.linkedjobs.helpers.TriggeredJobsHelper;
Expand All @@ -48,6 +49,7 @@
import hudson.model.labels.LabelAtom;
import hudson.model.RootAction;
import hudson.model.TopLevelItem;
import hudson.slaves.Cloud;
import hudson.tasks.Builder;

/**
Expand Down Expand Up @@ -104,6 +106,12 @@ public boolean getRefresh() {
return true;
}

// boolean indicator used on the dashboard page to determine whether
// clouds information should be displayed at all
public boolean getHasAtLeastOneCloud() {
return Jenkins.getInstance().clouds.size() > 0;
}

/**
* This function scans all jobs and all nodes of this Jenkins instance
* to extract all LabelAtom defined. Goal is to list, per LabelAtom, all jobs
Expand Down Expand Up @@ -261,12 +269,19 @@ private boolean isOrphanedLabel(Label label) {
return false;
}
}

// JENKINS-32445, also look for clouds that could support this label
for (Cloud c : Jenkins.getInstance().clouds) {
if (c.canProvision(label)) {
return false;
}
}
return true;
}

// this function finds all triggered jobs that can't run on any nodes
// because their triggering jobs trigger them with a label that is compatible
// with no nodes - JENKINS-27588
// with no nodes - JENKINS-27588 - nor clouds - JENKINS-32445
public List<TriggeredJob> getOrphanedTriggeredJobs() {
ArrayList<TriggeredJob> orphanedJobs = new ArrayList<TriggeredJob>();
for (Label label : m_triggeredJobsByLabel.keySet()) {
Expand All @@ -278,8 +293,8 @@ public List<TriggeredJob> getOrphanedTriggeredJobs() {
return orphanedJobs;
}

public List<AbstractProject<?, ?>> getOrphanedDefaultValueJobs() {
ArrayList<AbstractProject<?, ?>> orphanedJobs = new ArrayList<AbstractProject<?, ?>>();
public Set<AbstractProject<?, ?>> getOrphanedDefaultValueJobs() {
HashSet<AbstractProject<?, ?>> orphanedJobs = new HashSet<AbstractProject<?,?>>();
for (Label label : m_jobsByDefaultLabel.keySet()) {
if (isOrphanedLabel(label)) {
// all these triggered jobs are in trouble!
Expand Down
Expand Up @@ -29,9 +29,11 @@
import java.util.HashMap;
import java.util.List;

import jenkins.model.Jenkins;
import jenkins.plugins.linkedjobs.model.JobsGroup;
import hudson.model.Label;
import hudson.model.labels.LabelAtom;
import hudson.slaves.Cloud;

/**
* For each Label, Jenkins associates an object of this class to a Linked Jobs page.<br/><br/>
Expand Down Expand Up @@ -62,6 +64,24 @@ public String getTitle() {
public LabelAtom getLabel() {
return this.label;
}

// clouds that can provision this atomic label
public List<Cloud> getProvisioningClouds() {
List<Cloud> provisioningClouds = new ArrayList<Cloud>();
for (Cloud c : Jenkins.getInstance().clouds) {
if (c.canProvision(label)) {
provisioningClouds.add(c);
}
}
return provisioningClouds;
}

// util function, because List doesn't have a function
// to get its size starting with 'get', so no way to call it
// directly in index.jelly
public int getSize(List<Cloud> l) {
return l == null ? 0 : l.size();
}

/**
* This function retrieves all jobs existing on this jenkins instance and
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/jenkins/plugins/linkedjobs/model/JobsGroup.java
Expand Up @@ -26,6 +26,7 @@

import hudson.model.Label;
import hudson.model.Node;
import hudson.slaves.Cloud;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -82,6 +83,17 @@ public List<Node> getNodes() {
public boolean isSingleNode() {
return applicableNodes.size() == 1;
}

// clouds that can provision this label (and thus jobs in this group)
public List<Cloud> getProvisioningClouds() {
List<Cloud> provisioningClouds = new ArrayList<Cloud>();
for (Cloud c : Jenkins.getInstance().clouds) {
if (c.canProvision(label)) {
provisioningClouds.add(c);
}
}
return provisioningClouds;
}

/************************************
* implements Comparable<JobsGroup>
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/jenkins/plugins/linkedjobs/model/LabelAtomData.java
Expand Up @@ -30,6 +30,7 @@
import jenkins.plugins.linkedjobs.actions.LabelLinkedJobsAction;
import hudson.model.Node;
import hudson.model.labels.LabelAtom;
import hudson.slaves.Cloud;
import hudson.util.VersionNumber;

public class LabelAtomData extends AbstractJobsGroup implements Comparable<LabelAtomData> {
Expand Down Expand Up @@ -74,6 +75,18 @@ public int getNodesCount() {
return nodes.size();
}

// JENKINS-32445
// return the number of clouds that can provision this atomic label
public int getCloudsCount() {
int result = 0;
for (Cloud c : Jenkins.getInstance().clouds) {
if (c.canProvision(labelAtom)) {
result++;
}
}
return result;
}

public boolean getPluginActiveForLabel() {
for (hudson.model.Action a : labelAtom.getActions()) {
if (a instanceof LabelLinkedJobsAction) {
Expand Down
Expand Up @@ -36,13 +36,15 @@ THE SOFTWARE.

<h2>Labels</h2>
<j:set var="unused" value="${it.refresh}" />
<j:set var="hasClouds" value="${it.hasAtLeastOneCloud}" />
<j:set var="labels" value="${it.labelsData}" />
<j:forEach var="label" items="${labels}">
<div>
<j:set var="jobCount" value="${label.jobsCount}" />
<j:set var="triggeredJobCount" value="${label.triggeredJobsCount}" />
<j:set var="jobsWithLabelDefaultValueCount" value="${label.jobsWithLabelDefaultValueCount}" />
<j:set var="nodeCount" value="${label.nodesCount}" />
<j:set var="cloudCount" value="${label.cloudsCount}" />
<j:set var="pluginActive" value="${label.pluginActiveForLabel}" />
<h4><a href="${rootURL}/${label.labelURL}">${label.label}</a></h4>
<j:if test="${pluginActive}">
Expand All @@ -56,7 +58,8 @@ THE SOFTWARE.
<j:if test="${jobsWithLabelDefaultValueCount == 1}">This label is used by 1 job as a default value for its Label parameter.<br/></j:if>
<j:if test="${jobsWithLabelDefaultValueCount > 1}">This label is used by ${jobsWithLabelDefaultValueCount} jobs as a default value for their Label parameter.<br/></j:if>
This label is defined by ${nodeCount} node<j:if test="${nodeCount > 1}">s</j:if>.
<j:if test="${nodeCount == 0}"><b><font color="red">You should verify your configuration.</font></b></j:if>
<j:if test="${hasClouds}">It can be provisioned by ${cloudCount} cloud<j:if test="${cloudCount > 1}">s</j:if>.&amp;nbsp;</j:if>
<j:if test="${(nodeCount == 0) &amp;&amp; ((!hasClouds) || (cloudCount == 0))}"><b><font color="red">You should verify your configuration.</font></b></j:if>
</div>
</j:forEach>
<br/><br/>
Expand Down
Expand Up @@ -44,6 +44,17 @@ THE SOFTWARE.
<j:otherwise>
<h2>Label "${it.label}" is used by the following job(s)</h2>
<br/>

<j:set var="clouds" value="${it.provisioningClouds}" />
<j:if test="${it.getSize(clouds) > 0}">
<div>
Provisioning cloud<j:if test="${it.getSize(clouds) > 1}">s</j:if>:
<j:forEach var="cloud" items="${clouds}" varStatus="loopStatus">
${cloud.displayName}<j:if test="${!loopStatus.last}">,&#160;</j:if>
</j:forEach>
</div><br/>
</j:if>

<j:forEach var="group" items="${groups}">
<h3>Job<j:if test="${group.hasMoreThanOneJob}">s</j:if> configured with <a href="${rootURL}/${group.labelURL}">${group.label}</a></h3>

Expand All @@ -58,6 +69,16 @@ THE SOFTWARE.
</j:otherwise>
</j:choose>
</div><br/>

<j:set var="jobs_clouds" value="${group.provisioningClouds}" />
<j:if test="${it.getSize(jobs_clouds) > 0}">
<div>
Provisioning cloud<j:if test="${it.getSize(jobs_clouds) > 1}">s</j:if>:
<j:forEach var="job_cloud" items="${jobs_clouds}" varStatus="loopStatus">
${job_cloud.displayName}<j:if test="${!loopStatus.last}">,&#160;</j:if>
</j:forEach>
</div><br/>
</j:if>

<j:if test="${it.detailedView &amp;&amp; !empty(group.jobs)}">
<t:projectView jobs="${group.jobs}"/><br/>
Expand Down Expand Up @@ -85,6 +106,7 @@ THE SOFTWARE.
<j:forEach var="job" items="${group.jobsWithLabelDefaultValue}" varStatus="loopStatus">
<a href="${job.absoluteUrl}">${job.name}</a><j:if test="${!loopStatus.last}">,&#160;</j:if>
</j:forEach>
<br/><br/>
</j:if>

<br/><br/>
Expand Down

0 comments on commit 2605635

Please sign in to comment.