Search in sources :

Example 6 with InvalidEntityException

use of org.jboss.pnc.facade.validation.InvalidEntityException in project pnc by project-ncl.

the class ArtifactProviderImpl method createQualityLevelRevision.

@Override
public ArtifactRevision createQualityLevelRevision(String id, String quality, String reason) throws DTOValidationException {
    boolean isLoggedInUserSystemUser = userService.hasLoggedInUserRole(SYSTEM_USER);
    ArtifactQuality newQuality = validateProvidedArtifactQuality(quality, isLoggedInUserSystemUser);
    org.jboss.pnc.dto.Artifact artifact = getSpecific(id);
    if (artifact == null) {
        throw new InvalidEntityException("Artifact with id: " + id + " does not exist.");
    }
    validateIfArtifactQualityIsModifiable(artifact, newQuality);
    update(id, artifact.toBuilder().artifactQuality(newQuality).qualityLevelReason(reason).build());
    ArtifactAudited latestRevision = artifactAuditedRepository.findLatestById(Integer.parseInt(id));
    if (latestRevision == null) {
        throw new RepositoryViolationException("Entity should exist in the DB");
    }
    if (DA_SYNCRONIZED_ARTIFACT_QUALITIES.contains(newQuality)) {
        String jsonPayload = createBlacklistJSONPayload(artifact);
        blacklistAsyncInvoker.notifyBlacklistToDA(jsonPayload);
    }
    return artifactRevisionMapper.toDTO(latestRevision);
}
Also used : RepositoryViolationException(org.jboss.pnc.facade.validation.RepositoryViolationException) ArtifactQuality(org.jboss.pnc.enums.ArtifactQuality) InvalidEntityException(org.jboss.pnc.facade.validation.InvalidEntityException) ArtifactAudited(org.jboss.pnc.model.ArtifactAudited)

Example 7 with InvalidEntityException

use of org.jboss.pnc.facade.validation.InvalidEntityException 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.");
    }
}
Also used : AlreadyRunningException(org.jboss.pnc.facade.validation.AlreadyRunningException) ProcessException(org.jboss.pnc.spi.coordinator.ProcessException) BuildPushOperation(org.jboss.pnc.bpm.causeway.BuildPushOperation) BuildPushResult(org.jboss.pnc.dto.BuildPushResult) OperationNotAllowedException(org.jboss.pnc.facade.validation.OperationNotAllowedException) BuildRecord(org.jboss.pnc.model.BuildRecord) InvalidEntityException(org.jboss.pnc.facade.validation.InvalidEntityException) Artifact(org.jboss.pnc.model.Artifact) Result(org.jboss.pnc.bpm.causeway.Result) BuildPushResult(org.jboss.pnc.dto.BuildPushResult) BuildRecordPushResult(org.jboss.pnc.model.BuildRecordPushResult)

Example 8 with InvalidEntityException

use of org.jboss.pnc.facade.validation.InvalidEntityException in project pnc by project-ncl.

the class BuildTriggererImpl method loadAuditedsFromDB.

private Map<Integer, BuildConfigurationAudited> loadAuditedsFromDB(BuildConfigurationSet buildConfigurationSet, List<BuildConfigurationRevisionRef> buildConfigurationAuditedRests) throws InvalidEntityException {
    Map<Integer, BuildConfigurationAudited> buildConfigurationAuditedsMap = new HashMap<>();
    Set<IdRev> buildConfigurationAuditedRevs = nullableStreamOf(buildConfigurationAuditedRests).map(bcrRef -> new IdRev(Integer.valueOf(bcrRef.getId()), bcrRef.getRev())).collect(Collectors.toSet());
    if (!buildConfigurationAuditedRevs.isEmpty()) {
        Map<IdRev, BuildConfigurationAudited> buildConfigurationsAuditedMap = buildConfigurationAuditedRepository.queryById(buildConfigurationAuditedRevs);
        for (BuildConfigurationRevisionRef bc : buildConfigurationAuditedRests) {
            BuildConfigurationAudited buildConfigurationAudited = buildConfigurationsAuditedMap.get(new IdRev(Integer.valueOf(bc.getId()), bc.getRev()));
            Preconditions.checkArgument(buildConfigurationAudited != null, "Can't find Build Configuration with id=" + bc.getId() + ", rev=" + bc.getRev());
            buildConfigurationAudited = hibernateLazyInitializer.initializeBuildConfigurationAuditedBeforeTriggeringIt(buildConfigurationAudited);
            if (!buildConfigurationSet.getBuildConfigurations().contains(buildConfigurationAudited.getBuildConfiguration())) {
                throw new InvalidEntityException("BuildConfigurationSet " + buildConfigurationSet + " doesn't contain this BuildConfigurationAudited entity " + buildConfigurationAudited);
            }
            buildConfigurationAuditedsMap.put(buildConfigurationAudited.getId(), buildConfigurationAudited);
        }
    }
    return buildConfigurationAuditedsMap;
}
Also used : BuildOptions(org.jboss.pnc.spi.BuildOptions) BuildConfiguration(org.jboss.pnc.model.BuildConfiguration) BuildStatusNotifications(org.jboss.pnc.coordinator.notifications.buildTask.BuildStatusNotifications) HibernateLazyInitializer(org.jboss.pnc.facade.util.HibernateLazyInitializer) BuildConfigurationSetRepository(org.jboss.pnc.spi.datastore.repositories.BuildConfigurationSetRepository) LoggerFactory(org.slf4j.LoggerFactory) BuildConfigurationSet(org.jboss.pnc.model.BuildConfigurationSet) BuildConfigurationAuditedRepository(org.jboss.pnc.spi.datastore.repositories.BuildConfigurationAuditedRepository) BuildSetStatusNotifications(org.jboss.pnc.coordinator.notifications.buildSetTask.BuildSetStatusNotifications) HashMap(java.util.HashMap) BuildTask(org.jboss.pnc.spi.coordinator.BuildTask) OptionalInt(java.util.OptionalInt) BuildConfigurationAudited(org.jboss.pnc.model.BuildConfigurationAudited) BuildMapper(org.jboss.pnc.mapper.api.BuildMapper) Inject(javax.inject.Inject) UserService(org.jboss.pnc.facade.util.UserService) Map(java.util.Map) BuildSetTask(org.jboss.pnc.spi.coordinator.BuildSetTask) BuildTriggerer(org.jboss.pnc.facade.BuildTriggerer) BuildConfigurationRepository(org.jboss.pnc.spi.datastore.repositories.BuildConfigurationRepository) BuildConflictException(org.jboss.pnc.spi.exception.BuildConflictException) Stateless(javax.ejb.Stateless) Logger(org.slf4j.Logger) BuildTaskContext(org.jboss.pnc.common.logging.BuildTaskContext) BuildCoordinator(org.jboss.pnc.spi.coordinator.BuildCoordinator) Collection(java.util.Collection) Set(java.util.Set) Collectors(java.util.stream.Collectors) IdRev(org.jboss.pnc.model.IdRev) List(java.util.List) GenericSettingProvider(org.jboss.pnc.facade.providers.GenericSettingProvider) InvalidEntityException(org.jboss.pnc.facade.validation.InvalidEntityException) CoreException(org.jboss.pnc.spi.exception.CoreException) StreamHelper.nullableStreamOf(org.jboss.pnc.common.util.StreamHelper.nullableStreamOf) GroupBuildRequest(org.jboss.pnc.dto.requests.GroupBuildRequest) BuildConfigurationRevisionRef(org.jboss.pnc.dto.BuildConfigurationRevisionRef) Optional(java.util.Optional) Preconditions(com.google.common.base.Preconditions) Collections(java.util.Collections) BuildConfigurationAudited(org.jboss.pnc.model.BuildConfigurationAudited) HashMap(java.util.HashMap) BuildConfigurationRevisionRef(org.jboss.pnc.dto.BuildConfigurationRevisionRef) IdRev(org.jboss.pnc.model.IdRev) InvalidEntityException(org.jboss.pnc.facade.validation.InvalidEntityException)

Example 9 with InvalidEntityException

use of org.jboss.pnc.facade.validation.InvalidEntityException in project pnc by project-ncl.

the class BuildConfigurationEndpointImpl method validate.

private void validate(BuildConfiguration buildConfiguration) {
    if (buildConfiguration != null) {
        Map<String, String> parameters = buildConfiguration.getParameters();
        String buildCategoryKey = BuildConfigurationParameterKeys.BUILD_CATEGORY.name();
        if (parameters != null && parameters.containsKey(buildCategoryKey)) {
            String buildCategoryStr = parameters.get(buildCategoryKey);
            try {
                BuildCategory.valueOf(buildCategoryStr.toUpperCase());
            } catch (Exception ex) {
                List<String> categories = Stream.of(BuildCategory.values()).map(BuildCategory::name).collect(Collectors.toList());
                throw new InvalidEntityException(buildCategoryKey + " value '" + buildCategoryStr + "' is invalid. Valid values are: " + String.join(", ", categories) + '.');
            }
        }
    }
}
Also used : BuildCategory(org.jboss.pnc.enums.BuildCategory) List(java.util.List) BuildConflictException(org.jboss.pnc.spi.exception.BuildConflictException) NotFoundException(javax.ws.rs.NotFoundException) InvalidEntityException(org.jboss.pnc.facade.validation.InvalidEntityException) CoreException(org.jboss.pnc.spi.exception.CoreException) AlreadyRunningException(org.jboss.pnc.facade.validation.AlreadyRunningException) InvalidEntityException(org.jboss.pnc.facade.validation.InvalidEntityException)

Example 10 with InvalidEntityException

use of org.jboss.pnc.facade.validation.InvalidEntityException in project pnc by project-ncl.

the class OperationsManagerImpl method setResult.

@Override
public Operation setResult(Base32LongID id, OperationResult result) {
    Operation operation = repository.queryById(id);
    if (operation.getEndTime() != null) {
        throw new InvalidEntityException("Operation " + operation + " is already finished!");
    }
    log.debug("Updating result of operation " + operation + " to " + result);
    ProgressStatus previousProgress = operation.getProgressStatus();
    operation.setResult(result);
    operation.setEndTime(Date.from(Instant.now()));
    analysisStatusChangedEventNotifier.fire(new OperationChangedEvent(operation, previousProgress));
    return operation;
}
Also used : ProgressStatus(org.jboss.pnc.api.enums.ProgressStatus) Operation(org.jboss.pnc.model.Operation) DeliverableAnalyzerOperation(org.jboss.pnc.model.DeliverableAnalyzerOperation) InvalidEntityException(org.jboss.pnc.facade.validation.InvalidEntityException)

Aggregations

InvalidEntityException (org.jboss.pnc.facade.validation.InvalidEntityException)13 List (java.util.List)3 RepositoryViolationException (org.jboss.pnc.facade.validation.RepositoryViolationException)3 Collection (java.util.Collection)2 Collections (java.util.Collections)2 Map (java.util.Map)2 Optional (java.util.Optional)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 Stateless (javax.ejb.Stateless)2 Inject (javax.inject.Inject)2 ProgressStatus (org.jboss.pnc.api.enums.ProgressStatus)2 StreamHelper.nullableStreamOf (org.jboss.pnc.common.util.StreamHelper.nullableStreamOf)2 ArtifactQuality (org.jboss.pnc.enums.ArtifactQuality)2 UserService (org.jboss.pnc.facade.util.UserService)2 ConflictedEntryException (org.jboss.pnc.facade.validation.ConflictedEntryException)2 BuildMapper (org.jboss.pnc.mapper.api.BuildMapper)2 Artifact (org.jboss.pnc.model.Artifact)2 BuildConfiguration (org.jboss.pnc.model.BuildConfiguration)2 BuildConfigurationAudited (org.jboss.pnc.model.BuildConfigurationAudited)2