cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mtutkow...@apache.org
Subject [1/2] git commit: updated refs/heads/master to 8b0266d
Date Tue, 11 Aug 2015 01:01:11 GMT
Repository: cloudstack
Updated Branches:
  refs/heads/master cd02a5984 -> 8b0266d12


CLOUDSTACK-8601. VMFS storage added as local storage can be re-added as shared storage.
Fail addition of a VMFS shared storage pool in case it has already been added as local storage
in CS.


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

Branch: refs/heads/master
Commit: 13a98dd196c8b0f86e4fb68db357df41767535f9
Parents: 02c3d14
Author: Likitha Shetty <likitha.shetty@citrix.com>
Authored: Fri Apr 17 18:47:23 2015 +0530
Committer: Likitha Shetty <likitha.shetty@citrix.com>
Committed: Wed Jul 1 10:47:36 2015 +0530

----------------------------------------------------------------------
 .../exception/StorageConflictException.java     | 27 ++++++++++++++++++++
 .../agent/api/ModifyStoragePoolAnswer.java      |  9 +++++++
 .../api/storage/HypervisorHostListener.java     |  4 ++-
 .../datastore/db/PrimaryDataStoreDao.java       |  2 ++
 .../datastore/db/PrimaryDataStoreDaoImpl.java   | 16 ++++++++++++
 .../datastore/provider/DefaultHostListener.java | 16 +++++++++++-
 .../vmware/resource/VmwareResource.java         |  3 +++
 ...CloudStackPrimaryDataStoreLifeCycleImpl.java |  7 +++++
 .../src/com/cloud/storage/StorageManager.java   |  3 ++-
 .../com/cloud/storage/StorageManagerImpl.java   |  3 ++-
 .../utils/exception/CSExceptionErrorCode.java   |  1 +
 11 files changed, 87 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/13a98dd1/api/src/com/cloud/exception/StorageConflictException.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/exception/StorageConflictException.java b/api/src/com/cloud/exception/StorageConflictException.java
new file mode 100644
index 0000000..2006d59
--- /dev/null
+++ b/api/src/com/cloud/exception/StorageConflictException.java
@@ -0,0 +1,27 @@
+// 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 com.cloud.exception;
+
+public class StorageConflictException extends ManagementServerException {
+
+    private static final long serialVersionUID = -294905017911859479L;
+
+    public StorageConflictException(String message) {
+        super(message);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/13a98dd1/core/src/com/cloud/agent/api/ModifyStoragePoolAnswer.java
----------------------------------------------------------------------
diff --git a/core/src/com/cloud/agent/api/ModifyStoragePoolAnswer.java b/core/src/com/cloud/agent/api/ModifyStoragePoolAnswer.java
index c5c6215..b92bb72 100644
--- a/core/src/com/cloud/agent/api/ModifyStoragePoolAnswer.java
+++ b/core/src/com/cloud/agent/api/ModifyStoragePoolAnswer.java
@@ -26,6 +26,7 @@ import com.cloud.storage.template.TemplateProp;
 public class ModifyStoragePoolAnswer extends Answer {
     StoragePoolInfo poolInfo;
     Map<String, TemplateProp> templateInfo;
+    String localDatastoreName = null;
 
     protected ModifyStoragePoolAnswer() {
     }
@@ -55,4 +56,12 @@ public class ModifyStoragePoolAnswer extends Answer {
         this.templateInfo = templateInfo;
     }
 
+    public String getLocalDatastoreName() {
+        return localDatastoreName;
+    }
+
+    public void setLocalDatastoreName(String localDatastoreName) {
+        this.localDatastoreName = localDatastoreName;
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/13a98dd1/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/HypervisorHostListener.java
----------------------------------------------------------------------
diff --git a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/HypervisorHostListener.java
b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/HypervisorHostListener.java
index 8db4101..82ba8b6 100644
--- a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/HypervisorHostListener.java
+++ b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/HypervisorHostListener.java
@@ -18,8 +18,10 @@
  */
 package org.apache.cloudstack.engine.subsystem.api.storage;
 
+import com.cloud.exception.StorageConflictException;
+
 public interface HypervisorHostListener {
-    boolean hostConnect(long hostId, long poolId);
+    boolean hostConnect(long hostId, long poolId) throws StorageConflictException;
 
     boolean hostDisconnected(long hostId, long poolId);
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/13a98dd1/engine/schema/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDao.java
b/engine/schema/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDao.java
index 3939545..d265da1 100644
--- a/engine/schema/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDao.java
+++ b/engine/schema/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDao.java
@@ -117,4 +117,6 @@ public interface PrimaryDataStoreDao extends GenericDao<StoragePoolVO,
Long> {
     List<StoragePoolVO> findZoneWideStoragePoolsByHypervisor(long dataCenterId, HypervisorType
hypervisorType);
 
     List<StoragePoolVO> findLocalStoragePoolsByHostAndTags(long hostId, String[] tags);
+
+    List<StoragePoolVO> listLocalStoragePoolByPath(long datacenterId, String path);
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/13a98dd1/engine/schema/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDaoImpl.java
b/engine/schema/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDaoImpl.java
index d3c29f7..a614261 100644
--- a/engine/schema/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDaoImpl.java
+++ b/engine/schema/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDaoImpl.java
@@ -53,6 +53,7 @@ public class PrimaryDataStoreDaoImpl extends GenericDaoBase<StoragePoolVO,
Long>
     protected final SearchBuilder<StoragePoolVO> DcPodSearch;
     protected final SearchBuilder<StoragePoolVO> DcPodAnyClusterSearch;
     protected final SearchBuilder<StoragePoolVO> DeleteLvmSearch;
+    protected final SearchBuilder<StoragePoolVO> DcLocalStorageSearch;
     protected final GenericSearchBuilder<StoragePoolVO, Long> StatusCountSearch;
 
     @Inject
@@ -115,6 +116,11 @@ public class PrimaryDataStoreDaoImpl extends GenericDaoBase<StoragePoolVO,
Long>
         StatusCountSearch.select(null, Func.COUNT, null);
         StatusCountSearch.done();
 
+        DcLocalStorageSearch = createSearchBuilder();
+        DcLocalStorageSearch.and("datacenterId", DcLocalStorageSearch.entity().getDataCenterId(),
SearchCriteria.Op.EQ);
+        DcLocalStorageSearch.and("path", DcLocalStorageSearch.entity().getPath(), SearchCriteria.Op.EQ);
+        DcLocalStorageSearch.and("scope", DcLocalStorageSearch.entity().getScope(), SearchCriteria.Op.EQ);
+        DcLocalStorageSearch.done();
     }
 
     @Override
@@ -196,6 +202,16 @@ public class PrimaryDataStoreDaoImpl extends GenericDaoBase<StoragePoolVO,
Long>
     }
 
     @Override
+    public List<StoragePoolVO> listLocalStoragePoolByPath(long datacenterId, String
path) {
+        SearchCriteria<StoragePoolVO> sc = DcLocalStorageSearch.create();
+        sc.setParameters("path", path);
+        sc.setParameters("datacenterId", datacenterId);
+        sc.setParameters("scope", ScopeType.HOST);
+
+        return listBy(sc);
+    }
+
+    @Override
     public List<StoragePoolVO> listBy(long datacenterId, Long podId, Long clusterId,
ScopeType scope) {
         if (clusterId != null) {
             SearchCriteria<StoragePoolVO> sc = DcPodSearch.create();

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/13a98dd1/engine/storage/volume/src/org/apache/cloudstack/storage/datastore/provider/DefaultHostListener.java
----------------------------------------------------------------------
diff --git a/engine/storage/volume/src/org/apache/cloudstack/storage/datastore/provider/DefaultHostListener.java
b/engine/storage/volume/src/org/apache/cloudstack/storage/datastore/provider/DefaultHostListener.java
index e77d548..89af076 100644
--- a/engine/storage/volume/src/org/apache/cloudstack/storage/datastore/provider/DefaultHostListener.java
+++ b/engine/storage/volume/src/org/apache/cloudstack/storage/datastore/provider/DefaultHostListener.java
@@ -18,6 +18,8 @@
  */
 package org.apache.cloudstack.storage.datastore.provider;
 
+import java.util.List;
+
 import javax.inject.Inject;
 
 import org.apache.log4j.Logger;
@@ -32,6 +34,7 @@ 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.exception.StorageConflictException;
 import com.cloud.storage.DataStoreRole;
 import com.cloud.storage.StoragePool;
 import com.cloud.storage.StoragePoolHostVO;
@@ -52,7 +55,7 @@ public class DefaultHostListener implements HypervisorHostListener {
     PrimaryDataStoreDao primaryStoreDao;
 
     @Override
-    public boolean hostConnect(long hostId, long poolId) {
+    public boolean hostConnect(long hostId, long poolId) throws StorageConflictException
{
         StoragePool pool = (StoragePool)this.dataStoreMgr.getDataStore(poolId, DataStoreRole.Primary);
         ModifyStoragePoolCommand cmd = new ModifyStoragePoolCommand(true, pool);
         final Answer answer = agentMgr.easySend(hostId, cmd);
@@ -71,6 +74,17 @@ public class DefaultHostListener implements HypervisorHostListener {
         assert (answer instanceof ModifyStoragePoolAnswer) : "Well, now why won't you actually
return the ModifyStoragePoolAnswer when it's ModifyStoragePoolCommand? Pool=" +
             pool.getId() + "Host=" + hostId;
         ModifyStoragePoolAnswer mspAnswer = (ModifyStoragePoolAnswer)answer;
+        if (mspAnswer.getLocalDatastoreName() != null && pool.isShared()) {
+            String datastoreName = mspAnswer.getLocalDatastoreName();
+            List<StoragePoolVO> localStoragePools = this.primaryStoreDao.listLocalStoragePoolByPath(pool.getDataCenterId(),
datastoreName);
+            for (StoragePoolVO localStoragePool : localStoragePools) {
+                if (datastoreName.equals(localStoragePool.getPath())) {
+                    s_logger.warn("Storage pool: " + pool.getId() + " has already been added
as local storage: " + localStoragePool.getName());
+                    throw new StorageConflictException("Cannot add shared storage pool: "
+ pool.getId() + " because it has already been added as local storage:"
+                            + localStoragePool.getName());
+                }
+            }
+        }
 
         StoragePoolHostVO poolHost = storagePoolHostDao.findByPoolHost(pool.getId(), hostId);
         if (poolHost == null) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/13a98dd1/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
index 5701ee9..f550d86 100644
--- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
+++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
@@ -3413,6 +3413,9 @@ public class VmwareResource implements StoragePoolResource, ServerResource,
Vmwa
             long available = summary.getFreeSpace();
             Map<String, TemplateProp> tInfo = new HashMap<String, TemplateProp>();
             ModifyStoragePoolAnswer answer = new ModifyStoragePoolAnswer(cmd, capacity, available,
tInfo);
+            if (cmd.getAdd() && pool.getType() == StoragePoolType.VMFS) {
+                answer.setLocalDatastoreName(morDatastore.getValue());
+            }
             return answer;
         } catch (Throwable e) {
             if (e instanceof RemoteException) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/13a98dd1/plugins/storage/volume/default/src/org/apache/cloudstack/storage/datastore/lifecycle/CloudStackPrimaryDataStoreLifeCycleImpl.java
----------------------------------------------------------------------
diff --git a/plugins/storage/volume/default/src/org/apache/cloudstack/storage/datastore/lifecycle/CloudStackPrimaryDataStoreLifeCycleImpl.java
b/plugins/storage/volume/default/src/org/apache/cloudstack/storage/datastore/lifecycle/CloudStackPrimaryDataStoreLifeCycleImpl.java
index 38e9d9c..be128f7 100644
--- a/plugins/storage/volume/default/src/org/apache/cloudstack/storage/datastore/lifecycle/CloudStackPrimaryDataStoreLifeCycleImpl.java
+++ b/plugins/storage/volume/default/src/org/apache/cloudstack/storage/datastore/lifecycle/CloudStackPrimaryDataStoreLifeCycleImpl.java
@@ -49,6 +49,7 @@ import com.cloud.agent.api.DeleteStoragePoolCommand;
 import com.cloud.agent.api.StoragePoolInfo;
 import com.cloud.alert.AlertManager;
 import com.cloud.exception.InvalidParameterValueException;
+import com.cloud.exception.StorageConflictException;
 import com.cloud.host.Host;
 import com.cloud.host.HostVO;
 import com.cloud.host.dao.HostDao;
@@ -410,6 +411,9 @@ public class CloudStackPrimaryDataStoreLifeCycleImpl implements PrimaryDataStore
             try {
                 storageMgr.connectHostToSharedPool(h.getId(), primarystore.getId());
                 poolHosts.add(h);
+            } catch (StorageConflictException se) {
+                primaryDataStoreDao.expunge(primarystore.getId());
+                throw new CloudRuntimeException("Storage has already been added as local
storage");
             } catch (Exception e) {
                 s_logger.warn("Unable to establish a connection between " + h + " and " +
primarystore, e);
             }
@@ -434,6 +438,9 @@ public class CloudStackPrimaryDataStoreLifeCycleImpl implements PrimaryDataStore
             try {
                 storageMgr.connectHostToSharedPool(host.getId(), dataStore.getId());
                 poolHosts.add(host);
+            } catch (StorageConflictException se) {
+                    primaryDataStoreDao.expunge(dataStore.getId());
+                    throw new CloudRuntimeException("Storage has already been added as local
storage to host: " + host.getName());
             } catch (Exception e) {
                 s_logger.warn("Unable to establish a connection between " + host + " and
" + dataStore, e);
             }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/13a98dd1/server/src/com/cloud/storage/StorageManager.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/StorageManager.java b/server/src/com/cloud/storage/StorageManager.java
index eebbf7f..5487e2e 100644
--- a/server/src/com/cloud/storage/StorageManager.java
+++ b/server/src/com/cloud/storage/StorageManager.java
@@ -29,6 +29,7 @@ import com.cloud.agent.api.StoragePoolInfo;
 import com.cloud.agent.manager.Commands;
 import com.cloud.capacity.CapacityVO;
 import com.cloud.exception.ConnectionException;
+import com.cloud.exception.StorageConflictException;
 import com.cloud.exception.StorageUnavailableException;
 import com.cloud.host.Host;
 import com.cloud.hypervisor.Hypervisor.HypervisorType;
@@ -99,7 +100,7 @@ public interface StorageManager extends StorageService {
 
     boolean registerHostListener(String providerUuid, HypervisorHostListener listener);
 
-    void connectHostToSharedPool(long hostId, long poolId) throws StorageUnavailableException;
+    void connectHostToSharedPool(long hostId, long poolId) throws StorageUnavailableException,
StorageConflictException;
 
     void createCapacityEntry(long poolId);
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/13a98dd1/server/src/com/cloud/storage/StorageManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/StorageManagerImpl.java b/server/src/com/cloud/storage/StorageManagerImpl.java
index 2c70b17..ba39e1f 100644
--- a/server/src/com/cloud/storage/StorageManagerImpl.java
+++ b/server/src/com/cloud/storage/StorageManagerImpl.java
@@ -129,6 +129,7 @@ import com.cloud.exception.OperationTimedoutException;
 import com.cloud.exception.PermissionDeniedException;
 import com.cloud.exception.ResourceInUseException;
 import com.cloud.exception.ResourceUnavailableException;
+import com.cloud.exception.StorageConflictException;
 import com.cloud.exception.StorageUnavailableException;
 import com.cloud.host.Host;
 import com.cloud.host.HostVO;
@@ -943,7 +944,7 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager,
C
     }
 
     @Override
-    public void connectHostToSharedPool(long hostId, long poolId) throws StorageUnavailableException
{
+    public void connectHostToSharedPool(long hostId, long poolId) throws StorageUnavailableException,
StorageConflictException {
         StoragePool pool = (StoragePool)_dataStoreMgr.getDataStore(poolId, DataStoreRole.Primary);
         assert (pool.isShared()) : "Now, did you actually read the name of this method?";
         s_logger.debug("Adding pool " + pool.getName() + " to  host " + hostId);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/13a98dd1/utils/src/com/cloud/utils/exception/CSExceptionErrorCode.java
----------------------------------------------------------------------
diff --git a/utils/src/com/cloud/utils/exception/CSExceptionErrorCode.java b/utils/src/com/cloud/utils/exception/CSExceptionErrorCode.java
index 2837ccb..62af14e 100644
--- a/utils/src/com/cloud/utils/exception/CSExceptionErrorCode.java
+++ b/utils/src/com/cloud/utils/exception/CSExceptionErrorCode.java
@@ -68,6 +68,7 @@ public class CSExceptionErrorCode {
             ExceptionErrorCodeMap.put("com.cloud.exception.VirtualMachineMigrationException",
4395);
             ExceptionErrorCodeMap.put("com.cloud.async.AsyncCommandQueued", 4540);
             ExceptionErrorCodeMap.put("com.cloud.exception.RequestLimitException", 4545);
+            ExceptionErrorCodeMap.put("com.cloud.exception.StorageConflictException", 4550);
 
             // Have a special error code for ServerApiException when it is
             // thrown in a standalone manner when failing to detect any of the above


Mime
View raw message