Search in sources :

Example 1 with ProductMilestone

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

the class BuildTasksInitializer method fillBuildTaskSet.

/**
 * Creates build tasks and sets up the appropriate dependency relations
 *
 * @param buildSetTask The build set task which will contain the build tasks. This must already have initialized the
 *        BuildConfigSet, BuildConfigSetRecord, Milestone, etc.
 */
private void fillBuildTaskSet(BuildSetTask buildSetTask, User user, Supplier<String> buildTaskIdProvider, ProductMilestone productMilestone, Set<BuildConfigurationAudited> toBuild, Set<BuildTask> alreadySubmittedBuildTasks, BuildOptions buildOptions) {
    for (BuildConfigurationAudited buildConfigAudited : toBuild) {
        Optional<BuildTask> taskOptional = alreadySubmittedBuildTasks.stream().filter(bt -> bt.getBuildConfigurationAudited().equals(buildConfigAudited)).findAny();
        BuildTask buildTask;
        if (taskOptional.isPresent()) {
            buildTask = taskOptional.get();
            log.debug("Linking BuildConfigurationAudited {} to existing task {}.", buildConfigAudited, buildTask);
        } else {
            String buildId = buildTaskIdProvider.get();
            String buildContentId = ContentIdentityManager.getBuildContentId(buildId);
            // Used only for this operation inside the loop
            MDCUtils.addBuildContext(buildContentId, buildOptions.isTemporaryBuild(), ExpiresDate.getTemporaryBuildExpireDate(temporaryBuildLifespanDays, buildOptions.isTemporaryBuild()), user.getId().toString());
            try {
                Optional<String> requestContext = MDCUtils.getRequestContext();
                buildTask = BuildTask.build(buildConfigAudited, buildSetTask.getBuildOptions(), user, buildId, buildSetTask, buildSetTask.getStartTime(), productMilestone, buildContentId, requestContext);
                log.debug("Created new buildTask {} for BuildConfigurationAudited {}.", buildTask, buildConfigAudited);
            } finally {
                MDCUtils.removeBuildContext();
            }
        }
        buildSetTask.addBuildTask(buildTask);
    }
    // Loop again to set dependencies
    for (BuildTask buildTask : buildSetTask.getBuildTasks()) {
        for (BuildTask checkDepBuildTask : buildSetTask.getBuildTasks()) {
            if (buildTask.hasDirectConfigDependencyOn(checkDepBuildTask)) {
                buildTask.addDependency(checkDepBuildTask);
            }
        }
    }
}
Also used : BuildOptions(org.jboss.pnc.spi.BuildOptions) BuildConfiguration(org.jboss.pnc.model.BuildConfiguration) BuildConfigSetRecord(org.jboss.pnc.model.BuildConfigSetRecord) Date(java.util.Date) LoggerFactory(org.slf4j.LoggerFactory) BuildConfigurationSet(org.jboss.pnc.model.BuildConfigurationSet) AlignmentPreference(org.jboss.pnc.api.enums.AlignmentPreference) MDCUtils(org.jboss.pnc.common.logging.MDCUtils) BuildTask(org.jboss.pnc.spi.coordinator.BuildTask) Supplier(java.util.function.Supplier) BuildConfigurationAudited(org.jboss.pnc.model.BuildConfigurationAudited) HashSet(java.util.HashSet) Map(java.util.Map) ProductMilestone(org.jboss.pnc.model.ProductMilestone) BuildSetTask(org.jboss.pnc.spi.coordinator.BuildSetTask) User(org.jboss.pnc.model.User) DatastoreAdapter(org.jboss.pnc.coordinator.builder.datastore.DatastoreAdapter) Logger(org.slf4j.Logger) ExpiresDate(org.jboss.pnc.common.Date.ExpiresDate) ContentIdentityManager(org.jboss.pnc.model.utils.ContentIdentityManager) DatastoreException(org.jboss.pnc.spi.datastore.DatastoreException) Set(java.util.Set) Collectors(java.util.stream.Collectors) CoreException(org.jboss.pnc.spi.exception.CoreException) Optional(java.util.Optional) Collections(java.util.Collections) BuildConfigurationAudited(org.jboss.pnc.model.BuildConfigurationAudited) BuildTask(org.jboss.pnc.spi.coordinator.BuildTask)

Example 2 with ProductMilestone

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

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

the class ProductVersionProviderImpl method validateMilestone.

private void validateMilestone(Integer id, ProductVersion entity) {
    if (entity.getCurrentProductMilestone() != null) {
        Integer newMilestoneId = milestoneMapper.getIdMapper().toEntity(entity.getCurrentProductMilestone().getId());
        org.jboss.pnc.model.ProductVersion productVersion = repository.queryById(id);
        ProductMilestone currentMilestone = productVersion.getCurrentProductMilestone();
        if (currentMilestone == null || currentMilestone.getId() != newMilestoneId) {
            ProductMilestone newMilestone = milestoneRepository.queryById(newMilestoneId);
            if (newMilestone == null) {
                throw new InvalidEntityException("Milestone with id: " + newMilestoneId + " does not exist.");
            } else if (newMilestone.getEndDate() != null) {
                throw new InvalidEntityException("Milestone with id: " + newMilestoneId + " is closed, so cannot be set as current.");
            }
        }
    }
}
Also used : ProductMilestone(org.jboss.pnc.model.ProductMilestone) InvalidEntityException(org.jboss.pnc.facade.validation.InvalidEntityException)

Example 4 with ProductMilestone

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

the class ProductMilestoneProviderTest method testCancelMilestoneCloseProcessShouldFailIfAlreadyClosed.

@Test
public void testCancelMilestoneCloseProcessShouldFailIfAlreadyClosed() {
    // given
    ProductMilestone closed = ProductMilestoneFactory.getInstance().createNewProductMilestoneFromProductVersion(mock.getProductVersion(), "9.8.7.GA");
    closed.setEndDate(new Date());
    repositoryList.add(closed);
    // when then
    assertThatThrownBy(() -> provider.cancelMilestoneCloseProcess(closed.getId().toString())).isInstanceOf(RepositoryViolationException.class);
}
Also used : ProductMilestone(org.jboss.pnc.model.ProductMilestone) Date(java.util.Date) Test(org.junit.Test)

Example 5 with ProductMilestone

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

the class DeliverableAnalyzerManagerImpl method processDeliverables.

private void processDeliverables(int milestoneId, Collection<Build> builds, String distributionUrl) {
    ProductMilestone milestone = milestoneRepository.queryById(milestoneId);
    for (Build build : builds) {
        Function<Artifact, org.jboss.pnc.model.Artifact> artifactParser;
        if (build.getBuildSystemType() == null) {
            TargetRepository distributionRepository = getDistributionRepository(distributionUrl);
            artifactParser = art -> findOrCreateArtifact(art, distributionRepository);
        } else {
            switch(build.getBuildSystemType()) {
                case PNC:
                    artifactParser = this::getPncArtifact;
                    break;
                case BREW:
                    TargetRepository brewRepository = getBrewRepository(build);
                    artifactParser = art -> findOrCreateArtifact(assertBrewArtifacts(art), brewRepository);
                    break;
                default:
                    throw new UnsupportedOperationException("Unknown build system type " + build.getBuildSystemType());
            }
        }
        build.getArtifacts().stream().map(artifactParser).forEach(milestone::addDeliveredArtifact);
    }
    milestone.setDeliveredArtifactsImporter(userService.currentUser());
}
Also used : TargetRepository(org.jboss.pnc.model.TargetRepository) ProductMilestone(org.jboss.pnc.model.ProductMilestone)

Aggregations

ProductMilestone (org.jboss.pnc.model.ProductMilestone)15 Date (java.util.Date)4 Test (org.junit.Test)4 ProductMilestoneRelease (org.jboss.pnc.model.ProductMilestoneRelease)3 Optional (java.util.Optional)2 ProductMilestoneRef (org.jboss.pnc.dto.ProductMilestoneRef)2 BuildConfigSetRecord (org.jboss.pnc.model.BuildConfigSetRecord)2 BuildConfiguration (org.jboss.pnc.model.BuildConfiguration)2 BuildConfigurationSet (org.jboss.pnc.model.BuildConfigurationSet)2 BuildRecord (org.jboss.pnc.model.BuildRecord)2 ProductRelease (org.jboss.pnc.model.ProductRelease)2 ProductVersion (org.jboss.pnc.model.ProductVersion)2 Instant (java.time.Instant)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Set (java.util.Set)1