Shireesh Anjal has uploaded a new change for review. Change subject: gluster: resolve hostname before checking ip in db ......................................................................
gluster: resolve hostname before checking ip in db At two places, we are checking if a server with given ip address exists in the engine DB. However it is possible that the value passed is a hostname, and it's not same as what is present in the host_name field. To handle such cases, modified the code to make sure that we resolve the given ip/hostname, and check for the resolved ip addr in db. As part of this change, performed following refactoring: - Renamed GlusterUtils to GlusterDBUtils and moved it to dao module - Modified the test case in GetAddedGlusterServersQueryTest accordingly Change-Id: Iab25afc5cb0acb5be288c005d1110c1ad0a54b2d Signed-off-by: Shireesh Anjal <san...@redhat.com> --- M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ChangeVDSClusterCommand.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GetAddedGlusterServersQuery.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterManager.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/StartGlusterVolumeCommand.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/StopGlusterVolumeCommand.java D backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/utils/GlusterUtils.java M backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/gluster/GetAddedGlusterServersQueryTest.java A backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterDBUtils.java M backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/gluster/GlusterVolumesListReturnForXmlRpc.java 9 files changed, 174 insertions(+), 150 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/21/12021/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ChangeVDSClusterCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ChangeVDSClusterCommand.java index 8c44f5b..6fc8731 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ChangeVDSClusterCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ChangeVDSClusterCommand.java @@ -6,7 +6,6 @@ import org.ovirt.engine.core.bll.context.CommandContext; import org.ovirt.engine.core.bll.utils.ClusterUtils; -import org.ovirt.engine.core.bll.utils.GlusterUtils; import org.ovirt.engine.core.bll.utils.PermissionSubject; import org.ovirt.engine.core.common.AuditLogType; import org.ovirt.engine.core.common.VdcObjectType; @@ -26,6 +25,7 @@ import org.ovirt.engine.core.compat.TransactionScopeOption; import org.ovirt.engine.core.dal.VdcBllMessages; import org.ovirt.engine.core.dal.dbbroker.DbFacade; +import org.ovirt.engine.core.dao.gluster.GlusterDBUtils; import org.ovirt.engine.core.utils.ObjectIdentityChecker; import org.ovirt.engine.core.utils.transaction.TransactionMethod; import org.ovirt.engine.core.utils.transaction.TransactionSupport; @@ -223,8 +223,8 @@ return ClusterUtils.getInstance(); } - private GlusterUtils getGlusterUtils() { - return GlusterUtils.getInstance(); + private GlusterDBUtils getGlusterUtils() { + return GlusterDBUtils.getInstance(); } private VDSGroup getSourceCluster() { diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GetAddedGlusterServersQuery.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GetAddedGlusterServersQuery.java index 0b040cb..7c8b47b 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GetAddedGlusterServersQuery.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GetAddedGlusterServersQuery.java @@ -16,13 +16,13 @@ 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.dao.gluster.GlusterDBUtils; import org.ovirt.engine.core.utils.ssh.EngineSSHDialog; /** * Query to get Added Gluster Servers with/without server ssh key fingerprint */ public class GetAddedGlusterServersQuery<P extends AddedGlusterServersParameters> extends QueriesCommandBase<P> { - public GetAddedGlusterServersQuery(P params) { super(params); } @@ -47,10 +47,9 @@ private Map<String, String> getAddedGlusterServers(List<GlusterServerInfo> glusterServers) { Map<String, String> serversAndFingerprint = new HashMap<String, String>(); - List<VDS> serversList = getClusterUtils().getVdsDao().getAllForVdsGroup(getParameters().getClusterId()); for (GlusterServerInfo server : glusterServers) { - if (server.getStatus() == PeerStatus.CONNECTED && (!serverExists(serversList, server))) { + if (server.getStatus() == PeerStatus.CONNECTED && (!serverExists(server))) { String fingerprint = null; if (getParameters().isServerKeyFingerprintRequired()) { fingerprint = getServerFingerprint(server.getHostnameOrIp()); @@ -64,15 +63,12 @@ return serversAndFingerprint; } - private boolean serverExists(List<VDS> serversList, GlusterServerInfo glusterServer) { - for (VDS server : serversList) { - String serverHostnameOrIp = - server.getHostName().isEmpty() ? server.getManagmentIp() : server.getHostName(); - if (serverHostnameOrIp.equalsIgnoreCase(glusterServer.getHostnameOrIp())) { - return true; - } - } - return false; + protected GlusterDBUtils getDbUtils() { + return GlusterDBUtils.getInstance(); + } + + private boolean serverExists(GlusterServerInfo glusterServer) { + return getDbUtils().serverExists(getParameters().getClusterId(), glusterServer.getHostnameOrIp()); } public String getServerFingerprint(String serverName) { diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterManager.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterManager.java index 9b13a9d..47082e9 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterManager.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterManager.java @@ -13,7 +13,6 @@ import org.ovirt.engine.core.bll.Backend; import org.ovirt.engine.core.bll.job.ExecutionHandler; import org.ovirt.engine.core.bll.utils.ClusterUtils; -import org.ovirt.engine.core.bll.utils.GlusterUtils; import org.ovirt.engine.core.common.AuditLogType; import org.ovirt.engine.core.common.action.SetNonOperationalVdsParameters; import org.ovirt.engine.core.common.action.VdcActionType; @@ -55,6 +54,7 @@ import org.ovirt.engine.core.dao.VdsStatisticsDAO; import org.ovirt.engine.core.dao.gluster.GlusterBrickDao; import org.ovirt.engine.core.dao.gluster.GlusterOptionDao; +import org.ovirt.engine.core.dao.gluster.GlusterDBUtils; import org.ovirt.engine.core.dao.gluster.GlusterVolumeDao; import org.ovirt.engine.core.dao.network.InterfaceDao; import org.ovirt.engine.core.utils.lock.EngineLock; @@ -768,7 +768,7 @@ if (existingVolume.getStatus() != fetchedVolume.getStatus()) { existingVolume.setStatus(fetchedVolume.getStatus()); - GlusterUtils.getInstance().updateVolumeStatus(existingVolume.getId(), fetchedVolume.getStatus()); + GlusterDBUtils.getInstance().updateVolumeStatus(existingVolume.getId(), fetchedVolume.getStatus()); logUtil.logVolumeMessage(existingVolume, fetchedVolume.getStatus() == GlusterStatus.UP ? AuditLogType.GLUSTER_VOLUME_STARTED_FROM_CLI : AuditLogType.GLUSTER_VOLUME_STOPPED_FROM_CLI); diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/StartGlusterVolumeCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/StartGlusterVolumeCommand.java index 67eab29..4363015 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/StartGlusterVolumeCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/StartGlusterVolumeCommand.java @@ -2,7 +2,6 @@ import org.ovirt.engine.core.bll.LockIdNameAttribute; import org.ovirt.engine.core.bll.NonTransactiveCommandAttribute; -import org.ovirt.engine.core.bll.utils.GlusterUtils; import org.ovirt.engine.core.common.AuditLogType; import org.ovirt.engine.core.common.action.gluster.GlusterVolumeActionParameters; import org.ovirt.engine.core.common.businessentities.gluster.GlusterStatus; @@ -11,6 +10,7 @@ import org.ovirt.engine.core.common.vdscommands.VDSReturnValue; import org.ovirt.engine.core.common.vdscommands.gluster.GlusterVolumeActionVDSParameters; import org.ovirt.engine.core.dal.VdcBllMessages; +import org.ovirt.engine.core.dao.gluster.GlusterDBUtils; /** * BLL command to start a Gluster volume @@ -55,7 +55,7 @@ getGlusterVolumeName(), getParameters().isForceAction())); setSucceeded(returnValue.getSucceeded()); if(getSucceeded()) { - GlusterUtils.getInstance().updateVolumeStatus(getParameters().getVolumeId(), GlusterStatus.UP); + GlusterDBUtils.getInstance().updateVolumeStatus(getParameters().getVolumeId(), GlusterStatus.UP); } else { handleVdsError(AuditLogType.GLUSTER_VOLUME_START_FAILED, returnValue.getVdsError().getMessage()); return; diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/StopGlusterVolumeCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/StopGlusterVolumeCommand.java index ef504e7..e837032 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/StopGlusterVolumeCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/StopGlusterVolumeCommand.java @@ -2,7 +2,6 @@ import org.ovirt.engine.core.bll.LockIdNameAttribute; import org.ovirt.engine.core.bll.NonTransactiveCommandAttribute; -import org.ovirt.engine.core.bll.utils.GlusterUtils; import org.ovirt.engine.core.common.AuditLogType; import org.ovirt.engine.core.common.action.gluster.GlusterVolumeActionParameters; import org.ovirt.engine.core.common.businessentities.gluster.GlusterStatus; @@ -11,6 +10,7 @@ import org.ovirt.engine.core.common.vdscommands.VDSReturnValue; import org.ovirt.engine.core.common.vdscommands.gluster.GlusterVolumeActionVDSParameters; import org.ovirt.engine.core.dal.VdcBllMessages; +import org.ovirt.engine.core.dao.gluster.GlusterDBUtils; /** * BLL command to stop a Gluster volume @@ -55,7 +55,7 @@ getGlusterVolumeName(), getParameters().isForceAction())); setSucceeded(returnValue.getSucceeded()); if (getSucceeded()) { - GlusterUtils.getInstance().updateVolumeStatus(getParameters().getVolumeId(), GlusterStatus.DOWN); + GlusterDBUtils.getInstance().updateVolumeStatus(getParameters().getVolumeId(), GlusterStatus.DOWN); } else { handleVdsError(AuditLogType.GLUSTER_VOLUME_STOP_FAILED, returnValue.getVdsError().getMessage()); return; diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/utils/GlusterUtils.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/utils/GlusterUtils.java deleted file mode 100644 index 14d8bf4..0000000 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/utils/GlusterUtils.java +++ /dev/null @@ -1,51 +0,0 @@ -package org.ovirt.engine.core.bll.utils; - -import org.ovirt.engine.core.common.businessentities.gluster.GlusterBrickEntity; -import org.ovirt.engine.core.common.businessentities.gluster.GlusterStatus; -import org.ovirt.engine.core.compat.Guid; -import org.ovirt.engine.core.dal.dbbroker.DbFacade; -import org.ovirt.engine.core.dao.gluster.GlusterBrickDao; -import org.ovirt.engine.core.dao.gluster.GlusterVolumeDao; - -public class GlusterUtils { - private static GlusterUtils instance = new GlusterUtils(); - - public static GlusterUtils getInstance() { - return instance; - } - - private DbFacade getDbFacade() { - return DbFacade.getInstance(); - } - - private GlusterBrickDao getGlusterBrickDao() { - return getDbFacade().getGlusterBrickDao(); - } - - private GlusterVolumeDao getGlusterVolumeDao() { - return getDbFacade().getGlusterVolumeDao(); - } - - public boolean hasBricks(Guid serverId) { - return (getGlusterBrickDao().getGlusterVolumeBricksByServerId(serverId).size() > 0); - } - - /** - * Update status of all bricks of the given volume to the new status - */ - public void updateBricksStatuses(Guid volumeId, GlusterStatus newStatus) { - for (GlusterBrickEntity brick : getGlusterBrickDao().getBricksOfVolume(volumeId)) { - getGlusterBrickDao().updateBrickStatus(brick.getId(), newStatus); - } - } - - /** - * Update status of the given volume to the new status. This internally updates statuses of all bricks of the volume - * as well. - */ - public void updateVolumeStatus(Guid volumeId, GlusterStatus newStatus) { - getGlusterVolumeDao().updateVolumeStatus(volumeId, newStatus); - // When a volume goes UP or DOWN, all it's bricks should also be updated with the new status. - updateBricksStatuses(volumeId, newStatus); - } -} diff --git a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/gluster/GetAddedGlusterServersQueryTest.java b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/gluster/GetAddedGlusterServersQueryTest.java index fb901a4..276d223 100644 --- a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/gluster/GetAddedGlusterServersQueryTest.java +++ b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/gluster/GetAddedGlusterServersQueryTest.java @@ -30,23 +30,28 @@ import org.ovirt.engine.core.common.vdscommands.VDSReturnValue; import org.ovirt.engine.core.compat.Guid; import org.ovirt.engine.core.dao.VdsDAO; +import org.ovirt.engine.core.dao.gluster.GlusterDBUtils; import org.ovirt.engine.core.utils.ssh.EngineSSHDialog; public class GetAddedGlusterServersQueryTest extends AbstractQueryTest<AddedGlusterServersParameters, GetAddedGlusterServersQuery<AddedGlusterServersParameters>> { + private List<VDS> serversList; + private List<GlusterServerInfo> expectedServers; + private AddedGlusterServersParameters params; + private VDSBrokerFrontend vdsBrokerFrontend; + private VdsDAO vdsDaoMock; + private GlusterDBUtils dbUtils; + private EngineSSHDialog mockEngineSSHDialog; + private ClusterUtils clusterUtils; - List<VDS> serversList; - List<GlusterServerInfo> expectedServers; - AddedGlusterServersParameters params; - private Guid CLUSTER_ID = new Guid("b399944a-81ab-4ec5-8266-e19ba7c3c9d1"); - private Guid server_id1 = new Guid("85c42b0d-c2b7-424a-ae72-5174c25da40b"); - private Guid server_id2 = new Guid("6a697a38-cc82-4399-a6fb-0ec79c0ff1d5"); - private Guid server_id3 = new Guid("7a797a38-cb32-4399-b6fb-21c79c03a1d6"); - private String serverKeyFingerprint = "b5:ad:16:19:06:9f:b3:41:69:eb:1c:42:1d:12:b5:31"; - VDSBrokerFrontend vdsBrokerFrontend; - VdsDAO vdsDaoMock; - EngineSSHDialog mockEngineSSHDialog; - - ClusterUtils clusterUtils; + private static final String CLUSTER_NAME = "default"; + private static final String TEST_SERVER1 = "test_server1"; + private static final String TEST_SERVER2 = "test_server2"; + private static final String TEST_SERVER3 = "test_server3"; + private static final Guid CLUSTER_ID = new Guid("b399944a-81ab-4ec5-8266-e19ba7c3c9d1"); + private static final Guid server_id1 = new Guid("85c42b0d-c2b7-424a-ae72-5174c25da40b"); + private static final Guid server_id2 = new Guid("6a697a38-cc82-4399-a6fb-0ec79c0ff1d5"); + private static final Guid server_id3 = new Guid("7a797a38-cb32-4399-b6fb-21c79c03a1d6"); + private static final String serverKeyFingerprint = "b5:ad:16:19:06:9f:b3:41:69:eb:1c:42:1d:12:b5:31"; private VDS getVds(VDSStatus status) { VDS vds = new VDS(); @@ -65,18 +70,18 @@ serversList = new ArrayList<VDS>(); VDS server = new VDS(); server.setVdsGroupId(CLUSTER_ID); - server.setVdsGroupName("default"); + server.setVdsGroupName(CLUSTER_NAME); server.setId(server_id1); - server.setVdsName("test_server1"); - server.setHostName("test_server1"); + server.setVdsName(TEST_SERVER1); + server.setHostName(TEST_SERVER1); serversList.add(server); server = new VDS(); server.setVdsGroupId(CLUSTER_ID); - server.setVdsGroupName("default"); + server.setVdsGroupName(CLUSTER_NAME); server.setId(server_id2); - server.setVdsName("test_server2"); - server.setHostName("test_server2"); + server.setVdsName(TEST_SERVER2); + server.setHostName(TEST_SERVER2); serversList.add(server); } @@ -84,12 +89,12 @@ expectedServers = new ArrayList<GlusterServerInfo>(); GlusterServerInfo server = new GlusterServerInfo(); server.setUuid(server_id1); - server.setHostnameOrIp("test_server1"); + server.setHostnameOrIp(TEST_SERVER1); server.setStatus(PeerStatus.CONNECTED); expectedServers.add(server); server = new GlusterServerInfo(); server.setUuid(server_id3); - server.setHostnameOrIp("test_server3"); + server.setHostnameOrIp(TEST_SERVER3); server.setStatus(PeerStatus.CONNECTED); expectedServers.add(server); } @@ -98,9 +103,11 @@ vdsBrokerFrontend = mock(VDSBrokerFrontend.class); clusterUtils = mock(ClusterUtils.class); vdsDaoMock = mock(VdsDAO.class); + dbUtils = mock(GlusterDBUtils.class); doReturn(vdsBrokerFrontend).when(getQuery()).getBackendInstance(); doReturn(clusterUtils).when(getQuery()).getClusterUtils(); + doReturn(dbUtils).when(getQuery()).getDbUtils(); doReturn(getVds(VDSStatus.Up)).when(clusterUtils).getUpServer(CLUSTER_ID); VDSReturnValue returnValue = getVDSReturnValue(); @@ -111,6 +118,8 @@ doReturn(vdsDaoMock).when(clusterUtils).getVdsDao(); doReturn(serversList).when(vdsDaoMock).getAllForVdsGroup(CLUSTER_ID); + doReturn(true).when(dbUtils).serverExists(any(Guid.class), eq(TEST_SERVER1)); + doReturn(false).when(dbUtils).serverExists(any(Guid.class), eq(TEST_SERVER3)); mockEngineSSHDialog = mock(EngineSSHDialog.class); doNothing().when(mockEngineSSHDialog).connect(); @@ -127,7 +136,7 @@ private Map<String, String> getAddedServers() { Map<String, String> servers = new HashMap<String, String>(); - servers.put("test_server3", serverKeyFingerprint); + servers.put(TEST_SERVER3, serverKeyFingerprint); return servers; } diff --git a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterDBUtils.java b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterDBUtils.java new file mode 100644 index 0000000..6f17a39 --- /dev/null +++ b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterDBUtils.java @@ -0,0 +1,121 @@ +package org.ovirt.engine.core.dao.gluster; + +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.util.List; + +import org.ovirt.engine.core.common.businessentities.VDS; +import org.ovirt.engine.core.common.businessentities.gluster.GlusterBrickEntity; +import org.ovirt.engine.core.common.businessentities.gluster.GlusterStatus; +import org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface; +import org.ovirt.engine.core.compat.Guid; +import org.ovirt.engine.core.dal.dbbroker.DbFacade; +import org.ovirt.engine.core.dao.VdsDAO; +import org.ovirt.engine.core.dao.network.InterfaceDao; + +public class GlusterDBUtils { + private static GlusterDBUtils instance = new GlusterDBUtils(); + + public static GlusterDBUtils getInstance() { + return instance; + } + + private DbFacade getDbFacade() { + return DbFacade.getInstance(); + } + + private GlusterBrickDao getGlusterBrickDao() { + return getDbFacade().getGlusterBrickDao(); + } + + private GlusterVolumeDao getGlusterVolumeDao() { + return getDbFacade().getGlusterVolumeDao(); + } + + public boolean hasBricks(Guid serverId) { + return (getGlusterBrickDao().getGlusterVolumeBricksByServerId(serverId).size() > 0); + } + + /** + * Update status of all bricks of the given volume to the new status + */ + public void updateBricksStatuses(Guid volumeId, GlusterStatus newStatus) { + for (GlusterBrickEntity brick : getGlusterBrickDao().getBricksOfVolume(volumeId)) { + getGlusterBrickDao().updateBrickStatus(brick.getId(), newStatus); + } + } + + /** + * Update status of the given volume to the new status. This internally updates statuses of all bricks of the volume + * as well. + */ + public void updateVolumeStatus(Guid volumeId, GlusterStatus newStatus) { + getGlusterVolumeDao().updateVolumeStatus(volumeId, newStatus); + // When a volume goes UP or DOWN, all it's bricks should also be updated with the new status. + updateBricksStatuses(volumeId, newStatus); + } + + private VdsDAO getVdsDao() { + return DbFacade.getInstance().getVdsDao(); + } + + private InterfaceDao getInterfaceDao() { + return DbFacade.getInstance().getInterfaceDao(); + } + + private VDS getServerOfCluster(Guid clusterId, List<VDS> servers) { + for (VDS server : servers) { + if (server.getVdsGroupId().equals(clusterId)) { + return server; + } + } + return null; + } + + public boolean serverExists(Guid clusterId, String hostnameOrIp) { + return getServer(clusterId, hostnameOrIp) != null; + } + + /** + * Returns a server from the given cluster, having give host name or IP address. + * + * @return VDS object for the server if found, else null + */ + public VDS getServer(Guid clusterId, String hostnameOrIp) { + // first check for hostname + List<VDS> servers = getVdsDao().getAllForHostname(hostnameOrIp); + if (servers.size() > 0) { + return getServerOfCluster(clusterId, servers); + } + + // then for ip + List<VdsNetworkInterface> ifaces; + try { + ifaces = + getInterfaceDao().getAllInterfacesWithIpAddress(clusterId, + InetAddress.getByName(hostnameOrIp).getHostAddress()); + switch (ifaces.size()) { + case 0: + // not found + return null; + case 1: + VDS server = getVdsDao().get(ifaces.get(0).getVdsId()); + if (server != null && server.getVdsGroupId().equals(clusterId)) { + return server; + } + return null; + default: + // There are multiple servers in the DB having this ip address. Throw an exception so that the gluster + // manager doesn't try to update/add bricks belonging to such servers + throw new RuntimeException(String.format("There are multiple servers in DB having same IP address %1$s! " + + + "Cannot arrive at correct server id for bricks related to this ip address in cluster %2$s", + hostnameOrIp, + clusterId)); + + } + } catch (UnknownHostException e) { + throw new RuntimeException(e); + } + } +} diff --git a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/gluster/GlusterVolumesListReturnForXmlRpc.java b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/gluster/GlusterVolumesListReturnForXmlRpc.java index 5d19435..3657984 100644 --- a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/gluster/GlusterVolumesListReturnForXmlRpc.java +++ b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/gluster/GlusterVolumesListReturnForXmlRpc.java @@ -11,11 +11,8 @@ import org.ovirt.engine.core.common.businessentities.gluster.GlusterStatus; import org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeEntity; import org.ovirt.engine.core.common.businessentities.gluster.TransportType; -import org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface; import org.ovirt.engine.core.compat.Guid; -import org.ovirt.engine.core.dal.dbbroker.DbFacade; -import org.ovirt.engine.core.dao.VdsDAO; -import org.ovirt.engine.core.dao.network.InterfaceDao; +import org.ovirt.engine.core.dao.gluster.GlusterDBUtils; import org.ovirt.engine.core.utils.log.Log; import org.ovirt.engine.core.utils.log.LogFactory; import org.ovirt.engine.core.vdsbroker.irsbroker.StatusReturnForXmlRpc; @@ -40,6 +37,7 @@ private Guid clusterId; private Map<Guid, GlusterVolumeEntity> volumes = new HashMap<Guid, GlusterVolumeEntity>(); private static Log log = LogFactory.getLog(GlusterVolumesListReturnForXmlRpc.class); + private static final GlusterDBUtils dbUtils = GlusterDBUtils.getInstance(); @SuppressWarnings("unchecked") public GlusterVolumesListReturnForXmlRpc(Guid clusterId, Map<String, Object> innerMap) { @@ -149,7 +147,7 @@ */ private GlusterBrickEntity getBrick(Guid clusterId, Guid volumeId, String brickInfo, int brickOrder) { String[] brickParts = brickInfo.split(":", -1); - if(brickParts.length != 2) { + if (brickParts.length != 2) { throw new RuntimeException("Invalid brick representation [" + brickInfo + "]"); } @@ -161,63 +159,14 @@ brick.setBrickOrder(brickOrder); brick.setBrickDirectory(brickDir); - VDS server = getServer(clusterId, hostnameOrIp); - if(server == null) { + VDS server = dbUtils.getServer(clusterId, hostnameOrIp); + if (server == null) { log.warnFormat("Could not find server {0} in cluster {1}", hostnameOrIp, clusterId); } else { brick.setServerId(server.getId()); brick.setServerName(server.getHostName()); } return brick; - } - - private VdsDAO getVdsDao() { - return DbFacade.getInstance().getVdsDao(); - } - - private InterfaceDao getInterfaceDao() { - return DbFacade.getInstance().getInterfaceDao(); - } - - /** - * Returns a server from the given cluster, having give host name or IP address - * @param clusterId - * @param hostnameOrIp - * @return - */ - private VDS getServer(Guid clusterId, String hostnameOrIp) { - List<VDS> servers = getVdsDao().getAllForHostname(hostnameOrIp); - if(servers.size() > 0) { - return getServerOfCluster(clusterId, servers); - } - - List<VdsNetworkInterface> ifaces = getInterfaceDao().getAllInterfacesWithIpAddress(clusterId, hostnameOrIp); - if(ifaces.size() == 1) { - for(VdsNetworkInterface iface : ifaces) { - VDS server = getVdsDao().get(iface.getVdsId()); - if(server.getVdsGroupId().equals(clusterId)) { - return server; - } - } - } else if(ifaces.size() > 1) { - // There are multiple servers in the DB having this ip address. Throw an exception so that the gluster - // manager doesn't try to update/add bricks belonging to such servers - throw new RuntimeException(String.format("There are multiple servers in DB having same IP address %1$s! " + - "Cannot arrive at correct server id for bricks related to this ip address in cluster %2$s", - hostnameOrIp, - clusterId)); - } - - return null; - } - - private VDS getServerOfCluster(Guid clusterId, List<VDS> servers) { - for(VDS server : servers) { - if(server.getVdsGroupId().equals(clusterId)) { - return server; - } - } - return null; } public Map<Guid, GlusterVolumeEntity> getVolumes() { -- To view, visit http://gerrit.ovirt.org/12021 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Iab25afc5cb0acb5be288c005d1110c1ad0a54b2d Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Shireesh Anjal <san...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches