mirror of https://github.com/apache/cloudstack.git
kvm: Fixed removal of hosts from certsmap when running certificate auto-renewal (#4156)
When a host connects to a management server, the host IP address and the certificate are stored in memory on the management server. This mapping is checked periodically to determine if any certificates are due to expire. Before a certificate is renewed, a few checks are done to determine if the host is connected to the management server by fetching the host record from the database. The problem here is if the wrong record is fetched, the host is not checked for renewal. This PR improves the host record fetch from the database by looking only at hosts that are not removed. Fixes: #4129
This commit is contained in:
parent
f0a67cca7a
commit
7b881517b7
|
|
@ -97,6 +97,12 @@ public interface HostDao extends GenericDao<HostVO, Long>, StateDao<Status, Stat
|
|||
|
||||
List<HostVO> listByType(Type type);
|
||||
|
||||
/**
|
||||
* Finds a host by ip address, excludes removed hosts.
|
||||
*
|
||||
* @param ip The ip address to match on
|
||||
* @return One matched host
|
||||
*/
|
||||
HostVO findByIp(String ip);
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -90,7 +90,7 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
|
|||
protected SearchBuilder<HostVO> DcPrivateIpAddressSearch;
|
||||
protected SearchBuilder<HostVO> DcStorageIpAddressSearch;
|
||||
protected SearchBuilder<HostVO> PublicIpAddressSearch;
|
||||
protected SearchBuilder<HostVO> AnyIpAddressSearch;
|
||||
protected SearchBuilder<HostVO> UnremovedIpAddressSearch;
|
||||
|
||||
protected SearchBuilder<HostVO> GuidSearch;
|
||||
protected SearchBuilder<HostVO> DcSearch;
|
||||
|
|
@ -227,10 +227,12 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
|
|||
PublicIpAddressSearch.and("publicIpAddress", PublicIpAddressSearch.entity().getPublicIpAddress(), SearchCriteria.Op.EQ);
|
||||
PublicIpAddressSearch.done();
|
||||
|
||||
AnyIpAddressSearch = createSearchBuilder();
|
||||
AnyIpAddressSearch.or("publicIpAddress", AnyIpAddressSearch.entity().getPublicIpAddress(), SearchCriteria.Op.EQ);
|
||||
AnyIpAddressSearch.or("privateIpAddress", AnyIpAddressSearch.entity().getPrivateIpAddress(), SearchCriteria.Op.EQ);
|
||||
AnyIpAddressSearch.done();
|
||||
UnremovedIpAddressSearch = createSearchBuilder();
|
||||
UnremovedIpAddressSearch.and("removed", UnremovedIpAddressSearch.entity().getRemoved(), Op.NULL); // We don't want any removed hosts
|
||||
UnremovedIpAddressSearch.and().op("publicIpAddress", UnremovedIpAddressSearch.entity().getPublicIpAddress(), SearchCriteria.Op.EQ);
|
||||
UnremovedIpAddressSearch.or("privateIpAddress", UnremovedIpAddressSearch.entity().getPrivateIpAddress(), SearchCriteria.Op.EQ);
|
||||
UnremovedIpAddressSearch.cp();
|
||||
UnremovedIpAddressSearch.done();
|
||||
|
||||
GuidSearch = createSearchBuilder();
|
||||
GuidSearch.and("guid", GuidSearch.entity().getGuid(), SearchCriteria.Op.EQ);
|
||||
|
|
@ -308,12 +310,6 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
|
|||
UnmanagedDirectConnectSearch.and("lastPinged", UnmanagedDirectConnectSearch.entity().getLastPinged(), SearchCriteria.Op.LTEQ);
|
||||
UnmanagedDirectConnectSearch.and("resourceStates", UnmanagedDirectConnectSearch.entity().getResourceState(), SearchCriteria.Op.NIN);
|
||||
UnmanagedDirectConnectSearch.and("clusterIn", UnmanagedDirectConnectSearch.entity().getClusterId(), SearchCriteria.Op.IN);
|
||||
/*
|
||||
* UnmanagedDirectConnectSearch.op(SearchCriteria.Op.OR, "managementServerId",
|
||||
* UnmanagedDirectConnectSearch.entity().getManagementServerId(), SearchCriteria.Op.EQ);
|
||||
* UnmanagedDirectConnectSearch.and("lastPinged", UnmanagedDirectConnectSearch.entity().getLastPinged(),
|
||||
* SearchCriteria.Op.LTEQ); UnmanagedDirectConnectSearch.cp(); UnmanagedDirectConnectSearch.cp();
|
||||
*/
|
||||
try {
|
||||
HostTransferSearch = _hostTransferDao.createSearchBuilder();
|
||||
} catch (Throwable e) {
|
||||
|
|
@ -1116,7 +1112,7 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
|
|||
|
||||
@Override
|
||||
public HostVO findByIp(final String ipAddress) {
|
||||
SearchCriteria<HostVO> sc = AnyIpAddressSearch.create();
|
||||
SearchCriteria<HostVO> sc = UnremovedIpAddressSearch.create();
|
||||
sc.setParameters("publicIpAddress", ipAddress);
|
||||
sc.setParameters("privateIpAddress", ipAddress);
|
||||
return findOneBy(sc);
|
||||
|
|
|
|||
Loading…
Reference in New Issue