Search in sources :

Example 31 with HostVO

use of com.cloud.host.HostVO in project cosmic by MissionCriticalCloud.

the class KVMFencerTest method testWithSingleHost.

@Test
public void testWithSingleHost() {
    final HostVO host = Mockito.mock(HostVO.class);
    Mockito.when(host.getClusterId()).thenReturn(1l);
    Mockito.when(host.getHypervisorType()).thenReturn(HypervisorType.KVM);
    Mockito.when(host.getDataCenterId()).thenReturn(1l);
    Mockito.when(host.getPodId()).thenReturn(1l);
    Mockito.when(host.getStatus()).thenReturn(Status.Up);
    Mockito.when(host.getId()).thenReturn(1l);
    final VirtualMachine virtualMachine = Mockito.mock(VirtualMachine.class);
    Mockito.when(resourceManager.listAllHostsInCluster(1l)).thenReturn(Collections.singletonList(host));
    Assert.assertFalse(fencer.fenceOff(virtualMachine, host));
}
Also used : HostVO(com.cloud.host.HostVO) VirtualMachine(com.cloud.vm.VirtualMachine) Test(org.junit.Test)

Example 32 with HostVO

use of com.cloud.host.HostVO in project cosmic by MissionCriticalCloud.

the class KVMFencerTest method testWithSingleNotKVM.

@Test
public void testWithSingleNotKVM() {
    final HostVO host = Mockito.mock(HostVO.class);
    Mockito.when(host.getClusterId()).thenReturn(1l);
    Mockito.when(host.getHypervisorType()).thenReturn(HypervisorType.Any);
    Mockito.when(host.getStatus()).thenReturn(Status.Down);
    Mockito.when(host.getId()).thenReturn(1l);
    Mockito.when(host.getDataCenterId()).thenReturn(1l);
    Mockito.when(host.getPodId()).thenReturn(1l);
    final VirtualMachine virtualMachine = Mockito.mock(VirtualMachine.class);
    Mockito.when(resourceManager.listAllHostsInCluster(1l)).thenReturn(Collections.singletonList(host));
    Assert.assertNull(fencer.fenceOff(virtualMachine, host));
}
Also used : HostVO(com.cloud.host.HostVO) VirtualMachine(com.cloud.vm.VirtualMachine) Test(org.junit.Test)

Example 33 with HostVO

use of com.cloud.host.HostVO in project cloudstack by apache.

the class HostDaoImpl method listHostsWithActiveVMs.

@Override
public List<HostVO> listHostsWithActiveVMs(long offeringId) {
    TransactionLegacy txn = TransactionLegacy.currentTxn();
    PreparedStatement pstmt = null;
    List<HostVO> result = new ArrayList<>();
    StringBuilder sql = new StringBuilder(GET_HOSTS_OF_ACTIVE_VMS);
    try {
        pstmt = txn.prepareAutoCloseStatement(sql.toString());
        pstmt.setLong(1, offeringId);
        ResultSet rs = pstmt.executeQuery();
        while (rs.next()) {
            result.add(toEntityBean(rs, false));
        }
        return result;
    } catch (SQLException e) {
        throw new CloudRuntimeException("DB Exception on: " + sql, e);
    } catch (Throwable e) {
        throw new CloudRuntimeException("Caught: " + sql, e);
    }
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) SQLException(java.sql.SQLException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) HostVO(com.cloud.host.HostVO)

Example 34 with HostVO

use of com.cloud.host.HostVO in project cloudstack by apache.

the class StorageSystemDataMotionStrategy method handleVolumeMigrationForXenServer.

private void handleVolumeMigrationForXenServer(VolumeInfo srcVolumeInfo, VolumeInfo destVolumeInfo) {
    VirtualMachine vm = srcVolumeInfo.getAttachedVM();
    if (vm == null || vm.getState() != VirtualMachine.State.Running) {
        throw new CloudRuntimeException("Currently, a volume to migrate from non-managed storage to managed storage on XenServer must be attached to " + "a VM in the Running state.");
    }
    destVolumeInfo.getDataStore().getDriver().createAsync(destVolumeInfo.getDataStore(), destVolumeInfo, null);
    destVolumeInfo = _volumeDataFactory.getVolume(destVolumeInfo.getId(), destVolumeInfo.getDataStore());
    handleQualityOfServiceForVolumeMigration(destVolumeInfo, PrimaryDataStoreDriver.QualityOfServiceState.MIGRATION);
    HostVO hostVO = _hostDao.findById(vm.getHostId());
    _volumeService.grantAccess(destVolumeInfo, hostVO, destVolumeInfo.getDataStore());
    String value = _configDao.getValue(Config.MigrateWait.key());
    int waitInterval = NumbersUtil.parseInt(value, Integer.parseInt(Config.MigrateWait.getDefaultValue()));
    StoragePool destPool = (StoragePool) dataStoreMgr.getDataStore(destVolumeInfo.getDataStore().getId(), DataStoreRole.Primary);
    MigrateVolumeCommand command = new MigrateVolumeCommand(srcVolumeInfo.getId(), srcVolumeInfo.getPath(), destPool, srcVolumeInfo.getAttachedVmName(), srcVolumeInfo.getVolumeType(), waitInterval, null);
    Map<String, String> details = new HashMap<>();
    details.put(DiskTO.MANAGED, Boolean.TRUE.toString());
    details.put(DiskTO.IQN, destVolumeInfo.get_iScsiName());
    details.put(DiskTO.STORAGE_HOST, destPool.getHostAddress());
    details.put(DiskTO.PROTOCOL_TYPE, (destPool.getPoolType() != null) ? destPool.getPoolType().toString() : null);
    command.setDestDetails(details);
    EndPoint ep = selector.select(srcVolumeInfo, StorageAction.MIGRATEVOLUME);
    Answer answer;
    if (ep == null) {
        String errMsg = "No remote endpoint to send command to; check if host or SSVM is down";
        LOGGER.error(errMsg);
        answer = new Answer(command, false, errMsg);
    } else {
        answer = ep.sendMessage(command);
    }
    handleQualityOfServiceForVolumeMigration(destVolumeInfo, PrimaryDataStoreDriver.QualityOfServiceState.NO_MIGRATION);
    if (answer == null || !answer.getResult()) {
        handleFailedVolumeMigration(srcVolumeInfo, destVolumeInfo, hostVO);
        throw new CloudRuntimeException("Failed to migrate volume with ID " + srcVolumeInfo.getId() + " to storage pool with ID " + destPool.getId());
    } else {
        handleSuccessfulVolumeMigration(srcVolumeInfo, destPool, (MigrateVolumeAnswer) answer);
    }
}
Also used : MigrateVolumeCommand(com.cloud.agent.api.storage.MigrateVolumeCommand) ModifyTargetsAnswer(com.cloud.agent.api.ModifyTargetsAnswer) ResignatureAnswer(org.apache.cloudstack.storage.command.ResignatureAnswer) MigrateVolumeAnswer(com.cloud.agent.api.storage.MigrateVolumeAnswer) MigrateAnswer(com.cloud.agent.api.MigrateAnswer) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer) Answer(com.cloud.agent.api.Answer) CopyVolumeAnswer(com.cloud.agent.api.storage.CopyVolumeAnswer) StoragePool(com.cloud.storage.StoragePool) HashMap(java.util.HashMap) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) EndPoint(org.apache.cloudstack.engine.subsystem.api.storage.EndPoint) HostVO(com.cloud.host.HostVO) EndPoint(org.apache.cloudstack.engine.subsystem.api.storage.EndPoint) VirtualMachine(com.cloud.vm.VirtualMachine)

Example 35 with HostVO

use of com.cloud.host.HostVO in project cloudstack by apache.

the class EndpointSelectorTest method createHost.

public HostVO createHost(Hypervisor.HypervisorType hypervisorType) {
    String uuid = UUID.randomUUID().toString();
    HostVO host = new HostVO(uuid);
    host.setName("devcloud xenserver host");
    host.setType(Host.Type.Routing);
    host.setPrivateIpAddress(uuid);
    host.setDataCenterId(dcId);
    host.setVersion("6.0.1");
    host.setAvailable(true);
    host.setSetup(true);
    host.setPodId(podId);
    host.setLastPinged(0);
    host.setResourceState(ResourceState.Enabled);
    host.setHypervisorType(hypervisorType);
    host.setClusterId(clusterId);
    host = hostDao.persist(host);
    agentMgr.agentStatusTransitTo(host, Status.Event.AgentConnected, 1L);
    host = hostDao.findById(host.getId());
    agentMgr.agentStatusTransitTo(host, Status.Event.Ready, 1L);
    return hostDao.findById(host.getId());
}
Also used : HostVO(com.cloud.host.HostVO) StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO)

Aggregations

HostVO (com.cloud.host.HostVO)631 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)223 ArrayList (java.util.ArrayList)178 Answer (com.cloud.agent.api.Answer)105 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)95 StoragePoolHostVO (com.cloud.storage.StoragePoolHostVO)91 Test (org.junit.Test)81 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)75 OperationTimedoutException (com.cloud.exception.OperationTimedoutException)74 ClusterVO (com.cloud.dc.ClusterVO)72 Account (com.cloud.user.Account)67 HashMap (java.util.HashMap)67 VMInstanceVO (com.cloud.vm.VMInstanceVO)60 ConfigurationException (javax.naming.ConfigurationException)60 NoTransitionException (com.cloud.utils.fsm.NoTransitionException)58 DataCenterVO (com.cloud.dc.DataCenterVO)50 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)48 HostPodVO (com.cloud.dc.HostPodVO)47 DB (com.cloud.utils.db.DB)47 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)46