diff --git a/agent/src/com/cloud/agent/resource/consoleproxy/ConsoleProxyResource.java b/agent/src/com/cloud/agent/resource/consoleproxy/ConsoleProxyResource.java index b5483e44aca..28488cefbd8 100644 --- a/agent/src/com/cloud/agent/resource/consoleproxy/ConsoleProxyResource.java +++ b/agent/src/com/cloud/agent/resource/consoleproxy/ConsoleProxyResource.java @@ -49,6 +49,7 @@ import com.cloud.agent.api.StartupCommand; import com.cloud.agent.api.StartupProxyCommand; import com.cloud.agent.api.proxy.CheckConsoleProxyLoadCommand; import com.cloud.agent.api.proxy.ConsoleProxyLoadAnswer; +import com.cloud.agent.api.proxy.UpdateCertificateCommand; import com.cloud.agent.api.proxy.WatchConsoleProxyLoadCommand; import com.cloud.exception.AgentControlChannelException; import com.cloud.host.Host; @@ -83,6 +84,7 @@ public class ConsoleProxyResource extends ServerResourceBase implements ServerRe String _eth1ip; String _eth1mask; String _pubIp; + String certificate; @Override public Answer executeRequest(final Command cmd) { @@ -95,11 +97,27 @@ public class ConsoleProxyResource extends ServerResourceBase implements ServerRe return new ReadyAnswer((ReadyCommand)cmd); } else if(cmd instanceof CheckHealthCommand) { return new CheckHealthAnswer((CheckHealthCommand)cmd, true); - } else { + } else if(cmd instanceof UpdateCertificateCommand) { + return execute((UpdateCertificateCommand)cmd); + } + else { return Answer.createUnsupportedCommandAnswer(cmd); } } - + + protected Answer execute(final UpdateCertificateCommand cmd) { + boolean success = false; + try{ + certificate = cmd.getCertificate(); + success = true; + return new Answer(cmd, success, "Cert string in the console proxy resource status:"); + }catch (Exception e) + { + s_logger.error("Unable to read the cert string in console proxy resource"); + } + return new Answer(cmd, success, "Cert string in the console proxy resource status:"); + } + protected Answer execute(final CheckConsoleProxyLoadCommand cmd) { return executeProxyLoadScan(cmd, cmd.getProxyVmId(), cmd.getProxyVmName(), cmd.getProxyManagementIp(), cmd.getProxyCmdPort()); } diff --git a/core/src/com/cloud/certificate/dao/CertificateDao.java b/core/src/com/cloud/certificate/dao/CertificateDao.java index 9da10b49fef..192e1619307 100644 --- a/core/src/com/cloud/certificate/dao/CertificateDao.java +++ b/core/src/com/cloud/certificate/dao/CertificateDao.java @@ -22,5 +22,5 @@ import com.cloud.certificate.CertificateVO; import com.cloud.utils.db.GenericDao; public interface CertificateDao extends GenericDao { - public boolean persistCustomCertToDb(String certPath); + public Long persistCustomCertToDb(String certPath); } diff --git a/core/src/com/cloud/certificate/dao/CertificateDaoImpl.java b/core/src/com/cloud/certificate/dao/CertificateDaoImpl.java index 80985e90b66..8ff6c918af5 100644 --- a/core/src/com/cloud/certificate/dao/CertificateDaoImpl.java +++ b/core/src/com/cloud/certificate/dao/CertificateDaoImpl.java @@ -24,7 +24,7 @@ public class CertificateDaoImpl extends GenericDaoBase imp } @Override - public boolean persistCustomCertToDb(String certPath){ + public Long persistCustomCertToDb(String certPath){ String certStr = null; byte[] buffer = new byte[(int) new File(certPath).length()]; @@ -35,10 +35,10 @@ public class CertificateDaoImpl extends GenericDaoBase imp f.read(buffer); } catch (FileNotFoundException e) { s_logger.warn("Unable to read the certificate: "+e); - return false; + return new Long(0); } catch (IOException e) { s_logger.warn("Unable to read the certificate: "+e); - return false; + return new Long(0); } finally { @@ -51,6 +51,6 @@ public class CertificateDaoImpl extends GenericDaoBase imp certRec.setCertificate(certStr); this.persist(certRec); - return true; + return certRec.getId(); } } diff --git a/server/src/com/cloud/server/ManagementServerImpl.java b/server/src/com/cloud/server/ManagementServerImpl.java index c5031efe18d..34f526d1322 100755 --- a/server/src/com/cloud/server/ManagementServerImpl.java +++ b/server/src/com/cloud/server/ManagementServerImpl.java @@ -52,8 +52,10 @@ import org.apache.commons.codec.binary.Base64; import org.apache.log4j.Logger; import com.cloud.agent.AgentManager; +import com.cloud.agent.api.Answer; import com.cloud.agent.api.GetVncPortAnswer; import com.cloud.agent.api.GetVncPortCommand; +import com.cloud.agent.api.proxy.UpdateCertificateCommand; import com.cloud.agent.api.storage.CopyVolumeAnswer; import com.cloud.agent.api.storage.CopyVolumeCommand; import com.cloud.alert.AlertManager; @@ -180,6 +182,7 @@ import com.cloud.exception.InsufficientStorageCapacityException; import com.cloud.exception.InternalErrorException; import com.cloud.exception.InvalidParameterValueException; import com.cloud.exception.NetworkRuleConflictException; +import com.cloud.exception.OperationTimedoutException; import com.cloud.exception.PermissionDeniedException; import com.cloud.exception.ResourceAllocationException; import com.cloud.exception.StorageUnavailableException; @@ -6866,30 +6869,35 @@ public class ManagementServerImpl implements ManagementServer { @Override public boolean uploadCertificate(UploadCustomCertificateCmd cmd) { String certificatePath = cmd.getPath(); - boolean uploadStatus = _certDao.persistCustomCertToDb(certificatePath); + Long certVOId = _certDao.persistCustomCertToDb(certificatePath);//0 implies failure - if (uploadStatus) { + if (certVOId!=null && certVOId!=0) { //certficate uploaded to db successfully //get a list of all hosts from host table List hosts = _hostDao.listAll(); - List consoleProxyList = new ArrayList(); + List consoleProxyList = new ArrayList(); //find the console proxies, and send the command to them for(HostVO host : hosts) { - //find corresponding vms for this host - List vmList = _vmInstanceDao.listByHostId(host.getId()); - - for(VMInstanceVO vm : vmList){ - if(VirtualMachineName.isValidConsoleProxyName(vm.getInstanceName())){ - consoleProxyList.add(vm); - } + if(host.getType().equals(com.cloud.host.Host.Type.ConsoleProxy)){ + consoleProxyList.add(host); } } - //now restart each of these proxies - //restart will + for(HostVO consoleProxy : consoleProxyList){ + //now send a command to each console proxy + UpdateCertificateCommand certCmd = new UpdateCertificateCommand(_certDao.findById(certVOId).getCertificate()); + try { + Answer updateCertAns = _agentMgr.send(consoleProxy.getId(), certCmd); + int a = 30; + } catch (AgentUnavailableException e) { + s_logger.warn("Unable to send command to the console proxy resource", e); + } catch (OperationTimedoutException e) { + s_logger.warn("Unable to send command to the console proxy resource", e); + } + } } return false;