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;
}
Aggregations