use of com.cloud.vm.SecondaryStorageVmVO in project cloudstack by apache.
the class SecondaryStorageManagerImpl method stopSecStorageVm.
@Override
public boolean stopSecStorageVm(long secStorageVmId) {
SecondaryStorageVmVO secStorageVm = _secStorageVmDao.findById(secStorageVmId);
if (secStorageVm == null) {
String msg = "Stopping secondary storage vm failed: secondary storage vm " + secStorageVmId + " no longer exists";
if (s_logger.isDebugEnabled()) {
s_logger.debug(msg);
}
return false;
}
try {
if (secStorageVm.getHostId() != null) {
GlobalLock secStorageVmLock = GlobalLock.getInternLock(getSecStorageVmLockName(secStorageVm.getId()));
try {
if (secStorageVmLock.lock(ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_SYNC)) {
try {
_itMgr.stop(secStorageVm.getUuid());
return true;
} finally {
secStorageVmLock.unlock();
}
} else {
String msg = "Unable to acquire secondary storage vm lock : " + secStorageVm.toString();
s_logger.debug(msg);
return false;
}
} finally {
secStorageVmLock.releaseRef();
}
}
// vm was already stopped, return true
return true;
} catch (ResourceUnavailableException e) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Stopping secondary storage vm " + secStorageVm.getHostName() + " faled : exception " + e.toString());
}
return false;
}
}
use of com.cloud.vm.SecondaryStorageVmVO in project cosmic by MissionCriticalCloud.
the class StoragePoolAutomationImpl method cancelMaintain.
@Override
public boolean cancelMaintain(final DataStore store) {
// Change the storage state back to up
final Long userId = CallContext.current().getCallingUserId();
final User user = _userDao.findById(userId);
final Account account = CallContext.current().getCallingAccount();
final StoragePoolVO poolVO = primaryDataStoreDao.findById(store.getId());
final StoragePool pool = (StoragePool) store;
// Handeling the Zone wide and cluster wide primay storage
List<HostVO> hosts = new ArrayList<>();
// if the storage scope is ZONE wide, then get all the hosts for which hypervisor ZWSP created to send Modifystoragepoolcommand
if (poolVO.getScope().equals(ScopeType.ZONE)) {
if (HypervisorType.Any.equals(pool.getHypervisor())) {
hosts = _resourceMgr.listAllUpAndEnabledHostsInOneZone(pool.getDataCenterId());
} else {
hosts = _resourceMgr.listAllUpAndEnabledHostsInOneZoneByHypervisor(poolVO.getHypervisor(), pool.getDataCenterId());
}
} else {
hosts = _resourceMgr.listHostsInClusterByStatus(pool.getClusterId(), Status.Up);
}
if (hosts == null || hosts.size() == 0) {
return true;
}
// add heartbeat
for (final HostVO host : hosts) {
final ModifyStoragePoolCommand msPoolCmd = new ModifyStoragePoolCommand(true, pool);
final Answer answer = agentMgr.easySend(host.getId(), msPoolCmd);
if (answer == null || !answer.getResult()) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("ModifyStoragePool add failed due to " + ((answer == null) ? "answer null" : answer.getDetails()));
}
} else {
if (s_logger.isDebugEnabled()) {
s_logger.debug("ModifyStoragePool add secceeded");
}
}
}
// 2. Get a list of pending work for this queue
final List<StoragePoolWorkVO> pendingWork = _storagePoolWorkDao.listPendingWorkForCancelMaintenanceByPoolId(poolVO.getId());
// 3. work through the queue
for (final StoragePoolWorkVO work : pendingWork) {
try {
final VMInstanceVO vmInstance = vmDao.findById(work.getVmId());
if (vmInstance == null) {
continue;
}
// proxy
if (vmInstance.getType().equals(VirtualMachine.Type.ConsoleProxy)) {
final ConsoleProxyVO consoleProxy = _consoleProxyDao.findById(vmInstance.getId());
vmMgr.advanceStart(consoleProxy.getUuid(), null, null);
// update work queue
work.setStartedAfterMaintenance(true);
_storagePoolWorkDao.update(work.getId(), work);
}
// if the instance is of type ssvm, call the ssvm manager
if (vmInstance.getType().equals(VirtualMachine.Type.SecondaryStorageVm)) {
final SecondaryStorageVmVO ssVm = _secStrgDao.findById(vmInstance.getId());
vmMgr.advanceStart(ssVm.getUuid(), null, null);
// update work queue
work.setStartedAfterMaintenance(true);
_storagePoolWorkDao.update(work.getId(), work);
}
// manager
if (vmInstance.getType().equals(VirtualMachine.Type.DomainRouter)) {
final DomainRouterVO domR = _domrDao.findById(vmInstance.getId());
vmMgr.advanceStart(domR.getUuid(), null, null);
// update work queue
work.setStartedAfterMaintenance(true);
_storagePoolWorkDao.update(work.getId(), work);
}
// if the instance is of type user vm, call the user vm manager
if (vmInstance.getType().equals(VirtualMachine.Type.User)) {
// don't allow to start vm that doesn't have a root volume
if (volumeDao.findByInstanceAndType(vmInstance.getId(), Volume.Type.ROOT).isEmpty()) {
_storagePoolWorkDao.remove(work.getId());
} else {
final UserVmVO userVm = userVmDao.findById(vmInstance.getId());
vmMgr.advanceStart(userVm.getUuid(), null, null);
work.setStartedAfterMaintenance(true);
_storagePoolWorkDao.update(work.getId(), work);
}
}
} catch (final Exception e) {
s_logger.debug("Failed start vm", e);
throw new CloudRuntimeException(e.toString());
}
}
return false;
}
use of com.cloud.vm.SecondaryStorageVmVO in project cosmic by MissionCriticalCloud.
the class SecondaryStorageVmDaoImpl method remove.
@Override
public boolean remove(final Long id) {
final TransactionLegacy txn = TransactionLegacy.currentTxn();
txn.start();
final SecondaryStorageVmVO proxy = createForUpdate();
proxy.setPublicIpAddress(null);
proxy.setPrivateIpAddress(null);
final UpdateBuilder ub = getUpdateBuilder(proxy);
ub.set(proxy, "state", State.Destroyed);
ub.set(proxy, "privateIpAddress", null);
update(id, ub, proxy);
final boolean result = super.remove(id);
txn.commit();
return result;
}
use of com.cloud.vm.SecondaryStorageVmVO in project cosmic by MissionCriticalCloud.
the class SecondaryStorageVmAlertAdapter method onSSVMAlert.
public void onSSVMAlert(final Object sender, final SecStorageVmAlertEventArgs args) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("received secondary storage vm alert");
}
final Zone zone = zoneRepository.findOne(args.getZoneId());
SecondaryStorageVmVO secStorageVm = args.getSecStorageVm();
if (secStorageVm == null && args.getSecStorageVmId() != 0) {
secStorageVm = _ssvmDao.findById(args.getSecStorageVmId());
}
if (secStorageVm == null && args.getType() != SecStorageVmAlertEventArgs.SSVM_CREATE_FAILURE) {
throw new CloudRuntimeException("Invalid alert arguments, secStorageVm must be set");
}
switch(args.getType()) {
case SecStorageVmAlertEventArgs.SSVM_CREATED:
if (s_logger.isDebugEnabled()) {
s_logger.debug("New secondary storage vm created, zone: " + zone.getName() + ", secStorageVm: " + secStorageVm.getHostName() + ", public IP: " + secStorageVm.getPublicIpAddress() + ", private IP: " + secStorageVm.getPrivateIpAddress());
}
break;
case SecStorageVmAlertEventArgs.SSVM_UP:
if (s_logger.isDebugEnabled()) {
s_logger.debug("Secondary Storage Vm is up, zone: " + zone.getName() + ", secStorageVm: " + secStorageVm.getHostName() + ", public IP: " + secStorageVm.getPublicIpAddress() + ", private IP: " + secStorageVm.getPrivateIpAddress());
}
_alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_SSVM, args.getZoneId(), secStorageVm.getPodIdToDeployIn(), "Secondary Storage Vm up in zone: " + zone.getName() + ", secStorageVm: " + secStorageVm.getHostName() + ", public IP: " + secStorageVm.getPublicIpAddress() + ", private IP: " + (secStorageVm.getPrivateIpAddress() == null ? "N/A" : secStorageVm.getPrivateIpAddress()), "Secondary Storage Vm up (zone " + zone.getName() + ")");
break;
case SecStorageVmAlertEventArgs.SSVM_DOWN:
if (s_logger.isDebugEnabled()) {
s_logger.debug("Secondary Storage Vm is down, zone: " + zone.getName() + ", secStorageVm: " + secStorageVm.getHostName() + ", public IP: " + secStorageVm.getPublicIpAddress() + ", private IP: " + (secStorageVm.getPrivateIpAddress() == null ? "N/A" : secStorageVm.getPrivateIpAddress()));
}
_alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_SSVM, args.getZoneId(), secStorageVm.getPodIdToDeployIn(), "Secondary Storage Vm down in zone: " + zone.getName() + ", secStorageVm: " + secStorageVm.getHostName() + ", public IP: " + secStorageVm.getPublicIpAddress() + ", private IP: " + (secStorageVm.getPrivateIpAddress() == null ? "N/A" : secStorageVm.getPrivateIpAddress()), "Secondary Storage Vm down (zone " + zone.getName() + ")");
break;
case SecStorageVmAlertEventArgs.SSVM_REBOOTED:
if (s_logger.isDebugEnabled()) {
s_logger.debug("Secondary Storage Vm is rebooted, zone: " + zone.getName() + ", secStorageVm: " + secStorageVm.getHostName() + ", public IP: " + secStorageVm.getPublicIpAddress() + ", private IP: " + (secStorageVm.getPrivateIpAddress() == null ? "N/A" : secStorageVm.getPrivateIpAddress()));
}
_alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_SSVM, args.getZoneId(), secStorageVm.getPodIdToDeployIn(), "Secondary Storage Vm rebooted in zone: " + zone.getName() + ", secStorageVm: " + secStorageVm.getHostName() + ", public IP: " + secStorageVm.getPublicIpAddress() + ", private IP: " + (secStorageVm.getPrivateIpAddress() == null ? "N/A" : secStorageVm.getPrivateIpAddress()), "Secondary Storage Vm rebooted (zone " + zone.getName() + ")");
break;
case SecStorageVmAlertEventArgs.SSVM_CREATE_FAILURE:
if (s_logger.isDebugEnabled()) {
s_logger.debug("Secondary Storage Vm creation failure, zone: " + zone.getName());
}
_alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_SSVM, args.getZoneId(), null, "Secondary Storage Vm creation failure. zone: " + zone.getName() + ", error details: " + args.getMessage(), "Secondary Storage Vm creation failure (zone " + zone.getName() + ")");
break;
case SecStorageVmAlertEventArgs.SSVM_START_FAILURE:
if (s_logger.isDebugEnabled()) {
s_logger.debug("Secondary Storage Vm startup failure, zone: " + zone.getName() + ", secStorageVm: " + secStorageVm.getHostName() + ", public IP: " + secStorageVm.getPublicIpAddress() + ", private IP: " + (secStorageVm.getPrivateIpAddress() == null ? "N/A" : secStorageVm.getPrivateIpAddress()));
}
_alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_SSVM, args.getZoneId(), secStorageVm.getPodIdToDeployIn(), "Secondary Storage Vm startup failure. zone: " + zone.getName() + ", secStorageVm: " + secStorageVm.getHostName() + ", public IP: " + secStorageVm.getPublicIpAddress() + ", private IP: " + (secStorageVm.getPrivateIpAddress() == null ? "N/A" : secStorageVm.getPrivateIpAddress()) + ", error details: " + args.getMessage(), "Secondary Storage Vm startup failure (zone " + zone.getName() + ")");
break;
case SecStorageVmAlertEventArgs.SSVM_FIREWALL_ALERT:
if (s_logger.isDebugEnabled()) {
s_logger.debug("Secondary Storage Vm firewall alert, zone: " + zone.getName() + ", secStorageVm: " + secStorageVm.getHostName() + ", public IP: " + secStorageVm.getPublicIpAddress() + ", private IP: " + (secStorageVm.getPrivateIpAddress() == null ? "N/A" : secStorageVm.getPrivateIpAddress()));
}
_alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_SSVM, args.getZoneId(), secStorageVm.getPodIdToDeployIn(), "Failed to open secondary storage vm firewall port. zone: " + zone.getName() + ", secStorageVm: " + secStorageVm.getHostName() + ", public IP: " + secStorageVm.getPublicIpAddress() + ", private IP: " + (secStorageVm.getPrivateIpAddress() == null ? "N/A" : secStorageVm.getPrivateIpAddress()), "Secondary Storage Vm alert (zone " + zone.getName() + ")");
break;
case SecStorageVmAlertEventArgs.SSVM_STORAGE_ALERT:
if (s_logger.isDebugEnabled()) {
s_logger.debug("Secondary Storage Vm storage alert, zone: " + zone.getName() + ", secStorageVm: " + secStorageVm.getHostName() + ", public IP: " + secStorageVm.getPublicIpAddress() + ", private IP: " + secStorageVm.getPrivateIpAddress() + ", message: " + args.getMessage());
}
_alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_STORAGE_MISC, args.getZoneId(), secStorageVm.getPodIdToDeployIn(), "Secondary Storage Vm storage issue. zone: " + zone.getName() + ", message: " + args.getMessage(), "Secondary Storage Vm alert (zone " + zone.getName() + ")");
break;
}
}
use of com.cloud.vm.SecondaryStorageVmVO in project cosmic by MissionCriticalCloud.
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";
}
Aggregations