Skip to content

Commit c98b2a7

Browse files
rootabhishek
authored andcommitted
incremental checkin around the console proxy config enh
1 parent 9f92b81 commit c98b2a7

4 files changed

Lines changed: 45 additions & 19 deletions

File tree

‎agent/src/com/cloud/agent/resource/consoleproxy/ConsoleProxyResource.java‎

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import com.cloud.agent.api.StartupProxyCommand;
5050
import com.cloud.agent.api.proxy.CheckConsoleProxyLoadCommand;
5151
import com.cloud.agent.api.proxy.ConsoleProxyLoadAnswer;
52+
import com.cloud.agent.api.proxy.UpdateCertificateCommand;
5253
import com.cloud.agent.api.proxy.WatchConsoleProxyLoadCommand;
5354
import com.cloud.exception.AgentControlChannelException;
5455
import com.cloud.host.Host;
@@ -83,6 +84,7 @@ public class ConsoleProxyResource extends ServerResourceBase implements ServerRe
8384
String _eth1ip;
8485
String _eth1mask;
8586
String _pubIp;
87+
String certificate;
8688

8789
@Override
8890
public Answer executeRequest(final Command cmd) {
@@ -95,11 +97,27 @@ public Answer executeRequest(final Command cmd) {
9597
return new ReadyAnswer((ReadyCommand)cmd);
9698
} else if(cmd instanceof CheckHealthCommand) {
9799
return new CheckHealthAnswer((CheckHealthCommand)cmd, true);
98-
} else {
100+
} else if(cmd instanceof UpdateCertificateCommand) {
101+
return execute((UpdateCertificateCommand)cmd);
102+
}
103+
else {
99104
return Answer.createUnsupportedCommandAnswer(cmd);
100105
}
101106
}
102-
107+
108+
protected Answer execute(final UpdateCertificateCommand cmd) {
109+
boolean success = false;
110+
try{
111+
certificate = cmd.getCertificate();
112+
success = true;
113+
return new Answer(cmd, success, "Cert string in the console proxy resource status:");
114+
}catch (Exception e)
115+
{
116+
s_logger.error("Unable to read the cert string in console proxy resource");
117+
}
118+
return new Answer(cmd, success, "Cert string in the console proxy resource status:");
119+
}
120+
103121
protected Answer execute(final CheckConsoleProxyLoadCommand cmd) {
104122
return executeProxyLoadScan(cmd, cmd.getProxyVmId(), cmd.getProxyVmName(), cmd.getProxyManagementIp(), cmd.getProxyCmdPort());
105123
}

‎core/src/com/cloud/certificate/dao/CertificateDao.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@
2222
import com.cloud.utils.db.GenericDao;
2323

2424
public interface CertificateDao extends GenericDao<CertificateVO, Long> {
25-
public boolean persistCustomCertToDb(String certPath);
25+
public Long persistCustomCertToDb(String certPath);
2626
}

‎core/src/com/cloud/certificate/dao/CertificateDaoImpl.java‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public CertificateDaoImpl(){
2424
}
2525

2626
@Override
27-
public boolean persistCustomCertToDb(String certPath){
27+
public Long persistCustomCertToDb(String certPath){
2828

2929
String certStr = null;
3030
byte[] buffer = new byte[(int) new File(certPath).length()];
@@ -35,10 +35,10 @@ public boolean persistCustomCertToDb(String certPath){
3535
f.read(buffer);
3636
} catch (FileNotFoundException e) {
3737
s_logger.warn("Unable to read the certificate: "+e);
38-
return false;
38+
return new Long(0);
3939
} catch (IOException e) {
4040
s_logger.warn("Unable to read the certificate: "+e);
41-
return false;
41+
return new Long(0);
4242
}
4343
finally
4444
{
@@ -51,6 +51,6 @@ public boolean persistCustomCertToDb(String certPath){
5151
certRec.setCertificate(certStr);
5252
this.persist(certRec);
5353

54-
return true;
54+
return certRec.getId();
5555
}
5656
}

‎server/src/com/cloud/server/ManagementServerImpl.java‎

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,10 @@
5252
import org.apache.log4j.Logger;
5353

5454
import com.cloud.agent.AgentManager;
55+
import com.cloud.agent.api.Answer;
5556
import com.cloud.agent.api.GetVncPortAnswer;
5657
import com.cloud.agent.api.GetVncPortCommand;
58+
import com.cloud.agent.api.proxy.UpdateCertificateCommand;
5759
import com.cloud.agent.api.storage.CopyVolumeAnswer;
5860
import com.cloud.agent.api.storage.CopyVolumeCommand;
5961
import com.cloud.alert.AlertManager;
@@ -180,6 +182,7 @@
180182
import com.cloud.exception.InternalErrorException;
181183
import com.cloud.exception.InvalidParameterValueException;
182184
import com.cloud.exception.NetworkRuleConflictException;
185+
import com.cloud.exception.OperationTimedoutException;
183186
import com.cloud.exception.PermissionDeniedException;
184187
import com.cloud.exception.ResourceAllocationException;
185188
import com.cloud.exception.StorageUnavailableException;
@@ -6866,30 +6869,35 @@ public String getVersion(){
68666869
@Override
68676870
public boolean uploadCertificate(UploadCustomCertificateCmd cmd) {
68686871
String certificatePath = cmd.getPath();
6869-
boolean uploadStatus = _certDao.persistCustomCertToDb(certificatePath);
6872+
Long certVOId = _certDao.persistCustomCertToDb(certificatePath);//0 implies failure
68706873

6871-
if (uploadStatus) {
6874+
if (certVOId!=null && certVOId!=0) {
68726875
//certficate uploaded to db successfully
68736876

68746877
//get a list of all hosts from host table
68756878
List<HostVO> hosts = _hostDao.listAll();
68766879

6877-
List<VMInstanceVO> consoleProxyList = new ArrayList<VMInstanceVO>();
6880+
List<HostVO> consoleProxyList = new ArrayList<HostVO>();
68786881

68796882
//find the console proxies, and send the command to them
68806883
for(HostVO host : hosts) {
6881-
//find corresponding vms for this host
6882-
List<VMInstanceVO> vmList = _vmInstanceDao.listByHostId(host.getId());
6883-
6884-
for(VMInstanceVO vm : vmList){
6885-
if(VirtualMachineName.isValidConsoleProxyName(vm.getInstanceName())){
6886-
consoleProxyList.add(vm);
6887-
}
6884+
if(host.getType().equals(com.cloud.host.Host.Type.ConsoleProxy)){
6885+
consoleProxyList.add(host);
68886886
}
68896887
}
68906888

6891-
//now restart each of these proxies
6892-
//restart will
6889+
for(HostVO consoleProxy : consoleProxyList){
6890+
//now send a command to each console proxy
6891+
UpdateCertificateCommand certCmd = new UpdateCertificateCommand(_certDao.findById(certVOId).getCertificate());
6892+
try {
6893+
Answer updateCertAns = _agentMgr.send(consoleProxy.getId(), certCmd);
6894+
int a = 30;
6895+
} catch (AgentUnavailableException e) {
6896+
s_logger.warn("Unable to send command to the console proxy resource", e);
6897+
} catch (OperationTimedoutException e) {
6898+
s_logger.warn("Unable to send command to the console proxy resource", e);
6899+
}
6900+
}
68936901
}
68946902

68956903
return false;

0 commit comments

Comments
 (0)