Search in sources :

Example 1 with EmptyEntityException

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

the class BuildProviderImpl method getDependencyGraph.

@Override
public Graph<Build> getDependencyGraph(String buildId) {
    Build specific = getSpecific(buildId);
    if (specific == null) {
        throw new EmptyEntityException("there is no record for given buildId.");
    }
    org.jboss.util.graph.Graph<BuildWithDependencies> buildGraph = createBuildDependencyGraph(buildId);
    GraphDtoBuilder<BuildWithDependencies, Build> graphBuilder = new GraphDtoBuilder();
    return graphBuilder.from(buildGraph, Build.class, vertex -> vertex.getData().getBuild());
}
Also used : EmptyEntityException(org.jboss.pnc.facade.validation.EmptyEntityException) GraphDtoBuilder(org.jboss.pnc.facade.util.GraphDtoBuilder) BuildRecordPredicates.temporaryBuild(org.jboss.pnc.spi.datastore.predicates.BuildRecordPredicates.temporaryBuild) Build(org.jboss.pnc.dto.Build)

Example 2 with EmptyEntityException

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

the class BuildProviderImpl method getBuildGraphForGroupBuild.

@Override
public Graph<Build> getBuildGraphForGroupBuild(String groupBuildId) {
    BuildConfigSetRecord buildConfigSetRecord = buildConfigSetRecordRepository.queryById(Integer.valueOf(groupBuildId));
    if (buildConfigSetRecord == null) {
        throw new EmptyEntityException("Build group " + groupBuildId + " does not exists.");
    }
    List<String> runningAndStoredIds = getBuildIdsInTheGroup(buildConfigSetRecord);
    org.jboss.util.graph.Graph<BuildWithDependencies> buildGraph = new org.jboss.util.graph.Graph<>();
    for (String buildId : runningAndStoredIds) {
        org.jboss.util.graph.Graph<BuildWithDependencies> dependencyGraph = createBuildDependencyGraph(buildId);
        GraphUtils.merge(buildGraph, dependencyGraph);
        logger.trace("Merged graph from buildRecordId {} to BuildConfigSetRecordGraph {}; Edges {},", buildId, buildGraph, buildGraph.getEdges());
    }
    GraphDtoBuilder<BuildWithDependencies, Build> graphBuilder = new GraphDtoBuilder();
    Graph<Build> graphDto = graphBuilder.from(buildGraph, Build.class, vertex -> vertex.getData().getBuild());
    return graphDto;
}
Also used : GraphDtoBuilder(org.jboss.pnc.facade.util.GraphDtoBuilder) EmptyEntityException(org.jboss.pnc.facade.validation.EmptyEntityException) Graph(org.jboss.pnc.dto.response.Graph) BuildRecordPredicates.temporaryBuild(org.jboss.pnc.spi.datastore.predicates.BuildRecordPredicates.temporaryBuild) Build(org.jboss.pnc.dto.Build) BuildConfigSetRecord(org.jboss.pnc.model.BuildConfigSetRecord)

Example 3 with EmptyEntityException

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

the class BuildConfigurationProviderImpl method validateEnvironment.

private void validateEnvironment(BuildConfiguration buildConfigurationRest) {
    String envId = buildConfigurationRest.getEnvironment().getId();
    BuildEnvironment env = buildEnvironmentRepository.queryById(Integer.valueOf(envId));
    if (env == null) {
        throw new EmptyEntityException("Build environment " + envId + " does not exist.");
    }
}
Also used : EmptyEntityException(org.jboss.pnc.facade.validation.EmptyEntityException) BuildEnvironment(org.jboss.pnc.model.BuildEnvironment)

Example 4 with EmptyEntityException

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

the class BrewPusherImpl method brewPushCancel.

@Override
public boolean brewPushCancel(String buildId) {
    Base32LongID id = BuildMapper.idMapper.toEntity(buildId);
    Optional<InProgress.Context> pushContext = buildResultPushManager.getContext(id);
    if (pushContext.isPresent()) {
        MDCUtils.addProcessContext(pushContext.get().getPushResultId());
        MDCUtils.addCustomContext(BUILD_ID_KEY, id.getId());
        userLog.info("Build push cancel requested.");
        try {
            return buildResultPushManager.cancelInProgressPush(id);
        } finally {
            MDCUtils.removeProcessContext();
            MDCUtils.removeCustomContext(BUILD_ID_KEY);
        }
    } else {
        throw new EmptyEntityException("There is no running push operation for build id: " + buildId);
    }
}
Also used : Base32LongID(org.jboss.pnc.model.Base32LongID) EmptyEntityException(org.jboss.pnc.facade.validation.EmptyEntityException)

Example 5 with EmptyEntityException

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

the class BpmEndpointImpl method notifyTask.

@Override
public void notifyTask(int taskId) {
    String content;
    JsonNode node;
    try {
        content = readContent(request.getInputStream());
        node = JsonOutputConverterMapper.getMapper().readTree(content);
    } catch (IOException e) {
        throw new RuntimeException("Could not get JSON from request data. " + "Verify it is not empty and in the correct format.", e);
    }
    if (!node.has("eventType")) {
        throw new RuntimeException("Request JSON does not contain required \"eventType\" field.");
    }
    String eventTypeName = node.get("eventType").asText();
    BpmEventType eventType = nullableValueOf(eventTypeName);
    if (eventType != null) {
        BpmEvent notification;
        try {
            notification = JsonOutputConverterMapper.getMapper().readValue(node.traverse(), eventType.getType());
        } catch (IOException e) {
            throw new RuntimeException("Could not deserialize JSON request for event type '" + eventTypeName + "' " + " into '" + eventType.getType() + "'. JSON value: " + content, e);
        }
        logger.debug("Received notification {} for BPM task with id {}.", notification, taskId);
        try {
            bpmManager.notify(taskId, notification);
        } catch (NoEntityException e) {
            throw new EmptyEntityException(e.getMessage());
        }
    } else {
        logger.info("Received notification with unknown eventType {}, ignoring it.", eventTypeName);
    }
}
Also used : BpmEvent(org.jboss.pnc.bpm.model.BpmEvent) EmptyEntityException(org.jboss.pnc.facade.validation.EmptyEntityException) BpmEventType(org.jboss.pnc.bpm.BpmEventType) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) NoEntityException(org.jboss.pnc.bpm.NoEntityException)

Aggregations

EmptyEntityException (org.jboss.pnc.facade.validation.EmptyEntityException)7 Build (org.jboss.pnc.dto.Build)2 GraphDtoBuilder (org.jboss.pnc.facade.util.GraphDtoBuilder)2 BuildRecordPredicates.temporaryBuild (org.jboss.pnc.spi.datastore.predicates.BuildRecordPredicates.temporaryBuild)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 IOException (java.io.IOException)1 BpmEventType (org.jboss.pnc.bpm.BpmEventType)1 NoEntityException (org.jboss.pnc.bpm.NoEntityException)1 BpmEvent (org.jboss.pnc.bpm.model.BpmEvent)1 Graph (org.jboss.pnc.dto.response.Graph)1 OperationNotAllowedException (org.jboss.pnc.facade.validation.OperationNotAllowedException)1 Base32LongID (org.jboss.pnc.model.Base32LongID)1 BuildConfigSetRecord (org.jboss.pnc.model.BuildConfigSetRecord)1 BuildEnvironment (org.jboss.pnc.model.BuildEnvironment)1 BuildRecord (org.jboss.pnc.model.BuildRecord)1 DeliverableAnalyzerOperation (org.jboss.pnc.model.DeliverableAnalyzerOperation)1 ProductMilestone (org.jboss.pnc.model.ProductMilestone)1 InconsistentDataException (org.jboss.pnc.spi.datastore.InconsistentDataException)1