use of org.fakekoji.jobmanager.ConfigManager in project jenkins-scm-koji-plugin by judovana.
the class MatrixGeneratorTest method showPerProjectsMatrix.
@Test
public void showPerProjectsMatrix() throws ManagementException, StorageException, IOException {
final ConfigManager configManager = settings.getConfigManager();
final ConfigCache configCache = new ConfigCache(configManager);
final List<String> jdkProjectNames = configCache.getJdkProjects().stream().map(JDKProject::getId).sorted().collect(Collectors.toList());
final List<String> jdkTestProjectNames = configCache.getJdkTestProjects().stream().map(JDKTestProject::getId).sorted().collect(Collectors.toList());
final List<List<String>> jdkProjectLists = Arrays.asList(jdkProjectNames, jdkTestProjectNames);
final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
final String expectedContent = readResource("per_projects_matrices");
final PrintStream printStream = new PrintStream(outputStream);
for (List<String> projectNames : jdkProjectLists) {
MatrixGenerator m = new MatrixGenerator(settings, projectNames.toArray(new String[0]));
List<BuildSpec> bs = m.getBuilds();
List<TestSpec> ts = m.getTests();
m.printMatrix(printStream, bs, ts, true, true, tf, true);
}
assertContents(expectedContent, outputStream);
}
use of org.fakekoji.jobmanager.ConfigManager 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.jobmanager.ConfigManager in project jenkins-scm-koji-plugin by judovana.
the class BumpPlatformArgs method parse.
public static Result<BumpPlatformArgs, OToolError> parse(final ConfigManager configManger, final Map<String, List<String>> paramsMap) {
return extractParams(paramsMap).flatMap(params -> {
final Platform from;
final Platform to;
try {
final PlatformManager platformManager = configManger.platformManager;
from = platformManager.read(params.from);
to = platformManager.read(params.to);
} catch (StorageException e) {
LOGGER.log(Level.SEVERE, e.getMessage(), e);
return Result.err(new OToolError(e.getMessage(), 500));
} catch (ManagementException e) {
LOGGER.log(Level.SEVERE, e.getMessage(), e);
return Result.err(new OToolError(e.getMessage(), 400));
}
final Result<PlatformBumpVariant, String> variantParseResult = PlatformBumpVariant.parse(params.variant);
if (variantParseResult.isError()) {
return Result.err(new OToolError(variantParseResult.getError(), 400));
}
final PlatformBumpVariant variant = variantParseResult.getValue();
final List<String> projectsList = Arrays.asList(params.projects.split(","));
final Optional<Pattern> filter = Optional.ofNullable(compileFilter(params.filter));
return BumpArgs.parseBumpArgs(paramsMap).flatMap(bumpArgs -> configManger.getProjects(projectsList).flatMap(projects -> Result.ok(new BumpPlatformArgs(bumpArgs, from, to, filter, variant, projects))));
});
}
use of org.fakekoji.jobmanager.ConfigManager in project jenkins-scm-koji-plugin by judovana.
the class BumperAPI method addTaskVariant.
Result<BumpResult, OToolError> addTaskVariant(final Map<String, List<String>> params) {
final ConfigManager configManager = settings.getConfigManager();
final File buildsRoot = settings.getDbFileRoot();
return AddTaskVariantArgs.parse(configManager, params).flatMap(args -> {
final TaskVariant taskVariant = args.taskVariant;
try {
configManager.taskVariantManager.create(taskVariant);
} catch (StorageException e) {
return Result.err(new OToolError(e.getMessage(), 500));
} catch (ManagementException e) {
return Result.err(new OToolError(e.getMessage(), 400));
}
final Collection<Project> projects;
try {
final ConfigCache configCache = new ConfigCache(configManager);
projects = configCache.getProjects();
} catch (StorageException e) {
return Result.err(new OToolError(e.getMessage(), 500));
}
final TaskVariantAdder adder = new TaskVariantAdder(settings, taskVariant);
return adder.modifyJobs(projects, args).flatMap(results -> {
if (taskVariant.getType().equals(Task.Type.BUILD)) {
final BuildDirUpdater buildDirUpdater = new BuildDirUpdater(buildsRoot, configManager);
buildDirUpdater.updateBuildDirs(adder);
return Result.ok(new BumpResult(results, buildDirUpdater.getSummary()));
} else {
return Result.ok(new BumpResult(results));
}
});
});
}
use of org.fakekoji.jobmanager.ConfigManager in project jenkins-scm-koji-plugin by judovana.
the class BumperAPI method removeTaskVariant.
Result<BumpResult, OToolError> removeTaskVariant(final Map<String, List<String>> params) {
final ConfigManager configManager = settings.getConfigManager();
final File buildsRoot = settings.getDbFileRoot();
return RemoveTaskVariantArgs.parse(params).flatMap(args -> {
final TaskVariant taskVariant;
try {
taskVariant = configManager.taskVariantManager.read(args.name);
} catch (StorageException e) {
return Result.err(new OToolError(e.getMessage(), 500));
} catch (ManagementException e) {
return Result.err(new OToolError(e.getMessage(), 400));
}
final Collection<Project> projects;
try {
final ConfigCache configCache = new ConfigCache(configManager);
projects = configCache.getProjects();
} catch (StorageException e) {
return Result.err(new OToolError(e.getMessage(), 500));
}
final TaskVariantRemover remover = new TaskVariantRemover(settings, taskVariant);
return remover.modifyJobs(projects, args).flatMap(jobBumpResults -> {
final BuildDirUpdater.BuildUpdateSummary buildUpdateSummary;
if (taskVariant.getType().equals(Task.Type.BUILD)) {
final BuildDirUpdater updater = new BuildDirUpdater(buildsRoot, configManager);
updater.updateBuildDirs(remover);
buildUpdateSummary = updater.getSummary();
} else {
buildUpdateSummary = null;
}
String message;
try {
configManager.taskVariantManager.delete(taskVariant.getId());
message = null;
} catch (ManagementException | StorageException e) {
final String error = "Failed to delete task variant config: " + e.getMessage();
LOGGER.log(Level.SEVERE, error, e);
message = error;
}
return Result.ok(new BumpResult(jobBumpResults, buildUpdateSummary, message));
});
});
}
Aggregations