Search in sources :

Example 1 with PackageVersion

use of de.cinovo.cloudconductor.api.model.PackageVersion in project cloudconductor-agent-redhat by cinovo.

the class InstalledPackages method analyzeStream.

@Override
protected void analyzeStream(String[] dev, String[] error) throws ExecutionError {
    if (error.length > 0) {
        this.logger.error("Failed to get installed packages");
        for (String s : error) {
            this.logger.error(s);
        }
        throw new ExecutionError("Error while collecting installed packages");
    }
    this.logger.debug("Found installed packages: " + dev.length);
    String oldString = null;
    for (String str : dev) {
        if (oldString != null && str.startsWith(" ")) {
            // we need this to work around the yum list bullshit of breaking to new lines sometimes
            str = oldString + str;
        }
        str = str.replaceAll("\\s+", delimiter);
        String[] arr = str.split(InstalledPackages.delimiter);
        if (arr.length < 3) {
            oldString = str;
            continue;
        }
        oldString = null;
        String pkg = arr[0].split("\\.")[0];
        String version = arr[1].split(":")[arr[1].split(":").length - 1];
        if (!version.matches(".*\\d.*")) {
            // we don't have a version -> useless information
            continue;
        }
        String repo = arr[2].replace("@", "");
        PackageVersion packageVersion = new PackageVersion(pkg, version, null);
        Set<String> repos = new HashSet<>();
        repos.add(repo);
        packageVersion.setRepos(repos);
        this.logger.debug(pkg + " - " + version + " - " + repo);
        this.result.add(packageVersion);
    }
}
Also used : ExecutionError(de.cinovo.cloudconductor.agent.exceptions.ExecutionError) PackageVersion(de.cinovo.cloudconductor.api.model.PackageVersion) HashSet(java.util.HashSet)

Example 2 with PackageVersion

use of de.cinovo.cloudconductor.api.model.PackageVersion in project cloudconductor-agent-redhat by cinovo.

the class PackageHandler method run.

/**
 * @throws ExecutionError an error occurred during execution
 */
public void run() throws ExecutionError {
    PackageHandler.LOGGER.debug("Start PackageHandler");
    // report installed packages
    PackageStateChanges packageChanges = this.reportInstalledPackages();
    Set<String> repos = AgentState.info().getRepos();
    if (!repos.isEmpty()) {
        String repoNames = String.join(",", repos);
        PackageHandler.LOGGER.debug("Execute changes on repos {}", repoNames);
        // executed package changes for each repository
        List<PackageVersion> toDelete = packageChanges.getToErase();
        PackageHandler.LOGGER.debug("Delete: {}", toDelete.toString());
        List<PackageVersion> toInstall = packageChanges.getToInstall();
        PackageHandler.LOGGER.debug("Install: {}", toInstall.toString());
        List<PackageVersion> toUpdate = packageChanges.getToUpdate();
        PackageHandler.LOGGER.debug("Update: {}", toUpdate.toString());
        ScriptExecutor pkgHandler = ScriptExecutor.generatePackageHandler(repoNames, toDelete, toInstall, toUpdate);
        pkgHandler.execute();
        // re-report installed packages
        this.reportInstalledPackages();
    } else {
        PackageHandler.LOGGER.info("No repos in template");
    }
    PackageHandler.LOGGER.debug("Finished PackageHandler");
}
Also used : PackageStateChanges(de.cinovo.cloudconductor.api.model.PackageStateChanges) PackageVersion(de.cinovo.cloudconductor.api.model.PackageVersion) ScriptExecutor(de.cinovo.cloudconductor.agent.executors.ScriptExecutor)

Example 3 with PackageVersion

use of de.cinovo.cloudconductor.api.model.PackageVersion in project cloudconductor-agent-redhat by cinovo.

the class ScriptExecutor method generatePackageHandler.

/**
 * @param repo the name of the repository to use
 * @param remove packages to remove, separated by semicolon
 * @param install packages to install, separated by semicolon
 * @param update packages to update, separated by semicolon
 * @return the executor
 */
public static ScriptExecutor generatePackageHandler(String repo, Collection<PackageVersion> remove, Collection<PackageVersion> install, Collection<PackageVersion> update) {
    String scriptName = AgentVars.SCRIPT_YUM_HANDLER;
    String repoArg = "-y " + repo;
    StringBuilder d = new StringBuilder();
    StringBuilder i = new StringBuilder();
    StringBuilder u = new StringBuilder();
    if ((remove != null) && !remove.isEmpty()) {
        d.append("-d ");
        for (PackageVersion pck : remove) {
            d.append(ScriptExecutor.rpmToString(pck));
            d.append(";");
        }
    }
    if ((install != null) && !install.isEmpty()) {
        i.append("-i ");
        for (PackageVersion pck : install) {
            i.append(ScriptExecutor.rpmToString(pck));
            i.append(";");
        }
    }
    if ((update != null) && !update.isEmpty()) {
        u.append("-u ");
        for (PackageVersion pck : update) {
            u.append(ScriptExecutor.rpmToString(pck));
            u.append(";");
        }
    }
    return new ScriptExecutor(scriptName, repoArg, d.toString(), i.toString(), u.toString());
}
Also used : PackageVersion(de.cinovo.cloudconductor.api.model.PackageVersion)

Aggregations

PackageVersion (de.cinovo.cloudconductor.api.model.PackageVersion)3 ExecutionError (de.cinovo.cloudconductor.agent.exceptions.ExecutionError)1 ScriptExecutor (de.cinovo.cloudconductor.agent.executors.ScriptExecutor)1 PackageStateChanges (de.cinovo.cloudconductor.api.model.PackageStateChanges)1 HashSet (java.util.HashSet)1