Skip to content

Commit

Permalink
fix(concourse): support re-run (dot-) builds (#779)
Browse files Browse the repository at this point in the history
* fix(concourse): support re-run (dot-) builds

Concourse 6.x introduces "re-run" builds, which have a decimal build number (i.e. 12.1) breaking the existing getNumber() method expecting an int. This change will allow igor to properly parse these build numbers, and will collapse the build listing wherein each number is the max(decimalNumber).

Addresses issue: spinnaker/spinnaker#5773

* Updates per review

Co-authored-by: Jared Stehler <jared.stehler@edgenuity.com>
  • Loading branch information
jaredstehler and jared-stehler committed Jul 7, 2020
1 parent f47f4cf commit 5de2743
Show file tree
Hide file tree
Showing 4 changed files with 374 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public void onEvent(
// we don't care about task output
if (origin != null
&& !"stdout".equals(origin.getSource())
&& !"stderr".equals(origin.getSource())
&& ev.getData().getMetadata() != null) {
sink.next(ev);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,28 @@

package com.netflix.spinnaker.igor.concourse.client.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.netflix.spinnaker.igor.build.model.Result;
import java.math.BigDecimal;
import lombok.Getter;
import lombok.Setter;

@Setter
public class Build {
public class Build implements Comparable<Build> {
@Getter private String id;
private String name; // the readable build number

@Getter private long startTime; // milliseconds since Unix epoch

@Getter private String status;

@JsonIgnore
public BigDecimal getDecimalNumber() {
return new BigDecimal(name);
}

public int getNumber() {
return Integer.parseInt(name);
return getDecimalNumber().intValue();
}

public boolean isSuccessful() {
Expand All @@ -49,4 +56,9 @@ public Result getResult() {
}
return Result.NOT_BUILT;
}

@Override
public int compareTo(Build o) {
return o.getDecimalNumber().compareTo(getDecimalNumber());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
Expand All @@ -70,8 +71,18 @@ public class ConcourseService implements BuildOperations, BuildProperties {

public ConcourseService(
ConcourseProperties.Host host, Optional<ArtifactDecorator> artifactDecorator) {
this(
new ConcourseClient(host.getUrl(), host.getUsername(), host.getPassword()),
host,
artifactDecorator);
}

protected ConcourseService(
ConcourseClient client,
ConcourseProperties.Host host,
Optional<ArtifactDecorator> artifactDecorator) {
this.host = host;
this.client = new ConcourseClient(host.getUrl(), host.getUsername(), host.getPassword());
this.client = client;
this.resourceFilter =
host.getResourceFilterRegex() == null
? null
Expand Down Expand Up @@ -136,7 +147,8 @@ public List<GenericGitRevision> getGenericGitRevisions(String jobPath, GenericBu
public GenericBuild getGenericBuild(String jobPath, int buildNumber) {
return getBuilds(jobPath, null).stream()
.filter(build -> build.getNumber() == buildNumber)
.findAny()
.sorted()
.findFirst()
.map(build -> getGenericBuild(jobPath, build, true))
.orElse(null);
}
Expand All @@ -160,7 +172,7 @@ public GenericBuild getGenericBuild(String jobPath, Build b, boolean fetchResour
+ "/jobs/"
+ job.getName()
+ "/builds/"
+ b.getNumber());
+ b.getDecimalNumber());
build.setTimestamp(Long.toString(b.getStartTime() * 1000));

if (!fetchResources) {
Expand Down Expand Up @@ -327,14 +339,21 @@ public List<Build> getBuilds(String jobPath, @Nullable Long since) {
return emptyList();
}

return client
.getBuildService()
return client.getBuildService()
.builds(
job.getTeamName(),
job.getPipelineName(),
job.getName(),
host.getBuildLookbackLimit(),
since);
since)
.stream()
.sorted()
.collect(
Collectors.toMap(
(b) -> b.getNumber(), Function.identity(), (b1, b2) -> b1, LinkedHashMap::new))
.values()
.stream()
.collect(Collectors.toList());
}

public List<String> getResourceNames(String team, String pipeline) {
Expand Down
Loading

0 comments on commit 5de2743

Please sign in to comment.