Search in sources :

Example 1 with SecondaryStorageVmVO

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;
    }
}
Also used : GlobalLock(com.cloud.utils.db.GlobalLock) SecondaryStorageVmVO(com.cloud.vm.SecondaryStorageVmVO) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException)

Example 2 with SecondaryStorageVmVO

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;
}
Also used : Account(com.cloud.user.Account) SecondaryStorageVmVO(com.cloud.vm.SecondaryStorageVmVO) UserVmVO(com.cloud.vm.UserVmVO) User(com.cloud.user.User) ArrayList(java.util.ArrayList) VMInstanceVO(com.cloud.vm.VMInstanceVO) HostVO(com.cloud.host.HostVO) ModifyStoragePoolCommand(com.cloud.agent.api.ModifyStoragePoolCommand) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Answer(com.cloud.agent.api.Answer) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) StoragePoolVO(com.cloud.storage.datastore.db.StoragePoolVO) ConsoleProxyVO(com.cloud.vm.ConsoleProxyVO) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Example 3 with SecondaryStorageVmVO

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;
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) SecondaryStorageVmVO(com.cloud.vm.SecondaryStorageVmVO) UpdateBuilder(com.cloud.utils.db.UpdateBuilder)

Example 4 with SecondaryStorageVmVO

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;
    }
}
Also used : SecondaryStorageVmVO(com.cloud.vm.SecondaryStorageVmVO) Zone(com.cloud.db.model.Zone) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 5 with SecondaryStorageVmVO

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";
}
Also used : SecondaryStorageVmVO(com.cloud.vm.SecondaryStorageVmVO) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) DB(com.cloud.utils.db.DB)

Aggregations

SecondaryStorageVmVO (com.cloud.vm.SecondaryStorageVmVO)53 HostVO (com.cloud.host.HostVO)18 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)16 Answer (com.cloud.agent.api.Answer)14 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)11 CheckSshAnswer (com.cloud.agent.api.check.CheckSshAnswer)10 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)9 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)9 SecStorageSetupAnswer (com.cloud.agent.api.SecStorageSetupAnswer)8 ArrayList (java.util.ArrayList)8 Account (com.cloud.user.Account)7 DB (com.cloud.utils.db.DB)6 NicProfile (com.cloud.vm.NicProfile)6 ConfigurationException (javax.naming.ConfigurationException)6 DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)6 DataStore (com.cloud.engine.subsystem.api.storage.DataStore)5 OperationTimedoutException (com.cloud.exception.OperationTimedoutException)5 Pair (com.cloud.utils.Pair)5 ModifyStoragePoolCommand (com.cloud.agent.api.ModifyStoragePoolCommand)4 InsufficientAddressCapacityException (com.cloud.exception.InsufficientAddressCapacityException)4