Search in sources :

Example 1 with BuildCategory

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

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

the class BuildConfigurationEndpointImpl method validate.

private void validate(BuildConfiguration buildConfiguration) {
    if (buildConfiguration != null) {
        Map<String, String> parameters = buildConfiguration.getParameters();
        String buildCategoryKey = BuildConfigurationParameterKeys.BUILD_CATEGORY.name();
        if (parameters != null && parameters.containsKey(buildCategoryKey)) {
            String buildCategoryStr = parameters.get(buildCategoryKey);
            try {
                BuildCategory.valueOf(buildCategoryStr.toUpperCase());
            } catch (Exception ex) {
                List<String> categories = Stream.of(BuildCategory.values()).map(BuildCategory::name).collect(Collectors.toList());
                throw new InvalidEntityException(buildCategoryKey + " value '" + buildCategoryStr + "' is invalid. Valid values are: " + String.join(", ", categories) + '.');
            }
        }
    }
}
Also used : BuildCategory(org.jboss.pnc.enums.BuildCategory) List(java.util.List) BuildConflictException(org.jboss.pnc.spi.exception.BuildConflictException) NotFoundException(javax.ws.rs.NotFoundException) InvalidEntityException(org.jboss.pnc.facade.validation.InvalidEntityException) CoreException(org.jboss.pnc.spi.exception.CoreException) AlreadyRunningException(org.jboss.pnc.facade.validation.AlreadyRunningException) InvalidEntityException(org.jboss.pnc.facade.validation.InvalidEntityException)

Example 3 with BuildCategory

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

the class RepositoryManagerDriver method createBuildRepository.

/**
 * Use the Indy client API to setup global and build-set level repos and groups, then setup the repo/group needed
 * for this build. Calculate the URL to use for resolving artifacts using the Indy Folo API (Folo is an artifact
 * activity-tracker). Return a new session ({@link IndyRepositorySession}) containing this information.
 *
 * @throws RepositoryManagerException In the event one or more repositories or groups can't be created to support
 *         the build (or product, or shared-releases).
 */
@Override
public RepositorySession createBuildRepository(BuildExecution buildExecution, String accessToken, String serviceAccountToken, RepositoryType repositoryType, Map<String, String> genericParameters, boolean brewPullActive) throws RepositoryManagerException {
    Indy indy = init(accessToken);
    Indy serviceAccountIndy = init(serviceAccountToken);
    String packageType = getIndyPackageTypeKey(repositoryType);
    String buildId = buildExecution.getBuildContentId();
    try {
        setupBuildRepos(buildExecution, packageType, serviceAccountIndy, genericParameters, brewPullActive);
    } catch (IndyClientException e) {
        logger.debug("Failed to setup repository or repository group for this build");
        throw new RepositoryManagerException("Failed to setup repository or repository group for this build: %s", e, e.getMessage());
    }
    // since we're setting up a group/hosted repo per build, we can pin the tracking ID to the build repo ID.
    String url;
    String deployUrl;
    try {
        // manually initialize the tracking record, just in case (somehow) nothing gets downloaded/uploaded.
        indy.module(IndyFoloAdminClientModule.class).initReport(buildId);
        StoreKey groupKey = new StoreKey(packageType, StoreType.group, buildId);
        url = indy.module(IndyFoloContentClientModule.class).trackingUrl(buildId, groupKey);
        StoreKey hostedKey = new StoreKey(packageType, StoreType.hosted, buildId);
        deployUrl = indy.module(IndyFoloContentClientModule.class).trackingUrl(buildId, hostedKey);
        if (INDY_SIDECAR_ENABLED) {
            logger.info("Indy sidecar feature enabled: replacing Indy host with Indy sidecar host");
            try {
                url = UrlUtils.replaceHostInUrl(url, INDY_SIDECAR_URL);
                deployUrl = UrlUtils.replaceHostInUrl(deployUrl, INDY_SIDECAR_URL);
            } catch (MalformedURLException e) {
                throw new RuntimeException(String.format("Indy sidecar url ('%s') or Indy urls ('%s', '%s') are malformed!", INDY_SIDECAR_URL, url, deployUrl));
            }
        }
        logger.info("Using '{}' for {} repository access in build: {}", url, packageType, buildId);
    } catch (IndyClientException e) {
        logger.debug("Failed to retrieve Indy client module for the artifact tracker");
        throw new RepositoryManagerException("Failed to retrieve Indy client module for the artifact tracker: %s", e, e.getMessage());
    }
    boolean tempBuild = buildExecution.isTempBuild();
    String buildPromotionTarget = tempBuild ? TEMP_BUILD_PROMOTION_TARGET : BUILD_PROMOTION_TARGET;
    BuildCategory buildCategory = getBuildCategory(genericParameters);
    ArtifactFilter artifactFilter = new ArtifactFilterImpl(ignoredPathPatternsPromotion, ignoredPathPatternsData, ignoredRepoPatterns);
    return new IndyRepositorySession(indy, serviceAccountIndy, buildId, packageType, new IndyRepositoryConnectionInfo(url, deployUrl), artifactFilter, buildPromotionTarget, buildCategory, tempBuild);
}
Also used : MalformedURLException(java.net.MalformedURLException) RepositoryManagerException(org.jboss.pnc.spi.repositorymanager.RepositoryManagerException) StoreKey(org.commonjava.indy.model.core.StoreKey) IndyFoloAdminClientModule(org.commonjava.indy.folo.client.IndyFoloAdminClientModule) BuildCategory(org.jboss.pnc.enums.BuildCategory) Indy(org.commonjava.indy.client.core.Indy) IndyClientException(org.commonjava.indy.client.core.IndyClientException)

Example 4 with BuildCategory

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

the class RepositoryManagerDriver method collectRepoManagerResult.

@Override
public RepositoryManagerResult collectRepoManagerResult(String id) throws RepositoryManagerException {
    Base32LongID buildId = new Base32LongID(id);
    BuildRecord br = buildRecordRepository.findByIdFetchProperties(buildId);
    if (br == null) {
        return null;
    }
    BuildConfigurationAudited bc = br.getBuildConfigurationAudited();
    String buildContentId = br.getBuildContentId();
    BuildType buildType = bc.getBuildType();
    boolean tempBuild = br.isTemporaryBuild();
    Indy indy = init(null);
    String buildPromotionTarget = tempBuild ? TEMP_BUILD_PROMOTION_TARGET : BUILD_PROMOTION_TARGET;
    String packageType = getIndyPackageTypeKey(buildType.getRepoType());
    BuildCategory buildCategory = getBuildCategory(bc.getGenericParameters());
    ArtifactFilter artifactFilter = new ArtifactFilterImpl(ignoredPathPatternsPromotion, ignoredPathPatternsData, ignoredRepoPatterns);
    IndyRepositorySession session = new IndyRepositorySession(indy, indy, buildContentId, packageType, null, artifactFilter, buildPromotionTarget, buildCategory, tempBuild);
    return session.extractBuildArtifacts(false);
}
Also used : BuildConfigurationAudited(org.jboss.pnc.model.BuildConfigurationAudited) Base32LongID(org.jboss.pnc.model.Base32LongID) BuildCategory(org.jboss.pnc.enums.BuildCategory) Indy(org.commonjava.indy.client.core.Indy) BuildType(org.jboss.pnc.enums.BuildType) BuildRecord(org.jboss.pnc.model.BuildRecord)

Aggregations

BuildCategory (org.jboss.pnc.enums.BuildCategory)4 List (java.util.List)2 Indy (org.commonjava.indy.client.core.Indy)2 MalformedURLException (java.net.MalformedURLException)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 NotFoundException (javax.ws.rs.NotFoundException)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 IndyFoloAdminClientModule (org.commonjava.indy.folo.client.IndyFoloAdminClientModule)1 StoreKey (org.commonjava.indy.model.core.StoreKey)1 Artifact (org.jboss.pnc.dto.Artifact)1 ArtifactRevision (org.jboss.pnc.dto.ArtifactRevision)1 TargetRepository (org.jboss.pnc.dto.TargetRepository)1 Page (org.jboss.pnc.dto.response.Page)1 ArtifactQuality (org.jboss.pnc.enums.ArtifactQuality)1 BuildType (org.jboss.pnc.enums.BuildType)1 RepositoryType (org.jboss.pnc.enums.RepositoryType)1 UserService (org.jboss.pnc.facade.util.UserService)1