From 6bd978abfe4e68fa62b708fd5eb4b8eb2b5c19f8 Mon Sep 17 00:00:00 2001 From: Alex Huang Date: Tue, 29 Mar 2011 11:31:11 -0700 Subject: [PATCH] bug 9192: fixes the caches that are gone due to configuration server uses the same dao without cache --- .../xen/resource/CitrixResourceBase.java | 19 +++++++++++-------- .../com/cloud/resource/ServerResource.java | 14 ++++++-------- setup/db/create-schema.sql | 11 +++++++---- .../utils/component/ComponentLocator.java | 5 ++++- 4 files changed, 28 insertions(+), 21 deletions(-) diff --git a/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java b/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java index 8daab50a175..710194405aa 100644 --- a/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java +++ b/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java @@ -172,6 +172,7 @@ import com.cloud.network.ovs.OvsDestroyTunnelCommand; import com.cloud.network.ovs.OvsSetTagAndFlowAnswer; import com.cloud.network.ovs.OvsSetTagAndFlowCommand; import com.cloud.resource.ServerResource; +import com.cloud.resource.hypervisor.HypervisorResource; import com.cloud.storage.Storage; import com.cloud.storage.Storage.ImageFormat; import com.cloud.storage.Storage.StoragePoolType; @@ -221,7 +222,7 @@ import com.xensource.xenapi.XenAPIObject; * */ @Local(value = ServerResource.class) -public abstract class CitrixResourceBase implements ServerResource { +public abstract class CitrixResourceBase implements ServerResource, HypervisorResource { private static final Logger s_logger = Logger.getLogger(CitrixResourceBase.class); protected static final XenServerConnectionPool _connPool = XenServerConnectionPool.getInstance(); protected static final int MB = 1024 * 1024; @@ -376,7 +377,6 @@ public abstract class CitrixResourceBase implements ServerResource { @Override public Answer executeRequest(Command cmd) { - if (cmd instanceof CreateCommand) { return execute((CreateCommand) cmd); } else if (cmd instanceof SetPortForwardingRulesCommand) { @@ -1006,7 +1006,8 @@ public abstract class CitrixResourceBase implements ServerResource { } } - protected StartAnswer execute(StartCommand cmd) { + @Override + public StartAnswer execute(StartCommand cmd) { Connection conn = getConnection(); VirtualMachineTO vmSpec = cmd.getVirtualMachine(); String vmName = vmSpec.getName(); @@ -2575,7 +2576,8 @@ public abstract class CitrixResourceBase implements ServerResource { return NumbersUtil.parseInt(vncport, -1); } - protected Answer execute(final RebootCommand cmd) { + @Override + public RebootAnswer execute(RebootCommand cmd) { Connection conn = getConnection(); synchronized (_vms) { _vms.put(cmd.getVmName(), State.Starting); @@ -2617,7 +2619,7 @@ public abstract class CitrixResourceBase implements ServerResource { bytesSent = stats[0]; bytesRcvd = stats[1]; } - RebootAnswer answer = (RebootAnswer) execute((RebootCommand) cmd); + RebootAnswer answer = execute((RebootCommand) cmd); answer.setBytesSent(bytesSent); answer.setBytesReceived(bytesRcvd); if (answer.getResult()) { @@ -2952,8 +2954,9 @@ public abstract class CitrixResourceBase implements ServerResource { } return null; } - - protected StopAnswer execute(final StopCommand cmd) { + + @Override + public StopAnswer execute(StopCommand cmd) { Connection conn = getConnection(); String vmName = cmd.getVmName(); try { @@ -3082,7 +3085,7 @@ public abstract class CitrixResourceBase implements ServerResource { } return new StopAnswer(cmd, "Stop VM failed"); } - + private List getVdis(Connection conn, VM vm) { List vdis = new ArrayList(); try { diff --git a/core/src/com/cloud/resource/ServerResource.java b/core/src/com/cloud/resource/ServerResource.java index ca657140f60..af1dc3e6cab 100755 --- a/core/src/com/cloud/resource/ServerResource.java +++ b/core/src/com/cloud/resource/ServerResource.java @@ -40,35 +40,33 @@ public interface ServerResource extends Manager { * Generate a startup command containing information regarding the resource. * @return StartupCommand ready to be sent to the management server. */ - public StartupCommand[] initialize(); + StartupCommand[] initialize(); /** * @param id id of the server to put in the PingCommand * @return PingCommand */ - public PingCommand getCurrentStatus(long id); + PingCommand getCurrentStatus(long id); /** * Execute the request coming from the computing server. * @param cmd Command to execute. * @return Answer */ - public Answer executeRequest(Command cmd); - -// public void revertRequest(Command cmd, Answer answer); + Answer executeRequest(Command cmd); /** * disconnected() is called when the connection is down between the * agent and the management server. If there are any cleanups, this * is the time to do it. */ - public void disconnected(); + void disconnected(); /** * This is added to allow calling agent control service from within the resource * @return */ - public IAgentControl getAgentControl(); + IAgentControl getAgentControl(); - public void setAgentControl(IAgentControl agentControl); + void setAgentControl(IAgentControl agentControl); } diff --git a/setup/db/create-schema.sql b/setup/db/create-schema.sql index 2ac0784399b..6fd9850fc6d 100755 --- a/setup/db/create-schema.sql +++ b/setup/db/create-schema.sql @@ -189,7 +189,8 @@ CREATE TABLE `cloud`.`networks` ( CONSTRAINT `fk_networks__data_center_id` FOREIGN KEY (`data_center_id`) REFERENCES `data_center`(`id`), CONSTRAINT `fk_networks__related` FOREIGN KEY(`related`) REFERENCES `networks`(`id`) ON DELETE CASCADE, CONSTRAINT `fk_networks__account_id` FOREIGN KEY(`account_id`) REFERENCES `account`(`id`), - CONSTRAINT `fk_networks__domain_id` FOREIGN KEY(`domain_id`) REFERENCES `domain`(`id`) + CONSTRAINT `fk_networks__domain_id` FOREIGN KEY(`domain_id`) REFERENCES `domain`(`id`), + INDEX `i_networks__removed`(`removed`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE `cloud`.`account_network_ref` ( @@ -237,7 +238,8 @@ CREATE TABLE `cloud`.`nics` ( `removed` datetime COMMENT 'date removed if not null', PRIMARY KEY (`id`), CONSTRAINT `fk_nics__instance_id` FOREIGN KEY `fk_nics__instance_id`(`instance_id`) REFERENCES `vm_instance`(`id`) ON DELETE CASCADE, - CONSTRAINT `fk_nics__networks_id` FOREIGN KEY `fk_nics__networks_id`(`network_id`) REFERENCES `networks`(`id`) + CONSTRAINT `fk_nics__networks_id` FOREIGN KEY `fk_nics__networks_id`(`network_id`) REFERENCES `networks`(`id`), + INDEX `i_nics__removed`(`removed`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE `cloud`.`network_offerings` ( @@ -264,7 +266,8 @@ CREATE TABLE `cloud`.`network_offerings` ( `vpn_service` int(1) unsigned NOT NULL DEFAULT 0 COMMENT 'true if network offering provides vpn service', `dhcp_service` int(1) unsigned NOT NULL DEFAULT 0 COMMENT 'true if network offering provides dhcp service', `guest_type` char(32) COMMENT 'guest ip type of network offering', - PRIMARY KEY (`id`) + PRIMARY KEY (`id`), + INDEX `i_network_offerings__removed`(`removed`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE `cloud`.`cluster` ( @@ -435,7 +438,7 @@ CREATE TABLE `cloud`.`vlan` ( `data_center_id` bigint unsigned NOT NULL, `network_id` bigint unsigned NOT NULL COMMENT 'id of corresponding network offering', PRIMARY KEY (`id`), -# CONSTRAINT `fk_vlan__network_id` FOREIGN KEY (`network_id`) REFERENCES `networks`(`id`), + CONSTRAINT `fk_vlan__network_id` FOREIGN KEY (`network_id`) REFERENCES `networks`(`id`), CONSTRAINT `fk_vlan__data_center_id` FOREIGN KEY (`data_center_id`) REFERENCES `data_center`(`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/utils/src/com/cloud/utils/component/ComponentLocator.java b/utils/src/com/cloud/utils/component/ComponentLocator.java index 87e4b7662d6..0ca1ddc1b91 100755 --- a/utils/src/com/cloud/utils/component/ComponentLocator.java +++ b/utils/src/com/cloud/utils/component/ComponentLocator.java @@ -856,7 +856,6 @@ public class ComponentLocator implements ComponentLocatorMBean { if (info.name == null) { throw new CloudRuntimeException("Missing name attribute for " + interphace.getName()); } - info.name = info.name; s_logger.debug("Looking for class " + clazzName); try { info.clazz = Class.forName(clazzName); @@ -869,6 +868,10 @@ public class ComponentLocator implements ComponentLocatorMBean { if (!interphace.isAssignableFrom(info.clazz)) { throw new CloudRuntimeException("Class " + info.clazz.toString() + " does not implment " + interphace); } + String singleton = getAttribute(atts, "singleton"); + if (singleton != null) { + info.singleton = Boolean.parseBoolean(singleton); + } info.fillInfo(); }