Search in sources :

Example 1 with TargetRepository

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

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

the class IndyRepositorySession method collectUploads.

/**
 * Return list of output artifacts for promotion.
 *
 * @param report The tracking report that contains info about artifacts uploaded (output) from the build
 * @return List of output artifacts meta data
 * @throws RepositoryManagerException In case of a client API transport error or an error during promotion of
 *         artifacts
 */
private Uploads collectUploads(TrackedContentDTO report) throws RepositoryManagerException {
    List<Artifact> data;
    List<String> promotion;
    logger.info("BEGIN: Process artifacts uploaded from build");
    userLog.info("Processing built artifacts");
    StopWatch stopWatch = StopWatch.createStarted();
    Set<TrackedContentEntryDTO> uploads = report.getUploads();
    if (CollectionUtils.isEmpty(uploads)) {
        data = Collections.emptyList();
        promotion = Collections.emptyList();
    } else {
        data = new ArrayList<>();
        Set<String> promotionSet = new HashSet<>();
        IndyContentClientModule content;
        try {
            content = indy.content();
        } catch (IndyClientException e) {
            throw new RepositoryManagerException("Failed to retrieve Indy content module. Reason: %s", e, e.getMessage());
        }
        for (TrackedContentEntryDTO upload : uploads) {
            String path = upload.getPath();
            StoreKey storeKey = upload.getStoreKey();
            if (artifactFilter.acceptsForData(upload)) {
                String identifier = computeIdentifier(upload);
                String purl = computePurl(upload);
                logger.info("Recording upload: {}", identifier);
                RepositoryType repoType = toRepoType(storeKey.getPackageType());
                TargetRepository targetRepository = getUploadsTargetRepository(repoType, content);
                ArtifactQuality artifactQuality = getArtifactQuality(isTempBuild);
                Artifact.Builder artifactBuilder = Artifact.Builder.newBuilder().md5(upload.getMd5()).sha1(upload.getSha1()).sha256(upload.getSha256()).size(upload.getSize()).deployPath(upload.getPath()).filename(new File(path).getName()).identifier(identifier).purl(purl).targetRepository(targetRepository).artifactQuality(artifactQuality).buildCategory(buildCategory);
                Artifact artifact = validateArtifact(artifactBuilder.build());
                data.add(artifact);
            }
            if (artifactFilter.acceptsForPromotion(upload, false)) {
                promotionSet.add(path);
                if (MAVEN_PKG_KEY.equals(storeKey.getPackageType()) && !isChecksum(path)) {
                    // add the standard checksums to ensure, they are promoted (Maven usually uses only one, so
                    // the other would be missing) but avoid adding checksums of checksums.
                    promotionSet.add(path + ".md5");
                    promotionSet.add(path + ".sha1");
                }
            }
        }
        promotion = new ArrayList<>(promotionSet);
    }
    logger.info("END: Process artifacts uploaded from build, took {} seconds", stopWatch.getTime(TimeUnit.SECONDS));
    return new Uploads(data, promotion);
}
Also used : RepositoryType(org.jboss.pnc.enums.RepositoryType) RepositoryManagerException(org.jboss.pnc.spi.repositorymanager.RepositoryManagerException) StoreKey(org.commonjava.indy.model.core.StoreKey) Artifact(org.jboss.pnc.model.Artifact) StopWatch(org.apache.commons.lang3.time.StopWatch) TargetRepository(org.jboss.pnc.model.TargetRepository) TrackedContentEntryDTO(org.commonjava.indy.folo.dto.TrackedContentEntryDTO) IndyContentClientModule(org.commonjava.indy.client.core.module.IndyContentClientModule) IndyClientException(org.commonjava.indy.client.core.IndyClientException) ArtifactQuality(org.jboss.pnc.enums.ArtifactQuality) File(java.io.File) HashSet(java.util.HashSet)

Example 3 with TargetRepository

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

the class IndyRepositorySession method collectDownloadedArtifacts.

private List<Artifact> collectDownloadedArtifacts(TrackedContentDTO report) throws RepositoryManagerException {
    IndyContentClientModule content;
    try {
        content = indy.content();
    } catch (IndyClientException e) {
        throw new RepositoryManagerException("Failed to retrieve Indy content module. Reason: %s", e, e.getMessage());
    }
    Set<TrackedContentEntryDTO> downloads = report.getDownloads();
    List<Artifact> deps = new ArrayList<>(downloads.size());
    for (TrackedContentEntryDTO download : downloads) {
        String path = download.getPath();
        if (artifactFilter.acceptsForData(download)) {
            String identifier = computeIdentifier(download);
            String purl = computePurl(download);
            logger.info("Recording download: {}", identifier);
            String originUrl = download.getOriginUrl();
            if (originUrl == null) {
                // this is from a hosted repository, either shared-imports or a build, or something like that.
                originUrl = download.getLocalUrl();
            }
            TargetRepository targetRepository = getDownloadsTargetRepository(download, content);
            Artifact.Builder artifactBuilder = Artifact.Builder.newBuilder().md5(download.getMd5()).sha1(download.getSha1()).sha256(download.getSha256()).size(download.getSize()).deployPath(path).originUrl(originUrl).importDate(Date.from(Instant.now())).filename(new File(path).getName()).identifier(identifier).purl(purl).targetRepository(targetRepository);
            Artifact artifact = validateArtifact(artifactBuilder.build());
            deps.add(artifact);
        }
    }
    return deps;
}
Also used : TargetRepository(org.jboss.pnc.model.TargetRepository) TrackedContentEntryDTO(org.commonjava.indy.folo.dto.TrackedContentEntryDTO) IndyContentClientModule(org.commonjava.indy.client.core.module.IndyContentClientModule) ArrayList(java.util.ArrayList) IndyClientException(org.commonjava.indy.client.core.IndyClientException) RepositoryManagerException(org.jboss.pnc.spi.repositorymanager.RepositoryManagerException) File(java.io.File) Artifact(org.jboss.pnc.model.Artifact)

Example 4 with TargetRepository

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

Example 5 with TargetRepository

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

the class DeliverableAnalyzerManagerImpl method getBrewRepository.

private TargetRepository getBrewRepository(Build build) {
    String path = KOJI_PATH_MAVEN_PREFIX + build.getBrewNVR();
    TargetRepository tr = targetRepositoryRepository.queryByIdentifierAndPath(INDY_MAVEN, path);
    if (tr == null) {
        tr = createRepository(path, INDY_MAVEN, RepositoryType.MAVEN);
    }
    return tr;
}
Also used : TargetRepository(org.jboss.pnc.model.TargetRepository)

Aggregations

TargetRepository (org.jboss.pnc.model.TargetRepository)8 Artifact (org.jboss.pnc.model.Artifact)5 HashMap (java.util.HashMap)3 File (java.io.File)2 HashSet (java.util.HashSet)2 TransactionAttribute (javax.ejb.TransactionAttribute)2 IndyClientException (org.commonjava.indy.client.core.IndyClientException)2 IndyContentClientModule (org.commonjava.indy.client.core.module.IndyContentClientModule)2 TrackedContentEntryDTO (org.commonjava.indy.folo.dto.TrackedContentEntryDTO)2 ArtifactQuality (org.jboss.pnc.enums.ArtifactQuality)2 RepositoryType (org.jboss.pnc.enums.RepositoryType)2 BuildRecord (org.jboss.pnc.model.BuildRecord)2 RepositoryManagerException (org.jboss.pnc.spi.repositorymanager.RepositoryManagerException)2 MalformedURLException (java.net.MalformedURLException)1 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 StopWatch (org.apache.commons.lang3.time.StopWatch)1 StoreKey (org.commonjava.indy.model.core.StoreKey)1 ConfigurationParseException (org.jboss.pnc.common.json.ConfigurationParseException)1 GlobalModuleGroup (org.jboss.pnc.common.json.GlobalModuleGroup)1