Search in sources :

Example 1 with RemoteResourceException

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);
}
Also used : BuildConfiguration(org.jboss.pnc.dto.BuildConfiguration) RemoteResourceException(org.jboss.pnc.client.RemoteResourceException) HashMap(java.util.HashMap) ExecutorService(java.util.concurrent.ExecutorService) GroupConfigurationClient(org.jboss.pnc.client.GroupConfigurationClient) RemoteCollection(org.jboss.pnc.client.RemoteCollection) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Example 2 with RemoteResourceException

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");
    }
}
Also used : RemoteResourceException(org.jboss.pnc.client.RemoteResourceException) ProductVersion(org.jboss.pnc.dto.ProductVersion) ProductVersionClient(org.jboss.pnc.client.ProductVersionClient)

Example 3 with RemoteResourceException

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;
    }
}
Also used : RemoteResourceException(org.jboss.pnc.client.RemoteResourceException) GenericSettingClient(org.jboss.pnc.client.GenericSettingClient)

Example 4 with RemoteResourceException

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);
    }
}
Also used : BuildConfiguration(org.jboss.pnc.dto.BuildConfiguration) RemoteResourceException(org.jboss.pnc.client.RemoteResourceException) HashMap(java.util.HashMap) GroupBuildInfo(org.jboss.pnc.bacon.pig.impl.config.GroupBuildInfo)

Example 5 with RemoteResourceException

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);
    }
}
Also used : BuildRef(org.jboss.pnc.dto.BuildRef) RemoteResourceException(org.jboss.pnc.client.RemoteResourceException) HashMap(java.util.HashMap) GroupBuild(org.jboss.pnc.dto.GroupBuild) Build(org.jboss.pnc.dto.Build) GroupBuildInfo(org.jboss.pnc.bacon.pig.impl.config.GroupBuildInfo) BuildsFilterParameters(org.jboss.pnc.rest.api.parameters.BuildsFilterParameters)

Aggregations

RemoteResourceException (org.jboss.pnc.client.RemoteResourceException)9 HashMap (java.util.HashMap)3 IOException (java.io.IOException)2 GroupBuildInfo (org.jboss.pnc.bacon.pig.impl.config.GroupBuildInfo)2 ProductVersionClient (org.jboss.pnc.client.ProductVersionClient)2 RemoteCollection (org.jboss.pnc.client.RemoteCollection)2 Build (org.jboss.pnc.dto.Build)2 BuildConfiguration (org.jboss.pnc.dto.BuildConfiguration)2 GroupBuild (org.jboss.pnc.dto.GroupBuild)2 ProductVersion (org.jboss.pnc.dto.ProductVersion)2 File (java.io.File)1 InputStream (java.io.InputStream)1 URI (java.net.URI)1 Instant (java.time.Instant)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 Optional (java.util.Optional)1 ExecutorService (java.util.concurrent.ExecutorService)1 BadRequestException (javax.ws.rs.BadRequestException)1 Response (javax.ws.rs.core.Response)1