mirror of https://github.com/apache/cloudstack.git
improving efficiency by reducing the number of db lookups, whilst updating the custom certificates across multiple console proxies when the command is issued. Now, we use in memory hashmaps for hosts to get the hostids for cphosts, which eliminates the need to make a db lookup for every cpvm that needs to be rebooted
This commit is contained in:
parent
4d2e126ea1
commit
d9ebb7147c
|
|
@ -24,33 +24,33 @@ public class CertificateDaoImpl extends GenericDaoBase<CertificateVO, Long> imp
|
|||
}
|
||||
|
||||
@Override
|
||||
public Long persistCustomCertToDb(String certPath){
|
||||
|
||||
String certStr = null;
|
||||
byte[] buffer = new byte[(int) new File(certPath).length()];
|
||||
public Long persistCustomCertToDb(String certPath){
|
||||
BufferedInputStream f = null;
|
||||
try
|
||||
String certStr = null;
|
||||
try
|
||||
{
|
||||
byte[] buffer = new byte[(int) new File(certPath).length()];
|
||||
f = new BufferedInputStream(new FileInputStream(certPath));
|
||||
f.read(buffer);
|
||||
certStr = new String(buffer);
|
||||
CertificateVO certRec = new CertificateVO();
|
||||
certRec.setCertificate(certStr);
|
||||
this.persist(certRec);
|
||||
return certRec.getId();
|
||||
} catch (FileNotFoundException e) {
|
||||
s_logger.warn("Unable to read the certificate: "+e);
|
||||
return new Long(0);
|
||||
} catch (IOException e) {
|
||||
s_logger.warn("Unable to read the certificate: "+e);
|
||||
return new Long(0);
|
||||
}
|
||||
} catch (Exception e){
|
||||
s_logger.warn("Unable to read the certificate: "+e);
|
||||
return new Long(0);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (f != null)
|
||||
try { f.close(); } catch (IOException ignored) { }
|
||||
}
|
||||
certStr = new String(buffer);
|
||||
|
||||
CertificateVO certRec = new CertificateVO();
|
||||
certRec.setCertificate(certStr);
|
||||
this.persist(certRec);
|
||||
|
||||
return certRec.getId();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -137,7 +137,9 @@ public interface HostDao extends GenericDao<HostVO, Long> {
|
|||
|
||||
void loadDetails(HostVO host);
|
||||
|
||||
HostVO findConsoleProxyHost(String name, Type type);
|
||||
HostVO findConsoleProxyHost(String name, Type type);
|
||||
|
||||
List<HostVO> listAllConsoleProxyHosts(Type type);
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -80,6 +80,7 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
|
|||
protected final SearchBuilder<HostVO> MaintenanceCountSearch;
|
||||
protected final SearchBuilder<HostVO> ClusterSearch;
|
||||
protected final SearchBuilder<HostVO> ConsoleProxyHostSearch;
|
||||
protected final SearchBuilder<HostVO> ConsoleProxyHostsListSearch;
|
||||
|
||||
protected final Attribute _statusAttr;
|
||||
protected final Attribute _msIdAttr;
|
||||
|
|
@ -160,6 +161,10 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
|
|||
ConsoleProxyHostSearch.and("name", ConsoleProxyHostSearch.entity().getName(), SearchCriteria.Op.EQ);
|
||||
ConsoleProxyHostSearch.and("type", ConsoleProxyHostSearch.entity().getType(), SearchCriteria.Op.EQ);
|
||||
ConsoleProxyHostSearch.done();
|
||||
|
||||
ConsoleProxyHostsListSearch = createSearchBuilder();
|
||||
ConsoleProxyHostsListSearch.and("type", ConsoleProxyHostsListSearch.entity().getType(), SearchCriteria.Op.EQ);
|
||||
ConsoleProxyHostsListSearch.done();
|
||||
|
||||
PodSearch = createSearchBuilder();
|
||||
PodSearch.and("pod", PodSearch.entity().getPodId(), SearchCriteria.Op.EQ);
|
||||
|
|
@ -175,7 +180,7 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
|
|||
|
||||
NameLikeSearch = createSearchBuilder();
|
||||
NameLikeSearch.and("name", NameLikeSearch.entity().getName(), SearchCriteria.Op.LIKE);
|
||||
NameLikeSearch.done();
|
||||
NameLikeSearch.done();
|
||||
|
||||
SequenceSearch = createSearchBuilder();
|
||||
SequenceSearch.and("id", SequenceSearch.entity().getId(), SearchCriteria.Op.EQ);
|
||||
|
|
@ -461,6 +466,13 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
|
|||
else
|
||||
return hostList.get(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<HostVO> listAllConsoleProxyHosts(Type type) {
|
||||
SearchCriteria<HostVO> sc = ConsoleProxyHostSearch.create();
|
||||
sc.setParameters("type", type);
|
||||
return listBy(sc);
|
||||
}
|
||||
|
||||
public List<HostVO> listByHostPod(long podId) {
|
||||
SearchCriteria<HostVO> sc = PodSearch.create("pod", podId);
|
||||
|
|
|
|||
|
|
@ -5880,13 +5880,21 @@ public class ManagementServerImpl implements ManagementServer {
|
|||
//certficate uploaded to db successfully
|
||||
//get a list of all Console proxies from the cp table
|
||||
List<ConsoleProxyVO> cpList = _consoleProxyDao.listAll();
|
||||
//get a list of all hosts in host table for type cp
|
||||
List<HostVO> cpHosts = _hostDao.listAllConsoleProxyHosts(com.cloud.host.Host.Type.ConsoleProxy);
|
||||
//create a hashmap for fast lookup
|
||||
Map<String,Long> hostNameToHostIdMap = new HashMap<String, Long>();
|
||||
for(HostVO cpHost : cpHosts){
|
||||
hostNameToHostIdMap.put(cpHost.getName(), cpHost.getId());
|
||||
}
|
||||
|
||||
for(ConsoleProxyVO cp : cpList)
|
||||
{
|
||||
HostVO cpHost = _hostDao.findConsoleProxyHost(cp.getName(), com.cloud.host.Host.Type.ConsoleProxy);
|
||||
Long cpHostId = hostNameToHostIdMap.get(cp.getName());//there will always be a cphost for a cpvm
|
||||
//now send a command to each console proxy
|
||||
UpdateCertificateCommand certCmd = new UpdateCertificateCommand(_certDao.findById(certVOId).getCertificate());
|
||||
try {
|
||||
Answer updateCertAns = _agentMgr.send(cpHost.getId(), certCmd);
|
||||
Answer updateCertAns = _agentMgr.send(cpHostId, certCmd);
|
||||
if(updateCertAns.getResult() == true)
|
||||
{
|
||||
//we have the cert copied over on cpvm
|
||||
|
|
|
|||
Loading…
Reference in New Issue