Kanagaraj M has uploaded a new change for review. Change subject: gluster: [WIP] fix remove host ......................................................................
gluster: [WIP] fix remove host . Change-Id: I785beb895f0fb72bc486055c666936073b5a5d59 Bug-Url: https://bugzilla.redhat.com/1050135 Signed-off-by: Kanagaraj M <[email protected]> --- M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/InitVdsOnUpCommand.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveVdsCommand.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/utils/GlusterUtil.java 3 files changed, 82 insertions(+), 48 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/52/23152/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/InitVdsOnUpCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/InitVdsOnUpCommand.java index abaecf2..7194d42 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/InitVdsOnUpCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/InitVdsOnUpCommand.java @@ -1,7 +1,5 @@ package org.ovirt.engine.core.bll; -import java.net.InetAddress; -import java.net.UnknownHostException; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -34,7 +32,6 @@ import org.ovirt.engine.core.common.businessentities.VdsSpmStatus; import org.ovirt.engine.core.common.businessentities.gluster.GlusterServer; import org.ovirt.engine.core.common.businessentities.gluster.GlusterServerInfo; -import org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface; import org.ovirt.engine.core.common.config.Config; import org.ovirt.engine.core.common.config.ConfigValues; import org.ovirt.engine.core.common.errors.VDSError; @@ -59,7 +56,6 @@ import org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogDirector; import org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogableBase; import org.ovirt.engine.core.dao.gluster.GlusterServerDao; -import org.ovirt.engine.core.dao.network.InterfaceDao; import org.ovirt.engine.core.utils.ejb.BeanProxyType; import org.ovirt.engine.core.utils.ejb.BeanType; import org.ovirt.engine.core.utils.ejb.EjbUtils; @@ -403,7 +399,8 @@ customLogValues.put("Command", "gluster peer status"); setNonOperational(NonOperationalReason.GLUSTER_COMMAND_FAILED, customLogValues); return false; - } else if (!hostExists(glusterServers, getVds())) { + } + else if (!getGlusterUtil().isHostExists(glusterServers, getVds())) { if (!glusterPeerProbe(upServer.getId(), getVds().getHostName())) { customLogValues.put("Command", "gluster peer probe " + getVds().getHostName()); setNonOperational(NonOperationalReason.GLUSTER_COMMAND_FAILED, customLogValues); @@ -421,7 +418,7 @@ return true; } List<GlusterServerInfo> newGlusterServers = getGlusterPeers(newUpServer.getId()); - if (!hostExists(newGlusterServers, getVds())) { + if (!getGlusterUtil().isHostExists(newGlusterServers, getVds())) { log.infoFormat("Failed to find host {0} in gluster peer list from {1} on attempt {2}" , getVds(), newUpServer, ++retries); // if num of attempts done if (retries == MAX_RETRIES_GLUSTER_PROBE_STATUS) { @@ -446,6 +443,10 @@ } } + private GlusterUtil getGlusterUtil() { + return GlusterUtil.getInstance(); + } + private VDS getNewUpServer(VDS upServer) { List<VDS> vdsList = getVdsDAO().getAllForVdsGroupWithStatus(getVdsGroupId(), VDSStatus.Up); VDS newUpServer = null; @@ -456,39 +457,6 @@ } } return newUpServer; - } - - private boolean hostExists(List<GlusterServerInfo> glusterServers, VDS server) { - if (GlusterFeatureSupported.glusterHostUuidSupported(getVdsGroup().getcompatibility_version())) { - GlusterServer glusterServer = DbFacade.getInstance().getGlusterServerDao().getByServerId(server.getId()); - if (glusterServer != null) { - for (GlusterServerInfo glusterServerInfo : glusterServers) { - if (glusterServerInfo.getUuid().equals(glusterServer.getGlusterServerUuid())) { - return true; - } - } - } - } - else { - for (GlusterServerInfo glusterServer : glusterServers) { - if (glusterServer.getHostnameOrIp().equals(server.getHostName())) { - return true; - } - try { - String glusterHostAddr = InetAddress.getByName(glusterServer.getHostnameOrIp()).getHostAddress(); - for (VdsNetworkInterface vdsNwInterface : getVdsInterfaces(server.getId())) { - if (glusterHostAddr.equals(vdsNwInterface.getAddress())) { - return true; - } - } - } catch (UnknownHostException e) { - log.errorFormat("Could not resole IP address of the host {0}. Error: {1}", - glusterServer.getHostnameOrIp(), - e.getMessage()); - } - } - } - return false; } private boolean hostUuidExists(Guid addedServerUuid) { @@ -509,15 +477,6 @@ glusterServer.setGlusterServerUuid(addedServerUuid); glusterServerDao.save(glusterServer); } - } - - public InterfaceDao getInterfaceDAO() { - return getDbFacade().getInterfaceDao(); - } - - private List<VdsNetworkInterface> getVdsInterfaces(Guid vdsId) { - List<VdsNetworkInterface> interfaces = getInterfaceDAO().getAllInterfacesForVds(vdsId); - return (interfaces == null) ? new ArrayList<VdsNetworkInterface>() : interfaces; } @SuppressWarnings("unchecked") diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveVdsCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveVdsCommand.java index 324c405..bebd2b5 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveVdsCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveVdsCommand.java @@ -13,6 +13,7 @@ import org.ovirt.engine.core.common.businessentities.StorageType; import org.ovirt.engine.core.common.businessentities.VDS; import org.ovirt.engine.core.common.businessentities.VDSStatus; +import org.ovirt.engine.core.common.businessentities.gluster.GlusterServerInfo; import org.ovirt.engine.core.common.errors.VdcBllErrors; import org.ovirt.engine.core.common.errors.VdcBllMessages; import org.ovirt.engine.core.common.locks.LockingGroup; @@ -20,6 +21,7 @@ import org.ovirt.engine.core.common.vdscommands.RemoveVdsVDSCommandParameters; import org.ovirt.engine.core.common.vdscommands.VDSCommandType; import org.ovirt.engine.core.common.vdscommands.VDSReturnValue; +import org.ovirt.engine.core.common.vdscommands.VdsIdVDSCommandParametersBase; import org.ovirt.engine.core.common.vdscommands.gluster.RemoveGlusterServerVDSParameters; import org.ovirt.engine.core.compat.Guid; import org.ovirt.engine.core.dao.VdsDynamicDAO; @@ -227,6 +229,20 @@ setSucceeded(returnValue.getSucceeded() || VdcBllErrors.GlusterHostIsNotPartOfCluster == returnValue.getVdsError().getCode()); if (!getSucceeded()) { + // VDSM in 3.3 (or less) cluster will return GlusterHostRemoveFailedException + // if the host is not part of the cluster + // So if peer detach is failed, check the peer list to decide that the host is not part of the + // cluster + + if (returnValue.getVdsError().getCode() == VdcBllErrors.GlusterHostRemoveFailedException) { + List<GlusterServerInfo> glusterServers = getGlusterPeers(upServer); + if (glusterServers != null) { + if (!GlusterUtil.getInstance().isHostExists(glusterServers, getVds())) { + setSucceeded(true); + return; + } + } + } getReturnValue().getFault().setError(returnValue.getVdsError().getCode()); getReturnValue().getFault().setMessage(returnValue.getVdsError().getMessage()); errorType = AuditLogType.GLUSTER_SERVER_REMOVE_FAILED; @@ -236,6 +252,17 @@ } } + private List<GlusterServerInfo> getGlusterPeers(VDS upServer) { + VDSReturnValue returnValue = runVdsCommand(VDSCommandType.GlusterServersList, + new VdsIdVDSCommandParametersBase(upServer.getId())); + if (returnValue.getSucceeded()) { + return (List<GlusterServerInfo>) returnValue.getReturnValue(); + } + else { + return null; + } + } + private boolean clusterHasMultipleHosts() { return getClusterUtils().hasMultipleServers(getVdsGroupId()); } diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/utils/GlusterUtil.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/utils/GlusterUtil.java index cda3667..41efb49 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/utils/GlusterUtil.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/utils/GlusterUtil.java @@ -2,8 +2,12 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; +import java.util.List; import java.util.Map; import java.util.Set; @@ -13,15 +17,21 @@ import org.ovirt.engine.core.bll.Backend; import org.ovirt.engine.core.bll.LockMessagesMatchUtil; import org.ovirt.engine.core.bll.interfaces.BackendInternal; +import org.ovirt.engine.core.common.businessentities.VDS; +import org.ovirt.engine.core.common.businessentities.gluster.GlusterServer; +import org.ovirt.engine.core.common.businessentities.gluster.GlusterServerInfo; +import org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface; import org.ovirt.engine.core.common.config.Config; import org.ovirt.engine.core.common.config.ConfigValues; import org.ovirt.engine.core.common.errors.VdcBllMessages; +import org.ovirt.engine.core.common.gluster.GlusterFeatureSupported; import org.ovirt.engine.core.common.locks.LockingGroup; import org.ovirt.engine.core.common.queries.ServerParameters; import org.ovirt.engine.core.common.queries.VdcQueryReturnValue; import org.ovirt.engine.core.common.queries.VdcQueryType; import org.ovirt.engine.core.common.utils.Pair; import org.ovirt.engine.core.compat.Guid; +import org.ovirt.engine.core.dal.dbbroker.DbFacade; import org.ovirt.engine.core.utils.XmlUtils; import org.ovirt.engine.core.utils.lock.EngineLock; import org.ovirt.engine.core.utils.lock.LockManagerFactory; @@ -211,4 +221,42 @@ LockManagerFactory.getLockManager().acquireLockWait(lock); return lock; } + + public boolean isHostExists(List<GlusterServerInfo> glusterServers, VDS server) { + if (GlusterFeatureSupported.glusterHostUuidSupported(server.getVdsGroupCompatibilityVersion())) { + GlusterServer glusterServer = DbFacade.getInstance().getGlusterServerDao().getByServerId(server.getId()); + if (glusterServer != null) { + for (GlusterServerInfo glusterServerInfo : glusterServers) { + if (glusterServerInfo.getUuid().equals(glusterServer.getGlusterServerUuid())) { + return true; + } + } + } + } + else { + for (GlusterServerInfo glusterServer : glusterServers) { + if (glusterServer.getHostnameOrIp().equals(server.getHostName())) { + return true; + } + try { + String glusterHostAddr = InetAddress.getByName(glusterServer.getHostnameOrIp()).getHostAddress(); + for (VdsNetworkInterface vdsNwInterface : getVdsInterfaces(server.getId())) { + if (glusterHostAddr.equals(vdsNwInterface.getAddress())) { + return true; + } + } + } catch (UnknownHostException e) { + log.errorFormat("Could not resole IP address of the host {0}. Error: {1}", + glusterServer.getHostnameOrIp(), + e.getMessage()); + } + } + } + return false; + } + + private List<VdsNetworkInterface> getVdsInterfaces(Guid vdsId) { + List<VdsNetworkInterface> interfaces = DbFacade.getInstance().getInterfaceDao().getAllInterfacesForVds(vdsId); + return (interfaces == null) ? new ArrayList<VdsNetworkInterface>() : interfaces; + } } -- To view, visit http://gerrit.ovirt.org/23152 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I785beb895f0fb72bc486055c666936073b5a5d59 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Kanagaraj M <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
