use of org.jboss.pnc.client.RemoteResourceException in project pnc by project-ncl.
the class GroupConfigurationEndpointTest method testConcurrentGet.
/**
* reproducer for NCL-3552
*/
@Test
public void testConcurrentGet() throws RemoteResourceException {
GroupConfigurationClient client = new GroupConfigurationClient(RestClientConfiguration.asUser());
Map<Integer, RemoteCollection<BuildConfiguration>> responseMap = new HashMap<>();
String gcId = "100";
ExecutorService executorService = MDCExecutors.newFixedThreadPool(2);
executorService.execute(() -> {
logger.info("Making 1st request ...");
RemoteCollection<BuildConfiguration> configurations = null;
try {
configurations = client.getBuildConfigs(gcId);
} catch (RemoteResourceException e) {
// detected with null in responseMap
}
logger.info("1st done.");
responseMap.put(1, configurations);
});
executorService.execute(() -> {
logger.info("Making 2nd request ...");
RemoteCollection<BuildConfiguration> configurations = null;
try {
configurations = client.getBuildConfigs(gcId);
} catch (RemoteResourceException e) {
// detected with null in responseMap
}
logger.info("2nd done.");
responseMap.put(2, configurations);
});
try {
executorService.awaitTermination(10, TimeUnit.SECONDS);
} catch (InterruptedException e) {
executorService.shutdownNow();
throw new AssertionError("Requests were not completed in given timeout.", e);
}
assertThat(responseMap).containsKeys(1, 2).doesNotContainValue(null);
}
use of org.jboss.pnc.client.RemoteResourceException in project bacon by project-ncl.
the class PigFacade method getBrewTag.
private static String getBrewTag(ProductVersionRef versionRef) {
try (ProductVersionClient productVersionClient = new ProductVersionClient(PncClientHelper.getPncConfiguration())) {
String versionId = versionRef.getId();
ProductVersion version;
try {
version = productVersionClient.getSpecific(versionId);
} catch (RemoteResourceException e) {
throw new RuntimeException("Unable to get product version for " + versionId, e);
}
return version.getAttributes().get("BREW_TAG_PREFIX");
}
}
use of org.jboss.pnc.client.RemoteResourceException in project bacon by project-ncl.
the class PncClientHelper method printBannerIfNecessary.
private static void printBannerIfNecessary(Configuration configuration) {
if (!bannerChecked) {
try (GenericSettingClient genericSettingClient = new GenericSettingClient(configuration)) {
String banner = genericSettingClient.getAnnouncementBanner().getBanner();
if (banner != null && !banner.isEmpty()) {
log.warn("***********************");
log.warn("Announcement: {}", banner);
log.warn("***********************");
}
} catch (RemoteResourceException e) {
log.error(e.getMessage());
}
bannerChecked = true;
}
}
use of org.jboss.pnc.client.RemoteResourceException in project bacon by project-ncl.
the class BuildInfoCollector method getBuildsFromLatestGroupConfiguration.
/**
* Get the latest GroupBuildInfo from the groupConfiguration id. If there are no group builds, a runtime exception
* is thrown.
*
* @param groupConfigurationId the group configuration id
* @param temporaryBuild whether the group build is temporary or not
* @return GroupBuildInfo data of the group build and the list of builds
*/
public GroupBuildInfo getBuildsFromLatestGroupConfiguration(String groupConfigurationId, boolean temporaryBuild) {
try {
RemoteCollection<BuildConfiguration> configs = groupConfigurationClient.getBuildConfigs(groupConfigurationId);
Map<String, PncBuild> builds = new HashMap<>();
for (BuildConfiguration config : configs) {
PncBuild build = getLatestBuild(config.getId(), temporaryBuild ? BuildSearchType.ANY : BuildSearchType.PERMANENT);
builds.put(config.getName(), build);
}
// TODO: builds should be enough, getting latest build group to satisfy the current API
return new GroupBuildInfo(getLatestGroupBuild(groupConfigurationId, temporaryBuild), builds);
} catch (RemoteResourceException e) {
throw new RuntimeException("Cannot get list of group builds for group configuration " + groupConfigurationId);
}
}
use of org.jboss.pnc.client.RemoteResourceException 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);
}
}
Aggregations