Return-Path: X-Original-To: apmail-cloudstack-commits-archive@www.apache.org Delivered-To: apmail-cloudstack-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id A026910993 for ; Sat, 26 Oct 2013 01:24:56 +0000 (UTC) Received: (qmail 41648 invoked by uid 500); 26 Oct 2013 01:24:56 -0000 Delivered-To: apmail-cloudstack-commits-archive@cloudstack.apache.org Received: (qmail 41553 invoked by uid 500); 26 Oct 2013 01:24:56 -0000 Mailing-List: contact commits-help@cloudstack.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cloudstack.apache.org Delivered-To: mailing list commits@cloudstack.apache.org Received: (qmail 41537 invoked by uid 99); 26 Oct 2013 01:24:56 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 26 Oct 2013 01:24:56 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 0EC7381E9FA; Sat, 26 Oct 2013 01:24:55 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: edison@apache.org To: commits@cloudstack.apache.org Date: Sat, 26 Oct 2013 01:24:58 -0000 Message-Id: In-Reply-To: <7f249840190b409498570e33c1832d50@git.apache.org> References: <7f249840190b409498570e33c1832d50@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [4/5] git commit: updated refs/heads/master to 465c9ec rebase to spring changes Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/70b2c015 Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/70b2c015 Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/70b2c015 Branch: refs/heads/master Commit: 70b2c0150dad5ca3b42e34d20831a256661bc8f0 Parents: 51a8086 Author: Edison Su Authored: Fri Oct 25 18:15:36 2013 -0700 Committer: Edison Su Committed: Fri Oct 25 18:15:36 2013 -0700 ---------------------------------------------------------------------- .../core/spring-core-registry-core-context.xml | 7 ++- ...ng-lifecycle-storage-context-inheritable.xml | 6 ++ .../api/storage/StorageStrategyFactory.java | 5 +- .../api/storage/VMSnapshotStrategy.java | 2 +- .../spring-engine-schema-core-daos-context.xml | 1 + .../core/spring-engine-storage-core-context.xml | 1 + ...-engine-storage-snapshot-storage-context.xml | 7 ++- .../vmsnapshot/DefaultVMSnapshotStrategy.java | 5 +- .../helper/StorageStrategyFactoryImpl.java | 22 +++++++ .../vm/snapshot/VMSnapshotManagerImpl.java | 62 ++------------------ 10 files changed, 56 insertions(+), 62 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/70b2c015/core/resources/META-INF/cloudstack/core/spring-core-registry-core-context.xml ---------------------------------------------------------------------- diff --git a/core/resources/META-INF/cloudstack/core/spring-core-registry-core-context.xml b/core/resources/META-INF/cloudstack/core/spring-core-registry-core-context.xml index 26d70c9..a8b2e29 100644 --- a/core/resources/META-INF/cloudstack/core/spring-core-registry-core-context.xml +++ b/core/resources/META-INF/cloudstack/core/spring-core-registry-core-context.xml @@ -260,9 +260,14 @@ + + + + - \ No newline at end of file + http://git-wip-us.apache.org/repos/asf/cloudstack/blob/70b2c015/core/resources/META-INF/cloudstack/storage/spring-lifecycle-storage-context-inheritable.xml ---------------------------------------------------------------------- diff --git a/core/resources/META-INF/cloudstack/storage/spring-lifecycle-storage-context-inheritable.xml b/core/resources/META-INF/cloudstack/storage/spring-lifecycle-storage-context-inheritable.xml index b6eed7d..ad78cad 100644 --- a/core/resources/META-INF/cloudstack/storage/spring-lifecycle-storage-context-inheritable.xml +++ b/core/resources/META-INF/cloudstack/storage/spring-lifecycle-storage-context-inheritable.xml @@ -64,6 +64,12 @@ + + + + + http://git-wip-us.apache.org/repos/asf/cloudstack/blob/70b2c015/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/StorageStrategyFactory.java ---------------------------------------------------------------------- diff --git a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/StorageStrategyFactory.java b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/StorageStrategyFactory.java index ac1e311..91bcc1f 100644 --- a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/StorageStrategyFactory.java +++ b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/StorageStrategyFactory.java @@ -24,6 +24,7 @@ import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotStrategy.Snaps import com.cloud.host.Host; import com.cloud.storage.Snapshot; +import com.cloud.vm.snapshot.VMSnapshot; public interface StorageStrategyFactory { @@ -31,6 +32,8 @@ public interface StorageStrategyFactory { DataMotionStrategy getDataMotionStrategy(Map volumeMap, Host srcHost, Host destHost); - SnapshotStrategy getSnapshotStrategy(Snapshot snapshot, SnapshotOperation op); + SnapshotStrategy getSnapshotStrategy(Snapshot snapshot, SnapshotOperation op); + + VMSnapshotStrategy getVmSnapshotStrategy(VMSnapshot vmSnapshot); } http://git-wip-us.apache.org/repos/asf/cloudstack/blob/70b2c015/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/VMSnapshotStrategy.java ---------------------------------------------------------------------- diff --git a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/VMSnapshotStrategy.java b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/VMSnapshotStrategy.java index 8dd6eca..c2a0ded 100644 --- a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/VMSnapshotStrategy.java +++ b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/VMSnapshotStrategy.java @@ -24,5 +24,5 @@ public interface VMSnapshotStrategy { VMSnapshot takeVMSnapshot(VMSnapshot vmSnapshot); boolean deleteVMSnapshot(VMSnapshot vmSnapshot); boolean revertVMSnapshot(VMSnapshot vmSnapshot); - boolean canHandle(VMSnapshot vmSnapshot); + StrategyPriority canHandle(VMSnapshot vmSnapshot); } http://git-wip-us.apache.org/repos/asf/cloudstack/blob/70b2c015/engine/schema/resources/META-INF/cloudstack/core/spring-engine-schema-core-daos-context.xml ---------------------------------------------------------------------- diff --git a/engine/schema/resources/META-INF/cloudstack/core/spring-engine-schema-core-daos-context.xml b/engine/schema/resources/META-INF/cloudstack/core/spring-engine-schema-core-daos-context.xml index a70cd00..3fce439 100644 --- a/engine/schema/resources/META-INF/cloudstack/core/spring-engine-schema-core-daos-context.xml +++ b/engine/schema/resources/META-INF/cloudstack/core/spring-engine-schema-core-daos-context.xml @@ -291,6 +291,7 @@ + http://git-wip-us.apache.org/repos/asf/cloudstack/blob/70b2c015/engine/storage/resources/META-INF/cloudstack/core/spring-engine-storage-core-context.xml ---------------------------------------------------------------------- diff --git a/engine/storage/resources/META-INF/cloudstack/core/spring-engine-storage-core-context.xml b/engine/storage/resources/META-INF/cloudstack/core/spring-engine-storage-core-context.xml index 8a78fdd..a6a0c22 100644 --- a/engine/storage/resources/META-INF/cloudstack/core/spring-engine-storage-core-context.xml +++ b/engine/storage/resources/META-INF/cloudstack/core/spring-engine-storage-core-context.xml @@ -63,6 +63,7 @@ + http://git-wip-us.apache.org/repos/asf/cloudstack/blob/70b2c015/engine/storage/snapshot/resources/META-INF/cloudstack/storage/spring-engine-storage-snapshot-storage-context.xml ---------------------------------------------------------------------- diff --git a/engine/storage/snapshot/resources/META-INF/cloudstack/storage/spring-engine-storage-snapshot-storage-context.xml b/engine/storage/snapshot/resources/META-INF/cloudstack/storage/spring-engine-storage-snapshot-storage-context.xml index 3faa894..d25aeea 100644 --- a/engine/storage/snapshot/resources/META-INF/cloudstack/storage/spring-engine-storage-snapshot-storage-context.xml +++ b/engine/storage/snapshot/resources/META-INF/cloudstack/storage/spring-engine-storage-snapshot-storage-context.xml @@ -30,4 +30,9 @@ - \ No newline at end of file + + + + http://git-wip-us.apache.org/repos/asf/cloudstack/blob/70b2c015/engine/storage/snapshot/src/org/apache/cloudstack/storage/vmsnapshot/DefaultVMSnapshotStrategy.java ---------------------------------------------------------------------- diff --git a/engine/storage/snapshot/src/org/apache/cloudstack/storage/vmsnapshot/DefaultVMSnapshotStrategy.java b/engine/storage/snapshot/src/org/apache/cloudstack/storage/vmsnapshot/DefaultVMSnapshotStrategy.java index 0ef8ebb..be3cce9 100644 --- a/engine/storage/snapshot/src/org/apache/cloudstack/storage/vmsnapshot/DefaultVMSnapshotStrategy.java +++ b/engine/storage/snapshot/src/org/apache/cloudstack/storage/vmsnapshot/DefaultVMSnapshotStrategy.java @@ -24,6 +24,7 @@ import java.util.Map; import javax.inject.Inject; import javax.naming.ConfigurationException; +import org.apache.cloudstack.engine.subsystem.api.storage.StrategyPriority; import org.apache.cloudstack.engine.subsystem.api.storage.VMSnapshotStrategy; import org.apache.cloudstack.framework.config.dao.ConfigurationDao; import org.apache.cloudstack.storage.to.VolumeObjectTO; @@ -364,7 +365,7 @@ public class DefaultVMSnapshotStrategy extends ManagerBase implements VMSnapshot } @Override - public boolean canHandle(VMSnapshot vmSnapshot) { - return true; + public StrategyPriority canHandle(VMSnapshot vmSnapshot) { + return StrategyPriority.DEFAULT; } } http://git-wip-us.apache.org/repos/asf/cloudstack/blob/70b2c015/engine/storage/src/org/apache/cloudstack/storage/helper/StorageStrategyFactoryImpl.java ---------------------------------------------------------------------- diff --git a/engine/storage/src/org/apache/cloudstack/storage/helper/StorageStrategyFactoryImpl.java b/engine/storage/src/org/apache/cloudstack/storage/helper/StorageStrategyFactoryImpl.java index 30812bf..a1d128b 100644 --- a/engine/storage/src/org/apache/cloudstack/storage/helper/StorageStrategyFactoryImpl.java +++ b/engine/storage/src/org/apache/cloudstack/storage/helper/StorageStrategyFactoryImpl.java @@ -31,15 +31,18 @@ import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotStrategy; import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotStrategy.SnapshotOperation; import org.apache.cloudstack.engine.subsystem.api.storage.StorageStrategyFactory; import org.apache.cloudstack.engine.subsystem.api.storage.StrategyPriority; +import org.apache.cloudstack.engine.subsystem.api.storage.VMSnapshotStrategy; import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo; import com.cloud.host.Host; import com.cloud.storage.Snapshot; +import com.cloud.vm.snapshot.VMSnapshot; public class StorageStrategyFactoryImpl implements StorageStrategyFactory { List snapshotStrategies; List dataMotionStrategies; + List vmSnapshotStrategies; @Override public DataMotionStrategy getDataMotionStrategy(final DataObject srcData, final DataObject destData) { @@ -71,6 +74,16 @@ public class StorageStrategyFactoryImpl implements StorageStrategyFactory { }); } + @Override + public VMSnapshotStrategy getVmSnapshotStrategy(final VMSnapshot vmSnapshot) { + return bestMatch(vmSnapshotStrategies, new CanHandle() { + @Override + public StrategyPriority canHandle(VMSnapshotStrategy strategy) { + return strategy.canHandle(vmSnapshot); + } + }); + } + private static T bestMatch(Collection collection, final CanHandle canHandle) { if (collection.size() == 0) return null; @@ -111,4 +124,13 @@ public class StorageStrategyFactoryImpl implements StorageStrategyFactory { this.dataMotionStrategies = dataMotionStrategies; } + @Inject + public void setVmSnapshotStrategies(List vmSnapshotStrategies) { + this.vmSnapshotStrategies = vmSnapshotStrategies; + } + + public List getVmSnapshotStrategies() { + return vmSnapshotStrategies; + } + } http://git-wip-us.apache.org/repos/asf/cloudstack/blob/70b2c015/server/src/com/cloud/vm/snapshot/VMSnapshotManagerImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/vm/snapshot/VMSnapshotManagerImpl.java b/server/src/com/cloud/vm/snapshot/VMSnapshotManagerImpl.java index 3f473bd..ee81c82 100644 --- a/server/src/com/cloud/vm/snapshot/VMSnapshotManagerImpl.java +++ b/server/src/com/cloud/vm/snapshot/VMSnapshotManagerImpl.java @@ -27,26 +27,13 @@ import javax.ejb.Local; import javax.inject.Inject; import javax.naming.ConfigurationException; -import org.apache.log4j.Logger; -import org.springframework.stereotype.Component; import org.apache.cloudstack.api.command.user.vmsnapshot.ListVMSnapshotCmd; import org.apache.cloudstack.context.CallContext; -import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager; +import org.apache.cloudstack.engine.subsystem.api.storage.StorageStrategyFactory; +import org.apache.cloudstack.engine.subsystem.api.storage.VMSnapshotStrategy; import org.apache.cloudstack.framework.config.dao.ConfigurationDao; -import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; -import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; - -import com.cloud.agent.AgentManager; -import com.cloud.agent.api.Answer; -import com.cloud.agent.api.Command; -import com.cloud.agent.api.CreateVMSnapshotAnswer; -import com.cloud.agent.api.CreateVMSnapshotCommand; -import com.cloud.agent.api.DeleteVMSnapshotAnswer; -import com.cloud.agent.api.DeleteVMSnapshotCommand; -import com.cloud.agent.api.RevertToVMSnapshotAnswer; -import com.cloud.agent.api.RevertToVMSnapshotCommand; -import com.cloud.agent.api.VMSnapshotTO; -import com.cloud.agent.api.to.VolumeTO; +import org.apache.log4j.Logger; +import org.springframework.stereotype.Component; import com.cloud.event.ActionEvent; import com.cloud.event.EventTypes; @@ -75,14 +62,6 @@ import com.cloud.utils.component.ManagerBase; import com.cloud.utils.db.Filter; import com.cloud.utils.db.SearchBuilder; import com.cloud.utils.db.SearchCriteria; - -import com.cloud.utils.db.Transaction; -import com.cloud.utils.db.TransactionCallback; -import com.cloud.utils.db.TransactionCallbackNoReturn; -import com.cloud.utils.db.TransactionCallbackWithException; -import com.cloud.utils.db.TransactionCallbackWithExceptionNoReturn; -import com.cloud.utils.db.TransactionStatus; - import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.vm.UserVmVO; import com.cloud.vm.VMInstanceVO; @@ -92,21 +71,6 @@ import com.cloud.vm.VirtualMachineManager; import com.cloud.vm.VirtualMachineProfile; import com.cloud.vm.dao.UserVmDao; import com.cloud.vm.snapshot.dao.VMSnapshotDao; -import org.apache.cloudstack.api.command.user.vmsnapshot.ListVMSnapshotCmd; -import org.apache.cloudstack.context.CallContext; -import org.apache.cloudstack.engine.subsystem.api.storage.VMSnapshotStrategy; -import org.apache.cloudstack.framework.config.dao.ConfigurationDao; -import org.apache.log4j.Logger; -import org.springframework.stereotype.Component; - -import javax.ejb.Local; -import javax.inject.Inject; -import javax.naming.ConfigurationException; -import java.util.ArrayList; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; @Component @Local(value = { VMSnapshotManager.class, VMSnapshotService.class }) @@ -123,16 +87,8 @@ public class VMSnapshotManagerImpl extends ManagerBase implements VMSnapshotMana @Inject VirtualMachineManager _itMgr; @Inject ConfigurationDao _configDao; @Inject HypervisorCapabilitiesDao _hypervisorCapabilitiesDao; - @Inject List vmSnapshotStrategies; - - public List getVmSnapshotStrategies() { - return vmSnapshotStrategies; - } - @Inject - public void setVmSnapshotStrategies(List vmSnapshotStrategies) { - this.vmSnapshotStrategies = vmSnapshotStrategies; - } + StorageStrategyFactory storageStrategyFactory; int _vmSnapshotMax; int _wait; @@ -343,13 +299,7 @@ public class VMSnapshotManagerImpl extends ManagerBase implements VMSnapshotMana } private VMSnapshotStrategy findVMSnapshotStrategy(VMSnapshot vmSnapshot) { - VMSnapshotStrategy snapshotStrategy = null; - for(VMSnapshotStrategy strategy : vmSnapshotStrategies) { - if (strategy.canHandle(vmSnapshot)) { - snapshotStrategy = strategy; - break; - } - } + VMSnapshotStrategy snapshotStrategy = storageStrategyFactory.getVmSnapshotStrategy(vmSnapshot); if (snapshotStrategy == null) { throw new CloudRuntimeException("can't find vm snapshot strategy for vmsnapshot: " + vmSnapshot.getId());