Search in sources :

Example 1 with RepositoryType

use of org.jboss.pnc.enums.RepositoryType in project pnc by project-ncl.

the class DefaultBuildExecutor method configureRepository.

private RepositorySession configureRepository(DefaultBuildExecutionSession buildExecutionSession) {
    if (buildExecutionSession.isCanceled()) {
        return null;
    }
    ProcessStageUtils.logProcessStageBegin(BuildExecutionStatus.REPO_SETTING_UP.toString(), "Setting up repository...");
    buildExecutionSession.setStatus(BuildExecutionStatus.REPO_SETTING_UP);
    BuildType buildType = buildExecutionSession.getBuildExecutionConfiguration().getBuildType();
    if (buildType == null) {
        throw new BuildProcessException("Missing required value buildExecutionConfiguration.buildType");
    }
    RepositoryType repositoryType = BuildTypeToRepositoryType.getRepositoryType(buildType);
    try {
        RepositoryManager repositoryManager = repositoryManagerFactory.getRepositoryManager(repositoryType);
        BuildExecution buildExecution = buildExecutionSession.getBuildExecutionConfiguration();
        String serviceAccountToken = (serviceClient == null ? null : serviceClient.getAuthToken());
        RepositorySession buildRepository = repositoryManager.createBuildRepositoryWithRetries(buildExecution, buildExecutionSession.getAccessToken(), serviceAccountToken, repositoryType, buildExecutionSession.getBuildExecutionConfiguration().getGenericParameters(), buildExecutionSession.getBuildExecutionConfiguration().isBrewPullActive());
        return buildRepository;
    } catch (Throwable e) {
        throw new BuildProcessException(e);
    } finally {
        ProcessStageUtils.logProcessStageEnd(BuildExecutionStatus.REPO_SETTING_UP.toString(), "Repository setup complete.");
    }
}
Also used : RepositoryType(org.jboss.pnc.enums.RepositoryType) BuildType(org.jboss.pnc.enums.BuildType) BuildExecution(org.jboss.pnc.spi.repositorymanager.BuildExecution) RepositoryManager(org.jboss.pnc.spi.repositorymanager.RepositoryManager) RepositorySession(org.jboss.pnc.spi.repositorymanager.model.RepositorySession) BuildProcessException(org.jboss.pnc.executor.exceptions.BuildProcessException)

Example 2 with RepositoryType

use of org.jboss.pnc.enums.RepositoryType 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)

Example 3 with RepositoryType

use of org.jboss.pnc.enums.RepositoryType 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 4 with RepositoryType

use of org.jboss.pnc.enums.RepositoryType in project pnc by project-ncl.

the class ArtifactProviderTest method testStore.

@Test
public void testStore() {
    TargetRepository repo = TargetRepository.refBuilder().identifier("repo-id").repositoryPath("/repo/path").repositoryType(RepositoryType.MAVEN).build();
    final String identifier = "foo:bar:0.0.1";
    Artifact artifact = Artifact.builder().identifier(identifier).artifactQuality(ArtifactQuality.NEW).buildCategory(BuildCategory.STANDARD).build();
    Artifact stored = provider.store(artifact);
    assertThat(stored.getIdentifier()).isEqualTo(identifier);
    assertThat(stored.getId()).isNotNull();
    Mockito.verify(repository).save(ArgumentMatchers.argThat(a -> identifier.equals(a.getIdentifier())));
}
Also used : TargetRepository(org.jboss.pnc.dto.TargetRepository) TargetRepository(org.jboss.pnc.dto.TargetRepository) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ArgumentMatchers(org.mockito.ArgumentMatchers) SortInfo(org.jboss.pnc.spi.datastore.repositories.api.SortInfo) Predicate(org.jboss.pnc.spi.datastore.repositories.api.Predicate) Mock(org.mockito.Mock) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RunWith(org.junit.runner.RunWith) ArtifactQuality(org.jboss.pnc.enums.ArtifactQuality) ArtifactRevision(org.jboss.pnc.dto.ArtifactRevision) ArtifactRepository(org.jboss.pnc.spi.datastore.repositories.ArtifactRepository) Repository(org.jboss.pnc.spi.datastore.repositories.api.Repository) ArrayList(java.util.ArrayList) BuildRecordRepository(org.jboss.pnc.spi.datastore.repositories.BuildRecordRepository) RepositoryType(org.jboss.pnc.enums.RepositoryType) UserService(org.jboss.pnc.facade.util.UserService) DTOValidationException(org.jboss.pnc.facade.validation.DTOValidationException) Spy(org.mockito.Spy) Assert.fail(org.junit.Assert.fail) User(org.jboss.pnc.model.User) Before(org.junit.Before) InjectMocks(org.mockito.InjectMocks) ArtifactAudited(org.jboss.pnc.model.ArtifactAudited) Iterator(java.util.Iterator) ArtifactAuditedRepository(org.jboss.pnc.spi.datastore.repositories.ArtifactAuditedRepository) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Artifact(org.jboss.pnc.dto.Artifact) Page(org.jboss.pnc.dto.response.Page) IdRev(org.jboss.pnc.model.IdRev) Mockito(org.mockito.Mockito) List(java.util.List) Condition(org.assertj.core.api.Condition) BuildCategory(org.jboss.pnc.enums.BuildCategory) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Assert.assertEquals(org.junit.Assert.assertEquals) TargetRepositoryRepository(org.jboss.pnc.spi.datastore.repositories.TargetRepositoryRepository) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Artifact(org.jboss.pnc.dto.Artifact) Test(org.junit.Test)

Example 5 with RepositoryType

use of org.jboss.pnc.enums.RepositoryType in project pnc by project-ncl.

the class ArtifactEndpointTest method testGetAllArtifactsFilteredByRepoType.

@Test
public void testGetAllArtifactsFilteredByRepoType() throws RemoteResourceException {
    ArtifactClient client = new ArtifactClient(RestClientConfiguration.asAnonymous());
    RemoteCollection<ArtifactInfo> result;
    RepositoryType type = RepositoryType.NPM;
    result = client.getAllFiltered(null, null, type);
    // from DatabaseDataInitializer
    assertThat(result).hasSize(2).allSatisfy(a -> assertThat(a.getRepositoryType().equals(type)));
}
Also used : ArtifactInfo(org.jboss.pnc.dto.response.ArtifactInfo) RepositoryType(org.jboss.pnc.enums.RepositoryType) ArtifactClient(org.jboss.pnc.client.ArtifactClient) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Aggregations

RepositoryType (org.jboss.pnc.enums.RepositoryType)7 StoreKey (org.commonjava.indy.model.core.StoreKey)2 ArtifactQuality (org.jboss.pnc.enums.ArtifactQuality)2 Artifact (org.jboss.pnc.model.Artifact)2 TargetRepository (org.jboss.pnc.model.TargetRepository)2 RepositoryManagerException (org.jboss.pnc.spi.repositorymanager.RepositoryManagerException)2 File (java.io.File)1 MalformedURLException (java.net.MalformedURLException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 StopWatch (org.apache.commons.lang3.time.StopWatch)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Condition (org.assertj.core.api.Condition)1 IndyClientException (org.commonjava.indy.client.core.IndyClientException)1 IndyContentClientModule (org.commonjava.indy.client.core.module.IndyContentClientModule)1 TrackedContentEntryDTO (org.commonjava.indy.folo.dto.TrackedContentEntryDTO)1