Search in sources :

Example 1 with ModifyStoragePoolCommand

use of com.cloud.legacymodel.communication.command.ModifyStoragePoolCommand in project cosmic by MissionCriticalCloud.

the class LibvirtComputingResourceTest method testModifyStoragePoolCommandFailure.

@Test
public void testModifyStoragePoolCommandFailure() {
    final StoragePool pool = Mockito.mock(StoragePool.class);
    final ModifyStoragePoolCommand command = new ModifyStoragePoolCommand(true, pool);
    final KvmStoragePoolManager storagePoolMgr = Mockito.mock(KvmStoragePoolManager.class);
    when(this.libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
    when(storagePoolMgr.createStoragePool(command.getPool().getUuid(), command.getPool().getHost(), command.getPool().getPort(), command.getPool().getPath(), command.getPool().getUserInfo(), command.getPool().getType())).thenReturn(null);
    final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(command, this.libvirtComputingResource);
    assertFalse(answer.getResult());
    verify(this.libvirtComputingResource, times(1)).getStoragePoolMgr();
    verify(storagePoolMgr, times(1)).createStoragePool(command.getPool().getUuid(), command.getPool().getHost(), command.getPool().getPort(), command.getPool().getPath(), command.getPool().getUserInfo(), command.getPool().getType());
}
Also used : Answer(com.cloud.legacymodel.communication.answer.Answer) CheckRouterAnswer(com.cloud.legacymodel.communication.answer.CheckRouterAnswer) AttachAnswer(com.cloud.legacymodel.communication.answer.AttachAnswer) LibvirtRequestWrapper(com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper) NfsStoragePool(com.cloud.agent.resource.kvm.ha.KvmHaBase.NfsStoragePool) KvmStoragePool(com.cloud.agent.resource.kvm.storage.KvmStoragePool) StoragePool(com.cloud.legacymodel.storage.StoragePool) KvmStoragePoolManager(com.cloud.agent.resource.kvm.storage.KvmStoragePoolManager) ModifyStoragePoolCommand(com.cloud.legacymodel.communication.command.ModifyStoragePoolCommand) Test(org.junit.Test)

Example 2 with ModifyStoragePoolCommand

use of com.cloud.legacymodel.communication.command.ModifyStoragePoolCommand in project cosmic by MissionCriticalCloud.

the class LibvirtComputingResourceTest method testModifyStoragePoolCommand.

@Test
public void testModifyStoragePoolCommand() {
    final StoragePool pool = Mockito.mock(StoragePool.class);
    final ModifyStoragePoolCommand command = new ModifyStoragePoolCommand(true, pool);
    final KvmStoragePoolManager storagePoolMgr = Mockito.mock(KvmStoragePoolManager.class);
    final KvmStoragePool kvmStoragePool = Mockito.mock(KvmStoragePool.class);
    when(this.libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
    when(storagePoolMgr.createStoragePool(command.getPool().getUuid(), command.getPool().getHost(), command.getPool().getPort(), command.getPool().getPath(), command.getPool().getUserInfo(), command.getPool().getType())).thenReturn(kvmStoragePool);
    final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(command, this.libvirtComputingResource);
    assertTrue(answer.getResult());
    verify(this.libvirtComputingResource, times(1)).getStoragePoolMgr();
    verify(storagePoolMgr, times(1)).createStoragePool(command.getPool().getUuid(), command.getPool().getHost(), command.getPool().getPort(), command.getPool().getPath(), command.getPool().getUserInfo(), command.getPool().getType());
}
Also used : Answer(com.cloud.legacymodel.communication.answer.Answer) CheckRouterAnswer(com.cloud.legacymodel.communication.answer.CheckRouterAnswer) AttachAnswer(com.cloud.legacymodel.communication.answer.AttachAnswer) LibvirtRequestWrapper(com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper) NfsStoragePool(com.cloud.agent.resource.kvm.ha.KvmHaBase.NfsStoragePool) KvmStoragePool(com.cloud.agent.resource.kvm.storage.KvmStoragePool) StoragePool(com.cloud.legacymodel.storage.StoragePool) KvmStoragePool(com.cloud.agent.resource.kvm.storage.KvmStoragePool) KvmStoragePoolManager(com.cloud.agent.resource.kvm.storage.KvmStoragePoolManager) ModifyStoragePoolCommand(com.cloud.legacymodel.communication.command.ModifyStoragePoolCommand) Test(org.junit.Test)

Example 3 with ModifyStoragePoolCommand

use of com.cloud.legacymodel.communication.command.ModifyStoragePoolCommand in project cosmic by MissionCriticalCloud.

the class DefaultHostListener method hostConnect.

@Override
public boolean hostConnect(final long hostId, final long poolId) throws StorageConflictException {
    final StoragePool pool = (StoragePool) this.dataStoreMgr.getDataStore(poolId, DataStoreRole.Primary);
    final ModifyStoragePoolCommand cmd = new ModifyStoragePoolCommand(true, pool);
    final Answer answer = agentMgr.easySend(hostId, cmd);
    if (answer == null) {
        throw new CloudRuntimeException("Unable to get an answer to the modify storage pool command" + pool.getId());
    }
    if (!answer.getResult()) {
        final String msg = "Unable to attach storage pool" + poolId + " to the host" + hostId;
        alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_HOST, pool.getDataCenterId(), pool.getPodId(), msg, msg);
        throw new CloudRuntimeException("Unable establish connection from storage head to storage pool " + pool.getId() + " due to " + answer.getDetails() + pool.getId());
    }
    assert (answer instanceof ModifyStoragePoolAnswer) : "Well, now why won't you actually return the ModifyStoragePoolAnswer when it's ModifyStoragePoolCommand? Pool=" + pool.getId() + "Host=" + hostId;
    final ModifyStoragePoolAnswer mspAnswer = (ModifyStoragePoolAnswer) answer;
    if (mspAnswer.getLocalDatastoreName() != null && pool.isShared()) {
        final String datastoreName = mspAnswer.getLocalDatastoreName();
        final List<StoragePoolVO> localStoragePools = this.primaryStoreDao.listLocalStoragePoolByPath(pool.getDataCenterId(), datastoreName);
        for (final StoragePoolVO localStoragePool : localStoragePools) {
            if (datastoreName.equals(localStoragePool.getPath())) {
                s_logger.warn("Storage pool: " + pool.getId() + " has already been added as local storage: " + localStoragePool.getName());
                throw new StorageConflictException("Cannot add shared storage pool: " + pool.getId() + " because it has already been added as local storage:" + localStoragePool.getName());
            }
        }
    }
    StoragePoolHostVO poolHost = storagePoolHostDao.findByPoolHost(pool.getId(), hostId);
    if (poolHost == null) {
        poolHost = new StoragePoolHostVO(pool.getId(), hostId, mspAnswer.getPoolInfo().getLocalPath().replaceAll("//", "/"));
        storagePoolHostDao.persist(poolHost);
    } else {
        poolHost.setLocalPath(mspAnswer.getPoolInfo().getLocalPath().replaceAll("//", "/"));
    }
    final StoragePoolVO poolVO = this.primaryStoreDao.findById(poolId);
    poolVO.setUsedBytes(mspAnswer.getPoolInfo().getCapacityBytes() - mspAnswer.getPoolInfo().getAvailableBytes());
    poolVO.setCapacityBytes(mspAnswer.getPoolInfo().getCapacityBytes());
    primaryStoreDao.update(pool.getId(), poolVO);
    s_logger.info("Connection established between storage pool " + pool + " and host " + hostId);
    return true;
}
Also used : Answer(com.cloud.legacymodel.communication.answer.Answer) ModifyStoragePoolAnswer(com.cloud.legacymodel.communication.answer.ModifyStoragePoolAnswer) StoragePool(com.cloud.legacymodel.storage.StoragePool) StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) ModifyStoragePoolAnswer(com.cloud.legacymodel.communication.answer.ModifyStoragePoolAnswer) StoragePoolVO(com.cloud.storage.datastore.db.StoragePoolVO) StorageConflictException(com.cloud.legacymodel.exceptions.StorageConflictException) ModifyStoragePoolCommand(com.cloud.legacymodel.communication.command.ModifyStoragePoolCommand)

Example 4 with ModifyStoragePoolCommand

use of com.cloud.legacymodel.communication.command.ModifyStoragePoolCommand 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(), HostStatus.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(VirtualMachineType.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(VirtualMachineType.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(VirtualMachineType.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(VirtualMachineType.User)) {
                // don't allow to start vm that doesn't have a root volume
                if (volumeDao.findByInstanceAndType(vmInstance.getId(), VolumeType.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.legacymodel.user.Account) SecondaryStorageVmVO(com.cloud.vm.SecondaryStorageVmVO) UserVmVO(com.cloud.vm.UserVmVO) User(com.cloud.legacymodel.user.User) StoragePool(com.cloud.legacymodel.storage.StoragePool) ArrayList(java.util.ArrayList) VMInstanceVO(com.cloud.vm.VMInstanceVO) HostVO(com.cloud.host.HostVO) ModifyStoragePoolCommand(com.cloud.legacymodel.communication.command.ModifyStoragePoolCommand) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) Answer(com.cloud.legacymodel.communication.answer.Answer) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) StoragePoolVO(com.cloud.storage.datastore.db.StoragePoolVO) ConsoleProxyVO(com.cloud.vm.ConsoleProxyVO) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Example 5 with ModifyStoragePoolCommand

use of com.cloud.legacymodel.communication.command.ModifyStoragePoolCommand in project cosmic by MissionCriticalCloud.

the class NotAValidCommand method testModifyStoragePoolCommand.

@Test
public void testModifyStoragePoolCommand() {
    final StoragePoolVO poolVO = Mockito.mock(StoragePoolVO.class);
    final XsHost xsHost = Mockito.mock(XsHost.class);
    final ModifyStoragePoolCommand modifyStorageCommand = new ModifyStoragePoolCommand(false, poolVO);
    final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
    assertNotNull(wrapper);
    when(this.citrixResourceBase.getHost()).thenReturn(xsHost);
    final Answer answer = wrapper.execute(modifyStorageCommand, this.citrixResourceBase);
    verify(this.citrixResourceBase, times(1)).getConnection();
    assertFalse(answer.getResult());
}
Also used : RebootAnswer(com.cloud.legacymodel.communication.answer.RebootAnswer) Answer(com.cloud.legacymodel.communication.answer.Answer) CreateAnswer(com.cloud.legacymodel.communication.answer.CreateAnswer) AttachAnswer(com.cloud.legacymodel.communication.answer.AttachAnswer) XsHost(com.cloud.hypervisor.xenserver.resource.XsHost) StoragePoolVO(com.cloud.storage.datastore.db.StoragePoolVO) ModifyStoragePoolCommand(com.cloud.legacymodel.communication.command.ModifyStoragePoolCommand) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

Answer (com.cloud.legacymodel.communication.answer.Answer)6 ModifyStoragePoolCommand (com.cloud.legacymodel.communication.command.ModifyStoragePoolCommand)6 StoragePool (com.cloud.legacymodel.storage.StoragePool)5 StoragePoolVO (com.cloud.storage.datastore.db.StoragePoolVO)4 AttachAnswer (com.cloud.legacymodel.communication.answer.AttachAnswer)3 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)3 Test (org.junit.Test)3 NfsStoragePool (com.cloud.agent.resource.kvm.ha.KvmHaBase.NfsStoragePool)2 KvmStoragePool (com.cloud.agent.resource.kvm.storage.KvmStoragePool)2 KvmStoragePoolManager (com.cloud.agent.resource.kvm.storage.KvmStoragePoolManager)2 LibvirtRequestWrapper (com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper)2 HostVO (com.cloud.host.HostVO)2 CheckRouterAnswer (com.cloud.legacymodel.communication.answer.CheckRouterAnswer)2 Account (com.cloud.legacymodel.user.Account)2 User (com.cloud.legacymodel.user.User)2 ConsoleProxyVO (com.cloud.vm.ConsoleProxyVO)2 DomainRouterVO (com.cloud.vm.DomainRouterVO)2 SecondaryStorageVmVO (com.cloud.vm.SecondaryStorageVmVO)2 UserVmVO (com.cloud.vm.UserVmVO)2 VMInstanceVO (com.cloud.vm.VMInstanceVO)2