use of org.fakekoji.jobmanager.model.BuildJob in project jenkins-scm-koji-plugin by judovana.
the class DataGenerator method getJDKProjectJobs.
public static Set<Job> getJDKProjectJobs() {
final Set<BuildProvider> buildProviders = DataGenerator.getBuildProviders();
final JDKVersion jdkVersion = DataGenerator.getJDKVersion8();
final Platform rhel7x64 = DataGenerator.getRHEL7x64();
final Task tckTask = DataGenerator.getTCK();
final Task buildTask = DataGenerator.getBuildTask();
final File scriptsRoot = folderHolder.scriptsRoot;
final File repositoriesRoot = folderHolder.reposRoot;
final Product jdk8 = DataGenerator.getJDK8Product();
final TaskVariant jreSdk = getJreSdk();
final TaskVariantValue jreSdkDefault = jreSdk.getVariants().get(jreSdk.getDefaultValue());
final TaskVariant agent = getAgent();
final TaskVariantValue agentDefault = agent.getVariants().get(agent.getDefaultValue());
final TaskVariant crypto = getCrypto();
final TaskVariantValue cryptoDefault = crypto.getVariants().get(crypto.getDefaultValue());
final TaskVariant jfr = getJfr();
final TaskVariantValue jfrDefault = jfr.getVariants().get(jfr.getDefaultValue());
final PullJob pullJob = new PullJob(PROJECT_NAME, PROJECT_URL, jdk8, jdkVersion, repositoriesRoot, scriptsRoot, Collections.emptyList());
final BuildJob buildJobHotspotRelease = new BuildJob(BEAKER, PROJECT_NAME, jdk8, jdkVersion, buildProviders, buildTask, rhel7x64, Collections.unmodifiableMap(new HashMap<TaskVariant, TaskVariantValue>() {
{
put(DataGenerator.getJvmVariant(), DataGenerator.getHotspotVariant());
put(DataGenerator.getDebugModeVariant(), DataGenerator.getReleaseVariant());
put(jreSdk, jreSdkDefault);
}
}), scriptsRoot, Collections.emptyList());
final BuildJob buildJobZeroRelease = new BuildJob(BEAKER, PROJECT_NAME, jdk8, jdkVersion, buildProviders, buildTask, rhel7x64, Collections.unmodifiableMap(new HashMap<TaskVariant, TaskVariantValue>() {
{
put(DataGenerator.getJvmVariant(), DataGenerator.getZeroVariant());
put(DataGenerator.getDebugModeVariant(), DataGenerator.getReleaseVariant());
put(jreSdk, jreSdkDefault);
}
}), scriptsRoot, Collections.emptyList());
final TestJob testJobHotspotRelease = new TestJob(VAGRANT, buildJobHotspotRelease, tckTask, rhel7x64, Collections.unmodifiableMap(new HashMap<TaskVariant, TaskVariantValue>() {
{
put(DataGenerator.getGarbageCollectorCategory(), DataGenerator.getShenandoahVariant());
put(DataGenerator.getDisplayProtocolCategory(), DataGenerator.getXServerVariant());
put(agent, agentDefault);
put(crypto, cryptoDefault);
put(jfr, jfrDefault);
}
}));
final TestJob testJobZeroHotspot = new TestJob(BEAKER, buildJobZeroRelease, tckTask, rhel7x64, Collections.unmodifiableMap(new HashMap<TaskVariant, TaskVariantValue>() {
{
put(DataGenerator.getGarbageCollectorCategory(), DataGenerator.getShenandoahVariant());
put(DataGenerator.getDisplayProtocolCategory(), DataGenerator.getXServerVariant());
put(agent, agentDefault);
put(crypto, cryptoDefault);
put(jfr, jfrDefault);
}
}));
return new HashSet<>(Arrays.asList(pullJob, buildJobHotspotRelease, buildJobZeroRelease, testJobHotspotRelease, testJobZeroHotspot));
}
use of org.fakekoji.jobmanager.model.BuildJob 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.BuildJob in project jenkins-scm-koji-plugin by judovana.
the class RedeployApi method addEndpoints.
@Override
public void addEndpoints() {
get(LATEST, context -> {
String countValue = context.queryParam(LATEST_count);
String commentsValue = context.queryParam(PROCESSED_cmments);
String jobsNamesValue = context.queryParam(PROCESSED_job);
List<String> jobs = new RedeployApiWorkerBase.RedeployApiStringListing(context).process(jdkProjectManager, jdkTestProjectManager, parser);
Set<String> nvrs = new HashSet<>(jobs.size());
for (String job : jobs) {
File processed = new File(new File(settings.getJenkinsJobsRoot(), job), Constants.PROCESSED_BUILDS_HISTORY);
List<String> raw = new ArrayList<>(0);
if (processed.exists()) {
raw = Utils.readFileToLines(processed, null);
}
if (raw.size() > 0) {
nvrs.add(raw.get(raw.size() - 1).replaceAll("\\s*#.*", ""));
}
}
context.status(OToolService.OK).result(String.join("\n", nvrs) + "\n");
});
get(PROCESSED, context -> {
String job = context.queryParam(PROCESSED_job);
if (job != null) {
try {
File processed = new File(new File(settings.getJenkinsJobsRoot(), job), Constants.PROCESSED_BUILDS_HISTORY);
List<String> raw = Utils.readFileToLines(processed, null);
if (context.queryParam(PROCESSED_cmments) == null) {
for (int i = 0; i < raw.size(); i++) {
raw.set(i, raw.get(i).replaceAll("\\s*#.*", ""));
}
}
if (context.queryParam(PROCESSED_uniq) == null) {
raw = new ArrayList<>(new TreeSet<>(raw));
}
if (context.queryParam(PROCESSED_sort) != null) {
Collections.sort(raw);
// Collections.reverse(raw);no!
}
context.status(OToolService.OK).result(String.join("\n", raw) + "\n");
} catch (IOException e) {
LOGGER.log(Level.WARNING, e.getMessage(), e);
context.status(400).result(e.getMessage());
} catch (Exception e) {
LOGGER.log(Level.WARNING, e.getMessage(), e);
context.status(500).result(e.getMessage());
}
} else {
context.status(OToolService.BAD).result("job is mandatory\n");
}
});
get(REDEPLOY_CHECKOUT, context -> {
try {
String job = context.queryParam(RERUN_JOB);
String nvr = context.queryParam(REDEPLOY_NVR);
String force = context.queryParam("force");
StringBuilder sb = forceCheckoutOnJob(job, nvr, "true".equals(force));
context.status(OToolService.OK).result(sb.toString());
} catch (Exception e) {
LOGGER.log(Level.WARNING, e.getMessage(), e);
context.status(500).result(e.getClass().getName() + ": " + e.getMessage());
}
});
get(RELOAD, context -> {
try {
String job = context.queryParam(RERUN_JOB);
if (job == null) {
throw new RuntimeException(RERUN_JOB + " is required parameter for " + RELOAD);
}
JenkinsCliWrapper.ClientResponse cr = JenkinsCliWrapper.getCli().reloadJob(job);
try {
cr.throwIfNecessary();
} catch (Exception ex) {
LOGGER.log(Level.WARNING, ex.getMessage(), cr.toString());
context.status(500).result(ex.getMessage() + ": " + cr.toString());
}
context.status(OToolService.OK).result(cr.toString());
} catch (Exception e) {
LOGGER.log(Level.WARNING, e.getMessage(), e);
context.status(500).result(e.getClass().getName() + ": " + e.getMessage());
}
});
get(REPROVIDER, context -> {
try {
String OTOOL_PLATFORM_PROVIDER = JenkinsJobTemplateBuilder.OTOOL_BASH_VAR_PREFIX + JenkinsJobTemplateBuilder.PLATFORM_PROVIDER_VAR;
List<String> jobs = new RedeployApiWorkerBase.RedeployApiStringListing(context).process(jdkProjectManager, jdkTestProjectManager, parser);
String doAndHow = context.queryParam(REDEPLOY_DO);
String nwProvider = context.queryParam(REPROVIDERARG);
String skipSlaves = context.queryParam(SKIP_SLAVES);
if (nwProvider == null || nwProvider.trim().isEmpty()) {
throw new RuntimeException(REPROVIDERARG + " is mandatory\n");
}
Set<String> providers = GetterAPI.getProviders(settings.getConfigManager().platformManager);
if (!providers.contains(nwProvider)) {
throw new RuntimeException(nwProvider + ": is not valid provider. Use one of: " + String.join(",", providers) + "\n");
}
/*
* To be able to compute nodes, we need to load nearly everything
*/
List<Job> allJobs = new ArrayList<>();
List<Project> allProjects = new ArrayList<>();
allProjects.addAll(settings.getConfigManager().jdkProjectManager.readAll());
allProjects.addAll(settings.getConfigManager().jdkTestProjectManager.readAll());
for (Project project : allProjects) {
allJobs.addAll(parser.parse(project));
}
StringBuilder sb = new StringBuilder();
int totalFiles = 0;
int totalReplacements = 0;
int invalidNodes = 0;
final String noneNode = "NoneNodeFound";
for (String job : jobs) {
Job foundJob = findJob(allJobs, job);
sb.append(job).append("\n");
File jobDir = new File(settings.getJenkinsJobsRoot(), job);
File config = new File(jobDir, "config.xml");
List<String> lines = Utils.readFileToLines(config, null);
for (int i = 0; i < lines.size(); i++) {
String mainline = lines.get(i);
String[] xmlLines = mainline.split(JenkinsJobTemplateBuilder.XML_NEW_LINE);
for (String line : xmlLines) {
if (!"true".equals(skipSlaves)) {
if (line.contains("<assignedNode>")) {
List<OToolVariable> fakeList = new ArrayList<>();
JenkinsJobTemplateBuilder.VmWithNodes mWithNodes = null;
try {
if (foundJob instanceof TestJob) {
fakeList = Arrays.asList(new OToolVariable("OS_NAME", ((TestJob) foundJob).getPlatform().getOs()));
mWithNodes = JenkinsJobTemplateBuilder.getVmWithNodes(((TestJob) foundJob).getTask(), ((TestJob) foundJob).getPlatform(), new ArrayList<OToolVariable>(), nwProvider);
} else if (foundJob instanceof BuildJob) {
fakeList = Arrays.asList(new OToolVariable("OS_NAME", ((TestJob) foundJob).getPlatform().getOs()));
mWithNodes = JenkinsJobTemplateBuilder.getVmWithNodes(((BuildJob) foundJob).getTask(), ((BuildJob) foundJob).getPlatform(), new ArrayList<OToolVariable>(), nwProvider);
}
} catch (Exception ex) {
mWithNodes = new JenkinsJobTemplateBuilder.VmWithNodes("NoNodesForThisCombination", Arrays.asList(noneNode));
invalidNodes++;
}
String nwVal = "<assignedNode>" + String.join("||", mWithNodes.nodes) + "</assignedNode>";
List<String> nvWalToExpand = Arrays.asList(nwVal);
String nwValExpanded = JenkinsJobTemplateBuilder.expand(nvWalToExpand, fakeList).get(0);
mainline = mainline.replace(line.trim(), nwValExpanded);
sb.append(" - " + line.trim() + " -> " + nwValExpanded + "\n");
totalReplacements++;
}
}
if (line.contains(OTOOL_PLATFORM_PROVIDER + "=")) {
String nwVal = "export " + OTOOL_PLATFORM_PROVIDER + "=" + nwProvider + " # hacked at " + new Date().toString();
mainline = mainline.replace(line.trim(), nwVal);
sb.append(" - " + line.trim() + " -> " + nwVal + "\n");
totalReplacements++;
}
}
lines.set(i, mainline);
}
if ("true".equals(doAndHow)) {
Utils.writeToFile(config, String.join("\n", lines));
sb.append(" - written\n");
try {
JenkinsCliWrapper.getCli().reloadJob(job).throwIfNecessary();
sb.append(" - reloaded\n");
} catch (Exception ex) {
sb.append(" - reload failed, reload on your own\n");
}
}
totalFiles++;
}
sb.append("true".equals(doAndHow) ? "Written " : "Would be written: " + totalFiles + " of " + jobs.size() + "\n");
if ("true".equals(skipSlaves)) {
sb.append("Replaced " + totalReplacements + " of " + jobs.size() + "\n");
} else {
sb.append("Replaced " + totalReplacements + " of " + (jobs.size() * 2) + "\n");
}
sb.append("Invlaid nodes: " + invalidNodes + "; search for " + noneNode + "\n");
context.status(OToolService.OK).result(sb.toString() + "\n");
} catch (Exception e) {
LOGGER.log(Level.WARNING, e.getMessage(), e);
context.status(500).result(e.getClass().getName() + ": " + e.getMessage());
}
});
get(RESLAVES, context -> {
try {
List<String> jobs = new RedeployApiWorkerBase.RedeployApiStringListing(context).process(jdkProjectManager, jdkTestProjectManager, parser);
String doAndHow = context.queryParam(REDEPLOY_DO);
String nwSlaves = context.queryParam(RESLAVES);
if (nwSlaves == null || nwSlaves.trim().isEmpty()) {
throw new RuntimeException(RESLAVES + " is mandatory\n");
}
StringBuilder sb = new StringBuilder();
int totalCountReplacements = 0;
int totalCountFiles = 0;
for (String job : jobs) {
sb.append(job).append("\n");
File jobDir = new File(settings.getJenkinsJobsRoot(), job);
File config = new File(jobDir, "config.xml");
List<String> lines = Utils.readFileToLines(config, null);
for (int i = 0; i < lines.size(); i++) {
String line = lines.get(i);
if (line.contains("<assignedNode>")) {
String orig = line.trim();
String nw = "<assignedNode>" + nwSlaves + "</assignedNode>";
sb.append(" - " + orig + " -> " + nw + "\n");
lines.set(i, nw);
totalCountReplacements++;
}
}
if ("true".equals(doAndHow)) {
Utils.writeToFile(config, String.join("\n", lines));
sb.append(" - written\n");
try {
JenkinsCliWrapper.getCli().reloadJob(job).throwIfNecessary();
sb.append(" - reloaded\n");
} catch (Exception ex) {
sb.append(" - reload failed, reload on your own\n");
}
}
totalCountFiles++;
}
sb.append("true".equals(doAndHow) ? "Written " : "Would be written: " + totalCountFiles + " of " + jobs.size() + "\n");
sb.append("Replaced " + totalCountReplacements + " of " + jobs.size() + "\n");
context.status(OToolService.OK).result(sb.toString() + "\n");
} catch (Exception e) {
LOGGER.log(Level.WARNING, e.getMessage(), e);
context.status(500).result(e.getClass().getName() + ": " + e.getMessage());
}
});
get(REDEPLOY_CHECKOUT_ALL, context -> {
try {
List<String> jobs = new RedeployApiWorkerBase.RedeployApiStringListing(context).process(jdkProjectManager, jdkTestProjectManager, parser);
String doAndHow = context.queryParam(REDEPLOY_DO);
String nvr = context.queryParam(REDEPLOY_NVR);
String force = context.queryParam("force");
if ("true".equals(doAndHow)) {
List<String> results = new ArrayList<>(jobs.size());
for (String job : jobs) {
try {
forceCheckoutOnJob(job, nvr, "true".equals(force));
results.add("ok - checking out - " + job);
} catch (Exception ex) {
LOGGER.log(Level.WARNING, ex.getMessage(), ex);
results.add("failed " + job + ex.toString());
}
}
context.status(OToolService.OK).result(String.join("\n", results) + "\n");
} else {
context.status(OToolService.OK).result(String.join("\n", jobs) + "\n");
}
} catch (Exception e) {
LOGGER.log(Level.WARNING, e.getMessage(), e);
context.status(500).result(e.getClass().getName() + ": " + e.getMessage());
}
});
get(REDEPLOY_NOW, context -> {
try {
List<String> jobs = new RedeployApiWorkerBase.RedeployApiStringListing(context).process(jdkProjectManager, jdkTestProjectManager, parser);
String doAndHow = context.queryParam(REDEPLOY_DO);
if ("true".equals(doAndHow)) {
List<String> results = new ArrayList<>(jobs.size());
for (String job : jobs) {
try {
JenkinsCliWrapper.ClientResponse cr = JenkinsCliWrapper.getCli().scheduleBuild(job);
cr.throwIfNecessary();
results.add("ok - scheduling - " + job);
} catch (Exception ex) {
LOGGER.log(Level.WARNING, ex.getMessage(), ex);
results.add("failed " + job + ex.toString());
}
}
context.status(OToolService.OK).result(String.join("\n", results) + "\n");
} else {
context.status(OToolService.OK).result(String.join("\n", jobs) + "\n");
}
} catch (Exception e) {
LOGGER.log(Level.WARNING, e.getMessage(), e);
context.status(500).result(e.getClass().getName() + ": " + e.getMessage());
}
});
get(REDEPLOY_RUN, context -> {
// hmm enable filtering?
try {
String job = context.queryParam(RERUN_JOB);
if (job == null) {
throw new RuntimeException(RERUN_JOB + " must be an existing job id, was " + job);
}
String id = context.queryParam(RERUN_BUILD);
if (id == null) {
throw new RuntimeException(RERUN_BUILD + " must be an existing build number, was " + id);
}
File currentt = new File(settings.getJenkinsJobsRoot().getAbsolutePath() + File.separator + job + File.separator + "build.xml");
if (!currentt.getParentFile().exists()) {
throw new RuntimeException(currentt.getParentFile() + " do not exists. bad job?");
}
File archived = new File(settings.getJenkinsJobsRoot().getAbsolutePath() + File.separator + job + File.separator + "builds" + File.separator + id + File.separator + "changelog.xml");
if (!archived.exists()) {
throw new RuntimeException(archived.getAbsolutePath() + " do not exists. failed at checkout? Bad id? bad job?");
}
StringBuilder sb = new StringBuilder();
if (!currentt.exists()) {
sb.append(currentt.getAbsolutePath() + " do not exists. bad job? Broken checkou?t No koji-scm job?\n");
}
Files.copy(archived.toPath(), currentt.toPath(), StandardCopyOption.REPLACE_EXISTING);
sb.append("Copied " + archived.getAbsolutePath() + " as " + currentt.getAbsolutePath() + "\n");
JenkinsCliWrapper.ClientResponse cr = JenkinsCliWrapper.getCli().scheduleBuild(job);
cr.throwIfNecessary();
sb.append("scheduled " + job + "\n");
context.status(OToolService.OK).result(sb.toString());
} catch (Exception e) {
LOGGER.log(Level.WARNING, e.getMessage(), e);
context.status(500).result(e.getClass().getName() + ": " + e.getMessage());
}
});
get(REDEPLOY_BUILD, context -> {
WarHorse wh = new WarHorse(context);
wh.workload(new NvrDirOperatorFactory(), BuildJob.class);
});
get(REDEPLOY_TEST, context -> {
WarHorse wh = new WarHorse(context);
wh.workload(new FakeNvrDirOperatorFactory(), TestJob.class);
});
get(ARCHES_EXPECTED, context -> {
try {
String nvr = context.queryParam(REDEPLOY_NVR);
if (nvr != null) {
OToolParser.LegacyNVR nvrParsed = new OToolParser.LegacyNVR(nvr);
String set = context.queryParam(ARCHES_EXPECTED_SET);
if (set == null) {
File f = new File(settings.getDbFileRoot().toPath().toFile().getAbsolutePath() + "/" + nvrParsed.getFullPath() + "/data");
while (f.getParentFile() != null) {
File ae = new File(f, FakeBuild.archesConfigFileName);
if (ae.exists()) {
break;
}
f = f.getParentFile();
}
if (f.getParentFile() == null) {
context.status(OToolService.OK).result("No " + FakeBuild.archesConfigFileName + " for " + nvr + " arches expected are old api only!\n");
} else {
File ae = new File(f, FakeBuild.archesConfigFileName);
// by luck, same comments schema is used in processed.txt and arches.expected
List<String> archesWithoutCommenrs = Utils.readProcessedTxt(ae);
if (ae.length() < 4 || archesWithoutCommenrs.isEmpty()) {
context.status(OToolService.BAD).result(ae.getAbsolutePath() + " is emmpty or very small. That will break a lot of stuff!\n");
} else {
context.status(OToolService.OK).result(String.join(" ", archesWithoutCommenrs.get(0)) + " (" + ae.getAbsolutePath() + ")\n");
}
}
} else {
File mainPath = new File(settings.getDbFileRoot().toPath().toFile().getAbsolutePath() + "/" + nvrParsed.getFullPath());
if (!mainPath.exists()) {
context.status(OToolService.BAD).result(mainPath.getAbsolutePath() + " Do not exists. Invlid NVRos?\n");
} else {
File data = new File(mainPath, "data");
File mainFile = new File(data, FakeBuild.archesConfigFileName);
if (mainFile.exists()) {
List<String> archesWithoutCommenrs = Utils.readProcessedTxt(mainFile);
FakeBuild.generateDefaultArchesFile(mainFile, set);
if (archesWithoutCommenrs.isEmpty()) {
context.status(OToolService.OK).result("overwritten " + mainFile + " (was: empty, is`" + set + "`)\n");
} else {
context.status(OToolService.OK).result("overwritten " + mainFile + " (was: `" + archesWithoutCommenrs.get(0) + "`, is`" + set + "`)\n");
}
} else {
data.mkdirs();
FakeBuild.generateDefaultArchesFile(mainFile, set);
context.status(OToolService.OK).result("written " + mainFile + " (is`" + set + "`)\n");
}
}
}
} else {
ArchesExpectedWorker aw = new ArchesExpectedWorker();
aw.prepare();
List<Platform> platforms = platformManager.readAll();
Set<String> kojiArches = new HashSet<>();
for (Platform p : platforms) {
kojiArches.add(p.getKojiArch().orElse(p.getArchitecture()));
}
// filtr affected jobs + places in builds (s neb arches>
context.status(OToolService.OK).result(aw.dirsWithArches.entrySet().stream().map((Function<Map.Entry<String, String[]>, String>) e -> String.join(" ", e.getValue()) + " (" + e.getKey() + ")").sorted().collect(Collectors.joining("\n")) + "\n" + "All used: " + aw.usedArches.stream().collect(Collectors.joining(" ")) + "\n" + "All possible: " + kojiArches.stream().collect(Collectors.joining(" ")) + "\n");
// better to filter them up rather then here
}
} catch (StorageException | IOException e) {
LOGGER.log(Level.WARNING, e.getMessage(), e);
context.status(400).result(e.getMessage());
} catch (Exception e) {
LOGGER.log(Level.WARNING, e.getMessage(), e);
context.status(500).result(e.getMessage());
}
});
}
use of org.fakekoji.jobmanager.model.BuildJob in project jenkins-scm-koji-plugin by judovana.
the class MatrixGenerator method getJobConsumer.
private Consumer<TaskJob> getJobConsumer(final Map<String, Map<String, CellGroup>> map, final boolean inverted) {
return job -> {
final BuildSpec buildSpec;
final TestSpec testSpec;
final String projectName = job.getProjectName();
final Product product = job.getProduct();
final Task task = job.getTask();
final Platform.Provider provider = job.getPlatform().getProviders().stream().filter(p -> p.getId().equals(job.getPlatformProvider())).findFirst().orElseGet(this::createNoneProvider);
final List<String> variants = job.getVariants().entrySet().stream().sorted(Comparator.comparing(Map.Entry::getKey)).map(e -> e.getValue().getId()).collect(Collectors.toList());
if (job instanceof BuildJob) {
final BuildJob buildJob = (BuildJob) job;
buildSpec = new BuildSpec(buildJob.getPlatform(), provider, projectName, product, variants, buildFilter);
testSpec = new TestSpec(buildJob.getPlatform(), provider, task, testFilter);
} else if (job instanceof TestJob) {
final TestJob testJob = (TestJob) job;
final List<String> buildVariants = testJob.getBuildVariants().entrySet().stream().sorted(Comparator.comparing(Map.Entry::getKey)).map(e -> e.getValue().getId()).collect(Collectors.toList());
final Platform.Provider buildPlatformProvider = testJob.getBuildPlatform().getProviders().stream().filter(p -> p.getId().equals(testJob.getBuildPlatformProvider())).findFirst().orElse(provider);
testSpec = new TestSpec(testJob.getPlatform(), provider, task, variants, testFilter);
if (testJob.getProjectType() == Project.ProjectType.JDK_TEST_PROJECT) {
final BuildJob testOnlyBuildJob = new BuildJob(EXTERNAL_PLATFORM_PROVIDER, projectName, product, testJob.getJdkVersion(), job.getBuildProviders(), cache.getTask("build").orElse(null), testJob.getBuildPlatform(), testJob.getBuildVariants(), null, null);
buildSpec = new BuildSpec(testJob.getBuildPlatform(), createExternalProvider(), projectName, product, buildVariants, buildFilter);
final TestSpec testBuildSpec = new TestSpec(testOnlyBuildJob.getPlatform(), createExternalProvider(), testOnlyBuildJob.getTask(), testFilter);
addJob(map, buildSpec, testBuildSpec, parseExternalJob(testOnlyBuildJob), inverted);
} else {
buildSpec = new BuildSpec(testJob.getBuildPlatform(), buildPlatformProvider, projectName, product, buildVariants, buildFilter);
}
} else {
return;
}
addJob(map, buildSpec, testSpec, parseJob(job), inverted);
};
}
use of org.fakekoji.jobmanager.model.BuildJob in project jenkins-scm-koji-plugin by judovana.
the class JenkinsJobTemplateBuilderTest method buildBuildJobTemplateWithVmPlatform.
@Test
public void buildBuildJobTemplateWithVmPlatform() throws IOException {
final Set<BuildProvider> buildProviders = DataGenerator.getBuildProviders();
final Task buildTask = DataGenerator.getBuildTask();
final Platform vmPlatform = DataGenerator.getF29x64();
final BuildJob buildJob = new BuildJob(VAGRANT, PROJECT_NAME, jdk8Product, jdk8, buildProviders, buildTask, vmPlatform, buildVariants, scriptsRoot, null);
final String expectedTemplate = "<?xml version=\"1.1\" encoding=\"UTF-8\" ?>\n" + "<project>\n" + " <actions/>\n" + " <description/>\n" + " <keepDependencies>false</keepDependencies>\n" + " <properties/>\n" + " <scm class=\"hudson.plugins.scm.koji.KojiSCM\" plugin=\"jenkins-scm-koji-plugin@0.2-SNAPSHOT\">\n" + BUILD_PROVIDERS_TEMPLATE + " <kojiXmlRpcApi class=\"hudson.plugins.scm.koji.FakeKojiXmlRpcApi\">\n" + " <xmlRpcApiType>FAKE_KOJI</xmlRpcApiType>\n" + " <projectName>" + PROJECT_NAME + "</projectName>\n" + " <buildVariants>" + "buildPlatform=" + vmPlatform.getId() + " debugMode=" + buildVariants.get(debugMode).getId() + " jreSdk=" + buildVariants.get(jreSdk).getId() + " jvm=" + buildVariants.get(jvm).getId() + "</buildVariants>\n" + " <buildPlatform>src</buildPlatform>\n" + " <isBuilt>" + false + "</isBuilt>\n" + " </kojiXmlRpcApi>\n" + " <downloadDir>rpms</downloadDir>\n" + " <cleanDownloadDir>true</cleanDownloadDir>\n" + " <dirPerNvr>false</dirPerNvr>\n" + " <maxPreviousBuilds>10</maxPreviousBuilds>\n" + " </scm>\n" + " <assignedNode>" + String.join("||", vmPlatform.getProviders().get(0).getVmNodes()) + "</assignedNode>\n" + " <canRoam>false</canRoam>\n" + " <disabled>false</disabled>\n" + " <blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>\n" + " <blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>\n" + " <triggers>\n" + " <hudson.triggers.SCMTrigger>\n" + " <spec>" + SCP_POLL_SCHEDULE + "</spec>\n" + " <ignorePostCommitHooks>false</ignorePostCommitHooks>\n" + " </hudson.triggers.SCMTrigger>\n" + " </triggers>\n" + " <concurrentBuild>false</concurrentBuild>\n" + " <builders>\n" + " <hudson.tasks.Shell>\n" + " <command>\n" + "#!/bin/bash \n" + "export OTOOL_ARCH=" + vmPlatform.getArchitecture() + XML_NEW_LINE + "export OTOOL_JDK_VERSION=" + jdk8.getVersion() + XML_NEW_LINE + "export OTOOL_JOB_NAME=" + buildJob.getName() + XML_NEW_LINE + "export OTOOL_JOB_NAME_SHORTENED=" + buildJob.getShortName() + XML_NEW_LINE + "export OTOOL_OJDK=" + jdk8.getId() + XML_NEW_LINE + "export OTOOL_OS=" + vmPlatform.getOs() + '.' + vmPlatform.getVersion() + XML_NEW_LINE + "export OTOOL_OS_NAME=" + vmPlatform.getOs() + XML_NEW_LINE + "export OTOOL_OS_VERSION=" + vmPlatform.getVersionNumber() + XML_NEW_LINE + "export OTOOL_PACKAGE_NAME=" + jdk8.getPackageNames().get(0) + XML_NEW_LINE + "export OTOOL_PLATFORM_PROVIDER=" + vmPlatform.getProviders().get(0).getId() + XML_NEW_LINE + "export OTOOL_PROJECT_NAME=" + PROJECT_NAME + XML_NEW_LINE + "export OTOOL_RELEASE_SUFFIX=" + RELEASE + '.' + HOTSPOT + '.' + SDK + '.' + vmPlatform.getId() + XML_NEW_LINE + "export OTOOL_VM_NAME_OR_LOCAL=" + vmPlatform.getVmName() + XML_NEW_LINE + "export OTOOL_debugMode=" + buildVariants.get(debugMode).getId() + XML_NEW_LINE + "export OTOOL_jreSdk=" + buildVariants.get(jreSdk).getId() + XML_NEW_LINE + "export OTOOL_jvm=" + buildVariants.get(jvm).getId() + XML_NEW_LINE + "\nbash " + Paths.get(scriptsRoot.getAbsolutePath(), O_TOOL, RUN_SCRIPT_NAME) + " '" + buildTask.getScript() + "' \n" + "</command>\n" + " </hudson.tasks.Shell>\n" + " </builders>\n" + " <publishers>\n" + DataGenerator.BUILD_POST_BUILD_TASK + DataGenerator.getPostTasks(scriptsRoot.getAbsolutePath(), true, true, VAGRANT, buildJob.getShortName(), vmPlatform.getVmName()) + " </publishers>\n" + " <buildWrappers/>\n" + "</project>\n";
final String actualTemplate = buildJob.generateTemplate();
Assert.assertEquals(expectedTemplate, actualTemplate);
}
Aggregations