use of org.jboss.pnc.rest.api.parameters.BuildsFilterParameters in project bacon by project-ncl.
the class BuildInfoCollector method getLatestBuild.
public PncBuild getLatestBuild(String configId, BuildSearchType searchType) {
try {
BuildsFilterParameters filter = new BuildsFilterParameters();
Optional<String> queryParam;
switch(searchType) {
case ANY:
queryParam = query("status==%s", BuildStatus.SUCCESS);
break;
case PERMANENT:
queryParam = query("status==%s;temporaryBuild==%s", BuildStatus.SUCCESS, false);
break;
case TEMPORARY:
// NCL-5943 Cannot ignore permanent(regular) builds because they cause NO_REBUILD_REQUIRED even for
// temporary builds. That means "latest build" for a temporary build can be permanent(regular).
queryParam = query("status==%s", BuildStatus.SUCCESS);
break;
default:
queryParam = Optional.empty();
}
// Note: sort by id not allowed
Iterator<Build> buildIterator = buildConfigClient.getBuilds(configId, filter, of("=desc=submitTime"), queryParam).iterator();
if (!buildIterator.hasNext()) {
throw new NoSuccessfulBuildException(configId);
}
Build build = buildIterator.next();
PncBuild result = new PncBuild(build);
result.addBuiltArtifacts(toList(buildClient.getBuiltArtifacts(build.getId())));
return result;
} catch (ClientException e) {
throw new RuntimeException("Failed to get latest successful build for " + configId, e);
}
}
use of org.jboss.pnc.rest.api.parameters.BuildsFilterParameters in project bacon by project-ncl.
the class BuildInfoCollector method getBuildsFromGroupBuild.
/**
* Get all the builds done in a build group. If the build finished with 'NO_REBUILD_REQUIRED', get the 'original'
* successful build and return it instead If the build was successful, we don't grab the logs since they can be
* quite long.
*
* @param groupBuild the group build to get the builds
* @return The information on the group build and the builds performed
*/
public GroupBuildInfo getBuildsFromGroupBuild(GroupBuild groupBuild) {
Map<String, PncBuild> result = new HashMap<>();
BuildsFilterParameters filter = new BuildsFilterParameters();
filter.setLatest(false);
filter.setRunning(false);
try {
Collection<Build> builds = groupBuildClient.getBuilds(groupBuild.getId(), filter).getAll();
for (Build build : builds) {
PncBuild pncBuild;
if (build.getStatus() == BuildStatus.NO_REBUILD_REQUIRED) {
BuildRef buildRef = build.getNoRebuildCause();
Build realBuild = buildClient.getSpecific(buildRef.getId());
pncBuild = new PncBuild(realBuild);
} else {
pncBuild = new PncBuild(build);
}
pncBuild.addBuiltArtifacts(toList(buildClient.getBuiltArtifacts(pncBuild.getId())));
result.put(pncBuild.getName(), pncBuild);
}
return new GroupBuildInfo(groupBuild, result);
} catch (RemoteResourceException e) {
throw new RuntimeException("Failed to get group build info for " + groupBuild.getId(), e);
}
}
use of org.jboss.pnc.rest.api.parameters.BuildsFilterParameters in project bacon by project-ncl.
the class PncBuilder method verifyAllBuildsInGroupBuildInFinalStateWithProperCount.
/**
* This check makes sure that even when a group build is marked as done, we also need to make sure all its builds
* are also done (NCL-6044). We also make sure that the number of builds done is the same as the number of build
* configs in the group build's group config (NCL-6041)
*
* This is done to handle a weird timing error which happens when a group build finishes, the group build status is
* updated before the last individual build status is updated to their final state. This may cause inconsistency in
* the last build data.
*
* This is especially true when the Group build status is NO_REBUILD_REQUIRED, where it is also essential that all
* the individual builds are also in their final state (and logically NO_REBUILD_REQUIRED status) so that we can get
* the no rebuild cause.
*
* @param groupBuildId the group build id
* @return whether all the builds have a final status or not
*/
boolean verifyAllBuildsInGroupBuildInFinalStateWithProperCount(String groupBuildId) {
// log set to info for CPaaS to detect infinite loop
log.info("Checking if all builds in group build {} are in final state with proper count of builds ( {} )", groupBuildId, UrlGenerator.generateGroupBuildUrl(groupBuildId));
BuildsFilterParameters filter = new BuildsFilterParameters();
filter.setLatest(false);
filter.setRunning(false);
try {
Collection<Build> builds = groupBuildClient.getBuilds(groupBuildId, filter).getAll();
boolean allFinal = builds.stream().allMatch(b -> b.getStatus().isFinal());
return allFinal && getCountOfBuildConfigsForGroupBuild(groupBuildId) == builds.size();
} catch (ClientException e) {
log.warn("Failed to check if all builds in group build {} have a final status. Assuming it is not finished", groupBuildId, e);
return false;
}
}
use of org.jboss.pnc.rest.api.parameters.BuildsFilterParameters in project pnc by project-ncl.
the class AdvancedBuildConfigurationClient method fallbackSupplier.
/**
* Used to retrieve build through through REST when WS Client loses connection and reconnects
*
* @param bcId Id of the BuildConfig where the build was run
* @return
* @throws RemoteResourceException
*/
private Build fallbackSupplier(String bcId) throws RemoteResourceException {
BuildsFilterParameters parameters = new BuildsFilterParameters();
parameters.setLatest(true);
Build build = null;
try (BuildConfigurationClient client = new BuildConfigurationClient(configuration)) {
build = client.getBuilds(bcId, parameters).iterator().next();
}
return build;
}
use of org.jboss.pnc.rest.api.parameters.BuildsFilterParameters in project pnc by project-ncl.
the class BuildEndpointTest method shouldFilterByBuildConfigurationNameAndInvalidUserId.
@Test
public void shouldFilterByBuildConfigurationNameAndInvalidUserId() throws Exception {
BuildClient client = new BuildClient(RestClientConfiguration.asAnonymous());
String buildConfigName = DatabaseDataInitializer.PNC_PROJECT_BUILD_CFG_ID;
String username = "random-user-name";
String rsql = "user.username==" + username;
BuildsFilterParameters filter = new BuildsFilterParameters();
filter.setBuildConfigName(buildConfigName);
List<Build> builds = new ArrayList<>(client.getAll(filter, null, Optional.empty(), Optional.of(rsql)).getAll());
assertThat(builds).isEmpty();
}
Aggregations