Search in sources :

Example 1 with HostUpgradeManagerResult

use of org.ovirt.engine.core.common.HostUpgradeManagerResult in project ovirt-engine by oVirt.

the class HostUpgradeCheckInternalCommand method executeCommand.

@Override
protected void executeCommand() {
    HostUpgradeManagerResult hostUpgradeManagerResult = hostUpdatesChecker.checkForUpdates(vdsDao.get(getVdsId()));
    getReturnValue().setActionReturnValue(hostUpgradeManagerResult);
    setSucceeded(hostUpgradeManagerResult != null);
    setCommandStatus(hostUpgradeManagerResult != null ? CommandStatus.SUCCEEDED : CommandStatus.FAILED);
}
Also used : HostUpgradeManagerResult(org.ovirt.engine.core.common.HostUpgradeManagerResult)

Example 2 with HostUpgradeManagerResult

use of org.ovirt.engine.core.common.HostUpgradeManagerResult in project ovirt-engine by oVirt.

the class HostUpgradeManager method checkForUpdates.

@Override
public HostUpgradeManagerResult checkForUpdates(final VDS host) {
    AnsibleReturnValue ansibleReturnValue = null;
    try {
        AnsibleCommandBuilder command = new AnsibleCommandBuilder().hostnames(host.getHostName()).checkMode(true).enableLogging(false).verboseLevel(AnsibleVerbosity.LEVEL0).stdoutCallback(AnsibleConstants.HOST_UPGRADE_CALLBACK_PLUGIN).playbook(AnsibleConstants.HOST_UPGRADE_PLAYBOOK);
        ansibleReturnValue = ansibleExecutor.runCommand(command);
        if (ansibleReturnValue.getAnsibleReturnCode() != AnsibleReturnCode.OK) {
            String error = String.format("Failed to run check-update of host '%1$s'.", host.getHostName());
            log.error(error);
            throw new RuntimeException(error);
        }
        List<String> availablePackages = JsonHelper.jsonToList(ansibleReturnValue.getStdout());
        boolean updatesAvailable = !availablePackages.isEmpty();
        HostUpgradeManagerResult hostUpgradeManagerResult = new HostUpgradeManagerResult();
        hostUpgradeManagerResult.setUpdatesAvailable(updatesAvailable);
        if (updatesAvailable) {
            hostUpgradeManagerResult.setAvailablePackages(availablePackages);
            log.info("There are available package updates ({}) for host '{}'", StringUtils.join(availablePackages, ", "), host.getHostName());
            AuditLogable auditLog = new AuditLogableImpl();
            auditLog.setVdsId(host.getId());
            auditLog.setVdsName(host.getName());
            if (availablePackages.isEmpty()) {
                auditLogDirector.log(auditLog, AuditLogType.HOST_UPDATES_ARE_AVAILABLE);
            } else {
                if (availablePackages.size() > MAX_NUM_OF_DISPLAYED_UPDATES) {
                    auditLog.addCustomValue("Packages", String.format("%1$s and %2$s others. To see all packages check engine.log.", StringUtils.join(availablePackages.subList(0, MAX_NUM_OF_DISPLAYED_UPDATES), ", "), availablePackages.size() - MAX_NUM_OF_DISPLAYED_UPDATES));
                } else {
                    auditLog.addCustomValue("Packages", StringUtils.join(availablePackages, ", "));
                }
                auditLogDirector.log(auditLog, AuditLogType.HOST_UPDATES_ARE_AVAILABLE_WITH_PACKAGES);
            }
        }
        return hostUpgradeManagerResult;
    } catch (final IOException e) {
        log.error("Failed to read host packages: {}", e.getMessage());
        if (ansibleReturnValue != null) {
            log.debug("Ansible packages output: {}", ansibleReturnValue.getStdout());
        }
        throw new RuntimeException(e.getMessage(), e);
    } catch (final Exception e) {
        throw new RuntimeException(e.getMessage(), e);
    }
}
Also used : HostUpgradeManagerResult(org.ovirt.engine.core.common.HostUpgradeManagerResult) AnsibleReturnValue(org.ovirt.engine.core.common.utils.ansible.AnsibleReturnValue) AuditLogable(org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogable) AnsibleCommandBuilder(org.ovirt.engine.core.common.utils.ansible.AnsibleCommandBuilder) AuditLogableImpl(org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogableImpl) IOException(java.io.IOException) IOException(java.io.IOException)

Example 3 with HostUpgradeManagerResult

use of org.ovirt.engine.core.common.HostUpgradeManagerResult in project ovirt-engine by oVirt.

the class OvirtNodeUpgradeManager method checkForUpdates.

@Override
public HostUpgradeManagerResult checkForUpdates(VDS host) {
    QueryReturnValue returnValue = backendInternal.runInternalQuery(QueryType.GetoVirtISOs, new IdQueryParameters(host.getId()));
    List<RpmVersion> isos = returnValue.getReturnValue();
    boolean updateAvailable = RpmVersionUtils.isUpdateAvailable(isos, host.getHostOs());
    HostUpgradeManagerResult hostUpgradeManagerResult = new HostUpgradeManagerResult();
    hostUpgradeManagerResult.setUpdatesAvailable(updateAvailable);
    if (updateAvailable) {
        AuditLogable auditLog = new AuditLogableImpl();
        auditLog.setVdsName(host.getName());
        auditLog.setVdsId(host.getId());
        auditLog.setClusterName(host.getClusterName());
        auditLog.setClusterId(host.getClusterId());
        auditLogDirector.log(auditLog, AuditLogType.HOST_UPDATES_ARE_AVAILABLE);
    }
    return hostUpgradeManagerResult;
}
Also used : HostUpgradeManagerResult(org.ovirt.engine.core.common.HostUpgradeManagerResult) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) IdQueryParameters(org.ovirt.engine.core.common.queries.IdQueryParameters) AuditLogable(org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogable) AuditLogableImpl(org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogableImpl) RpmVersion(org.ovirt.engine.core.compat.RpmVersion)

Example 4 with HostUpgradeManagerResult

use of org.ovirt.engine.core.common.HostUpgradeManagerResult in project ovirt-engine by oVirt.

the class HostUpdatesChecker method checkForUpdates.

public HostUpgradeManagerResult checkForUpdates(VDS host) {
    AuditLogable auditLog = new AuditLogableImpl();
    auditLog.setVdsName(host.getName());
    auditLog.setVdsId(host.getId());
    if (!vdsDynamicDao.get(host.getId()).getStatus().isEligibleForOnDemandCheckUpdates()) {
        log.warn("Check for available updates is skipped for host '{}' due to unsupported host status '{}' ", host.getName(), host.getStatus());
        auditLogDirector.log(auditLog, AuditLogType.HOST_AVAILABLE_UPDATES_SKIPPED_UNSUPPORTED_STATUS);
        return null;
    }
    HostUpgradeManagerResult updatesResult = null;
    try {
        updatesResult = availableUpdatesFinder.checkForUpdates(host);
        if (updatesResult.isUpdatesAvailable()) {
            List<String> availablePackages = updatesResult.getAvailablePackages();
            String message;
            if (availablePackages.size() > HostUpgradeManager.MAX_NUM_OF_DISPLAYED_UPDATES) {
                message = String.format("%1$s and %2$s others. To see all packages check engine.log.", StringUtils.join(availablePackages.subList(0, HostUpgradeManager.MAX_NUM_OF_DISPLAYED_UPDATES), ", "), availablePackages.size() - HostUpgradeManager.MAX_NUM_OF_DISPLAYED_UPDATES);
            } else {
                message = String.format("found updates for packages %s", StringUtils.join(updatesResult.getAvailablePackages(), ", "));
            }
            auditLog.addCustomValue("Message", message);
        } else {
            auditLog.addCustomValue("Message", "no updates found.");
        }
        auditLogDirector.log(auditLog, AuditLogType.HOST_AVAILABLE_UPDATES_FINISHED);
    } catch (IllegalStateException e) {
        log.warn(e.getMessage());
        auditLogDirector.log(auditLog, AuditLogType.HOST_AVAILABLE_UPDATES_PROCESS_IS_ALREADY_RUNNING);
    } catch (Exception e) {
        log.error("Failed to check if updates are available for host '{}' with error message '{}'", host.getName(), e.getMessage());
        log.debug("Exception", e);
        auditLog.addCustomValue("Message", StringUtils.defaultString(e.getMessage(), e.getCause() == null ? null : e.getCause().toString()));
        auditLogDirector.log(auditLog, AuditLogType.HOST_AVAILABLE_UPDATES_FAILED);
    }
    if (updatesResult != null && updatesResult.isUpdatesAvailable() != host.isUpdateAvailable()) {
        VdsManager hostManager = resourceManager.getVdsManager(host.getId());
        synchronized (hostManager) {
            hostManager.updateUpdateAvailable(updatesResult.isUpdatesAvailable());
        }
    }
    return updatesResult;
}
Also used : HostUpgradeManagerResult(org.ovirt.engine.core.common.HostUpgradeManagerResult) AuditLogable(org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogable) VdsManager(org.ovirt.engine.core.vdsbroker.VdsManager) AuditLogableImpl(org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogableImpl)

Aggregations

HostUpgradeManagerResult (org.ovirt.engine.core.common.HostUpgradeManagerResult)4 AuditLogable (org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogable)3 AuditLogableImpl (org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogableImpl)3 IOException (java.io.IOException)1 IdQueryParameters (org.ovirt.engine.core.common.queries.IdQueryParameters)1 QueryReturnValue (org.ovirt.engine.core.common.queries.QueryReturnValue)1 AnsibleCommandBuilder (org.ovirt.engine.core.common.utils.ansible.AnsibleCommandBuilder)1 AnsibleReturnValue (org.ovirt.engine.core.common.utils.ansible.AnsibleReturnValue)1 RpmVersion (org.ovirt.engine.core.compat.RpmVersion)1 VdsManager (org.ovirt.engine.core.vdsbroker.VdsManager)1