mirror of https://github.com/apache/cloudstack.git
server: indirectagentlb hypervisor type fix
Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
This commit is contained in:
parent
38765f327c
commit
8038b28b1c
|
|
@ -171,8 +171,9 @@ public interface HostDao extends GenericDao<HostVO, Long>, StateDao<Status, Stat
|
|||
|
||||
boolean isHostUp(long hostId);
|
||||
|
||||
List<Long> findHostIdsByZoneClusterResourceStateAndType(final Long zoneId, final Long clusterId,
|
||||
final List<ResourceState> resourceStates, final List<Type> types);
|
||||
List<Long> findHostIdsByZoneClusterResourceStateTypeAndHypervisorType(final Long zoneId, final Long clusterId,
|
||||
final List<ResourceState> resourceStates, final List<Type> types,
|
||||
final List<Hypervisor.HypervisorType> hypervisorTypes);
|
||||
|
||||
List<Long> listAllIds();
|
||||
|
||||
|
|
|
|||
|
|
@ -1570,14 +1570,20 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<Long> findHostIdsByZoneClusterResourceStateAndType(final Long zoneId, final Long clusterId,
|
||||
final List<ResourceState> resourceStates, final List<Type> types) {
|
||||
public List<Long> findHostIdsByZoneClusterResourceStateTypeAndHypervisorType(final Long zoneId, final Long clusterId,
|
||||
final List<ResourceState> resourceStates, final List<Type> types,
|
||||
final List<Hypervisor.HypervisorType> hypervisorTypes) {
|
||||
GenericSearchBuilder<HostVO, Long> sb = createSearchBuilder(Long.class);
|
||||
sb.selectFields(sb.entity().getId());
|
||||
sb.and("zoneId", sb.entity().getDataCenterId(), SearchCriteria.Op.EQ);
|
||||
sb.and("clusterId", sb.entity().getClusterId(), SearchCriteria.Op.EQ);
|
||||
sb.and("resourceState", sb.entity().getResourceState(), SearchCriteria.Op.IN);
|
||||
sb.and("type", sb.entity().getType(), SearchCriteria.Op.IN);
|
||||
if (CollectionUtils.isNotEmpty(hypervisorTypes)) {
|
||||
sb.and().op(sb.entity().getHypervisorType(), SearchCriteria.Op.NULL);
|
||||
sb.or("hypervisorTypes", sb.entity().getHypervisorType(), SearchCriteria.Op.IN);
|
||||
sb.cp();
|
||||
}
|
||||
sb.done();
|
||||
SearchCriteria<Long> sc = sb.create();
|
||||
if (zoneId != null) {
|
||||
|
|
@ -1586,6 +1592,11 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
|
|||
if (clusterId != null) {
|
||||
sc.setParameters("clusterId", clusterId);
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(hypervisorTypes)) {
|
||||
sb.and().op(sb.entity().getHypervisorType(), SearchCriteria.Op.NULL);
|
||||
sc.setParameters("hypervisorTypes", hypervisorTypes.toArray());
|
||||
sb.cp();
|
||||
}
|
||||
sc.setParameters("resourceState", resourceStates.toArray());
|
||||
sc.setParameters("type", types.toArray());
|
||||
return customSearch(sc, null);
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ import com.cloud.dc.dao.ClusterDao;
|
|||
import com.cloud.dc.dao.DataCenterDao;
|
||||
import com.cloud.host.Host;
|
||||
import com.cloud.host.dao.HostDao;
|
||||
import com.cloud.hypervisor.Hypervisor;
|
||||
import com.cloud.resource.ResourceState;
|
||||
import com.cloud.utils.component.ComponentLifecycleBase;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
|
|
@ -132,11 +133,12 @@ public class IndirectAgentLBServiceImpl extends ComponentLifecycleBase implement
|
|||
}
|
||||
|
||||
private List<Long> getAllAgentBasedHostsFromDB(final Long zoneId, final Long clusterId) {
|
||||
return hostDao.findHostIdsByZoneClusterResourceStateAndType(zoneId, clusterId,
|
||||
return hostDao.findHostIdsByZoneClusterResourceStateTypeAndHypervisorType(zoneId, clusterId,
|
||||
List.of(ResourceState.Enabled, ResourceState.Maintenance, ResourceState.Disabled,
|
||||
ResourceState.ErrorInMaintenance, ResourceState.PrepareForMaintenance),
|
||||
List.of(Host.Type.Routing, Host.Type.ConsoleProxy,
|
||||
Host.Type.SecondaryStorage, Host.Type.SecondaryStorageVM));
|
||||
Host.Type.SecondaryStorage, Host.Type.SecondaryStorageVM),
|
||||
List.of(Hypervisor.HypervisorType.KVM, Hypervisor.HypervisorType.KVM));
|
||||
}
|
||||
|
||||
private org.apache.cloudstack.agent.lb.IndirectAgentLBAlgorithm getAgentMSLBAlgorithm() {
|
||||
|
|
|
|||
|
|
@ -103,8 +103,8 @@ public class IndirectAgentLBServiceImplTest {
|
|||
addField(agentMSLB, "agentManager", agentManager);
|
||||
|
||||
List<Long> hostIds = hosts.stream().map(HostVO::getId).collect(Collectors.toList());
|
||||
doReturn(hostIds).when(hostDao).findHostIdsByZoneClusterResourceStateAndType(Mockito.anyLong(), Mockito.eq(null),
|
||||
Mockito.anyList(), Mockito.anyList());
|
||||
doReturn(hostIds).when(hostDao).findHostIdsByZoneClusterResourceStateTypeAndHypervisorType(Mockito.anyLong(),
|
||||
Mockito.eq(null), Mockito.anyList(), Mockito.anyList(), Mockito.anyList());
|
||||
}
|
||||
|
||||
@Before
|
||||
|
|
@ -195,16 +195,16 @@ public class IndirectAgentLBServiceImplTest {
|
|||
|
||||
@Test
|
||||
public void testGetOrderedRunningHostIdsEmptyList() {
|
||||
doReturn(Collections.emptyList()).when(hostDao).findHostIdsByZoneClusterResourceStateAndType(Mockito.eq(DC_1_ID), Mockito.eq(null),
|
||||
Mockito.anyList(), Mockito.anyList());
|
||||
doReturn(Collections.emptyList()).when(hostDao).findHostIdsByZoneClusterResourceStateTypeAndHypervisorType(
|
||||
Mockito.eq(DC_1_ID), Mockito.eq(null), Mockito.anyList(), Mockito.anyList(), Mockito.anyList());
|
||||
Assert.assertTrue(agentMSLB.getOrderedHostIdList(DC_1_ID).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetOrderedRunningHostIdsOrderList() {
|
||||
doReturn(Arrays.asList(host4.getId(), host2.getId(), host1.getId(), host3.getId())).when(hostDao)
|
||||
.findHostIdsByZoneClusterResourceStateAndType(Mockito.eq(DC_1_ID), Mockito.eq(null),
|
||||
Mockito.anyList(), Mockito.anyList());
|
||||
.findHostIdsByZoneClusterResourceStateTypeAndHypervisorType(Mockito.eq(DC_1_ID), Mockito.eq(null),
|
||||
Mockito.anyList(), Mockito.anyList(), Mockito.anyList());
|
||||
Assert.assertEquals(Arrays.asList(host1.getId(), host2.getId(), host3.getId(), host4.getId()),
|
||||
agentMSLB.getOrderedHostIdList(DC_1_ID));
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue