Search in sources :

Example 6 with RemoteResourceException

use of org.jboss.pnc.client.RemoteResourceException in project bacon by project-ncl.

the class PncBuilder method cancelRunningGroupBuild.

public String cancelRunningGroupBuild(String groupConfigurationId) {
    try {
        Collection<GroupBuild> groupBuilds = groupConfigClient.getAllGroupBuilds(groupConfigurationId, of("=desc=startTime"), query("status==%s", BuildStatus.BUILDING)).getAll();
        if (groupBuilds.size() > 1) {
            return ("Can't cancel, there are multiple GroupBuilds running for single GroupConfiguration name and we can't decide correct one to cancel from build-config.yaml information. Found:" + groupBuilds);
        }
        if (groupBuilds.isEmpty()) {
            return "No build is running for this group.";
        }
        GroupBuild running = groupBuilds.iterator().next();
        groupBuildClient.cancel(running.getId());
        return "Group build " + running.getId() + " canceled.";
    } catch (RemoteResourceException e) {
        throw new RuntimeException("Failed to get group build info to cancel running build.", e);
    }
}
Also used : RemoteResourceException(org.jboss.pnc.client.RemoteResourceException) GroupBuild(org.jboss.pnc.dto.GroupBuild)

Example 7 with RemoteResourceException

use of org.jboss.pnc.client.RemoteResourceException in project bacon by project-ncl.

the class PigFacade method pushToBrew.

private static void pushToBrew(boolean reimport) {
    abortIfBuildDataAbsentFromContext();
    Map<String, PncBuild> builds = PigContext.get().getBuilds();
    String tagPrefix = getBrewTag(context().getPncImportResult().getVersion());
    List<PncBuild> buildsToPush = getBuildsToPush(builds);
    if (log.isInfoEnabled()) {
        log.info("Pushing the following builds to brew: {}", buildsToPush.stream().map(PncBuild::getId).collect(Collectors.toList()));
    }
    for (PncBuild build : buildsToPush) {
        BuildPushParameters request = BuildPushParameters.builder().tagPrefix(tagPrefix).reimport(reimport).build();
        // TODO: customize the timeout
        try (AdvancedBuildClient pushingClient = new AdvancedBuildClient(PncClientHelper.getPncConfiguration())) {
            BuildPushResult pushResult = pushingClient.executeBrewPush(build.getId(), request, 15L, TimeUnit.MINUTES);
            if (pushResult.getStatus() != BuildPushStatus.SUCCESS) {
                throw new RuntimeException("Failed to push build " + build.getId() + " to brew. Push result: " + pushResult);
            }
            log.info("{} pushed to brew ( {} ) ", build.getId(), UrlGenerator.generateBuildUrl(build.getId()));
        } catch (RemoteResourceException e) {
            throw new RuntimeException("Failed to push build " + build.getId() + " to brew (" + UrlGenerator.generateBuildUrl(build.getId()) + ")", e);
        }
    }
}
Also used : RemoteResourceException(org.jboss.pnc.client.RemoteResourceException) AdvancedBuildClient(org.jboss.pnc.restclient.AdvancedBuildClient) BuildPushParameters(org.jboss.pnc.dto.requests.BuildPushParameters) BuildPushResult(org.jboss.pnc.dto.BuildPushResult) PncBuild(org.jboss.pnc.bacon.pig.impl.pnc.PncBuild)

Example 8 with RemoteResourceException

use of org.jboss.pnc.client.RemoteResourceException in project bacon by project-ncl.

the class SourcesGenerator method downloadSourcesFromBuilds.

private void downloadSourcesFromBuilds(Map<String, PncBuild> builds, File workDir, File contentsDir) {
    builds.values().forEach(build -> {
        URI url = gerritSnapshotDownloadUrl(build.getInternalScmUrl(), build.getScmRevision());
        File targetPath = new File(workDir, build.getName() + ".tar.gz");
        try (BuildClient client = CREATOR.newClient();
            Response response = client.getInternalScmArchiveLink(build.getId())) {
            InputStream in = (InputStream) response.getEntity();
            Files.copy(in, targetPath.toPath());
        } catch (IOException | RemoteResourceException e) {
            throw new RuntimeException(e);
        }
        Collection<String> untaredFiles = FileUtils.untar(targetPath, contentsDir);
        List<String> topLevelDirectories = untaredFiles.stream().filter(this::isNotANestedFile).collect(Collectors.toList());
        if (topLevelDirectories.size() != 1) {
            throw new RuntimeException("Found more than one top-level directory (" + topLevelDirectories.size() + ") untared for build " + build + ", the untared archive: " + targetPath.getAbsolutePath() + ", the top level directories:" + topLevelDirectories);
        }
        String topLevelDirectoryName = untaredFiles.iterator().next();
        File topLevelDirectory = new File(contentsDir, topLevelDirectoryName);
        File properTopLevelDirectory = new File(contentsDir, build.getName());
        topLevelDirectory.renameTo(properTopLevelDirectory);
    });
}
Also used : Response(javax.ws.rs.core.Response) RemoteResourceException(org.jboss.pnc.client.RemoteResourceException) InputStream(java.io.InputStream) BuildClient(org.jboss.pnc.client.BuildClient) IOException(java.io.IOException) URI(java.net.URI) File(java.io.File)

Example 9 with RemoteResourceException

use of org.jboss.pnc.client.RemoteResourceException in project pnc by project-ncl.

the class ProductMilestoneEndpointTest method shouldGetMilestoneRelease.

@Test
public void shouldGetMilestoneRelease() throws IOException, RemoteResourceException {
    // given
    ProductClient productClient = new ProductClient(RestClientConfiguration.asAnonymous());
    RemoteCollection<Product> products = productClient.getAll(Optional.empty(), Optional.of("name==\"" + PNC_PRODUCT_NAME + "\""));
    Product product = products.iterator().next();
    Map<String, ProductVersionRef> productVersions = product.getProductVersions();
    Optional<ProductVersionRef> productVersion = productVersions.values().stream().filter(pv -> pv.getVersion().equals(DatabaseDataInitializer.PNC_PRODUCT_VERSION_1)).findAny();
    ProductVersionClient productVersionClient = new ProductVersionClient(RestClientConfiguration.asAnonymous());
    RemoteCollection<ProductMilestone> milestones = productVersionClient.getMilestones(productVersion.get().getId(), Optional.empty(), Optional.of("version==\"" + PNC_PRODUCT_MILESTONE3 + "\""));
    ProductMilestone milestone = milestones.iterator().next();
    ProductMilestoneClient milestoneClient = new ProductMilestoneClient(RestClientConfiguration.asAnonymous());
    // when
    RemoteCollection<ProductMilestoneCloseResult> milestoneReleases = milestoneClient.getCloseResults(milestone.getId(), null);
    // then
    Assert.assertEquals(3, milestoneReleases.size());
    // make sure the result is ordered by date
    Instant previous = Instant.EPOCH;
    for (Iterator<ProductMilestoneCloseResult> iter = milestoneReleases.iterator(); iter.hasNext(); ) {
        ProductMilestoneCloseResult next = iter.next();
        logger.debug("MilestoneRelease id: {}, StartingDate: {}.", next.getId(), next.getStartingDate());
        Assert.assertTrue("Wong milestone releases order.", next.getStartingDate().isAfter(previous));
        previous = next.getStartingDate();
    }
    // when
    ProductMilestoneCloseParameters filter = new ProductMilestoneCloseParameters();
    filter.setLatest(true);
    RemoteCollection<ProductMilestoneCloseResult> latestMilestoneRelease = milestoneClient.getCloseResults(milestone.getId(), filter);
    // then
    Assert.assertEquals(1, latestMilestoneRelease.getAll().size());
    // the latest one in demo data has status SUCCEEDED
    Assert.assertEquals(MilestoneCloseStatus.SUCCEEDED, latestMilestoneRelease.iterator().next().getStatus());
}
Also used : BeforeClass(org.junit.BeforeClass) Arquillian(org.jboss.arquillian.junit.Arquillian) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RunWith(org.junit.runner.RunWith) LoggerFactory(org.slf4j.LoggerFactory) ProductClient(org.jboss.pnc.client.ProductClient) RunAsClient(org.jboss.arquillian.container.test.api.RunAsClient) RemoteCollection(org.jboss.pnc.client.RemoteCollection) ContainerTest(org.jboss.pnc.test.category.ContainerTest) ClientException(org.jboss.pnc.client.ClientException) ProductMilestoneCloseParameters(org.jboss.pnc.rest.api.parameters.ProductMilestoneCloseParameters) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) ProductMilestone(org.jboss.pnc.dto.ProductMilestone) Map(java.util.Map) BadRequestException(javax.ws.rs.BadRequestException) Deployments(org.jboss.pnc.integration.setup.Deployments) PNC_PRODUCT_MILESTONE3(org.jboss.pnc.demo.data.DatabaseDataInitializer.PNC_PRODUCT_MILESTONE3) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) ValidationResponse(org.jboss.pnc.dto.response.ValidationResponse) ValidationErrorType(org.jboss.pnc.enums.ValidationErrorType) DatabaseDataInitializer(org.jboss.pnc.demo.data.DatabaseDataInitializer) EnterpriseArchive(org.jboss.shrinkwrap.api.spec.EnterpriseArchive) Product(org.jboss.pnc.dto.Product) ProductMilestoneClient(org.jboss.pnc.client.ProductMilestoneClient) Test(org.junit.Test) IOException(java.io.IOException) Artifact(org.jboss.pnc.dto.Artifact) VersionValidationRequest(org.jboss.pnc.dto.requests.validation.VersionValidationRequest) Category(org.junit.experimental.categories.Category) Instant(java.time.Instant) RestClientConfiguration(org.jboss.pnc.integration.setup.RestClientConfiguration) ProductVersionClient(org.jboss.pnc.client.ProductVersionClient) Build(org.jboss.pnc.dto.Build) PNC_PRODUCT_NAME(org.jboss.pnc.demo.data.DatabaseDataInitializer.PNC_PRODUCT_NAME) Deployment(org.jboss.arquillian.container.test.api.Deployment) ProductMilestoneCloseResult(org.jboss.pnc.dto.ProductMilestoneCloseResult) ProductVersionRef(org.jboss.pnc.dto.ProductVersionRef) ProductVersion(org.jboss.pnc.dto.ProductVersion) RemoteResourceException(org.jboss.pnc.client.RemoteResourceException) Optional(java.util.Optional) Assert(org.junit.Assert) MilestoneCloseStatus(org.jboss.pnc.enums.MilestoneCloseStatus) ProductMilestone(org.jboss.pnc.dto.ProductMilestone) ProductMilestoneClient(org.jboss.pnc.client.ProductMilestoneClient) Instant(java.time.Instant) Product(org.jboss.pnc.dto.Product) ProductVersionRef(org.jboss.pnc.dto.ProductVersionRef) ProductMilestoneCloseParameters(org.jboss.pnc.rest.api.parameters.ProductMilestoneCloseParameters) ProductVersionClient(org.jboss.pnc.client.ProductVersionClient) ProductClient(org.jboss.pnc.client.ProductClient) ProductMilestoneCloseResult(org.jboss.pnc.dto.ProductMilestoneCloseResult) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

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