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