mirror of https://github.com/apache/cloudstack.git
incremental checkin around the console proxy config enh
This commit is contained in:
parent
9f92b81f45
commit
c98b2a7fa2
|
|
@ -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());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,5 +22,5 @@ import com.cloud.certificate.CertificateVO;
|
|||
import com.cloud.utils.db.GenericDao;
|
||||
|
||||
public interface CertificateDao extends GenericDao<CertificateVO, Long> {
|
||||
public boolean persistCustomCertToDb(String certPath);
|
||||
public Long persistCustomCertToDb(String certPath);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ public class CertificateDaoImpl extends GenericDaoBase<CertificateVO, Long> 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<CertificateVO, Long> 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<CertificateVO, Long> imp
|
|||
certRec.setCertificate(certStr);
|
||||
this.persist(certRec);
|
||||
|
||||
return true;
|
||||
return certRec.getId();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<HostVO> hosts = _hostDao.listAll();
|
||||
|
||||
List<VMInstanceVO> consoleProxyList = new ArrayList<VMInstanceVO>();
|
||||
List<HostVO> consoleProxyList = new ArrayList<HostVO>();
|
||||
|
||||
//find the console proxies, and send the command to them
|
||||
for(HostVO host : hosts) {
|
||||
//find corresponding vms for this host
|
||||
List<VMInstanceVO> 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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue