Search in sources :

Example 6 with BuildType

use of org.jboss.pnc.enums.BuildType 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)

Aggregations

BuildType (org.jboss.pnc.enums.BuildType)6 Indy (org.commonjava.indy.client.core.Indy)2 Group (org.commonjava.indy.model.core.Group)2 StoreKey (org.commonjava.indy.model.core.StoreKey)2 BuildConfigurationAudited (org.jboss.pnc.model.BuildConfigurationAudited)2 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 HostedRepository (org.commonjava.indy.model.core.HostedRepository)1 Build (org.jboss.pnc.api.causeway.dto.push.Build)1 BuildImportRequest (org.jboss.pnc.api.causeway.dto.push.BuildImportRequest)1 BuildRoot (org.jboss.pnc.api.causeway.dto.push.BuildRoot)1 BuiltArtifact (org.jboss.pnc.api.causeway.dto.push.BuiltArtifact)1 Dependency (org.jboss.pnc.api.causeway.dto.push.Dependency)1 MavenBuild (org.jboss.pnc.api.causeway.dto.push.MavenBuild)1 MavenBuiltArtifact (org.jboss.pnc.api.causeway.dto.push.MavenBuiltArtifact)1 NpmBuild (org.jboss.pnc.api.causeway.dto.push.NpmBuild)1 NpmBuiltArtifact (org.jboss.pnc.api.causeway.dto.push.NpmBuiltArtifact)1 Request (org.jboss.pnc.api.dto.Request)1