Search in sources :

Example 41 with HostPodVO

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

the class ConfigurationManagerTest method checkIfPodIsDeletableFailureOnVolumeTest.

@Test(expected = CloudRuntimeException.class)
public void checkIfPodIsDeletableFailureOnVolumeTest() {
    HostPodVO hostPodVO = Mockito.mock(HostPodVO.class);
    Mockito.when(hostPodVO.getDataCenterId()).thenReturn(new Random().nextLong());
    Mockito.when(_podDao.findById(anyLong())).thenReturn(hostPodVO);
    VolumeVO volumeVO = Mockito.mock(VolumeVO.class);
    ArrayList<VolumeVO> arrayList = new ArrayList<VolumeVO>();
    arrayList.add(volumeVO);
    Mockito.when(_privateIpAddressDao.countIPs(anyLong(), anyLong(), anyBoolean())).thenReturn(0);
    Mockito.when(_volumeDao.findByPod(anyLong())).thenReturn(arrayList);
    Mockito.when(_hostDao.findByPodId(anyLong())).thenReturn(new ArrayList<HostVO>());
    Mockito.when(_vmInstanceDao.listByPodId(anyLong())).thenReturn(new ArrayList<VMInstanceVO>());
    Mockito.when(_clusterDao.listByPodId(anyLong())).thenReturn(new ArrayList<ClusterVO>());
    configurationMgr.checkIfPodIsDeletable(new Random().nextLong());
}
Also used : ClusterVO(com.cloud.dc.ClusterVO) Random(java.util.Random) VolumeVO(com.cloud.storage.VolumeVO) ArrayList(java.util.ArrayList) VMInstanceVO(com.cloud.vm.VMInstanceVO) HostPodVO(com.cloud.dc.HostPodVO) HostVO(com.cloud.host.HostVO) Test(org.junit.Test)

Example 42 with HostPodVO

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

the class ConfigurationManagerTest method checkIfZoneIsDeletableFailureOnPhysicalNetworkTest.

@Test(expected = CloudRuntimeException.class)
public void checkIfZoneIsDeletableFailureOnPhysicalNetworkTest() {
    PhysicalNetworkVO physicalNetworkVO = Mockito.mock(PhysicalNetworkVO.class);
    ArrayList<PhysicalNetworkVO> arrayList = new ArrayList<PhysicalNetworkVO>();
    arrayList.add(physicalNetworkVO);
    Mockito.when(_hostDao.listByDataCenterId(anyLong())).thenReturn(new ArrayList<HostVO>());
    Mockito.when(_podDao.listByDataCenterId(anyLong())).thenReturn(new ArrayList<HostPodVO>());
    Mockito.when(_privateIpAddressDao.countIPs(anyLong(), anyBoolean())).thenReturn(0);
    Mockito.when(_publicIpAddressDao.countIPs(anyLong(), anyBoolean())).thenReturn(0);
    Mockito.when(_vmInstanceDao.listByZoneId(anyLong())).thenReturn(new ArrayList<VMInstanceVO>());
    Mockito.when(_volumeDao.findByDc(anyLong())).thenReturn(new ArrayList<VolumeVO>());
    Mockito.when(_physicalNetworkDao.listByZone(anyLong())).thenReturn(arrayList);
    configurationMgr.checkIfZoneIsDeletable(new Random().nextLong());
}
Also used : VolumeVO(com.cloud.storage.VolumeVO) Random(java.util.Random) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) ArrayList(java.util.ArrayList) VMInstanceVO(com.cloud.vm.VMInstanceVO) HostPodVO(com.cloud.dc.HostPodVO) HostVO(com.cloud.host.HostVO) Test(org.junit.Test)

Example 43 with HostPodVO

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

the class ConfigurationManagerTest method checkIfPodIsDeletableFailureOnPrivateIpAddressTest.

@Test(expected = CloudRuntimeException.class)
public void checkIfPodIsDeletableFailureOnPrivateIpAddressTest() {
    HostPodVO hostPodVO = Mockito.mock(HostPodVO.class);
    Mockito.when(hostPodVO.getDataCenterId()).thenReturn(new Random().nextLong());
    Mockito.when(_podDao.findById(anyLong())).thenReturn(hostPodVO);
    Mockito.when(_privateIpAddressDao.countIPs(anyLong(), anyLong(), anyBoolean())).thenReturn(1);
    Mockito.when(_volumeDao.findByPod(anyLong())).thenReturn(new ArrayList<VolumeVO>());
    Mockito.when(_hostDao.findByPodId(anyLong())).thenReturn(new ArrayList<HostVO>());
    Mockito.when(_vmInstanceDao.listByPodId(anyLong())).thenReturn(new ArrayList<VMInstanceVO>());
    Mockito.when(_clusterDao.listByPodId(anyLong())).thenReturn(new ArrayList<ClusterVO>());
    configurationMgr.checkIfPodIsDeletable(new Random().nextLong());
}
Also used : ClusterVO(com.cloud.dc.ClusterVO) Random(java.util.Random) VolumeVO(com.cloud.storage.VolumeVO) VMInstanceVO(com.cloud.vm.VMInstanceVO) HostPodVO(com.cloud.dc.HostPodVO) HostVO(com.cloud.host.HostVO) Test(org.junit.Test)

Example 44 with HostPodVO

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

the class ConfigurationManagerImpl method createPod.

@Override
@DB
public HostPodVO createPod(final long userId, final String podName, final long zoneId, final String gateway, final String cidr, final String startIp, String endIp, final String allocationStateStr, final boolean skipGatewayOverlapCheck) {
    // Check if the zone is valid
    if (!validZone(zoneId)) {
        throw new InvalidParameterValueException("Please specify a valid zone.");
    }
    // Check if zone is disabled
    final DataCenterVO zone = _zoneDao.findById(zoneId);
    final Account account = CallContext.current().getCallingAccount();
    if (Grouping.AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(account.getId())) {
        throw new PermissionDeniedException("Cannot perform this operation, Zone is currently disabled: " + zoneId);
    }
    final String cidrAddress = getCidrAddress(cidr);
    final int cidrSize = getCidrSize(cidr);
    // end ip of the pod's cidr
    if (startIp != null) {
        if (endIp == null) {
            endIp = NetUtils.getIpRangeEndIpFromCidr(cidrAddress, cidrSize);
        }
    }
    // Validate new pod settings
    checkPodAttributes(-1, podName, zoneId, gateway, cidr, startIp, endIp, allocationStateStr, true, skipGatewayOverlapCheck);
    // Create the new pod in the database
    String ipRange;
    if (startIp != null) {
        ipRange = startIp + "-" + endIp;
    } else {
        throw new InvalidParameterValueException("Start ip is required parameter");
    }
    final HostPodVO podFinal = new HostPodVO(podName, zoneId, gateway, cidrAddress, cidrSize, ipRange);
    Grouping.AllocationState allocationState = null;
    if (allocationStateStr != null && !allocationStateStr.isEmpty()) {
        allocationState = Grouping.AllocationState.valueOf(allocationStateStr);
        podFinal.setAllocationState(allocationState);
    }
    final String endIpFinal = endIp;
    return Transaction.execute(new TransactionCallback<HostPodVO>() {

        @Override
        public HostPodVO doInTransaction(final TransactionStatus status) {
            final HostPodVO pod = _podDao.persist(podFinal);
            if (startIp != null) {
                _zoneDao.addPrivateIpAddress(zoneId, pod.getId(), startIp, endIpFinal);
            }
            final String[] linkLocalIpRanges = getLinkLocalIPRange();
            if (linkLocalIpRanges != null) {
                _zoneDao.addLinkLocalIpAddress(zoneId, pod.getId(), linkLocalIpRanges[0], linkLocalIpRanges[1]);
            }
            return pod;
        }
    });
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) Account(com.cloud.user.Account) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) AllocationState(com.cloud.org.Grouping.AllocationState) TransactionStatus(com.cloud.utils.db.TransactionStatus) PermissionDeniedException(com.cloud.exception.PermissionDeniedException) Grouping(com.cloud.org.Grouping) HostPodVO(com.cloud.dc.HostPodVO) DB(com.cloud.utils.db.DB)

Example 45 with HostPodVO

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

the class ConfigurationManagerImpl method checkIfPodIsDeletable.

protected void checkIfPodIsDeletable(final long podId) {
    final HostPodVO pod = _podDao.findById(podId);
    final String errorMsg = "The pod cannot be deleted because ";
    // Check if there are allocated private IP addresses in the pod
    if (_privateIpAddressDao.countIPs(podId, pod.getDataCenterId(), true) != 0) {
        throw new CloudRuntimeException(errorMsg + "there are private IP addresses allocated in this pod.");
    }
    // Check if there are any non-removed volumes in the pod.
    if (!_volumeDao.findByPod(podId).isEmpty()) {
        throw new CloudRuntimeException(errorMsg + "there are storage volumes in this pod.");
    }
    // Check if there are any non-removed hosts in the pod.
    if (!_hostDao.findByPodId(podId).isEmpty()) {
        throw new CloudRuntimeException(errorMsg + "there are servers in this pod.");
    }
    // Check if there are any non-removed vms in the pod.
    if (!_vmInstanceDao.listByPodId(podId).isEmpty()) {
        throw new CloudRuntimeException(errorMsg + "there are virtual machines in this pod.");
    }
    // Check if there are any non-removed clusters in the pod.
    if (!_clusterDao.listByPodId(podId).isEmpty()) {
        throw new CloudRuntimeException(errorMsg + "there are clusters in this pod.");
    }
}
Also used : CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) HostPodVO(com.cloud.dc.HostPodVO)

Aggregations

HostPodVO (com.cloud.dc.HostPodVO)68 DataCenterVO (com.cloud.dc.DataCenterVO)32 HostVO (com.cloud.host.HostVO)32 ClusterVO (com.cloud.dc.ClusterVO)31 ArrayList (java.util.ArrayList)29 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)23 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)16 VolumeVO (com.cloud.storage.VolumeVO)14 VMInstanceVO (com.cloud.vm.VMInstanceVO)14 Account (com.cloud.user.Account)13 DB (com.cloud.utils.db.DB)12 Test (org.junit.Test)12 Random (java.util.Random)11 TransactionStatus (com.cloud.utils.db.TransactionStatus)10 ConfigurationException (javax.naming.ConfigurationException)10 HashMap (java.util.HashMap)8 List (java.util.List)8 DataCenter (com.cloud.dc.DataCenter)7 DedicatedResourceVO (com.cloud.dc.DedicatedResourceVO)7 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)6