Search in sources :

Example 11 with BuildConfigSetRecord

use of org.jboss.pnc.model.BuildConfigSetRecord in project pnc by project-ncl.

the class TemporaryBuildsCleaner method deleteTemporaryBuildConfigSetRecord.

/**
 * Deletes a BuildConfigSetRecord and BuildRecords produced in the build
 *
 * @param buildConfigSetRecordId BuildConfigSetRecord to be deleted
 * @param authToken
 */
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public Result deleteTemporaryBuildConfigSetRecord(Integer buildConfigSetRecordId, String authToken) throws ValidationException {
    BuildConfigSetRecord buildConfigSetRecord = buildConfigSetRecordRepository.queryById(buildConfigSetRecordId);
    if (buildConfigSetRecord == null) {
        throw new ValidationException("Cannot delete temporary BuildConfigSetRecord with id " + buildConfigSetRecordId + " as no BuildConfigSetRecord with this id exists");
    }
    if (!buildConfigSetRecord.isTemporaryBuild()) {
        throw new ValidationException("Only deletion of the temporary builds is allowed");
    }
    log.info("Starting deletion of a temporary build record set " + buildConfigSetRecord);
    for (BuildRecord br : buildConfigSetRecord.getBuildRecords()) {
        br.setBuildConfigSetRecord(null);
        buildRecordRepository.save(br);
    }
    buildConfigSetRecordRepository.delete(buildConfigSetRecord.getId());
    log.info("Deletion of a temporary build record set {} finished successfully.", buildConfigSetRecord);
    return new Result(buildConfigSetRecordId.toString(), ResultStatus.SUCCESS);
}
Also used : ValidationException(org.jboss.pnc.spi.exception.ValidationException) BuildRecord(org.jboss.pnc.model.BuildRecord) BuildConfigSetRecord(org.jboss.pnc.model.BuildConfigSetRecord) Result(org.jboss.pnc.spi.coordinator.Result) TransactionAttribute(javax.ejb.TransactionAttribute)

Example 12 with BuildConfigSetRecord

use of org.jboss.pnc.model.BuildConfigSetRecord in project pnc by project-ncl.

the class BuildTask method build.

public static BuildTask build(BuildConfigurationAudited buildConfigurationAudited, BuildOptions buildOptions, User user, String buildTaskId, BuildSetTask buildSetTask, Date submitTime, ProductMilestone productMilestone, String contentId, Optional<String> requestContext) {
    Integer buildConfigSetRecordId = null;
    if (buildSetTask != null) {
        buildConfigSetRecordId = buildSetTask.getBuildConfigSetRecord().map(BuildConfigSetRecord::getId).orElse(null);
    }
    ProductMilestone milestone = productMilestone;
    if (milestone != null && milestone.getEndDate() != null) {
        userLog.warn("Not using current milestone {} for build task {}, because the milestone is closed.", productMilestone, buildTaskId);
        milestone = null;
    }
    return new BuildTask(buildConfigurationAudited, buildOptions, user, submitTime, buildSetTask, buildTaskId, buildConfigSetRecordId, milestone, contentId, requestContext);
}
Also used : ProductMilestone(org.jboss.pnc.model.ProductMilestone) BuildConfigSetRecord(org.jboss.pnc.model.BuildConfigSetRecord)

Example 13 with BuildConfigSetRecord

use of org.jboss.pnc.model.BuildConfigSetRecord in project pnc by project-ncl.

the class GroupBuildProviderTest method prepareBCSetRecord.

private BuildConfigSetRecord prepareBCSetRecord(BuildConfigurationSet buildConfigurationSet) {
    final BuildConfigSetRecord record = BuildConfigSetRecord.Builder.newBuilder().id(entityId.getAndIncrement()).buildConfigurationSet(buildConfigurationSet).startTime(Date.from(Instant.now())).user(mockUser()).temporaryBuild(false).build();
    buildConfigurationSet.addBuildConfigSetRecord(record);
    return record;
}
Also used : BuildConfigSetRecord(org.jboss.pnc.model.BuildConfigSetRecord)

Example 14 with BuildConfigSetRecord

use of org.jboss.pnc.model.BuildConfigSetRecord 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 15 with BuildConfigSetRecord

use of org.jboss.pnc.model.BuildConfigSetRecord in project pnc by project-ncl.

the class StatusUpdatesTest method BuildTaskCallbacksShouldBeCalled.

@Test
@InSequence(30)
public void BuildTaskCallbacksShouldBeCalled() throws DatastoreException, CoreException {
    User user = User.Builder.newBuilder().id(3).username("test-user-3").build();
    Set<BuildTask> buildTasks = initializeBuildTaskSet(configurationBuilder, user, (buildConfigSetRecord) -> {
    }).getBuildTasks();
    Set<String> tasksIds = buildTasks.stream().map((BuildTask::getId)).collect(Collectors.toSet());
    Set<String> receivedUpdatesForId = new HashSet<>();
    Consumer<BuildStatusChangedEvent> statusChangeEventConsumer = (statusChangedEvent) -> {
        receivedUpdatesForId.add(statusChangedEvent.getBuild().getId());
    };
    tasksIds.forEach((id) -> buildStatusNotifications.subscribe(new BuildCallBack(id, statusChangeEventConsumer)));
    buildTasks.forEach((bt) -> buildCoordinator.updateBuildTaskStatus(bt, BuildCoordinationStatus.DONE));
    System.out.println("Received updates: " + receivedUpdatesForId);
    tasksIds.forEach((id) -> Assert.assertTrue("Did not receive update for task " + id, receivedUpdatesForId.contains(id)));
}
Also used : BuildOptions(org.jboss.pnc.spi.BuildOptions) BuildStatusNotifications(org.jboss.pnc.coordinator.notifications.buildTask.BuildStatusNotifications) Arquillian(org.jboss.arquillian.junit.Arquillian) BuildCoordinationStatus(org.jboss.pnc.enums.BuildCoordinationStatus) LoggerFactory(org.slf4j.LoggerFactory) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) User(org.jboss.pnc.model.User) DatastoreAdapter(org.jboss.pnc.coordinator.builder.datastore.DatastoreAdapter) BuildCoordinator(org.jboss.pnc.spi.coordinator.BuildCoordinator) BuildResult(org.jboss.pnc.spi.BuildResult) DatastoreException(org.jboss.pnc.spi.datastore.DatastoreException) Set(java.util.Set) BuildStatus(org.jboss.pnc.enums.BuildStatus) Collectors(java.util.stream.Collectors) TestProjectConfigurationBuilder(org.jboss.pnc.mock.model.builders.TestProjectConfigurationBuilder) BuildDriverResult(org.jboss.pnc.spi.builddriver.BuildDriverResult) CoreException(org.jboss.pnc.spi.exception.CoreException) JavaArchive(org.jboss.shrinkwrap.api.spec.JavaArchive) BuildStatusChangedEvent(org.jboss.pnc.spi.events.BuildStatusChangedEvent) BuildSetStatusChangedEvent(org.jboss.pnc.spi.events.BuildSetStatusChangedEvent) Optional(java.util.Optional) RandomStringUtils(org.apache.commons.lang3.RandomStringUtils) IndyRepositoryManagerResult(org.jboss.pnc.indyrepositorymanager.IndyRepositoryManagerResult) BuildConfigSetRecord(org.jboss.pnc.model.BuildConfigSetRecord) BuildSetStatus(org.jboss.pnc.spi.BuildSetStatus) RunWith(org.junit.runner.RunWith) BuildConfigurationSet(org.jboss.pnc.model.BuildConfigurationSet) BuildSetStatusNotifications(org.jboss.pnc.coordinator.notifications.buildSetTask.BuildSetStatusNotifications) BuildCallBack(org.jboss.pnc.coordinator.notifications.buildTask.BuildCallBack) RebuildMode(org.jboss.pnc.enums.RebuildMode) BuildTask(org.jboss.pnc.spi.coordinator.BuildTask) Supplier(java.util.function.Supplier) Inject(javax.inject.Inject) HashSet(java.util.HashSet) BuildCoordinatorDeployments(org.jboss.pnc.coordinator.test.BuildCoordinatorDeployments) CompletionStatus(org.jboss.pnc.spi.coordinator.CompletionStatus) BuildTasksInitializer(org.jboss.pnc.coordinator.builder.BuildTasksInitializer) BuildSetTask(org.jboss.pnc.spi.coordinator.BuildSetTask) BuildQueue(org.jboss.pnc.coordinator.builder.BuildQueue) Event(javax.enterprise.event.Event) Logger(org.slf4j.Logger) Test(org.junit.Test) InSequence(org.jboss.arquillian.junit.InSequence) Consumer(java.util.function.Consumer) ObjectWrapper(org.jboss.pnc.common.util.ObjectWrapper) Deployment(org.jboss.arquillian.container.test.api.Deployment) Assert(org.junit.Assert) Sequence(org.jboss.pnc.common.concurrent.Sequence) Collections(java.util.Collections) User(org.jboss.pnc.model.User) BuildTask(org.jboss.pnc.spi.coordinator.BuildTask) BuildStatusChangedEvent(org.jboss.pnc.spi.events.BuildStatusChangedEvent) BuildCallBack(org.jboss.pnc.coordinator.notifications.buildTask.BuildCallBack) HashSet(java.util.HashSet) Test(org.junit.Test) InSequence(org.jboss.arquillian.junit.InSequence)

Aggregations

BuildConfigSetRecord (org.jboss.pnc.model.BuildConfigSetRecord)23 Test (org.junit.Test)10 BuildRecord (org.jboss.pnc.model.BuildRecord)9 BuildOptions (org.jboss.pnc.spi.BuildOptions)8 BuildConfigurationSet (org.jboss.pnc.model.BuildConfigurationSet)7 BuildSetStatus (org.jboss.pnc.spi.BuildSetStatus)7 BuildSetTask (org.jboss.pnc.spi.coordinator.BuildSetTask)7 HashSet (java.util.HashSet)6 User (org.jboss.pnc.model.User)6 DatastoreException (org.jboss.pnc.spi.datastore.DatastoreException)6 BuildTask (org.jboss.pnc.spi.coordinator.BuildTask)5 CoreException (org.jboss.pnc.spi.exception.CoreException)5 Optional (java.util.Optional)4 Set (java.util.Set)4 DatastoreAdapter (org.jboss.pnc.coordinator.builder.datastore.DatastoreAdapter)4 Logger (org.slf4j.Logger)4 LoggerFactory (org.slf4j.LoggerFactory)4 Collections (java.util.Collections)3 Date (java.util.Date)3 Event (javax.enterprise.event.Event)3