use of org.jboss.pnc.bpm.causeway.BuildPushOperation 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.");
}
}
Aggregations