Search in sources :

Example 1 with BuildPushResult

use of org.jboss.pnc.dto.BuildPushResult in project pnc by project-ncl.

the class BuildPushTest method shouldPushBuild.

@Test
public void shouldPushBuild() throws ClientException {
    BuildClient client = new BuildClient(RestClientConfiguration.asUser());
    Build build = client.getSpecific(buildId);
    // first push accepted
    BuildPushParameters parameters = BuildPushParameters.builder().reimport(false).tagPrefix("test-tag").build();
    BuildPushResult result = client.push(build.getId(), parameters);
    String buildPushResultId = result.getId();
    assertThat(result).isNotNull();
    assertThat(result.getStatus()).isEqualTo(BuildPushStatus.ACCEPTED);
    // second push rejected because already in process
    assertThatThrownBy(() -> client.push(build.getId(), parameters)).hasCauseInstanceOf(ClientErrorException.class);
    // should reject completion with invalid result id
    assertThatThrownBy(() -> client.completePush(buildId, returnSuccessfulResult(buildId, "1111"))).hasCauseInstanceOf(ClientErrorException.class);
    // successful complete of first push
    client.completePush(buildId, returnSuccessfulResult(buildId, buildPushResultId));
    // get result from db
    BuildPushResult successPushResult = client.getPushResult(buildId);
    assertThat(successPushResult.getStatus()).isEqualTo(BuildPushStatus.SUCCESS);
    assertThat(successPushResult.getLogContext()).isEqualTo(buildPushResultId);
    // next push should accept again
    BuildPushResult result2 = client.push(build.getId(), parameters);
    assertThat(result2).isNotNull();
    assertThat(result2.getStatus()).isEqualTo(BuildPushStatus.ACCEPTED);
}
Also used : Build(org.jboss.pnc.dto.Build) BuildClient(org.jboss.pnc.client.BuildClient) BuildPushParameters(org.jboss.pnc.dto.requests.BuildPushParameters) BuildPushResult(org.jboss.pnc.dto.BuildPushResult) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Example 2 with BuildPushResult

use of org.jboss.pnc.dto.BuildPushResult in project pnc by project-ncl.

the class BrewPusherImpl method doPushBuild.

private BuildPushResult doPushBuild(Base32LongID buildId, BuildPushParameters buildPushParameters, Long buildPushResultId) throws ProcessException {
    // TODO START timing event
    userLog.info("Push started.");
    // collect and validate input data
    BuildRecord buildRecord = getLatestSuccessfullyExecutedBuildRecord(buildId);
    if (buildRecord.getExecutionRootName() == null && !buildRecord.getBuildConfigurationAudited().getGenericParameters().containsKey(BREW_BUILD_NAME.name())) {
        throw new InvalidEntityException("Build " + buildId + " cannot be pushed to brew, because it is missing " + Attributes.BUILD_BREW_NAME + " attribute with brew name.");
    }
    List<Artifact> artifacts = artifactRepository.queryWithPredicates(ArtifactPredicates.withBuildRecordId(buildRecord.getId()));
    if (hasBadArtifactQuality(artifacts)) {
        String message = "Build contains artifacts of insufficient quality: BLACKLISTED/DELETED.";
        log.debug(message);
        BuildPushResult pushResult = BuildPushResult.builder().buildId(BuildMapper.idMapper.toDto(buildId)).status(BuildPushStatus.REJECTED).id(buildPushResultId.toString()).logContext(buildPushResultId.toString()).message(message).build();
        throw new OperationNotAllowedException(message, pushResult);
    }
    log.debug("Pushing Build.id {}.", buildRecord.getId());
    BuildPushOperation buildPushOperation = new BuildPushOperation(buildRecord, buildPushResultId, buildPushParameters.getTagPrefix(), buildPushParameters.isReimport(), getCompleteCallbackUrlTemplate());
    Result pushResult = buildResultPushManager.push(buildPushOperation, userService.currentUserToken());
    log.info("Push Result {}.", pushResult);
    BuildPushResult result = BuildPushResult.builder().id(pushResult.getId()).buildId(pushResult.getBuildId()).status(pushResult.getStatus()).logContext(pushResult.getId()).message(pushResult.getMessage()).build();
    // verify operation status
    switch(pushResult.getStatus()) {
        case ACCEPTED:
            userLog.info("Push ACCEPTED.");
            return result;
        case REJECTED:
            userLog.warn("Push REJECTED.");
            throw new AlreadyRunningException(pushResult.getMessage(), result);
        case SYSTEM_ERROR:
            userLog.error("Brew push failed: " + pushResult.getMessage());
            throw new ProcessException(pushResult.getMessage());
        default:
            userLog.error("Invalid push result status.");
            throw new ProcessException("Invalid push result status.");
    }
}
Also used : AlreadyRunningException(org.jboss.pnc.facade.validation.AlreadyRunningException) ProcessException(org.jboss.pnc.spi.coordinator.ProcessException) BuildPushOperation(org.jboss.pnc.bpm.causeway.BuildPushOperation) BuildPushResult(org.jboss.pnc.dto.BuildPushResult) OperationNotAllowedException(org.jboss.pnc.facade.validation.OperationNotAllowedException) BuildRecord(org.jboss.pnc.model.BuildRecord) InvalidEntityException(org.jboss.pnc.facade.validation.InvalidEntityException) Artifact(org.jboss.pnc.model.Artifact) Result(org.jboss.pnc.bpm.causeway.Result) BuildPushResult(org.jboss.pnc.dto.BuildPushResult) BuildRecordPushResult(org.jboss.pnc.model.BuildRecordPushResult)

Example 3 with BuildPushResult

use of org.jboss.pnc.dto.BuildPushResult in project pnc by project-ncl.

the class BrewPusherImpl method pushGroup.

@Override
public Set<BuildPushResult> pushGroup(int buildGroupId, String tagPrefix) {
    BuildPushParameters buildPushParameters = BuildPushParameters.builder().tagPrefix(tagPrefix).reimport(false).build();
    List<BuildRecord> buildRecords = buildRecordRepository.queryWithPredicates(BuildRecordPredicates.withBuildConfigSetRecordId(buildGroupId));
    Set<BuildPushResult> results = new HashSet<>();
    for (BuildRecord buildRecord : buildRecords) {
        Long buildPushResultId = Sequence.nextId();
        MDCUtils.addProcessContext(buildPushResultId.toString());
        MDCUtils.addCustomContext(BUILD_ID_KEY, buildRecord.getId().getId());
        try {
            results.add(doPushBuild(buildRecord.getId(), buildPushParameters, buildPushResultId));
        } catch (OperationNotAllowedException | AlreadyRunningException e) {
            results.add(BuildPushResult.builder().status(BuildPushStatus.REJECTED).id(buildPushResultId.toString()).buildId(BuildMapper.idMapper.toDto(buildRecord.getId())).message(e.getMessage()).build());
        } catch (InconsistentDataException | ProcessException e) {
            results.add(BuildPushResult.builder().status(BuildPushStatus.SYSTEM_ERROR).id(buildPushResultId.toString()).buildId(BuildMapper.idMapper.toDto(buildRecord.getId())).message(e.getMessage()).build());
        } finally {
            MDCUtils.removeProcessContext();
            MDCUtils.removeCustomContext(BUILD_ID_KEY);
        }
    }
    return results;
}
Also used : BuildPushParameters(org.jboss.pnc.dto.requests.BuildPushParameters) BuildPushResult(org.jboss.pnc.dto.BuildPushResult) OperationNotAllowedException(org.jboss.pnc.facade.validation.OperationNotAllowedException) BuildRecord(org.jboss.pnc.model.BuildRecord) AlreadyRunningException(org.jboss.pnc.facade.validation.AlreadyRunningException) ProcessException(org.jboss.pnc.spi.coordinator.ProcessException) InconsistentDataException(org.jboss.pnc.spi.datastore.InconsistentDataException) HashSet(java.util.HashSet)

Example 4 with BuildPushResult

use of org.jboss.pnc.dto.BuildPushResult 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 5 with BuildPushResult

use of org.jboss.pnc.dto.BuildPushResult in project pnc by project-ncl.

the class BuildResultPushManager method cancelInProgressPush.

public boolean cancelInProgressPush(Base32LongID buildRecordId) {
    InProgress.Context pushContext = inProgress.remove(buildRecordId);
    BuildPushResult buildRecordPushResultRest = BuildPushResult.builder().status(BuildPushStatus.CANCELED).buildId(buildRecordId.toString()).build();
    buildPushResultEvent.fire(buildRecordPushResultRest);
    return pushContext != null;
}
Also used : BuildPushResult(org.jboss.pnc.dto.BuildPushResult)

Aggregations

BuildPushResult (org.jboss.pnc.dto.BuildPushResult)6 BuildPushParameters (org.jboss.pnc.dto.requests.BuildPushParameters)3 AlreadyRunningException (org.jboss.pnc.facade.validation.AlreadyRunningException)2 OperationNotAllowedException (org.jboss.pnc.facade.validation.OperationNotAllowedException)2 BuildRecord (org.jboss.pnc.model.BuildRecord)2 BuildRecordPushResult (org.jboss.pnc.model.BuildRecordPushResult)2 ProcessException (org.jboss.pnc.spi.coordinator.ProcessException)2 HashSet (java.util.HashSet)1 PncBuild (org.jboss.pnc.bacon.pig.impl.pnc.PncBuild)1 BuildPushOperation (org.jboss.pnc.bpm.causeway.BuildPushOperation)1 Result (org.jboss.pnc.bpm.causeway.Result)1 BuildClient (org.jboss.pnc.client.BuildClient)1 RemoteResourceException (org.jboss.pnc.client.RemoteResourceException)1 Build (org.jboss.pnc.dto.Build)1 InvalidEntityException (org.jboss.pnc.facade.validation.InvalidEntityException)1 Artifact (org.jboss.pnc.model.Artifact)1 Base32LongID (org.jboss.pnc.model.Base32LongID)1 AdvancedBuildClient (org.jboss.pnc.restclient.AdvancedBuildClient)1 InconsistentDataException (org.jboss.pnc.spi.datastore.InconsistentDataException)1 ContainerTest (org.jboss.pnc.test.category.ContainerTest)1