use of org.fakekoji.storage.StorageException in project jenkins-scm-koji-plugin by judovana.
the class VariantBumperTest method okBumpJdkTestJobs.
@Test
public void okBumpJdkTestJobs() throws ManagementException, StorageException, IOException {
CurrentSetup cs = setup(true, false);
List<Project> a = getProjects(DataGenerator.PROJECT_VBC_JTP);
// create all
JobUpdateResults r1 = cs.settings.getJobUpdater().regenerateAll(null, cs.settings.getConfigManager().jdkProjectManager, null);
// create all
JobUpdateResults r2 = cs.settings.getJobUpdater().regenerateAll(null, cs.settings.getConfigManager().jdkTestProjectManager, null);
String[] nJobsO0 = cs.settings.getJenkinsJobsRoot().list();
Arrays.sort(nJobsO0);
String[] bumpedTests = new String[] { "tck-jdk8-vagrantBeakerConflictsProjectJdkTestProject-el6.x86_64-release.hotspot.sdk-el6.x86_64.vagrant-defaultgc.x11.legacy.lnxagent.jfroff", "tck-jdk8-vagrantBeakerConflictsProjectJdkTestProject-el6.x86_64-release.hotspot.sdk-el6.x86_64.vagrant-zgc.x11.legacy.lnxagent.jfroff" };
String po1 = Utils.readFile(new File(cs.settings.getConfigRoot(), "jdkTestProjects/" + DataGenerator.PROJECT_VBC_JTP + ".json"));
String so2 = Utils.readFile(cfgFile(cs.settings, bumpedTests[0], ".vagrant-", ".beaker-"));
Assert.assertTrue(so2.contains("OTOOL_PLATFORM_PROVIDER=beaker"));
Assert.assertTrue(so2.contains("<assignedNode>c||d</assignedNode>"));
VariantBumper bumper = new VariantBumper(cs.settings, "beaker", "vagrant", Pattern.compile(".*tck.*el6.*"));
Result<JobUpdateResults, OToolError> r = bumper.modifyJobs(a, new BumpArgs(JobCollisionAction.STOP, true));
Assert.assertNotNull(r);
Assert.assertTrue(r.isOk());
Assert.assertEquals(1, r.getValue().jobsCreated.size());
Assert.assertEquals(0, r.getValue().jobsArchived.size());
Assert.assertEquals(0, r.getValue().jobsRevived.size());
Assert.assertEquals(0, r.getValue().jobsRewritten.size());
allAre(r.getValue().jobsCreated, false);
Assert.assertEquals("tck-jdk8-vagrantBeakerConflictsProjectJdkTestProject-el6.x86_64-release.hotspot.sdk-el6.x86_64.beaker-defaultgc.x11.legacy.lnxagent.jfroff => tck-jdk8-vagrantBeakerConflictsProjectJdkTestProject-el6.x86_64-release.hotspot.sdk-el6.x86_64.vagrant-defaultgc.x11.legacy.lnxagent.jfroff", r.getValue().jobsCreated.get(0).jobName);
String[] nJobsO1 = cs.settings.getJenkinsJobsRoot().list();
Arrays.sort(nJobsO1);
Assert.assertArrayEquals(nJobsO0, nJobsO1);
String po2 = Utils.readFile(new File(cs.settings.getConfigRoot(), "jdkTestProjects/" + DataGenerator.PROJECT_VBC_JTP + ".json"));
Assert.assertEquals(po1, po2);
bumper = new VariantBumper(cs.settings, "beaker", "vagrant", Pattern.compile(".*tck.*el6.*"));
r = bumper.modifyJobs(a, new BumpArgs(JobCollisionAction.KEEP_BUMPED, true));
Assert.assertNotNull(r);
Assert.assertTrue(r.isOk());
Assert.assertEquals(2, r.getValue().jobsCreated.size());
Assert.assertEquals(0, r.getValue().jobsArchived.size());
Assert.assertEquals(0, r.getValue().jobsRevived.size());
Assert.assertEquals(0, r.getValue().jobsRewritten.size());
allAre(r.getValue().jobsCreated, true);
String sb1 = Utils.readFile(cfgFile(cs.settings, bumpedTests[0], "", ""));
Assert.assertTrue(sb1.contains("OTOOL_PLATFORM_PROVIDER=vagrant"));
Assert.assertTrue(sb1.contains("<assignedNode>Odin||Tyr||os-el</assignedNode>"));
Arrays.sort(bumpedTests);
Assert.assertEquals(r.getValue().jobsCreated.stream().map(b -> b.jobName).sorted().collect(Collectors.toList()), Arrays.asList(bumpedTests));
String pb1 = Utils.readFile(new File(cs.settings.getConfigRoot(), "jdkTestProjects/" + DataGenerator.PROJECT_VBC_JTP + ".json"));
Assert.assertNotEquals(po1, pb1);
String[] nJobsB1 = cs.settings.getJenkinsJobsRoot().list();
Arrays.sort(nJobsB1);
// two jobs changed, but one lsot because of conflict
Assert.assertTrue(nJobsO0.length == nJobsB1.length + 1);
for (String bt : bumpedTests) {
Assert.assertTrue(Arrays.binarySearch(nJobsB1, bt) >= 0);
Assert.assertTrue(Arrays.binarySearch(nJobsB1, bt.replace(".vagrant-", ".beaker-")) < 0);
Assert.assertTrue(Arrays.binarySearch(nJobsO1, bt.replace(".vagrant-", ".beaker-")) >= 0);
}
// although windows bump is checking bump to net existing provider, there is hidden sub catch
// dacapo require ohw slave, and windows are the only one which do not have it
bumper = new VariantBumper(cs.settings, "beaker", "vagrant", Pattern.compile(".*dacapo.*win2019.*"));
r = bumper.modifyJobs(a, new BumpArgs(JobCollisionAction.STOP, true));
Assert.assertNotNull(r);
Assert.assertTrue(r.isOk());
Assert.assertEquals(0, r.getValue().jobsCreated.size());
Assert.assertEquals(0, r.getValue().jobsArchived.size());
Assert.assertEquals(0, r.getValue().jobsRevived.size());
Assert.assertEquals(0, r.getValue().jobsRewritten.size());
allAre(r.getValue().jobsCreated, false);
bumper = new VariantBumper(cs.settings, "vagrant", "beaker", Pattern.compile(".*dacapo.*win2019.*"));
r = bumper.modifyJobs(a, new BumpArgs(JobCollisionAction.KEEP_BUMPED, true));
Assert.assertNotNull(r);
Assert.assertTrue(r.isOk());
Assert.assertTrue(r.isOk());
Assert.assertEquals(1, r.getValue().jobsCreated.size());
Assert.assertEquals(0, r.getValue().jobsArchived.size());
Assert.assertEquals(0, r.getValue().jobsRevived.size());
Assert.assertEquals(0, r.getValue().jobsRewritten.size());
allAre(r.getValue().jobsCreated, false);
bumper = new VariantBumper(cs.settings, "beaker", "vagrant", Pattern.compile(".*tck.*win2019.*"));
r = bumper.modifyJobs(a, new BumpArgs(JobCollisionAction.STOP, true));
Assert.assertNotNull(r);
Assert.assertTrue(r.isOk());
Assert.assertEquals(0, r.getValue().jobsCreated.size());
Assert.assertEquals(0, r.getValue().jobsArchived.size());
Assert.assertEquals(0, r.getValue().jobsRevived.size());
Assert.assertEquals(0, r.getValue().jobsRewritten.size());
allAre(r.getValue().jobsCreated, false);
bumper = new VariantBumper(cs.settings, "vagrant", "beaker", Pattern.compile(".*tck.*win2019.*"));
r = bumper.modifyJobs(a, new BumpArgs(JobCollisionAction.KEEP_BUMPED, true));
Assert.assertNotNull(r);
Assert.assertTrue(r.isOk());
Assert.assertEquals(1, r.getValue().jobsCreated.size());
Assert.assertEquals(0, r.getValue().jobsArchived.size());
Assert.assertEquals(0, r.getValue().jobsRevived.size());
Assert.assertEquals(0, r.getValue().jobsRewritten.size());
allAre(r.getValue().jobsCreated, false);
}
use of org.fakekoji.storage.StorageException in project jenkins-scm-koji-plugin by judovana.
the class DataGenerator method initConfigsRoot.
public static void initConfigsRoot(final AccessibleSettings settings) {
final String root = settings.getConfigRoot().getAbsolutePath();
final File products = Paths.get(root, ConfigManager.JDK_VERSIONS).toFile();
final File platforms = Paths.get(root, ConfigManager.PLATFORMS).toFile();
final File tasks = Paths.get(root, ConfigManager.TASKS).toFile();
final File buildProviders = Paths.get(root, ConfigManager.BUILD_PROVIDERS).toFile();
final File taskVariantCategories = Paths.get(root, ConfigManager.TASK_VARIANTS).toFile();
final File jdkProjects = Paths.get(root, ConfigManager.JDK_PROJECTS).toFile();
final File jdkTestProjects = Paths.get(root, ConfigManager.JDK_TEST_PROJECTS).toFile();
final List<File> configFiles = Arrays.asList(products, platforms, tasks, buildProviders, taskVariantCategories, jdkProjects, jdkTestProjects);
for (final File configFile : configFiles) {
if (!configFile.mkdir()) {
throw new RuntimeException("Couldn't create " + configFile.getAbsolutePath());
}
}
try {
final ConfigManager configManager = settings.getConfigManager();
for (final JDKVersion jdkVersion : getJDKVersions()) {
configManager.jdkVersionManager.create(jdkVersion);
}
for (final Platform platform : getPlatforms()) {
configManager.platformManager.create(platform);
}
for (final TaskVariant taskVariant : getTaskVariants()) {
configManager.taskVariantManager.create(taskVariant);
}
for (final Task task : getTasks()) {
configManager.taskManager.create(task);
}
for (final JDKProject jdkProject : getJDKProjects()) {
configManager.jdkProjectManager.create(jdkProject);
}
for (final JDKTestProject jdkTestProject : getJDKTestProjects()) {
configManager.jdkTestProjectManager.create(jdkTestProject);
}
final Set<BuildProvider> buildProviderSet = getBuildProviders();
for (final BuildProvider buildProvider : buildProviderSet) {
configManager.buildProviderManager.create(buildProvider);
}
} catch (StorageException | ManagementException e) {
throw new RuntimeException(e);
}
}
use of org.fakekoji.storage.StorageException in project jenkins-scm-koji-plugin by judovana.
the class JDKProjectManager method createRepoCloningThread.
private Runnable createRepoCloningThread(final JDKProject jdkProject, final JDKVersion jdkVersion) {
return () -> {
LOGGER.info("Starting cloning project's repository");
final ProcessBuilder processBuilder = new ProcessBuilder("bash", Paths.get(scriptsRoot.getAbsolutePath(), "otool", "clone_repo.sh").toString(), jdkVersion.getVersion(), jdkProject.getUrl(), Paths.get(repositoriesRoot.getAbsolutePath(), jdkProject.getId()).toString());
processBuilder.directory(repositoriesRoot);
LOGGER.info("Executing command: " + String.join(" ", processBuilder.command()));
final Process cloningProcess;
int exitCode;
try {
cloningProcess = processBuilder.start();
exitCode = cloningProcess.waitFor();
String line;
try (final BufferedReader outputReader = new BufferedReader(new InputStreamReader(cloningProcess.getInputStream(), "utf-8"))) {
while ((line = outputReader.readLine()) != null) {
System.out.println(line);
}
}
try (final BufferedReader errorReader = new BufferedReader(new InputStreamReader(cloningProcess.getErrorStream(), "utf-8"))) {
while ((line = errorReader.readLine()) != null) {
System.out.println(line);
}
}
} catch (InterruptedException | IOException e) {
LOGGER.severe("Exception occurred during cloning: " + e.getMessage());
exitCode = 1;
}
final JDKProject.RepoState repoState = exitCode == 0 ? JDKProject.RepoState.CLONED : JDKProject.RepoState.CLONE_ERROR;
final JDKProject clonedJDKProject = setProjectRepoStatus(jdkProject, repoState);
try {
LOGGER.info("Updating JDK project " + clonedJDKProject.getId() + " after cloning its repository");
jdkProjectStorage.store(clonedJDKProject.getId(), clonedJDKProject);
} catch (StorageException e) {
LOGGER.severe(e.getMessage());
}
};
}
use of org.fakekoji.storage.StorageException in project jenkins-scm-koji-plugin by judovana.
the class JobModifier method modifyJobs.
public Result<JobUpdateResults, OToolError> modifyJobs(final Collection<Project> projects, final JobCollisionAction jobCollisionAction, final boolean execute) {
final Set<Job> jobs = new HashSet<>();
try {
for (final Project project : projects) {
final Set<Job> projectJobs = settings.getJdkProjectParser().parse(project);
jobs.addAll(projectJobs);
}
final Set<Tuple<Job, Optional<Job>>> jobTuples = jobs.stream().map(getTransformFunction()).collect(Collectors.toSet());
final Set<JobBump> jobsToBump = jobTuples.stream().filter(jobTuple -> jobTuple.y.isPresent()).map(jobTuple -> new Tuple<>(jobTuple.x, jobTuple.y.get())).map(settings.getJobUpdater().getCollisionCheck()).collect(Collectors.toSet());
if (!execute) {
return Result.ok(new JobUpdateResults(Collections.emptyList(), Collections.emptyList(), jobsToBump.stream().map(jobBump -> new JobUpdateResult(jobBump.from.getName() + " => " + jobBump.to.getName(), true)).collect(Collectors.toList()), Collections.emptyList()));
}
final Set<Tuple<Job, Job>> collisions = jobsToBump.stream().filter(jobBump -> jobBump.isCollision).map(triple -> new Tuple<>(triple.from, triple.to)).collect(Collectors.toSet());
if (!collisions.isEmpty() && jobCollisionAction.equals(JobCollisionAction.STOP)) {
return Result.ok(new JobUpdateResults(collisions.stream().map(jobTuple -> new JobUpdateResult(jobTuple.x.getName() + " => " + jobTuple.y.getName(), false, jobTuple.y + " already exists")).collect(Collectors.toList()), Collections.emptyList(), Collections.emptyList(), Collections.emptyList()));
}
final Set<Job> finalJobs = jobTuples.stream().map(tuple -> tuple.y.orElseGet(() -> tuple.x)).collect(Collectors.toSet());
final Map<String, Set<Job>> jobMap = new HashMap<>();
for (final Job job : finalJobs) {
final String projectName = job.getProjectName();
if (!jobMap.containsKey(projectName)) {
jobMap.put(projectName, new HashSet<>());
}
final Set<Job> projectJobs = jobMap.get(projectName);
projectJobs.add(job);
}
final List<Project> assembledProjects = new ArrayList<>();
for (final Set<Job> projectJobs : jobMap.values()) {
final Result<Project, String> result = settings.getReverseJDKProjectParser().parseJobs(projectJobs);
if (result.isError()) {
return Result.err(new OToolError(result.getError(), 500));
} else {
assembledProjects.add(result.getValue());
}
}
for (final Project project : assembledProjects) {
final String id = project.getId();
switch(project.getType()) {
case JDK_PROJECT:
settings.getConfigManager().jdkProjectManager.update(id, (JDKProject) project);
break;
case JDK_TEST_PROJECT:
settings.getConfigManager().jdkTestProjectManager.update(id, (JDKTestProject) project);
break;
}
}
JenkinsJobUpdater.wakeUpJenkins();
return Result.ok(settings.getJobUpdater().bump(jobsToBump, jobCollisionAction));
} catch (StorageException e) {
return Result.err(new OToolError(e.getMessage(), 500));
} catch (ManagementException e) {
return Result.err(new OToolError(e.getMessage(), 400));
}
}
use of org.fakekoji.storage.StorageException in project jenkins-scm-koji-plugin by judovana.
the class GetterAPI method getJDKVersionHandler.
private QueryHandler getJDKVersionHandler() {
final JDKProjectManager jdkProjectManager = settings.getConfigManager().jdkProjectManager;
final JDKTestProjectManager jdkTestProjectManager = settings.getConfigManager().jdkTestProjectManager;
final JDKVersionManager jdkVersionManager = settings.getConfigManager().jdkVersionManager;
return new QueryHandler() {
@Override
public Result<String, String> handle(Map<String, List<String>> paramsMap) throws StorageException, ManagementException {
Optional<String> productOpt = extractParamValue(paramsMap, PRODUCT);
if (productOpt.isPresent()) {
final String product = productOpt.get();
final List<JDKVersion> jdkVersions = jdkVersionManager.readAll();
final Optional<JDKVersion> optionalJDKVersion = jdkVersions.stream().filter(jdkVersion -> jdkVersion.getPackageNames().contains(product)).findFirst();
if (optionalJDKVersion.isPresent()) {
final JDKVersion jdkVersion = optionalJDKVersion.get();
return Result.ok(jdkVersion.getId());
}
}
final Optional<String> projectOpt = extractParamValue(paramsMap, PROJECT);
if (projectOpt.isPresent()) {
final String projectName = projectOpt.get();
final Project project;
if (jdkProjectManager.contains(projectName)) {
project = jdkProjectManager.read(projectName);
} else if (jdkTestProjectManager.contains(projectName)) {
project = jdkTestProjectManager.read(projectName);
} else {
return Result.err("Project " + projectName + " doesn't exist");
}
return Result.ok(project.getProduct().getJdk());
}
return Result.err("Wrong/missing parameters");
}
@Override
public String about() {
return "/jdkVersion?[" + String.join("|", PRODUCT + "=<packageName>", PROJECT + "=<projectName>") + "]";
}
};
}
Aggregations