diff --git a/server/src/com/cloud/async/executor/CancelPrimaryStorageMaintenanceExecutor.java b/server/src/com/cloud/async/executor/CancelPrimaryStorageMaintenanceExecutor.java
deleted file mode 100644
index d609577ce17..00000000000
--- a/server/src/com/cloud/async/executor/CancelPrimaryStorageMaintenanceExecutor.java
+++ /dev/null
@@ -1,117 +0,0 @@
-/**
- * Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
- *
- * This software is licensed under the GNU General Public License v3 or later.
- *
- * It is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or any later version.
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- *
- */
-
-package com.cloud.async.executor;
-
-import org.apache.log4j.Logger;
-
-import com.cloud.api.BaseCmd;
-import com.cloud.async.AsyncJobManager;
-import com.cloud.async.AsyncJobResult;
-import com.cloud.async.AsyncJobVO;
-import com.cloud.async.BaseAsyncJobExecutor;
-import com.cloud.dc.ClusterVO;
-import com.cloud.serializer.GsonHelper;
-import com.cloud.server.ManagementServer;
-import com.cloud.storage.StoragePoolVO;
-import com.cloud.storage.StorageStats;
-import com.google.gson.Gson;
-
-public class CancelPrimaryStorageMaintenanceExecutor extends BaseAsyncJobExecutor {
- public static final Logger s_logger = Logger.getLogger(CancelPrimaryStorageMaintenanceExecutor.class.getName());
-
- public boolean execute() {
- Gson gson = GsonHelper.getBuilder().create();
- AsyncJobManager asyncMgr = getAsyncJobMgr();
- AsyncJobVO job = getJob();
- ManagementServer managementServer = asyncMgr.getExecutorContext().getManagementServer();
- Long param = gson.fromJson(job.getCmdInfo(), Long.class);
- Long userId = job.getUserId();
- /*
- try {
- boolean result = managementServer.cancelPrimaryStorageMaintenance(param.longValue(), userId.longValue());
- if(result)
- {
- StoragePoolVO primaryStorage = managementServer.findPoolById(param);
-
- asyncMgr.completeAsyncJob(getJob().getId(), AsyncJobResult.STATUS_SUCCEEDED, 0,
- composeResultObject(primaryStorage,managementServer));
- }
- else
- {
- StoragePoolVO primaryStorage = managementServer.findPoolById(param);
-
- asyncMgr.completeAsyncJob(getJob().getId(), AsyncJobResult.STATUS_FAILED, BaseCmd.INTERNAL_ERROR,
- composeResultObject(primaryStorage,managementServer));
- }
- } catch(Exception e) {
- s_logger.warn("Unable to prepare maintenance: " + e.getMessage(), e);
- asyncMgr.completeAsyncJob(getJob().getId(), AsyncJobResult.STATUS_FAILED, BaseCmd.INTERNAL_ERROR,
- e.getMessage());
- }
- */
- return true;
- }
-
- private PrimaryStorageResultObject composeResultObject(StoragePoolVO storagePoolVO, ManagementServer managementServer)
- {
-
- PrimaryStorageResultObject primaryStorageRO = new PrimaryStorageResultObject();
-
- primaryStorageRO.setId(storagePoolVO.getId());
-
- primaryStorageRO.setName(storagePoolVO.getName());
- primaryStorageRO.setType(storagePoolVO.getPoolType().toString());
- primaryStorageRO.setState(storagePoolVO.getStatus().toString());
- primaryStorageRO.setIpAddress(storagePoolVO.getHostAddress());
- primaryStorageRO.setZoneId(storagePoolVO.getDataCenterId());
-// primaryStorageRO.setZoneName(managementServer.getDataCenterBy(storagePoolVO.getDataCenterId()).getName());
-
- if (storagePoolVO.getPodId() != null && managementServer.findHostPodById(storagePoolVO.getPodId()) != null) {
- primaryStorageRO.setPodId(storagePoolVO.getPodId());
- primaryStorageRO.setPodName((managementServer.findHostPodById(storagePoolVO.getPodId())).getName());
- }
-
- if (storagePoolVO.getCreated() != null) {
- primaryStorageRO.setCreated(storagePoolVO.getCreated());
- }
- primaryStorageRO.setDiskSizeTotal(storagePoolVO.getCapacityBytes());
-
-// StorageStats stats = managementServer.getStoragePoolStatistics(storagePoolVO.getId());
- long capacity = storagePoolVO.getCapacityBytes();
- long available = storagePoolVO.getAvailableBytes() ;
- long used = capacity - available;
-
-// if (stats != null) {
-// used = stats.getByteUsed();
-// available = capacity - used;
-// }
-
- primaryStorageRO.setDiskSizeAllocated(used);
- if (storagePoolVO.getClusterId() != null)
- {
-// ClusterVO cluster = managementServer.findClusterById(storagePoolVO.getClusterId());
- primaryStorageRO.setClusterId(storagePoolVO.getClusterId());
-// primaryStorageRO.setClusterName(cluster.getName());
- }
-
-// primaryStorageRO.setTags(managementServer.getStoragePoolTags(storagePoolVO.getId()));
- return primaryStorageRO;
-
- }
-}
diff --git a/server/src/com/cloud/async/executor/CompleteMaintenanceExecutor.java b/server/src/com/cloud/async/executor/CompleteMaintenanceExecutor.java
deleted file mode 100644
index 5be90e2b5ab..00000000000
--- a/server/src/com/cloud/async/executor/CompleteMaintenanceExecutor.java
+++ /dev/null
@@ -1,188 +0,0 @@
-/**
- * Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
- *
- * This software is licensed under the GNU General Public License v3 or later.
- *
- * It is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or any later version.
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- *
- */
-
-package com.cloud.async.executor;
-
-import java.text.DecimalFormat;
-import java.util.List;
-import java.util.Set;
-
-import org.apache.log4j.Logger;
-
-import com.cloud.api.BaseCmd;
-import com.cloud.async.AsyncJobManager;
-import com.cloud.async.AsyncJobResult;
-import com.cloud.async.AsyncJobVO;
-import com.cloud.async.BaseAsyncJobExecutor;
-import com.cloud.host.Host;
-import com.cloud.host.HostStats;
-import com.cloud.host.HostVO;
-import com.cloud.host.Status.Event;
-import com.cloud.offering.ServiceOffering;
-import com.cloud.serializer.GsonHelper;
-import com.cloud.server.ManagementServer;
-import com.cloud.storage.GuestOSCategoryVO;
-import com.cloud.vm.UserVmVO;
-import com.google.gson.Gson;
-
-public class CompleteMaintenanceExecutor extends BaseAsyncJobExecutor {
- public static final Logger s_logger = Logger.getLogger(CompleteMaintenanceExecutor.class.getName());
-
- @Override
- public boolean execute() {
- Gson gson = GsonHelper.getBuilder().create();
- AsyncJobManager asyncMgr = getAsyncJobMgr();
- AsyncJobVO job = getJob();
- ManagementServer managementServer = asyncMgr.getExecutorContext().getManagementServer();
- Long param = gson.fromJson(job.getCmdInfo(), Long.class);
-
- /*
- try
- {
- boolean result = managementServer.maintenanceCompleted(param.longValue());
- if(result)
- {
- HostVO host = managementServer.getHostBy(param);
- asyncMgr.completeAsyncJob(getJob().getId(), AsyncJobResult.STATUS_SUCCEEDED, 0,
- composeResultObject(host,managementServer));
- }
- else
- {
- HostVO host = managementServer.getHostBy(param);
- asyncMgr.completeAsyncJob(getJob().getId(), AsyncJobResult.STATUS_FAILED, BaseCmd.INTERNAL_ERROR,
- composeResultObject(host, managementServer));
- }
- } catch(Exception e) {
- s_logger.warn("Unexpected exception: ", e);
-
- asyncMgr.completeAsyncJob(getJob().getId(), AsyncJobResult.STATUS_FAILED, BaseCmd.INTERNAL_ERROR,
- e.getMessage());
- }
- */
- return true;
- }
-
- private HostResultObject composeResultObject(HostVO hostVO, ManagementServer managementServer)
- {
-
- HostResultObject hostRO = new HostResultObject();
-
- hostRO.setId(hostVO.getId());
-
- hostRO.setName(hostVO.getName());
- hostRO.setState(hostVO.getStatus().toString());
-
- if(hostVO.getDisconnectedOn() != null)
- hostRO.setDisconnected(hostVO.getDisconnectedOn());
-
-
- if (hostVO.getType() != null) {
- hostRO.setType(hostVO.getType().toString());
- }
-
-// GuestOSCategoryVO guestOSCategory = managementServer.getHostGuestOSCategory(hostVO.getId());
-// if (guestOSCategory != null) {
-// hostRO.setOsCategoryId(guestOSCategory.getId());
-// hostRO.setOsCategoryName(guestOSCategory.getName());
-// }
-
-
- hostRO.setIpAddress(hostVO.getPrivateIpAddress());
- hostRO.setZoneId(hostVO.getDataCenterId());
-// hostRO.setZoneName(managementServer.getDataCenterBy(hostVO.getDataCenterId()).getName());
-
- if (hostVO.getPodId() != null && managementServer.findHostPodById(hostVO.getPodId()) != null) {
- hostRO.setPodId(hostVO.getPodId());
- hostRO.setPodName((managementServer.findHostPodById(hostVO.getPodId())).getName());
- }
-
- hostRO.setVersion(hostVO.getVersion().toString());
-
- if (hostVO.getHypervisorType() != null) {
- hostRO.setHypervisorType(hostVO.getHypervisorType().toString());
- }
-
- if ((hostVO.getCpus() != null) && (hostVO.getSpeed() != null) && !(hostVO.getType().toString().equals("Storage")))
- {
-
- hostRO.setCpuNumber(hostVO.getCpus());
- hostRO.setCpuSpeed(hostVO.getSpeed());
- // calculate cpu allocated by vm
- int cpu = 0;
- String cpuAlloc = null;
- DecimalFormat decimalFormat = new DecimalFormat("#.##");
-// List instances = managementServer.listUserVMsByHostId(hostVO.getId());
-// for (UserVmVO vm : instances) {
-// ServiceOffering so = managementServer.findServiceOfferingById(vm.getServiceOfferingId());
-// cpu += so.getCpu() * so.getSpeed();
-// }
- cpuAlloc = decimalFormat.format(((float) cpu / (float) (hostVO.getCpus() * hostVO.getSpeed())) * 100f) + "%";
- hostRO.setCpuAllocated(cpuAlloc);
-
- // calculate cpu utilized
- String cpuUsed = null;
-// HostStats hostStats = managementServer.getHostStatistics(hostVO.getId());
-// if (hostStats != null) {
-// float cpuUtil = (float) hostStats.getCpuUtilization();
-// cpuUsed = decimalFormat.format(cpuUtil) + "%";
-// hostRO.setCpuUsed(cpuUsed);
-//
-// long avgLoad = (long)hostStats.getAverageLoad();
-// hostRO.setAverageLoad(avgLoad);
-//
-// long networkKbsRead = (long)hostStats.getNetworkReadKBs();
-// hostRO.setNetworkKbsRead(networkKbsRead);
-//
-// long networkKbsWrite = (long)hostStats.getNetworkWriteKBs();
-// hostRO.setNetworkKbsWrite(networkKbsWrite);
-// }
- }
-
- if ( hostVO.getType() == Host.Type.Routing ) {
- Long memory = hostVO.getTotalMemory();
- hostRO.setTotalMemory(memory);
- // calculate memory allocated by systemVM and userVm
- long mem = managementServer.getMemoryUsagebyHost(hostVO.getId());
- hostRO.setMemoryAllocated(mem);
- // calculate memory utilized, we don't provide memory over commit
- hostRO.setMemoryUsed(mem);
- }
- if (hostVO.getType().toString().equals("Storage")) {
- hostRO.setDiskSizeTotal(hostVO.getTotalSize());
- hostRO.setDiskSizeAllocated(0);
- }
- hostRO.setCaps(hostVO.getCapabilities());
- hostRO.setLastPinged(hostVO.getLastPinged());
- if (hostVO.getManagementServerId() != null) {
- hostRO.setManagementServerId(hostVO.getManagementServerId());
- }
-
- if (hostVO.getCreated() != null) {
- hostRO.setCreated(hostVO.getCreated());
- }
- if (hostVO.getRemoved() != null) {
- hostRO.setRemoved(hostVO.getRemoved());
- }
-
- Set possibleEvents = hostVO.getStatus().getPossibleEvents();
- hostRO.setEvents(possibleEvents);
-
- return hostRO;
-
- }
-}
diff --git a/setup/db/create-index-fk.sql b/setup/db/create-index-fk.sql
index 18ed15b3ad4..17abc564753 100755
--- a/setup/db/create-index-fk.sql
+++ b/setup/db/create-index-fk.sql
@@ -11,8 +11,6 @@ ALTER TABLE `cloud`.`volumes` ADD INDEX `i_volumes__pool_id`(`pool_id`);
ALTER TABLE `cloud`.`volumes` ADD CONSTRAINT `fk_volumes__instance_id` FOREIGN KEY `fk_volumes__instance_id` (`instance_id`) REFERENCES `vm_instance` (`id`) ON DELETE CASCADE;
ALTER TABLE `cloud`.`volumes` ADD INDEX `i_volumes__instance_id`(`instance_id`);
-ALTER TABLE `cloud`.`template_spool_ref` ADD UNIQUE `i_template_spool_ref__template_id__pool_id`(`template_id`, `pool_id`);
-
#ALTER TABLE `cloud`.`op_ha_work` ADD CONSTRAINT `fk_op_ha_work__instance_id` FOREIGN KEY `fk_op_ha_work__instance_id` (`instance_id`) REFERENCES `vm_instance` (`id`);
ALTER TABLE `cloud`.`op_ha_work` ADD INDEX `i_op_ha_work__instance_id`(`instance_id`);
@@ -124,20 +122,10 @@ ALTER TABLE `cloud`.`op_host_capacity` ADD INDEX `i_op_host_capacity__pod_id`(`p
ALTER TABLE `cloud`.`op_host_capacity` ADD CONSTRAINT `fk_op_host_capacity__data_center_id` FOREIGN KEY `fk_op_host_capacity__data_center_id` (`data_center_id`) REFERENCES `data_center` (`id`) ON DELETE CASCADE;
ALTER TABLE `cloud`.`op_host_capacity` ADD INDEX `i_op_host_capacity__data_center_id`(`data_center_id`);
-ALTER TABLE `cloud`.`template_host_ref` ADD CONSTRAINT `fk_template_host_ref__host_id` FOREIGN KEY `fk_template_host_ref__host_id` (`host_id`) REFERENCES `host` (`id`) ON DELETE CASCADE;
-ALTER TABLE `cloud`.`template_host_ref` ADD INDEX `i_template_host_ref__host_id`(`host_id`);
-ALTER TABLE `cloud`.`template_host_ref` ADD CONSTRAINT `fk_template_host_ref__template_id` FOREIGN KEY `fk_template_host_ref__template_id` (`template_id`) REFERENCES `vm_template` (`id`) ON DELETE CASCADE;
-ALTER TABLE `cloud`.`template_host_ref` ADD INDEX `i_template_host_ref__template_id`(`template_id`);
-
ALTER TABLE `cloud`.`upload` ADD CONSTRAINT `fk_upload__host_id` FOREIGN KEY `fk_upload__host_id` (`host_id`) REFERENCES `host` (`id`) ON DELETE CASCADE;
ALTER TABLE `cloud`.`upload` ADD INDEX `i_upload__host_id`(`host_id`);
ALTER TABLE `cloud`.`upload` ADD INDEX `i_upload__type_id`(`type_id`);
-ALTER TABLE `cloud`.`template_zone_ref` ADD CONSTRAINT `fk_template_zone_ref__zone_id` FOREIGN KEY `fk_template_zone_ref__zone_id` (`zone_id`) REFERENCES `data_center` (`id`) ON DELETE CASCADE;
-ALTER TABLE `cloud`.`template_zone_ref` ADD INDEX `i_template_zone_ref__zone_id`(`zone_id`);
-ALTER TABLE `cloud`.`template_zone_ref` ADD CONSTRAINT `fk_template_zone_ref__template_id` FOREIGN KEY `fk_template_zone_ref__template_id` (`template_id`) REFERENCES `vm_template` (`id`) ON DELETE CASCADE;
-ALTER TABLE `cloud`.`template_zone_ref` ADD INDEX `i_template_zone_ref__template_id`(`template_id`);
-
ALTER TABLE `cloud`.`pod_vlan_map` ADD CONSTRAINT `fk_pod_vlan_map__pod_id` FOREIGN KEY `fk_pod_vlan_map__pod_id` (`pod_id`) REFERENCES `host_pod_ref` (`id`) ON DELETE CASCADE;
ALTER TABLE `cloud`.`pod_vlan_map` ADD INDEX `i_pod_vlan_map__pod_id`(`pod_id`);
diff --git a/setup/db/create-schema.sql b/setup/db/create-schema.sql
index abe5efe9537..c1e682fbe3c 100755
--- a/setup/db/create-schema.sql
+++ b/setup/db/create-schema.sql
@@ -850,7 +850,11 @@ CREATE TABLE `cloud`.`template_host_ref` (
`url` varchar(255),
`destroyed` tinyint(1) COMMENT 'indicates whether the template_host entry was destroyed by the user or not',
`is_copy` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'indicates whether this was copied ',
- PRIMARY KEY (`id`)
+ PRIMARY KEY (`id`),
+ CONSTRAINT `fk_template_host_ref__host_id` FOREIGN KEY `fk_template_host_ref__host_id` (`host_id`) REFERENCES `host` (`id`) ON DELETE CASCADE,
+ INDEX `i_template_host_ref__host_id`(`host_id`),
+ CONSTRAINT `fk_template_host_ref__template_id` FOREIGN KEY `fk_template_host_ref__template_id` (`template_id`) REFERENCES `vm_template` (`id`),
+ INDEX `i_template_host_ref__template_id`(`template_id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
CREATE TABLE `cloud`.`template_zone_ref` (
@@ -860,7 +864,11 @@ CREATE TABLE `cloud`.`template_zone_ref` (
`created` DATETIME NOT NULL,
`last_updated` DATETIME,
`removed` datetime COMMENT 'date removed if not null',
- PRIMARY KEY (`id`)
+ PRIMARY KEY (`id`),
+ CONSTRAINT `fk_template_zone_ref__zone_id` FOREIGN KEY `fk_template_zone_ref__zone_id` (`zone_id`) REFERENCES `data_center` (`id`) ON DELETE CASCADE,
+ INDEX `i_template_zone_ref__zone_id`(`zone_id`),
+ CONSTRAINT `fk_template_zone_ref__template_id` FOREIGN KEY `fk_template_zone_ref__template_id` (`template_id`) REFERENCES `vm_template` (`id`) ON DELETE CASCADE,
+ INDEX `i_template_zone_ref__template_id`(`template_id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
CREATE TABLE `cloud`.`console_proxy` (
@@ -1178,7 +1186,10 @@ CREATE TABLE `cloud`.`template_spool_ref` (
`install_path` varchar(255),
`template_size` bigint unsigned NOT NULL COMMENT 'the size of the template on the pool',
`marked_for_gc` tinyint(1) unsigned NOT NULL DEFAULT 0 COMMENT 'if true, the garbage collector will evict the template from this pool.',
- PRIMARY KEY (`id`)
+ PRIMARY KEY (`id`),
+ UNIQUE `i_template_spool_ref__template_id__pool_id`(`template_id`, `pool_id`),
+ CONSTRAINT `fk_template_spool_ref__template_id` FOREIGN KEY (`template_id`) REFERENCES `vm_template`(`id`),
+ CONSTRAINT `fk_template_spool_ref__pool_id` FOREIGN KEY (`pool_id`) REFERENCES `storage_pool`(`id`) ON DELETE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
CREATE TABLE `cloud`.`guest_os` (