Search in sources :

Example 1 with Artifact

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

the class BuildExecutionTest method testBuild.

@Test
public void testBuild() throws ExecutorException, TimeoutException, InterruptedException, BuildDriverException {
    BuildConfiguration buildConfiguration = configurationBuilder.build(1, "c1-java");
    Set<BuildExecutionStatusChangedEvent> statusChangedEvents = new HashSet<>();
    ObjectWrapper<BuildResult> buildExecutionResultWrapper = new ObjectWrapper<>();
    runBuild(buildConfiguration, statusChangedEvents, buildExecutionResultWrapper);
    List<BuildExecutionStatus> expectedStatuses = getBuildExecutionStatusesSuccess();
    // check build statuses
    checkBuildStatuses(statusChangedEvents, expectedStatuses);
    // check results
    BuildResult buildResult = buildExecutionResultWrapper.get();
    // check results: logs
    BuildDriverResult buildDriverResult = buildResult.getBuildDriverResult().get();
    String buildLog = buildDriverResult.getBuildLog();
    Assert.assertTrue("Invalid build log.", buildLog.contains("Finished: SUCCESS"));
    // check results: artifacts
    RepositoryManagerResult repositoryManagerResult = buildResult.getRepositoryManagerResult().get();
    Assert.assertTrue("Missing build artifacts.", repositoryManagerResult.getBuiltArtifacts().size() > 0);
    Assert.assertTrue("Missing build dependencies.", repositoryManagerResult.getDependencies().size() > 0);
    Artifact artifact = repositoryManagerResult.getBuiltArtifacts().iterator().next();
    Assert.assertTrue("Invalid built artifact in the result.", artifact.getIdentifier().startsWith(ArtifactBuilder.IDENTIFIER_PREFIX));
}
Also used : BuildDriverResult(org.jboss.pnc.spi.builddriver.BuildDriverResult) RepositoryManagerResult(org.jboss.pnc.spi.repositorymanager.RepositoryManagerResult) BuildExecutionStatus(org.jboss.pnc.enums.BuildExecutionStatus) Artifact(org.jboss.pnc.model.Artifact) BuildExecutionStatusChangedEvent(org.jboss.pnc.spi.events.BuildExecutionStatusChangedEvent) BuildConfiguration(org.jboss.pnc.model.BuildConfiguration) BuildResult(org.jboss.pnc.spi.BuildResult) ObjectWrapper(org.jboss.pnc.common.util.ObjectWrapper) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 2 with Artifact

use of org.jboss.pnc.model.Artifact 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)

Example 3 with Artifact

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

the class TemporaryBuildsCleaner method removeBuiltArtifacts.

private void removeBuiltArtifacts(BuildRecord buildRecord) {
    Set<Artifact> toDelete = new HashSet<>(buildRecord.getBuiltArtifacts());
    for (Artifact artifact : toDelete) {
        log.debug(String.format("Deleting relation BR-Artifact. BR=%s, artifact=%s", buildRecord, artifact.getDescriptiveString()));
        if (!artifact.getDeliveredInProductMilestones().isEmpty()) {
            log.error("Temporary artifact was delivered in milestone! Artifact: " + artifact + "\n Milestones: " + artifact.getDeliveredInProductMilestones());
            continue;
        }
        artifact.setBuildRecord(null);
        deleteArtifact(artifact);
    }
}
Also used : Artifact(org.jboss.pnc.model.Artifact) HashSet(java.util.HashSet)

Example 4 with Artifact

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

the class DefaultDatastore method fetchOrSaveRequiredTargetRepositories.

private void fetchOrSaveRequiredTargetRepositories(Collection<Artifact> artifacts, Map<TargetRepository.IdentifierPath, TargetRepository> storedTargetRepositories) {
    Map<TargetRepository.IdentifierPath, TargetRepository> requiredTargetRepositories = new HashMap<>();
    for (Artifact artifact : artifacts) {
        TargetRepository targetRepository = artifact.getTargetRepository();
        logger.trace("Adding repository for artifact: {}.", artifact.toString());
        if (!storedTargetRepositories.containsKey(targetRepository.getIdentifierPath())) {
            requiredTargetRepositories.put(targetRepository.getIdentifierPath(), targetRepository);
        }
    }
    if (requiredTargetRepositories.size() > 0) {
        List<TargetRepository> targetRepositoriesInDB = targetRepositoryRepository.queryByIdentifiersAndPaths(requiredTargetRepositories.keySet());
        for (TargetRepository targetRepository : targetRepositoriesInDB) {
            storedTargetRepositories.put(targetRepository.getIdentifierPath(), targetRepository);
            requiredTargetRepositories.remove(targetRepository.getIdentifierPath());
        }
        for (TargetRepository targetRepository : requiredTargetRepositories.values()) {
            // NCL-5474: This can potentionally cause unique constraint violation if two builds finish at the same
            // time, both with the same new target repository. This is unlikely to happen, so we take the risk.
            TargetRepository savedTargetRepository = targetRepositoryRepository.save(targetRepository);
            storedTargetRepositories.put(targetRepository.getIdentifierPath(), savedTargetRepository);
        }
    }
}
Also used : TargetRepository(org.jboss.pnc.model.TargetRepository) HashMap(java.util.HashMap) Artifact(org.jboss.pnc.model.Artifact)

Example 5 with Artifact

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

the class DefaultDatastore method checkForBuiltArtifacts.

@Override
public Map<Artifact, String> checkForBuiltArtifacts(Collection<Artifact> artifacts) {
    Map<RepositoryType, Map<String, Artifact>> repoTypes = new HashMap<>();
    for (Artifact artifact : artifacts) {
        RepositoryType repoType = artifact.getTargetRepository().getRepositoryType();
        if (!repoTypes.containsKey(repoType)) {
            repoTypes.put(repoType, new HashMap<>());
        }
        Map<String, Artifact> identifiers = repoTypes.get(repoType);
        identifiers.put(artifact.getIdentifier(), artifact);
    }
    Map<Artifact, String> conflicts = new HashMap<>();
    for (RepositoryType repoType : repoTypes.keySet()) {
        Map<String, Artifact> identifiers = repoTypes.get(repoType);
        List<Artifact> conflicting = artifactRepository.queryWithPredicates(withIdentifierInAndBuilt(identifiers.keySet()));
        for (Artifact conflict : conflicting) {
            if (conflict.getTargetRepository().getRepositoryType() == repoType) {
                Artifact artifact = identifiers.get(conflict.getIdentifier());
                conflicts.put(artifact, ARTIFACT_ALREADY_BUILT_CONFLICT_MESSAGE + conflict.getBuildRecord().getId());
            }
        }
    }
    return conflicts;
}
Also used : HashMap(java.util.HashMap) RepositoryType(org.jboss.pnc.enums.RepositoryType) HashMap(java.util.HashMap) Map(java.util.Map) Artifact(org.jboss.pnc.model.Artifact)

Aggregations

Artifact (org.jboss.pnc.model.Artifact)36 Test (org.junit.Test)16 RepositoryManagerResult (org.jboss.pnc.spi.repositorymanager.RepositoryManagerResult)14 ContainerTest (org.jboss.pnc.test.category.ContainerTest)14 HashSet (java.util.HashSet)13 BuildRecord (org.jboss.pnc.model.BuildRecord)12 RepositorySession (org.jboss.pnc.spi.repositorymanager.model.RepositorySession)12 TestBuildExecution (org.jboss.pnc.indyrepositorymanager.fixture.TestBuildExecution)11 BuildExecution (org.jboss.pnc.spi.repositorymanager.BuildExecution)11 StoreKey (org.commonjava.indy.model.core.StoreKey)10 File (java.io.File)8 HashMap (java.util.HashMap)7 TargetRepository (org.jboss.pnc.model.TargetRepository)7 Map (java.util.Map)5 SimpleArtifactRef (org.commonjava.atlas.maven.ident.ref.SimpleArtifactRef)5 BuildConfigurationAudited (org.jboss.pnc.model.BuildConfigurationAudited)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ArrayList (java.util.ArrayList)4 Date (java.util.Date)4 List (java.util.List)4