Search in sources :

Example 6 with Result

use of org.jboss.pnc.spi.coordinator.Result in project pnc by project-ncl.

the class DefaultRemoteBuildsCleaner method requestDeleteViaCauseway.

private Result requestDeleteViaCauseway(BuildRecord buildRecord) {
    List<BuildRecordPushResult> toRemove = buildRecordPushResultRepository.getAllSuccessfulForBuildRecord(buildRecord.getId());
    String externalBuildId = BuildMapper.idMapper.toDto(buildRecord.getId());
    for (BuildRecordPushResult pushResult : toRemove) {
        boolean success = causewayUntag(pushResult.getTagPrefix(), pushResult.getBrewBuildId());
        if (!success) {
            logger.error("Failed to un-tag pushed build record. BuildRecord.id: {}; brewBuildId: {}; tagPrefix: {};", buildRecord.getId(), pushResult.getBrewBuildId(), pushResult.getTagPrefix());
            return new Result(externalBuildId, ResultStatus.FAILED, "Failed to un-tag pushed build record.");
        }
    }
    return new Result(externalBuildId, ResultStatus.SUCCESS);
}
Also used : BuildRecordPushResult(org.jboss.pnc.model.BuildRecordPushResult) BuildRecordPushResult(org.jboss.pnc.model.BuildRecordPushResult) Result(org.jboss.pnc.spi.coordinator.Result)

Example 7 with Result

use of org.jboss.pnc.spi.coordinator.Result in project pnc by project-ncl.

the class DefaultRemoteBuildsCleaner method deleteBuildsFromIndy.

private Result deleteBuildsFromIndy(BuildRecord buildRecord, String authToken) {
    String buildContentId = buildRecord.getBuildContentId();
    BuildType buildType = buildRecord.getBuildConfigurationAudited().getBuildType();
    String pkgKey = getRepoPkgKey(buildType);
    Result result;
    if (buildContentId == null) {
        logger.debug("Build contentId is null. Nothing to be deleted from Indy.");
        return new Result(buildContentId, ResultStatus.SUCCESS, "BuildContentId is null. Nothing to be deleted from Indy.");
    }
    Indy indy = indyFactory.get(authToken);
    try {
        IndyStoresClientModule indyStores = indy.stores();
        if (pkgKey != null) {
            StoreKey tempHostedKey = new StoreKey(pkgKey, StoreType.hosted, tempBuildPromotionGroup);
            // delete artifacts from consolidated repository
            BatchDeleteRequest request = new BatchDeleteRequest();
            request.setTrackingID(buildContentId);
            request.setStoreKey(tempHostedKey);
            indy.module(IndyFoloAdminClientModule.class).deleteFilesFromStoreByTrackingID(request);
            // delete the content
            StoreKey storeKey = new StoreKey(pkgKey, StoreType.hosted, buildContentId);
            indyStores.delete(storeKey, "Scheduled cleanup of temporary builds.", true);
        }
        // delete generic http repos
        List<Group> genericGroups;
        try {
            StoreListingDTO<Group> groupListing = indyStores.listGroups(PKG_TYPE_GENERIC_HTTP);
            genericGroups = groupListing.getItems();
            for (Group genericGroup : genericGroups) {
                if (genericGroup.getName().startsWith("g-") && genericGroup.getName().endsWith("-" + buildContentId)) {
                    deleteRepoGroup(indyStores, genericGroup);
                }
            }
        } catch (IndyClientException e) {
            String description = MessageFormat.format("Error in deleting generic http repos for build {0}: {1}", buildContentId, e);
            logger.error(description, e);
        }
        // delete the tracking record
        IndyFoloAdminClientModule foloAdmin = indy.module(IndyFoloAdminClientModule.class);
        foloAdmin.clearTrackingRecord(buildContentId);
        result = new Result(buildContentId, ResultStatus.SUCCESS);
    } catch (IndyClientException e) {
        String description = MessageFormat.format("Failed to delete temporary hosted repository identified by buildContentId {0}.", buildContentId);
        logger.error(description, e);
        result = new Result(buildContentId, ResultStatus.FAILED, description);
    } finally {
        IOUtils.closeQuietly(indy);
    }
    return result;
}
Also used : Group(org.commonjava.indy.model.core.Group) IndyFoloAdminClientModule(org.commonjava.indy.folo.client.IndyFoloAdminClientModule) BatchDeleteRequest(org.commonjava.indy.model.core.BatchDeleteRequest) Indy(org.commonjava.indy.client.core.Indy) BuildType(org.jboss.pnc.enums.BuildType) IndyClientException(org.commonjava.indy.client.core.IndyClientException) IndyStoresClientModule(org.commonjava.indy.client.core.module.IndyStoresClientModule) StoreKey(org.commonjava.indy.model.core.StoreKey) BuildRecordPushResult(org.jboss.pnc.model.BuildRecordPushResult) Result(org.jboss.pnc.spi.coordinator.Result)

Example 8 with Result

use of org.jboss.pnc.spi.coordinator.Result in project pnc by project-ncl.

the class DefaultRemoteBuildsCleaner method deleteRemoteBuilds.

@Override
public Result deleteRemoteBuilds(BuildRecord buildRecord, String authToken) {
    Result result = deleteBuildsFromIndy(buildRecord, authToken);
    if (!result.isSuccess()) {
        return result;
    }
    result = requestDeleteViaCauseway(buildRecord);
    if (!result.isSuccess()) {
        return result;
    }
    return new Result(BuildMapper.idMapper.toDto(buildRecord.getId()), ResultStatus.SUCCESS);
}
Also used : BuildRecordPushResult(org.jboss.pnc.model.BuildRecordPushResult) Result(org.jboss.pnc.spi.coordinator.Result)

Example 9 with Result

use of org.jboss.pnc.spi.coordinator.Result in project pnc by project-ncl.

the class TemporaryBuildsCleaner method deleteTemporaryBuild.

private Result deleteTemporaryBuild(BuildRecord buildRecord, String authToken) throws ValidationException {
    if (!buildRecord.isTemporaryBuild()) {
        throw new ValidationException("Only deletion of the temporary builds is allowed");
    }
    // first delete BRs where this build is noRebuildCause
    List<BuildRecord> noRebuildBRs = buildRecordRepository.getBuildByCausingRecord(buildRecord.getId());
    for (BuildRecord noRebuildBR : noRebuildBRs) {
        log.info("Deleting build " + noRebuildBR.getId() + " which has noRebuildCause " + buildRecord.getId() + ".");
        deleteTemporaryBuild(noRebuildBR.getId(), authToken);
    }
    // delete the build itself
    log.info("Starting deletion of a temporary build " + buildRecord + "; Built artifacts: " + buildRecord.getBuiltArtifacts() + "; Dependencies: " + buildRecord.getDependencies());
    String externalBuildId = BuildMapper.idMapper.toDto(buildRecord.getId());
    Result result = remoteBuildsCleaner.deleteRemoteBuilds(buildRecord, authToken);
    if (!result.isSuccess()) {
        log.error("Failed to delete remote temporary builds for BR.id:{}.", buildRecord.getId());
        return new Result(externalBuildId, ResultStatus.FAILED, "Failed to delete remote temporary builds.");
    }
    removeBuiltArtifacts(buildRecord);
    buildRecordRepository.delete(buildRecord.getId());
    log.info("Deletion of the temporary build {} finished successfully.", buildRecord);
    return new Result(externalBuildId, ResultStatus.SUCCESS);
}
Also used : ValidationException(org.jboss.pnc.spi.exception.ValidationException) BuildRecord(org.jboss.pnc.model.BuildRecord) Result(org.jboss.pnc.spi.coordinator.Result)

Aggregations

Result (org.jboss.pnc.spi.coordinator.Result)9 ValidationException (org.jboss.pnc.spi.exception.ValidationException)4 BuildRecord (org.jboss.pnc.model.BuildRecord)3 BuildRecordPushResult (org.jboss.pnc.model.BuildRecordPushResult)3 WireMockServer (com.github.tomakehurst.wiremock.WireMockServer)2 Consumer (java.util.function.Consumer)2 BuildConfigSetRecord (org.jboss.pnc.model.BuildConfigSetRecord)2 Test (org.junit.Test)2 TransactionAttribute (javax.ejb.TransactionAttribute)1 Indy (org.commonjava.indy.client.core.Indy)1 IndyClientException (org.commonjava.indy.client.core.IndyClientException)1 IndyStoresClientModule (org.commonjava.indy.client.core.module.IndyStoresClientModule)1 IndyFoloAdminClientModule (org.commonjava.indy.folo.client.IndyFoloAdminClientModule)1 BatchDeleteRequest (org.commonjava.indy.model.core.BatchDeleteRequest)1 Group (org.commonjava.indy.model.core.Group)1 StoreKey (org.commonjava.indy.model.core.StoreKey)1 BuildType (org.jboss.pnc.enums.BuildType)1 Base32LongID (org.jboss.pnc.model.Base32LongID)1