Search in sources :

Example 6 with BuildConfigurationAudited

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

the class DatastoreMock method getLatestBuildConfigurationAuditedLoadBCDependencies.

@Override
public BuildConfigurationAudited getLatestBuildConfigurationAuditedLoadBCDependencies(Integer buildConfigurationId) {
    BuildConfiguration buildConfig = buildConfigurations.get(buildConfigurationId);
    int rev = buildConfigAuditedRevSequence.incrementAndGet();
    BuildConfigurationAudited buildConfigurationAudited = BuildConfigurationAudited.Builder.newBuilder().buildConfiguration(buildConfig).rev(rev).build();
    return buildConfigurationAudited;
}
Also used : BuildConfiguration(org.jboss.pnc.model.BuildConfiguration) BuildConfigurationAudited(org.jboss.pnc.model.BuildConfigurationAudited)

Example 7 with BuildConfigurationAudited

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

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

the class BuildTasksInitializer method createBuildSetTask.

public BuildSetTask createBuildSetTask(BuildConfigurationAudited buildConfigurationAudited, User user, BuildOptions buildOptions, Supplier<String> buildTaskIdProvider, Set<BuildTask> submittedBuildTasks) {
    BuildSetTask buildSetTask = BuildSetTask.Builder.newBuilder().buildOptions(buildOptions).startTime(new Date()).build();
    Set<BuildConfigurationAudited> toBuild = new HashSet<>();
    collectBuildTasks(buildConfigurationAudited, buildOptions, toBuild);
    log.debug("Collected build tasks for the BuildConfigurationAudited: {}. Collected: {}.", buildConfigurationAudited, toBuild.stream().map(BuildConfigurationAudited::toString).collect(Collectors.joining(", ")));
    fillBuildTaskSet(buildSetTask, user, buildTaskIdProvider, buildConfigurationAudited.getBuildConfiguration().getCurrentProductMilestone(), toBuild, submittedBuildTasks, buildOptions);
    return buildSetTask;
}
Also used : BuildConfigurationAudited(org.jboss.pnc.model.BuildConfigurationAudited) BuildSetTask(org.jboss.pnc.spi.coordinator.BuildSetTask) Date(java.util.Date) ExpiresDate(org.jboss.pnc.common.Date.ExpiresDate) HashSet(java.util.HashSet)

Example 9 with BuildConfigurationAudited

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

the class DefaultBuildCoordinator method isBuildConfigurationAlreadyInQueue.

private boolean isBuildConfigurationAlreadyInQueue(BuildTask buildTask) {
    BuildConfigurationAudited buildConfigurationAudited = buildTask.getBuildConfigurationAudited();
    Optional<BuildTask> unfinishedTask = buildQueue.getUnfinishedTask(buildConfigurationAudited);
    if (unfinishedTask.isPresent()) {
        log.debug("Task with the same buildConfigurationAudited is in the queue {}.", unfinishedTask.get());
        return true;
    } else {
        return false;
    }
}
Also used : BuildConfigurationAudited(org.jboss.pnc.model.BuildConfigurationAudited) BuildTask(org.jboss.pnc.spi.coordinator.BuildTask)

Example 10 with BuildConfigurationAudited

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

the class BuildResultPushManager method createCausewayPushRequest.

private BuildImportRequest createCausewayPushRequest(BuildRecord buildRecord, String tagPrefix, URI callBackUrl, String authToken, Long pushResultId, boolean reimport) {
    BuildEnvironment buildEnvironment = buildRecord.getBuildConfigurationAudited().getBuildEnvironment();
    logger.debug("BuildRecord: {}", buildRecord.getId());
    logger.debug("BuildEnvironment: {}", buildEnvironment);
    BuildRoot buildRoot = BuildRoot.builder().container("DOCKER_IMAGE").containerArchitecture(// TODO set based on env, some env has native build tools
    "x86_64").host("rhel").hostArchitecture("x86_64").tools(buildEnvironment.getAttributes()).build();
    List<Artifact> builtArtifactEntities = artifactRepository.queryWithPredicates(ArtifactPredicates.withBuildRecordId(buildRecord.getId()));
    List<Artifact> dependencyEntities = artifactRepository.queryWithPredicates(ArtifactPredicates.withDependantBuildRecordId(buildRecord.getId()));
    logger.debug("Preparing BuildImportRequest containing {} built artifacts and {} dependencies.", builtArtifactEntities.size(), dependencyEntities.size());
    BuildType buildType = buildRecord.getBuildConfigurationAudited().getBuildType();
    Set<Dependency> dependencies = collectDependencies(dependencyEntities);
    Set<BuiltArtifact> builtArtifacts = collectBuiltArtifacts(builtArtifactEntities, buildType);
    Map<String, String> callbackHeaders = Collections.singletonMap(MDCUtils.getMDCToHeaderMappings().get(MDCKeys.PROCESS_CONTEXT_KEY), pushResultId.toString());
    Request callbackTarget = Request.builder().method(Request.Method.POST).authTokenHeader(authToken).uri(callBackUrl).header(MDCUtils.getMDCToHeaderMappings().get(MDCKeys.PROCESS_CONTEXT_KEY), pushResultId.toString()).build();
    String executionRootName = buildRecord.getExecutionRootName();
    // prefer execution root name from generic parameters
    BuildConfigurationAudited buildConfigurationAudited = buildConfigurationAuditedRepository.queryById(buildRecord.getBuildConfigurationAuditedIdRev());
    Map<String, String> genericParameters = buildConfigurationAudited.getGenericParameters();
    if (executionRootName == null) {
        if (genericParameters.containsKey(BREW_BUILD_NAME.name())) {
            executionRootName = genericParameters.get(BREW_BUILD_NAME.name());
        } else {
            throw new IllegalArgumentException("Provided build " + buildRecord.getId() + " is missing brew name. Please set build attribute " + BUILD_BREW_NAME + ".");
        }
    }
    Build build = getBuild(buildRecord, tagPrefix, buildRoot, dependencies, builtArtifacts, executionRootName, buildType);
    return new BuildImportRequest(callbackTarget, build, reimport);
}
Also used : BuildImportRequest(org.jboss.pnc.api.causeway.dto.push.BuildImportRequest) Request(org.jboss.pnc.api.dto.Request) BuildImportRequest(org.jboss.pnc.api.causeway.dto.push.BuildImportRequest) Dependency(org.jboss.pnc.api.causeway.dto.push.Dependency) Artifact(org.jboss.pnc.model.Artifact) BuiltArtifact(org.jboss.pnc.api.causeway.dto.push.BuiltArtifact) MavenBuiltArtifact(org.jboss.pnc.api.causeway.dto.push.MavenBuiltArtifact) NpmBuiltArtifact(org.jboss.pnc.api.causeway.dto.push.NpmBuiltArtifact) BuiltArtifact(org.jboss.pnc.api.causeway.dto.push.BuiltArtifact) MavenBuiltArtifact(org.jboss.pnc.api.causeway.dto.push.MavenBuiltArtifact) NpmBuiltArtifact(org.jboss.pnc.api.causeway.dto.push.NpmBuiltArtifact) BuildConfigurationAudited(org.jboss.pnc.model.BuildConfigurationAudited) BuildEnvironment(org.jboss.pnc.model.BuildEnvironment) Build(org.jboss.pnc.api.causeway.dto.push.Build) MavenBuild(org.jboss.pnc.api.causeway.dto.push.MavenBuild) NpmBuild(org.jboss.pnc.api.causeway.dto.push.NpmBuild) BuildType(org.jboss.pnc.enums.BuildType) BuildRoot(org.jboss.pnc.api.causeway.dto.push.BuildRoot)

Aggregations

BuildConfigurationAudited (org.jboss.pnc.model.BuildConfigurationAudited)35 BuildConfiguration (org.jboss.pnc.model.BuildConfiguration)12 IdRev (org.jboss.pnc.model.IdRev)12 BuildSetTask (org.jboss.pnc.spi.coordinator.BuildSetTask)10 BuildTask (org.jboss.pnc.spi.coordinator.BuildTask)10 Test (org.junit.Test)8 HashSet (java.util.HashSet)7 BuildRecord (org.jboss.pnc.model.BuildRecord)6 Date (java.util.Date)5 Logger (org.slf4j.Logger)5 LoggerFactory (org.slf4j.LoggerFactory)5 Map (java.util.Map)4 Set (java.util.Set)4 Collectors (java.util.stream.Collectors)4 Inject (javax.inject.Inject)4 Base32LongID (org.jboss.pnc.model.Base32LongID)4 Collections (java.util.Collections)3 List (java.util.List)3 Optional (java.util.Optional)3 Stateless (javax.ejb.Stateless)3