Search in sources :

Example 86 with BuildConfiguration

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

the class RSQLPredicateProducerTest method testComparator.

@Test
public void testComparator() {
    Comparator<BuildConfiguration> comparator = producer.getComparator("=desc=id");
    BuildConfiguration foo = BuildConfiguration.builder().id("3").name("FooBC").build();
    BuildConfiguration bar = BuildConfiguration.builder().id("5").name("BarBC").build();
    BuildConfiguration baz = BuildConfiguration.builder().id("7").name("BazBC").build();
    List<BuildConfiguration> sorted = Arrays.asList(foo, bar, baz).stream().sorted(comparator).collect(Collectors.toList());
    assertEquals(3, sorted.size());
    assertEquals("BazBC", sorted.get(0).getName());
    assertEquals("BarBC", sorted.get(1).getName());
    assertEquals("FooBC", sorted.get(2).getName());
}
Also used : BuildConfiguration(org.jboss.pnc.dto.BuildConfiguration) Test(org.junit.Test)

Example 87 with BuildConfiguration

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

the class SCMRepositoryProviderImpl method startRCreationTask.

/**
 * @param externalURL
 * @param preBuildSyncEnabled
 * @param jobType
 * @param consumer
 * @param buildConfiguration required when repository is created as part of BC creation process
 * @return
 */
private Integer startRCreationTask(String externalURL, String revision, boolean preBuildSyncEnabled, JobNotificationType jobType, Consumer<RepositoryCreated> consumer, Optional<BuildConfiguration> buildConfiguration) {
    String userToken = userService.currentUserToken();
    org.jboss.pnc.bpm.model.RepositoryConfiguration repositoryConfiguration = org.jboss.pnc.bpm.model.RepositoryConfiguration.builder().externalUrl(externalURL).preBuildSyncEnabled(preBuildSyncEnabled).build();
    RepositoryCreationTask task;
    if (bpmConfig.isNewBpmForced() || userService.hasLoggedInUserRole(WORK_WITH_TECH_PREVIEW)) {
        RepositoryCreationProcess.RepositoryCreationProcessBuilder repositoryCreationProcess = RepositoryCreationProcess.builder().repositoryConfiguration(repositoryConfiguration).revision(revision);
        buildConfiguration.ifPresent(bc -> repositoryCreationProcess.buildConfiguration(bc));
        task = new RepositoryCreationTask(repositoryCreationProcess.build(), userToken);
        task.setTaskId(bpmManager.getNextTaskId());
        task.setGlobalConfig(globalConfig);
        task.setJsonEncodedProcessParameters(false);
        task.setJobType(jobType);
        RestConnector restConnector = new RestConnector(bpmConfig);
        try {
            Map<String, Object> processParameters = task.getExtendedProcessParameters();
            restConnector.startProcess(bpmConfig.getNewBcCreationProcessId(), processParameters, userToken);
        } catch (CoreException e) {
            throw new RuntimeException("Could not get process parameters: " + task, e);
        } catch (ProcessManagerException e) {
            throw new RuntimeException("Could not start BPM task using REST connector: " + task, e);
        }
    } else {
        // deprecated
        RepositoryCreationProcess repositoryCreationProcess = RepositoryCreationProcess.builder().repositoryConfiguration(repositoryConfiguration).revision(revision).build();
        task = new RepositoryCreationTask(repositoryCreationProcess, userToken);
        task.setJobType(jobType);
        Consumer<RepositoryCloneSuccess> successListener = event -> onRepoCloneSuccess(event.getData().getInternalUrl(), task.getTaskId(), consumer, jobType, externalURL, preBuildSyncEnabled);
        task.addListener(BpmEventType.RC_REPO_CLONE_SUCCESS, MDCWrappers.wrap(successListener));
        addErrorListeners(jobType, task);
        try {
            bpmManager.startTask(task);
        } catch (CoreException e) {
            throw new RuntimeException("Could not start BPM task: " + task, e);
        }
    }
    return task.getTaskId();
}
Also used : GlobalModuleGroup(org.jboss.pnc.common.json.GlobalModuleGroup) RepositoryCreationProcess(org.jboss.pnc.bpm.model.RepositoryCreationProcess) Notifier(org.jboss.pnc.spi.notifications.Notifier) LoggerFactory(org.slf4j.LoggerFactory) StringUtils(org.jboss.pnc.common.util.StringUtils) RepositoryCreationResponse(org.jboss.pnc.dto.response.RepositoryCreationResponse) UserService(org.jboss.pnc.facade.util.UserService) Map(java.util.Map) RepositoryCreationTask(org.jboss.pnc.bpm.task.RepositoryCreationTask) UrlUtils(org.jboss.pnc.common.util.UrlUtils) SCMRepositoryProvider(org.jboss.pnc.facade.providers.api.SCMRepositoryProvider) BpmEventType(org.jboss.pnc.bpm.BpmEventType) RepourClient(org.jboss.pnc.facade.util.RepourClient) INTERNAL_REPOSITORY_NAME(org.jboss.pnc.constants.Patterns.INTERNAL_REPOSITORY_NAME) SCM_REPOSITORY_CREATION(org.jboss.pnc.enums.JobNotificationType.SCM_REPOSITORY_CREATION) Stateless(javax.ejb.Stateless) PermitAll(javax.annotation.security.PermitAll) BpmStringMapNotificationRest(org.jboss.pnc.bpm.model.BpmStringMapNotificationRest) RepositoryCreationResult(org.jboss.pnc.dto.tasks.RepositoryCreationResult) PncConfigProvider(org.jboss.pnc.common.json.moduleprovider.PncConfigProvider) List(java.util.List) CoreException(org.jboss.pnc.spi.exception.CoreException) RepositoryConfigurationRepository(org.jboss.pnc.spi.datastore.repositories.RepositoryConfigurationRepository) ConflictedEntryException(org.jboss.pnc.facade.validation.ConflictedEntryException) Optional(java.util.Optional) ProcessManagerException(org.jboss.pnc.spi.exception.ProcessManagerException) Pattern(java.util.regex.Pattern) Predicate(org.jboss.pnc.spi.datastore.repositories.api.Predicate) RepositoryConfigurationPredicates(org.jboss.pnc.spi.datastore.predicates.RepositoryConfigurationPredicates) JobNotificationType(org.jboss.pnc.enums.JobNotificationType) RepositoryCloneSuccess(org.jboss.pnc.bpm.model.RepositoryCloneSuccess) Function(java.util.function.Function) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) ConfigurationParseException(org.jboss.pnc.common.json.ConfigurationParseException) SCMRepositoryMapper(org.jboss.pnc.mapper.api.SCMRepositoryMapper) BuildConfigurationProvider(org.jboss.pnc.facade.providers.api.BuildConfigurationProvider) SCMRepositoryCreationSuccess(org.jboss.pnc.dto.notification.SCMRepositoryCreationSuccess) BpmManager(org.jboss.pnc.bpm.BpmManager) WORK_WITH_TECH_PREVIEW(org.jboss.pnc.facade.providers.api.UserRoles.WORK_WITH_TECH_PREVIEW) RepositoryCreationFailure(org.jboss.pnc.dto.notification.RepositoryCreationFailure) Logger(org.slf4j.Logger) RepositoryConfiguration(org.jboss.pnc.model.RepositoryConfiguration) RestConnector(org.jboss.pnc.bpm.RestConnector) RepositoryConfigurationPredicates.withExactInternalScmRepoUrl(org.jboss.pnc.spi.datastore.predicates.RepositoryConfigurationPredicates.withExactInternalScmRepoUrl) Configuration(org.jboss.pnc.common.Configuration) ScmModuleConfig(org.jboss.pnc.common.json.moduleconfig.ScmModuleConfig) Page(org.jboss.pnc.dto.response.Page) Consumer(java.util.function.Consumer) BuildConfiguration(org.jboss.pnc.dto.BuildConfiguration) InvalidEntityException(org.jboss.pnc.facade.validation.InvalidEntityException) SCMRepository(org.jboss.pnc.dto.SCMRepository) MDCWrappers(org.jboss.pnc.common.concurrent.MDCWrappers) BpmModuleConfig(org.jboss.pnc.common.json.moduleconfig.BpmModuleConfig) RestConnector(org.jboss.pnc.bpm.RestConnector) RepositoryCreationProcess(org.jboss.pnc.bpm.model.RepositoryCreationProcess) RepositoryCloneSuccess(org.jboss.pnc.bpm.model.RepositoryCloneSuccess) CoreException(org.jboss.pnc.spi.exception.CoreException) ProcessManagerException(org.jboss.pnc.spi.exception.ProcessManagerException) RepositoryCreationTask(org.jboss.pnc.bpm.task.RepositoryCreationTask)

Example 88 with BuildConfiguration

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

the class BuildConfigurationPatchTest method shouldReplaceCollection.

@Test
public void shouldReplaceCollection() throws PatchBuilderException, IOException, JsonPatchException {
    BuildConfigurationRef dependency1 = BuildConfigurationRef.refBuilder().id("1").build();
    BuildConfigurationRef dependency2 = BuildConfigurationRef.refBuilder().id("2").build();
    BuildConfigurationRef dependency2a = BuildConfigurationRef.refBuilder().id("2").build();
    BuildConfigurationRef dependency3 = BuildConfigurationRef.refBuilder().id("3").build();
    BuildConfigurationRef dependency4 = BuildConfigurationRef.refBuilder().id("4").build();
    Map<String, BuildConfigurationRef> dependencies = new HashMap<>();
    dependencies.put(dependency1.getId(), dependency1);
    dependencies.put(dependency2.getId(), dependency2);
    BuildConfiguration buildConfiguration = BuildConfiguration.builder().id("1").dependencies(dependencies).build();
    Map<String, BuildConfigurationRef> newDependencies = new HashMap<>();
    newDependencies.put(dependency2a.getId(), dependency2a);
    newDependencies.put(dependency3.getId(), dependency3);
    newDependencies.put(dependency4.getId(), dependency4);
    String patchString = new BuildConfigurationPatchBuilder().replaceDependencies(newDependencies).getJsonPatch();
    BuildConfiguration updatedBuildConfiguration = applyPatch(buildConfiguration, patchString);
    Assertions.assertThat(updatedBuildConfiguration.getDependencies()).containsOnly(newDependencies.entrySet().toArray(new Map.Entry[3]));
}
Also used : BuildConfigurationRef(org.jboss.pnc.dto.BuildConfigurationRef) BuildConfiguration(org.jboss.pnc.dto.BuildConfiguration) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 89 with BuildConfiguration

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

the class BuildConfigurationPatchTest method shouldAddToMap.

@Test
public void shouldAddToMap() throws PatchBuilderException, IOException, JsonPatchException {
    Map<String, String> genericParameters = new HashMap<>();
    genericParameters.put("k", "v");
    BuildConfiguration buildConfiguration = BuildConfiguration.builder().id("1").parameters(genericParameters).build();
    Map<String, String> addParameters = Collections.singletonMap("k2", "v2");
    String patchString = new BuildConfigurationPatchBuilder().addParameters(addParameters).getJsonPatch();
    BuildConfiguration updatedBuildConfiguration = applyPatch(buildConfiguration, patchString);
    genericParameters.putAll(addParameters);
    Assertions.assertThat(updatedBuildConfiguration.getParameters()).contains(genericParameters.entrySet().toArray(new Map.Entry[2]));
}
Also used : BuildConfiguration(org.jboss.pnc.dto.BuildConfiguration) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 90 with BuildConfiguration

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

the class BuildConfigurationPatchTest method shouldAddToCollection.

@Test
public void shouldAddToCollection() throws PatchBuilderException, IOException, JsonPatchException {
    Map<String, BuildConfigurationRef> dependencies = new HashMap<>();
    BuildConfigurationRef dependency1 = BuildConfigurationRef.refBuilder().id("1").build();
    dependencies.put(dependency1.getId(), dependency1);
    BuildConfiguration buildConfiguration = BuildConfiguration.builder().id("1").dependencies(dependencies).build();
    Map<String, BuildConfigurationRef> addDependencies = new HashMap<>();
    BuildConfigurationRef dependency2 = BuildConfigurationRef.refBuilder().id("2").build();
    addDependencies.put(dependency2.getId(), dependency2);
    String patchString = new BuildConfigurationPatchBuilder().addDependencies(addDependencies).getJsonPatch();
    BuildConfiguration updatedBuildConfiguration = applyPatch(buildConfiguration, patchString);
    dependencies.putAll(addDependencies);
    Assertions.assertThat(updatedBuildConfiguration.getDependencies()).containsKeys(dependency1.getId(), dependency2.getId());
}
Also used : BuildConfigurationRef(org.jboss.pnc.dto.BuildConfigurationRef) BuildConfiguration(org.jboss.pnc.dto.BuildConfiguration) HashMap(java.util.HashMap) Test(org.junit.Test)

Aggregations

BuildConfiguration (org.jboss.pnc.dto.BuildConfiguration)90 Test (org.junit.Test)65 ContainerTest (org.jboss.pnc.test.category.ContainerTest)45 BuildConfigurationClient (org.jboss.pnc.client.BuildConfigurationClient)31 HashMap (java.util.HashMap)17 InSequence (org.jboss.arquillian.junit.InSequence)17 Build (org.jboss.pnc.dto.Build)13 GroupBuild (org.jboss.pnc.dto.GroupBuild)12 SCMRepository (org.jboss.pnc.dto.SCMRepository)10 Test (org.junit.jupiter.api.Test)10 BuildConfigurationRef (org.jboss.pnc.dto.BuildConfigurationRef)9 Instant (java.time.Instant)8 GroupConfiguration (org.jboss.pnc.dto.GroupConfiguration)7 BuildStatus (org.jboss.pnc.enums.BuildStatus)7 GroupConfigurationClient (org.jboss.pnc.client.GroupConfigurationClient)5 Logger (org.slf4j.Logger)5 LoggerFactory (org.slf4j.LoggerFactory)5 ArrayList (java.util.ArrayList)4 BuildConfigurationRevision (org.jboss.pnc.dto.BuildConfigurationRevision)4 HashSet (java.util.HashSet)3