cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mtutkow...@apache.org
Subject [3/3] git commit: updated refs/heads/master to f3cbb69
Date Fri, 18 Jul 2014 03:35:18 GMT
first commit of improvised cloudbyte storage plugin

Signed-off-by: Mike Tutkowski <mike.tutkowski@solidfire.com>


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/f3cbb699
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/f3cbb699
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/f3cbb699

Branch: refs/heads/master
Commit: f3cbb699955243007ffb53b335d9508b2e422a06
Parents: b080eaf
Author: punith-cloudbyte <punith.s@cloudbyte.com>
Authored: Fri Jul 11 16:35:23 2014 +0530
Committer: Mike Tutkowski <mike.tutkowski@solidfire.com>
Committed: Thu Jul 17 21:34:37 2014 -0600

----------------------------------------------------------------------
 .../spring-storage-volume-cloudbyte-context.xml |   16 +-
 .../ElastistorPrimaryDataStoreDriver.java       |  325 ++-
 .../ElastistorPrimaryDataStoreLifeCycle.java    |  527 +++--
 .../provider/ElastistorHostListener.java        |   27 +-
 .../ElastistorPrimaryDataStoreProvider.java     |   97 +-
 .../storage/datastore/util/ElastistorUtil.java  | 2042 +++++++++++++++---
 .../util/ElastistorVolumeApiService.java        |   32 +
 .../util/ElastistorVolumeApiServiceImpl.java    |  206 ++
 .../util/ListElastistorInterfaceCmd.java        |   58 +
 .../util/ListElastistorInterfaceResponse.java   |   63 +
 .../datastore/util/ListElastistorPoolCmd.java   |   61 +
 .../util/ListElastistorPoolResponse.java        |  114 +
 .../datastore/util/ListElastistorVolumeCmd.java |   59 +
 .../util/ListElastistorVolumeResponse.java      |   99 +
 14 files changed, 3130 insertions(+), 596 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f3cbb699/plugins/storage/volume/cloudbyte/resources/META-INF/cloudstack/storage-volume-cloudbyte/spring-storage-volume-cloudbyte-context.xml
----------------------------------------------------------------------
diff --git a/plugins/storage/volume/cloudbyte/resources/META-INF/cloudstack/storage-volume-cloudbyte/spring-storage-volume-cloudbyte-context.xml b/plugins/storage/volume/cloudbyte/resources/META-INF/cloudstack/storage-volume-cloudbyte/spring-storage-volume-cloudbyte-context.xml
index 87c5f51..4a56482 100755
--- a/plugins/storage/volume/cloudbyte/resources/META-INF/cloudstack/storage-volume-cloudbyte/spring-storage-volume-cloudbyte-context.xml
+++ b/plugins/storage/volume/cloudbyte/resources/META-INF/cloudstack/storage-volume-cloudbyte/spring-storage-volume-cloudbyte-context.xml
@@ -28,13 +28,11 @@
                       >
 
     <bean id="elastistorDataStoreProvider"
-        class="org.apache.cloudstack.storage.datastore.provider.ElastistorPrimaryDataStoreProvider">
-        <property name="esmanagementip" value="10.10.171.180"/>
-        <property name="esapikey" value="PubSInZaCji8hrRfOsCxgbug2I2k_sRJ0i2a9qmAzZIiCTcFPmZelzx6uNK9TYgqkdohCmq1L2J9eYmUe9YO6A"/>
-        <property name="esaccountid" value="9e9f67d5-e06f-4d63-a0b8-e7255cba84b8"/>
-        <property name="espoolid" value="d2d15d11-0f06-3426-a097-3e6e8b36f85c"/>
-        <property name="esdefaultgateway" value="10.10.1.1"/>
-        <property name="essubnet" value="8"/>
-        <property name="estntinterface" value="em0"/>
-  </bean>
+		class="org.apache.cloudstack.storage.datastore.provider.ElastistorPrimaryDataStoreProvider">
+	</bean>
+
+	<bean id="elastistorVolumeApiService"
+		class="org.apache.cloudstack.storage.datastore.util.ElastistorVolumeApiServiceImpl">
+		<property name="name" value="elastistorVolumeApiService" />
+	</bean>
 </beans>

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f3cbb699/plugins/storage/volume/cloudbyte/src/org/apache/cloudstack/storage/datastore/driver/ElastistorPrimaryDataStoreDriver.java
----------------------------------------------------------------------
diff --git a/plugins/storage/volume/cloudbyte/src/org/apache/cloudstack/storage/datastore/driver/ElastistorPrimaryDataStoreDriver.java b/plugins/storage/volume/cloudbyte/src/org/apache/cloudstack/storage/datastore/driver/ElastistorPrimaryDataStoreDriver.java
index 99d1e2a..a4f38ce 100755
--- a/plugins/storage/volume/cloudbyte/src/org/apache/cloudstack/storage/datastore/driver/ElastistorPrimaryDataStoreDriver.java
+++ b/plugins/storage/volume/cloudbyte/src/org/apache/cloudstack/storage/datastore/driver/ElastistorPrimaryDataStoreDriver.java
@@ -18,6 +18,7 @@
  */
 package org.apache.cloudstack.storage.datastore.driver;
 
+import java.util.Map;
 
 import javax.inject.Inject;
 
@@ -31,14 +32,39 @@ 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.command.CommandResult;
+import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
+import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
+import org.apache.cloudstack.storage.datastore.util.ElastistorUtil;
+import org.apache.cloudstack.storage.datastore.util.ElastistorUtil.FileSystem;
+import org.apache.cloudstack.storage.to.SnapshotObjectTO;
+import org.apache.cloudstack.storage.volume.VolumeObject;
 import org.apache.log4j.Logger;
 
+import com.cloud.agent.api.Answer;
+import com.cloud.agent.api.to.DataObjectType;
 import com.cloud.agent.api.to.DataStoreTO;
 import com.cloud.agent.api.to.DataTO;
+import com.cloud.host.Host;
+import com.cloud.storage.DiskOfferingVO;
+import com.cloud.storage.ResizeVolumePayload;
+import com.cloud.storage.Storage.StoragePoolType;
+import com.cloud.storage.StorageManager;
+import com.cloud.storage.StoragePool;
+import com.cloud.storage.Volume;
+import com.cloud.storage.VolumeDetailVO;
+import com.cloud.storage.VolumeVO;
 import com.cloud.storage.dao.DiskOfferingDao;
+import com.cloud.storage.dao.VolumeDao;
+import com.cloud.storage.dao.VolumeDetailsDao;
 import com.cloud.user.AccountManager;
+import com.cloud.utils.exception.CloudRuntimeException;
 
-public class ElastistorPrimaryDataStoreDriver  extends CloudStackPrimaryDataStoreDriverImpl implements PrimaryDataStoreDriver{
+/**
+ * The implementation class for <code>ElastistorPrimaryDataStoreDriver</code>.
+ * This directs the public interface methods to use CloudByte's Elastistor based
+ * volumes.
+ */
+public class ElastistorPrimaryDataStoreDriver extends CloudStackPrimaryDataStoreDriverImpl implements PrimaryDataStoreDriver {
 
     private static final Logger s_logger = Logger.getLogger(ElastistorPrimaryDataStoreDriver.class);
 
@@ -46,6 +72,15 @@ public class ElastistorPrimaryDataStoreDriver  extends CloudStackPrimaryDataStor
     AccountManager _accountMgr;
     @Inject
     DiskOfferingDao _diskOfferingDao;
+    @Inject
+    private VolumeDao _volumeDao;
+    @Inject
+    private PrimaryDataStoreDao _storagePoolDao;
+    @Inject
+    StorageManager storageMgr;
+    @Inject
+    VolumeDetailsDao _volumeDetailsDao;
+
     @Override
     public DataTO getTO(DataObject data) {
         return null;
@@ -57,11 +92,167 @@ public class ElastistorPrimaryDataStoreDriver  extends CloudStackPrimaryDataStor
     }
 
     public void createAsync(DataStore dataStore, DataObject dataObject, AsyncCompletionCallback<CreateCmdResult> callback) {
-         super.createAsync(dataStore, dataObject, callback);
+
+        String iqn = null;
+        String errMsg = null;
+
+        CreateCmdResult result = new CreateCmdResult(iqn, new Answer(null, errMsg == null, errMsg));
+
+        if (dataObject.getType() == DataObjectType.VOLUME) {
+
+            VolumeInfo volumeInfo = (VolumeInfo) dataObject;
+
+            long storagePoolId = dataStore.getId();
+            String volumeName = volumeInfo.getName();
+            Long Iops = volumeInfo.getMaxIops();
+            // quota size of the cloudbyte volume will be increased with the given HypervisorSnapshotReserve
+            Long quotaSize = getVolumeSizeIncludingHypervisorSnapshotReserve(volumeInfo, _storagePoolDao.findById(storagePoolId));
+
+            StoragePoolVO storagePool = _storagePoolDao.findById(dataStore.getId());
+            VolumeVO volume = _volumeDao.findById(volumeInfo.getId());
+
+            // if the primary storage is not managed (thick provisioned)
+            // then no need to create volume at elastistor,
+            // calling super(default) that creates a vdi(disk) only.
+            if (!(storagePool.isManaged())) {
+                super.createAsync(dataStore, dataObject, callback);
+
+                // update the volume property
+                volume.setPoolType(storagePool.getPoolType());
+                _volumeDao.update(volume.getId(), volume);
+
+                return;
+            }
+
+            DiskOfferingVO diskOffering = _diskOfferingDao.findById(volumeInfo.getDiskOfferingId());
+
+            long capacityIops = storagePool.getCapacityIops();
+            capacityIops = capacityIops - Iops;
+
+            if (capacityIops < 0) {
+                throw new CloudRuntimeException("IOPS not available. [pool:" + storagePool.getName() + "] [availiops:" + capacityIops + "] [requirediops:" + Iops + "]");
+            }
+
+            String protocoltype = null;
+            StoragePoolVO dataStoreVO = (StoragePoolVO) _storagePoolDao.findById(storagePoolId);
+            String desc = diskOffering.getDisplayText();
+
+            if (desc.toLowerCase().contains("iscsi")) {
+                protocoltype = "iscsi";
+            } else if (dataStoreVO.getPoolType().equals(StoragePoolType.NetworkFilesystem) || dataStoreVO.getPoolType().equals(StoragePoolType.Filesystem)) {
+                protocoltype = "nfs";
+            } else {
+                protocoltype = "iscsi";
+            }
+
+            FileSystem esvolume = null;
+            try {
+                esvolume = ElastistorUtil.createElastistorVolume(volumeName, dataStoreVO.getUuid(), quotaSize, Iops, protocoltype, volumeName);
+            } catch (Throwable e) {
+                s_logger.error(e.toString(), e);
+                result.setResult(e.toString());
+                callback.complete(result);
+                throw new CloudRuntimeException(e.getMessage());
+            }
+
+            if (esvolume.getNfsenabled().equalsIgnoreCase("true")) {
+                volume.set_iScsiName(esvolume.getPath());
+                volume.setPoolType(StoragePoolType.NetworkFilesystem);
+            } else {
+                iqn = esvolume.getIqn();
+                String modifiediqn = "/" + iqn + "/0";
+                volume.set_iScsiName(modifiediqn);
+                volume.setPoolType(StoragePoolType.IscsiLUN);
+            }
+
+            volume.setFolder(String.valueOf(esvolume.getUuid()));
+            volume.setPoolId(storagePoolId);
+            volume.setUuid(esvolume.getUuid());
+            volume.setPath(null);
+
+            _volumeDao.update(volume.getId(), volume);
+
+            // create new volume details for the volume
+            updateVolumeDetails(volume, esvolume);
+
+            long capacityBytes = storagePool.getCapacityBytes();
+            long usedBytes = storagePool.getUsedBytes();
+
+            Long inbytes = volume.getSize();
+
+            usedBytes += inbytes;
+
+            storagePool.setCapacityIops(capacityIops);
+            storagePool.setUsedBytes(usedBytes > capacityBytes ? capacityBytes : usedBytes);
+
+            _storagePoolDao.update(storagePoolId, storagePool);
+            s_logger.info("Elastistor volume creation complete.");
+        } else {
+            errMsg = "Invalid DataObjectType (" + dataObject.getType() + ") passed to createAsync";
+            s_logger.error(errMsg);
+        }
+
+        result.setResult(errMsg);
+
+        callback.complete(result);
     }
 
     public void deleteAsync(DataStore dataStore, DataObject dataObject, AsyncCompletionCallback<CommandResult> callback) {
-         super.deleteAsync(dataStore, dataObject, callback);
+
+        String errMsg = null;
+
+        StoragePoolVO storagePool = _storagePoolDao.findById(dataStore.getId());
+
+        // if the primary storage is not managed(thick provisioned) then no need
+        // to delete volume at elastistor, just
+        // call the super(default) to delete a vdi(disk) only.
+
+        if (!(storagePool.isManaged())) {
+            super.deleteAsync(dataStore, dataObject, callback);
+            return;
+        }
+
+        if (dataObject.getType() == DataObjectType.VOLUME) {
+            VolumeInfo volumeInfo = (VolumeInfo) dataObject;
+
+            long storagePoolId = dataStore.getId();
+            boolean result = false;
+            try {
+                result = ElastistorUtil.deleteElastistorVolume(volumeInfo.getUuid());
+            } catch (Throwable e) {
+                e.printStackTrace();
+                CommandResult result2 = new CommandResult();
+                result2.setResult(e.toString());
+                callback.complete(result2);
+            }
+
+            if (result) {
+
+                _volumeDao.deleteVolumesByInstance(volumeInfo.getId());
+
+                long usedBytes = storagePool.getUsedBytes();
+                long capacityIops = storagePool.getCapacityIops();
+
+                usedBytes -= volumeInfo != null ? volumeInfo.getSize() : 0;
+                capacityIops += volumeInfo != null ? volumeInfo.getMaxIops() : 0;
+
+                storagePool.setUsedBytes(usedBytes < 0 ? 0 : usedBytes);
+                storagePool.setCapacityIops(capacityIops < 0 ? 0 : capacityIops);
+
+                _storagePoolDao.update(storagePoolId, storagePool);
+            } else {
+                errMsg = "Invalid DataObjectType (" + dataObject.getType() + ") passed to deleteAsync";
+            }
+
+        } else {
+            errMsg = "Invalid DataObjectType (" + dataObject.getType() + ") passed to deleteAsync";
+        }
+
+        CommandResult result = new CommandResult();
+
+        result.setResult(errMsg);
+
+        callback.complete(result);
     }
 
     @Override
@@ -77,16 +268,120 @@ public class ElastistorPrimaryDataStoreDriver  extends CloudStackPrimaryDataStor
 
     @Override
     public void resize(DataObject data, AsyncCompletionCallback<CreateCmdResult> callback) {
-        throw new UnsupportedOperationException();
+
+        s_logger.debug("Resize elastistor volume started");
+        Boolean status = false;
+        VolumeObject vol = (VolumeObject) data;
+        StoragePool pool = (StoragePool) data.getDataStore();
+
+        ResizeVolumePayload resizeParameter = (ResizeVolumePayload) vol.getpayload();
+
+        CreateCmdResult result = new CreateCmdResult(null, null);
+
+        StoragePoolVO poolVO = _storagePoolDao.findById(pool.getId());
+
+        if (!(poolVO.isManaged())) {
+            super.resize(data, callback);
+            return;
+        }
+
+        try {
+
+            status = ElastistorUtil.updateElastistorVolumeSize(vol.getUuid(), resizeParameter.newSize);
+
+        } catch (Throwable e) {
+            s_logger.error("Resize elastistor volume failed, please contact elastistor admin.", e);
+            result.setResult(e.toString());
+            callback.complete(result);
+        }
+
+        if (status) {
+            // now updating the cloudstack storagepool usedbytes and volume
+            Long usedBytes = poolVO.getUsedBytes();
+            Long currentVolumeSize = vol.getSize();
+            Long newUsedBytes;
+
+            if (currentVolumeSize < resizeParameter.newSize) {
+                newUsedBytes = usedBytes + (resizeParameter.newSize - currentVolumeSize);
+                poolVO.setUsedBytes(newUsedBytes);
+            } else {
+                newUsedBytes = usedBytes - (currentVolumeSize - resizeParameter.newSize);
+                poolVO.setUsedBytes(newUsedBytes);
+            }
+
+            _storagePoolDao.update(pool.getId(), poolVO);
+
+            vol.getVolume().setSize(resizeParameter.newSize);
+            vol.update();
+            callback.complete(result);
+        } else {
+            callback.complete(result);
+        }
+
+    }
+
+    //this method will utilize the volume details table to add third party volume properties
+    public void updateVolumeDetails(VolumeVO volume, FileSystem esvolume) {
+
+        VolumeDetailVO compression = new VolumeDetailVO(volume.getId(), "compression", esvolume.getCompression(), false);
+        _volumeDetailsDao.persist(compression);
+        VolumeDetailVO deduplication = new VolumeDetailVO(volume.getId(), "deduplication", esvolume.getDeduplication(), false);
+        _volumeDetailsDao.persist(deduplication);
+        VolumeDetailVO sync = new VolumeDetailVO(volume.getId(), "sync", esvolume.getSync(), false);
+        _volumeDetailsDao.persist(sync);
+        VolumeDetailVO graceallowed = new VolumeDetailVO(volume.getId(), "graceallowed", esvolume.getGraceallowed(), false);
+        _volumeDetailsDao.persist(graceallowed);
+
+    }
+
+    @Override
+    public long getVolumeSizeIncludingHypervisorSnapshotReserve(Volume volume, StoragePool pool) {
+        long volumeSize = volume.getSize();
+        Integer hypervisorSnapshotReserve = volume.getHypervisorSnapshotReserve();
+
+        if (hypervisorSnapshotReserve != null) {
+            if (hypervisorSnapshotReserve < 25) {
+                hypervisorSnapshotReserve = 25;
+            }
+
+            volumeSize += volumeSize * (hypervisorSnapshotReserve / 100f);
+        }
+
+        return volumeSize;
     }
 
     public ChapInfo getChapInfo(VolumeInfo volumeInfo) {
-        return super.getChapInfo(volumeInfo);
+        return null;
     }
 
     @Override
     public void takeSnapshot(SnapshotInfo snapshot, AsyncCompletionCallback<CreateCmdResult> callback) {
-        throw new UnsupportedOperationException();
+        CreateCmdResult result = null;
+        try {
+            s_logger.info("taking elastistor volume snapshot");
+            SnapshotObjectTO snapshotTO = (SnapshotObjectTO)snapshot.getTO();
+
+            String volumeid = snapshotTO.getVolume().getUuid();
+            String snapshotname = snapshotTO.getName();
+
+            Answer answer = ElastistorUtil.createElastistorVolumeSnapshot(volumeid, snapshotname);
+
+            if(answer.getResult() == false){
+                s_logger.info("elastistor volume snapshot failed");
+                throw new CloudRuntimeException("elastistor volume snapshot failed");
+            }else{
+                s_logger.info("elastistor volume snapshot succesfull");
+                result = new CreateCmdResult(null, null);
+                result.setSuccess(answer.getResult());
+                result.setAnswer(answer);
+            }
+        }
+         catch (Throwable e) {
+            s_logger.debug("Failed to take snapshot: " + e.getMessage());
+            result = new CreateCmdResult(null, null);
+            result.setResult(e.toString());
+        }
+        callback.complete(result);
     }
 
     @Override
@@ -94,4 +389,22 @@ public class ElastistorPrimaryDataStoreDriver  extends CloudStackPrimaryDataStor
         throw new UnsupportedOperationException();
     }
 
+    @Override
+    public Map<String, String> getCapabilities() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public boolean connectVolumeToHost(VolumeInfo volumeInfo, Host host, DataStore dataStore) {
+        // TODO Auto-generated method stub
+        return false;
+    }
+
+    @Override
+    public void disconnectVolumeFromHost(VolumeInfo volumeInfo, Host host, DataStore dataStore) {
+        // TODO Auto-generated method stub
+
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f3cbb699/plugins/storage/volume/cloudbyte/src/org/apache/cloudstack/storage/datastore/lifecycle/ElastistorPrimaryDataStoreLifeCycle.java
----------------------------------------------------------------------
diff --git a/plugins/storage/volume/cloudbyte/src/org/apache/cloudstack/storage/datastore/lifecycle/ElastistorPrimaryDataStoreLifeCycle.java b/plugins/storage/volume/cloudbyte/src/org/apache/cloudstack/storage/datastore/lifecycle/ElastistorPrimaryDataStoreLifeCycle.java
index 33004e3..8dbf03a 100755
--- a/plugins/storage/volume/cloudbyte/src/org/apache/cloudstack/storage/datastore/lifecycle/ElastistorPrimaryDataStoreLifeCycle.java
+++ b/plugins/storage/volume/cloudbyte/src/org/apache/cloudstack/storage/datastore/lifecycle/ElastistorPrimaryDataStoreLifeCycle.java
@@ -36,8 +36,10 @@ import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
 import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailsDao;
 import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
 import org.apache.cloudstack.storage.datastore.util.ElastistorUtil;
-import org.apache.cloudstack.storage.datastore.util.ElastistorUtil.CreateTsmCmdResponse;
-import org.apache.cloudstack.storage.datastore.util.ElastistorUtil.CreateVolumeCmdResponse;
+import org.apache.cloudstack.storage.datastore.util.ElastistorUtil.FileSystem;
+import org.apache.cloudstack.storage.datastore.util.ElastistorUtil.Tsm;
+import org.apache.cloudstack.storage.datastore.util.ElastistorUtil.UpdateTsmCmdResponse;
+import org.apache.cloudstack.storage.datastore.util.ElastistorUtil.UpdateTsmStorageCmdResponse;
 import org.apache.cloudstack.storage.volume.datastore.PrimaryDataStoreHelper;
 import org.apache.log4j.Logger;
 
@@ -46,6 +48,7 @@ import com.cloud.agent.api.Answer;
 import com.cloud.agent.api.CreateStoragePoolCommand;
 import com.cloud.agent.api.DeleteStoragePoolCommand;
 import com.cloud.agent.api.StoragePoolInfo;
+import com.cloud.capacity.CapacityManager;
 import com.cloud.dc.dao.DataCenterDao;
 import com.cloud.host.Host;
 import com.cloud.host.HostVO;
@@ -87,6 +90,8 @@ public class ElastistorPrimaryDataStoreLifeCycle implements PrimaryDataStoreLife
     StoragePoolDetailsDao _storagePoolDetailsDao;
     @Inject
     DataCenterDao _zoneDao;
+    @Inject
+    CapacityManager _capacityMgr;
 
     @Override
     public DataStore initialize(Map<String, Object> dsInfos) {
@@ -100,36 +105,56 @@ public class ElastistorPrimaryDataStoreLifeCycle implements PrimaryDataStoreLife
         Long capacityBytes = (Long) dsInfos.get("capacityBytes");
         Long capacityIops = (Long) dsInfos.get("capacityIops");
         String tags = (String) dsInfos.get("tags");
+        boolean managed = (Boolean) dsInfos.get("managed");
         Map<String, String> details = (Map<String, String>) dsInfos.get("details");
-        String storageIp = getStorageIp(url);
-        int storagePort = getDefaultStoragePort(url);
-        StoragePoolType storagetype = getStorageType(url);
-        String accesspath = getAccessPath(url);
-        String protocoltype = getProtocolType(url);
-        String[]  mp = accesspath.split("/");
-        String mountpoint = mp[1];
-        String uuid = null ;
-
+        String domainName = details.get("domainname");
+
+        String storageIp;
+        int storagePort = 0;
+        StoragePoolType storagetype = null;
+        String accesspath = null;
+        String protocoltype = null;
+        String mountpoint = null;
+
+        if (!managed) {
+            storageIp = getStorageIp(url);
+            storagePort = getDefaultStoragePort(url);
+            storagetype = getStorageType(url);
+            accesspath = getAccessPath(url);
+            protocoltype = getProtocolType(url);
+            String[] mp = accesspath.split("/");
+            mountpoint = mp[1];
+
+        } else if (details.get("hypervisortype") == "KVM") {
+            storageIp = url;
+            storagePort = 3260;
+            storagetype = StoragePoolType.Iscsi;
+            accesspath = storageIp + ":/" + storagePoolName;
+        }else{
+            storageIp = url;
+            storagePort = 2049;
+            storagetype = StoragePoolType.NetworkFilesystem;
+            accesspath = storageIp + ":/" + storagePoolName;
+        }
         /**
          * if the elastistor params which are required for plugin configuration
-         *  are not injected through spring-storage-volume-cloudbyte-context.xml, it can be set from details map.
+         * are not injected through spring-storage-volume-cloudbyte-context.xml,
+         * it can be set from details map.
          */
-        if(details.get("esaccountid") != null)
+        if (details.get("esaccountid") != null)
             ElastistorUtil.setElastistorAccountId(details.get("esaccountid"));
-        if(details.get("esapikey") != null)
-            ElastistorUtil.setElastistorApiKey(details.get("esapikey"));
-        if(details.get("esdefaultgateway") != null)
+        if (details.get("esdefaultgateway") != null)
             ElastistorUtil.setElastistorGateway(details.get("esdefaultgateway"));
-        if(details.get("estntinterface") != null)
+        if (details.get("estntinterface") != null)
             ElastistorUtil.setElastistorInterface(details.get("estntinterface"));
-        if(details.get("esmanagementip") != null)
-            ElastistorUtil.setElastistorManagementIp(details.get("esmanagementip"));
-        if(details.get("espoolid") != null)
+        if (details.get("espoolid") != null)
             ElastistorUtil.setElastistorPoolId(details.get("espoolid"));
-        if(details.get("essubnet") != null)
+        if (details.get("essubnet") != null)
             ElastistorUtil.setElastistorSubnet(details.get("essubnet"));
 
-       if (capacityBytes == null || capacityBytes <= 0) {
+        s_logger.info("Elastistor details was set successfully.");
+
+        if (capacityBytes == null || capacityBytes <= 0) {
             throw new IllegalArgumentException("'capacityBytes' must be present and greater than 0.");
         }
 
@@ -137,33 +162,33 @@ public class ElastistorPrimaryDataStoreLifeCycle implements PrimaryDataStoreLife
             throw new IllegalArgumentException("'capacityIops' must be present and greater than 0.");
         }
 
+        if (domainName == null) {
+            domainName = "ROOT";
+            s_logger.debug("setting the domain to ROOT");
+        }
+
         // elastistor does not allow same name and ip pools.
         List<StoragePoolVO> storagePoolVO = _storagePoolDao.listAll();
-        for(StoragePoolVO poolVO : storagePoolVO){
-        if (storagePoolName.equals(poolVO.getName())) {
-            throw new IllegalArgumentException("storage pool with that name already exists in elastistor,please specify a unique name .");
-        }
-        if (storageIp.equals(poolVO.getHostAddress())) {
-            throw new IllegalArgumentException("storage pool with that ip already exists in elastistor,please specify a unique ip .");
-        }
+        for (StoragePoolVO poolVO : storagePoolVO) {
+            if (storagePoolName.equals(poolVO.getName())) {
+                throw new IllegalArgumentException("Storage pool with this name already exists in elastistor, please specify a unique name. [name:" + storagePoolName + "]");
+            }
+            if (storageIp.equals(poolVO.getHostAddress())) {
+                throw new IllegalArgumentException("Storage pool with this ip already exists in elastistor, please specify a unique ip. [ip:" + storageIp + "]");
+            }
         }
 
         PrimaryDataStoreParameters parameters = new PrimaryDataStoreParameters();
 
-        // creates the volume in elastistor
-        parameters = createElastistorVolume(parameters, storagePoolName, storageIp, capacityBytes, capacityIops, protocoltype, mountpoint);
-
         parameters.setHost(storageIp);
         parameters.setPort(storagePort);
-        if(protocoltype.contentEquals("nfs")){
         parameters.setPath(accesspath);
-        }
         parameters.setType(storagetype);
         parameters.setZoneId(zoneId);
         parameters.setPodId(podId);
         parameters.setName(storagePoolName);
         parameters.setProviderName(providerName);
-        parameters.setManaged(false);
+        parameters.setManaged(managed);
         parameters.setCapacityBytes(capacityBytes);
         parameters.setUsedBytes(0);
         parameters.setCapacityIops(capacityIops);
@@ -172,147 +197,173 @@ public class ElastistorPrimaryDataStoreLifeCycle implements PrimaryDataStoreLife
         parameters.setDetails(details);
         parameters.setClusterId(clusterId);
 
+        Tsm tsm = null;
+        if (managed) {
+            // creates the TSM in elastistor
+            tsm = createElastistorTSM(storagePoolName, storageIp, capacityBytes, capacityIops, domainName);
+        } else {
+            // creates the TSM & Volume in elastistor
+            tsm = createElastistorTSM(storagePoolName, storageIp, capacityBytes, capacityIops, domainName);
+
+            parameters = createElastistorVolume(parameters, tsm, storagePoolName, capacityBytes, capacityIops, protocoltype, mountpoint);
+        }
+
+        // setting tsm's uuid as storagepool's uuid
+        parameters.setUuid(tsm.getUuid());
+
         return _dataStoreHelper.createPrimaryDataStore(parameters);
     }
 
-    private PrimaryDataStoreParameters createElastistorVolume(PrimaryDataStoreParameters parameters, String storagePoolName, String storageIp, Long capacityBytes, Long capacityIops, String protocoltype, String mountpoint){
+    private Tsm createElastistorTSM(String storagePoolName, String storageIp, Long capacityBytes, Long capacityIops, String domainName) {
 
-        s_logger.info("creation of elastistor volume started");
+        s_logger.info("Creation of elastistor TSM started.");
+
+        Tsm tsm;
+        String elastistorAccountId;
         try {
+            // to create a tsm , account id is required, so getting the account id for the given cloudstack domain
+            elastistorAccountId = ElastistorUtil.getElastistorAccountId(domainName);
 
-            CreateTsmCmdResponse tsmCmdResponse = ElastistorUtil.createElastistorTsm(storagePoolName, storageIp, capacityBytes, capacityIops);
+            // create the tsm for the given account id
+            tsm = ElastistorUtil.createElastistorTsm(storagePoolName, storageIp, capacityBytes, capacityIops, elastistorAccountId);
+        } catch (Throwable e) {
+            s_logger.error("Failed to create TSM in elastistor.", e);
+            throw new CloudRuntimeException("Failed to create TSM in elastistor. " + e.getMessage());
+        }
+
+        s_logger.info("Creation of elastistor TSM completed successfully.");
 
-            String uuid = tsmCmdResponse.getTsm().getUuid();
-            parameters.setUuid(uuid);
+        return tsm;
+    }
 
-            CreateVolumeCmdResponse volumeCmdResponse = ElastistorUtil.createElastistorVolume(storagePoolName, tsmCmdResponse, capacityBytes, capacityIops, protocoltype ,mountpoint);
+    private PrimaryDataStoreParameters createElastistorVolume(PrimaryDataStoreParameters parameters, Tsm tsm, String storagePoolName, Long capacityBytes, Long capacityIops, String protocoltype,
+            String mountpoint) {
 
-            if(protocoltype.contentEquals("iscsi")){
-              String accesspath = "/"+volumeCmdResponse.getFileSystem().getIqn()+"/0";
-              parameters.setPath(accesspath);
+        try {
+
+            s_logger.info("Creation of elastistor volume started.");
+
+            FileSystem volume = ElastistorUtil.createElastistorVolume(storagePoolName, tsm.getUuid(), capacityBytes, capacityIops, protocoltype, mountpoint);
+
+            if (protocoltype.contentEquals("iscsi")) {
+                String accesspath = "/" + volume.getIqn() + "/0";
+                parameters.setPath(accesspath);
             }
-        s_logger.info("creation of elastistor volume complete");
+            s_logger.info("Creation of elastistor volume completed successfully.");
 
             return parameters;
         } catch (Throwable e) {
-            throw new CloudRuntimeException("Failed to create volume in elastistor" + e.toString());
+            s_logger.error("Failed to create volume in elastistor.", e);
+            throw new CloudRuntimeException("Failed to create volume in elastistor. " + e.getMessage());
         }
 
     }
 
     private String getAccessPath(String url) {
-        StringTokenizer st = new StringTokenizer(url ,"/");
+        StringTokenizer st = new StringTokenizer(url, "/");
         int count = 0;
         while (st.hasMoreElements()) {
-      if(count == 2)
-      {  String s = "/" ;
-            return s.concat(st.nextElement().toString());
-      }
-      st.nextElement();
-      count++;
-      }
+            if (count == 2) {
+                String s = "/";
+                return s.concat(st.nextElement().toString());
+            }
+            st.nextElement();
+            count++;
+        }
         return null;
     }
 
-
     private StoragePoolType getStorageType(String url) {
 
-        StringTokenizer st = new StringTokenizer(url ,":");
+        StringTokenizer st = new StringTokenizer(url, ":");
 
-    while (st.hasMoreElements())
-    {
+        while (st.hasMoreElements()) {
             String accessprotocol = st.nextElement().toString();
 
-             if(accessprotocol.contentEquals("nfs"))
-             {
-                 return StoragePoolType.NetworkFilesystem;
-             }
-             else if(accessprotocol.contentEquals("iscsi"))
-             {
-                 return StoragePoolType.IscsiLUN;
-             }
+            if (accessprotocol.contentEquals("nfs")) {
+                return StoragePoolType.NetworkFilesystem;
+            } else if (accessprotocol.contentEquals("iscsi")) {
+                return StoragePoolType.IscsiLUN;
+            }
 
-             else
+            else
 
-                 break;
+                break;
 
-      }
-    return null;
+        }
+        return null;
     }
 
     private String getProtocolType(String url) {
-        StringTokenizer st = new StringTokenizer(url ,":");
-
-        while (st.hasMoreElements())
-        {
-                String accessprotocol = st.nextElement().toString();
-
-                 if(accessprotocol.contentEquals("nfs")){
-                     return "nfs";
-                 }else if(accessprotocol.contentEquals("iscsi")){
-                     return "iscsi";
-                 } else
-                     break;
-          }
+        StringTokenizer st = new StringTokenizer(url, ":");
+
+        while (st.hasMoreElements()) {
+            String accessprotocol = st.nextElement().toString();
+
+            if (accessprotocol.contentEquals("nfs")) {
+                return "nfs";
+            } else if (accessprotocol.contentEquals("iscsi")) {
+                return "iscsi";
+            } else
+                break;
+        }
         return null;
     }
 
-    // this method parses the url and gets the default storage port based on access protocol
+    // this method parses the url and gets the default storage port based on
+    // access protocol
     private int getDefaultStoragePort(String url) {
 
-        StringTokenizer st = new StringTokenizer(url ,":");
+        StringTokenizer st = new StringTokenizer(url, ":");
 
-        while (st.hasMoreElements())
-        {
+        while (st.hasMoreElements()) {
 
-                String accessprotocol = st.nextElement().toString();
+            String accessprotocol = st.nextElement().toString();
 
-                 if(accessprotocol.contentEquals("nfs")){
-                     return 2049;
-                 }
-                 else if(accessprotocol.contentEquals("iscsi")){
-                     return 3260;
-                 }
-                 else
-                     break;
+            if (accessprotocol.contentEquals("nfs")) {
+                return 2049;
+            } else if (accessprotocol.contentEquals("iscsi")) {
+                return 3260;
+            } else
+                break;
 
-          }
+        }
         return -1;
 
     }
 
-  // parses the url and returns the storage volume ip
+    // parses the url and returns the storage volume ip
     private String getStorageIp(String url) {
 
-        StringTokenizer st = new StringTokenizer(url ,"/");
+        StringTokenizer st = new StringTokenizer(url, "/");
         int count = 0;
 
         while (st.hasMoreElements()) {
-         if(count == 1)
-              return st.nextElement().toString();
+            if (count == 1)
+                return st.nextElement().toString();
 
-         st.nextElement();
+            st.nextElement();
             count++;
-      }
+        }
         return null;
     }
 
-     @Override
-        public boolean attachCluster(DataStore store, ClusterScope scope) {
+    @Override
+    public boolean attachCluster(DataStore store, ClusterScope scope) {
 
-         dataStoreHelper.attachCluster(store);
+        dataStoreHelper.attachCluster(store);
 
-           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()) {
-                primaryDataStoreDao.expunge(primarystore.getId());
-                throw new CloudRuntimeException("No host up to associate a storage pool with in cluster "
-                        + primarystore.getClusterId());
-            }
+        StoragePoolVO dataStoreVO = _storagePoolDao.findById(store.getId());
 
+        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()) {
+            primaryDataStoreDao.expunge(primarystore.getId());
+            throw new CloudRuntimeException("No host up to associate a storage pool with in cluster " + primarystore.getClusterId());
+        }
 
+        if (!dataStoreVO.isManaged()) {
             boolean success = false;
             for (HostVO h : allHosts) {
                 success = createStoragePool(h.getId(), primarystore);
@@ -320,56 +371,54 @@ public class ElastistorPrimaryDataStoreLifeCycle implements PrimaryDataStoreLife
                     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 {
-                    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);
-                }
+        s_logger.debug("In createPool Adding the pool to each of the hosts");
+        List<HostVO> poolHosts = new ArrayList<HostVO>();
+        for (HostVO h : allHosts) {
+            try {
+                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());
+            if (poolHosts.isEmpty()) {
+                s_logger.warn("No host can access storage pool " + primarystore + " on cluster " + primarystore.getClusterId());
                 primaryDataStoreDao.expunge(primarystore.getId());
                 throw new CloudRuntimeException("Failed to access storage pool");
             }
-         }
-
-            return true;
         }
 
-    private 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);
-          }
+        return true;
     }
 
+    private 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 attachHost(DataStore store, HostScope scope, StoragePoolInfo existingInfo) {
@@ -379,24 +428,24 @@ public class ElastistorPrimaryDataStoreLifeCycle implements PrimaryDataStoreLife
 
     @Override
     public boolean attachZone(DataStore dataStore, ZoneScope scope, HypervisorType hypervisorType) {
-    List<HostVO> hosts = _resourceMgr.listAllUpAndEnabledHostsInOneZoneByHypervisor(hypervisorType, scope.getScopeId());
-    s_logger.debug("In createPool. Attaching the pool to each of the hosts.");
-    List<HostVO> poolHosts = new ArrayList<HostVO>();
-    for (HostVO host : hosts) {
-        try {
-            storageMgr.connectHostToSharedPool(host.getId(), dataStore.getId());
-            poolHosts.add(host);
-        } catch (Exception e) {
-            s_logger.warn("Unable to establish a connection between " + host + " and " + dataStore, e);
+        List<HostVO> hosts = _resourceMgr.listAllUpAndEnabledHostsInOneZoneByHypervisor(hypervisorType, scope.getScopeId());
+        s_logger.debug("In createPool. Attaching the pool to each of the hosts.");
+        List<HostVO> poolHosts = new ArrayList<HostVO>();
+        for (HostVO host : hosts) {
+            try {
+                storageMgr.connectHostToSharedPool(host.getId(), dataStore.getId());
+                poolHosts.add(host);
+            } catch (Exception e) {
+                s_logger.warn("Unable to establish a connection between " + host + " and " + dataStore, e);
+            }
         }
-    }
-    if (poolHosts.isEmpty()) {
-        s_logger.warn("No host can access storage pool " + dataStore + " in this zone.");
-        primaryDataStoreDao.expunge(dataStore.getId());
-        throw new CloudRuntimeException("Failed to create storage pool as it is not accessible to hosts.");
-    }
-    dataStoreHelper.attachZone(dataStore, hypervisorType);
-    return true;
+        if (poolHosts.isEmpty()) {
+            s_logger.warn("No host can access storage pool " + dataStore + " in this zone.");
+            primaryDataStoreDao.expunge(dataStore.getId());
+            throw new CloudRuntimeException("Failed to create storage pool as it is not accessible to hosts.");
+        }
+        dataStoreHelper.attachZone(dataStore, hypervisorType);
+        return true;
     }
 
     @Override
@@ -421,63 +470,53 @@ public class ElastistorPrimaryDataStoreLifeCycle implements PrimaryDataStoreLife
 
         // find the hypervisor where the storage is attached to.
         HypervisorType hType = null;
-        if(hostPoolRecords.size() > 0 ){
+        if (hostPoolRecords.size() > 0) {
             hType = getHypervisorType(hostPoolRecords.get(0).getHostId());
         }
 
-        // 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()) {
-                // if host is KVM hypervisor then send deleteStoragepoolcmd to all the kvm hosts.
-                if (HypervisorType.KVM != hType) {
-                    break;
-                }
-            } else {
-                if (answer != null) {
-                    s_logger.error("Failed to delete storage pool: " + answer.getResult());
+        StoragePoolVO storagePoolVO = _storagePoolDao.findById(store.getId());
+
+        if (!(storagePoolVO.isManaged())) {
+            // 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()) {
+                    // if host is KVM hypervisor then send deleteStoragepoolcmd
+                    // to all the kvm hosts.
+                    if (HypervisorType.KVM != hType) {
+                        break;
+                    }
+                } else {
+                    if (answer != null) {
+                        s_logger.error("Failed to delete storage pool: " + answer.getResult());
+                    }
                 }
             }
         }
-
-        //delete the Elastistor volume at backend
-            deleteElastistorVolume(pool);
+        // delete the Elastistor volume at backend
+        deleteElastistorVolume(pool, storagePoolVO.isManaged());
 
         return _dataStoreHelper.deletePrimaryDataStore(store);
     }
 
-    private void deleteElastistorVolume(StoragePool pool){
-
-            String poolip = pool.getHostAddress();
-            String esip = null;
-            String apikey = null;
-
-            // check if apikey and managentip is empty, if so getting it from stragepooldetails
-            if(ElastistorUtil.s_esIPVAL == "" && ElastistorUtil.s_esAPIKEYVAL == ""){
-            Map<String, String> detailsMap = _storagePoolDetailsDao.listDetailsKeyPairs(pool.getId());
-            ElastistorUtil.setElastistorManagementIp(detailsMap.get("esmanagementip"));
-            esip=ElastistorUtil.s_esIPVAL;
-            ElastistorUtil.setElastistorApiKey(detailsMap.get("esapikey"));
-            apikey = ElastistorUtil.s_esAPIKEYVAL;
-            }else{
-                esip = ElastistorUtil.s_esIPVAL;
-                apikey = ElastistorUtil.s_esAPIKEYVAL;
-            }
+    private void deleteElastistorVolume(StoragePool pool, boolean managed) {
 
-            boolean status;
-            try {
-                status = ElastistorUtil.deleteElastistorVolume(poolip,esip,apikey);
-            } catch (Throwable e) {
-                throw new CloudRuntimeException("Failed to delete primary storage on elastistor" + e);
-            }
+        String poolid = pool.getUuid();
+        boolean status;
 
-            if(status == true){
-                s_logger.info("deletion of elastistor primary storage complete");
-            }else{
-                s_logger.error("deletion of elastistor volume failed");
-            }
+        try {
+            status = ElastistorUtil.deleteElastistorTsm(poolid, managed);
+        } catch (Throwable e) {
+            throw new CloudRuntimeException("Failed to delete primary storage on elastistor" + e);
+        }
+
+        if (status == true) {
+            s_logger.info("deletion of elastistor primary storage complete");
+        } else {
+            s_logger.error("deletion of elastistor volume failed");
+        }
 
     }
 
@@ -495,5 +534,57 @@ public class ElastistorPrimaryDataStoreLifeCycle implements PrimaryDataStoreLife
 
     @Override
     public void updateStoragePool(StoragePool storagePool, Map<String, String> details) {
+        String capacityBytes = details.get(PrimaryDataStoreLifeCycle.CAPACITY_BYTES);
+        String capacityIops = details.get(PrimaryDataStoreLifeCycle.CAPACITY_IOPS);
+
+        StoragePoolVO storagePoolVO = _storagePoolDao.findById(storagePool.getId());
+
+           try {
+                if(capacityBytes != null){
+                    long usedBytes = _capacityMgr.getUsedBytes(storagePoolVO);
+
+                    if (Long.valueOf(capacityBytes) < usedBytes) {
+                        throw new CloudRuntimeException("Cannot reduce the number of bytes for this storage pool as it would lead to an insufficient number of bytes");
+                    }
+
+                    UpdateTsmStorageCmdResponse updateTsmStorageCmdResponse  = ElastistorUtil.updateElastistorTsmStorage(capacityBytes,storagePool.getUuid());
+
+                   if(updateTsmStorageCmdResponse.getStorage().getId() != null){
+                    // update the cloudstack db
+                    _storagePoolDao.updateCapacityBytes(storagePool.getId(), Long.valueOf(capacityBytes));
+
+                    s_logger.info("elastistor TSM storage successfully updated");
+                   }else{
+                       throw new CloudRuntimeException("Failed to update the storage of Elastistor TSM" + updateTsmStorageCmdResponse.toString());
+                   }
+                }
+
+                if(capacityIops != null){
+
+                    long usedIops = _capacityMgr.getUsedIops(storagePoolVO);
+
+                    if (Long.valueOf(capacityIops) < usedIops) {
+                        throw new CloudRuntimeException("Cannot reduce the number of IOPS for this storage pool as it would lead to an insufficient number of IOPS");
+                    }
+
+                    UpdateTsmCmdResponse updateTsmCmdResponse   = ElastistorUtil.updateElastistorTsmIOPS(capacityIops,storagePool.getUuid());
+
+                   if(updateTsmCmdResponse.getTsm(0).getUuid() != null){
+                   // update the cloudstack db
+                    _storagePoolDao.updateCapacityIops(storagePool.getId(), Long.valueOf(capacityIops));
+
+                    s_logger.info("elastistor TSM IOPS successfully updated");
+
+                   }else{
+                       throw new CloudRuntimeException("Failed to update the IOPS of Elastistor TSM" + updateTsmCmdResponse.toString());
+                   }
+                }
+
+            } catch (Throwable e) {
+                throw new CloudRuntimeException("Failed to update the storage pool" + e);
+            }
+
+
     }
+
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f3cbb699/plugins/storage/volume/cloudbyte/src/org/apache/cloudstack/storage/datastore/provider/ElastistorHostListener.java
----------------------------------------------------------------------
diff --git a/plugins/storage/volume/cloudbyte/src/org/apache/cloudstack/storage/datastore/provider/ElastistorHostListener.java b/plugins/storage/volume/cloudbyte/src/org/apache/cloudstack/storage/datastore/provider/ElastistorHostListener.java
index de4711a..c68e51d 100755
--- a/plugins/storage/volume/cloudbyte/src/org/apache/cloudstack/storage/datastore/provider/ElastistorHostListener.java
+++ b/plugins/storage/volume/cloudbyte/src/org/apache/cloudstack/storage/datastore/provider/ElastistorHostListener.java
@@ -23,6 +23,7 @@ import javax.inject.Inject;
 import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
 import org.apache.cloudstack.engine.subsystem.api.storage.HypervisorHostListener;
 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;
@@ -30,6 +31,9 @@ import com.cloud.agent.api.Answer;
 import com.cloud.agent.api.ModifyStoragePoolAnswer;
 import com.cloud.agent.api.ModifyStoragePoolCommand;
 import com.cloud.alert.AlertManager;
+import com.cloud.host.HostVO;
+import com.cloud.host.dao.HostDao;
+import com.cloud.hypervisor.Hypervisor.HypervisorType;
 import com.cloud.storage.DataStoreRole;
 import com.cloud.storage.StoragePool;
 import com.cloud.storage.StoragePoolHostVO;
@@ -48,10 +52,30 @@ public class ElastistorHostListener implements HypervisorHostListener {
     StoragePoolHostDao storagePoolHostDao;
     @Inject
     PrimaryDataStoreDao primaryStoreDao;
+    @Inject
+    PrimaryDataStoreDao storagePoolDao;
+    @Inject
+    HostDao  _hostDao;
 
     @Override
     public boolean hostConnect(long hostId, long poolId) {
         StoragePool pool = (StoragePool) this.dataStoreMgr.getDataStore(poolId, DataStoreRole.Primary);
+
+        StoragePoolHostVO storagePoolHost = storagePoolHostDao.findByPoolHost(poolId, hostId);
+        HostVO host = _hostDao.findById(hostId);
+
+        if (storagePoolHost == null) {
+            storagePoolHost = new StoragePoolHostVO(poolId, hostId, "");
+
+            storagePoolHostDao.persist(storagePoolHost);
+        }
+
+        StoragePoolVO poolVO = storagePoolDao.findById(pool.getId());
+
+        if(poolVO.isManaged() && (host.getHypervisorType() != HypervisorType.KVM)){
+            return true;
+        }
+
         ModifyStoragePoolCommand cmd = new ModifyStoragePoolCommand(true, pool);
         final Answer answer = agentMgr.easySend(hostId, cmd);
 
@@ -75,8 +99,7 @@ public class ElastistorHostListener implements HypervisorHostListener {
 
     @Override
     public boolean hostDisconnected(long hostId, long poolId) {
-        StoragePoolHostVO storagePoolHost = storagePoolHostDao.findByPoolHost(
-                poolId, hostId);
+        StoragePoolHostVO storagePoolHost = storagePoolHostDao.findByPoolHost(poolId, hostId);
 
         if (storagePoolHost != null) {
             storagePoolHostDao.deleteStoragePoolHostDetails(hostId, poolId);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f3cbb699/plugins/storage/volume/cloudbyte/src/org/apache/cloudstack/storage/datastore/provider/ElastistorPrimaryDataStoreProvider.java
----------------------------------------------------------------------
diff --git a/plugins/storage/volume/cloudbyte/src/org/apache/cloudstack/storage/datastore/provider/ElastistorPrimaryDataStoreProvider.java b/plugins/storage/volume/cloudbyte/src/org/apache/cloudstack/storage/datastore/provider/ElastistorPrimaryDataStoreProvider.java
index e591082..f0b0943 100755
--- a/plugins/storage/volume/cloudbyte/src/org/apache/cloudstack/storage/datastore/provider/ElastistorPrimaryDataStoreProvider.java
+++ b/plugins/storage/volume/cloudbyte/src/org/apache/cloudstack/storage/datastore/provider/ElastistorPrimaryDataStoreProvider.java
@@ -29,6 +29,8 @@ import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
 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.framework.config.dao.ConfigurationDao;
+import org.apache.cloudstack.framework.config.impl.ConfigurationVO;
 import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
 import org.apache.cloudstack.storage.datastore.driver.ElastistorPrimaryDataStoreDriver;
 import org.apache.cloudstack.storage.datastore.lifecycle.ElastistorPrimaryDataStoreLifeCycle;
@@ -41,24 +43,21 @@ import com.cloud.alert.AlertManager;
 import com.cloud.storage.dao.StoragePoolHostDao;
 import com.cloud.utils.component.ComponentContext;
 
+/**
+ * This is the starting point of the elastistor storage plugin. This bean will
+ * be detected by Spring container & initialized. This will be one of the
+ * providers available via {@link DataStoreProviderManagerImpl} object.
+ */
 @Component
 public class ElastistorPrimaryDataStoreProvider implements PrimaryDataStoreProvider {
 
     private static final Logger s_logger = Logger.getLogger(DefaultHostListener.class);
 
-    //these classes will be injected by spring
+    // these classes will be injected by spring
     private ElastistorPrimaryDataStoreLifeCycle lifecycle;
     private PrimaryDataStoreDriver driver;
     private HypervisorHostListener listener;
 
-    // these params will be initialized with respective values given in spring-storage-volume-cloudbyte-context.xml bean for the elastistor porpose only.
-    private String esmanagementip;
-    private String esapikey;
-    private String esaccountid;
-    private String espoolid;
-    private String esdefaultgateway;
-    private String essubnet;
-    private String estntinterface;
 
     @Inject
     AgentManager agentMgr;
@@ -70,7 +69,8 @@ public class ElastistorPrimaryDataStoreProvider implements PrimaryDataStoreProvi
     StoragePoolHostDao storagePoolHostDao;
     @Inject
     PrimaryDataStoreDao primaryStoreDao;
-
+    @Inject
+    ConfigurationDao configurationDao;
 
     @Override
     public String getName() {
@@ -95,17 +95,19 @@ public class ElastistorPrimaryDataStoreProvider implements PrimaryDataStoreProvi
     @Override
     public boolean configure(Map<String, Object> params) {
 
+        s_logger.info("Will configure elastistor's lifecycle, driver, listener & global configurations.");
+
         lifecycle = ComponentContext.inject(ElastistorPrimaryDataStoreLifeCycle.class);
         driver = ComponentContext.inject(ElastistorPrimaryDataStoreDriver.class);
         listener = ComponentContext.inject(ElastistorHostListener.class);
 
-        ElastistorUtil.setElastistorAccountId(esaccountid);
-        ElastistorUtil.setElastistorApiKey(esapikey);
-        ElastistorUtil.setElastistorManagementIp(esmanagementip);
-        ElastistorUtil.setElastistorPoolId(espoolid);
-        ElastistorUtil.setElastistorGateway(esdefaultgateway);
-        ElastistorUtil.setElastistorInterface(estntinterface);
-        ElastistorUtil.setElastistorSubnet(essubnet);
+        // insert new cloudbyte global config to the configuration table
+        setCloudbyteGlobalConfiguration();
+
+        // set the injected configuration object in elastistor util class too!!!
+        ElastistorUtil.setConfigurationDao(configurationDao);
+
+        s_logger.info("Successfully configured elastistor's lifecycle, driver, listener & global configurations.");
 
         return true;
     }
@@ -118,58 +120,21 @@ public class ElastistorPrimaryDataStoreProvider implements PrimaryDataStoreProvi
 
         return types;
     }
-    public String getEspoolid() {
-        return espoolid;
-    }
-
-    public void setEspoolid(String espoolid) {
-        this.espoolid = espoolid;
-    }
-
-    public String getEsmanagementip() {
-        return esmanagementip;
-    }
-
-    public void setEsmanagementip(String esmanagementip) {
-        this.esmanagementip = esmanagementip;
-    }
 
-    public String getEsaccountid() {
-        return esaccountid;
-    }
-
-    public void setEsaccountid(String esaccountid) {
-        this.esaccountid = esaccountid;
-    }
+    private void setCloudbyteGlobalConfiguration() {
 
-    public String getEsapikey() {
-        return esapikey;
-    }
+        if (configurationDao.findByName("cloudbyte.management.ip") == null) {
+            ConfigurationVO managementIP = new ConfigurationVO("Advanced", "DEFAULT", "management-server",
+                    "cloudbyte.management.ip", null, "configure the cloudbyte elasticenter management IP");
 
-    public void setEsapikey(String esapikey) {
-        this.esapikey = esapikey;
-    }
-
-    public String getesdefaultgateway() {
-        return esdefaultgateway;
-    }
+            configurationDao.persist(managementIP);
+        }
 
-    public void setesdefaultgateway(String esdefaultgateway) {
-        this.esdefaultgateway = esdefaultgateway;
-    }
-    public String getEssubnet() {
-        return essubnet;
-    }
-
-    public void setEssubnet(String essubnet) {
-        this.essubnet = essubnet;
-    }
-
-    public String getEstntinterface(){
-     return estntinterface;
-    }
+        if (configurationDao.findByName("cloudbyte.management.apikey") == null) {
+            ConfigurationVO managementApiKey = new ConfigurationVO("Advanced", "DEFAULT", "management-server",
+                    "cloudbyte.management.apikey", null, "configure the cloudbyte elasticenter management API KEY");
 
-    public void setEstntinterface(String estntinterface){
-      this.estntinterface = estntinterface;
+            configurationDao.persist(managementApiKey);
+        }
     }
-}
+}
\ No newline at end of file


Mime
View raw message