From cb4a80b8acc0b522107829ecd6c4e127ceb7134e Mon Sep 17 00:00:00 2001 From: abhishek Date: Mon, 25 Oct 2010 18:41:26 -0700 Subject: [PATCH] starting off with the listener logic.This will ensure that every new console proxy vm that starts, will potentially look for any custom certs uploaded to our db. If they exist, we will send a command to the agent, so that the cert is uploaded, and the ssl context is re-initialized. --- .../consoleproxy/ConsoleProxyResource.java | 9 ++++----- .../cloud/server/ManagementServerImpl.java | 20 ++++++++++--------- setup/db/create-schema.sql | 2 +- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/agent/src/com/cloud/agent/resource/consoleproxy/ConsoleProxyResource.java b/agent/src/com/cloud/agent/resource/consoleproxy/ConsoleProxyResource.java index e9bab07ffdf..12443c1a17f 100644 --- a/agent/src/com/cloud/agent/resource/consoleproxy/ConsoleProxyResource.java +++ b/agent/src/com/cloud/agent/resource/consoleproxy/ConsoleProxyResource.java @@ -121,8 +121,8 @@ public class ConsoleProxyResource extends ServerResourceBase implements ServerRe if (dirCreated) { - s_logger.info("Directory: " + strDirectoy + " created"); - + if(s_logger.isDebugEnabled()) + s_logger.info("Directory: " + strDirectoy + " created"); //copy cert to the dir FileWriter fstream = new FileWriter("/etc/cloud/consoleproxy/cert/customcert"); BufferedWriter out = new BufferedWriter(fstream); @@ -131,14 +131,13 @@ public class ConsoleProxyResource extends ServerResourceBase implements ServerRe out.close(); success = true; } - - return new Answer(cmd, success, "Cert string in the console proxy resource status:"); + return new Answer(cmd, success, "Custom certificate update required status"); }catch (Exception e) { s_logger.error("Unable to read the cert string in console proxy resource",e); success = false; } - return new Answer(cmd, success, "Cert string in the console proxy resource status:"); + return new Answer(cmd, success, "Custom certificate response from the updatecertificate flow"); } protected Answer execute(final CheckConsoleProxyLoadCommand cmd) { diff --git a/server/src/com/cloud/server/ManagementServerImpl.java b/server/src/com/cloud/server/ManagementServerImpl.java index bcd2a37d0e2..7b3caf4e962 100755 --- a/server/src/com/cloud/server/ManagementServerImpl.java +++ b/server/src/com/cloud/server/ManagementServerImpl.java @@ -6950,9 +6950,9 @@ public class ManagementServerImpl implements ManagementServer { String certificatePath = cmd.getPath(); Long certVOId = _certDao.persistCustomCertToDb(certificatePath);//0 implies failure - if (certVOId!=null && certVOId!=0) { - //certficate uploaded to db successfully - + if (certVOId!=null && certVOId!=0) + { + //certficate uploaded to db successfully //get a list of all Console proxies from the cp table List cpList = _consoleProxyDao.listAll(); @@ -6964,12 +6964,11 @@ public class ManagementServerImpl implements ManagementServer { UpdateCertificateCommand certCmd = new UpdateCertificateCommand(_certDao.findById(certVOId).getCertificate()); try { Answer updateCertAns = _agentMgr.send(cpHost.getId(), certCmd); - if(updateCertAns.getResult() == true) { //we have the cert copied over on cpvm - long eventId = saveScheduledEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, EventTypes.EVENT_PROXY_REBOOT, "stopping console proxy with Id: "+cp.getId()); - boolean cpReboot = _consoleProxyMgr.rebootProxy(cp.getId(), eventId); + long eventId = saveScheduledEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, EventTypes.EVENT_PROXY_REBOOT, "rebooting console proxy with Id: "+cp.getId()); + _consoleProxyMgr.rebootProxy(cp.getId(), eventId); //when cp reboots, the context will be reinit with the new cert } } catch (AgentUnavailableException e) { @@ -6979,10 +6978,13 @@ public class ManagementServerImpl implements ManagementServer { } } - + + return true; + } + else + { + return false; } - - return true; } @Override diff --git a/setup/db/create-schema.sql b/setup/db/create-schema.sql index 3f2b97dff4d..69b0c5d800c 100755 --- a/setup/db/create-schema.sql +++ b/setup/db/create-schema.sql @@ -118,7 +118,7 @@ CREATE TABLE `cloud`.`account_network_ref` ( CREATE TABLE `cloud`.`certificate` ( `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'id', - `certificate` text COMMENT 'the actual custom certificate being stored in the db', + `certificate` text NOT NULL UNIQUE COMMENT 'the actual custom certificate being stored in the db', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;