cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bfede...@apache.org
Subject [8/29] git commit: refs/heads/ui-multiple-nics - CLOUDSTACK-1173: fix the regression caused by life-cycle management changes
Date Wed, 06 Mar 2013 18:00:04 GMT
CLOUDSTACK-1173: fix the regression caused by life-cycle management changes


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

Branch: refs/heads/ui-multiple-nics
Commit: 3f2b771e072592535e9a71788635e11c264c461a
Parents: 333dd81
Author: Kelven Yang <kelveny@gmail.com>
Authored: Tue Feb 26 11:51:03 2013 -0800
Committer: Kelven Yang <kelveny@gmail.com>
Committed: Tue Mar 5 19:03:30 2013 -0500

----------------------------------------------------------------------
 .../consoleproxy/ConsoleProxyResource.java         |   25 ++++++++++++-
 .../src/com/cloud/cluster/ClusterManagerImpl.java  |    5 ++-
 .../ExternalLoadBalancerDeviceManagerImpl.java     |    3 +-
 .../src/com/cloud/network/NetworkManagerImpl.java  |   17 +++++----
 server/src/com/cloud/network/NetworkModelImpl.java |    7 ++--
 .../src/com/cloud/network/NetworkServiceImpl.java  |   21 ++---------
 .../src/com/cloud/consoleproxy/ConsoleProxy.java   |   29 ++++++++++-----
 .../src/com/cloud/utils/component/AdapterBase.java |    2 +-
 .../cloud/utils/component/ComponentContext.java    |    2 +-
 9 files changed, 66 insertions(+), 45 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/3f2b771e/agent/src/com/cloud/agent/resource/consoleproxy/ConsoleProxyResource.java
----------------------------------------------------------------------
diff --git a/agent/src/com/cloud/agent/resource/consoleproxy/ConsoleProxyResource.java b/agent/src/com/cloud/agent/resource/consoleproxy/ConsoleProxyResource.java
index 8a3a271..516430b 100644
--- a/agent/src/com/cloud/agent/resource/consoleproxy/ConsoleProxyResource.java
+++ b/agent/src/com/cloud/agent/resource/consoleproxy/ConsoleProxyResource.java
@@ -26,6 +26,7 @@ import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.net.URL;
 import java.net.URLConnection;
+import java.util.HashMap;
 import java.util.Map;
 import java.util.Properties;
 
@@ -77,7 +78,7 @@ import com.google.gson.Gson;
  * server.
  * 
  */
-public abstract class ConsoleProxyResource extends ServerResourceBase implements
+public class ConsoleProxyResource extends ServerResourceBase implements
         ServerResource {
     static final Logger s_logger = Logger.getLogger(ConsoleProxyResource.class);
 
@@ -489,4 +490,26 @@ public abstract class ConsoleProxyResource extends ServerResourceBase
implements
             }
         }
     }
+
+	@Override
+	public void setName(String name) {
+	}
+
+	@Override
+	public void setConfigParams(Map<String, Object> params) {
+	}
+
+	@Override
+	public Map<String, Object> getConfigParams() {
+		return new HashMap<String, Object>();
+	}
+
+	@Override
+	public int getRunLevel() {
+		return 0;
+	}
+
+	@Override
+	public void setRunLevel(int level) {
+	}
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/3f2b771e/server/src/com/cloud/cluster/ClusterManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/cluster/ClusterManagerImpl.java b/server/src/com/cloud/cluster/ClusterManagerImpl.java
index 45d9dca..27e0e03 100755
--- a/server/src/com/cloud/cluster/ClusterManagerImpl.java
+++ b/server/src/com/cloud/cluster/ClusterManagerImpl.java
@@ -74,6 +74,7 @@ import com.cloud.utils.DateUtil;
 import com.cloud.utils.NumbersUtil;
 import com.cloud.utils.Profiler;
 import com.cloud.utils.PropertiesUtil;
+import com.cloud.utils.component.ComponentContext;
 import com.cloud.utils.component.ComponentLifecycle;
 import com.cloud.utils.component.ManagerBase;
 import com.cloud.utils.concurrency.NamedThreadFactory;
@@ -364,11 +365,11 @@ public class ClusterManagerImpl extends ManagerBase implements ClusterManager
{
 
         try {
             // schedule a scan task immediately
-            if (_agentMgr instanceof ClusteredAgentManagerImpl) {
+            if (ComponentContext.getTargetObject(_agentMgr) instanceof ClusteredAgentManagerImpl)
{
                 if (s_logger.isDebugEnabled()) {
                     s_logger.debug("Received notification as part of addHost command to start
a host scan task");
                 }
-                ClusteredAgentManagerImpl clusteredAgentMgr = (ClusteredAgentManagerImpl)_agentMgr;
+                ClusteredAgentManagerImpl clusteredAgentMgr = (ClusteredAgentManagerImpl)ComponentContext.getTargetObject(_agentMgr);
                 clusteredAgentMgr.scheduleHostScanTask();
             }
         } catch (Exception e) {

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/3f2b771e/server/src/com/cloud/network/ExternalLoadBalancerDeviceManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/ExternalLoadBalancerDeviceManagerImpl.java b/server/src/com/cloud/network/ExternalLoadBalancerDeviceManagerImpl.java
index bcefccc..8856881 100644
--- a/server/src/com/cloud/network/ExternalLoadBalancerDeviceManagerImpl.java
+++ b/server/src/com/cloud/network/ExternalLoadBalancerDeviceManagerImpl.java
@@ -109,6 +109,7 @@ import com.cloud.user.dao.AccountDao;
 import com.cloud.user.dao.UserStatisticsDao;
 import com.cloud.utils.NumbersUtil;
 import com.cloud.utils.component.AdapterBase;
+import com.cloud.utils.component.ComponentContext;
 import com.cloud.utils.db.DB;
 import com.cloud.utils.db.GlobalLock;
 import com.cloud.utils.db.Transaction;
@@ -1102,7 +1103,7 @@ public abstract class ExternalLoadBalancerDeviceManagerImpl extends
AdapterBase
         }
 
         NetworkElement element = _networkModel.getElementImplementingProvider(providers.get(0).getName());
-        if (!(element instanceof IpDeployer)) {
+        if (!(ComponentContext.getTargetObject(element) instanceof IpDeployer)) {
             s_logger.error("The firewall provider for network " + network.getName() + " don't
have ability to deploy IP address!");
             return null;
         }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/3f2b771e/server/src/com/cloud/network/NetworkManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java
index a575183..ba5ab5d 100755
--- a/server/src/com/cloud/network/NetworkManagerImpl.java
+++ b/server/src/com/cloud/network/NetworkManagerImpl.java
@@ -129,6 +129,7 @@ import com.cloud.utils.Journal;
 import com.cloud.utils.NumbersUtil;
 import com.cloud.utils.Pair;
 import com.cloud.utils.component.AdapterBase;
+import com.cloud.utils.component.ComponentContext;
 import com.cloud.utils.component.ManagerBase;
 import com.cloud.utils.concurrency.NamedThreadFactory;
 import com.cloud.utils.db.*;
@@ -546,10 +547,10 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager,
L
                 }
                 IpDeployer deployer = null;
                 NetworkElement element = _networkModel.getElementImplementingProvider(provider.getName());
-                if (!(element instanceof IpDeployingRequester)) {
+                if (!(ComponentContext.getTargetObject(element) instanceof IpDeployingRequester))
{
                     throw new CloudRuntimeException("Element " + element + " is not a IpDeployingRequester!");
                 }
-                deployer = ((IpDeployingRequester)element).getIpDeployer(network);
+                deployer = ((IpDeployingRequester)ComponentContext.getTargetObject(element)).getIpDeployer(network);
                 if (deployer == null) {
                     throw new CloudRuntimeException("Fail to get ip deployer for element:
" + element);
                 }
@@ -1529,13 +1530,13 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager,
L
         if (vmProfile.getType() == Type.User && element.getProvider() != null) {
             if (_networkModel.areServicesSupportedInNetwork(network.getId(), Service.Dhcp)
&&
                     _networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.Dhcp,
element.getProvider()) &&
-                    (element instanceof DhcpServiceProvider)) {
+                    (ComponentContext.getTargetObject(element) instanceof DhcpServiceProvider))
{
                 DhcpServiceProvider sp = (DhcpServiceProvider) element;
                 sp.addDhcpEntry(network, profile, vmProfile, dest, context);
             }
             if (_networkModel.areServicesSupportedInNetwork(network.getId(), Service.UserData)
&&
                     _networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.UserData,
element.getProvider()) &&
-                    (element instanceof UserDataServiceProvider)) {
+                    (ComponentContext.getTargetObject(element) instanceof UserDataServiceProvider))
{
                 UserDataServiceProvider sp = (UserDataServiceProvider) element;
                 sp.addPasswordAndUserdata(network, profile, vmProfile, dest, context);
             }
@@ -3622,15 +3623,15 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager,
L
     @Override
     public StaticNatServiceProvider getStaticNatProviderForNetwork(Network network) {
         NetworkElement element = getElementForServiceInNetwork(network, Service.StaticNat);
-        assert element instanceof StaticNatServiceProvider;
-        return (StaticNatServiceProvider)element;
+        assert ComponentContext.getTargetObject(element) instanceof StaticNatServiceProvider;
+        return (StaticNatServiceProvider)ComponentContext.getTargetObject(element);
     }
 
     @Override
     public LoadBalancingServiceProvider getLoadBalancingProviderForNetwork(Network network)
{
         NetworkElement element = getElementForServiceInNetwork(network, Service.Lb);
-        assert element instanceof LoadBalancingServiceProvider; 
-        return ( LoadBalancingServiceProvider)element;
+        assert ComponentContext.getTargetObject(element) instanceof LoadBalancingServiceProvider;

+        return ( LoadBalancingServiceProvider)ComponentContext.getTargetObject(element);
     }
     @Override
     public boolean isNetworkInlineMode(Network network) {

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/3f2b771e/server/src/com/cloud/network/NetworkModelImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/NetworkModelImpl.java b/server/src/com/cloud/network/NetworkModelImpl.java
index 0525888..e83c0d2 100644
--- a/server/src/com/cloud/network/NetworkModelImpl.java
+++ b/server/src/com/cloud/network/NetworkModelImpl.java
@@ -92,6 +92,7 @@ import com.cloud.user.Account;
 import com.cloud.user.DomainManager;
 import com.cloud.user.dao.AccountDao;
 import com.cloud.utils.component.AdapterBase;
+import com.cloud.utils.component.ComponentContext;
 import com.cloud.utils.component.Manager;
 import com.cloud.utils.component.ManagerBase;
 import com.cloud.utils.db.DB;
@@ -398,9 +399,9 @@ public class NetworkModelImpl extends ManagerBase implements NetworkModel
{
         Network network = _networksDao.findById(networkId);
         NetworkElement oldElement = getElementImplementingProvider(oldProvider.getName());
         NetworkElement newElement = getElementImplementingProvider(newProvider.getName());
-        if (oldElement instanceof IpDeployingRequester && newElement instanceof IpDeployingRequester)
{
-        	IpDeployer oldIpDeployer = ((IpDeployingRequester)oldElement).getIpDeployer(network);
-        	IpDeployer newIpDeployer = ((IpDeployingRequester)newElement).getIpDeployer(network);
+        if (ComponentContext.getTargetObject(oldElement) instanceof IpDeployingRequester
&& ComponentContext.getTargetObject(newElement) instanceof IpDeployingRequester) {
+        	IpDeployer oldIpDeployer = ((IpDeployingRequester)ComponentContext.getTargetObject(oldElement)).getIpDeployer(network);
+        	IpDeployer newIpDeployer = ((IpDeployingRequester)ComponentContext.getTargetObject(newElement)).getIpDeployer(network);
         	if (!oldIpDeployer.getProvider().getName().equals(newIpDeployer.getProvider().getName()))
{
         		throw new InvalidParameterException("There would be multiple providers for IP "
+ publicIp.getAddress() + "!");
         	}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/3f2b771e/server/src/com/cloud/network/NetworkServiceImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/NetworkServiceImpl.java b/server/src/com/cloud/network/NetworkServiceImpl.java
index 8792037..821aa6d 100755
--- a/server/src/com/cloud/network/NetworkServiceImpl.java
+++ b/server/src/com/cloud/network/NetworkServiceImpl.java
@@ -2175,10 +2175,7 @@ public class NetworkServiceImpl extends ManagerBase implements  NetworkService
{
             addDefaultSecurityGroupProviderToPhysicalNetwork(pNetwork.getId());
             
             // add VPCVirtualRouter as the defualt network service provider
-            addDefaultVpcVirtualRouterToPhysicalNetwork(pNetwork.getId());
-            
-            // add baremetal pxe/dhcp provider to the physical network
-            addDefaultBaremetalProvidersToPhysicalNetwork(pNetwork.getId());
+            addDefaultVpcVirtualRouterToPhysicalNetwork(pNetwork.getId());
 
             txn.commit();
             return pNetwork;
@@ -2984,22 +2981,10 @@ public class NetworkServiceImpl extends ManagerBase implements  NetworkService
{
             throw new CloudRuntimeException("Unable to find the Network Element implementing
the VirtualRouter Provider");
         }
         
-        VirtualRouterElement element = ComponentContext.getTargetObject(networkElement);
+        VirtualRouterElement element = (VirtualRouterElement)networkElement;
         element.addElement(nsp.getId(), VirtualRouterProviderType.VirtualRouter);
 
         return nsp;
-    }
-    
-    
-    private PhysicalNetworkServiceProvider addDefaultBaremetalProvidersToPhysicalNetwork(long
physicalNetworkId) {
-        PhysicalNetworkVO pvo = _physicalNetworkDao.findById(physicalNetworkId);
-        DataCenterVO dvo = _dcDao.findById(pvo.getDataCenterId());
-        if (dvo.getNetworkType() == NetworkType.Basic) {
-            addProviderToPhysicalNetwork(physicalNetworkId, "BaremetalDhcpProvider", null,
null);
-            addProviderToPhysicalNetwork(physicalNetworkId, "BaremetalPxeProvider", null,
null);
-            addProviderToPhysicalNetwork(physicalNetworkId, "BaremetaUserdataProvider", null,
null);
-        }
-        return null;
     }
     
     protected PhysicalNetworkServiceProvider addDefaultVpcVirtualRouterToPhysicalNetwork(long
physicalNetworkId) {
@@ -3012,7 +2997,7 @@ public class NetworkServiceImpl extends ManagerBase implements  NetworkService
{
             throw new CloudRuntimeException("Unable to find the Network Element implementing
the VPCVirtualRouter Provider");
         }
         
-        VpcVirtualRouterElement element = ComponentContext.getTargetObject(networkElement);
+        VpcVirtualRouterElement element = (VpcVirtualRouterElement)networkElement;
         element.addElement(nsp.getId(), VirtualRouterProviderType.VPCVirtualRouter);
 
         return nsp;

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/3f2b771e/services/console-proxy/server/src/com/cloud/consoleproxy/ConsoleProxy.java
----------------------------------------------------------------------
diff --git a/services/console-proxy/server/src/com/cloud/consoleproxy/ConsoleProxy.java b/services/console-proxy/server/src/com/cloud/consoleproxy/ConsoleProxy.java
index a722d83..b5c2989 100644
--- a/services/console-proxy/server/src/com/cloud/consoleproxy/ConsoleProxy.java
+++ b/services/console-proxy/server/src/com/cloud/consoleproxy/ConsoleProxy.java
@@ -425,23 +425,32 @@ public class ConsoleProxy {
         synchronized (connectionMap) {
             ConsoleProxyClient viewer = connectionMap.get(clientKey);
             if (viewer == null) {
+                authenticationExternally(param);
                 viewer = new ConsoleProxyVncClient();
                 viewer.initClient(param);
                 
                 connectionMap.put(clientKey, viewer);
                 s_logger.info("Added viewer object " + viewer);
                 reportLoadChange = true;
-            } else if (!viewer.isFrontEndAlive()) {
-                s_logger.info("The rfb thread died, reinitializing the viewer " + viewer);
-                viewer.initClient(param);
-            } else if (!param.getClientHostPassword().equals(viewer.getClientHostPassword()))
{
-                s_logger.warn("Bad sid detected(VNC port may be reused). sid in session:
" 
-                    + viewer.getClientHostPassword() + ", sid in request: " + param.getClientHostPassword());
-                viewer.initClient(param);
-            } else {
-                if(ajaxSession == null || ajaxSession.isEmpty())
+            }  else {
+				// protected against malicous attack by modifying URL content
+				if(ajaxSession != null) {
+					long ajaxSessionIdFromUrl = Long.parseLong(ajaxSession);
+					if(ajaxSessionIdFromUrl != viewer.getAjaxSessionId())
+						throw new AuthenticationException ("Cannot use the existing viewer " +
+								viewer + ": modified AJAX session id");
+				}
+				
+				if(param.getClientHostPassword() == null || param.getClientHostPassword().isEmpty() ||
!param.getClientHostPassword().equals(viewer.getClientHostPassword()))
+					throw new AuthenticationException ("Cannot use the existing viewer " +
+							viewer + ": bad sid");
+				
+				if(!viewer.isFrontEndAlive()) {
                     authenticationExternally(param);
-            }
+					viewer.initClient(param);
+					reportLoadChange = true;
+				}
+			}
             
             if(reportLoadChange) {
                 ConsoleProxyClientStatsCollector statsCollector = getStatsCollector();

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/3f2b771e/utils/src/com/cloud/utils/component/AdapterBase.java
----------------------------------------------------------------------
diff --git a/utils/src/com/cloud/utils/component/AdapterBase.java b/utils/src/com/cloud/utils/component/AdapterBase.java
index 405762d..a8f4f46 100644
--- a/utils/src/com/cloud/utils/component/AdapterBase.java
+++ b/utils/src/com/cloud/utils/component/AdapterBase.java
@@ -27,7 +27,7 @@ public class AdapterBase extends ComponentLifecycleBase implements Adapter
{
 	public static <T extends Adapter> T getAdapterByName(List<T> adapters, String
name) {
     	for(T adapter : adapters) {
     		if(adapter.getName() != null && adapter.getName().equalsIgnoreCase(name))
-    			return adapter;
+    			return ComponentContext.getTargetObject(adapter);
     	}
     	return null;
     }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/3f2b771e/utils/src/com/cloud/utils/component/ComponentContext.java
----------------------------------------------------------------------
diff --git a/utils/src/com/cloud/utils/component/ComponentContext.java b/utils/src/com/cloud/utils/component/ComponentContext.java
index e598b85..82fe90d 100644
--- a/utils/src/com/cloud/utils/component/ComponentContext.java
+++ b/utils/src/com/cloud/utils/component/ComponentContext.java
@@ -214,7 +214,7 @@ public class ComponentContext implements ApplicationContextAware {
 
         return (T)instance;
     }
-
+    
     public static <T> T inject(Class<T> clz) {
         T instance = s_appContext.getAutowireCapableBeanFactory().createBean(clz);
         return instance;


Mime
View raw message