mirror of https://github.com/apache/cloudstack.git
fixed a bug in the listener flow; now handling the application of certs to existing cpvms and new cpvms based on a fork in the logic in the console proxy resource
This commit is contained in:
parent
abd64eddd1
commit
7b87aad660
|
|
@ -109,36 +109,69 @@ public class ConsoleProxyResource extends ServerResourceBase implements ServerRe
|
|||
|
||||
protected Answer execute(final UpdateCertificateCommand cmd) {
|
||||
boolean success = false;
|
||||
String errorStr = null;
|
||||
String successStr = null;
|
||||
try
|
||||
{
|
||||
String certificate = cmd.getCertificate();
|
||||
//write the cert to /etc/cloud/consoleproxy/cert/
|
||||
boolean dirCreated = false;
|
||||
String strDirectoy = "/etc/cloud/consoleproxy/cert/";
|
||||
dirCreated = (new File(strDirectoy)).mkdirs();
|
||||
if (dirCreated)
|
||||
{
|
||||
boolean dirExists = false;
|
||||
boolean forNewProxy = cmd.isForNewProxy();
|
||||
String strDirectory = "/etc/cloud/consoleproxy/cert/";
|
||||
String filePath = "/etc/cloud/consoleproxy/cert/customcert";
|
||||
if(forNewProxy){
|
||||
dirCreated = (new File(strDirectory)).mkdirs();
|
||||
if(s_logger.isDebugEnabled())
|
||||
s_logger.debug("Directory: " + strDirectoy + " created");
|
||||
//copy cert to the dir
|
||||
FileWriter fstream = new FileWriter("/etc/cloud/consoleproxy/cert/customcert");
|
||||
BufferedWriter out = new BufferedWriter(fstream);
|
||||
out.write(certificate);
|
||||
//Close the output stream
|
||||
out.close();
|
||||
success = true;
|
||||
}
|
||||
s_logger.debug("Directory: " + strDirectory + " created");
|
||||
if(dirCreated){
|
||||
//copy cert to the dir
|
||||
FileWriter fstream = new FileWriter(filePath);
|
||||
BufferedWriter out = new BufferedWriter(fstream);
|
||||
out.write(certificate);
|
||||
//Close the output stream
|
||||
out.close();
|
||||
success = true;
|
||||
successStr = "Successfully created cert at /etc/cloud/consoleproxy/cert/ from the listener flow for new console proxy starting up";
|
||||
}
|
||||
}
|
||||
else{
|
||||
File dir = new File(strDirectory);
|
||||
dirExists = dir.exists();
|
||||
if(!dirExists){
|
||||
dirCreated = (new File(strDirectory)).mkdirs();
|
||||
if(s_logger.isDebugEnabled())
|
||||
s_logger.debug("Directory: " + strDirectory + " created");
|
||||
}
|
||||
if (dirExists || dirCreated)
|
||||
{
|
||||
//copy cert to the dir
|
||||
FileWriter fstream = new FileWriter(filePath);
|
||||
BufferedWriter out = new BufferedWriter(fstream);
|
||||
out.write(certificate);
|
||||
//Close the output stream
|
||||
out.close();
|
||||
success = true;
|
||||
successStr = "Successfully created cert at /etc/cloud/consoleproxy/cert/ from the UploadCustomCert cmd flow for existing console proxy";
|
||||
}
|
||||
}
|
||||
}catch (SecurityException se){
|
||||
s_logger.error("Unable to read the cert string in console proxy resource due to directory creation failure",se);
|
||||
errorStr = "Unable to upload cert in console proxy resource due to directory creation failure";
|
||||
s_logger.error(errorStr,se);
|
||||
success = false;
|
||||
}catch (IOException ioe){
|
||||
errorStr = "Unable to write cert to the location /etc/cloud/consoleproxy/cert/ ";
|
||||
s_logger.error(errorStr,ioe);
|
||||
success = false;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
s_logger.error("Unable to read the cert string in console proxy resource",e);
|
||||
errorStr = "Unable to upload cert in console proxy resource";
|
||||
s_logger.error(errorStr,e);
|
||||
success = false;
|
||||
}
|
||||
|
||||
return new Answer(cmd, success, "Custom certificate response from the updatecertificate flow");
|
||||
return new Answer(cmd, success, errorStr!=null?errorStr:successStr);
|
||||
}
|
||||
|
||||
protected Answer execute(final CheckConsoleProxyLoadCommand cmd) {
|
||||
|
|
|
|||
|
|
@ -25,19 +25,30 @@ package com.cloud.agent.api.proxy;
|
|||
public class UpdateCertificateCommand extends ProxyCommand {
|
||||
|
||||
private String certificate; //certificate to be applied
|
||||
private boolean forNewProxy; //denotes if this is called from the listener flow
|
||||
|
||||
public UpdateCertificateCommand() {
|
||||
this.forNewProxy = false;
|
||||
}
|
||||
|
||||
public UpdateCertificateCommand(String certificate) {
|
||||
public UpdateCertificateCommand(String certificate, boolean forNewProxy) {
|
||||
this.certificate = certificate;
|
||||
this.forNewProxy = forNewProxy;
|
||||
}
|
||||
|
||||
public String getCertificate() {
|
||||
return this.certificate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isForNewProxy() {
|
||||
return forNewProxy;
|
||||
}
|
||||
|
||||
public void setForNewProxy(boolean forNewProxy) {
|
||||
this.forNewProxy = forNewProxy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean executeInSequence() {
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2456,7 +2456,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, VirtualMach
|
|||
if(consoleProxy!=null){
|
||||
HostVO consoleProxyHost = _hostDao.findConsoleProxyHost(consoleProxy.getName(), Type.ConsoleProxy);
|
||||
//now send a command to console proxy
|
||||
UpdateCertificateCommand certCmd = new UpdateCertificateCommand(certStr);
|
||||
UpdateCertificateCommand certCmd = new UpdateCertificateCommand(certStr, true);
|
||||
try {
|
||||
Answer updateCertAns = _agentMgr.send(consoleProxyHost.getId(), certCmd);
|
||||
if(updateCertAns.getResult() == true)
|
||||
|
|
|
|||
|
|
@ -5908,7 +5908,7 @@ public class ManagementServerImpl implements ManagementServer {
|
|||
{
|
||||
Long cpHostId = hostNameToHostIdMap.get(cp.getName());
|
||||
//now send a command to each console proxy
|
||||
UpdateCertificateCommand certCmd = new UpdateCertificateCommand(_certDao.findById(certVOId).getCertificate());
|
||||
UpdateCertificateCommand certCmd = new UpdateCertificateCommand(_certDao.findById(certVOId).getCertificate(), false);
|
||||
try {
|
||||
Answer updateCertAns = _agentMgr.send(cpHostId, certCmd);
|
||||
if(updateCertAns.getResult() == true)
|
||||
|
|
|
|||
Loading…
Reference in New Issue