Search in sources :

Example 1 with BuildPlatformConfig

use of org.fakekoji.jobmanager.model.BuildPlatformConfig in project jenkins-scm-koji-plugin by judovana.

the class ReverseJDKProjectParser method parseJDKProjectJobs.

public Result<JDKProject, String> parseJDKProjectJobs(Set<Job> jobs) {
    final List<PullJob> pullJobs = jobs.stream().filter(j -> j instanceof PullJob).map(j -> (PullJob) j).collect(Collectors.toList());
    final Set<TaskJob> taskJobs = jobs.stream().filter(j -> j instanceof TaskJob).map(j -> (TaskJob) j).collect(Collectors.toSet());
    final Set<BuildJob> buildJobs = jobs.stream().filter(j -> j instanceof BuildJob).map(j -> (BuildJob) j).collect(Collectors.toSet());
    final Set<TestJob> testJobs = jobs.stream().filter(j -> j instanceof TestJob).map(j -> (TestJob) j).collect(Collectors.toSet());
    if (pullJobs.isEmpty()) {
        return Result.err("Error: pull job not found");
    }
    if (pullJobs.size() > 1) {
        return Result.err("Error: more than one pull job (" + pullJobs.size() + ")");
    }
    final PullJob pullJob = pullJobs.get(0);
    return validateJobs(taskJobs, getTaskJobValidator()).flatMap(projectRepresentingJob -> {
        final Set<PlatformConfig> buildPlatforms = new HashSet<>();
        for (final BuildJob buildJob : buildJobs) {
            final String platformProvider = buildJob.getPlatformProvider();
            final Platform buildPlatform = buildJob.getPlatform();
            final Map<String, String> buildVariants = variantsMapToStringMap(buildJob.getVariants());
            final Task buildTask = buildJob.getTask();
            final PlatformConfig buildPlatformConfig = findOrCreatePlatform(buildPlatforms, buildPlatform.getId(), platformProvider);
            final TaskConfig buildTaskConfig = findOrCreateTask(buildPlatformConfig.getTasks(), buildTask.getId());
            final VariantsConfig buildVariantsConfig;
            final Optional<VariantsConfig> bvOptional = findVariants(buildTaskConfig.getVariants(), buildVariants);
            if (bvOptional.isPresent()) {
                return Result.err("Duplicate build job: " + buildJob.getName());
            } else {
                buildVariantsConfig = new VariantsConfig(buildVariants, new HashSet<>());
                buildTaskConfig.getVariants().add(buildVariantsConfig);
            }
        }
        for (final TestJob testJob : testJobs) {
            final String platformProvider = testJob.getPlatformProvider();
            final String buildPlatformProvider = testJob.getBuildPlatformProvider();
            final Platform testPlatform = testJob.getPlatform();
            final Map<String, String> buildVariants = variantsMapToStringMap(testJob.getBuildVariants());
            final Task buildTask = testJob.getBuildTask();
            final Platform buildPlatform = testJob.getBuildPlatform();
            final Map<String, String> testVariants = variantsMapToStringMap(testJob.getVariants());
            final Task testTask = testJob.getTask();
            final PlatformConfig buildPlatformConfig;
            final TaskConfig buildTaskConfig;
            final VariantsConfig buildVariantsConfig;
            final Optional<PlatformConfig> buildPlatformConfigOptional = findPlatform(buildPlatforms, buildPlatform.getId(), buildPlatformProvider);
            if (buildPlatformConfigOptional.isPresent()) {
                buildPlatformConfig = buildPlatformConfigOptional.get();
            } else {
                return Result.err("Could not find build platform " + buildPlatform.getId() + " for job: " + testJob.getName());
            }
            final Optional<TaskConfig> buildTaskConfigOptional = findTask(buildPlatformConfig.getTasks(), buildTask.getId());
            if (buildTaskConfigOptional.isPresent()) {
                buildTaskConfig = buildTaskConfigOptional.get();
            } else {
                return Result.err("Could not find build task " + buildTask.getId() + " for job: " + testJob.getName());
            }
            final Optional<VariantsConfig> buildVariantsOptional = findVariants(buildTaskConfig.getVariants(), buildVariants);
            if (buildVariantsOptional.isPresent()) {
                buildVariantsConfig = buildVariantsOptional.get();
            } else {
                return Result.err("Could not find build variants for job: " + testJob.getName());
            }
            final PlatformConfig testPlatformConfig = findOrCreatePlatform(buildVariantsConfig.getPlatforms(), testPlatform.getId(), platformProvider);
            final TaskConfig testTaskConfig = findOrCreateTask(testPlatformConfig.getTasks(), testTask.getId());
            final Optional<VariantsConfig> testVariantsConfigOptional = findVariants(testTaskConfig.getVariants(), testVariants);
            if (testVariantsConfigOptional.isPresent()) {
                return Result.err("Duplicate test job: " + testJob.getName());
            } else {
                testTaskConfig.getVariants().add(new VariantsConfig(testVariants, new HashSet<>()));
            }
        }
        return Result.ok(new JDKProject(projectRepresentingJob.getProjectName(), projectRepresentingJob.getProduct(), pullJob.getRepoUrl(), projectRepresentingJob.getBuildProviders().stream().map(BuildProvider::getId).collect(Collectors.toSet()), new JobConfiguration(buildPlatforms), projectRepresentingJob.getProjectVariables()));
    });
}
Also used : Platform(org.fakekoji.model.Platform) Task(org.fakekoji.model.Task) Job(org.fakekoji.jobmanager.model.Job) TaskConfig(org.fakekoji.jobmanager.model.TaskConfig) PlatformConfig(org.fakekoji.jobmanager.model.PlatformConfig) JDKTestProject(org.fakekoji.jobmanager.model.JDKTestProject) Function(java.util.function.Function) Supplier(java.util.function.Supplier) TaskJob(org.fakekoji.jobmanager.model.TaskJob) JobConfiguration(org.fakekoji.jobmanager.model.JobConfiguration) HashSet(java.util.HashSet) Map(java.util.Map) BuildJob(org.fakekoji.jobmanager.model.BuildJob) Project(org.fakekoji.jobmanager.model.Project) TestJobConfiguration(org.fakekoji.jobmanager.model.TestJobConfiguration) VariantsConfig(org.fakekoji.jobmanager.model.VariantsConfig) Predicate(java.util.function.Predicate) Set(java.util.Set) BuildPlatformConfig(org.fakekoji.jobmanager.model.BuildPlatformConfig) JDKProject(org.fakekoji.jobmanager.model.JDKProject) Collectors(java.util.stream.Collectors) BuildProvider(org.fakekoji.model.BuildProvider) TaskVariantValue(org.fakekoji.model.TaskVariantValue) List(java.util.List) TestJob(org.fakekoji.jobmanager.model.TestJob) PullJob(org.fakekoji.jobmanager.model.PullJob) Result(org.fakekoji.functional.Result) TaskVariant(org.fakekoji.model.TaskVariant) Optional(java.util.Optional) JDKProject(org.fakekoji.jobmanager.model.JDKProject) Task(org.fakekoji.model.Task) TestJob(org.fakekoji.jobmanager.model.TestJob) Platform(org.fakekoji.model.Platform) PullJob(org.fakekoji.jobmanager.model.PullJob) TaskConfig(org.fakekoji.jobmanager.model.TaskConfig) TaskJob(org.fakekoji.jobmanager.model.TaskJob) PlatformConfig(org.fakekoji.jobmanager.model.PlatformConfig) BuildPlatformConfig(org.fakekoji.jobmanager.model.BuildPlatformConfig) VariantsConfig(org.fakekoji.jobmanager.model.VariantsConfig) BuildJob(org.fakekoji.jobmanager.model.BuildJob) JobConfiguration(org.fakekoji.jobmanager.model.JobConfiguration) TestJobConfiguration(org.fakekoji.jobmanager.model.TestJobConfiguration) HashSet(java.util.HashSet)

Example 2 with BuildPlatformConfig

use of org.fakekoji.jobmanager.model.BuildPlatformConfig in project jenkins-scm-koji-plugin by judovana.

the class ReverseJDKProjectParser method parseJDKTestProjectJobs.

public Result<JDKTestProject, String> parseJDKTestProjectJobs(Set<TestJob> jobs) {
    return validateJobs(jobs, getTestJobValidator()).flatMap(projectRepresentingJob -> {
        final Set<BuildPlatformConfig> buildPlatforms = new HashSet<>();
        for (final TestJob job : jobs) {
            final String platformProvider = job.getPlatformProvider();
            final Platform bp = job.getBuildPlatform();
            final Map<String, String> bv = variantsMapToStringMap(job.getBuildVariants());
            final Platform tp = job.getPlatform();
            final Task tt = job.getTask();
            final Map<String, String> tv = variantsMapToStringMap(job.getVariants());
            final VariantsConfig testVariants;
            final BuildPlatformConfig bpc = findOrCreatePlatform(buildPlatforms, bp.getId());
            final VariantsConfig buildVariants = findOrCreateVariants(bpc.getVariants(), bv);
            final PlatformConfig testPlatform = findOrCreatePlatform(buildVariants.getPlatforms(), tp.getId(), platformProvider);
            final TaskConfig task = findOrCreateTask(testPlatform.getTasks(), tt.getId());
            final Optional<VariantsConfig> tvOptional = findVariants(task.getVariants(), tv);
            if (tvOptional.isPresent()) {
                return Result.err("Duplicate job: " + job.getName());
            } else {
                testVariants = new VariantsConfig(tv);
                task.getVariants().add(testVariants);
            }
        }
        return Result.ok(new JDKTestProject(projectRepresentingJob.getProjectName(), projectRepresentingJob.getProduct(), projectRepresentingJob.getBuildProviders().stream().map(BuildProvider::getId).collect(Collectors.toSet()), projectRepresentingJob.getProjectSubpackageBlacklist(), projectRepresentingJob.getProjectSubpackageWhitelist(), new TestJobConfiguration(buildPlatforms), projectRepresentingJob.getProjectVariables()));
    });
}
Also used : Task(org.fakekoji.model.Task) TestJob(org.fakekoji.jobmanager.model.TestJob) Platform(org.fakekoji.model.Platform) BuildPlatformConfig(org.fakekoji.jobmanager.model.BuildPlatformConfig) TaskConfig(org.fakekoji.jobmanager.model.TaskConfig) TestJobConfiguration(org.fakekoji.jobmanager.model.TestJobConfiguration) PlatformConfig(org.fakekoji.jobmanager.model.PlatformConfig) BuildPlatformConfig(org.fakekoji.jobmanager.model.BuildPlatformConfig) VariantsConfig(org.fakekoji.jobmanager.model.VariantsConfig) JDKTestProject(org.fakekoji.jobmanager.model.JDKTestProject) HashSet(java.util.HashSet)

Aggregations

HashSet (java.util.HashSet)2 BuildPlatformConfig (org.fakekoji.jobmanager.model.BuildPlatformConfig)2 JDKTestProject (org.fakekoji.jobmanager.model.JDKTestProject)2 PlatformConfig (org.fakekoji.jobmanager.model.PlatformConfig)2 TaskConfig (org.fakekoji.jobmanager.model.TaskConfig)2 TestJob (org.fakekoji.jobmanager.model.TestJob)2 TestJobConfiguration (org.fakekoji.jobmanager.model.TestJobConfiguration)2 VariantsConfig (org.fakekoji.jobmanager.model.VariantsConfig)2 Platform (org.fakekoji.model.Platform)2 Task (org.fakekoji.model.Task)2 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Function (java.util.function.Function)1 Predicate (java.util.function.Predicate)1 Supplier (java.util.function.Supplier)1 Collectors (java.util.stream.Collectors)1 Result (org.fakekoji.functional.Result)1 BuildJob (org.fakekoji.jobmanager.model.BuildJob)1