Search in sources :

Example 6 with UpdateVdsActionParameters

use of org.ovirt.engine.core.common.action.hostdeploy.UpdateVdsActionParameters in project ovirt-engine by oVirt.

the class RegisterVdsQuery method updateExistingHost.

private boolean updateExistingHost(VDS vds, boolean pending) {
    boolean returnValue = true;
    vds.setHostName(vds.getHostName());
    vds.setPort(getParameters().getVdsPort());
    log.debug("RegisterVdsQuery::register - Will try now to update VDS with existing unique id; Name: '{}', Hostname: '{}', Unique: '{}', VdsPort: '{}', isPending: '{}' with force synchronize", getParameters().getVdsHostName(), getStrippedVdsUniqueId(), getStrippedVdsUniqueId(), getParameters().getVdsPort(), pending);
    UpdateVdsActionParameters p = new UpdateVdsActionParameters(vds.getStaticData(), "", false);
    p.setInstallHost(!pending);
    p.setReinstallOrUpgrade(!pending);
    p.setAuthMethod(VdsOperationActionParameters.AuthenticationMethod.PublicKey);
    if (vds.isFenceAgentsExist()) {
        p.setFenceAgents(vds.getFenceAgents());
    }
    p.setTransactionScopeOption(TransactionScopeOption.RequiresNew);
    ActionReturnValue rc = Backend.getInstance().runInternalAction(ActionType.UpdateVds, p);
    if (!rc.getSucceeded()) {
        error = AuditLogType.VDS_REGISTER_EXISTING_VDS_UPDATE_FAILED;
        log.debug("RegisterVdsQuery::register - Failed to update existing VDS Name: '{}', Hostname: '{}', Unique: '{}', VdsPort: '{}', isPending: '{}'", getParameters().getVdsHostName(), getStrippedVdsUniqueId(), getStrippedVdsUniqueId(), getParameters().getVdsPort(), pending);
        captureCommandErrorsToLogger(rc, "RegisterVdsQuery::register");
        returnValue = false;
    } else {
        log.info("RegisterVdsQuery::register - Updated a '{}' registered VDS - Name: '{}', Hostname: '{}', UniqueID: '{}'", vds.getStatus() == VDSStatus.PendingApproval ? "Pending " : "", getParameters().getVdsName(), getParameters().getVdsHostName(), getStrippedVdsUniqueId());
    }
    return returnValue;
}
Also used : UpdateVdsActionParameters(org.ovirt.engine.core.common.action.hostdeploy.UpdateVdsActionParameters) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue)

Example 7 with UpdateVdsActionParameters

use of org.ovirt.engine.core.common.action.hostdeploy.UpdateVdsActionParameters in project ovirt-engine by oVirt.

the class RegisterVdsQuery method handleOldVdssWithSameName.

/**
 * Check if another host has the same name as hostToRegister and if yes append a number to it. Eventually if the
 * host is in the db, persist the changes.
 */
private boolean handleOldVdssWithSameName(VDS hostToRegister) {
    log.debug("Entering");
    boolean returnValue = true;
    VDS storedHost = vdsDao.getByName(getParameters().getVdsName());
    List<String> allHostNames = getAllHostNames(vdsDao.getAll());
    boolean hostExistInDB = hostToRegister != null;
    if (storedHost != null) {
        log.debug("found VDS with the same name {0}.  Will try to register with a new name", getParameters().getVdsName());
        String nameToRegister = getParameters().getVdsName();
        String uniqueIdToRegister = getParameters().getVdsUniqueId();
        String newName;
        // check different uniqueIds but same name
        if (!uniqueIdToRegister.equals(storedHost.getUniqueId()) && nameToRegister.equals(storedHost.getName())) {
            if (hostExistInDB) {
                // update the registered host if exist in db
                allHostNames.remove(hostToRegister.getName());
                newName = generateUniqueName(nameToRegister, allHostNames);
                hostToRegister.setVdsName(newName);
                UpdateVdsActionParameters parameters = new UpdateVdsActionParameters(hostToRegister.getStaticData(), "", false);
                if (hostToRegister.isFenceAgentsExist()) {
                    parameters.setFenceAgents(hostToRegister.getFenceAgents());
                }
                ActionReturnValue ret = Backend.getInstance().runInternalAction(ActionType.UpdateVds, parameters);
                if (!ret.getSucceeded()) {
                    error = AuditLogType.VDS_REGISTER_ERROR_UPDATING_NAME;
                    logable.addCustomValue("VdsName2", newName);
                    log.error("could not update VDS '{}'", nameToRegister);
                    captureCommandErrorsToLogger(ret, "RegisterVdsQuery::handleOldVdssWithSameName");
                    return false;
                } else {
                    log.info("Another VDS was using this name with IP '{}'. Changed to '{}'", nameToRegister, newName);
                }
            } else {
                // host doesn't exist in db yet. not persisting changes just object values.
                newName = generateUniqueName(nameToRegister, allHostNames);
                getParameters().setVdsName(newName);
            }
        }
    }
    log.debug("Leaving with value '{}'", returnValue);
    return returnValue;
}
Also used : VDS(org.ovirt.engine.core.common.businessentities.VDS) UpdateVdsActionParameters(org.ovirt.engine.core.common.action.hostdeploy.UpdateVdsActionParameters) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue)

Aggregations

UpdateVdsActionParameters (org.ovirt.engine.core.common.action.hostdeploy.UpdateVdsActionParameters)7 ActionReturnValue (org.ovirt.engine.core.common.action.ActionReturnValue)5 VDS (org.ovirt.engine.core.common.businessentities.VDS)5 ChangeVDSClusterParameters (org.ovirt.engine.core.common.action.ChangeVDSClusterParameters)2 AddVdsActionParameters (org.ovirt.engine.core.common.action.hostdeploy.AddVdsActionParameters)2 ExternalComputeResource (org.ovirt.engine.core.common.businessentities.ExternalComputeResource)2 ExternalDiscoveredHost (org.ovirt.engine.core.common.businessentities.ExternalDiscoveredHost)2 ExternalHostGroup (org.ovirt.engine.core.common.businessentities.ExternalHostGroup)2 HostedEngineDeployConfiguration (org.ovirt.engine.core.common.businessentities.HostedEngineDeployConfiguration)2 Guid (org.ovirt.engine.core.compat.Guid)2 JsSingleValueStringObject (org.ovirt.engine.ui.frontend.utils.JsSingleValueStringObject)2 Window (com.google.gwt.user.client.Window)1 Inject (com.google.inject.Inject)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1