Search in sources :

Example 1 with BuildConfigurationRevisionRef

use of org.jboss.pnc.dto.BuildConfigurationRevisionRef in project pnc by project-ncl.

the class BuildEndpointTest method shouldFilterByBuildConfigurationNameAndUserId.

@Test
public void shouldFilterByBuildConfigurationNameAndUserId() throws Exception {
    BuildClient client = new BuildClient(RestClientConfiguration.asAnonymous());
    String buildConfigName = DatabaseDataInitializer.PNC_PROJECT_BUILD_CFG_ID;
    String username = "pnc-admin";
    String rsql = "user.username==" + username;
    BuildsFilterParameters filter = new BuildsFilterParameters();
    filter.setBuildConfigName(buildConfigName);
    List<Build> builds = new ArrayList<>(client.getAll(filter, null, Optional.empty(), Optional.of(rsql)).getAll());
    assertThat(builds).hasSize(2);
    assertThat(builds.stream().map(Build::getBuildConfigRevision).map(BuildConfigurationRevisionRef::getName).allMatch(name -> name.equals(buildConfigName)));
    assertThat(builds.stream().map(Build::getUser).map(User::getUsername).allMatch(name -> name.equals(username)));
}
Also used : Arquillian(org.jboss.arquillian.junit.Arquillian) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) LoggerFactory(org.slf4j.LoggerFactory) User(org.jboss.pnc.dto.User) BadRequestException(javax.ws.rs.BadRequestException) BuildConfigurationRevision(org.jboss.pnc.dto.BuildConfigurationRevision) Deployments(org.jboss.pnc.integration.setup.Deployments) ClientBase(org.jboss.pnc.client.ClientBase) BuildRef(org.jboss.pnc.dto.BuildRef) EnterpriseArchive(org.jboss.shrinkwrap.api.spec.EnterpriseArchive) BASE_REST_PATH(org.jboss.pnc.integration.setup.RestClientConfiguration.BASE_REST_PATH) Set(java.util.Set) MAX_PAGE_SIZE(org.jboss.pnc.rest.configuration.Constants.MAX_PAGE_SIZE) Category(org.junit.experimental.categories.Category) Instant(java.time.Instant) BuildStatus(org.jboss.pnc.enums.BuildStatus) Collectors(java.util.stream.Collectors) List(java.util.List) Response(javax.ws.rs.core.Response) ApacheHttpClient43EngineWithRetry(org.jboss.pnc.client.ApacheHttpClient43EngineWithRetry) ResteasyClient(org.jboss.resteasy.client.jaxrs.ResteasyClient) NotAuthorizedException(javax.ws.rs.NotAuthorizedException) Optional(java.util.Optional) RestAssured.given(io.restassured.RestAssured.given) BeforeClass(org.junit.BeforeClass) BuildClient(org.jboss.pnc.client.BuildClient) Credentials(org.jboss.pnc.integration.setup.Credentials) BuildPushParameters(org.jboss.pnc.dto.requests.BuildPushParameters) RunWith(org.junit.runner.RunWith) ArtifactQuality(org.jboss.pnc.enums.ArtifactQuality) RunAsClient(org.jboss.arquillian.container.test.api.RunAsClient) RemoteCollection(org.jboss.pnc.client.RemoteCollection) ArrayList(java.util.ArrayList) ContainerTest(org.jboss.pnc.test.category.ContainerTest) HashSet(java.util.HashSet) ClientException(org.jboss.pnc.client.ClientException) Configuration(org.jboss.pnc.client.Configuration) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) Attributes(org.jboss.pnc.constants.Attributes) Status(javax.ws.rs.core.Response.Status) BuildsFilterParameters(org.jboss.pnc.rest.api.parameters.BuildsFilterParameters) Logger(org.slf4j.Logger) ForbiddenException(javax.ws.rs.ForbiddenException) Iterator(java.util.Iterator) IoUtils(org.jboss.pnc.common.util.IoUtils) DatabaseDataInitializer(org.jboss.pnc.demo.data.DatabaseDataInitializer) Test(org.junit.Test) IOException(java.io.IOException) InSequence(org.jboss.arquillian.junit.InSequence) Artifact(org.jboss.pnc.dto.Artifact) Field(java.lang.reflect.Field) RestClientConfiguration(org.jboss.pnc.integration.setup.RestClientConfiguration) Assertions.entry(org.assertj.core.api.Assertions.entry) Build(org.jboss.pnc.dto.Build) Deployment(org.jboss.arquillian.container.test.api.Deployment) ArtifactClient(org.jboss.pnc.client.ArtifactClient) RemoteResourceException(org.jboss.pnc.client.RemoteResourceException) BuildConfigurationRevisionRef(org.jboss.pnc.dto.BuildConfigurationRevisionRef) BuildCategory(org.jboss.pnc.enums.BuildCategory) Collections(java.util.Collections) InputStream(java.io.InputStream) User(org.jboss.pnc.dto.User) Build(org.jboss.pnc.dto.Build) BuildClient(org.jboss.pnc.client.BuildClient) BuildConfigurationRevisionRef(org.jboss.pnc.dto.BuildConfigurationRevisionRef) ArrayList(java.util.ArrayList) BuildsFilterParameters(org.jboss.pnc.rest.api.parameters.BuildsFilterParameters) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Example 2 with BuildConfigurationRevisionRef

use of org.jboss.pnc.dto.BuildConfigurationRevisionRef in project pnc by project-ncl.

the class BuildBCRevisionFetcher method mapFromAuditedBuildConfig.

@BeforeMapping
public void mapFromAuditedBuildConfig(BuildRecord build, @MappingTarget Build.Builder dtoBuilder) {
    Integer id = build.getBuildConfigurationId();
    Integer revision = build.getBuildConfigurationRev();
    // If somebody before us already set the BCA we don't need to query it from DB again
    BuildConfigurationAudited bca = build.getBuildConfigurationAudited();
    if (bca == null) {
        bca = bcAuditedRepository.queryById(new IdRev(id, revision));
    }
    BuildConfigurationRevisionRef bcRevision = bcRevisionMapper.toRef(bca);
    ProjectRef project = projectMapper.toRef(bca.getProject());
    Environment environment = environmentMapper.toRef(bca.getBuildEnvironment());
    SCMRepository scmRepository = scmRepositoryMapper.toRef(bca.getRepositoryConfiguration());
    dtoBuilder.buildConfigRevision(bcRevision);
    dtoBuilder.project(project);
    dtoBuilder.environment(environment);
    dtoBuilder.scmRepository(scmRepository);
}
Also used : BuildConfigurationAudited(org.jboss.pnc.model.BuildConfigurationAudited) BuildConfigurationRevisionRef(org.jboss.pnc.dto.BuildConfigurationRevisionRef) Environment(org.jboss.pnc.dto.Environment) IdRev(org.jboss.pnc.model.IdRev) ProjectRef(org.jboss.pnc.dto.ProjectRef) SCMRepository(org.jboss.pnc.dto.SCMRepository) BeforeMapping(org.mapstruct.BeforeMapping)

Example 3 with BuildConfigurationRevisionRef

use of org.jboss.pnc.dto.BuildConfigurationRevisionRef in project pnc by project-ncl.

the class BuildTriggererImpl method loadAuditedsFromDB.

private Map<Integer, BuildConfigurationAudited> loadAuditedsFromDB(BuildConfigurationSet buildConfigurationSet, List<BuildConfigurationRevisionRef> buildConfigurationAuditedRests) throws InvalidEntityException {
    Map<Integer, BuildConfigurationAudited> buildConfigurationAuditedsMap = new HashMap<>();
    Set<IdRev> buildConfigurationAuditedRevs = nullableStreamOf(buildConfigurationAuditedRests).map(bcrRef -> new IdRev(Integer.valueOf(bcrRef.getId()), bcrRef.getRev())).collect(Collectors.toSet());
    if (!buildConfigurationAuditedRevs.isEmpty()) {
        Map<IdRev, BuildConfigurationAudited> buildConfigurationsAuditedMap = buildConfigurationAuditedRepository.queryById(buildConfigurationAuditedRevs);
        for (BuildConfigurationRevisionRef bc : buildConfigurationAuditedRests) {
            BuildConfigurationAudited buildConfigurationAudited = buildConfigurationsAuditedMap.get(new IdRev(Integer.valueOf(bc.getId()), bc.getRev()));
            Preconditions.checkArgument(buildConfigurationAudited != null, "Can't find Build Configuration with id=" + bc.getId() + ", rev=" + bc.getRev());
            buildConfigurationAudited = hibernateLazyInitializer.initializeBuildConfigurationAuditedBeforeTriggeringIt(buildConfigurationAudited);
            if (!buildConfigurationSet.getBuildConfigurations().contains(buildConfigurationAudited.getBuildConfiguration())) {
                throw new InvalidEntityException("BuildConfigurationSet " + buildConfigurationSet + " doesn't contain this BuildConfigurationAudited entity " + buildConfigurationAudited);
            }
            buildConfigurationAuditedsMap.put(buildConfigurationAudited.getId(), buildConfigurationAudited);
        }
    }
    return buildConfigurationAuditedsMap;
}
Also used : BuildOptions(org.jboss.pnc.spi.BuildOptions) BuildConfiguration(org.jboss.pnc.model.BuildConfiguration) BuildStatusNotifications(org.jboss.pnc.coordinator.notifications.buildTask.BuildStatusNotifications) HibernateLazyInitializer(org.jboss.pnc.facade.util.HibernateLazyInitializer) BuildConfigurationSetRepository(org.jboss.pnc.spi.datastore.repositories.BuildConfigurationSetRepository) LoggerFactory(org.slf4j.LoggerFactory) BuildConfigurationSet(org.jboss.pnc.model.BuildConfigurationSet) BuildConfigurationAuditedRepository(org.jboss.pnc.spi.datastore.repositories.BuildConfigurationAuditedRepository) BuildSetStatusNotifications(org.jboss.pnc.coordinator.notifications.buildSetTask.BuildSetStatusNotifications) HashMap(java.util.HashMap) BuildTask(org.jboss.pnc.spi.coordinator.BuildTask) OptionalInt(java.util.OptionalInt) BuildConfigurationAudited(org.jboss.pnc.model.BuildConfigurationAudited) BuildMapper(org.jboss.pnc.mapper.api.BuildMapper) Inject(javax.inject.Inject) UserService(org.jboss.pnc.facade.util.UserService) Map(java.util.Map) BuildSetTask(org.jboss.pnc.spi.coordinator.BuildSetTask) BuildTriggerer(org.jboss.pnc.facade.BuildTriggerer) BuildConfigurationRepository(org.jboss.pnc.spi.datastore.repositories.BuildConfigurationRepository) BuildConflictException(org.jboss.pnc.spi.exception.BuildConflictException) Stateless(javax.ejb.Stateless) Logger(org.slf4j.Logger) BuildTaskContext(org.jboss.pnc.common.logging.BuildTaskContext) BuildCoordinator(org.jboss.pnc.spi.coordinator.BuildCoordinator) Collection(java.util.Collection) Set(java.util.Set) Collectors(java.util.stream.Collectors) IdRev(org.jboss.pnc.model.IdRev) List(java.util.List) GenericSettingProvider(org.jboss.pnc.facade.providers.GenericSettingProvider) InvalidEntityException(org.jboss.pnc.facade.validation.InvalidEntityException) CoreException(org.jboss.pnc.spi.exception.CoreException) StreamHelper.nullableStreamOf(org.jboss.pnc.common.util.StreamHelper.nullableStreamOf) GroupBuildRequest(org.jboss.pnc.dto.requests.GroupBuildRequest) BuildConfigurationRevisionRef(org.jboss.pnc.dto.BuildConfigurationRevisionRef) Optional(java.util.Optional) Preconditions(com.google.common.base.Preconditions) Collections(java.util.Collections) BuildConfigurationAudited(org.jboss.pnc.model.BuildConfigurationAudited) HashMap(java.util.HashMap) BuildConfigurationRevisionRef(org.jboss.pnc.dto.BuildConfigurationRevisionRef) IdRev(org.jboss.pnc.model.IdRev) InvalidEntityException(org.jboss.pnc.facade.validation.InvalidEntityException)

Example 4 with BuildConfigurationRevisionRef

use of org.jboss.pnc.dto.BuildConfigurationRevisionRef in project pnc by project-ncl.

the class BuildTest method shouldTriggerGroupBuildWithBCInRevisionAndFinishWithoutProblems.

@Test
public void shouldTriggerGroupBuildWithBCInRevisionAndFinishWithoutProblems() throws ClientException {
    // given
    GroupConfiguration groupConfiguration = groupConfigurationClient.getAll().iterator().next();
    assertThat(groupConfiguration.getBuildConfigs()).isNotEmpty();
    List<BuildConfigurationRevisionRef> buildConfigurationRevisions = new ArrayList<>();
    BuildConfigurationRevision buildConfigurationRevision = BuildConfigurationRevision.builder().id(groupConfiguration.getBuildConfigs().keySet().iterator().next()).rev(1).name(groupConfiguration.getName()).build();
    buildConfigurationRevisions.add(buildConfigurationRevision);
    GroupBuildRequest groupConfigWithAuditedBCsRest = GroupBuildRequest.builder().buildConfigurationRevisions(buildConfigurationRevisions).build();
    GroupBuildParameters groupBuildParameters = new GroupBuildParameters();
    groupBuildParameters.setRebuildMode(RebuildMode.FORCE);
    // when
    GroupBuild groupBuild = groupConfigurationClient.trigger(groupConfiguration.getId(), groupBuildParameters, groupConfigWithAuditedBCsRest);
    // then
    assertThat(groupBuild).isNotNull().extracting("id").isNotNull().isNotEqualTo("");
    EnumSet<BuildStatus> isIn = EnumSet.of(BuildStatus.SUCCESS);
    EnumSet<BuildStatus> isNotIn = EnumSet.of(BuildStatus.REJECTED);
    ResponseUtils.waitSynchronouslyFor(() -> groupBuildToFinish(groupBuild.getId(), isIn, isNotIn), 15, TimeUnit.SECONDS);
}
Also used : GroupBuildRequest(org.jboss.pnc.dto.requests.GroupBuildRequest) GroupBuild(org.jboss.pnc.dto.GroupBuild) BuildConfigurationRevisionRef(org.jboss.pnc.dto.BuildConfigurationRevisionRef) ArrayList(java.util.ArrayList) BuildConfigurationRevision(org.jboss.pnc.dto.BuildConfigurationRevision) BuildStatus(org.jboss.pnc.enums.BuildStatus) GroupBuildParameters(org.jboss.pnc.rest.api.parameters.GroupBuildParameters) GroupConfiguration(org.jboss.pnc.dto.GroupConfiguration) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Example 5 with BuildConfigurationRevisionRef

use of org.jboss.pnc.dto.BuildConfigurationRevisionRef in project pnc by project-ncl.

the class BuildStatusChangedTest method getBuild.

private Build getBuild() {
    ProjectRef projectRef = ProjectRef.refBuilder().id("1").name("A").description("desc").projectUrl("url1").issueTrackerUrl("url2").build();
    SCMRepository scmRepository = SCMRepository.builder().id("1").internalUrl("url1").externalUrl("url2").preBuildSyncEnabled(true).build();
    Environment buildEnvironment = Environment.builder().id("1").name("jdk8").description("desc").systemImageRepositoryUrl("url").systemImageId("11").systemImageType(SystemImageType.DOCKER_IMAGE).deprecated(true).build();
    User user = User.builder().id("1").username("user").build();
    BuildConfigurationRevisionRef buildConfigurationRevisionRef = BuildConfigurationRevisionRef.refBuilder().id("1").rev(1).name("name").buildScript("true").scmRevision("awqs21").build();
    return Build.builder().project(projectRef).scmRepository(scmRepository).environment(buildEnvironment).user(user).buildConfigRevision(buildConfigurationRevisionRef).status(BuildStatus.BUILDING).buildContentId("build-42").temporaryBuild(true).build();
}
Also used : User(org.jboss.pnc.dto.User) BuildConfigurationRevisionRef(org.jboss.pnc.dto.BuildConfigurationRevisionRef) Environment(org.jboss.pnc.dto.Environment) ProjectRef(org.jboss.pnc.dto.ProjectRef) SCMRepository(org.jboss.pnc.dto.SCMRepository)

Aggregations

BuildConfigurationRevisionRef (org.jboss.pnc.dto.BuildConfigurationRevisionRef)7 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Optional (java.util.Optional)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 BuildConfigurationAudited (org.jboss.pnc.model.BuildConfigurationAudited)2 IdRev (org.jboss.pnc.model.IdRev)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 Preconditions (com.google.common.base.Preconditions)1 RestAssured.given (io.restassured.RestAssured.given)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Field (java.lang.reflect.Field)1 Instant (java.time.Instant)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1