incubator-cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wid...@apache.org
Subject [19/58] [abbrv] refactor snapshot, move existing snapshot code into its own snapshotstrategy
Date Fri, 22 Feb 2013 14:01:12 GMT
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/ff047e75/engine/storage/volume/src/org/apache/cloudstack/storage/datastore/DefaultPrimaryDataStore.java
----------------------------------------------------------------------
diff --git a/engine/storage/volume/src/org/apache/cloudstack/storage/datastore/DefaultPrimaryDataStore.java b/engine/storage/volume/src/org/apache/cloudstack/storage/datastore/DefaultPrimaryDataStore.java
index 72c1843..f2a9993 100644
--- a/engine/storage/volume/src/org/apache/cloudstack/storage/datastore/DefaultPrimaryDataStore.java
+++ b/engine/storage/volume/src/org/apache/cloudstack/storage/datastore/DefaultPrimaryDataStore.java
@@ -31,6 +31,7 @@ import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider;
 import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreRole;
 import org.apache.cloudstack.engine.subsystem.api.storage.ImageDataFactory;
 import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine;
+import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreDriver;
 import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreLifeCycle;
 import org.apache.cloudstack.engine.subsystem.api.storage.Scope;
 import org.apache.cloudstack.engine.subsystem.api.storage.ScopeType;
@@ -42,7 +43,6 @@ import org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope;
 import org.apache.cloudstack.engine.subsystem.api.storage.disktype.DiskFormat;
 import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
 import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
-import org.apache.cloudstack.storage.volume.PrimaryDataStoreDriver;
 import org.apache.cloudstack.storage.volume.VolumeObject;
 import org.apache.log4j.Logger;
 

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/ff047e75/engine/storage/volume/src/org/apache/cloudstack/storage/datastore/driver/AncientPrimaryDataStoreDriverImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/volume/src/org/apache/cloudstack/storage/datastore/driver/AncientPrimaryDataStoreDriverImpl.java b/engine/storage/volume/src/org/apache/cloudstack/storage/datastore/driver/AncientPrimaryDataStoreDriverImpl.java
index 9946fba..657ba80 100644
--- a/engine/storage/volume/src/org/apache/cloudstack/storage/datastore/driver/AncientPrimaryDataStoreDriverImpl.java
+++ b/engine/storage/volume/src/org/apache/cloudstack/storage/datastore/driver/AncientPrimaryDataStoreDriverImpl.java
@@ -29,261 +29,325 @@ import org.apache.cloudstack.engine.subsystem.api.storage.DataObject;
 import org.apache.cloudstack.engine.subsystem.api.storage.DataObjectType;
 import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
 import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
+import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreDriver;
 import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo;
 import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
 import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
 import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
-import org.apache.cloudstack.storage.volume.PrimaryDataStoreDriver;
+import org.apache.cloudstack.storage.volume.VolumeObject;
 import org.apache.log4j.Logger;
 
 import com.cloud.agent.api.Answer;
+import com.cloud.agent.api.ManageSnapshotAnswer;
+import com.cloud.agent.api.ManageSnapshotCommand;
 import com.cloud.agent.api.storage.CreateAnswer;
 import com.cloud.agent.api.storage.CreateCommand;
 import com.cloud.agent.api.storage.DestroyCommand;
+import com.cloud.agent.api.storage.ResizeVolumeAnswer;
+import com.cloud.agent.api.storage.ResizeVolumeCommand;
 import com.cloud.agent.api.to.StorageFilerTO;
 import com.cloud.exception.StorageUnavailableException;
 import com.cloud.host.HostVO;
 import com.cloud.host.dao.HostDao;
 import com.cloud.storage.DiskOfferingVO;
+import com.cloud.storage.ResizeVolumePayload;
 import com.cloud.storage.Storage;
 import com.cloud.storage.Storage.StoragePoolType;
+import com.cloud.storage.SnapshotVO;
 import com.cloud.storage.StorageManager;
 import com.cloud.storage.StoragePool;
 import com.cloud.storage.VMTemplateHostVO;
 import com.cloud.storage.VMTemplateStoragePoolVO;
 import com.cloud.storage.VMTemplateVO;
+import com.cloud.storage.VolumeManager;
 import com.cloud.storage.VolumeVO;
 import com.cloud.storage.dao.DiskOfferingDao;
+import com.cloud.storage.dao.SnapshotDao;
 import com.cloud.storage.dao.VMTemplateDao;
 import com.cloud.storage.dao.VolumeDao;
+import com.cloud.storage.snapshot.SnapshotManager;
 import com.cloud.template.TemplateManager;
 import com.cloud.utils.exception.CloudRuntimeException;
 import com.cloud.vm.DiskProfile;
 import com.cloud.vm.dao.VMInstanceDao;
 
 public class AncientPrimaryDataStoreDriverImpl implements PrimaryDataStoreDriver {
-    private static final Logger s_logger = Logger
-            .getLogger(AncientPrimaryDataStoreDriverImpl.class);
-    @Inject DiskOfferingDao diskOfferingDao;
-    @Inject VMTemplateDao templateDao;
-    @Inject VolumeDao volumeDao;
-    @Inject TemplateManager templateMgr;
-    @Inject HostDao hostDao;
-    @Inject StorageManager storageMgr;
-    @Inject VMInstanceDao vmDao;
-    @Inject PrimaryDataStoreDao primaryStoreDao;
-    @Override
-    public String grantAccess(DataObject data, EndPoint ep) {
-        // TODO Auto-generated method stub
-        return null;
-    }
-
-    @Override
-    public boolean revokeAccess(DataObject data, EndPoint ep) {
-        // TODO Auto-generated method stub
-        return false;
-    }
-
-    @Override
-    public Set<DataObject> listObjects(DataStore store) {
-        // TODO Auto-generated method stub
-        return null;
-    }
-
-    public boolean createVolume(
-            VolumeInfo volume) throws StorageUnavailableException {
-        if (s_logger.isDebugEnabled()) {
-            s_logger.debug("Creating volume: " + volume);
-        }
-        
-        DiskOfferingVO offering = diskOfferingDao.findById(volume.getDiskOfferingId());
-        DiskProfile diskProfile = new DiskProfile(volume, offering,
-                null);
+	private static final Logger s_logger = Logger
+			.getLogger(AncientPrimaryDataStoreDriverImpl.class);
+	@Inject DiskOfferingDao diskOfferingDao;
+	@Inject VMTemplateDao templateDao;
+	@Inject VolumeDao volumeDao;
+	@Inject TemplateManager templateMgr;
+	@Inject HostDao hostDao;
+	@Inject StorageManager storageMgr;
+	@Inject VolumeManager volumeMgr;
+	@Inject VMInstanceDao vmDao;
+	@Inject SnapshotDao snapshotDao;
+	@Inject PrimaryDataStoreDao primaryStoreDao;
+	@Inject SnapshotManager snapshotMgr;
+	@Override
+	public String grantAccess(DataObject data, EndPoint ep) {
+		// TODO Auto-generated method stub
+		return null;
+	}
 
-        VMTemplateVO template = null;
-        if (volume.getTemplateId() != null) {
-            template = templateDao.findById(volume.getTemplateId());
-        }
+	@Override
+	public boolean revokeAccess(DataObject data, EndPoint ep) {
+		// TODO Auto-generated method stub
+		return false;
+	}
 
-        StoragePool pool = (StoragePool)volume.getDataStore();
-        VolumeVO vol = volumeDao.findById(volume.getId());
-        if (pool != null) {
-            if (s_logger.isDebugEnabled()) {
-                s_logger.debug("Trying to create in " + pool);
-            }
-            vol.setPoolId(pool.getId());
-   
-            CreateCommand cmd = null;
-            VMTemplateStoragePoolVO tmpltStoredOn = null;
-
-            for (int i = 0; i < 2; i++) {
-                if (template != null
-                        && template.getFormat() != Storage.ImageFormat.ISO) {
-                    if (pool.getPoolType() == StoragePoolType.CLVM) {
-                        // prepareISOForCreate does what we need, which is to
-                        // tell us where the template is
-                        VMTemplateHostVO tmpltHostOn = templateMgr
-                                .prepareISOForCreate(template, pool);
-                        if (tmpltHostOn == null) {
-                            s_logger.debug("cannot find template "
-                                    + template.getId() + " "
-                                    + template.getName());
-                            throw new CloudRuntimeException("cannot find template"
-                                    + template.getId() 
-                                    + template.getName());
-                        }
-                        HostVO secondaryStorageHost = hostDao
-                                .findById(tmpltHostOn.getHostId());
-                        String tmpltHostUrl = secondaryStorageHost
-                                .getStorageUrl();
-                        String fullTmpltUrl = tmpltHostUrl + "/"
-                                + tmpltHostOn.getInstallPath();
-                        cmd = new CreateCommand(diskProfile, fullTmpltUrl,
-                                new StorageFilerTO(pool));
-                    } else {
-                        tmpltStoredOn = templateMgr.prepareTemplateForCreate(
-                                template, pool);
-                        if (tmpltStoredOn == null) {
-                            s_logger.debug("Cannot use this pool " + pool
-                                    + " because we can't propagate template "
-                                    + template);
-                            throw new CloudRuntimeException("Cannot use this pool " + pool
-                                    + " because we can't propagate template "
-                                    + template);
-                        }
-                        cmd = new CreateCommand(diskProfile,
-                                tmpltStoredOn.getLocalDownloadPath(),
-                                new StorageFilerTO(pool));
-                    }
-                } else {
-                    if (template != null
-                            && Storage.ImageFormat.ISO == template.getFormat()) {
-                        VMTemplateHostVO tmpltHostOn = templateMgr
-                                .prepareISOForCreate(template, pool);
-                        if (tmpltHostOn == null) {
-                            throw new CloudRuntimeException(
-                                    "Did not find ISO in secondry storage in zone "
-                                            + pool.getDataCenterId());
-                        }
-                    }
-                    cmd = new CreateCommand(diskProfile, new StorageFilerTO(
-                            pool));
-                }
-
-                Answer answer = storageMgr.sendToPool(pool, null, cmd);
-                if (answer.getResult()) {
-                    CreateAnswer createAnswer = (CreateAnswer) answer;
-                    vol.setFolder(pool.getPath());
-                    vol.setPath(createAnswer.getVolume().getPath());
-                    vol.setSize(createAnswer.getVolume().getSize());
-                    vol.setPoolType(pool.getPoolType());
-                    vol.setPoolId(pool.getId());
-                    vol.setPodId(pool.getPodId());
-                    this.volumeDao.update(vol.getId(), vol);
-                    return true;
-                } else {
-                    if (tmpltStoredOn != null
-                            && (answer instanceof CreateAnswer)
-                            && ((CreateAnswer) answer)
-                                    .templateReloadRequested()) {
-                        if (!templateMgr
-                                .resetTemplateDownloadStateOnPool(tmpltStoredOn
-                                        .getId())) {
-                            break; // break out of template-redeploy retry loop
-                        }
-                    } else {
-                        break;
-                    }
-                }
-            }
-        }
+	@Override
+	public Set<DataObject> listObjects(DataStore store) {
+		// TODO Auto-generated method stub
+		return null;
+	}
 
-        if (s_logger.isDebugEnabled()) {
-            s_logger.debug("Unable to create volume " + volume.getId());
-        }
-        return false;
-    }
-
-    @Override
-    public void createAsync(DataObject data,
-            AsyncCompletionCallback<CreateCmdResult> callback) {
-        // TODO Auto-generated method stub
-        String errMsg = null;
-        if (data.getType() == DataObjectType.VOLUME) {
-            try {
-                createVolume((VolumeInfo)data);
-            } catch (StorageUnavailableException e) {
-                s_logger.debug("failed to create volume", e);
-                errMsg = e.toString();
-            } catch (Exception e) {
-                s_logger.debug("failed to create volume", e);
-                errMsg = e.toString();
-            }
-        }
-        CreateCmdResult result = new CreateCmdResult(null, null);
-        if (errMsg != null) {
-            result.setResult(errMsg);
-        }
-        
-        callback.complete(result);
+	public boolean createVolume(
+			VolumeInfo volume) throws StorageUnavailableException {
+		if (s_logger.isDebugEnabled()) {
+			s_logger.debug("Creating volume: " + volume);
+		}
+
+		DiskOfferingVO offering = diskOfferingDao.findById(volume.getDiskOfferingId());
+		DiskProfile diskProfile = new DiskProfile(volume, offering,
+				null);
+
+		VMTemplateVO template = null;
+		if (volume.getTemplateId() != null) {
+			template = templateDao.findById(volume.getTemplateId());
+		}
+
+		StoragePool pool = (StoragePool)volume.getDataStore();
+		VolumeVO vol = volumeDao.findById(volume.getId());
+		if (pool != null) {
+			if (s_logger.isDebugEnabled()) {
+				s_logger.debug("Trying to create in " + pool);
+			}
+			vol.setPoolId(pool.getId());
+
+			CreateCommand cmd = null;
+			VMTemplateStoragePoolVO tmpltStoredOn = null;
+
+			for (int i = 0; i < 2; i++) {
+				if (template != null
+						&& template.getFormat() != Storage.ImageFormat.ISO) {
+					if (pool.getPoolType() == StoragePoolType.CLVM) {
+						// prepareISOForCreate does what we need, which is to
+						// tell us where the template is
+						VMTemplateHostVO tmpltHostOn = templateMgr
+								.prepareISOForCreate(template, pool);
+						if (tmpltHostOn == null) {
+							s_logger.debug("cannot find template "
+									+ template.getId() + " "
+									+ template.getName());
+							throw new CloudRuntimeException("cannot find template"
+									+ template.getId() 
+									+ template.getName());
+						}
+						HostVO secondaryStorageHost = hostDao
+								.findById(tmpltHostOn.getHostId());
+						String tmpltHostUrl = secondaryStorageHost
+								.getStorageUrl();
+						String fullTmpltUrl = tmpltHostUrl + "/"
+								+ tmpltHostOn.getInstallPath();
+						cmd = new CreateCommand(diskProfile, fullTmpltUrl,
+								new StorageFilerTO(pool));
+					} else {
+						tmpltStoredOn = templateMgr.prepareTemplateForCreate(
+								template, pool);
+						if (tmpltStoredOn == null) {
+							s_logger.debug("Cannot use this pool " + pool
+									+ " because we can't propagate template "
+									+ template);
+							throw new CloudRuntimeException("Cannot use this pool " + pool
+									+ " because we can't propagate template "
+									+ template);
+						}
+						cmd = new CreateCommand(diskProfile,
+								tmpltStoredOn.getLocalDownloadPath(),
+								new StorageFilerTO(pool));
+					}
+				} else {
+					if (template != null
+							&& Storage.ImageFormat.ISO == template.getFormat()) {
+						VMTemplateHostVO tmpltHostOn = templateMgr
+								.prepareISOForCreate(template, pool);
+						if (tmpltHostOn == null) {
+							throw new CloudRuntimeException(
+									"Did not find ISO in secondry storage in zone "
+											+ pool.getDataCenterId());
+						}
+					}
+					cmd = new CreateCommand(diskProfile, new StorageFilerTO(
+							pool));
+				}
+
+				Answer answer = storageMgr.sendToPool(pool, null, cmd);
+				if (answer.getResult()) {
+					CreateAnswer createAnswer = (CreateAnswer) answer;
+					vol.setFolder(pool.getPath());
+					vol.setPath(createAnswer.getVolume().getPath());
+					vol.setSize(createAnswer.getVolume().getSize());
+					vol.setPoolType(pool.getPoolType());
+					vol.setPoolId(pool.getId());
+					vol.setPodId(pool.getPodId());
+					this.volumeDao.update(vol.getId(), vol);
+					return true;
+				} else {
+					if (tmpltStoredOn != null
+							&& (answer instanceof CreateAnswer)
+							&& ((CreateAnswer) answer)
+							.templateReloadRequested()) {
+						if (!templateMgr
+								.resetTemplateDownloadStateOnPool(tmpltStoredOn
+										.getId())) {
+							break; // break out of template-redeploy retry loop
+						}
+					} else {
+						break;
+					}
+				}
+			}
+		}
+
+		if (s_logger.isDebugEnabled()) {
+			s_logger.debug("Unable to create volume " + volume.getId());
+		}
+		return false;
+	}
+
+	@Override
+	public void createAsync(DataObject data,
+			AsyncCompletionCallback<CreateCmdResult> callback) {
+		// TODO Auto-generated method stub
+		String errMsg = null;
+		if (data.getType() == DataObjectType.VOLUME) {
+			try {
+				createVolume((VolumeInfo)data);
+			} catch (StorageUnavailableException e) {
+				s_logger.debug("failed to create volume", e);
+				errMsg = e.toString();
+			} catch (Exception e) {
+				s_logger.debug("failed to create volume", e);
+				errMsg = e.toString();
+			}
+		}
+		CreateCmdResult result = new CreateCmdResult(null, null);
+		if (errMsg != null) {
+			result.setResult(errMsg);
+		}
+
+		callback.complete(result);
+
+	}
+
+	@Override
+	public void deleteAsync(DataObject data,
+			AsyncCompletionCallback<CommandResult> callback) {
+
+		String vmName = null;
+		VolumeVO vol = this.volumeDao.findById(data.getId());
+
+
+		StoragePool pool = (StoragePool)data.getDataStore();
+
+		DestroyCommand cmd = new DestroyCommand(pool, vol, vmName);
+
+		CommandResult result = new CommandResult();
+		try {
+			Answer answer = this.storageMgr.sendToPool(pool, cmd);
+			if (answer != null && !answer.getResult()) {
+				result.setResult(answer.getDetails());
+				s_logger.info("Will retry delete of " + vol + " from " + pool.getId());
+			}
+		} catch (StorageUnavailableException e) {
+			s_logger.error("Storage is unavailable currently.  Will retry delete of "
+					+ vol + " from " + pool.getId(), e);
+			result.setResult(e.toString());
+		} catch (Exception ex) {
+			s_logger.debug("Unable to destoy volume" + vol + " from " + pool.getId(), ex);
+			result.setResult(ex.toString());
+		}
+		callback.complete(result);
+	}
+
+	@Override
+	public void copyAsync(DataObject srcdata, DataObject destData,
+			AsyncCompletionCallback<CopyCommandResult> callback) {
+		// TODO Auto-generated method stub
+
+	}
+
+	@Override
+	public boolean canCopy(DataObject srcData, DataObject destData) {
+		// TODO Auto-generated method stub
+		return false;
+	}
+
+	@Override
+	public void takeSnapshot(SnapshotInfo snapshot,
+			AsyncCompletionCallback<CreateCmdResult> callback) {
+		VolumeInfo volume = snapshot.getBaseVolume();
+        String vmName = this.volumeMgr.getVmNameOnVolume(volume);
+        SnapshotVO preSnapshotVO = this.snapshotMgr.getParentSnapshot(volume, snapshot);
+        StoragePool srcPool = (StoragePool)volume.getDataStore();
+
+        ManageSnapshotCommand cmd = new ManageSnapshotCommand(snapshot.getId(), volume.getPath(), srcPool, preSnapshotVO.getPath(), snapshot.getName(), vmName);
+      
+        ManageSnapshotAnswer answer = (ManageSnapshotAnswer) this.snapshotMgr.sendToPool(volume, cmd);
         
-    }
-
-    @Override
-    public void deleteAsync(DataObject data,
-            AsyncCompletionCallback<CommandResult> callback) {
-
-        String vmName = null;
-        VolumeVO vol = this.volumeDao.findById(data.getId());
-
-
-        StoragePool pool = (StoragePool)data.getDataStore();
-
-        DestroyCommand cmd = new DestroyCommand(pool, vol, vmName);
-
-        CommandResult result = new CommandResult();
-        try {
-            Answer answer = this.storageMgr.sendToPool(pool, cmd);
-            if (answer != null && !answer.getResult()) {
-                result.setResult(answer.getDetails());
-                s_logger.info("Will retry delete of " + vol + " from " + pool.getId());
-            }
-        } catch (StorageUnavailableException e) {
-            s_logger.error("Storage is unavailable currently.  Will retry delete of "
-                        + vol + " from " + pool.getId(), e);
-            result.setResult(e.toString());
-        } catch (Exception ex) {
-            s_logger.debug("Unable to destoy volume" + vol + " from " + pool.getId(), ex);
-            result.setResult(ex.toString());
+        CreateCmdResult result = null;
+        if ((answer != null) && answer.getResult()) {
+        	result = new CreateCmdResult(answer.getSnapshotPath(), null);
+        } else {
+        	result = new CreateCmdResult(null, null);
         }
+        
         callback.complete(result);
-    }
+	}
 
-    @Override
-    public void copyAsync(DataObject srcdata, DataObject destData,
-            AsyncCompletionCallback<CopyCommandResult> callback) {
-        // TODO Auto-generated method stub
+	@Override
+	public void revertSnapshot(SnapshotInfo snapshot,
+			AsyncCompletionCallback<CommandResult> callback) {
+		// TODO Auto-generated method stub
 
-    }
+	}
 
-    @Override
-    public boolean canCopy(DataObject srcData, DataObject destData) {
-        // TODO Auto-generated method stub
-        return false;
-    }
+	@Override
+	public void resize(DataObject data,
+			AsyncCompletionCallback<CreateCmdResult> callback) {
+		VolumeObject vol = (VolumeObject)data;
+		StoragePool pool = (StoragePool)data.getDataStore();
+		ResizeVolumePayload resizeParameter = (ResizeVolumePayload)vol.getpayload();
 
-    @Override
-    public void takeSnapshot(SnapshotInfo snapshot,
-            AsyncCompletionCallback<CommandResult> callback) {
-        // TODO Auto-generated method stub
-        
-    }
+		ResizeVolumeCommand resizeCmd = new ResizeVolumeCommand(
+				vol.getPath(), new StorageFilerTO(pool), vol.getSize(),
+				resizeParameter.newSize, resizeParameter.shrinkOk, resizeParameter.instanceName);
+		CreateCmdResult result = new CreateCmdResult(null, null);
+		try {
+			ResizeVolumeAnswer answer = (ResizeVolumeAnswer) this.storageMgr.sendToPool(pool,
+					resizeParameter.hosts, resizeCmd);
+			if (answer != null && answer.getResult()) {
+				long finalSize = answer.getNewSize();
+				s_logger.debug("Resize: volume started at size " + vol.getSize()
+						+ " and ended at size " + finalSize);
 
-    @Override
-    public void revertSnapshot(SnapshotInfo snapshot,
-            AsyncCompletionCallback<CommandResult> callback) {
-        // TODO Auto-generated method stub
-        
-    }
+				vol.setSize(finalSize);
+				vol.update();
+			} else if (answer != null) {
+				result.setResult(answer.getDetails());
+			} else {
+				s_logger.debug("return a null answer, mark it as failed for unknown reason");
+				result.setResult("return a null answer, mark it as failed for unknown reason");
+			}
+
+		} catch (Exception e) {
+			s_logger.debug("sending resize command failed", e);
+			result.setResult(e.toString());
+		}
+
+		callback.complete(result);
+	}
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/ff047e75/engine/storage/volume/src/org/apache/cloudstack/storage/datastore/driver/DefaultPrimaryDataStoreDriverImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/volume/src/org/apache/cloudstack/storage/datastore/driver/DefaultPrimaryDataStoreDriverImpl.java b/engine/storage/volume/src/org/apache/cloudstack/storage/datastore/driver/DefaultPrimaryDataStoreDriverImpl.java
index efd04d1..6d0c2c6 100644
--- a/engine/storage/volume/src/org/apache/cloudstack/storage/datastore/driver/DefaultPrimaryDataStoreDriverImpl.java
+++ b/engine/storage/volume/src/org/apache/cloudstack/storage/datastore/driver/DefaultPrimaryDataStoreDriverImpl.java
@@ -27,6 +27,7 @@ import org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult;
 import org.apache.cloudstack.engine.subsystem.api.storage.DataObject;
 import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
 import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
+import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreDriver;
 import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo;
 import org.apache.cloudstack.framework.async.AsyncCallbackDispatcher;
 import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
@@ -36,7 +37,6 @@ import org.apache.cloudstack.storage.command.CreateObjectCommand;
 import org.apache.cloudstack.storage.command.DeleteCommand;
 import org.apache.cloudstack.storage.datastore.DataObjectManager;
 import org.apache.cloudstack.storage.endpoint.EndPointSelector;
-import org.apache.cloudstack.storage.volume.PrimaryDataStoreDriver;
 import org.apache.log4j.Logger;
 
 import com.cloud.agent.api.Answer;
@@ -211,13 +211,6 @@ public class DefaultPrimaryDataStoreDriverImpl implements PrimaryDataStoreDriver
     }
 
     @Override
-    public void takeSnapshot(SnapshotInfo snapshot,
-            AsyncCompletionCallback<CommandResult> callback) {
-        // TODO Auto-generated method stub
-        
-    }
-
-    @Override
     public void revertSnapshot(SnapshotInfo snapshot,
             AsyncCompletionCallback<CommandResult> callback) {
         // TODO Auto-generated method stub
@@ -238,5 +231,19 @@ public class DefaultPrimaryDataStoreDriverImpl implements PrimaryDataStoreDriver
         // TODO Auto-generated method stub
         
     }
+
+	@Override
+	public void resize(DataObject data,
+			AsyncCompletionCallback<CreateCmdResult> callback) {
+		// TODO Auto-generated method stub
+		
+	}
+
+	@Override
+	public void takeSnapshot(SnapshotInfo snapshot,
+			AsyncCompletionCallback<CreateCmdResult> callback) {
+		// TODO Auto-generated method stub
+		
+	}
    
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/ff047e75/engine/storage/volume/src/org/apache/cloudstack/storage/datastore/manager/DefaultPrimaryDataStoreProviderManagerImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/volume/src/org/apache/cloudstack/storage/datastore/manager/DefaultPrimaryDataStoreProviderManagerImpl.java b/engine/storage/volume/src/org/apache/cloudstack/storage/datastore/manager/DefaultPrimaryDataStoreProviderManagerImpl.java
index fdbe4b4..f395061 100644
--- a/engine/storage/volume/src/org/apache/cloudstack/storage/datastore/manager/DefaultPrimaryDataStoreProviderManagerImpl.java
+++ b/engine/storage/volume/src/org/apache/cloudstack/storage/datastore/manager/DefaultPrimaryDataStoreProviderManagerImpl.java
@@ -27,13 +27,13 @@ import javax.inject.Inject;
 import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider;
 import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProviderManager;
 import org.apache.cloudstack.engine.subsystem.api.storage.HypervisorHostListener;
+import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreDriver;
 import org.apache.cloudstack.storage.datastore.DefaultPrimaryDataStore;
 import org.apache.cloudstack.storage.datastore.PrimaryDataStore;
 import org.apache.cloudstack.storage.datastore.PrimaryDataStoreProviderManager;
 import org.apache.cloudstack.storage.datastore.db.DataStoreProviderDao;
 import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
 import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
-import org.apache.cloudstack.storage.volume.PrimaryDataStoreDriver;
 import org.springframework.stereotype.Component;
 
 @Component

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/ff047e75/engine/storage/volume/src/org/apache/cloudstack/storage/datastore/provider/AncientPrimaryDataStoreProviderImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/volume/src/org/apache/cloudstack/storage/datastore/provider/AncientPrimaryDataStoreProviderImpl.java b/engine/storage/volume/src/org/apache/cloudstack/storage/datastore/provider/AncientPrimaryDataStoreProviderImpl.java
index 702ab23..0ef1704 100644
--- a/engine/storage/volume/src/org/apache/cloudstack/storage/datastore/provider/AncientPrimaryDataStoreProviderImpl.java
+++ b/engine/storage/volume/src/org/apache/cloudstack/storage/datastore/provider/AncientPrimaryDataStoreProviderImpl.java
@@ -23,10 +23,10 @@ import java.util.Map;
 import javax.inject.Inject;
 
 import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreLifeCycle;
+import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreDriver;
 import org.apache.cloudstack.storage.datastore.PrimaryDataStoreProviderManager;
 import org.apache.cloudstack.storage.datastore.driver.AncientPrimaryDataStoreDriverImpl;
 import org.apache.cloudstack.storage.datastore.lifecycle.AncientPrimaryDataStoreLifeCyclImpl;
-import org.apache.cloudstack.storage.volume.PrimaryDataStoreDriver;
 import org.springframework.stereotype.Component;
 
 import com.cloud.utils.component.ComponentContext;

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/ff047e75/engine/storage/volume/src/org/apache/cloudstack/storage/datastore/provider/DefaultPrimaryDatastoreProviderImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/volume/src/org/apache/cloudstack/storage/datastore/provider/DefaultPrimaryDatastoreProviderImpl.java b/engine/storage/volume/src/org/apache/cloudstack/storage/datastore/provider/DefaultPrimaryDatastoreProviderImpl.java
index 85a5d02..a1402c1 100644
--- a/engine/storage/volume/src/org/apache/cloudstack/storage/datastore/provider/DefaultPrimaryDatastoreProviderImpl.java
+++ b/engine/storage/volume/src/org/apache/cloudstack/storage/datastore/provider/DefaultPrimaryDatastoreProviderImpl.java
@@ -22,10 +22,10 @@ import javax.inject.Inject;
 
 import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreLifeCycle;
 import org.apache.cloudstack.engine.subsystem.api.storage.HypervisorHostListener;
+import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreDriver;
 import org.apache.cloudstack.storage.datastore.PrimaryDataStoreProviderManager;
 import org.apache.cloudstack.storage.datastore.driver.DefaultPrimaryDataStoreDriverImpl;
 import org.apache.cloudstack.storage.datastore.lifecycle.DefaultPrimaryDataStoreLifeCycleImpl;
-import org.apache.cloudstack.storage.volume.PrimaryDataStoreDriver;
 import org.springframework.stereotype.Component;
 
 import com.cloud.utils.component.ComponentContext;

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/ff047e75/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeObject.java
----------------------------------------------------------------------
diff --git a/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeObject.java b/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeObject.java
index 87951ce..6ad6cc9 100644
--- a/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeObject.java
+++ b/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeObject.java
@@ -30,6 +30,7 @@ import org.apache.cloudstack.engine.subsystem.api.storage.disktype.DiskFormat;
 import org.apache.cloudstack.storage.datastore.ObjectInDataStoreManager;
 import org.apache.log4j.Logger;
 
+import com.cloud.hypervisor.Hypervisor.HypervisorType;
 import com.cloud.storage.Volume;
 import com.cloud.storage.VolumeVO;
 import com.cloud.storage.dao.VolumeDao;
@@ -73,6 +74,10 @@ public class VolumeObject implements VolumeInfo {
     public void setPath(String uuid) {
         volumeVO.setPath(uuid);
     }
+    
+    public void setSize(Long size) {
+    	volumeVO.setSize(size);
+    }
 
     public Volume.State getState() {
         return volumeVO.getState();
@@ -182,6 +187,8 @@ public class VolumeObject implements VolumeInfo {
                 volEvent = Volume.Event.OperationSucceeded;
             } else if (event == ObjectInDataStoreStateMachine.Event.OperationFailed) {
                 volEvent = Volume.Event.OperationFailed;
+            } else if (event == ObjectInDataStoreStateMachine.Event.ResizeRequested) {
+            	volEvent = Volume.Event.ResizeRequested;
             }
             this.stateTransit(volEvent);
         } catch (Exception e) {
@@ -310,4 +317,14 @@ public class VolumeObject implements VolumeInfo {
     public Object getpayload() {
        return this.payload;
     }
+
+	@Override
+	public HypervisorType getHypervisorType() {
+		return this.volumeDao.getHypervisorType(this.volumeVO.getId());
+	}
+
+	@Override
+	public Long getLastPoolId() {
+		return this.volumeVO.getLastPoolId();
+	}
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/ff047e75/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java b/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java
index ef99a49..c019374 100644
--- a/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java
+++ b/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java
@@ -56,9 +56,6 @@ import com.cloud.utils.exception.CloudRuntimeException;
 import com.cloud.vm.VirtualMachine;
 import com.cloud.vm.dao.VMInstanceDao;
 
-//1. change volume state
-//2. orchestrator of volume, control most of the information of volume, storage pool id, voluem state, scope etc.
-
 @Component
 public class VolumeServiceImpl implements VolumeService {
     private static final Logger s_logger = Logger
@@ -423,8 +420,49 @@ public class VolumeServiceImpl implements VolumeService {
     public AsyncCallFuture<VolumeApiResult> createVolumeFromSnapshot(
             VolumeInfo volume, DataStore store, SnapshotInfo snapshot) {
         AsyncCallFuture<VolumeApiResult> future = new AsyncCallFuture<VolumeApiResult>();
-        VolumeApiResult result = new VolumeApiResult(volume);
-        return null;
+        
+        try {
+        	DataObject volumeOnStore = store.create(volume);
+        	volume.processEvent(Event.CreateOnlyRequested);
+        	 CreateVolumeFromBaseImageContext<VolumeApiResult> context = new CreateVolumeFromBaseImageContext<VolumeApiResult>(null, 
+        			 (VolumeObject)volume, store, volumeOnStore, future);
+             AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> caller =  AsyncCallbackDispatcher.create(this);
+             caller.setCallback(caller.getTarget().createVolumeFromSnapshotCallback(null, null))
+             .setContext(context);
+        	this.motionSrv.copyAsync(snapshot, volumeOnStore, caller);
+        } catch (Exception e) {
+        	s_logger.debug("create volume from snapshot failed", e);
+        	VolumeApiResult result = new VolumeApiResult(volume);
+        	result.setResult(e.toString());
+        	future.complete(result);
+        }
+        
+        return future;
+    }
+    
+    protected Void createVolumeFromSnapshotCallback(AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> callback, 
+    		CreateVolumeFromBaseImageContext<VolumeApiResult> context) {
+    	CopyCommandResult result = callback.getResult();
+    	VolumeInfo volume = context.vo;
+    	VolumeApiResult apiResult = new VolumeApiResult(volume);
+    	Event event = null;
+    	if (result.isFailed()) {
+    		apiResult.setResult(result.getResult());
+    		event = Event.OperationFailed;
+    	} else {
+    		event = Event.OperationSuccessed;
+    	}
+    	
+    	try {
+    		volume.processEvent(event);
+    	} catch (Exception e) {
+    		s_logger.debug("create volume from snapshot failed", e);
+    		apiResult.setResult(e.toString());
+    	}
+    	
+    	AsyncCallFuture<VolumeApiResult> future = context.future;
+    	future.complete(apiResult);
+    	return null;
     }
     
     protected VolumeVO duplicateVolumeOnAnotherStorage(Volume volume, StoragePool pool) {
@@ -552,5 +590,61 @@ public class VolumeServiceImpl implements VolumeService {
         context.future.complete(res);
         return null;
     }
+    
+
+	@Override
+	public AsyncCallFuture<VolumeApiResult> resize(VolumeInfo volume) {
+		AsyncCallFuture<VolumeApiResult> future = new AsyncCallFuture<VolumeApiResult>();
+		VolumeApiResult result = new VolumeApiResult(volume);
+		try {
+			volume.processEvent(Event.ResizeRequested);
+		} catch (Exception e) {
+			s_logger.debug("Failed to change state to resize", e);
+			result.setResult(e.toString());
+			future.complete(result);
+			return future;
+		}
+		 CreateVolumeContext<VolumeApiResult> context = new CreateVolumeContext<VolumeApiResult>(null, volume, future);
+	        AsyncCallbackDispatcher<VolumeServiceImpl, CreateCmdResult> caller = AsyncCallbackDispatcher.create(this);
+	        caller.setCallback(caller.getTarget().registerVolumeCallback(null, null))
+	        .setContext(context);
+		volume.getDataStore().getDriver().resize(volume, caller);
+		return future;
+	}
+	
+	protected Void resizeVolumeCallback(AsyncCallbackDispatcher<VolumeServiceImpl, CreateCmdResult> callback, CreateVolumeContext<VolumeApiResult> context) {
+		CreateCmdResult result = callback.getResult();
+		AsyncCallFuture<VolumeApiResult> future  = context.future;
+		VolumeInfo volume = (VolumeInfo)context.volume;
+		
+		if (result.isFailed()) {
+			try {
+				volume.processEvent(Event.OperationFailed);
+			} catch (Exception e) {
+				s_logger.debug("Failed to change state", e);
+			}
+			VolumeApiResult res = new VolumeApiResult(volume);
+			res.setResult(result.getResult());
+			future.complete(res);
+			return null;
+		}
+		
+		try {
+			volume.processEvent(Event.OperationSuccessed);
+		} catch(Exception e) {
+			s_logger.debug("Failed to change state", e);
+			VolumeApiResult res = new VolumeApiResult(volume);
+			res.setResult(result.getResult());
+			future.complete(res);
+			return null;
+		}
+		
+		VolumeApiResult res = new VolumeApiResult(volume);
+		future.complete(res);
+		
+		return null;
+	}
+	
+	
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/ff047e75/plugins/storage/volume/solidfire/src/org/apache/cloudstack/storage/datastore/driver/SolidfirePrimaryDataStoreDriver.java
----------------------------------------------------------------------
diff --git a/plugins/storage/volume/solidfire/src/org/apache/cloudstack/storage/datastore/driver/SolidfirePrimaryDataStoreDriver.java b/plugins/storage/volume/solidfire/src/org/apache/cloudstack/storage/datastore/driver/SolidfirePrimaryDataStoreDriver.java
index 88c5374..f31126c 100644
--- a/plugins/storage/volume/solidfire/src/org/apache/cloudstack/storage/datastore/driver/SolidfirePrimaryDataStoreDriver.java
+++ b/plugins/storage/volume/solidfire/src/org/apache/cloudstack/storage/datastore/driver/SolidfirePrimaryDataStoreDriver.java
@@ -24,9 +24,9 @@ import org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult;
 import org.apache.cloudstack.engine.subsystem.api.storage.DataObject;
 import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
 import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
+import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreDriver;
 import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo;
 import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
-import org.apache.cloudstack.storage.volume.PrimaryDataStoreDriver;
 
 public class SolidfirePrimaryDataStoreDriver implements PrimaryDataStoreDriver {
 
@@ -73,16 +73,24 @@ public class SolidfirePrimaryDataStoreDriver implements PrimaryDataStoreDriver {
     }
 
     @Override
-    public void takeSnapshot(SnapshotInfo snapshot, AsyncCompletionCallback<CommandResult> callback) {
-        // TODO Auto-generated method stub
-        
-    }
-
-    @Override
     public void revertSnapshot(SnapshotInfo snapshot, AsyncCompletionCallback<CommandResult> callback) {
         // TODO Auto-generated method stub
         
     }
 
+	@Override
+	public void resize(DataObject data,
+			AsyncCompletionCallback<CreateCmdResult> callback) {
+		// TODO Auto-generated method stub
+		
+	}
+
+	@Override
+	public void takeSnapshot(SnapshotInfo snapshot,
+			AsyncCompletionCallback<CreateCmdResult> callback) {
+		// TODO Auto-generated method stub
+		
+	}
+
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/ff047e75/server/src/com/cloud/api/ApiDBUtils.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/ApiDBUtils.java b/server/src/com/cloud/api/ApiDBUtils.java
index 0a20352..c28daef 100755
--- a/server/src/com/cloud/api/ApiDBUtils.java
+++ b/server/src/com/cloud/api/ApiDBUtils.java
@@ -618,7 +618,7 @@ public class ApiDBUtils {
 
     public static String getSnapshotIntervalTypes(long snapshotId) {
         SnapshotVO snapshot = _snapshotDao.findById(snapshotId);
-        return snapshot.getType().name();
+        return snapshot.getRecurringType().name();
     }
 
     public static String getStoragePoolTags(long poolId) {

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/ff047e75/server/src/com/cloud/api/ApiResponseHelper.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/ApiResponseHelper.java b/server/src/com/cloud/api/ApiResponseHelper.java
index 3da3168..845b242 100755
--- a/server/src/com/cloud/api/ApiResponseHelper.java
+++ b/server/src/com/cloud/api/ApiResponseHelper.java
@@ -341,7 +341,7 @@ public class ApiResponseHelper implements ResponseGenerator {
         populateOwner(snapshotResponse, snapshot);
 
         VolumeVO volume = findVolumeById(snapshot.getVolumeId());
-        String snapshotTypeStr = snapshot.getType().name();
+        String snapshotTypeStr = snapshot.getRecurringType().name();
         snapshotResponse.setSnapshotType(snapshotTypeStr);
         if (volume != null) {
             snapshotResponse.setVolumeId(volume.getUuid());

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/ff047e75/server/src/com/cloud/configuration/Config.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/configuration/Config.java b/server/src/com/cloud/configuration/Config.java
index c0c23b6..8c77715 100755
--- a/server/src/com/cloud/configuration/Config.java
+++ b/server/src/com/cloud/configuration/Config.java
@@ -137,7 +137,8 @@ public enum Config {
     SnapshotMonthlyMax("Snapshots", SnapshotManager.class, Integer.class, "snapshot.max.monthly", "8", "Maximum monthly snapshots for a volume", null),
     SnapshotPollInterval("Snapshots", SnapshotManager.class, Integer.class, "snapshot.poll.interval", "300", "The time interval in seconds when the management server polls for snapshots to be scheduled.", null),
     SnapshotDeltaMax("Snapshots", SnapshotManager.class, Integer.class, "snapshot.delta.max", "16", "max delta snapshots between two full snapshots.", null),
-
+    BackupSnapshotAferTakingSnapshot("Snapshots", SnapshotManager.class, Boolean.class, "snapshot.backup.rightafter", "true", "backup snapshot right after snapshot is taken", null),
+    
 	// Advanced
     JobExpireMinutes("Advanced", ManagementServer.class, String.class, "job.expire.minutes", "1440", "Time (in minutes) for async-jobs to be kept in system", null),
     JobCancelThresholdMinutes("Advanced", ManagementServer.class, String.class, "job.cancel.threshold.minutes", "60", "Time (in minutes) for async-jobs to be forcely cancelled if it has been in process for long", null),

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/ff047e75/server/src/com/cloud/storage/ResizeVolumePayload.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/ResizeVolumePayload.java b/server/src/com/cloud/storage/ResizeVolumePayload.java
new file mode 100644
index 0000000..472d627
--- /dev/null
+++ b/server/src/com/cloud/storage/ResizeVolumePayload.java
@@ -0,0 +1,14 @@
+package com.cloud.storage;
+
+public class ResizeVolumePayload {
+	public final Long newSize;
+	public final boolean shrinkOk;
+	public final String instanceName;
+	public final long[] hosts;
+	public ResizeVolumePayload(Long newSize, boolean shrinkOk, String instanceName, long[] hosts) {
+		this.newSize = newSize;
+		this.shrinkOk = shrinkOk;
+		this.instanceName = instanceName;
+		this.hosts = hosts;
+	}
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/ff047e75/server/src/com/cloud/storage/VolumeManager.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/VolumeManager.java b/server/src/com/cloud/storage/VolumeManager.java
index ebb9e54..af3cbbf 100644
--- a/server/src/com/cloud/storage/VolumeManager.java
+++ b/server/src/com/cloud/storage/VolumeManager.java
@@ -52,9 +52,9 @@ public interface VolumeManager extends VolumeApiService {
 
     boolean volumeOnSharedStoragePool(VolumeVO volume);
 
-    boolean volumeInactive(VolumeVO volume);
+    boolean volumeInactive(Volume volume);
 
-    String getVmNameOnVolume(VolumeVO volume);
+    String getVmNameOnVolume(Volume volume);
 
     VolumeVO allocVolume(CreateVolumeCmd cmd)
             throws ResourceAllocationException;

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/ff047e75/server/src/com/cloud/storage/VolumeManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/VolumeManagerImpl.java b/server/src/com/cloud/storage/VolumeManagerImpl.java
index 573b8e9..a69607f 100644
--- a/server/src/com/cloud/storage/VolumeManagerImpl.java
+++ b/server/src/com/cloud/storage/VolumeManagerImpl.java
@@ -66,12 +66,6 @@ import com.cloud.agent.AgentManager;
 import com.cloud.agent.api.Answer;
 import com.cloud.agent.api.AttachVolumeAnswer;
 import com.cloud.agent.api.AttachVolumeCommand;
-import com.cloud.agent.api.storage.CopyVolumeAnswer;
-import com.cloud.agent.api.storage.CopyVolumeCommand;
-import com.cloud.agent.api.storage.DestroyCommand;
-import com.cloud.agent.api.storage.ResizeVolumeAnswer;
-import com.cloud.agent.api.storage.ResizeVolumeCommand;
-import com.cloud.agent.api.to.StorageFilerTO;
 import com.cloud.agent.api.to.VolumeTO;
 import com.cloud.alert.AlertManager;
 import com.cloud.api.ApiDBUtils;
@@ -763,7 +757,7 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager {
     }
 
     @Override
-    public boolean volumeInactive(VolumeVO volume) {
+    public boolean volumeInactive(Volume volume) {
         Long vmId = volume.getInstanceId();
         if (vmId != null) {
             UserVm vm = _userVmDao.findById(vmId);
@@ -779,7 +773,7 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager {
     }
 
     @Override
-    public String getVmNameOnVolume(VolumeVO volume) {
+    public String getVmNameOnVolume(Volume volume) {
         Long vmId = volume.getInstanceId();
         if (vmId != null) {
             VMInstanceVO vm = _vmInstanceDao.findById(vmId);
@@ -1013,7 +1007,6 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager {
     public VolumeVO resizeVolume(ResizeVolumeCmd cmd) {
         Long newSize = null;
         boolean shrinkOk = cmd.getShrinkOk();
-        boolean success = false;
         
         VolumeVO volume = _volsDao.findById(cmd.getEntityId());
         if (volume == null) {
@@ -1170,64 +1163,31 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager {
                         "VM must be stopped or disk detached in order to resize with the Xen HV");
             }
         }
-
+        
+        ResizeVolumePayload payload = new ResizeVolumePayload(newSize, shrinkOk, instanceName, hosts);
+        
         try {
-            try {
-                stateTransitTo(volume, Volume.Event.ResizeRequested);
-            } catch (NoTransitionException etrans) {
-                throw new CloudRuntimeException(
-                        "Unable to change volume state for resize: "
-                                + etrans.toString());
-            }
-
-            ResizeVolumeCommand resizeCmd = new ResizeVolumeCommand(
-                    volume.getPath(), new StorageFilerTO(pool), currentSize,
-                    newSize, shrinkOk, instanceName);
-            ResizeVolumeAnswer answer = (ResizeVolumeAnswer) this.storageMgr.sendToPool(pool,
-                    hosts, resizeCmd);
-
-            /*
-             * need to fetch/store new volume size in database. This value comes
-             * from hypervisor rather than trusting that a success means we have
-             * a volume of the size we requested
-             */
-            if (answer != null && answer.getResult()) {
-                long finalSize = answer.getNewSize();
-                s_logger.debug("Resize: volume started at size " + currentSize
-                        + " and ended at size " + finalSize);
-                volume.setSize(finalSize);
-                if (newDiskOffering != null) {
-                    volume.setDiskOfferingId(cmd.getNewDiskOfferingId());
-                }
-                _volsDao.update(volume.getId(), volume);
-
-                success = true;
-                return volume;
-            } else if (answer != null) {
-                s_logger.debug("Resize: returned '" + answer.getDetails() + "'");
-            }
-        } catch (StorageUnavailableException e) {
-            s_logger.debug("volume failed to resize: " + e);
-            return null;
-        } finally {
-            if (success) {
-                try {
-                    stateTransitTo(volume, Volume.Event.OperationSucceeded);
-                } catch (NoTransitionException etrans) {
-                    throw new CloudRuntimeException(
-                            "Failed to change volume state: "
-                                    + etrans.toString());
-                }
-            } else {
-                try {
-                    stateTransitTo(volume, Volume.Event.OperationFailed);
-                } catch (NoTransitionException etrans) {
-                    throw new CloudRuntimeException(
-                            "Failed to change volume state: "
-                                    + etrans.toString());
-                }
-            }
-        }
+        	VolumeInfo vol = this.volFactory.getVolume(volume.getId());
+            vol.addPayload(payload);
+            
+        	AsyncCallFuture<VolumeApiResult> future = this.volService.resize(vol);
+        	future.get();
+        	volume = _volsDao.findById(volume.getId());
+
+        	if (newDiskOffering != null) {
+        		volume.setDiskOfferingId(cmd.getNewDiskOfferingId());
+        	}
+        	_volsDao.update(volume.getId(), volume);
+
+        	return volume;
+		} catch (InterruptedException e) {
+			s_logger.debug("failed get resize volume result", e);
+		} catch (ExecutionException e) {
+			s_logger.debug("failed get resize volume result", e);
+		} catch (Exception e) {
+			s_logger.debug("failed get resize volume result", e);
+		}
+       
         return null;
     }
     

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/ff047e75/server/src/com/cloud/storage/dao/SnapshotDao.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/dao/SnapshotDao.java b/server/src/com/cloud/storage/dao/SnapshotDao.java
index 3b961f6..0e378a7 100644
--- a/server/src/com/cloud/storage/dao/SnapshotDao.java
+++ b/server/src/com/cloud/storage/dao/SnapshotDao.java
@@ -25,7 +25,7 @@ import com.cloud.utils.fsm.StateDao;
 
 import java.util.List;
 
-public interface SnapshotDao extends GenericDao<SnapshotVO, Long>, StateDao<Snapshot.State, Snapshot.Event, Snapshot> {
+public interface SnapshotDao extends GenericDao<SnapshotVO, Long>, StateDao<Snapshot.State, Snapshot.Event, SnapshotVO> {
 	List<SnapshotVO> listByVolumeId(long volumeId);
 	List<SnapshotVO> listByVolumeId(Filter filter, long volumeId);
 	SnapshotVO findNextSnapshot(long parentSnapId);

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/ff047e75/server/src/com/cloud/storage/dao/SnapshotDaoImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/dao/SnapshotDaoImpl.java b/server/src/com/cloud/storage/dao/SnapshotDaoImpl.java
index a8a07dc..5b3f273 100644
--- a/server/src/com/cloud/storage/dao/SnapshotDaoImpl.java
+++ b/server/src/com/cloud/storage/dao/SnapshotDaoImpl.java
@@ -324,7 +324,7 @@ public class SnapshotDaoImpl extends GenericDaoBase<SnapshotVO, Long> implements
     }
 
     @Override
-    public boolean updateState(State currentState, Event event, State nextState, Snapshot snapshot, Object data) {
+    public boolean updateState(State currentState, Event event, State nextState, SnapshotVO snapshot, Object data) {
         Transaction txn = Transaction.currentTxn();
         txn.start();
         SnapshotVO snapshotVO = (SnapshotVO)snapshot;

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/ff047e75/server/src/com/cloud/storage/listener/SnapshotStateListener.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/listener/SnapshotStateListener.java b/server/src/com/cloud/storage/listener/SnapshotStateListener.java
index 17ccce5..8f94f23 100644
--- a/server/src/com/cloud/storage/listener/SnapshotStateListener.java
+++ b/server/src/com/cloud/storage/listener/SnapshotStateListener.java
@@ -17,24 +17,24 @@
 
 package com.cloud.storage.listener;
 
-import com.cloud.event.EventCategory;
-import com.cloud.storage.Snapshot;
-import com.cloud.storage.Snapshot.Event;
-import com.cloud.storage.Snapshot.State;
-import com.cloud.server.ManagementServer;
-import com.cloud.utils.fsm.StateListener;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.inject.Inject;
 
 import org.apache.cloudstack.framework.events.EventBus;
 import org.apache.cloudstack.framework.events.EventBusException;
 import org.apache.log4j.Logger;
 
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.inject.Inject;
+import com.cloud.event.EventCategory;
+import com.cloud.server.ManagementServer;
+import com.cloud.storage.Snapshot;
+import com.cloud.storage.Snapshot.Event;
+import com.cloud.storage.Snapshot.State;
+import com.cloud.storage.SnapshotVO;
+import com.cloud.utils.fsm.StateListener;
 
-public class SnapshotStateListener implements StateListener<State, Event, Snapshot> {
+public class SnapshotStateListener implements StateListener<State, Event, SnapshotVO> {
 
     // get the event bus provider if configured
     @Inject protected EventBus _eventBus;
@@ -46,13 +46,13 @@ public class SnapshotStateListener implements StateListener<State, Event, Snapsh
     }
 
     @Override
-    public boolean preStateTransitionEvent(State oldState, Event event, State newState, Snapshot vo, boolean status, Object opaque) {
+    public boolean preStateTransitionEvent(State oldState, Event event, State newState, SnapshotVO vo, boolean status, Object opaque) {
         pubishOnEventBus(event.name(), "preStateTransitionEvent", vo, oldState, newState);
         return true;
     }
 
     @Override
-    public boolean postStateTransitionEvent(State oldState, Event event, State newState, Snapshot vo, boolean status, Object opaque) {
+    public boolean postStateTransitionEvent(State oldState, Event event, State newState, SnapshotVO vo, boolean status, Object opaque) {
         pubishOnEventBus(event.name(), "postStateTransitionEvent", vo, oldState, newState);
         return true;
     }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/ff047e75/server/src/com/cloud/storage/snapshot/SnapshotManager.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/snapshot/SnapshotManager.java b/server/src/com/cloud/storage/snapshot/SnapshotManager.java
index 72e8163..8181330 100755
--- a/server/src/com/cloud/storage/snapshot/SnapshotManager.java
+++ b/server/src/com/cloud/storage/snapshot/SnapshotManager.java
@@ -18,13 +18,19 @@ package com.cloud.storage.snapshot;
 
 import java.util.List;
 
+import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
+
+import com.cloud.agent.api.Answer;
+import com.cloud.agent.api.Command;
 import com.cloud.exception.ResourceAllocationException;
 import com.cloud.host.HostVO;
+import com.cloud.storage.Snapshot;
 import com.cloud.storage.SnapshotPolicyVO;
 import com.cloud.storage.SnapshotVO;
 import com.cloud.storage.Volume;
 import com.cloud.storage.VolumeVO;
 import com.cloud.utils.db.Filter;
+import com.cloud.utils.fsm.NoTransitionException;
 
 /**
  * 
@@ -38,66 +44,6 @@ public interface SnapshotManager {
     public static final int MONTHLYMAX = 12;
     public static final int DELTAMAX = 16;
 
-    /**
-     * After successfully creating a snapshot of a volume, copy the snapshot to the secondary storage for 1) reliability 2) So
-     * that storage space on Primary is conserved.
-     * 
-     * @param snapshot
-     *            Info about the created snapshot on primary storage.
-     * @param startEventId
-     *            event id of the scheduled event for this snapshot
-     * @return True if the snapshot was successfully backed up.
-     */
-    public boolean backupSnapshotToSecondaryStorage(SnapshotVO snapshot);
-
-    /**
-     * Once a snapshot has completed, 1) If success, update the database entries 2) If success and there are excess snapshots
-     * for any of the policies given, delete the oldest one. 3) Schedule the next recurring snapshot.
-     * 
-     * @param volumeId
-     *            The volume for which the snapshot is being taken
-     * @param snapshotId
-     *            The snapshot which has just completed
-     * @param policyIds
-     *            The list of policyIds to which this snapshot belongs to
-     * @param backedUp
-     *            If true, the snapshot has been successfully created.
-     */
-    void postCreateSnapshot(Long volumeId, Long snapshotId, Long policyId, boolean backedUp);
-
-    /**
-     * Destroys the specified snapshot from secondary storage
-     */
-    boolean destroySnapshot(long userId, long snapshotId, long policyId);
-
-    /**
-     * Deletes snapshot scheduling policy. Delete will fail if this policy is assigned to one or more volumes
-     */
-    boolean deletePolicy(long userId, Long policyId);
-
-    /**
-     * Lists all snapshots for the volume which are created using schedule of the specified policy
-     */
-    /*
-     * List<SnapshotVO> listSnapsforPolicy(long policyId, Filter filter);
-     */
-    /**
-     * List all policies which are assigned to the specified volume
-     */
-    List<SnapshotPolicyVO> listPoliciesforVolume(long volumeId);
-
-    /**
-     * List all policies to which a specified snapshot belongs. For ex: A snapshot may belong to a hourly snapshot and a daily
-     * snapshot run at the same time
-     */
-    /*
-     * List<SnapshotPolicyVO> listPoliciesforSnapshot(long snapshotId);
-     */
-    /**
-     * List all snapshots for a specified volume irrespective of the policy which created the snapshot
-     */
-    List<SnapshotVO> listSnapsforVolume(long volumeId);
-
     void deletePoliciesForVolume(Long volumeId);
 
     /**
@@ -109,35 +55,20 @@ public interface SnapshotManager {
      *            The account which is to be deleted.
      */
     boolean deleteSnapshotDirsForAccount(long accountId);
-
-    SnapshotPolicyVO getPolicyForVolume(long volumeId);
-
-    boolean destroySnapshotBackUp(long snapshotId);
-
-    /**
-     * Create a snapshot of a volume
-     * 
-     * @param cmd
-     *            the API command wrapping the parameters for creating the snapshot (mainly volumeId)
-     * @return the Snapshot that was created
-     */
-    SnapshotVO createSnapshotOnPrimary(VolumeVO volume, Long polocyId, Long snapshotId) throws ResourceAllocationException;
-
-    List<SnapshotPolicyVO> listPoliciesforSnapshot(long snapshotId);
-
-    List<SnapshotVO> listSnapsforPolicy(long policyId, Filter filter);
-
+  
     void downloadSnapshotsFromSwift(SnapshotVO ss);
 
     void downloadSnapshotsFromS3(SnapshotVO snapshot);
 
-    HostVO getSecondaryStorageHost(SnapshotVO snapshot);
-
     String getSecondaryStorageURL(SnapshotVO snapshot);
 
-    void deleteSnapshotsForVolume (String secondaryStoragePoolUrl, Long dcId, Long accountId, Long volumeId );
-
     void deleteSnapshotsDirForVolume(String secondaryStoragePoolUrl, Long dcId, Long accountId, Long volumeId);
 
 	boolean canOperateOnVolume(Volume volume);
+
+	Answer sendToPool(Volume vol, Command cmd);
+
+	SnapshotVO getParentSnapshot(VolumeInfo volume, Snapshot snapshot);
+
+	Snapshot backupSnapshot(Long snapshotId);
 }


Mime
View raw message