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()));
});
}
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());
}
}
}
}
}
}
}
}
}
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()));
});
}
Aggregations