Search in sources :

Example 16 with SCMRepository

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

the class BuildConfigurationProviderImpl method createWithScm.

@Override
public BuildConfigCreationResponse createWithScm(BuildConfigWithSCMRequest request) {
    ValidationBuilder.validateObject(request, WhenCreatingNew.class).validateNotEmptyArgument().validateAnnotations();
    BuildConfiguration buildConfiguration = request.getBuildConfig();
    validateBeforeSaving(buildConfiguration.toBuilder().scmRepository(FAKE_REPOSITORY).build());
    Long buildConfigurationId = sequenceHandlerRepository.getNextID(org.jboss.pnc.model.BuildConfiguration.SEQUENCE_NAME);
    MDCUtils.addProcessContext(buildConfigurationId.toString());
    BuildConfiguration newBuildConfigurationWithId = buildConfiguration.toBuilder().id(buildConfigurationId.toString()).build();
    RepositoryCreationResponse rcResponse = scmRepositoryProvider.createSCMRepository(request.getScmUrl(), request.getBuildConfig().getScmRevision(), request.getPreBuildSyncEnabled(), JobNotificationType.BUILD_CONFIG_CREATION, // consumer is deprecated with new stateless approach
    MDCWrappers.wrap(event -> {
        createBuildConfigurationWithRepository(event.getTaskId() == null ? null : event.getTaskId().toString(), event.getRepositoryId(), newBuildConfigurationWithId);
    }), Optional.of(newBuildConfigurationWithId));
    BuildConfigCreationResponse response;
    if (rcResponse.getTaskId() == null) {
        // scm is internal, not running a RepositoryCreationTask.
        // onRCCreationSuccess already called with id = rcResponse.getRepository().getId()
        org.jboss.pnc.model.BuildConfiguration buildConfigurationFromDB = repository.queryByPredicates(withName(newBuildConfigurationWithId.getName()), isNotArchived());
        response = new BuildConfigCreationResponse(mapper.toDTO(buildConfigurationFromDB));
    } else {
        response = new BuildConfigCreationResponse(rcResponse.getTaskId().toString());
    }
    MDCUtils.removeProcessContext();
    return response;
}
Also used : BuildConfiguration(org.jboss.pnc.dto.BuildConfiguration) BuildConfigurationPredicates.withDependencyConfiguration(org.jboss.pnc.spi.datastore.predicates.BuildConfigurationPredicates.withDependencyConfiguration) Notifier(org.jboss.pnc.spi.notifications.Notifier) Date(java.util.Date) BuildConfigurationSetRepository(org.jboss.pnc.spi.datastore.repositories.BuildConfigurationSetRepository) LoggerFactory(org.slf4j.LoggerFactory) BuildConfigurationAuditedRepository(org.jboss.pnc.spi.datastore.repositories.BuildConfigurationAuditedRepository) BuildConfigurationPredicates.withScmRepositoryId(org.jboss.pnc.spi.datastore.predicates.BuildConfigurationPredicates.withScmRepositoryId) MDCUtils(org.jboss.pnc.common.logging.MDCUtils) BuildConfigurationMapper(org.jboss.pnc.mapper.api.BuildConfigurationMapper) BuildEnvironment(org.jboss.pnc.model.BuildEnvironment) BuildConfigurationAudited(org.jboss.pnc.model.BuildConfigurationAudited) EmptyEntityException(org.jboss.pnc.facade.validation.EmptyEntityException) RepositoryCreationResponse(org.jboss.pnc.dto.response.RepositoryCreationResponse) User(org.jboss.pnc.dto.User) UserService(org.jboss.pnc.facade.util.UserService) Map(java.util.Map) BuildConfigurationRevisionMapper(org.jboss.pnc.mapper.api.BuildConfigurationRevisionMapper) SCMRepositoryProvider(org.jboss.pnc.facade.providers.api.SCMRepositoryProvider) BuildConfigurationRevision(org.jboss.pnc.dto.BuildConfigurationRevision) BuildConfigurationRepository(org.jboss.pnc.spi.datastore.repositories.BuildConfigurationRepository) WhenCreatingNew(org.jboss.pnc.dto.validation.groups.WhenCreatingNew) BuildRef(org.jboss.pnc.dto.BuildRef) Stateless(javax.ejb.Stateless) PermitAll(javax.annotation.security.PermitAll) BuildCoordinator(org.jboss.pnc.spi.coordinator.BuildCoordinator) BuildProvider(org.jboss.pnc.facade.providers.api.BuildProvider) ValidationBuilder(org.jboss.pnc.facade.validation.ValidationBuilder) Set(java.util.Set) RepositoryViolationException(org.jboss.pnc.facade.validation.RepositoryViolationException) Collectors(java.util.stream.Collectors) BuildConfigCreationResponse(org.jboss.pnc.dto.response.BuildConfigCreationResponse) IdRev(org.jboss.pnc.model.IdRev) BuildConfigurationPredicates.withDependantConfiguration(org.jboss.pnc.spi.datastore.predicates.BuildConfigurationPredicates.withDependantConfiguration) Objects(java.util.Objects) SequenceHandlerRepository(org.jboss.pnc.spi.datastore.repositories.SequenceHandlerRepository) List(java.util.List) ConflictedEntryValidator(org.jboss.pnc.facade.validation.ConflictedEntryValidator) RepositoryConfigurationRepository(org.jboss.pnc.spi.datastore.repositories.RepositoryConfigurationRepository) ConflictedEntryException(org.jboss.pnc.facade.validation.ConflictedEntryException) BuildConfigurationPredicates.isNotArchived(org.jboss.pnc.spi.datastore.predicates.BuildConfigurationPredicates.isNotArchived) Optional(java.util.Optional) BuildConfigurationPredicates.withProductVersionId(org.jboss.pnc.spi.datastore.predicates.BuildConfigurationPredicates.withProductVersionId) BuildConfigWithSCMRequest(org.jboss.pnc.dto.requests.BuildConfigWithSCMRequest) ProjectRepository(org.jboss.pnc.spi.datastore.repositories.ProjectRepository) BuildConfigurationCreation(org.jboss.pnc.dto.notification.BuildConfigurationCreation) JobNotificationType(org.jboss.pnc.enums.JobNotificationType) BuildConfigurationSet(org.jboss.pnc.model.BuildConfigurationSet) BuildTask(org.jboss.pnc.spi.coordinator.BuildTask) BuildEnvironmentRepository(org.jboss.pnc.spi.datastore.repositories.BuildEnvironmentRepository) BuildMapper(org.jboss.pnc.mapper.api.BuildMapper) ArrayList(java.util.ArrayList) BuildConfigurationRef(org.jboss.pnc.dto.BuildConfigurationRef) BuildRecordRepository(org.jboss.pnc.spi.datastore.repositories.BuildRecordRepository) Inject(javax.inject.Inject) HashSet(java.util.HashSet) UserMapper(org.jboss.pnc.mapper.api.UserMapper) SCMRepositoryMapper(org.jboss.pnc.mapper.api.SCMRepositoryMapper) DTOValidationException(org.jboss.pnc.facade.validation.DTOValidationException) BuildConfigurationProvider(org.jboss.pnc.facade.providers.api.BuildConfigurationProvider) ProductVersionRepository(org.jboss.pnc.spi.datastore.repositories.ProductVersionRepository) WhenUpdating(org.jboss.pnc.dto.validation.groups.WhenUpdating) Logger(org.slf4j.Logger) RepositoryConfiguration(org.jboss.pnc.model.RepositoryConfiguration) BuildRecord(org.jboss.pnc.model.BuildRecord) BuildConfigurationPredicates.withProjectId(org.jboss.pnc.spi.datastore.predicates.BuildConfigurationPredicates.withProjectId) Page(org.jboss.pnc.dto.response.Page) Build(org.jboss.pnc.dto.Build) BuildConfiguration(org.jboss.pnc.dto.BuildConfiguration) InvalidEntityException(org.jboss.pnc.facade.validation.InvalidEntityException) BuildConfigurationWithLatestBuild(org.jboss.pnc.dto.BuildConfigurationWithLatestBuild) SCMRepository(org.jboss.pnc.dto.SCMRepository) StreamHelper.nullableStreamOf(org.jboss.pnc.common.util.StreamHelper.nullableStreamOf) MDCWrappers(org.jboss.pnc.common.concurrent.MDCWrappers) Comparator(java.util.Comparator) BuildConfigurationPredicates.withName(org.jboss.pnc.spi.datastore.predicates.BuildConfigurationPredicates.withName) Collections(java.util.Collections) BuildConfigurationPredicates.withBuildConfigurationSetId(org.jboss.pnc.spi.datastore.predicates.BuildConfigurationPredicates.withBuildConfigurationSetId) BuildConfigCreationResponse(org.jboss.pnc.dto.response.BuildConfigCreationResponse) RepositoryCreationResponse(org.jboss.pnc.dto.response.RepositoryCreationResponse)

Example 17 with SCMRepository

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

the class PncEntitiesImporter method generatePncBuildConfig.

/**
 * @param buildConfig PiG buildconfig to generate
 * @param existing if present, we'll use it as the buildconfig to modify if null: we'll use a fresh buildconfig
 *        object
 *
 * @return BuildConfiguration generated
 */
private BuildConfiguration generatePncBuildConfig(BuildConfig buildConfig, BuildConfiguration existing) {
    ProjectRef project = getOrGenerateProject(buildConfig.getProject());
    SCMRepository repository = getOrGenerateRepository(buildConfig);
    Environment environment = Environment.builder().id(buildConfig.getEnvironmentId()).build();
    BuildConfiguration.Builder builder = BuildConfiguration.builder();
    if (existing != null) {
        builder = existing.toBuilder();
    }
    return builder.productVersion(version).parameters(buildConfig.getGenericParameters(null, false)).name(buildConfig.getName()).project(project).environment(environment).scmRepository(repository).scmRevision(buildConfig.getScmRevision()).buildScript(buildConfig.getBuildScript()).buildType(BuildType.valueOf(buildConfig.getBuildType())).brewPullActive(buildConfig.getBrewPullActive()).build();
}
Also used : BuildConfiguration(org.jboss.pnc.dto.BuildConfiguration) Environment(org.jboss.pnc.dto.Environment) ProjectRef(org.jboss.pnc.dto.ProjectRef) SCMRepository(org.jboss.pnc.dto.SCMRepository)

Example 18 with SCMRepository

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

the class PigTest method shouldCreateProduct.

@Test
@Order(1)
void shouldCreateProduct() throws IOException {
    final Path configFile = CONFIG_LOCATION;
    replaceSuffixInConfigFile(configFile.resolve("build-config.yaml"));
    final Product product = Product.builder().id(UNIVERSAL_ID).name(PRODUCT_NAME).abbreviation(PRODUCT_ABBREVIATION).build();
    final ProductVersion productVersion = ProductVersion.builder().id(UNIVERSAL_ID).version(VERSION).product(product).build();
    final ProductMilestone productMilestone = ProductMilestone.builder().id(UNIVERSAL_ID).productVersion(productVersion).version(MILESTONE).build();
    final ProductVersion productVersionWithCurrentMilestone = productVersion.toBuilder().currentProductMilestone(productMilestone).build();
    final GroupConfiguration groupConfig = GroupConfiguration.builder().id(UNIVERSAL_ID).name(GROUP_NAME).productVersion(productVersionWithCurrentMilestone).build();
    final Project project = Project.builder().id(UNIVERSAL_ID).name(PROJECT_NAME).build();
    final SCMRepository scmRepository = SCMRepository.builder().id(UNIVERSAL_ID).internalUrl(SCM_URL).preBuildSyncEnabled(true).build();
    final Environment environment = Environment.builder().id(UNIVERSAL_ID).deprecated(false).build();
    final BuildConfiguration buildConfig = BuildConfiguration.builder().id(UNIVERSAL_ID).name(BC_NAME).buildScript(BUILD_SCRIPT).scmRevision(SCM_REVISION).creationTime(Instant.now()).modificationTime(Instant.now()).scmRepository(scmRepository).environment(environment).project(project).productVersion(productVersionWithCurrentMilestone).build();
    final GroupConfiguration groupConfigWithBuildConfig = groupConfig.toBuilder().buildConfigs(Collections.singletonMap(UNIVERSAL_ID, buildConfig)).build();
    wmock.list(PRODUCT, new Page<Product>());
    wmock.creation(PRODUCT, product);
    wmock.list(PRODUCT_VERSIONS.apply(UNIVERSAL_ID), new Page<ProductVersion>());
    wmock.creation(PRODUCT_VERSION, productVersion);
    wmock.list(PRODUCT_VERSION_MILESTONES.apply(UNIVERSAL_ID), new Page<ProductMilestone>());
    wmock.creation(PRODUCT_MILESTONE, productMilestone);
    wmock.update(PRODUCT_VERSION, productVersion, productVersionWithCurrentMilestone);
    wmock.list(GROUP_CONFIG, new Page<GroupConfiguration>());
    wmock.creation(GROUP_CONFIG, groupConfig);
    wmock.list(GROUP_CONFIG_BUILD_CONFIGS.apply(UNIVERSAL_ID), new Page<BuildConfiguration>());
    wmock.list(BUILD_CONFIG, new Page<BuildConfiguration>());
    wmock.list(PROJECT, new Page<Project>());
    wmock.creation(PROJECT, project);
    wmock.list(SCM_REPOSITORY, new Page<SCMRepository>());
    wmock.creation(SCM_REPOSITORY_CREATE, RepositoryCreationResponse.builder().repository(scmRepository).build());
    wmock.get(ENVIRONMENT, environment);
    wmock.creation(BUILD_CONFIG, buildConfig);
    wmock.list(BUILD_CONFIG_DEPENDENCIES.apply(UNIVERSAL_ID), new Page<BuildConfiguration>());
    wmock.get(BUILD_CONFIG, buildConfig);
    wmock.creation(BUILD_CONFIG, buildConfig);
    wmock.scenario("add BC to GC").getEntity(GROUP_CONFIG, groupConfig).when().post(GROUP_CONFIG_BUILD_CONFIGS.apply(UNIVERSAL_ID)).then().getEntity(GROUP_CONFIG, groupConfigWithBuildConfig);
    ExecutionResult output = executeAndGetResult("pig", "configure", configFile.toString());
    assertThat(output.getOutput()).contains("name: \"Product Foobar " + SUFFIX + "\"");
}
Also used : Path(java.nio.file.Path) ProductMilestone(org.jboss.pnc.dto.ProductMilestone) Product(org.jboss.pnc.dto.Product) ExecutionResult(org.jboss.pnc.bacon.test.ExecutionResult) ProductVersion(org.jboss.pnc.dto.ProductVersion) GroupConfiguration(org.jboss.pnc.dto.GroupConfiguration) BuildConfiguration(org.jboss.pnc.dto.BuildConfiguration) Project(org.jboss.pnc.dto.Project) Environment(org.jboss.pnc.dto.Environment) SCMRepository(org.jboss.pnc.dto.SCMRepository) Order(org.junit.jupiter.api.Order) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) AbstractTest(org.jboss.pnc.bacon.test.AbstractTest) Test(org.junit.jupiter.api.Test)

Example 19 with SCMRepository

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

the class SecondLevelCacheStoreTest method prepareData.

/**
 * At first we need to create testing data and commit it.
 */
@Test
@InSequence(-2)
public void prepareData() throws Exception {
    EnvironmentClient client = new EnvironmentClient(RestClientConfiguration.asAnonymous());
    environmentId = client.getAll().iterator().next().getId();
    SCMRepositoryClient scmrc = new SCMRepositoryClient(RestClientConfiguration.asAnonymous());
    final Iterator<SCMRepository> scmrIt = scmrc.getAll(null, null).iterator();
    repositoryConfigurationBCId = scmrIt.next().getId();
    repositoryConfigurationDepBCId = scmrIt.next().getId();
    Project projectBC = createProjectAndValidateResults("https://github.com/project-ncl/dependency-analysis", null, "Dependency Analysis New", "Dependency Analysis - Analise project dependencies.");
    Project projectDepBC = createProjectAndValidateResults("https://github.com/project-ncl/pnc", null, "Project Newcastle Demo Project 1 New", "Example Project for Newcastle Demo");
    projectBCId = projectBC.getId();
    projectDepBCId = projectDepBC.getId();
    BuildConfiguration dependencyBC = createBuildConfigurationAndValidateResults(projectDepBCId, environmentId, repositoryConfigurationDepBCId, "pnc-1.0.0.DR1-new", UUID.randomUUID().toString());
    BuildConfiguration buildConfiguration = createBuildConfigurationAndValidateResults(projectBCId, environmentId, repositoryConfigurationBCId, "dependency-analysis-master-new", UUID.randomUUID().toString());
    dependencyBCId = dependencyBC.getId();
    buildConfigurationId = buildConfiguration.getId();
}
Also used : BuildConfiguration(org.jboss.pnc.dto.BuildConfiguration) SCMRepositoryClient(org.jboss.pnc.client.SCMRepositoryClient) Project(org.jboss.pnc.dto.Project) EnvironmentClient(org.jboss.pnc.client.EnvironmentClient) SCMRepository(org.jboss.pnc.dto.SCMRepository) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test) InSequence(org.jboss.arquillian.junit.InSequence)

Example 20 with SCMRepository

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

the class SCMRepositoryEndpointTest method testGetBuildConfigurationForARepository.

@Test
public void testGetBuildConfigurationForARepository() throws ClientException {
    BuildConfigurationClient buildConfigurationClient = new BuildConfigurationClient(RestClientConfiguration.asUser());
    SCMRepository scmRepository = repositoryClient.getAll(null, null).iterator().next();
    Iterator<BuildConfiguration> allConfigsIterator = buildConfigurationClient.getAll().iterator();
    BuildConfiguration buildConfiguration1 = allConfigsIterator.next().toBuilder().scmRepository(scmRepository).build();
    BuildConfiguration buildConfiguration2 = allConfigsIterator.next().toBuilder().scmRepository(scmRepository).build();
    buildConfigurationClient.update(buildConfiguration1.getId(), buildConfiguration1);
    buildConfigurationClient.update(buildConfiguration2.getId(), buildConfiguration2);
    RemoteCollection<BuildConfiguration> buildConfigs = repositoryClient.getBuildConfigs(scmRepository.getId());
    assertThat(buildConfigs).usingElementComparatorIgnoringFields("modificationTime", "creationUser", "modificationUser").contains(buildConfiguration1, buildConfiguration2).allSatisfy((bc -> scmRepository.equals(bc.getScmRepository())));
}
Also used : BuildConfiguration(org.jboss.pnc.dto.BuildConfiguration) Arquillian(org.jboss.arquillian.junit.Arquillian) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RunWith(org.junit.runner.RunWith) LoggerFactory(org.slf4j.LoggerFactory) RunAsClient(org.jboss.arquillian.container.test.api.RunAsClient) ClientErrorException(javax.ws.rs.ClientErrorException) RemoteCollection(org.jboss.pnc.client.RemoteCollection) CreateAndSyncSCMRequest(org.jboss.pnc.dto.requests.CreateAndSyncSCMRequest) ContainerTest(org.jboss.pnc.test.category.ContainerTest) ClientException(org.jboss.pnc.client.ClientException) RepositoryCreationResponse(org.jboss.pnc.dto.response.RepositoryCreationResponse) BuildConfigurationClient(org.jboss.pnc.client.BuildConfigurationClient) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) BadRequestException(javax.ws.rs.BadRequestException) Deployments(org.jboss.pnc.integration.setup.Deployments) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) EnterpriseArchive(org.jboss.shrinkwrap.api.spec.EnterpriseArchive) Test(org.junit.Test) Category(org.junit.experimental.categories.Category) RestClientConfiguration(org.jboss.pnc.integration.setup.RestClientConfiguration) SCMRepositoryClient(org.jboss.pnc.client.SCMRepositoryClient) BuildConfiguration(org.jboss.pnc.dto.BuildConfiguration) SCMRepository(org.jboss.pnc.dto.SCMRepository) Ignore(org.junit.Ignore) Deployment(org.jboss.arquillian.container.test.api.Deployment) Condition(org.assertj.core.api.Condition) RemoteResourceException(org.jboss.pnc.client.RemoteResourceException) BuildConfigurationClient(org.jboss.pnc.client.BuildConfigurationClient) SCMRepository(org.jboss.pnc.dto.SCMRepository) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Aggregations

SCMRepository (org.jboss.pnc.dto.SCMRepository)28 Test (org.junit.Test)17 ContainerTest (org.jboss.pnc.test.category.ContainerTest)9 BuildConfiguration (org.jboss.pnc.dto.BuildConfiguration)8 Environment (org.jboss.pnc.dto.Environment)5 ProjectRef (org.jboss.pnc.dto.ProjectRef)4 CreateAndSyncSCMRequest (org.jboss.pnc.dto.requests.CreateAndSyncSCMRequest)4 ClientErrorException (javax.ws.rs.ClientErrorException)3 SCMRepositoryClient (org.jboss.pnc.client.SCMRepositoryClient)3 RepositoryCreationResponse (org.jboss.pnc.dto.response.RepositoryCreationResponse)3 InvalidEntityException (org.jboss.pnc.facade.validation.InvalidEntityException)3 RepositoryConfiguration (org.jboss.pnc.model.RepositoryConfiguration)3 BuildConfigurationClient (org.jboss.pnc.client.BuildConfigurationClient)2 EnvironmentClient (org.jboss.pnc.client.EnvironmentClient)2 Project (org.jboss.pnc.dto.Project)2 BuildConfigurationCreation (org.jboss.pnc.dto.notification.BuildConfigurationCreation)2 ConflictedEntryException (org.jboss.pnc.facade.validation.ConflictedEntryException)2 DTOValidationException (org.jboss.pnc.facade.validation.DTOValidationException)2 EmptyEntityException (org.jboss.pnc.facade.validation.EmptyEntityException)2 RepositoryViolationException (org.jboss.pnc.facade.validation.RepositoryViolationException)2