Search in sources :

Example 1 with ConfigManager

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);
}
Also used : ConfigCache(org.fakekoji.jobmanager.ConfigCache) JDKProject(org.fakekoji.jobmanager.model.JDKProject) PrintStream(java.io.PrintStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ConfigManager(org.fakekoji.jobmanager.ConfigManager) List(java.util.List) JDKTestProject(org.fakekoji.jobmanager.model.JDKTestProject) Test(org.junit.Test)

Example 2 with ConfigManager

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);
    }
}
Also used : JDKProject(org.fakekoji.jobmanager.model.JDKProject) Task(org.fakekoji.model.Task) Platform(org.fakekoji.model.Platform) BuildProvider(org.fakekoji.model.BuildProvider) JDKVersion(org.fakekoji.model.JDKVersion) ConfigManager(org.fakekoji.jobmanager.ConfigManager) TaskVariant(org.fakekoji.model.TaskVariant) ManagementException(org.fakekoji.jobmanager.ManagementException) File(java.io.File) StorageException(org.fakekoji.storage.StorageException) JDKTestProject(org.fakekoji.jobmanager.model.JDKTestProject)

Example 3 with ConfigManager

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))));
    });
}
Also used : OToolError(org.fakekoji.api.http.rest.OToolError) Project(org.fakekoji.jobmanager.model.Project) Arrays(java.util.Arrays) Platform(org.fakekoji.model.Platform) ManagementException(org.fakekoji.jobmanager.ManagementException) BUMP_TO(org.fakekoji.api.http.rest.BumperAPI.BUMP_TO) RestUtils.extractMandatoryParamValue(org.fakekoji.api.http.rest.RestUtils.extractMandatoryParamValue) Logger(java.util.logging.Logger) PlatformManager(org.fakekoji.jobmanager.manager.PlatformManager) PlatformBumpVariant(org.fakekoji.jobmanager.model.PlatformBumpVariant) Level(java.util.logging.Level) ConfigManager(org.fakekoji.jobmanager.ConfigManager) List(java.util.List) PLATFORM_BUMP_VARIANT(org.fakekoji.api.http.rest.BumperAPI.PLATFORM_BUMP_VARIANT) OToolError(org.fakekoji.api.http.rest.OToolError) FILTER(org.fakekoji.api.http.rest.BumperAPI.FILTER) Map(java.util.Map) RestUtils.extractParamValue(org.fakekoji.api.http.rest.RestUtils.extractParamValue) Result(org.fakekoji.functional.Result) StorageException(org.fakekoji.storage.StorageException) Optional(java.util.Optional) JavaServerConstants(org.fakekoji.xmlrpc.server.JavaServerConstants) Pattern(java.util.regex.Pattern) BUMP_FROM(org.fakekoji.api.http.rest.BumperAPI.BUMP_FROM) PROJECTS(org.fakekoji.api.http.rest.BumperAPI.PROJECTS) Pattern(java.util.regex.Pattern) PlatformManager(org.fakekoji.jobmanager.manager.PlatformManager) Platform(org.fakekoji.model.Platform) PlatformBumpVariant(org.fakekoji.jobmanager.model.PlatformBumpVariant) ManagementException(org.fakekoji.jobmanager.ManagementException) StorageException(org.fakekoji.storage.StorageException)

Example 4 with ConfigManager

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));
            }
        });
    });
}
Also used : Project(org.fakekoji.jobmanager.model.Project) ConfigCache(org.fakekoji.jobmanager.ConfigCache) BumpResult(org.fakekoji.jobmanager.bumpers.BumpResult) ManagementException(org.fakekoji.jobmanager.ManagementException) BuildDirUpdater(org.fakekoji.jobmanager.BuildDirUpdater) TaskVariantAdder(org.fakekoji.jobmanager.bumpers.impl.TaskVariantAdder) File(java.io.File) StorageException(org.fakekoji.storage.StorageException) ConfigManager(org.fakekoji.jobmanager.ConfigManager) TaskVariant(org.fakekoji.model.TaskVariant)

Example 5 with ConfigManager

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));
        });
    });
}
Also used : ConfigCache(org.fakekoji.jobmanager.ConfigCache) BuildDirUpdater(org.fakekoji.jobmanager.BuildDirUpdater) ConfigManager(org.fakekoji.jobmanager.ConfigManager) TaskVariant(org.fakekoji.model.TaskVariant) Project(org.fakekoji.jobmanager.model.Project) BumpResult(org.fakekoji.jobmanager.bumpers.BumpResult) ManagementException(org.fakekoji.jobmanager.ManagementException) TaskVariantRemover(org.fakekoji.jobmanager.bumpers.impl.TaskVariantRemover) File(java.io.File) StorageException(org.fakekoji.storage.StorageException)

Aggregations

ConfigManager (org.fakekoji.jobmanager.ConfigManager)7 ConfigCache (org.fakekoji.jobmanager.ConfigCache)5 ManagementException (org.fakekoji.jobmanager.ManagementException)5 Project (org.fakekoji.jobmanager.model.Project)5 StorageException (org.fakekoji.storage.StorageException)5 File (java.io.File)4 JDKProject (org.fakekoji.jobmanager.model.JDKProject)4 JDKTestProject (org.fakekoji.jobmanager.model.JDKTestProject)4 TaskVariant (org.fakekoji.model.TaskVariant)4 List (java.util.List)3 Platform (org.fakekoji.model.Platform)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 PrintStream (java.io.PrintStream)2 Map (java.util.Map)2 Optional (java.util.Optional)2 BuildDirUpdater (org.fakekoji.jobmanager.BuildDirUpdater)2 BumpResult (org.fakekoji.jobmanager.bumpers.BumpResult)2 BuildProvider (org.fakekoji.model.BuildProvider)2 JDKVersion (org.fakekoji.model.JDKVersion)2 Arrays (java.util.Arrays)1