Search in sources :

Example 26 with StoragePoolVO

use of com.cloud.storage.datastore.db.StoragePoolVO 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 : ModifyStoragePoolAnswer(com.cloud.agent.api.ModifyStoragePoolAnswer) Answer(com.cloud.agent.api.Answer) StoragePool(com.cloud.storage.StoragePool) StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ModifyStoragePoolAnswer(com.cloud.agent.api.ModifyStoragePoolAnswer) StoragePoolVO(com.cloud.storage.datastore.db.StoragePoolVO) StorageConflictException(com.cloud.exception.StorageConflictException) ModifyStoragePoolCommand(com.cloud.agent.api.ModifyStoragePoolCommand)

Example 27 with StoragePoolVO

use of com.cloud.storage.datastore.db.StoragePoolVO in project cosmic by MissionCriticalCloud.

the class NotAValidCommand method testDeleteStoragePoolCommand.

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

Example 28 with StoragePoolVO

use of com.cloud.storage.datastore.db.StoragePoolVO in project cosmic by MissionCriticalCloud.

the class NotAValidCommand method testPrimaryStorageDownloadCommand.

@Test
public void testPrimaryStorageDownloadCommand() {
    final XsHost xsHost = Mockito.mock(XsHost.class);
    final StoragePoolVO poolVO = Mockito.mock(StoragePoolVO.class);
    final PrimaryStorageDownloadCommand storageDownloadCommand = new PrimaryStorageDownloadCommand("Test", "http://127.0.0.1", ImageFormat.VHD, 1l, poolVO, 200);
    final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
    assertNotNull(wrapper);
    when(citrixResourceBase.getHost()).thenReturn(xsHost);
    final Answer answer = wrapper.execute(storageDownloadCommand, citrixResourceBase);
    verify(citrixResourceBase, times(1)).getConnection();
    assertFalse(answer.getResult());
}
Also used : RebootAnswer(com.cloud.agent.api.RebootAnswer) CreateAnswer(com.cloud.agent.api.storage.CreateAnswer) Answer(com.cloud.agent.api.Answer) AttachAnswer(com.cloud.storage.command.AttachAnswer) XsHost(com.cloud.hypervisor.xenserver.resource.XsHost) PrimaryStorageDownloadCommand(com.cloud.agent.api.storage.PrimaryStorageDownloadCommand) StoragePoolVO(com.cloud.storage.datastore.db.StoragePoolVO) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 29 with StoragePoolVO

use of com.cloud.storage.datastore.db.StoragePoolVO in project cosmic by MissionCriticalCloud.

the class NotAValidCommand method testUpgradeSnapshotCommand.

@Test
public void testUpgradeSnapshotCommand() {
    final StoragePoolVO poolVO = Mockito.mock(StoragePoolVO.class);
    final UpgradeSnapshotCommand upgradeSnapshotCommand = new UpgradeSnapshotCommand(poolVO, "http", 1l, 1l, 1l, 1l, 1l, "/", "58c5778b-7dd1-47cc-a7b5-f768541bf278", "Test", "2.1");
    final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(upgradeSnapshotCommand, citrixResourceBase);
    verify(citrixResourceBase, times(1)).getConnection();
    assertTrue(answer.getResult());
}
Also used : RebootAnswer(com.cloud.agent.api.RebootAnswer) CreateAnswer(com.cloud.agent.api.storage.CreateAnswer) Answer(com.cloud.agent.api.Answer) AttachAnswer(com.cloud.storage.command.AttachAnswer) StoragePoolVO(com.cloud.storage.datastore.db.StoragePoolVO) UpgradeSnapshotCommand(com.cloud.agent.api.UpgradeSnapshotCommand) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 30 with StoragePoolVO

use of com.cloud.storage.datastore.db.StoragePoolVO in project cosmic by MissionCriticalCloud.

the class NotAValidCommand method testUpgradeSnapshotCommandNo21.

@Test
public void testUpgradeSnapshotCommandNo21() {
    final StoragePoolVO poolVO = Mockito.mock(StoragePoolVO.class);
    final UpgradeSnapshotCommand upgradeSnapshotCommand = new UpgradeSnapshotCommand(poolVO, "http", 1l, 1l, 1l, 1l, 1l, "/", "58c5778b-7dd1-47cc-a7b5-f768541bf278", "Test", "3.1");
    final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(upgradeSnapshotCommand, citrixResourceBase);
    verify(citrixResourceBase, times(0)).getConnection();
    assertTrue(answer.getResult());
}
Also used : RebootAnswer(com.cloud.agent.api.RebootAnswer) CreateAnswer(com.cloud.agent.api.storage.CreateAnswer) Answer(com.cloud.agent.api.Answer) AttachAnswer(com.cloud.storage.command.AttachAnswer) StoragePoolVO(com.cloud.storage.datastore.db.StoragePoolVO) UpgradeSnapshotCommand(com.cloud.agent.api.UpgradeSnapshotCommand) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

StoragePoolVO (com.cloud.storage.datastore.db.StoragePoolVO)86 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)29 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)22 Test (org.junit.Test)18 HostVO (com.cloud.host.HostVO)15 VolumeVO (com.cloud.storage.VolumeVO)15 ArrayList (java.util.ArrayList)15 Answer (com.cloud.agent.api.Answer)14 Account (com.cloud.user.Account)13 DataStore (com.cloud.engine.subsystem.api.storage.DataStore)12 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)11 StoragePool (com.cloud.storage.StoragePool)10 AttachAnswer (com.cloud.storage.command.AttachAnswer)10 VolumeInfo (com.cloud.engine.subsystem.api.storage.VolumeInfo)9 VMInstanceVO (com.cloud.vm.VMInstanceVO)9 RebootAnswer (com.cloud.agent.api.RebootAnswer)8 PrimaryDataStore (com.cloud.engine.subsystem.api.storage.PrimaryDataStore)8 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)8 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)8 VMTemplateStoragePoolVO (com.cloud.storage.VMTemplateStoragePoolVO)8