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());
}
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());
}
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());
}
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;
}
});
}
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.");
}
}
Aggregations