Bug 9331 - Even when there is no longer clusters in the pod, 'Delete Pod - Failed - because there are clusters in this pod'

Changes:
- Cluster entry is not removed from the table when a cluster is deleted because there are some foreign key constraints failing if the row delete is attempted. Instead the cluster is marked as 'removed'
- While deleting the pod changed the check to see if pod has any clusters - we now check that there are no clusters with removed column null.

- Also pod entry cannot be deleted from the db due to  foreign key constraints. So added 'removed' column to Pod table host_pod_ref
- Now on deleting a pod, the pod will be marked as removed and pod name is set to null.
This commit is contained in:
prachi 2011-04-15 16:03:03 -07:00
parent 227b03fd93
commit 734e3f17c2
6 changed files with 53 additions and 13 deletions

View File

@ -503,7 +503,10 @@ public class ApiResponseHelper implements ResponseGenerator {
hostResponse.setZoneName(ApiDBUtils.findZoneById(host.getDataCenterId()).getName());
if (host.getPodId() != null) {
hostResponse.setPodName(ApiDBUtils.findPodById(host.getPodId()).getName());
HostPodVO pod = ApiDBUtils.findPodById(host.getPodId());
if(pod != null){
hostResponse.setPodName(pod.getName());
}
}
DecimalFormat decimalFormat = new DecimalFormat("#.##");
@ -587,7 +590,9 @@ public class ApiResponseHelper implements ResponseGenerator {
if (podId != null) {
HostPodVO pod = ApiDBUtils.findPodById(podId);
vlanResponse.setPodId(podId);
vlanResponse.setPodName(pod.getName());
if(pod != null){
vlanResponse.setPodName(pod.getName());
}
}
vlanResponse.setGateway(vlan.getVlanGateway());
@ -886,7 +891,10 @@ public class ApiResponseHelper implements ResponseGenerator {
}
if (pool.getPodId() != null) {
poolResponse.setPodId(pool.getPodId());
poolResponse.setPodName(ApiDBUtils.findPodById(pool.getPodId()).getName());
HostPodVO pod = ApiDBUtils.findPodById(pool.getPodId());
if(pod != null){
poolResponse.setPodName(pod.getName());
}
}
if (pool.getCreated() != null) {
poolResponse.setCreated(pool.getCreated());
@ -926,7 +934,9 @@ public class ApiResponseHelper implements ResponseGenerator {
clusterResponse.setClusterType(cluster.getClusterType().toString());
clusterResponse.setAllocationState(cluster.getAllocationState().toString());
HostPodVO pod = ApiDBUtils.findPodById(cluster.getPodId());
clusterResponse.setPodName(pod.getName());
if(pod != null){
clusterResponse.setPodName(pod.getName());
}
DataCenterVO zone = ApiDBUtils.findZoneById(cluster.getDataCenterId());
clusterResponse.setZoneName(zone.getName());
clusterResponse.setObjectName("cluster");
@ -2189,7 +2199,10 @@ public class ApiResponseHelper implements ResponseGenerator {
if (summedCapacity.getPodId() != null) {
capacityResponse.setPodId(summedCapacity.getPodId());
if (summedCapacity.getPodId() > 0) {
capacityResponse.setPodName(ApiDBUtils.findPodById(summedCapacity.getPodId()).getName());
HostPodVO pod = ApiDBUtils.findPodById(summedCapacity.getPodId());
if(pod != null){
capacityResponse.setPodName(pod.getName());
}
} else {
capacityResponse.setPodName("All");
}

View File

@ -490,7 +490,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
String selectSql = "SELECT * FROM `" + dbName + "`.`" + tableName + "` WHERE " + column + " = ?";
if (tableName.equals("host")) {
if (tableName.equals("host") || tableName.equals("cluster")) {
selectSql += " and removed IS NULL";
}
@ -621,7 +621,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
}
// Delete the pod
if (!(_podDao.expunge(podId))) {
if (!(_podDao.remove(podId))) {
throw new CloudRuntimeException("Failed to delete pod " + podId);
}

View File

@ -18,6 +18,8 @@
package com.cloud.dc;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
@ -28,8 +30,8 @@ import javax.persistence.Id;
import javax.persistence.Table;
import com.cloud.org.Grouping;
import com.cloud.org.Grouping.AllocationState;
import com.cloud.utils.NumbersUtil;
import com.cloud.utils.db.GenericDao;
@Entity
@Table(name = "host_pod_ref")
@ -61,7 +63,11 @@ public class HostPodVO implements Pod {
AllocationState allocationState;
@Column(name = "external_dhcp")
private Boolean externalDhcp;
private Boolean externalDhcp;
@Column(name=GenericDao.REMOVED_COLUMN)
private Date removed;
public HostPodVO(String name, long dcId, String gateway, String cidrAddress, int cidrSize, String description) {
this.name = name;
@ -169,5 +175,9 @@ public class HostPodVO implements Pod {
} else {
return false;
}
}
}
public Date getRemoved() {
return removed;
}
}

View File

@ -77,7 +77,7 @@ public class HostPodDaoImpl extends GenericDaoBase<HostPodVO, Long> implements H
public HashMap<Long, List<Object>> getCurrentPodCidrSubnets(long zoneId, long podIdToSkip) {
HashMap<Long, List<Object>> currentPodCidrSubnets = new HashMap<Long, List<Object>>();
String selectSql = "SELECT id, cidr_address, cidr_size FROM host_pod_ref WHERE data_center_id=" + zoneId;
String selectSql = "SELECT id, cidr_address, cidr_size FROM host_pod_ref WHERE data_center_id=" + zoneId +" and removed IS NULL";
Transaction txn = Transaction.currentTxn();
try {
PreparedStatement stmt = txn.prepareAutoCloseStatement(selectSql);
@ -197,5 +197,19 @@ public class HostPodDaoImpl extends GenericDaoBase<HostPodVO, Long> implements H
}
return true;
}
}
@Override
public boolean remove(Long id) {
Transaction txn = Transaction.currentTxn();
txn.start();
HostPodVO pod = createForUpdate();
pod.setName(null);
update(id, pod);
boolean result = super.remove(id);
txn.commit();
return result;
}
}

View File

@ -523,7 +523,7 @@ CREATE TABLE `cloud`.`op_dc_link_local_ip_address_alloc` (
CREATE TABLE `cloud`.`host_pod_ref` (
`id` bigint unsigned NOT NULL UNIQUE auto_increment,
`name` varchar(255) NOT NULL,
`name` varchar(255),
`data_center_id` bigint unsigned NOT NULL,
`gateway` varchar(255) NOT NULL COMMENT 'gateway for the pod',
`cidr_address` varchar(15) NOT NULL COMMENT 'CIDR address for the pod',
@ -531,6 +531,7 @@ CREATE TABLE `cloud`.`host_pod_ref` (
`description` varchar(255) COMMENT 'store private ip range in startIP-endIP format',
`allocation_state` varchar(32) NOT NULL DEFAULT 'Enabled' COMMENT 'Is this Pod enabled for allocation for new resources',
`external_dhcp` tinyint NOT NULL DEFAULT 0 COMMENT 'Is this Pod using external DHCP',
`removed` datetime COMMENT 'date removed if not null',
PRIMARY KEY (`id`),
UNIQUE KEY (`name`, `data_center_id`),
INDEX `i_host_pod_ref__data_center_id`(`data_center_id`),

View File

@ -22,3 +22,5 @@ ALTER TABLE `cloud`.`secondary_storage_vm` ADD COLUMN `role` varchar(64) NOT NUL
INSERT INTO `cloud`.`configuration` (category, instance, component, name, value, description) VALUES ('Network', 'DEFAULT', 'management-server', 'vm.network.throttling.rate', 200, 'Default data transfer rate in megabits per second allowed in user vm\'s default network.');
ALTER TABLE `cloud`.`host_pod_ref` ADD COLUMN `removed` datetime COMMENT 'date removed if not null';
ALTER TABLE `cloud`.`host_pod_ref` MODIFY `name` varchar(255);