use of com.cloud.vm.SecondaryStorageVmVO in project cloudstack by apache.
the class SecondaryStorageManagerImpl method destroySecStorageVm.
@Override
public boolean destroySecStorageVm(long vmId) {
SecondaryStorageVmVO ssvm = _secStorageVmDao.findById(vmId);
try {
_itMgr.expunge(ssvm.getUuid());
_secStorageVmDao.remove(ssvm.getId());
HostVO host = _hostDao.findByTypeNameAndZoneId(ssvm.getDataCenterId(), ssvm.getHostName(), Host.Type.SecondaryStorageVM);
if (host != null) {
s_logger.debug("Removing host entry for ssvm id=" + vmId);
_hostDao.remove(host.getId());
//Expire the download urls in the entire zone for templates and volumes.
_tmplStoreDao.expireDnldUrlsForZone(host.getDataCenterId());
_volumeStoreDao.expireDnldUrlsForZone(host.getDataCenterId());
return true;
}
return false;
} catch (ResourceUnavailableException e) {
s_logger.warn("Unable to expunge " + ssvm, e);
return false;
}
}
use of com.cloud.vm.SecondaryStorageVmVO in project cloudstack by apache.
the class ManagementServerImpl method uploadCertificate.
@Override
@DB
public String uploadCertificate(final UploadCustomCertificateCmd cmd) {
if (cmd.getPrivateKey() != null && cmd.getAlias() != null) {
throw new InvalidParameterValueException("Can't change the alias for private key certification");
}
if (cmd.getPrivateKey() == null) {
if (cmd.getAlias() == null) {
throw new InvalidParameterValueException("alias can't be empty, if it's a certification chain");
}
if (cmd.getCertIndex() == null) {
throw new InvalidParameterValueException("index can't be empty, if it's a certifciation chain");
}
}
final String certificate = cmd.getCertificate();
final String key = cmd.getPrivateKey();
if (cmd.getPrivateKey() != null && !_ksMgr.validateCertificate(certificate, key, cmd.getDomainSuffix())) {
throw new InvalidParameterValueException("Failed to pass certificate validation check");
}
if (cmd.getPrivateKey() != null) {
_ksMgr.saveCertificate(ConsoleProxyManager.CERTIFICATE_NAME, certificate, key, cmd.getDomainSuffix());
// Reboot ssvm here since private key is present - meaning server cert being passed
final List<SecondaryStorageVmVO> alreadyRunning = _secStorageVmDao.getSecStorageVmListInStates(null, State.Running, State.Migrating, State.Starting);
for (final SecondaryStorageVmVO ssVmVm : alreadyRunning) {
_secStorageVmMgr.rebootSecStorageVm(ssVmVm.getId());
}
} else {
_ksMgr.saveCertificate(cmd.getAlias(), certificate, cmd.getCertIndex(), cmd.getDomainSuffix());
}
_consoleProxyMgr.setManagementState(ConsoleProxyManagementState.ResetSuspending);
return "Certificate has been successfully updated, if its the server certificate we would reboot all " + "running console proxy VMs and secondary storage VMs to propagate the new certificate, " + "please give a few minutes for console access and storage services service to be up and working again";
}
use of com.cloud.vm.SecondaryStorageVmVO in project cloudstack by apache.
the class PremiumSecondaryStorageManagerImpl method scanPool.
@Override
public Pair<AfterScanAction, Object> scanPool(Long pool) {
long dataCenterId = pool.longValue();
if (!isSecondaryStorageVmRequired(dataCenterId)) {
return new Pair<AfterScanAction, Object>(AfterScanAction.nop, null);
}
Date cutTime = new Date(DateUtil.currentGMTTime().getTime() - _maxExecutionTimeMs);
_cmdExecLogDao.expungeExpiredRecords(cutTime);
boolean suspendAutoLoading = !reserveStandbyCapacity();
if (!suspendAutoLoading) {
// this is a hacking, has nothing to do with console proxy, it is just a flag that primary storage is being under maintenance mode
String restart = _configDao.getValue("consoleproxy.restart");
if (restart != null && restart.equalsIgnoreCase("false")) {
s_logger.debug("Capacity scan disabled purposefully, consoleproxy.restart = false. This happens when the primarystorage is in maintenance mode");
suspendAutoLoading = true;
}
}
List<SecondaryStorageVmVO> alreadyRunning = _secStorageVmDao.getSecStorageVmListInStates(SecondaryStorageVm.Role.templateProcessor, dataCenterId, State.Running, State.Migrating, State.Starting);
if (alreadyRunning.size() == 0) {
s_logger.info("No running secondary storage vms found in datacenter id=" + dataCenterId + ", starting one");
List<SecondaryStorageVmVO> stopped = _secStorageVmDao.getSecStorageVmListInStates(SecondaryStorageVm.Role.templateProcessor, dataCenterId, State.Stopped, State.Stopping);
if (stopped.size() == 0 || !suspendAutoLoading) {
List<SecondaryStorageVmVO> stopping = _secStorageVmDao.getSecStorageVmListInStates(SecondaryStorageVm.Role.templateProcessor, State.Stopping);
if (stopping.size() > 0) {
s_logger.info("Found SSVMs that are currently at stopping state, wait until they are settled");
return new Pair<AfterScanAction, Object>(AfterScanAction.nop, null);
}
expandPool(pool, SecondaryStorageVm.Role.templateProcessor);
}
}
if (!suspendAutoLoading) {
// this is to avoid surprises that people may accidently see two SSVMs being launched, capacity expanding only happens when we have at least the primary SSVM is up
if (alreadyRunning.size() == 0) {
s_logger.info("Primary secondary storage is not even started, wait until next turn");
return new Pair<AfterScanAction, Object>(AfterScanAction.nop, null);
}
alreadyRunning = _secStorageVmDao.getSecStorageVmListInStates(null, dataCenterId, State.Running, State.Migrating, State.Starting);
List<CommandExecLogVO> activeCmds = listActiveCommands(dataCenterId, cutTime);
if (alreadyRunning.size() * _capacityPerSSVM - activeCmds.size() < _standbyCapacity) {
s_logger.info("secondary storage command execution standby capactiy low (running VMs: " + alreadyRunning.size() + ", active cmds: " + activeCmds.size() + "), starting a new one");
return new Pair<AfterScanAction, Object>(AfterScanAction.expand, SecondaryStorageVm.Role.commandExecutor);
}
}
return new Pair<AfterScanAction, Object>(AfterScanAction.nop, null);
}
use of com.cloud.vm.SecondaryStorageVmVO in project cloudstack by apache.
the class SecondaryStorageManagerImpl method allocCapacity.
private void allocCapacity(long dataCenterId, SecondaryStorageVm.Role role) {
if (s_logger.isTraceEnabled()) {
s_logger.trace("Allocate secondary storage vm standby capacity for data center : " + dataCenterId);
}
if (!isSecondaryStorageVmRequired(dataCenterId)) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Secondary storage vm not required in zone " + dataCenterId + " according to zone config");
}
return;
}
SecondaryStorageVmVO secStorageVm = null;
String errorString = null;
try {
boolean secStorageVmFromStoppedPool = false;
secStorageVm = assignSecStorageVmFromStoppedPool(dataCenterId, role);
if (secStorageVm == null) {
if (s_logger.isInfoEnabled()) {
s_logger.info("No stopped secondary storage vm is available, need to allocate a new secondary storage vm");
}
if (_allocLock.lock(ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_SYNC)) {
try {
secStorageVm = startNew(dataCenterId, role);
for (UploadVO upload : _uploadDao.listAll()) {
_uploadDao.expunge(upload.getId());
}
} finally {
_allocLock.unlock();
}
} else {
if (s_logger.isInfoEnabled()) {
s_logger.info("Unable to acquire synchronization lock for secondary storage vm allocation, wait for next scan");
}
return;
}
} else {
if (s_logger.isInfoEnabled()) {
s_logger.info("Found a stopped secondary storage vm, starting it. Vm id : " + secStorageVm.getId());
}
secStorageVmFromStoppedPool = true;
}
if (secStorageVm != null) {
long secStorageVmId = secStorageVm.getId();
GlobalLock secStorageVmLock = GlobalLock.getInternLock(getSecStorageVmLockName(secStorageVmId));
try {
if (secStorageVmLock.lock(ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_SYNC)) {
try {
secStorageVm = startSecStorageVm(secStorageVmId);
} finally {
secStorageVmLock.unlock();
}
} else {
if (s_logger.isInfoEnabled()) {
s_logger.info("Unable to acquire synchronization lock for starting secondary storage vm id : " + secStorageVm.getId());
}
return;
}
} finally {
secStorageVmLock.releaseRef();
}
if (secStorageVm == null) {
if (s_logger.isInfoEnabled()) {
s_logger.info("Unable to start secondary storage vm for standby capacity, vm id : " + secStorageVmId + ", will recycle it and start a new one");
}
if (secStorageVmFromStoppedPool) {
destroySecStorageVm(secStorageVmId);
}
} else {
SubscriptionMgr.getInstance().notifySubscribers(ALERT_SUBJECT, this, new SecStorageVmAlertEventArgs(SecStorageVmAlertEventArgs.SSVM_UP, dataCenterId, secStorageVmId, secStorageVm, null));
if (s_logger.isInfoEnabled()) {
s_logger.info("Secondary storage vm " + secStorageVm.getHostName() + " is started");
}
}
}
} catch (Exception e) {
errorString = e.getMessage();
throw e;
} finally {
// Also add failure reason since startvm masks some of them.
if (secStorageVm == null || secStorageVm.getState() != State.Running)
SubscriptionMgr.getInstance().notifySubscribers(ALERT_SUBJECT, this, new SecStorageVmAlertEventArgs(SecStorageVmAlertEventArgs.SSVM_CREATE_FAILURE, dataCenterId, 0l, null, errorString));
}
}
use of com.cloud.vm.SecondaryStorageVmVO in project cloudstack by apache.
the class SecondaryStorageManagerImpl method generateVMSetupCommand.
@Override
public boolean generateVMSetupCommand(Long ssAHostId) {
HostVO ssAHost = _hostDao.findById(ssAHostId);
if (ssAHost.getType() != Host.Type.SecondaryStorageVM) {
return false;
}
SecondaryStorageVmVO secStorageVm = _secStorageVmDao.findByInstanceName(ssAHost.getName());
if (secStorageVm == null) {
s_logger.warn("secondary storage VM " + ssAHost.getName() + " doesn't exist");
return false;
}
SecStorageVMSetupCommand setupCmd = new SecStorageVMSetupCommand();
if (_allowedInternalSites != null) {
List<String> allowedCidrs = new ArrayList<String>();
String[] cidrs = _allowedInternalSites.split(",");
for (String cidr : cidrs) {
if (NetUtils.isValidCIDR(cidr) || NetUtils.isValidIp(cidr) || !cidr.startsWith("0.0.0.0")) {
allowedCidrs.add(cidr);
}
}
setupCmd.setAllowedInternalSites(allowedCidrs.toArray(new String[allowedCidrs.size()]));
}
String copyPasswd = _configDao.getValue("secstorage.copy.password");
setupCmd.setCopyPassword(copyPasswd);
setupCmd.setCopyUserName(TemplateConstants.DEFAULT_HTTP_AUTH_USER);
Answer answer = _agentMgr.easySend(ssAHostId, setupCmd);
if (answer != null && answer.getResult()) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Successfully programmed http auth into " + secStorageVm.getHostName());
}
return true;
} else {
if (s_logger.isDebugEnabled()) {
s_logger.debug("failed to program http auth into secondary storage vm : " + secStorageVm.getHostName());
}
return false;
}
}
Aggregations