Search in sources :

Example 1 with VdsManager

use of org.ovirt.engine.core.vdsbroker.VdsManager in project ovirt-engine by oVirt.

the class SshSoftFencingCommand method checkIfHostBecomeUp.

/**
 * Check if host become Up after successful SSH Soft Fencing execution until grace period is over
 *
 * @return {@code true} if host became Up during grace period, otherwise {@code false}
 */
private boolean checkIfHostBecomeUp() {
    VdsManager vdsManager = getResourceManager().getVdsManager(getVdsId());
    long sleepInterval = TimeUnit.SECONDS.toMillis(Config.<Long>getValue(ConfigValues.VdsRefreshRate));
    while (vdsManager.isHostInGracePeriod(true)) {
        if (vdsManager.getCopyVds().getStatus() == VDSStatus.Up) {
            // host became Up during grace period
            return true;
        }
        // wait until next host monitoring attempt
        ThreadUtils.sleep(sleepInterval);
    }
    return false;
}
Also used : VdsManager(org.ovirt.engine.core.vdsbroker.VdsManager)

Example 2 with VdsManager

use of org.ovirt.engine.core.vdsbroker.VdsManager in project ovirt-engine by oVirt.

the class HttpImageTaskVDSCommand method executeHttpMethod.

protected void executeHttpMethod(final T method) {
    int responseCode = -1;
    VdsManager manager = resourceManager.getVdsManager(getParameters().getVdsId());
    final HttpClient httpclient = manager.getVdsProxy().getHttpClient();
    try {
        FutureTask<Integer> futureTask = new FutureTask(() -> httpclient.executeMethod(method));
        Future<Integer> f = ThreadPoolUtil.execute(futureTask);
        if (f.get(Config.<Integer>getValue(getConfigValueTimeLimitForOperation()), TimeUnit.MINUTES) == null) {
            responseCode = futureTask.get();
        }
    } catch (InterruptedException e) {
        throw new RuntimeException(e);
    } catch (Exception e) {
        log.debug("Exception", e);
        throw createNetworkException(e);
    }
    if (responseCode == getSuccessCode()) {
        Guid createdTask = Guid.createGuidFromString(processResponseHeaderValue(getMethod(), "Task-Id", null));
        getVDSReturnValue().setCreationInfo(new AsyncTaskCreationInfo(createdTask, getCreatedTaskType(), getParameters().getStoragePoolId()));
        handleOkResponse();
        getVDSReturnValue().setSucceeded(true);
        return;
    }
    processResponseHeaderValue(getMethod(), "Content-type", "application/json");
    String response;
    try {
        response = getMethod().getResponseBodyAsString();
    } catch (Exception e) {
        throw createNetworkException(e);
    }
    Map<String, Object> resultMap = null;
    try {
        resultMap = new ObjectMapper().readValue(response, HashMap.class);
        status = new StatusOnlyReturn(resultMap);
    } catch (Exception e) {
        throwVdsErrorException("failed to parse response " + response, EngineError.GeneralException);
    }
    proceedProxyReturnValue();
}
Also used : HashMap(java.util.HashMap) AsyncTaskCreationInfo(org.ovirt.engine.core.common.asynctasks.AsyncTaskCreationInfo) Guid(org.ovirt.engine.core.compat.Guid) StatusOnlyReturn(org.ovirt.engine.core.vdsbroker.vdsbroker.StatusOnlyReturn) VDSErrorException(org.ovirt.engine.core.vdsbroker.vdsbroker.VDSErrorException) FutureTask(java.util.concurrent.FutureTask) HttpClient(org.apache.commons.httpclient.HttpClient) VdsManager(org.ovirt.engine.core.vdsbroker.VdsManager) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 3 with VdsManager

use of org.ovirt.engine.core.vdsbroker.VdsManager in project ovirt-engine by oVirt.

the class VdsBrokerCommand method initializeVdsBroker.

protected IVdsServer initializeVdsBroker(Guid vdsId) {
    VdsManager vdsmanager = Injector.get(ResourceManager.class).getVdsManager(vdsId);
    if (vdsmanager == null) {
        throw new EngineException(EngineError.RESOURCE_MANAGER_VDS_NOT_FOUND, String.format("Vds with id: %1$s was not found", vdsId));
    }
    setVdsAndVdsStatic(vdsmanager.getCopyVds());
    return vdsmanager.getVdsProxy();
}
Also used : VdsManager(org.ovirt.engine.core.vdsbroker.VdsManager) EngineException(org.ovirt.engine.core.common.errors.EngineException) ResourceManager(org.ovirt.engine.core.vdsbroker.ResourceManager)

Example 4 with VdsManager

use of org.ovirt.engine.core.vdsbroker.VdsManager 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)

Example 5 with VdsManager

use of org.ovirt.engine.core.vdsbroker.VdsManager in project ovirt-engine by oVirt.

the class PendingResourceManager method notifyHostManagers.

/**
 * Notify host manager that the pending memory and CPU data have changed.
 * This is automatically called when a VM or Host are cleared, however the user is responsible
 * for calling it after finished with adding all new pending resources for a VM.
 * @param hostId - it of the affected host
 */
public void notifyHostManagers(Guid hostId) {
    if (resourceManager == null) {
        return;
    }
    VdsManager vdsManager = resourceManager.getVdsManager(hostId);
    int pendingCpus = PendingCpuCores.collectForHost(this, hostId);
    int pendingMemory = PendingOvercommitMemory.collectForHost(this, hostId);
    vdsManager.updatePendingData(pendingMemory, pendingCpus);
}
Also used : VdsManager(org.ovirt.engine.core.vdsbroker.VdsManager)

Aggregations

VdsManager (org.ovirt.engine.core.vdsbroker.VdsManager)6 Certificate (java.security.cert.Certificate)1 X509Certificate (java.security.cert.X509Certificate)1 HashMap (java.util.HashMap)1 FutureTask (java.util.concurrent.FutureTask)1 HttpClient (org.apache.commons.httpclient.HttpClient)1 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)1 HostUpgradeManagerResult (org.ovirt.engine.core.common.HostUpgradeManagerResult)1 AsyncTaskCreationInfo (org.ovirt.engine.core.common.asynctasks.AsyncTaskCreationInfo)1 EngineException (org.ovirt.engine.core.common.errors.EngineException)1 Guid (org.ovirt.engine.core.compat.Guid)1 AuditLogable (org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogable)1 AuditLogableImpl (org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogableImpl)1 ResourceManager (org.ovirt.engine.core.vdsbroker.ResourceManager)1 StatusOnlyReturn (org.ovirt.engine.core.vdsbroker.vdsbroker.StatusOnlyReturn)1 VDSErrorException (org.ovirt.engine.core.vdsbroker.vdsbroker.VDSErrorException)1