cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alena1...@apache.org
Subject [5/5] git commit: updated refs/heads/internallb to d8ea854
Date Wed, 10 Apr 2013 01:00:47 GMT
InternalLB: Modified pluggable service VirtualRouterElementService to accept only VirtualRouter
and VpcVirtualRouter as a VirtualRouterProvider type when add/configure elements. Other VirtualRouterProviderTypes
are are taken care by elb/internal lb plugins.


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

Branch: refs/heads/internallb
Commit: 0f215bc6bee28f3c9180ccc707bb04753e23e35b
Parents: caa6d87
Author: Alena Prokharchyk <alena.prokharchyk@citrix.com>
Authored: Tue Apr 9 14:01:11 2013 -0700
Committer: Alena Prokharchyk <alena.prokharchyk@citrix.com>
Committed: Tue Apr 9 17:55:59 2013 -0700

----------------------------------------------------------------------
 .../com/cloud/network/VirtualRouterProvider.java   |    3 +-
 .../org/apache/cloudstack/api/ApiConstants.java    |    1 +
 .../router/CreateVirtualRouterElementCmd.java      |   21 +++++-
 .../response/VirtualRouterProviderResponse.java    |    8 +++
 .../element/InternalLoadBalancerElement.java       |   50 ++++++++++++++-
 server/src/com/cloud/api/ApiResponseHelper.java    |    1 +
 .../src/com/cloud/network/NetworkServiceImpl.java  |    2 +-
 .../network/element/VirtualRouterElement.java      |   14 +++-
 8 files changed, 90 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/0f215bc6/api/src/com/cloud/network/VirtualRouterProvider.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/network/VirtualRouterProvider.java b/api/src/com/cloud/network/VirtualRouterProvider.java
index ed6a274..f67686e 100644
--- a/api/src/com/cloud/network/VirtualRouterProvider.java
+++ b/api/src/com/cloud/network/VirtualRouterProvider.java
@@ -23,7 +23,8 @@ public interface VirtualRouterProvider extends InternalIdentity, Identity
{
     public enum VirtualRouterProviderType {
         VirtualRouter,
         ElasticLoadBalancerVm,
-        VPCVirtualRouter
+        VPCVirtualRouter,
+        InternalLbVm
     }
 
     public VirtualRouterProviderType getType();

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/0f215bc6/api/src/org/apache/cloudstack/api/ApiConstants.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/ApiConstants.java b/api/src/org/apache/cloudstack/api/ApiConstants.java
index e3297d5..13bce07 100755
--- a/api/src/org/apache/cloudstack/api/ApiConstants.java
+++ b/api/src/org/apache/cloudstack/api/ApiConstants.java
@@ -478,6 +478,7 @@ public class ApiConstants {
     public static final String SOURCE_IP = "sourceipaddress";
     public static final String SOURCE_IP_NETWORK_ID = "sourceipaddressnetworkid";
     public static final String SCHEME = "scheme";
+    public static final String PROVIDER_TYPE = "providertype";
 
     public enum HostDetails {
         all, capacity, events, stats, min;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/0f215bc6/api/src/org/apache/cloudstack/api/command/admin/router/CreateVirtualRouterElementCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/admin/router/CreateVirtualRouterElementCmd.java
b/api/src/org/apache/cloudstack/api/command/admin/router/CreateVirtualRouterElementCmd.java
index 39fac13..b3fca5a 100644
--- a/api/src/org/apache/cloudstack/api/command/admin/router/CreateVirtualRouterElementCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/admin/router/CreateVirtualRouterElementCmd.java
@@ -31,6 +31,7 @@ import org.apache.cloudstack.api.response.VirtualRouterProviderResponse;
 import org.apache.log4j.Logger;
 
 import com.cloud.event.EventTypes;
+import com.cloud.exception.InvalidParameterValueException;
 import com.cloud.exception.ResourceAllocationException;
 import com.cloud.network.VirtualRouterProvider;
 import com.cloud.network.VirtualRouterProvider.VirtualRouterProviderType;
@@ -52,6 +53,9 @@ public class CreateVirtualRouterElementCmd extends BaseAsyncCreateCmd {
 
     @Parameter(name=ApiConstants.NETWORK_SERVICE_PROVIDER_ID, type=CommandType.UUID, entityType
= ProviderResponse.class, required=true, description="the network service provider ID of the
virtual router element")
     private Long nspId;
+    
+    @Parameter(name=ApiConstants.PROVIDER_TYPE, type=CommandType.UUID, entityType = ProviderResponse.class,
description="The provider type. Supported types are VirtualRouter (default) and VPCVirtualRouter")
+    private String providerType;
 
     /////////////////////////////////////////////////////
     /////////////////// Accessors ///////////////////////
@@ -61,16 +65,27 @@ public class CreateVirtualRouterElementCmd extends BaseAsyncCreateCmd
{
         this.nspId = nspId;
     }
 
-
-
     public Long getNspId() {
         return nspId;
     }
+    
+    public VirtualRouterProviderType getProviderType() {
+        if (providerType != null) {
+            if (providerType.equalsIgnoreCase(VirtualRouterProviderType.VirtualRouter.toString()))
{
+                return VirtualRouterProviderType.VirtualRouter;
+            } else if (providerType.equalsIgnoreCase(VirtualRouterProviderType.VPCVirtualRouter.toString()))
{
+                return VirtualRouterProviderType.VPCVirtualRouter;
+            } else throw new InvalidParameterValueException("Invalid providerType specified");
+        } 
+        return VirtualRouterProviderType.VirtualRouter;
+    }
 
     /////////////////////////////////////////////////////
     /////////////// API Implementation///////////////////
     /////////////////////////////////////////////////////
 
+
+
     @Override
     public String getCommandName() {
         return s_name;
@@ -96,7 +111,7 @@ public class CreateVirtualRouterElementCmd extends BaseAsyncCreateCmd {
 
     @Override
     public void create() throws ResourceAllocationException {
-        VirtualRouterProvider result = _service.get(0).addElement(getNspId(), VirtualRouterProviderType.VirtualRouter);
+        VirtualRouterProvider result = _service.get(0).addElement(getNspId(), getProviderType());
         if (result != null) {
             setEntityId(result.getId());
             setEntityUuid(result.getUuid());

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/0f215bc6/api/src/org/apache/cloudstack/api/response/VirtualRouterProviderResponse.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/response/VirtualRouterProviderResponse.java
b/api/src/org/apache/cloudstack/api/response/VirtualRouterProviderResponse.java
index 92d9a1d..14532dd 100644
--- a/api/src/org/apache/cloudstack/api/response/VirtualRouterProviderResponse.java
+++ b/api/src/org/apache/cloudstack/api/response/VirtualRouterProviderResponse.java
@@ -25,6 +25,7 @@ import com.cloud.serializer.Param;
 import com.google.gson.annotations.SerializedName;
 
 @EntityReference(value=VirtualRouterProvider.class)
+@SuppressWarnings("unused")
 public class VirtualRouterProviderResponse extends BaseResponse implements ControlledEntityResponse
{
     @SerializedName(ApiConstants.ID) @Param(description="the id of the router")
     private String id;
@@ -49,6 +50,9 @@ public class VirtualRouterProviderResponse extends BaseResponse implements
Contr
 
     @SerializedName(ApiConstants.DOMAIN) @Param(description="the domain associated with the
provider")
     private String domainName;
+    
+    @SerializedName(ApiConstants.TYPE) @Param(description="Type of the service provider")
+    private String type;
 
     @Override
     public void setAccountName(String accountName) {
@@ -86,4 +90,8 @@ public class VirtualRouterProviderResponse extends BaseResponse implements
Contr
     public void setEnabled(Boolean enabled) {
         this.enabled = enabled;
     }
+
+    public void setType(String type) {
+        this.type = type;
+    }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/0f215bc6/plugins/network-elements/internal-loadbalancer/src/org/apache/cloudstack/network/element/InternalLoadBalancerElement.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/internal-loadbalancer/src/org/apache/cloudstack/network/element/InternalLoadBalancerElement.java
b/plugins/network-elements/internal-loadbalancer/src/org/apache/cloudstack/network/element/InternalLoadBalancerElement.java
index 6d3269c..5157f44 100644
--- a/plugins/network-elements/internal-loadbalancer/src/org/apache/cloudstack/network/element/InternalLoadBalancerElement.java
+++ b/plugins/network-elements/internal-loadbalancer/src/org/apache/cloudstack/network/element/InternalLoadBalancerElement.java
@@ -26,6 +26,9 @@ import java.util.Set;
 import javax.ejb.Local;
 import javax.inject.Inject;
 
+import org.apache.cloudstack.api.command.admin.router.ConfigureVirtualRouterElementCmd;
+import org.apache.cloudstack.api.command.admin.router.CreateVirtualRouterElementCmd;
+import org.apache.cloudstack.api.command.admin.router.ListVirtualRouterElementsCmd;
 import org.apache.log4j.Logger;
 
 import com.cloud.agent.api.to.LoadBalancerTO;
@@ -40,11 +43,16 @@ import com.cloud.network.Network.Service;
 import com.cloud.network.NetworkModel;
 import com.cloud.network.Networks.TrafficType;
 import com.cloud.network.PhysicalNetworkServiceProvider;
+import com.cloud.network.VirtualRouterProvider;
+import com.cloud.network.VirtualRouterProvider.VirtualRouterProviderType;
 import com.cloud.network.dao.NetworkServiceMapDao;
+import com.cloud.network.dao.VirtualRouterProviderDao;
 import com.cloud.network.element.IpDeployer;
 import com.cloud.network.element.LoadBalancingServiceProvider;
 import com.cloud.network.element.NetworkElement;
 import com.cloud.network.element.VirtualRouterElement;
+import com.cloud.network.element.VirtualRouterElementService;
+import com.cloud.network.element.VirtualRouterProviderVO;
 import com.cloud.network.lb.LoadBalancingRule;
 import com.cloud.network.router.VirtualRouter.Role;
 import com.cloud.network.rules.LoadBalancerContainer;
@@ -58,13 +66,14 @@ import com.cloud.vm.VirtualMachineProfile;
 import com.cloud.vm.dao.DomainRouterDao;
 
 @Local(value = {NetworkElement.class})
-public class InternalLoadBalancerElement extends AdapterBase implements LoadBalancingServiceProvider{
+public class InternalLoadBalancerElement extends AdapterBase implements LoadBalancingServiceProvider,
VirtualRouterElementService{
     private static final Logger s_logger = Logger.getLogger(InternalLoadBalancerElement.class);
     protected static final Map<Service, Map<Capability, String>> capabilities
= setCapabilities();
 
     @Inject NetworkModel _ntwkModel;
     @Inject NetworkServiceMapDao _ntwkSrvcDao;
     @Inject DomainRouterDao _routerDao;
+    @Inject VirtualRouterProviderDao _vrProviderDao;
     
     private boolean canHandle(Network config, List<LoadBalancingRule> rules) {
         if (config.getGuestType() != Network.GuestType.Isolated || config.getTrafficType()
!= TrafficType.Guest) {
@@ -200,4 +209,43 @@ public class InternalLoadBalancerElement extends AdapterBase implements
LoadBala
         return capabilities;
     }
 
+    @Override
+    public List<Class<?>> getCommands() {
+        List<Class<?>> cmdList = new ArrayList<Class<?>>();
+        cmdList.add(CreateVirtualRouterElementCmd.class);
+        cmdList.add(ConfigureVirtualRouterElementCmd.class);
+        cmdList.add(ListVirtualRouterElementsCmd.class);
+        return cmdList;
+    }
+
+    @Override
+    public VirtualRouterProvider configure(ConfigureVirtualRouterElementCmd cmd) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public VirtualRouterProvider addElement(Long nspId, VirtualRouterProviderType providerType)
{
+        VirtualRouterProviderVO element = _vrProviderDao.findByNspIdAndType(nspId, providerType);
+        if (element != null) {
+            s_logger.debug("There is already a virtual router element with service provider
id " + nspId);
+            return null;
+        }
+        element = new VirtualRouterProviderVO(nspId, providerType);
+        _vrProviderDao.persist(element);
+        return element;
+    }
+
+    @Override
+    public VirtualRouterProvider getCreatedElement(long id) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public List<? extends VirtualRouterProvider> searchForVirtualRouterElement(ListVirtualRouterElementsCmd
cmd) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/0f215bc6/server/src/com/cloud/api/ApiResponseHelper.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/ApiResponseHelper.java b/server/src/com/cloud/api/ApiResponseHelper.java
index d360075..724a511 100755
--- a/server/src/com/cloud/api/ApiResponseHelper.java
+++ b/server/src/com/cloud/api/ApiResponseHelper.java
@@ -2768,6 +2768,7 @@ public class ApiResponseHelper implements ResponseGenerator {
             response.setNspId(nsp.getUuid());
         }
         response.setEnabled(result.isEnabled());
+        response.setType(result.getType().toString());
 
         response.setObjectName("virtualrouterelement");
         return response;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/0f215bc6/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 b0dcee0..00b0ac4 100755
--- a/server/src/com/cloud/network/NetworkServiceImpl.java
+++ b/server/src/com/cloud/network/NetworkServiceImpl.java
@@ -3089,7 +3089,7 @@ public class NetworkServiceImpl extends ManagerBase implements  NetworkService
{
         }
         
         VirtualRouterElement element = (VirtualRouterElement)networkElement;
-        element.addElement(nsp.getId(), VirtualRouterProviderType.VirtualRouter);
+        element.addElement(nsp.getId(), VirtualRouterProviderType.InternalLbVm);
 
         return nsp;
     }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/0f215bc6/server/src/com/cloud/network/element/VirtualRouterElement.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/element/VirtualRouterElement.java b/server/src/com/cloud/network/element/VirtualRouterElement.java
index bf9ac49..7a13703 100755
--- a/server/src/com/cloud/network/element/VirtualRouterElement.java
+++ b/server/src/com/cloud/network/element/VirtualRouterElement.java
@@ -90,8 +90,6 @@ import com.cloud.vm.dao.DomainRouterDao;
 import com.cloud.vm.dao.UserVmDao;
 import com.google.gson.Gson;
 
-import edu.emory.mathcs.backport.java.util.Arrays;
-
 @Local(value = {NetworkElement.class, FirewallServiceProvider.class, 
 		        DhcpServiceProvider.class, UserDataServiceProvider.class, 
 		        StaticNatServiceProvider.class, LoadBalancingServiceProvider.class,
@@ -723,8 +721,8 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
     @Override
     public VirtualRouterProvider configure(ConfigureVirtualRouterElementCmd cmd) {
         VirtualRouterProviderVO element = _vrProviderDao.findById(cmd.getId());
-        if (element == null) {
-            s_logger.debug("Can't find element with network service provider id " + cmd.getId());
+        if (element == null || !(element.getType() == VirtualRouterProviderType.VirtualRouter
|| element.getType() == VirtualRouterProviderType.VPCVirtualRouter)) {
+            s_logger.debug("Can't find Virtual Router element with network service provider
id " + cmd.getId());
             return null;
         }
 
@@ -736,6 +734,10 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
 
     @Override
     public VirtualRouterProvider addElement(Long nspId, VirtualRouterProviderType providerType)
{
+        if (!(providerType != VirtualRouterProviderType.VirtualRouter) || (providerType !=
VirtualRouterProviderType.VPCVirtualRouter)) {
+            throw new InvalidParameterValueException("Element " + this.getName() + " supports
only providerTypes: " + 
+        VirtualRouterProviderType.VirtualRouter.toString() + " and " + VirtualRouterProviderType.VPCVirtualRouter);
+        }
         VirtualRouterProviderVO element = _vrProviderDao.findByNspIdAndType(nspId, providerType);
         if (element != null) {
             s_logger.debug("There is already a virtual router element with service provider
id " + nspId);
@@ -919,6 +921,10 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
         if (enabled != null) {
             sc.addAnd(sc.getEntity().isEnabled(), Op.EQ, enabled);
         }
+        
+        //return only VR and VPC VR
+        sc.addAnd(sc.getEntity().getType(), Op.IN, VirtualRouterProvider.VirtualRouterProviderType.VPCVirtualRouter,
VirtualRouterProvider.VirtualRouterProviderType.VirtualRouter);
+        
         return sc.list();
     }
 


Mime
View raw message