Search in sources :

Example 1 with VariantsConfig

use of org.fakekoji.jobmanager.model.VariantsConfig 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 VariantsConfig

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

the class DataGenerator method initBuildsRoot.

public static void initBuildsRoot(final File buildsRoot) throws IOException {
    final Map<String, TaskVariant> buildVariants = getBuildVariants().keySet().stream().collect(Collectors.toMap(TaskVariant::getId, key -> key));
    long timeStamp = new Date().getTime();
    final Set<Platform> platforms = DataGenerator.getPlatforms();
    final Set<JDKVersion> jdkVersions = DataGenerator.getJDKVersions();
    for (final JDKProject jdkProject : DataGenerator.getJDKProjects()) {
        final JDKVersion jdkVersion = jdkVersions.stream().filter(v -> v.getId().equals(jdkProject.getProduct().getJdk())).findFirst().get();
        final File productDir = new File(buildsRoot, jdkVersion.getPackageNames().get(0));
        productDir.mkdirs();
        for (int versionIndex = 0; versionIndex < versions.length; versionIndex++) {
            final String version = versions[versionIndex];
            final File versionDir = new File(productDir, version);
            versionDir.mkdirs();
            for (int releaseIndex = 0; releaseIndex < releases.length; releaseIndex++) {
                final String release = releases[releaseIndex];
                final String releaseName = release + '.' + jdkProject.getId();
                final File releaseDir = new File(versionDir, releaseName);
                releaseDir.mkdirs();
                final File dataDir = new File(releaseDir, "data");
                dataDir.mkdirs();
                final File logsDir = new File(dataDir, "logs");
                logsDir.mkdirs();
                final String baseName = jdkVersion.getPackageNames().get(0) + '-' + version + '-' + releaseName + '.';
                final File srcDir = new File(releaseDir, JenkinsJobTemplateBuilder.SOURCES);
                srcDir.mkdirs();
                final String srcName = baseName + JenkinsJobTemplateBuilder.SOURCES + SUFFIX;
                final File srcFile = new File(srcDir, srcName);
                Files.write(srcFile.toPath(), srcName.getBytes());
                if (!srcFile.setLastModified(timeStamp += 60000)) {
                    throw new RuntimeException("Failed to set lastModified of file " + srcFile.getAbsolutePath());
                }
                for (final PlatformConfig platformConfig : jdkProject.getJobConfiguration().getPlatforms()) {
                    for (final TaskConfig buildTaskConfig : platformConfig.getTasks()) {
                        for (final VariantsConfig variantsConfig : buildTaskConfig.getVariants()) {
                            final Platform platform = platforms.stream().filter(p -> p.getId().equals(platformConfig.getId())).findFirst().get();
                            final String archName = variantsConfig.getMap().entrySet().stream().map(entry -> new Tuple<>(buildVariants.get(entry.getKey()), entry.getValue())).sorted(Comparator.comparing(tuple -> tuple.x)).map(tuple -> tuple.y).collect(Collectors.joining(".")) + '.' + platform.getId();
                            final File platformDir = new File(releaseDir, archName);
                            final String archiveFileName = baseName + archName + SUFFIX;
                            if (!notBuilt.contains(archiveFileName)) {
                                final File archiveFile = new File(platformDir, archiveFileName);
                                platformDir.mkdirs();
                                final File archiveLogsDir = new File(logsDir, archName);
                                archiveLogsDir.mkdirs();
                                final File log = new File(archiveLogsDir, "log");
                                log.createNewFile();
                                Files.write(archiveFile.toPath(), archiveFileName.getBytes());
                                if (!archiveFile.setLastModified(timeStamp += 60000)) {
                                    throw new RuntimeException("Failed to set lastModified of file " + archiveFile.getAbsolutePath());
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : Arrays(java.util.Arrays) URL(java.net.URL) Date(java.util.Date) JDKTestProject(org.fakekoji.jobmanager.model.JDKTestProject) SummaryReportRunner(org.fakekoji.core.utils.matrix.SummaryReportRunner) Map(java.util.Map) StorageException(org.fakekoji.storage.StorageException) BuildJob(org.fakekoji.jobmanager.model.BuildJob) JavaServerConstants(org.fakekoji.xmlrpc.server.JavaServerConstants) Project(org.fakekoji.jobmanager.model.Project) JOB_NAME_SHORTENED(org.fakekoji.jobmanager.JenkinsJobTemplateBuilder.JOB_NAME_SHORTENED) VariantsConfig(org.fakekoji.jobmanager.model.VariantsConfig) Set(java.util.Set) BuildPlatformConfig(org.fakekoji.jobmanager.model.BuildPlatformConfig) JDKProject(org.fakekoji.jobmanager.model.JDKProject) Collectors(java.util.stream.Collectors) TaskVariantValue(org.fakekoji.model.TaskVariantValue) List(java.util.List) Stream(java.util.stream.Stream) DESTROY_SCRIPT_NAME(org.fakekoji.jobmanager.JenkinsJobTemplateBuilder.DESTROY_SCRIPT_NAME) PullJob(org.fakekoji.jobmanager.model.PullJob) Result(org.fakekoji.functional.Result) TaskVariant(org.fakekoji.model.TaskVariant) Optional(java.util.Optional) JDKVersion(org.fakekoji.model.JDKVersion) Platform(org.fakekoji.model.Platform) Tuple(org.fakekoji.functional.Tuple) Product(org.fakekoji.jobmanager.model.Product) Task(org.fakekoji.model.Task) Job(org.fakekoji.jobmanager.model.Job) TaskConfig(org.fakekoji.jobmanager.model.TaskConfig) PlatformConfig(org.fakekoji.jobmanager.model.PlatformConfig) HashMap(java.util.HashMap) OToolVariable(org.fakekoji.model.OToolVariable) ArrayList(java.util.ArrayList) JobConfiguration(org.fakekoji.jobmanager.model.JobConfiguration) HashSet(java.util.HashSet) ConfigManager(org.fakekoji.jobmanager.ConfigManager) TestJobConfiguration(org.fakekoji.jobmanager.model.TestJobConfiguration) ManagementException(org.fakekoji.jobmanager.ManagementException) MalformedURLException(java.net.MalformedURLException) Files(java.nio.file.Files) JenkinsJobTemplateBuilder(org.fakekoji.jobmanager.JenkinsJobTemplateBuilder) IOException(java.io.IOException) BuildProvider(org.fakekoji.model.BuildProvider) File(java.io.File) TestJob(org.fakekoji.jobmanager.model.TestJob) Paths(java.nio.file.Paths) Comparator(java.util.Comparator) JENKINS(org.fakekoji.jobmanager.JenkinsJobTemplateBuilder.JENKINS) Collections(java.util.Collections) TemporaryFolder(org.junit.rules.TemporaryFolder) AccessibleSettings(org.fakekoji.core.AccessibleSettings) JDKProject(org.fakekoji.jobmanager.model.JDKProject) Platform(org.fakekoji.model.Platform) JDKVersion(org.fakekoji.model.JDKVersion) TaskConfig(org.fakekoji.jobmanager.model.TaskConfig) Date(java.util.Date) TaskVariant(org.fakekoji.model.TaskVariant) BuildPlatformConfig(org.fakekoji.jobmanager.model.BuildPlatformConfig) PlatformConfig(org.fakekoji.jobmanager.model.PlatformConfig) VariantsConfig(org.fakekoji.jobmanager.model.VariantsConfig) File(java.io.File) Tuple(org.fakekoji.functional.Tuple)

Example 3 with VariantsConfig

use of org.fakekoji.jobmanager.model.VariantsConfig 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)3 BuildPlatformConfig (org.fakekoji.jobmanager.model.BuildPlatformConfig)3 JDKTestProject (org.fakekoji.jobmanager.model.JDKTestProject)3 PlatformConfig (org.fakekoji.jobmanager.model.PlatformConfig)3 TaskConfig (org.fakekoji.jobmanager.model.TaskConfig)3 TestJob (org.fakekoji.jobmanager.model.TestJob)3 TestJobConfiguration (org.fakekoji.jobmanager.model.TestJobConfiguration)3 VariantsConfig (org.fakekoji.jobmanager.model.VariantsConfig)3 Platform (org.fakekoji.model.Platform)3 Task (org.fakekoji.model.Task)3 List (java.util.List)2 Map (java.util.Map)2 Optional (java.util.Optional)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 Result (org.fakekoji.functional.Result)2 BuildJob (org.fakekoji.jobmanager.model.BuildJob)2 JDKProject (org.fakekoji.jobmanager.model.JDKProject)2 File (java.io.File)1 IOException (java.io.IOException)1