Search in sources :

Example 46 with ClusterVO

use of com.cloud.dc.ClusterVO in project cloudstack by apache.

the class ResourceManagerImpl method listByDataCenter.

@Override
public List<PodCluster> listByDataCenter(final long dcId) {
    final List<HostPodVO> pods = _podDao.listByDataCenterId(dcId);
    final ArrayList<PodCluster> pcs = new ArrayList<PodCluster>();
    for (final HostPodVO pod : pods) {
        final List<ClusterVO> clusters = _clusterDao.listByPodId(pod.getId());
        if (clusters.size() == 0) {
            pcs.add(new PodCluster(pod, null));
        } else {
            for (final ClusterVO cluster : clusters) {
                pcs.add(new PodCluster(pod, cluster));
            }
        }
    }
    return pcs;
}
Also used : ClusterVO(com.cloud.dc.ClusterVO) ArrayList(java.util.ArrayList) HostPodVO(com.cloud.dc.HostPodVO) PodCluster(com.cloud.dc.PodCluster)

Example 47 with ClusterVO

use of com.cloud.dc.ClusterVO in project cloudstack by apache.

the class ResourceManagerImpl method fillRoutingHostVO.

@Override
public HostVO fillRoutingHostVO(final HostVO host, final StartupRoutingCommand ssCmd, final HypervisorType hyType, Map<String, String> details, final List<String> hostTags) {
    if (host.getPodId() == null) {
        s_logger.error("Host " + ssCmd.getPrivateIpAddress() + " sent incorrect pod, pod id is null");
        throw new IllegalArgumentException("Host " + ssCmd.getPrivateIpAddress() + " sent incorrect pod, pod id is null");
    }
    final ClusterVO clusterVO = _clusterDao.findById(host.getClusterId());
    if (clusterVO.getHypervisorType() != hyType) {
        throw new IllegalArgumentException("Can't add host whose hypervisor type is: " + hyType + " into cluster: " + clusterVO.getId() + " whose hypervisor type is: " + clusterVO.getHypervisorType());
    }
    final Map<String, String> hostDetails = ssCmd.getHostDetails();
    if (hostDetails != null) {
        if (details != null) {
            details.putAll(hostDetails);
        } else {
            details = hostDetails;
        }
    }
    final HostPodVO pod = _podDao.findById(host.getPodId());
    final DataCenterVO dc = _dcDao.findById(host.getDataCenterId());
    checkIPConflicts(pod, dc, ssCmd.getPrivateIpAddress(), ssCmd.getPublicIpAddress(), ssCmd.getPublicIpAddress(), ssCmd.getPublicNetmask());
    host.setType(com.cloud.host.Host.Type.Routing);
    host.setDetails(details);
    host.setCaps(ssCmd.getCapabilities());
    host.setCpuSockets(ssCmd.getCpuSockets());
    host.setCpus(ssCmd.getCpus());
    host.setTotalMemory(ssCmd.getMemory());
    host.setSpeed(ssCmd.getSpeed());
    host.setHypervisorType(hyType);
    host.setHypervisorVersion(ssCmd.getHypervisorVersion());
    host.setGpuGroups(ssCmd.getGpuGroupDetails());
    return host;
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) ClusterVO(com.cloud.dc.ClusterVO) HostPodVO(com.cloud.dc.HostPodVO)

Example 48 with ClusterVO

use of com.cloud.dc.ClusterVO in project cloudstack by apache.

the class SnapshotManagerImpl method supportedByHypervisor.

private boolean supportedByHypervisor(VolumeInfo volume) {
    HypervisorType hypervisorType;
    StoragePoolVO storagePool = _storagePoolDao.findById(volume.getDataStore().getId());
    ScopeType scope = storagePool.getScope();
    if (scope.equals(ScopeType.ZONE)) {
        hypervisorType = storagePool.getHypervisor();
    } else {
        hypervisorType = volume.getHypervisorType();
    }
    if (hypervisorType.equals(HypervisorType.Ovm)) {
        throw new InvalidParameterValueException("Ovm won't support taking snapshot");
    }
    if (hypervisorType.equals(HypervisorType.KVM)) {
        List<HostVO> hosts = null;
        if (scope.equals(ScopeType.CLUSTER)) {
            ClusterVO cluster = _clusterDao.findById(storagePool.getClusterId());
            hosts = _resourceMgr.listAllHostsInCluster(cluster.getId());
        } else if (scope.equals(ScopeType.ZONE)) {
            hosts = _resourceMgr.listAllUpAndEnabledHostsInOneZoneByHypervisor(hypervisorType, volume.getDataCenterId());
        }
        if (hosts != null && !hosts.isEmpty()) {
            HostVO host = hosts.get(0);
            if (!hostSupportSnapsthotForVolume(host, volume)) {
                throw new CloudRuntimeException("KVM Snapshot is not supported for Running VMs. It is disabled by default due to a possible volume corruption in certain cases. To enable it set global settings kvm.snapshot.enabled to True. See the documentation for more details.");
            }
        }
    }
    // if volume is attached to a vm in destroyed or expunging state; disallow
    if (volume.getInstanceId() != null) {
        UserVmVO userVm = _vmDao.findById(volume.getInstanceId());
        if (userVm != null) {
            if (userVm.getState().equals(State.Destroyed) || userVm.getState().equals(State.Expunging)) {
                throw new CloudRuntimeException("Creating snapshot failed due to volume:" + volume.getId() + " is associated with vm:" + userVm.getInstanceName() + " is in " + userVm.getState().toString() + " state");
            }
            if (userVm.getHypervisorType() == HypervisorType.VMware || userVm.getHypervisorType() == HypervisorType.KVM) {
                List<SnapshotVO> activeSnapshots = _snapshotDao.listByInstanceId(volume.getInstanceId(), Snapshot.State.Creating, Snapshot.State.CreatedOnPrimary, Snapshot.State.BackingUp);
                if (activeSnapshots.size() > 0) {
                    throw new InvalidParameterValueException("There is other active snapshot tasks on the instance to which the volume is attached, please try again later");
                }
            }
            List<VMSnapshotVO> activeVMSnapshots = _vmSnapshotDao.listByInstanceId(userVm.getId(), VMSnapshot.State.Creating, VMSnapshot.State.Reverting, VMSnapshot.State.Expunging);
            if (activeVMSnapshots.size() > 0) {
                throw new CloudRuntimeException("There is other active vm snapshot tasks on the instance to which the volume is attached, please try again later");
            }
        }
    }
    return true;
}
Also used : ScopeType(com.cloud.storage.ScopeType) UserVmVO(com.cloud.vm.UserVmVO) ClusterVO(com.cloud.dc.ClusterVO) HostVO(com.cloud.host.HostVO) HypervisorType(com.cloud.hypervisor.Hypervisor.HypervisorType) VMSnapshotVO(com.cloud.vm.snapshot.VMSnapshotVO) VMSnapshotVO(com.cloud.vm.snapshot.VMSnapshotVO) SnapshotVO(com.cloud.storage.SnapshotVO) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO)

Example 49 with ClusterVO

use of com.cloud.dc.ClusterVO in project cloudstack by apache.

the class UnmanagedVMsManagerImplTest method listUnmanagedInstancesInvalidHypervisorTest.

@Test(expected = InvalidParameterValueException.class)
public void listUnmanagedInstancesInvalidHypervisorTest() {
    ListUnmanagedInstancesCmd cmd = Mockito.mock(ListUnmanagedInstancesCmd.class);
    ClusterVO cluster = new ClusterVO(1, 1, "Cluster");
    cluster.setHypervisorType(Hypervisor.HypervisorType.KVM.toString());
    when(clusterDao.findById(Mockito.anyLong())).thenReturn(cluster);
    unmanagedVMsManager.listUnmanagedInstances(cmd);
}
Also used : ClusterVO(com.cloud.dc.ClusterVO) ListUnmanagedInstancesCmd(org.apache.cloudstack.api.command.admin.vm.ListUnmanagedInstancesCmd) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 50 with ClusterVO

use of com.cloud.dc.ClusterVO in project cloudstack by apache.

the class ResourceManagerImpl method doDeleteHost.

@DB
protected boolean doDeleteHost(final long hostId, final boolean isForced, final boolean isForceDeleteStorage) {
    _accountMgr.getActiveUser(CallContext.current().getCallingUserId());
    // Verify that host exists
    final HostVO host = _hostDao.findById(hostId);
    if (host == null) {
        throw new InvalidParameterValueException("Host with id " + hostId + " doesn't exist");
    }
    _accountMgr.checkAccessAndSpecifyAuthority(CallContext.current().getCallingAccount(), host.getDataCenterId());
    if (!canDeleteHost(host) && !isForced) {
        throw new CloudRuntimeException("Host " + host.getUuid() + " cannot be deleted as it is not in maintenance mode. Either put the host into maintenance or perform a forced deletion.");
    }
    // Get storage pool host mappings here because they can be removed as a
    // part of handleDisconnect later
    final List<StoragePoolHostVO> pools = _storagePoolHostDao.listByHostIdIncludingRemoved(hostId);
    final ResourceStateAdapter.DeleteHostAnswer answer = (ResourceStateAdapter.DeleteHostAnswer) dispatchToStateAdapters(ResourceStateAdapter.Event.DELETE_HOST, false, host, isForced, isForceDeleteStorage);
    if (answer == null) {
        throw new CloudRuntimeException("No resource adapter respond to DELETE_HOST event for " + host.getName() + " id = " + hostId + ", hypervisorType is " + host.getHypervisorType() + ", host type is " + host.getType());
    }
    if (answer.getIsException()) {
        return false;
    }
    if (!answer.getIsContinue()) {
        return true;
    }
    Long clusterId = host.getClusterId();
    _agentMgr.notifyMonitorsOfHostAboutToBeRemoved(host.getId());
    Transaction.execute(new TransactionCallbackNoReturn() {

        @Override
        public void doInTransactionWithoutResult(final TransactionStatus status) {
            _dcDao.releasePrivateIpAddress(host.getPrivateIpAddress(), host.getDataCenterId(), null);
            _agentMgr.disconnectWithoutInvestigation(hostId, Status.Event.Remove);
            // delete host details
            _hostDetailsDao.deleteDetails(hostId);
            // if host is GPU enabled, delete GPU entries
            _hostGpuGroupsDao.deleteGpuEntries(hostId);
            // delete host tags
            _hostTagsDao.deleteTags(hostId);
            host.setGuid(null);
            final Long clusterId = host.getClusterId();
            host.setClusterId(null);
            _hostDao.update(host.getId(), host);
            Host hostRemoved = _hostDao.findById(hostId);
            _hostDao.remove(hostId);
            if (clusterId != null) {
                final List<HostVO> hosts = listAllHostsInCluster(clusterId);
                if (hosts.size() == 0) {
                    final ClusterVO cluster = _clusterDao.findById(clusterId);
                    cluster.setGuid(null);
                    _clusterDao.update(clusterId, cluster);
                }
            }
            try {
                resourceStateTransitTo(host, ResourceState.Event.DeleteHost, _nodeId);
            } catch (final NoTransitionException e) {
                s_logger.debug(String.format("Cannot transit %s to Enabled state", host), e);
            }
            // Delete the associated entries in host ref table
            _storagePoolHostDao.deletePrimaryRecordsForHost(hostId);
            // Make sure any VMs that were marked as being on this host are cleaned up
            final List<VMInstanceVO> vms = _vmDao.listByHostId(hostId);
            for (final VMInstanceVO vm : vms) {
                // this is how VirtualMachineManagerImpl does it when it syncs VM states
                vm.setState(State.Stopped);
                vm.setHostId(null);
                _vmDao.persist(vm);
            }
            // where
            for (final StoragePoolHostVO pool : pools) {
                final Long poolId = pool.getPoolId();
                final StoragePoolVO storagePool = _storagePoolDao.findById(poolId);
                if (storagePool.isLocal() && isForceDeleteStorage) {
                    storagePool.setUuid(null);
                    storagePool.setClusterId(null);
                    _storagePoolDao.update(poolId, storagePool);
                    _storagePoolDao.remove(poolId);
                    s_logger.debug(String.format("Local storage [id: %s] is removed as a part of %s removal", poolId, hostRemoved.toString()));
                }
            }
            // delete the op_host_capacity entry
            final Object[] capacityTypes = { Capacity.CAPACITY_TYPE_CPU, Capacity.CAPACITY_TYPE_MEMORY, Capacity.CAPACITY_TYPE_CPU_CORE };
            final SearchCriteria<CapacityVO> hostCapacitySC = _capacityDao.createSearchCriteria();
            hostCapacitySC.addAnd("hostOrPoolId", SearchCriteria.Op.EQ, hostId);
            hostCapacitySC.addAnd("capacityType", SearchCriteria.Op.IN, capacityTypes);
            _capacityDao.remove(hostCapacitySC);
            // remove from dedicated resources
            final DedicatedResourceVO dr = _dedicatedDao.findByHostId(hostId);
            if (dr != null) {
                _dedicatedDao.remove(dr.getId());
            }
            // Remove comments (if any)
            annotationDao.removeByEntityType(AnnotationService.EntityType.HOST.name(), host.getUuid());
        }
    });
    if (clusterId != null) {
        _agentMgr.notifyMonitorsOfRemovedHost(host.getId(), clusterId);
    }
    return true;
}
Also used : ClusterVO(com.cloud.dc.ClusterVO) StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO) TransactionStatus(com.cloud.utils.db.TransactionStatus) VMInstanceVO(com.cloud.vm.VMInstanceVO) TransactionCallbackNoReturn(com.cloud.utils.db.TransactionCallbackNoReturn) Host(com.cloud.host.Host) StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO) HostVO(com.cloud.host.HostVO) SearchCriteria(com.cloud.utils.db.SearchCriteria) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) ArrayList(java.util.ArrayList) List(java.util.List) DedicatedResourceVO(com.cloud.dc.DedicatedResourceVO) DB(com.cloud.utils.db.DB)

Aggregations

ClusterVO (com.cloud.dc.ClusterVO)151 HostVO (com.cloud.host.HostVO)72 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)66 ArrayList (java.util.ArrayList)55 HostPodVO (com.cloud.dc.HostPodVO)46 DataCenterVO (com.cloud.dc.DataCenterVO)38 ConfigurationException (javax.naming.ConfigurationException)37 HashMap (java.util.HashMap)28 HypervisorType (com.cloud.hypervisor.Hypervisor.HypervisorType)24 Map (java.util.Map)24 DiscoveryException (com.cloud.exception.DiscoveryException)21 DB (com.cloud.utils.db.DB)21 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)20 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)20 Account (com.cloud.user.Account)17 List (java.util.List)17 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)17 StoragePoolHostVO (com.cloud.storage.StoragePoolHostVO)16 ClusterDetailsVO (com.cloud.dc.ClusterDetailsVO)15 DedicatedResourceVO (com.cloud.dc.DedicatedResourceVO)14