cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t..@apache.org
Subject [28/50] [abbrv] move default primary storage plugin into its own pom
Date Sat, 23 Mar 2013 12:31:08 GMT
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3ed6200e/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
deleted file mode 100644
index 440cb8c..0000000
--- a/engine/storage/volume/src/org/apache/cloudstack/storage/datastore/driver/AncientPrimaryDataStoreDriverImpl.java
+++ /dev/null
@@ -1,362 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.cloudstack.storage.datastore.driver;
-
-import java.util.Set;
-
-import javax.inject.Inject;
-
-import org.apache.cloudstack.engine.subsystem.api.storage.CommandResult;
-import org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult;
-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.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.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 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;
-	}
-
-	@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);
-
-		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) {
-	    CreateCmdResult result = null;
-	    try {
-	        VolumeInfo volume = snapshot.getBaseVolume();
-	        String vmName = this.volumeMgr.getVmNameOnVolume(volume);
-	        SnapshotVO preSnapshotVO = this.snapshotMgr.getParentSnapshot(volume, snapshot);
-	        String parentSnapshotPath = null;
-	        if (preSnapshotVO != null) {
-	            parentSnapshotPath = preSnapshotVO.getPath();
-	        }
-	        StoragePool srcPool = (StoragePool)volume.getDataStore();
-	        
-	        ManageSnapshotCommand cmd = new ManageSnapshotCommand(snapshot.getId(), volume.getPath(), srcPool, parentSnapshotPath, snapshot.getName(), vmName);
-
-	        ManageSnapshotAnswer answer = (ManageSnapshotAnswer) this.snapshotMgr.sendToPool(volume, cmd);
-	        
-	        if ((answer != null) && answer.getResult()) {
-	            result = new CreateCmdResult(answer.getSnapshotPath(), null);
-	        } else {
-	            result = new CreateCmdResult(null, null);
-	        }
-	    } catch (Exception e) {
-	        s_logger.debug("Failed to take snapshot: " + snapshot.getId(), e);
-	        result = new CreateCmdResult(null, null);
-	        result.setResult(e.toString());
-	    }
-        callback.complete(result);
-	}
-
-	@Override
-	public void revertSnapshot(SnapshotInfo snapshot,
-			AsyncCompletionCallback<CommandResult> callback) {
-		// TODO Auto-generated method stub
-
-	}
-
-	@Override
-	public void resize(DataObject data,
-			AsyncCompletionCallback<CreateCmdResult> callback) {
-		VolumeObject vol = (VolumeObject)data;
-		StoragePool pool = (StoragePool)data.getDataStore();
-		ResizeVolumePayload resizeParameter = (ResizeVolumePayload)vol.getpayload();
-
-		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);
-
-				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/cloudstack/blob/3ed6200e/engine/storage/volume/src/org/apache/cloudstack/storage/datastore/lifecycle/AncientPrimaryDataStoreLifeCycleImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/volume/src/org/apache/cloudstack/storage/datastore/lifecycle/AncientPrimaryDataStoreLifeCycleImpl.java b/engine/storage/volume/src/org/apache/cloudstack/storage/datastore/lifecycle/AncientPrimaryDataStoreLifeCycleImpl.java
deleted file mode 100644
index 6154a66..0000000
--- a/engine/storage/volume/src/org/apache/cloudstack/storage/datastore/lifecycle/AncientPrimaryDataStoreLifeCycleImpl.java
+++ /dev/null
@@ -1,963 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.cloudstack.storage.datastore.lifecycle;
-
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
-
-import javax.inject.Inject;
-
-import org.apache.cloudstack.engine.subsystem.api.storage.ClusterScope;
-import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
-import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
-import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreRole;
-import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreStatus;
-import org.apache.cloudstack.engine.subsystem.api.storage.HostScope;
-import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreInfo;
-import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreLifeCycle;
-import org.apache.cloudstack.engine.subsystem.api.storage.ScopeType;
-import org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope;
-import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
-import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
-import org.apache.log4j.Logger;
-
-import com.cloud.agent.AgentManager;
-import com.cloud.agent.api.Answer;
-import com.cloud.agent.api.CreateStoragePoolCommand;
-import com.cloud.agent.api.DeleteStoragePoolCommand;
-import com.cloud.agent.api.ModifyStoragePoolCommand;
-import com.cloud.agent.api.StoragePoolInfo;
-import com.cloud.alert.AlertManager;
-import com.cloud.capacity.Capacity;
-import com.cloud.capacity.CapacityVO;
-import com.cloud.capacity.dao.CapacityDao;
-import com.cloud.exception.DiscoveryException;
-import com.cloud.exception.InvalidParameterValueException;
-import com.cloud.host.Host;
-import com.cloud.host.HostVO;
-import com.cloud.host.Status;
-import com.cloud.hypervisor.Hypervisor.HypervisorType;
-import com.cloud.resource.ResourceManager;
-import com.cloud.server.ManagementServer;
-import com.cloud.storage.OCFS2Manager;
-import com.cloud.storage.Storage.StoragePoolType;
-import com.cloud.storage.StorageManager;
-import com.cloud.storage.StoragePool;
-import com.cloud.storage.StoragePoolDiscoverer;
-import com.cloud.storage.StoragePoolHostVO;
-import com.cloud.storage.StoragePoolStatus;
-import com.cloud.storage.StoragePoolWorkVO;
-import com.cloud.storage.VolumeVO;
-import com.cloud.storage.dao.StoragePoolHostDao;
-import com.cloud.storage.dao.StoragePoolWorkDao;
-import com.cloud.storage.dao.VolumeDao;
-import com.cloud.user.Account;
-import com.cloud.user.User;
-import com.cloud.user.UserContext;
-import com.cloud.user.dao.UserDao;
-import com.cloud.utils.NumbersUtil;
-import com.cloud.utils.UriUtils;
-import com.cloud.utils.db.DB;
-import com.cloud.utils.db.Transaction;
-import com.cloud.utils.exception.CloudRuntimeException;
-import com.cloud.utils.exception.ExecutionException;
-import com.cloud.vm.ConsoleProxyVO;
-import com.cloud.vm.DomainRouterVO;
-import com.cloud.vm.SecondaryStorageVmVO;
-import com.cloud.vm.UserVmVO;
-import com.cloud.vm.VMInstanceVO;
-import com.cloud.vm.VirtualMachine;
-import com.cloud.vm.VirtualMachine.State;
-import com.cloud.vm.VirtualMachineManager;
-import com.cloud.vm.dao.ConsoleProxyDao;
-import com.cloud.vm.dao.DomainRouterDao;
-import com.cloud.vm.dao.SecondaryStorageVmDao;
-import com.cloud.vm.dao.UserVmDao;
-import com.cloud.vm.dao.VMInstanceDao;
-
-public class AncientPrimaryDataStoreLifeCycleImpl implements
-        PrimaryDataStoreLifeCycle {
-    private static final Logger s_logger = Logger
-            .getLogger(AncientPrimaryDataStoreLifeCycleImpl.class);
-    @Inject
-    protected ResourceManager _resourceMgr;
-    protected List<StoragePoolDiscoverer> _discoverers;
-    @Inject
-    PrimaryDataStoreDao primaryDataStoreDao;
-    @Inject
-    protected OCFS2Manager _ocfs2Mgr;
-    @Inject
-    DataStoreManager dataStoreMgr;
-    @Inject
-    AgentManager agentMgr;
-    @Inject
-    StorageManager storageMgr;
-    @Inject
-    protected CapacityDao _capacityDao;
-
-    @Inject
-    VolumeDao volumeDao;
-    @Inject
-    VMInstanceDao vmDao;
-    @Inject
-    ManagementServer server;
-    @Inject
-    protected VirtualMachineManager vmMgr;
-    @Inject
-    protected SecondaryStorageVmDao _secStrgDao;
-    @Inject
-    UserVmDao userVmDao;
-    @Inject
-    protected UserDao _userDao;
-    @Inject
-    protected DomainRouterDao _domrDao;
-    @Inject
-    protected StoragePoolHostDao _storagePoolHostDao;
-    @Inject
-    protected AlertManager _alertMgr;
-    @Inject
-    protected ConsoleProxyDao _consoleProxyDao;
-
-    @Inject
-    protected StoragePoolWorkDao _storagePoolWorkDao;
-
-    @Override
-    public DataStore initialize(Map<String, Object> dsInfos) {
-        Long clusterId = (Long) dsInfos.get("clusterId");
-        Long podId = (Long) dsInfos.get("podId");
-        Long zoneId = (Long) dsInfos.get("zoneId");
-        String url = (String) dsInfos.get("url");
-        Long providerId = (Long)dsInfos.get("providerId");
-        if (clusterId != null && podId == null) {
-            throw new InvalidParameterValueException(
-                    "Cluster id requires pod id");
-        }
-
-        URI uri = null;
-        try {
-            uri = new URI(UriUtils.encodeURIComponent(url));
-            if (uri.getScheme() == null) {
-                throw new InvalidParameterValueException("scheme is null "
-                        + url + ", add nfs:// as a prefix");
-            } else if (uri.getScheme().equalsIgnoreCase("nfs")) {
-                String uriHost = uri.getHost();
-                String uriPath = uri.getPath();
-                if (uriHost == null || uriPath == null
-                        || uriHost.trim().isEmpty() || uriPath.trim().isEmpty()) {
-                    throw new InvalidParameterValueException(
-                            "host or path is null, should be nfs://hostname/path");
-                }
-            } else if (uri.getScheme().equalsIgnoreCase("sharedMountPoint")) {
-                String uriPath = uri.getPath();
-                if (uriPath == null) {
-                    throw new InvalidParameterValueException(
-                            "host or path is null, should be sharedmountpoint://localhost/path");
-                }
-            } else if (uri.getScheme().equalsIgnoreCase("rbd")) {
-                String uriPath = uri.getPath();
-                if (uriPath == null) {
-                    throw new InvalidParameterValueException(
-                            "host or path is null, should be rbd://hostname/pool");
-                }
-            }
-        } catch (URISyntaxException e) {
-            throw new InvalidParameterValueException(url
-                    + " is not a valid uri");
-        }
-
-        String tags = (String) dsInfos.get("tags");
-        Map<String, String> details = (Map<String, String>) dsInfos
-                .get("details");
-        if (tags != null) {
-            String[] tokens = tags.split(",");
-
-            for (String tag : tokens) {
-                tag = tag.trim();
-                if (tag.length() == 0) {
-                    continue;
-                }
-                details.put(tag, "true");
-            }
-        }
-
-        String scheme = uri.getScheme();
-        String storageHost = uri.getHost();
-        String hostPath = uri.getPath();
-        Object localStorage = dsInfos.get("localStorage");
-        if (localStorage != null) {
-            hostPath = hostPath.replace("/", "");
-        }
-        String userInfo = uri.getUserInfo();
-        int port = uri.getPort();
-        StoragePoolVO pool = null;
-        if (s_logger.isDebugEnabled()) {
-            s_logger.debug("createPool Params @ scheme - " + scheme
-                    + " storageHost - " + storageHost + " hostPath - "
-                    + hostPath + " port - " + port);
-        }
-        if (scheme.equalsIgnoreCase("nfs")) {
-            if (port == -1) {
-                port = 2049;
-            }
-            pool = new StoragePoolVO(StoragePoolType.NetworkFilesystem,
-                    storageHost, port, hostPath);
-        } else if (scheme.equalsIgnoreCase("file")) {
-            if (port == -1) {
-                port = 0;
-            }
-            pool = new StoragePoolVO(StoragePoolType.Filesystem,
-                    "localhost", 0, hostPath);
-        } else if (scheme.equalsIgnoreCase("sharedMountPoint")) {
-            pool = new StoragePoolVO(StoragePoolType.SharedMountPoint,
-                    storageHost, 0, hostPath);
-        } else if (scheme.equalsIgnoreCase("clvm")) {
-            pool = new StoragePoolVO(StoragePoolType.CLVM, storageHost, 0,
-                    hostPath.replaceFirst("/", ""));
-        } else if (scheme.equalsIgnoreCase("rbd")) {
-            if (port == -1) {
-                port = 6789;
-            }
-            pool = new StoragePoolVO(StoragePoolType.RBD, storageHost,
-                    port, hostPath.replaceFirst("/", ""));
-            pool.setUserInfo(userInfo);
-        } else if (scheme.equalsIgnoreCase("PreSetup")) {
-            pool = new StoragePoolVO(StoragePoolType.PreSetup,
-                    storageHost, 0, hostPath);
-        } else if (scheme.equalsIgnoreCase("iscsi")) {
-            String[] tokens = hostPath.split("/");
-            int lun = NumbersUtil.parseInt(tokens[tokens.length - 1], -1);
-            if (port == -1) {
-                port = 3260;
-            }
-            if (lun != -1) {
-                if (clusterId == null) {
-                    throw new IllegalArgumentException(
-                            "IscsiLUN need to have clusters specified");
-                }
-                hostPath.replaceFirst("/", "");
-                pool = new StoragePoolVO(StoragePoolType.IscsiLUN,
-                        storageHost, port, hostPath);
-            } else {
-                for (StoragePoolDiscoverer discoverer : _discoverers) {
-                    Map<StoragePoolVO, Map<String, String>> pools;
-                    try {
-                        pools = discoverer.find(zoneId, podId, uri, details);
-                    } catch (DiscoveryException e) {
-                        throw new IllegalArgumentException(
-                                "Not enough information for discovery " + uri,
-                                e);
-                    }
-                    if (pools != null) {
-                        Map.Entry<StoragePoolVO, Map<String, String>> entry = pools
-                                .entrySet().iterator().next();
-                        pool = entry.getKey();
-                        details = entry.getValue();
-                        break;
-                    }
-                }
-            }
-        } else if (scheme.equalsIgnoreCase("iso")) {
-            if (port == -1) {
-                port = 2049;
-            }
-            pool = new StoragePoolVO(StoragePoolType.ISO, storageHost,
-                    port, hostPath);
-        } else if (scheme.equalsIgnoreCase("vmfs")) {
-            pool = new StoragePoolVO(StoragePoolType.VMFS,
-                    "VMFS datastore: " + hostPath, 0, hostPath);
-        } else if (scheme.equalsIgnoreCase("ocfs2")) {
-            port = 7777;
-            pool = new StoragePoolVO(StoragePoolType.OCFS2, "clustered",
-                    port, hostPath);
-        } else {
-            StoragePoolType type = Enum.valueOf(StoragePoolType.class, scheme);
-                
-            if (type != null) {
-                pool = new StoragePoolVO(type, storageHost,
-                        0, hostPath);
-            } else {
-            s_logger.warn("Unable to figure out the scheme for URI: " + uri);
-            throw new IllegalArgumentException(
-                    "Unable to figure out the scheme for URI: " + uri);
-            }
-        }
-
-        if (pool == null) {
-            s_logger.warn("Unable to figure out the scheme for URI: " + uri);
-            throw new IllegalArgumentException(
-                    "Unable to figure out the scheme for URI: " + uri);
-        }
-
-        if (localStorage == null) {
-            List<StoragePoolVO> pools = primaryDataStoreDao
-                    .listPoolByHostPath(storageHost, hostPath);
-            if (!pools.isEmpty() && !scheme.equalsIgnoreCase("sharedmountpoint")) {
-                Long oldPodId = pools.get(0).getPodId();
-                throw new CloudRuntimeException("Storage pool " + uri
-                        + " already in use by another pod (id=" + oldPodId + ")");
-            }
-        }
-
-        long poolId = primaryDataStoreDao.getNextInSequence(Long.class, "id");
-        Object existingUuid = dsInfos.get("uuid");
-        String uuid = null;
-
-        if (existingUuid != null) {
-            uuid = (String)existingUuid;
-        } else if (scheme.equalsIgnoreCase("sharedmountpoint")
-                || scheme.equalsIgnoreCase("clvm")) {
-            uuid = UUID.randomUUID().toString();
-        } else if (scheme.equalsIgnoreCase("PreSetup")) {
-            uuid = hostPath.replace("/", "");
-        } else {
-            uuid = UUID.nameUUIDFromBytes(
-                    new String(storageHost + hostPath).getBytes()).toString();
-        }
-
-        List<StoragePoolVO> spHandles = primaryDataStoreDao
-                .findIfDuplicatePoolsExistByUUID(uuid);
-        if ((spHandles != null) && (spHandles.size() > 0)) {
-            if (s_logger.isDebugEnabled()) {
-                s_logger.debug("Another active pool with the same uuid already exists");
-            }
-            throw new CloudRuntimeException(
-                    "Another active pool with the same uuid already exists");
-        }
-
-        String poolName = (String) dsInfos.get("name");
-        if (s_logger.isDebugEnabled()) {
-            s_logger.debug("In createPool Setting poolId - " + poolId
-                    + " uuid - " + uuid + " zoneId - " + zoneId + " podId - "
-                    + podId + " poolName - " + poolName);
-        }
-
-        pool.setId(poolId);
-        pool.setUuid(uuid);
-        pool.setDataCenterId(zoneId);
-        pool.setPodId(podId);
-        pool.setName(poolName);
-        pool.setClusterId(clusterId);
-        pool.setStorageProviderId(providerId);
-        pool.setStatus(StoragePoolStatus.Initialized);
-        pool = primaryDataStoreDao.persist(pool, details);
-
-        return dataStoreMgr.getDataStore(pool.getId(), DataStoreRole.Primary);
-    }
-
-    protected boolean createStoragePool(long hostId, StoragePool pool) {
-        s_logger.debug("creating pool " + pool.getName() + " on  host "
-                + hostId);
-        if (pool.getPoolType() != StoragePoolType.NetworkFilesystem
-                && pool.getPoolType() != StoragePoolType.Filesystem
-                && pool.getPoolType() != StoragePoolType.IscsiLUN
-                && pool.getPoolType() != StoragePoolType.Iscsi
-                && pool.getPoolType() != StoragePoolType.VMFS
-                && pool.getPoolType() != StoragePoolType.SharedMountPoint
-                && pool.getPoolType() != StoragePoolType.PreSetup
-                && pool.getPoolType() != StoragePoolType.OCFS2
-                && pool.getPoolType() != StoragePoolType.RBD
-                && pool.getPoolType() != StoragePoolType.CLVM) {
-            s_logger.warn(" Doesn't support storage pool type "
-                    + pool.getPoolType());
-            return false;
-        }
-        CreateStoragePoolCommand cmd = new CreateStoragePoolCommand(true, pool);
-        final Answer answer = agentMgr.easySend(hostId, cmd);
-        if (answer != null && answer.getResult()) {
-            return true;
-        } else {
-            primaryDataStoreDao.expunge(pool.getId());
-            String msg = "";
-            if (answer != null) {
-                msg = "Can not create storage pool through host " + hostId
-                        + " due to " + answer.getDetails();
-                s_logger.warn(msg);
-            } else {
-                msg = "Can not create storage pool through host " + hostId
-                        + " due to CreateStoragePoolCommand returns null";
-                s_logger.warn(msg);
-            }
-            throw new CloudRuntimeException(msg);
-        }
-    }
-
-    @Override
-    public boolean attachCluster(DataStore store, ClusterScope scope) {
-        PrimaryDataStoreInfo primarystore = (PrimaryDataStoreInfo) store;
-        // Check if there is host up in this cluster
-        List<HostVO> allHosts = _resourceMgr.listAllUpAndEnabledHosts(
-                Host.Type.Routing, primarystore.getClusterId(),
-                primarystore.getPodId(), primarystore.getDataCenterId());
-        if (allHosts.isEmpty()) {
-            throw new CloudRuntimeException(
-                    "No host up to associate a storage pool with in cluster "
-                            + primarystore.getClusterId());
-        }
-
-        if (primarystore.getPoolType() == StoragePoolType.OCFS2
-                && !_ocfs2Mgr.prepareNodes(allHosts, primarystore)) {
-            s_logger.warn("Can not create storage pool " + primarystore
-                    + " on cluster " + primarystore.getClusterId());
-            primaryDataStoreDao.expunge(primarystore.getId());
-            return false;
-        }
-
-        boolean success = false;
-        for (HostVO h : allHosts) {
-            success = createStoragePool(h.getId(), primarystore);
-            if (success) {
-                break;
-            }
-        }
-
-        s_logger.debug("In createPool Adding the pool to each of the hosts");
-        List<HostVO> poolHosts = new ArrayList<HostVO>();
-        for (HostVO h : allHosts) {
-            try {
-                this.storageMgr.connectHostToSharedPool(h.getId(),
-                        primarystore.getId());
-                poolHosts.add(h);
-            } catch (Exception e) {
-                s_logger.warn("Unable to establish a connection between " + h
-                        + " and " + primarystore, e);
-            }
-        }
-
-        if (poolHosts.isEmpty()) {
-            s_logger.warn("No host can access storage pool " + primarystore
-                    + " on cluster " + primarystore.getClusterId());
-            primaryDataStoreDao.expunge(primarystore.getId());
-            return false;
-        } else {
-            storageMgr.createCapacityEntry(primarystore.getId());
-        }
-        StoragePoolVO pool = this.primaryDataStoreDao.findById(store.getId());
-        pool.setScope(ScopeType.CLUSTER);
-        pool.setStatus(StoragePoolStatus.Up);
-        this.primaryDataStoreDao.update(pool.getId(), pool);
-        return true;
-    }
-
-    @Override
-    public boolean attachZone(DataStore dataStore, ZoneScope scope) {
-    	List<HostVO> hosts = _resourceMgr.listAllUpAndEnabledHostsInOneZoneByHypervisor(HypervisorType.KVM, scope.getScopeId());
-    	for (HostVO host : hosts) {
-    		try {
-    			this.storageMgr.connectHostToSharedPool(host.getId(),
-    					dataStore.getId());
-    		} catch (Exception e) {
-    			s_logger.warn("Unable to establish a connection between " + host
-    					+ " and " + dataStore, e);
-    		}
-    	}
-    	StoragePoolVO pool = this.primaryDataStoreDao.findById(dataStore.getId());
-        
-        pool.setScope(ScopeType.ZONE);
-        pool.setStatus(StoragePoolStatus.Up);
-        this.primaryDataStoreDao.update(pool.getId(), pool);
-        return true;
-    }
-
-    @Override
-    public boolean dettach() {
-        // TODO Auto-generated method stub
-        return false;
-    }
-
-    @Override
-    public boolean unmanaged() {
-        // TODO Auto-generated method stub
-        return false;
-    }
-
-    @Override
-    public boolean maintain(long storeId) {
-        Long userId = UserContext.current().getCallerUserId();
-        User user = _userDao.findById(userId);
-        Account account = UserContext.current().getCaller();
-        StoragePoolVO pool = this.primaryDataStoreDao.findById(storeId);
-        try {
-            StoragePool storagePool = (StoragePool) this.dataStoreMgr
-                    .getDataStore(storeId, DataStoreRole.Primary);
-            List<HostVO> hosts = _resourceMgr.listHostsInClusterByStatus(
-                    pool.getClusterId(), Status.Up);
-            if (hosts == null || hosts.size() == 0) {
-                pool.setStatus(StoragePoolStatus.Maintenance);
-                primaryDataStoreDao.update(pool.getId(), pool);
-                return true;
-            } else {
-                // set the pool state to prepare for maintenance
-                pool.setStatus(StoragePoolStatus.PrepareForMaintenance);
-                primaryDataStoreDao.update(pool.getId(), pool);
-            }
-            // remove heartbeat
-            for (HostVO host : hosts) {
-                ModifyStoragePoolCommand cmd = new ModifyStoragePoolCommand(
-                        false, storagePool);
-                final Answer answer = agentMgr.easySend(host.getId(), cmd);
-                if (answer == null || !answer.getResult()) {
-                    if (s_logger.isDebugEnabled()) {
-                        s_logger.debug("ModifyStoragePool false failed due to "
-                                + ((answer == null) ? "answer null" : answer
-                                        .getDetails()));
-                    }
-                } else {
-                    if (s_logger.isDebugEnabled()) {
-                        s_logger.debug("ModifyStoragePool false secceeded");
-                    }
-                }
-            }
-            // check to see if other ps exist
-            // if they do, then we can migrate over the system vms to them
-            // if they dont, then just stop all vms on this one
-            List<StoragePoolVO> upPools = primaryDataStoreDao
-                    .listByStatusInZone(pool.getDataCenterId(),
-                            StoragePoolStatus.Up);
-            boolean restart = true;
-            if (upPools == null || upPools.size() == 0) {
-                restart = false;
-            }
-
-            // 2. Get a list of all the ROOT volumes within this storage pool
-            List<VolumeVO> allVolumes = this.volumeDao.findByPoolId(pool
-                    .getId());
-
-            // 3. Enqueue to the work queue
-            for (VolumeVO volume : allVolumes) {
-                VMInstanceVO vmInstance = vmDao
-                        .findById(volume.getInstanceId());
-
-                if (vmInstance == null) {
-                    continue;
-                }
-
-                // enqueue sp work
-                if (vmInstance.getState().equals(State.Running)
-                        || vmInstance.getState().equals(State.Starting)
-                        || vmInstance.getState().equals(State.Stopping)) {
-
-                    try {
-                        StoragePoolWorkVO work = new StoragePoolWorkVO(
-                                vmInstance.getId(), pool.getId(), false, false,
-                                server.getId());
-                        _storagePoolWorkDao.persist(work);
-                    } catch (Exception e) {
-                        if (s_logger.isDebugEnabled()) {
-                            s_logger.debug("Work record already exists, re-using by re-setting values");
-                        }
-                        StoragePoolWorkVO work = _storagePoolWorkDao
-                                .findByPoolIdAndVmId(pool.getId(),
-                                        vmInstance.getId());
-                        work.setStartedAfterMaintenance(false);
-                        work.setStoppedForMaintenance(false);
-                        work.setManagementServerId(server.getId());
-                        _storagePoolWorkDao.update(work.getId(), work);
-                    }
-                }
-            }
-
-            // 4. Process the queue
-            List<StoragePoolWorkVO> pendingWork = _storagePoolWorkDao
-                    .listPendingWorkForPrepareForMaintenanceByPoolId(pool
-                            .getId());
-
-            for (StoragePoolWorkVO work : pendingWork) {
-                // shut down the running vms
-                VMInstanceVO vmInstance = vmDao.findById(work.getVmId());
-
-                if (vmInstance == null) {
-                    continue;
-                }
-
-                // if the instance is of type consoleproxy, call the console
-                // proxy
-                if (vmInstance.getType().equals(
-                        VirtualMachine.Type.ConsoleProxy)) {
-                    // call the consoleproxymanager
-                    ConsoleProxyVO consoleProxy = _consoleProxyDao
-                            .findById(vmInstance.getId());
-                    if (!vmMgr.advanceStop(consoleProxy, true, user, account)) {
-                        String errorMsg = "There was an error stopping the console proxy id: "
-                                + vmInstance.getId()
-                                + " ,cannot enable storage maintenance";
-                        s_logger.warn(errorMsg);
-                        throw new CloudRuntimeException(errorMsg);
-                    } else {
-                        // update work status
-                        work.setStoppedForMaintenance(true);
-                        _storagePoolWorkDao.update(work.getId(), work);
-                    }
-
-                    if (restart) {
-
-                        if (this.vmMgr.advanceStart(consoleProxy, null, user,
-                                account) == null) {
-                            String errorMsg = "There was an error starting the console proxy id: "
-                                    + vmInstance.getId()
-                                    + " on another storage pool, cannot enable primary storage maintenance";
-                            s_logger.warn(errorMsg);
-                        } else {
-                            // update work status
-                            work.setStartedAfterMaintenance(true);
-                            _storagePoolWorkDao.update(work.getId(), work);
-                        }
-                    }
-                }
-
-                // if the instance is of type uservm, call the user vm manager
-                if (vmInstance.getType().equals(VirtualMachine.Type.User)) {
-                    UserVmVO userVm = userVmDao.findById(vmInstance.getId());
-                    if (!vmMgr.advanceStop(userVm, true, user, account)) {
-                        String errorMsg = "There was an error stopping the user vm id: "
-                                + vmInstance.getId()
-                                + " ,cannot enable storage maintenance";
-                        s_logger.warn(errorMsg);
-                        throw new CloudRuntimeException(errorMsg);
-                    } else {
-                        // update work status
-                        work.setStoppedForMaintenance(true);
-                        _storagePoolWorkDao.update(work.getId(), work);
-                    }
-                }
-
-                // if the instance is of type secondary storage vm, call the
-                // secondary storage vm manager
-                if (vmInstance.getType().equals(
-                        VirtualMachine.Type.SecondaryStorageVm)) {
-                    SecondaryStorageVmVO secStrgVm = _secStrgDao
-                            .findById(vmInstance.getId());
-                    if (!vmMgr.advanceStop(secStrgVm, true, user, account)) {
-                        String errorMsg = "There was an error stopping the ssvm id: "
-                                + vmInstance.getId()
-                                + " ,cannot enable storage maintenance";
-                        s_logger.warn(errorMsg);
-                        throw new CloudRuntimeException(errorMsg);
-                    } else {
-                        // update work status
-                        work.setStoppedForMaintenance(true);
-                        _storagePoolWorkDao.update(work.getId(), work);
-                    }
-
-                    if (restart) {
-                        if (vmMgr.advanceStart(secStrgVm, null, user, account) == null) {
-                            String errorMsg = "There was an error starting the ssvm id: "
-                                    + vmInstance.getId()
-                                    + " on another storage pool, cannot enable primary storage maintenance";
-                            s_logger.warn(errorMsg);
-                        } else {
-                            // update work status
-                            work.setStartedAfterMaintenance(true);
-                            _storagePoolWorkDao.update(work.getId(), work);
-                        }
-                    }
-                }
-
-                // if the instance is of type domain router vm, call the network
-                // manager
-                if (vmInstance.getType().equals(
-                        VirtualMachine.Type.DomainRouter)) {
-                    DomainRouterVO domR = _domrDao.findById(vmInstance.getId());
-                    if (!vmMgr.advanceStop(domR, true, user, account)) {
-                        String errorMsg = "There was an error stopping the domain router id: "
-                                + vmInstance.getId()
-                                + " ,cannot enable primary storage maintenance";
-                        s_logger.warn(errorMsg);
-                        throw new CloudRuntimeException(errorMsg);
-                    } else {
-                        // update work status
-                        work.setStoppedForMaintenance(true);
-                        _storagePoolWorkDao.update(work.getId(), work);
-                    }
-
-                    if (restart) {
-                        if (vmMgr.advanceStart(domR, null, user, account) == null) {
-                            String errorMsg = "There was an error starting the domain router id: "
-                                    + vmInstance.getId()
-                                    + " on another storage pool, cannot enable primary storage maintenance";
-                            s_logger.warn(errorMsg);
-                        } else {
-                            // update work status
-                            work.setStartedAfterMaintenance(true);
-                            _storagePoolWorkDao.update(work.getId(), work);
-                        }
-                    }
-                }
-            }
-
-            // 5. Update the status
-            pool.setStatus(StoragePoolStatus.Maintenance);
-            this.primaryDataStoreDao.update(pool.getId(), pool);
-
-            return true;
-        } catch (Exception e) {
-            s_logger.error(
-                    "Exception in enabling primary storage maintenance:", e);
-            setPoolStateToError(pool);
-            throw new CloudRuntimeException(e.getMessage());
-        }
-    }
-
-    private void setPoolStateToError(StoragePoolVO primaryStorage) {
-        primaryStorage.setStatus(StoragePoolStatus.ErrorInMaintenance);
-        this.primaryDataStoreDao.update(primaryStorage.getId(), primaryStorage);
-    }
-
-    @Override
-    public boolean cancelMaintain(long storageId) {
-        // Change the storage state back to up
-        Long userId = UserContext.current().getCallerUserId();
-        User user = _userDao.findById(userId);
-        Account account = UserContext.current().getCaller();
-        StoragePoolVO poolVO = this.primaryDataStoreDao
-                .findById(storageId);
-        StoragePool pool = (StoragePool) this.dataStoreMgr.getDataStore(
-                storageId, DataStoreRole.Primary);
-        poolVO.setStatus(StoragePoolStatus.Up);
-        primaryDataStoreDao.update(storageId, poolVO);
-
-        List<HostVO> hosts = _resourceMgr.listHostsInClusterByStatus(
-                pool.getClusterId(), Status.Up);
-        if (hosts == null || hosts.size() == 0) {
-            return true;
-        }
-        // add heartbeat
-        for (HostVO host : hosts) {
-            ModifyStoragePoolCommand msPoolCmd = new ModifyStoragePoolCommand(
-                    true, pool);
-            final Answer answer = agentMgr.easySend(host.getId(), msPoolCmd);
-            if (answer == null || !answer.getResult()) {
-                if (s_logger.isDebugEnabled()) {
-                    s_logger.debug("ModifyStoragePool add failed due to "
-                            + ((answer == null) ? "answer null" : answer
-                                    .getDetails()));
-                }
-            } else {
-                if (s_logger.isDebugEnabled()) {
-                    s_logger.debug("ModifyStoragePool add secceeded");
-                }
-            }
-        }
-
-        // 2. Get a list of pending work for this queue
-        List<StoragePoolWorkVO> pendingWork = _storagePoolWorkDao
-                .listPendingWorkForCancelMaintenanceByPoolId(poolVO.getId());
-
-        // 3. work through the queue
-        for (StoragePoolWorkVO work : pendingWork) {
-            try {
-                VMInstanceVO vmInstance = vmDao.findById(work.getVmId());
-
-                if (vmInstance == null) {
-                    continue;
-                }
-
-                // if the instance is of type consoleproxy, call the console
-                // proxy
-                if (vmInstance.getType().equals(
-                        VirtualMachine.Type.ConsoleProxy)) {
-
-                    ConsoleProxyVO consoleProxy = _consoleProxyDao
-                            .findById(vmInstance.getId());
-                    if (vmMgr.advanceStart(consoleProxy, null, user, account) == null) {
-                        String msg = "There was an error starting the console proxy id: "
-                                + vmInstance.getId()
-                                + " on storage pool, cannot complete primary storage maintenance";
-                        s_logger.warn(msg);
-                        throw new ExecutionException(msg);
-                    } else {
-                        // update work queue
-                        work.setStartedAfterMaintenance(true);
-                        _storagePoolWorkDao.update(work.getId(), work);
-                    }
-                }
-
-                // if the instance is of type ssvm, call the ssvm manager
-                if (vmInstance.getType().equals(
-                        VirtualMachine.Type.SecondaryStorageVm)) {
-                    SecondaryStorageVmVO ssVm = _secStrgDao.findById(vmInstance
-                            .getId());
-                    if (vmMgr.advanceStart(ssVm, null, user, account) == null) {
-                        String msg = "There was an error starting the ssvm id: "
-                                + vmInstance.getId()
-                                + " on storage pool, cannot complete primary storage maintenance";
-                        s_logger.warn(msg);
-                        throw new ExecutionException(msg);
-                    } else {
-                        // update work queue
-                        work.setStartedAfterMaintenance(true);
-                        _storagePoolWorkDao.update(work.getId(), work);
-                    }
-                }
-
-                // if the instance is of type ssvm, call the ssvm manager
-                if (vmInstance.getType().equals(
-                        VirtualMachine.Type.DomainRouter)) {
-                    DomainRouterVO domR = _domrDao.findById(vmInstance.getId());
-                    if (vmMgr.advanceStart(domR, null, user, account) == null) {
-                        String msg = "There was an error starting the domR id: "
-                                + vmInstance.getId()
-                                + " on storage pool, cannot complete primary storage maintenance";
-                        s_logger.warn(msg);
-                        throw new ExecutionException(msg);
-                    } else {
-                        // update work queue
-                        work.setStartedAfterMaintenance(true);
-                        _storagePoolWorkDao.update(work.getId(), work);
-                    }
-                }
-
-                // if the instance is of type user vm, call the user vm manager
-                if (vmInstance.getType().equals(VirtualMachine.Type.User)) {
-                    UserVmVO userVm = userVmDao.findById(vmInstance.getId());
-
-                    if (vmMgr.advanceStart(userVm, null, user, account) == null) {
-
-                        String msg = "There was an error starting the user vm id: "
-                                + vmInstance.getId()
-                                + " on storage pool, cannot complete primary storage maintenance";
-                        s_logger.warn(msg);
-                        throw new ExecutionException(msg);
-                    } else {
-                        // update work queue
-                        work.setStartedAfterMaintenance(true);
-                        _storagePoolWorkDao.update(work.getId(), work);
-                    }
-                }
-            } catch (Exception e) {
-                s_logger.debug("Failed start vm", e);
-                throw new CloudRuntimeException(e.toString());
-            }
-        }
-        return true;
-    }
-
-    @DB
-    @Override
-    public boolean deleteDataStore(long storeId) {
-        // for the given pool id, find all records in the storage_pool_host_ref
-        List<StoragePoolHostVO> hostPoolRecords = this._storagePoolHostDao
-                .listByPoolId(storeId);
-        StoragePoolVO poolVO = this.primaryDataStoreDao.findById(storeId);
-        StoragePool pool = (StoragePool)this.dataStoreMgr.getDataStore(storeId, DataStoreRole.Primary);
-        boolean deleteFlag = false;
-        Transaction txn = Transaction.currentTxn();
-        try {
-            // if not records exist, delete the given pool (base case)
-            if (hostPoolRecords.size() == 0) {
-
-                txn.start();
-                poolVO.setUuid(null);
-                this.primaryDataStoreDao.update(poolVO.getId(), poolVO);
-                primaryDataStoreDao.remove(poolVO.getId());
-                deletePoolStats(poolVO.getId());
-                txn.commit();
-
-                deleteFlag = true;
-                return true;
-            } else {
-                // Remove the SR associated with the Xenserver
-                for (StoragePoolHostVO host : hostPoolRecords) {
-                    DeleteStoragePoolCommand deleteCmd = new DeleteStoragePoolCommand(
-                            pool);
-                    final Answer answer = agentMgr.easySend(host.getHostId(),
-                            deleteCmd);
-
-                    if (answer != null && answer.getResult()) {
-                        deleteFlag = true;
-                        break;
-                    }
-                }
-            }
-        } finally {
-            if (deleteFlag) {
-                // now delete the storage_pool_host_ref and storage_pool records
-                txn.start();
-                for (StoragePoolHostVO host : hostPoolRecords) {
-                    _storagePoolHostDao.deleteStoragePoolHostDetails(
-                            host.getHostId(), host.getPoolId());
-                }
-                poolVO.setUuid(null);
-                this.primaryDataStoreDao.update(poolVO.getId(), poolVO);
-                primaryDataStoreDao.remove(poolVO.getId());
-                deletePoolStats(poolVO.getId());
-                // Delete op_host_capacity entries
-                this._capacityDao.removeBy(Capacity.CAPACITY_TYPE_STORAGE_ALLOCATED,
-                        null, null, null, poolVO.getId());
-                txn.commit();
-
-                s_logger.debug("Storage pool id=" + poolVO.getId()
-                        + " is removed successfully");
-                return true;
-            } else {
-                // alert that the storage cleanup is required
-                s_logger.warn("Failed to Delete storage pool id: " + poolVO.getId());
-                _alertMgr
-                        .sendAlert(AlertManager.ALERT_TYPE_STORAGE_DELETE,
-                                poolVO.getDataCenterId(), poolVO.getPodId(),
-                                "Unable to delete storage pool id= " + poolVO.getId(),
-                                "Delete storage pool command failed.  Please check logs.");
-            }
-        }
-        return false;
-    }
-
-    @DB
-    private boolean deletePoolStats(Long poolId) {
-        CapacityVO capacity1 = _capacityDao.findByHostIdType(poolId,
-                CapacityVO.CAPACITY_TYPE_STORAGE);
-        CapacityVO capacity2 = _capacityDao.findByHostIdType(poolId,
-                CapacityVO.CAPACITY_TYPE_STORAGE_ALLOCATED);
-        Transaction txn = Transaction.currentTxn();
-        txn.start();
-        if (capacity1 != null) {
-            _capacityDao.remove(capacity1.getId());
-        }
-
-        if (capacity2 != null) {
-            _capacityDao.remove(capacity2.getId());
-        }
-
-        txn.commit();
-        return true;
-    }
-
-    @Override
-    public boolean attachHost(DataStore store, HostScope scope, StoragePoolInfo existingInfo) {
-        StoragePoolHostVO poolHost = _storagePoolHostDao.findByPoolHost(store.getId(), scope.getScopeId());
-        if (poolHost == null) {
-            poolHost = new StoragePoolHostVO(store.getId(), scope.getScopeId(), existingInfo.getLocalPath());
-            _storagePoolHostDao.persist(poolHost);
-        }
-       
-        StoragePoolVO pool = this.primaryDataStoreDao.findById(store.getId());
-        pool.setScope(scope.getScopeType());
-        pool.setAvailableBytes(existingInfo.getAvailableBytes());
-        pool.setCapacityBytes(existingInfo.getCapacityBytes());
-        pool.setStatus(StoragePoolStatus.Up);
-        this.primaryDataStoreDao.update(pool.getId(), pool);
-        this.storageMgr.createCapacityEntry(pool, Capacity.CAPACITY_TYPE_LOCAL_STORAGE, pool.getCapacityBytes() - pool.getAvailableBytes());
-        
-        return true;
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3ed6200e/engine/storage/volume/src/org/apache/cloudstack/storage/datastore/lifecycle/DefaultPrimaryDataStoreLifeCycleImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/volume/src/org/apache/cloudstack/storage/datastore/lifecycle/DefaultPrimaryDataStoreLifeCycleImpl.java b/engine/storage/volume/src/org/apache/cloudstack/storage/datastore/lifecycle/DefaultPrimaryDataStoreLifeCycleImpl.java
index 5e8727a..fea02e8 100644
--- a/engine/storage/volume/src/org/apache/cloudstack/storage/datastore/lifecycle/DefaultPrimaryDataStoreLifeCycleImpl.java
+++ b/engine/storage/volume/src/org/apache/cloudstack/storage/datastore/lifecycle/DefaultPrimaryDataStoreLifeCycleImpl.java
@@ -60,8 +60,8 @@ public class DefaultPrimaryDataStoreLifeCycleImpl implements PrimaryDataStoreLif
     @Override
     public DataStore initialize(Map<String, Object> dsInfos) {
         
-        StoragePoolVO storeVO = primaryStoreHelper.createPrimaryDataStore(dsInfos); 
-        return providerMgr.getPrimaryDataStore(storeVO.getId());
+        DataStore store = primaryStoreHelper.createPrimaryDataStore(null); 
+        return providerMgr.getPrimaryDataStore(store.getId());
     }
 
     protected void attachCluster(DataStore store) {
@@ -114,34 +114,32 @@ public class DefaultPrimaryDataStoreLifeCycleImpl implements PrimaryDataStoreLif
     }
 
     @Override
-    public boolean maintain(long storeId) {
+    public boolean attachZone(DataStore dataStore, ZoneScope scope) {
         // TODO Auto-generated method stub
         return false;
     }
 
     @Override
-    public boolean cancelMaintain(long storeId) {
+    public boolean attachHost(DataStore store, HostScope scope,
+            StoragePoolInfo existingInfo) {
         // TODO Auto-generated method stub
         return false;
     }
 
     @Override
-    public boolean deleteDataStore(long storeId) {
+    public boolean maintain(DataStore store) {
         // TODO Auto-generated method stub
         return false;
     }
 
-
-
     @Override
-    public boolean attachZone(DataStore dataStore, ZoneScope scope) {
+    public boolean cancelMaintain(DataStore store) {
         // TODO Auto-generated method stub
         return false;
     }
 
     @Override
-    public boolean attachHost(DataStore store, HostScope scope,
-            StoragePoolInfo existingInfo) {
+    public boolean deleteDataStore(DataStore store) {
         // TODO Auto-generated method stub
         return false;
     }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3ed6200e/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 e181ada..e38c3b3 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
@@ -57,18 +57,18 @@ public class DefaultPrimaryDataStoreProviderManagerImpl implements PrimaryDataSt
     @Override
     public PrimaryDataStore getPrimaryDataStore(long dataStoreId) {
         StoragePoolVO dataStoreVO = dataStoreDao.findById(dataStoreId);
-        long providerId = dataStoreVO.getStorageProviderId();
-        DataStoreProvider provider = providerManager.getDataStoreProviderById(providerId);
-        DefaultPrimaryDataStore dataStore = DefaultPrimaryDataStore.createDataStore(dataStoreVO, driverMaps.get(provider.getUuid()), provider);
+        String providerName = dataStoreVO.getStorageProviderName();
+        DataStoreProvider provider = providerManager.getDataStoreProvider(providerName);
+        DefaultPrimaryDataStore dataStore = DefaultPrimaryDataStore.createDataStore(dataStoreVO, driverMaps.get(provider.getName()), provider);
         return dataStore;
     }
     
     @Override
-    public boolean registerDriver(String uuid, PrimaryDataStoreDriver driver) {
-        if (driverMaps.get(uuid) != null) {
+    public boolean registerDriver(String providerName, PrimaryDataStoreDriver driver) {
+        if (driverMaps.get(providerName) != null) {
             return false;
         }
-        driverMaps.put(uuid, driver);
+        driverMaps.put(providerName, driver);
         return true;
     }
 
@@ -79,7 +79,7 @@ public class DefaultPrimaryDataStoreProviderManagerImpl implements PrimaryDataSt
     }
 
     @Override
-    public boolean registerHostListener(String uuid, HypervisorHostListener listener) {
-        return storageMgr.registerHostListener(uuid, listener);
+    public boolean registerHostListener(String providerName, HypervisorHostListener listener) {
+        return storageMgr.registerHostListener(providerName, listener);
     }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3ed6200e/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
deleted file mode 100644
index 09e78e4..0000000
--- a/engine/storage/volume/src/org/apache/cloudstack/storage/datastore/provider/AncientPrimaryDataStoreProviderImpl.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.cloudstack.storage.datastore.provider;
-
-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.HypervisorHostListener;
-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.AncientPrimaryDataStoreLifeCycleImpl;
-import org.springframework.stereotype.Component;
-
-import com.cloud.utils.component.ComponentContext;
-
-@Component
-public class AncientPrimaryDataStoreProviderImpl implements
-        PrimaryDataStoreProvider {
-
-    private final String providerName = "ancient primary data store provider";
-    protected PrimaryDataStoreDriver driver;
-    @Inject
-    PrimaryDataStoreProviderManager storeMgr;
-    protected DataStoreLifeCycle lifecyle;
-    protected String uuid;
-    protected long id;
-    @Override
-    public String getName() {
-        return providerName;
-    }
-
-    @Override
-    public DataStoreLifeCycle getLifeCycle() {
-        return this.lifecyle;
-    }
-
-    @Override
-    public boolean configure(Map<String, Object> params) {
-        lifecyle = ComponentContext.inject(AncientPrimaryDataStoreLifeCycleImpl.class);
-        driver = ComponentContext.inject(AncientPrimaryDataStoreDriverImpl.class);
-        uuid = (String)params.get("uuid");
-        id = (Long)params.get("id");
-        storeMgr.registerDriver(uuid, this.driver);
-        HypervisorHostListener listener = ComponentContext.inject(DefaultHostListener.class);
-        storeMgr.registerHostListener(uuid, listener);
-        return true;
-    }
-
-    @Override
-    public String getUuid() {
-        return this.uuid;
-    }
-
-    @Override
-    public long getId() {
-        return this.id;
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3ed6200e/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 a1402c1..46fa738 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
@@ -16,24 +16,29 @@
 // under the License.
 package org.apache.cloudstack.storage.datastore.provider;
 
+import java.util.HashSet;
 import java.util.Map;
+import java.util.Set;
 
 import javax.inject.Inject;
 
 import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreLifeCycle;
+import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider;
 import org.apache.cloudstack.engine.subsystem.api.storage.HypervisorHostListener;
 import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreDriver;
+import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreProvider;
+import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider.DataStoreProviderType;
 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.springframework.stereotype.Component;
 
 import com.cloud.utils.component.ComponentContext;
 
-@Component
+
 public class DefaultPrimaryDatastoreProviderImpl implements PrimaryDataStoreProvider {
     private final String providerName = "default primary data store provider";
     protected PrimaryDataStoreDriver driver;
+    protected HypervisorHostListener listener;
     @Inject
     PrimaryDataStoreProviderManager storeMgr;
 
@@ -46,7 +51,7 @@ public class DefaultPrimaryDatastoreProviderImpl implements PrimaryDataStoreProv
     }
 
     @Override
-    public DataStoreLifeCycle getLifeCycle() {
+    public DataStoreLifeCycle getDataStoreLifeCycle() {
         return this.lifecyle;
     }
 
@@ -54,22 +59,25 @@ public class DefaultPrimaryDatastoreProviderImpl implements PrimaryDataStoreProv
     public boolean configure(Map<String, Object> params) {
         lifecyle = ComponentContext.inject(DefaultPrimaryDataStoreLifeCycleImpl.class);
         driver = ComponentContext.inject(DefaultPrimaryDataStoreDriverImpl.class);
-        HypervisorHostListener listener = ComponentContext.inject(DefaultHostListener.class);
-        uuid = (String)params.get("uuid");
-        id = (Long)params.get("id");
-        storeMgr.registerDriver(uuid, this.driver);
-        storeMgr.registerHostListener(uuid, listener);
+        listener = ComponentContext.inject(DefaultHostListener.class);
         return true;
     }
 
     @Override
-    public String getUuid() {
-        return this.uuid;
+    public PrimaryDataStoreDriver getDataStoreDriver() {
+        return this.driver;
     }
 
     @Override
-    public long getId() {
-        return this.id;
+    public HypervisorHostListener getHostListener() {
+        return this.listener;
+    }
+    
+    @Override
+    public Set<DataStoreProviderType> getTypes() {
+        Set<DataStoreProviderType> types =  new HashSet<DataStoreProviderType>();
+        types.add(DataStoreProviderType.PRIMARY);
+        return types;
     }
 
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3ed6200e/engine/storage/volume/test/org/apache/cloudstack/storage/volume/test/ConfiguratorTest.java
----------------------------------------------------------------------
diff --git a/engine/storage/volume/test/org/apache/cloudstack/storage/volume/test/ConfiguratorTest.java b/engine/storage/volume/test/org/apache/cloudstack/storage/volume/test/ConfiguratorTest.java
index 829694b..122c353 100644
--- a/engine/storage/volume/test/org/apache/cloudstack/storage/volume/test/ConfiguratorTest.java
+++ b/engine/storage/volume/test/org/apache/cloudstack/storage/volume/test/ConfiguratorTest.java
@@ -28,7 +28,7 @@ import java.util.Map;
 import javax.inject.Inject;
 import javax.naming.ConfigurationException;
 
-import org.apache.cloudstack.storage.datastore.provider.PrimaryDataStoreProvider;
+import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreProvider;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3ed6200e/plugins/pom.xml
----------------------------------------------------------------------
diff --git a/plugins/pom.xml b/plugins/pom.xml
index 5d31a72..39d9907 100755
--- a/plugins/pom.xml
+++ b/plugins/pom.xml
@@ -57,6 +57,7 @@
     <module>network-elements/dns-notifier</module>
     <module>storage/image/s3</module>
     <module>storage/volume/solidfire</module>
+    <module>storage/volume/default</module>
     <module>alert-handlers/snmp-alerts</module>
   </modules>
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3ed6200e/plugins/storage/volume/default/pom.xml
----------------------------------------------------------------------
diff --git a/plugins/storage/volume/default/pom.xml b/plugins/storage/volume/default/pom.xml
new file mode 100644
index 0000000..1eb2e12
--- /dev/null
+++ b/plugins/storage/volume/default/pom.xml
@@ -0,0 +1,56 @@
+<!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor 
+  license agreements. See the NOTICE file distributed with this work for additional 
+  information regarding copyright ownership. The ASF licenses this file to 
+  you under the Apache License, Version 2.0 (the "License"); you may not use 
+  this file except in compliance with the License. You may obtain a copy of 
+  the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required 
+  by applicable law or agreed to in writing, software distributed under the 
+  License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS 
+  OF ANY KIND, either express or implied. See the License for the specific 
+  language governing permissions and limitations under the License. -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <artifactId>cloud-plugin-storage-volume-default</artifactId>
+  <name>Apache CloudStack Plugin - Storage Volume default provider</name>
+  <parent>
+    <groupId>org.apache.cloudstack</groupId>
+    <artifactId>cloudstack-plugins</artifactId>
+    <version>4.2.0-SNAPSHOT</version>
+    <relativePath>../../../pom.xml</relativePath>
+  </parent>
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.cloudstack</groupId>
+      <artifactId>cloud-engine-storage-volume</artifactId>
+      <version>${project.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>mysql</groupId>
+      <artifactId>mysql-connector-java</artifactId>
+      <version>${cs.mysql.version}</version>
+      <scope>provided</scope>
+    </dependency>
+  </dependencies>
+  <build>
+    <defaultGoal>install</defaultGoal>
+    <sourceDirectory>src</sourceDirectory>
+    <testSourceDirectory>test</testSourceDirectory>
+    <plugins>
+      <plugin>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <configuration>
+          <skipTests>true</skipTests>
+        </configuration>
+        <executions>
+          <execution>
+            <phase>integration-test</phase>
+            <goals>
+              <goal>test</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+</project>

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3ed6200e/plugins/storage/volume/default/src/org/apache/cloudstack/storage/datastore/driver/CloudStackPrimaryDataStoreDriverImpl.java
----------------------------------------------------------------------
diff --git a/plugins/storage/volume/default/src/org/apache/cloudstack/storage/datastore/driver/CloudStackPrimaryDataStoreDriverImpl.java b/plugins/storage/volume/default/src/org/apache/cloudstack/storage/datastore/driver/CloudStackPrimaryDataStoreDriverImpl.java
new file mode 100644
index 0000000..0486902
--- /dev/null
+++ b/plugins/storage/volume/default/src/org/apache/cloudstack/storage/datastore/driver/CloudStackPrimaryDataStoreDriverImpl.java
@@ -0,0 +1,362 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cloudstack.storage.datastore.driver;
+
+import java.util.Set;
+
+import javax.inject.Inject;
+
+import org.apache.cloudstack.engine.subsystem.api.storage.CommandResult;
+import org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult;
+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.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.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 CloudStackPrimaryDataStoreDriverImpl implements PrimaryDataStoreDriver {
+	private static final Logger s_logger = Logger
+			.getLogger(CloudStackPrimaryDataStoreDriverImpl.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;
+	}
+
+	@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);
+
+		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) {
+	    CreateCmdResult result = null;
+	    try {
+	        VolumeInfo volume = snapshot.getBaseVolume();
+	        String vmName = this.volumeMgr.getVmNameOnVolume(volume);
+	        SnapshotVO preSnapshotVO = this.snapshotMgr.getParentSnapshot(volume, snapshot);
+	        String parentSnapshotPath = null;
+	        if (preSnapshotVO != null) {
+	            parentSnapshotPath = preSnapshotVO.getPath();
+	        }
+	        StoragePool srcPool = (StoragePool)volume.getDataStore();
+	        
+	        ManageSnapshotCommand cmd = new ManageSnapshotCommand(snapshot.getId(), volume.getPath(), srcPool, parentSnapshotPath, snapshot.getName(), vmName);
+
+	        ManageSnapshotAnswer answer = (ManageSnapshotAnswer) this.snapshotMgr.sendToPool(volume, cmd);
+	        
+	        if ((answer != null) && answer.getResult()) {
+	            result = new CreateCmdResult(answer.getSnapshotPath(), null);
+	        } else {
+	            result = new CreateCmdResult(null, null);
+	        }
+	    } catch (Exception e) {
+	        s_logger.debug("Failed to take snapshot: " + snapshot.getId(), e);
+	        result = new CreateCmdResult(null, null);
+	        result.setResult(e.toString());
+	    }
+        callback.complete(result);
+	}
+
+	@Override
+	public void revertSnapshot(SnapshotInfo snapshot,
+			AsyncCompletionCallback<CommandResult> callback) {
+		// TODO Auto-generated method stub
+
+	}
+
+	@Override
+	public void resize(DataObject data,
+			AsyncCompletionCallback<CreateCmdResult> callback) {
+		VolumeObject vol = (VolumeObject)data;
+		StoragePool pool = (StoragePool)data.getDataStore();
+		ResizeVolumePayload resizeParameter = (ResizeVolumePayload)vol.getpayload();
+
+		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);
+
+				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);
+	}
+
+}


Mime
View raw message