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