Search in sources :

Example 11 with AuditLogableBase

use of org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogableBase in project ovirt-engine by oVirt.

the class RestartVdsVmsOperation method restartVms.

/**
 * Changes status of specified VMs to Down and starts HA VMs on another hosts
 *
 * @param vms list of VM to stopped/restarted
 */
public void restartVms(List<VM> vms) {
    List<Guid> autoStartVmIdsToRerun = new ArrayList<>();
    // restart all running vms of a failed vds.
    for (VM vm : vms) {
        destroyVmOnDestination(vm);
        VDSReturnValue returnValue = Backend.getInstance().getResourceManager().runVdsCommand(VDSCommandType.SetVmStatus, new SetVmStatusVDSCommandParameters(vm.getId(), VMStatus.Down, VmExitStatus.Error));
        // Write that this VM was shut down by host reboot or manual fence
        if (returnValue != null && returnValue.getSucceeded()) {
            Injector.get(AuditLogDirector.class).log(Injector.injectMembers(new AuditLogableBase(vds.getId(), vm.getId())), AuditLogType.VM_WAS_SET_DOWN_DUE_TO_HOST_REBOOT_OR_MANUAL_FENCE);
        }
        Backend.getInstance().runInternalAction(ActionType.ProcessDownVm, new ProcessDownVmParameters(vm.getId(), true), ExecutionHandler.createDefaultContextForTasks(commandContext));
        // Handle highly available VMs
        if (vm.isAutoStartup()) {
            autoStartVmIdsToRerun.add(vm.getId());
        }
    }
    if (!autoStartVmIdsToRerun.isEmpty()) {
        Injector.get(HaAutoStartVmsRunner.class).addVmsToRun(autoStartVmIdsToRerun);
    }
}
Also used : AuditLogableBase(org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogableBase) ProcessDownVmParameters(org.ovirt.engine.core.common.action.ProcessDownVmParameters) VM(org.ovirt.engine.core.common.businessentities.VM) SetVmStatusVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.SetVmStatusVDSCommandParameters) ArrayList(java.util.ArrayList) Guid(org.ovirt.engine.core.compat.Guid) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue) AuditLogDirector(org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogDirector)

Example 12 with AuditLogableBase

use of org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogableBase in project ovirt-engine by oVirt.

the class QuotaManager method consume.

/**
 * Consume from quota according to the parameters.
 *
 * @param parameters
 *            - Quota consumption parameters
 * @return - true if the request was validated and set
 */
public boolean consume(QuotaConsumptionParametersWrapper parameters) throws InvalidQuotaParametersException {
    Pair<AuditLogType, AuditLogableBase> auditLogPair = new Pair<>();
    auditLogPair.setSecond(parameters.getAuditLogable());
    StoragePool storagePool = parameters.getAuditLogable().getStoragePool();
    if (storagePool == null) {
        throw new InvalidQuotaParametersException("Null storage pool passed to QuotaManager");
    }
    addStoragePoolToCacheWithLock(storagePool.getId());
    lock.readLock().lock();
    try {
        if (parameters.getStoragePool().getQuotaEnforcementType() != QuotaEnforcementTypeEnum.DISABLED) {
            synchronized (storagePoolQuotaMap.get(storagePool.getId())) {
                return validateAndCompleteParameters(parameters, auditLogPair) && internalConsumeAndReleaseHandler(parameters, auditLogPair);
            }
        }
    } finally {
        lock.readLock().unlock();
        getQuotaManagerAuditLogger().auditLog(auditLogPair.getFirst(), auditLogPair.getSecond());
    }
    return true;
}
Also used : AuditLogableBase(org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogableBase) AuditLogType(org.ovirt.engine.core.common.AuditLogType) StoragePool(org.ovirt.engine.core.common.businessentities.StoragePool) Pair(org.ovirt.engine.core.common.utils.Pair)

Example 13 with AuditLogableBase

use of org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogableBase in project ovirt-engine by oVirt.

the class RegisterVdsQuery method reportClusterError.

private void reportClusterError() {
    log.error("No default or valid cluster was found, host registration failed.");
    AuditLogableBase logableBase = Injector.injectMembers(new AuditLogableBase());
    logableBase.setVdsId(getParameters().getVdsId());
    auditLogDirector.log(logableBase, AuditLogType.HOST_REGISTRATION_FAILED_INVALID_CLUSTER);
}
Also used : AuditLogableBase(org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogableBase)

Example 14 with AuditLogableBase

use of org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogableBase in project ovirt-engine by oVirt.

the class RegisterVdsQuery method validateInputs.

@Override
protected boolean validateInputs() {
    if (!super.validateInputs()) {
        return false;
    }
    QueryReturnValue returnValue = getQueryReturnValue();
    returnValue.setExceptionString("");
    try {
        String hostName = getParameters().getVdsHostName();
        if (StringUtils.isEmpty(hostName)) {
            returnValue.setExceptionString("Cannot register Host - no Hostname address specified.");
            return false;
        }
        String vdsUniqueId = getParameters().getVdsUniqueId();
        if (StringUtils.isEmpty(vdsUniqueId)) {
            returnValue.setExceptionString(String.format("Cannot register host '%1$s' - host id is empty.", hostName));
            AuditLogableBase logable = Injector.injectMembers(new AuditLogableBase());
            logable.addCustomValue("VdsHostName", hostName);
            auditLogDirector.log(logable, AuditLogType.VDS_REGISTER_EMPTY_ID);
            return false;
        }
        List<VDS> vdssByUniqueId = getVdssByUniqueId();
        if (vdssByUniqueId.size() > 1) {
            returnValue.setExceptionString("Cannot register Host - unique id is ambigious.");
            return false;
        }
        if (vdssByUniqueId.size() == 1) {
            VDS vds = vdssByUniqueId.get(0);
            if (!VdsHandler.isPendingOvirt(vds)) {
                returnValue.setExceptionString(EngineMessage.VDS_STATUS_NOT_VALID_FOR_UPDATE.name());
                return false;
            }
        }
    } catch (RuntimeException ex) {
        log.error("Exception", ex);
        returnValue.setExceptionString(String.format("Cannot register Host - An exception has been thrown: %1$s", ex.getMessage()));
        return false;
    }
    return true;
}
Also used : AuditLogableBase(org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogableBase) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) VDS(org.ovirt.engine.core.common.businessentities.VDS)

Example 15 with AuditLogableBase

use of org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogableBase in project ovirt-engine by oVirt.

the class ConnectStorageServerVDSCommand method logFailedStorageConnections.

private void logFailedStorageConnections(Map<String, String> returnValue) {
    StringBuilder failedDomainNames = new StringBuilder();
    String namesSeparator = ",";
    for (Entry<String, String> result : returnValue.entrySet()) {
        if (!"0".equals(result.getValue())) {
            List<StorageDomain> domains = DbFacade.getInstance().getStorageDomainDao().getAllByConnectionId(new Guid(result.getKey()));
            if (!domains.isEmpty()) {
                for (StorageDomain domain : domains) {
                    if (failedDomainNames.length() > 0) {
                        failedDomainNames.append(namesSeparator);
                    }
                    failedDomainNames.append(domain.getStorageName());
                }
            }
        }
    }
    if (failedDomainNames.length() > 0) {
        AuditLogableBase logable = Injector.injectMembers(new AuditLogableBase(getParameters().getVdsId()));
        logable.addCustomValue("failedStorageDomains", failedDomainNames.toString());
        auditLogDirector.log(logable, AuditLogType.VDS_STORAGES_CONNECTION_FAILED);
    }
}
Also used : AuditLogableBase(org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogableBase) StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) Guid(org.ovirt.engine.core.compat.Guid)

Aggregations

AuditLogableBase (org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogableBase)22 AuditLogType (org.ovirt.engine.core.common.AuditLogType)3 VmDynamic (org.ovirt.engine.core.common.businessentities.VmDynamic)2 Guid (org.ovirt.engine.core.compat.Guid)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 Before (org.junit.Before)1 ProcessDownVmParameters (org.ovirt.engine.core.common.action.ProcessDownVmParameters)1 AuditLog (org.ovirt.engine.core.common.businessentities.AuditLog)1 StorageDomain (org.ovirt.engine.core.common.businessentities.StorageDomain)1 StoragePool (org.ovirt.engine.core.common.businessentities.StoragePool)1 VDS (org.ovirt.engine.core.common.businessentities.VDS)1 VM (org.ovirt.engine.core.common.businessentities.VM)1 VmBalloonInfo (org.ovirt.engine.core.common.businessentities.VmBalloonInfo)1 QueryReturnValue (org.ovirt.engine.core.common.queries.QueryReturnValue)1 Pair (org.ovirt.engine.core.common.utils.Pair)1 SetVmStatusVDSCommandParameters (org.ovirt.engine.core.common.vdscommands.SetVmStatusVDSCommandParameters)1 VDSReturnValue (org.ovirt.engine.core.common.vdscommands.VDSReturnValue)1 AuditLogDirector (org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogDirector)1