Skip to content

Commit

Permalink
Merge pull request #4 from pjanouse/JENKINS-38196
Browse files Browse the repository at this point in the history
[JENKINS-38196] Fix a NPE when there is a job without label restriction
  • Loading branch information
scoheb committed Sep 20, 2016
2 parents e2e8aa2 + 2663d79 commit 14ca897
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions src/main/java/com/redhat/foreman/ForemanSharedNodeCloud.java
Expand Up @@ -153,9 +153,8 @@ public boolean canProvision(Label label) {
Map<String, String> hostsMap = getForemanAPI().getCompatibleHosts();
Set<String> hosts = hostsMap.keySet();
for (String host: hosts) {
boolean match = label.matches(Label.parse(hostsMap.get(host)));
if (match) {
return true;
if (label == null || label.matches(Label.parse(hostsMap.get(host)))) {
return true;
}
}
return false;
Expand All @@ -178,8 +177,12 @@ public Node call() throws Exception {
}
});
if (futurePlannedNode.get() != null) {
String name = "ForemanNode";
if (label != null) {
name = label.toString();
}
result.add(new NodeProvisioner.PlannedNode(
label.toString(),
name,
futurePlannedNode,
1));
}
Expand All @@ -199,7 +202,11 @@ public Node call() throws Exception {
*/
@CheckForNull
private ForemanSharedNode provision(Label label) throws Exception {
LOGGER.debug("Trying to provision Foreman Shared Node for '" + label.toString() + "'");
String labelName = "";
if (label != null) {
labelName = label.toString();
}
LOGGER.debug("Trying to provision Foreman Shared Node for '" + labelName + "'");

String reservedHostName = getHostToReserve(label);
if (reservedHostName == null) {
Expand Down Expand Up @@ -283,11 +290,9 @@ private String getHostToReserve(Label label) {
Map<String, String> hostsMap = getForemanAPI().getCompatibleHosts();
Set<String> hosts = hostsMap.keySet();
for (String host: hosts) {
boolean match = label.matches(Label.parse(hostsMap.get(host)));
if (match) {
if (getForemanAPI().isHostFree(host)) {
return host;
}
if (getForemanAPI().isHostFree(host)
&& (label == null || label.matches(Label.parse(hostsMap.get(host))))) {
return host;
}
}
return null;
Expand Down

0 comments on commit 14ca897

Please sign in to comment.