cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sw...@apache.org
Subject [13/39] git commit: updated refs/heads/master to 3c800b4
Date Thu, 26 May 2016 03:05:52 GMT
Bug-ID: CLOUDSTACK-8870: Skip external device usage collection if no external devices exist


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

Branch: refs/heads/master
Commit: c12d83601d5203ffee461901f92f21f3337769c3
Parents: 570b676
Author: Kishan Kavala <kishan@apache.org>
Authored: Mon May 23 15:23:23 2016 +0530
Committer: Kishan Kavala <kishan@apache.org>
Committed: Mon May 23 15:23:23 2016 +0530

----------------------------------------------------------------------
 engine/schema/src/com/cloud/host/dao/HostDao.java      |  2 ++
 engine/schema/src/com/cloud/host/dao/HostDaoImpl.java  |  7 +++++++
 .../cloud/network/ExternalDeviceUsageManagerImpl.java  | 11 ++++++++++-
 .../ExternalLoadBalancerDeviceManagerImplTest.java     | 13 +++++++++++++
 4 files changed, 32 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c12d8360/engine/schema/src/com/cloud/host/dao/HostDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/host/dao/HostDao.java b/engine/schema/src/com/cloud/host/dao/HostDao.java
index 3cfdc94..88a3547 100644
--- a/engine/schema/src/com/cloud/host/dao/HostDao.java
+++ b/engine/schema/src/com/cloud/host/dao/HostDao.java
@@ -97,4 +97,6 @@ public interface HostDao extends GenericDao<HostVO, Long>, StateDao<Status,
Stat
     List<HostVO> listAllHostsByType(Host.Type type);
 
     HostVO findByPublicIp(String publicIp);
+
+    List<HostVO> listByType(Type type);
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c12d8360/engine/schema/src/com/cloud/host/dao/HostDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/host/dao/HostDaoImpl.java b/engine/schema/src/com/cloud/host/dao/HostDaoImpl.java
index 54133b9..46f8a4d 100644
--- a/engine/schema/src/com/cloud/host/dao/HostDaoImpl.java
+++ b/engine/schema/src/com/cloud/host/dao/HostDaoImpl.java
@@ -1137,4 +1137,11 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long>
implements HostDao
 
         return listBy(sc);
     }
+
+    @Override
+    public List<HostVO> listByType(Host.Type type) {
+        SearchCriteria<HostVO> sc = TypeSearch.create();
+        sc.setParameters("type", type);
+        return listBy(sc);
+    }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c12d8360/server/src/com/cloud/network/ExternalDeviceUsageManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/ExternalDeviceUsageManagerImpl.java b/server/src/com/cloud/network/ExternalDeviceUsageManagerImpl.java
index 59b398f..200b279 100644
--- a/server/src/com/cloud/network/ExternalDeviceUsageManagerImpl.java
+++ b/server/src/com/cloud/network/ExternalDeviceUsageManagerImpl.java
@@ -340,6 +340,15 @@ public class ExternalDeviceUsageManagerImpl extends ManagerBase implements
Exter
 
         @Override
         protected void runInContext() {
+
+            // Check if there are any external devices
+            // Skip external device usage collection if none exist
+
+            if(_hostDao.listByType(Host.Type.ExternalFirewall).isEmpty() && _hostDao.listByType(Host.Type.ExternalLoadBalancer).isEmpty()){
+                s_logger.debug("External devices are not used. Skipping external device usage
collection");
+                return;
+            }
+
             GlobalLock scanLock = GlobalLock.getInternLock("ExternalDeviceNetworkUsageManagerImpl");
             try {
                 if (scanLock.lock(20)) {
@@ -356,7 +365,7 @@ public class ExternalDeviceUsageManagerImpl extends ManagerBase implements
Exter
             }
         }
 
-        private void runExternalDeviceNetworkUsageTask() {
+        protected void runExternalDeviceNetworkUsageTask() {
             s_logger.debug("External devices stats collector is running...");
 
             for (DataCenterVO zone : _dcDao.listAll()) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c12d8360/server/test/com/cloud/network/ExternalLoadBalancerDeviceManagerImplTest.java
----------------------------------------------------------------------
diff --git a/server/test/com/cloud/network/ExternalLoadBalancerDeviceManagerImplTest.java
b/server/test/com/cloud/network/ExternalLoadBalancerDeviceManagerImplTest.java
index 046bdb6..dbc31ba 100644
--- a/server/test/com/cloud/network/ExternalLoadBalancerDeviceManagerImplTest.java
+++ b/server/test/com/cloud/network/ExternalLoadBalancerDeviceManagerImplTest.java
@@ -20,11 +20,13 @@ package com.cloud.network;
 import java.lang.reflect.Field;
 import java.net.URI;
 import java.net.URISyntaxException;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
 
 import javax.inject.Inject;
 
+import com.cloud.host.Host;
 import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
 import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
 import org.junit.Assert;
@@ -207,4 +209,15 @@ public class ExternalLoadBalancerDeviceManagerImplTest {
         HostVO hostVo = Mockito.mock(HostVO.class);
         Mockito.when(_hostDao.findById(Mockito.anyLong())).thenReturn(hostVo);
     }
+
+
+    @Test
+    public void testUsageTask()  {
+        ExternalDeviceUsageManagerImpl.ExternalDeviceNetworkUsageTask usageTask = Mockito
+                .mock(ExternalDeviceUsageManagerImpl.ExternalDeviceNetworkUsageTask.class);
+        Mockito.when(_hostDao.listByType(Host.Type.ExternalFirewall)).thenReturn(new ArrayList<HostVO>());
+        Mockito.when(_hostDao.listByType(Host.Type.ExternalLoadBalancer)).thenReturn(new
ArrayList<HostVO>());
+        usageTask.runInContext();
+        Mockito.verify(usageTask, Mockito.times(0)).runExternalDeviceNetworkUsageTask();
+    }
 }


Mime
View raw message