cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alena1...@apache.org
Subject [2/2] git commit: updated refs/heads/internallb to c113ea1
Date Fri, 12 Apr 2013 19:21:57 GMT
Add Internal Lb Provider/Element as a part of adding a physical network


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

Branch: refs/heads/internallb
Commit: c113ea184b575ccae5d2be411c5bbc345473e35e
Parents: 78c9db7
Author: Alena Prokharchyk <alena.prokharchyk@citrix.com>
Authored: Fri Apr 12 12:00:09 2013 -0700
Committer: Alena Prokharchyk <alena.prokharchyk@citrix.com>
Committed: Fri Apr 12 12:21:24 2013 -0700

----------------------------------------------------------------------
 .../ConfigureInternalLoadBalancerElementCmd.java   |   26 +--------
 .../CreateInternalLoadBalancerElementCmd.java      |    4 +-
 .../ListInternalLoadBalancerElementsCmd.java       |   18 +------
 .../InternalLoadBalancerElementService.java        |   36 +++++++++++--
 .../element/InternalLoadBalancerElement.java       |   40 +++++++++------
 .../network/lb/InternalLoadBalancerManager.java    |    6 ++
 .../src/com/cloud/network/NetworkManagerImpl.java  |    1 -
 .../src/com/cloud/network/NetworkServiceImpl.java  |   22 ++++++++
 8 files changed, 90 insertions(+), 63 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c113ea18/api/src/org/apache/cloudstack/api/command/admin/internallb/ConfigureInternalLoadBalancerElementCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/admin/internallb/ConfigureInternalLoadBalancerElementCmd.java
b/api/src/org/apache/cloudstack/api/command/admin/internallb/ConfigureInternalLoadBalancerElementCmd.java
index 89b0f39..1bd6bda 100644
--- a/api/src/org/apache/cloudstack/api/command/admin/internallb/ConfigureInternalLoadBalancerElementCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/admin/internallb/ConfigureInternalLoadBalancerElementCmd.java
@@ -31,7 +31,6 @@ import org.apache.cloudstack.api.response.VirtualRouterProviderResponse;
 import org.apache.cloudstack.network.element.InternalLoadBalancerElementService;
 import org.apache.log4j.Logger;
 
-import com.cloud.async.AsyncJob;
 import com.cloud.event.EventTypes;
 import com.cloud.exception.ConcurrentOperationException;
 import com.cloud.exception.InsufficientCapacityException;
@@ -41,7 +40,7 @@ import com.cloud.user.Account;
 import com.cloud.user.UserContext;
 
 @APICommand(name = "configureInternalLoadBalancerElement", responseObject=VirtualRouterProviderResponse.class,
-            description="Configures an internal load balancer element.", since="4.2.0")
+            description="Configures an Internal Load Balancer element.", since="4.2.0")
 public class ConfigureInternalLoadBalancerElementCmd extends BaseAsyncCmd {
     public static final Logger s_logger = Logger.getLogger(ConfigureInternalLoadBalancerElementCmd.class.getName());
     private static final String s_name = "configureinternalloadbalancerelementresponse";
@@ -57,25 +56,18 @@ public class ConfigureInternalLoadBalancerElementCmd extends BaseAsyncCmd
{
             required=true, description="the ID of the internal lb provider")
     private Long id;
 
-    @Parameter(name=ApiConstants.ENABLED, type=CommandType.BOOLEAN, required=true, description="Enables/Disables
the Internal load balancer element")
+    @Parameter(name=ApiConstants.ENABLED, type=CommandType.BOOLEAN, required=true, description="Enables/Disables
the Internal Load Balancer element")
     private Boolean enabled;
 
     /////////////////////////////////////////////////////
     /////////////////// Accessors ///////////////////////
     /////////////////////////////////////////////////////
 
-    public void setId(Long id) {
-        this.id = id;
-    }
 
     public Long getId() {
         return id;
     }
 
-    public void setEnabled(Boolean enabled) {
-        this.enabled = enabled;
-    }
-
     public Boolean getEnabled() {
         return enabled;
     }
@@ -89,10 +81,6 @@ public class ConfigureInternalLoadBalancerElementCmd extends BaseAsyncCmd
{
         return s_name;
     }
 
-    public static String getResultObjectName() {
-        return "boolean";
-    }
-
     @Override
     public long getEntityOwnerId() {
         return Account.ACCOUNT_ID_SYSTEM;
@@ -108,20 +96,12 @@ public class ConfigureInternalLoadBalancerElementCmd extends BaseAsyncCmd
{
         return  "configuring internal load balancer element: " + id;
     }
 
-    public AsyncJob.Type getInstanceType() {
-        return AsyncJob.Type.None;
-    }
-
-    public Long getInstanceId() {
-        return id;
-    }
-
     @Override
     public void execute() throws ConcurrentOperationException, ResourceUnavailableException,
InsufficientCapacityException{
         s_logger.debug("hello alena");
         UserContext.current().setEventDetails("Internal load balancer element: " + id);
         s_logger.debug("hello alena");
-        VirtualRouterProvider result = _service.get(0).configure(this);
+        VirtualRouterProvider result = _service.get(0).configureInternalLoadBalancerElement(getId(),
getEnabled());
         s_logger.debug("hello alena");
         if (result != null){
             VirtualRouterProviderResponse routerResponse = _responseGenerator.createVirtualRouterProviderResponse(result);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c113ea18/api/src/org/apache/cloudstack/api/command/admin/internallb/CreateInternalLoadBalancerElementCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/admin/internallb/CreateInternalLoadBalancerElementCmd.java
b/api/src/org/apache/cloudstack/api/command/admin/internallb/CreateInternalLoadBalancerElementCmd.java
index ec6305e..32c47bc 100644
--- a/api/src/org/apache/cloudstack/api/command/admin/internallb/CreateInternalLoadBalancerElementCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/admin/internallb/CreateInternalLoadBalancerElementCmd.java
@@ -83,7 +83,7 @@ public class CreateInternalLoadBalancerElementCmd extends BaseAsyncCreateCmd
{
     @Override
     public void execute(){
         UserContext.current().setEventDetails("Virtual router element Id: "+getEntityId());
-        VirtualRouterProvider result = _service.get(0).getCreatedElement(getEntityId());
+        VirtualRouterProvider result = _service.get(0).getInternalLoadBalancerElement(getEntityId());
         if (result != null) {
             VirtualRouterProviderResponse response = _responseGenerator.createVirtualRouterProviderResponse(result);
             response.setResponseName(getCommandName());
@@ -95,7 +95,7 @@ public class CreateInternalLoadBalancerElementCmd extends BaseAsyncCreateCmd
{
 
     @Override
     public void create() throws ResourceAllocationException {
-        VirtualRouterProvider result = _service.get(0).addElement(getNspId());
+        VirtualRouterProvider result = _service.get(0).addInternalLoadBalancerElement(getNspId());
         if (result != null) {
             setEntityId(result.getId());
             setEntityUuid(result.getUuid());

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c113ea18/api/src/org/apache/cloudstack/api/command/admin/internallb/ListInternalLoadBalancerElementsCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/admin/internallb/ListInternalLoadBalancerElementsCmd.java
b/api/src/org/apache/cloudstack/api/command/admin/internallb/ListInternalLoadBalancerElementsCmd.java
index 56e99fb..122c233 100644
--- a/api/src/org/apache/cloudstack/api/command/admin/internallb/ListInternalLoadBalancerElementsCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/admin/internallb/ListInternalLoadBalancerElementsCmd.java
@@ -39,14 +39,14 @@ import com.cloud.exception.ResourceAllocationException;
 import com.cloud.exception.ResourceUnavailableException;
 import com.cloud.network.VirtualRouterProvider;
 
-@APICommand(name = "listInternalLoadBalancerElements", description="Lists all available internal
load balancer elements.",
+@APICommand(name = "listInternalLoadBalancerElements", description="Lists all available Internal
Load Balancer elements.",
             responseObject=VirtualRouterProviderResponse.class, since="4.2.0")
 public class ListInternalLoadBalancerElementsCmd extends BaseListCmd {
     public static final Logger s_logger = Logger.getLogger(ListNetworkOfferingsCmd.class.getName());
     private static final String _name = "listinternalloadbalancerelementsresponse";
 
     @Inject
-    private List<InternalLoadBalancerElementService> _service;
+    private InternalLoadBalancerElementService _service;
 
     /////////////////////////////////////////////////////
     //////////////// API parameters /////////////////////
@@ -66,26 +66,14 @@ public class ListInternalLoadBalancerElementsCmd extends BaseListCmd {
     /////////////////// Accessors ///////////////////////
     /////////////////////////////////////////////////////
 
-    public void setId(Long id) {
-        this.id = id;
-    }
-
     public Long getId() {
         return id;
     }
 
-    public void setNspId(Long nspId) {
-        this.nspId = nspId;
-    }
-
     public Long getNspId() {
         return nspId;
     }
 
-    public void setEnabled(Boolean enabled) {
-        this.enabled = enabled;
-    }
-
     public Boolean getEnabled() {
         return enabled;
     }
@@ -97,7 +85,7 @@ public class ListInternalLoadBalancerElementsCmd extends BaseListCmd {
 
     @Override
     public void execute() throws ResourceUnavailableException, InsufficientCapacityException,
ServerApiException, ConcurrentOperationException, ResourceAllocationException {
-        List<? extends VirtualRouterProvider> providers = _service.get(0).searchForInternalLoadBalancerElements(this);
+        List<? extends VirtualRouterProvider> providers = _service.searchForInternalLoadBalancerElements(getId(),
getNspId(), getEnabled());
         ListResponse<VirtualRouterProviderResponse> response = new ListResponse<VirtualRouterProviderResponse>();
         List<VirtualRouterProviderResponse> providerResponses = new ArrayList<VirtualRouterProviderResponse>();
         for (VirtualRouterProvider provider : providers) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c113ea18/api/src/org/apache/cloudstack/network/element/InternalLoadBalancerElementService.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/network/element/InternalLoadBalancerElementService.java
b/api/src/org/apache/cloudstack/network/element/InternalLoadBalancerElementService.java
index b05e759..33a0c64 100644
--- a/api/src/org/apache/cloudstack/network/element/InternalLoadBalancerElementService.java
+++ b/api/src/org/apache/cloudstack/network/element/InternalLoadBalancerElementService.java
@@ -18,15 +18,39 @@ package org.apache.cloudstack.network.element;
 
 import java.util.List;
 
-import org.apache.cloudstack.api.command.admin.internallb.ConfigureInternalLoadBalancerElementCmd;
-import org.apache.cloudstack.api.command.admin.internallb.ListInternalLoadBalancerElementsCmd;
 
 import com.cloud.network.VirtualRouterProvider;
 import com.cloud.utils.component.PluggableService;
 
 public interface InternalLoadBalancerElementService extends PluggableService{
-    VirtualRouterProvider configure(ConfigureInternalLoadBalancerElementCmd cmd);
-    VirtualRouterProvider addElement(Long nspId);
-    VirtualRouterProvider getCreatedElement(long id);
-    List<? extends VirtualRouterProvider> searchForInternalLoadBalancerElements(ListInternalLoadBalancerElementsCmd
cmd);
+    /**
+     * Configures existing Internal Load Balancer Element (enables or disables it)
+     * @param id
+     * @param enable
+     * @return
+     */
+    VirtualRouterProvider configureInternalLoadBalancerElement(long id, boolean enable);
+    
+    /**
+     * Adds Internal Load Balancer element to the Network Service Provider
+     * @param ntwkSvcProviderId
+     * @return
+     */
+    VirtualRouterProvider addInternalLoadBalancerElement(long ntwkSvcProviderId);
+    
+    /**
+     * Retrieves existing Internal Load Balancer element
+     * @param id
+     * @return
+     */
+    VirtualRouterProvider getInternalLoadBalancerElement(long id);
+    
+    /**
+     * Searches for existing Internal Load Balancer elements based on parameters passed to
the call
+     * @param id
+     * @param ntwkSvsProviderId
+     * @param enabled
+     * @return
+     */
+    List<? extends VirtualRouterProvider> searchForInternalLoadBalancerElements(Long
id, Long ntwkSvsProviderId, Boolean enabled);
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c113ea18/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 0c662a8..1067bd5 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
@@ -85,6 +85,7 @@ import com.cloud.vm.dao.DomainRouterDao;
 public class InternalLoadBalancerElement extends AdapterBase implements LoadBalancingServiceProvider,
InternalLoadBalancerElementService, IpDeployer{
     private static final Logger s_logger = Logger.getLogger(InternalLoadBalancerElement.class);
     protected static final Map<Service, Map<Capability, String>> capabilities
= setCapabilities();
+    private static InternalLoadBalancerElement internalLbElement = null;
 
     @Inject NetworkModel _ntwkModel;
     @Inject NetworkServiceMapDao _ntwkSrvcDao;
@@ -95,6 +96,16 @@ public class InternalLoadBalancerElement extends AdapterBase implements
LoadBala
     @Inject ConfigurationManager _configMgr;
     @Inject AccountManager _accountMgr;
     
+    protected InternalLoadBalancerElement() {
+    }
+    
+    public static InternalLoadBalancerElement getInstance() {
+        if ( internalLbElement == null) {
+            internalLbElement = new InternalLoadBalancerElement();
+        }
+        return internalLbElement;
+     }
+    
     private boolean canHandle(Network config, List<LoadBalancingRule> rules) {
         //works in Advance zone only
         DataCenter dc = _configMgr.getZone(config.getDataCenterId());
@@ -405,40 +416,40 @@ public class InternalLoadBalancerElement extends AdapterBase implements
LoadBala
     }
 
     @Override
-    public VirtualRouterProvider configure(ConfigureInternalLoadBalancerElementCmd cmd) {
-        VirtualRouterProviderVO element = _vrProviderDao.findById(cmd.getId());
+    public VirtualRouterProvider configureInternalLoadBalancerElement(long id, boolean enable)
{
+        VirtualRouterProviderVO element = _vrProviderDao.findById(id);
         if (element == null || element.getType() != VirtualRouterProviderType.InternalLbVm)
{
-            s_logger.debug("Can't find " + this.getName() + " element with network service
provider id " + cmd.getId() +
+            s_logger.debug("Can't find " + this.getName() + " element with network service
provider id " + id +
                     " to be used as a provider for " + this.getName());
             return null;
         }
 
-        element.setEnabled(cmd.getEnabled());
+        element.setEnabled(enable);
         _vrProviderDao.persist(element);
 
         return element;
     }
 
     @Override
-    public VirtualRouterProvider addElement(Long nspId) {
-        VirtualRouterProviderVO element = _vrProviderDao.findByNspIdAndType(nspId, VirtualRouterProviderType.InternalLbVm);
+    public VirtualRouterProvider addInternalLoadBalancerElement(long ntwkSvcProviderId) {
+        VirtualRouterProviderVO element = _vrProviderDao.findByNspIdAndType(ntwkSvcProviderId,
VirtualRouterProviderType.InternalLbVm);
         if (element != null) {
-            s_logger.debug("There is already an " + this.getName() + " with service provider
id " + nspId);
+            s_logger.debug("There is already an " + this.getName() + " with service provider
id " + ntwkSvcProviderId);
             return null;
         }
         
-        PhysicalNetworkServiceProvider provider = _pNtwkSvcProviderDao.findById(nspId);
+        PhysicalNetworkServiceProvider provider = _pNtwkSvcProviderDao.findById(ntwkSvcProviderId);
         if (provider == null || !provider.getProviderName().equalsIgnoreCase(this.getName()))
{
             throw new InvalidParameterValueException("Invalid network service provider is
specified");
         }
         
-        element = new VirtualRouterProviderVO(nspId, VirtualRouterProviderType.InternalLbVm);
+        element = new VirtualRouterProviderVO(ntwkSvcProviderId, VirtualRouterProviderType.InternalLbVm);
         _vrProviderDao.persist(element);
         return element;
     }
 
     @Override
-    public VirtualRouterProvider getCreatedElement(long id) {
+    public VirtualRouterProvider getInternalLoadBalancerElement(long id) {
         VirtualRouterProvider provider = _vrProviderDao.findById(id);
         if (provider.getType() != VirtualRouterProviderType.InternalLbVm) {
             throw new InvalidParameterValueException("Unable to find " + this.getName() +
" by id");
@@ -447,17 +458,14 @@ public class InternalLoadBalancerElement extends AdapterBase implements
LoadBala
     }
 
     @Override
-    public List<? extends VirtualRouterProvider> searchForInternalLoadBalancerElements(ListInternalLoadBalancerElementsCmd
cmd) {
-        Long id = cmd.getId();
-        Long nspId = cmd.getNspId();
-        Boolean enabled = cmd.getEnabled();
+    public List<? extends VirtualRouterProvider> searchForInternalLoadBalancerElements(Long
id, Long ntwkSvsProviderId, Boolean enabled) {
 
         SearchCriteriaService<VirtualRouterProviderVO, VirtualRouterProviderVO> sc
= SearchCriteria2.create(VirtualRouterProviderVO.class);
         if (id != null) {
             sc.addAnd(sc.getEntity().getId(), Op.EQ, id);
         }
-        if (nspId != null) {
-            sc.addAnd(sc.getEntity().getNspId(), Op.EQ, nspId);
+        if (ntwkSvsProviderId != null) {
+            sc.addAnd(sc.getEntity().getNspId(), Op.EQ, ntwkSvsProviderId);
         }
         if (enabled != null) {
             sc.addAnd(sc.getEntity().isEnabled(), Op.EQ, enabled);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c113ea18/plugins/network-elements/internal-loadbalancer/src/org/apache/cloudstack/network/lb/InternalLoadBalancerManager.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/internal-loadbalancer/src/org/apache/cloudstack/network/lb/InternalLoadBalancerManager.java
b/plugins/network-elements/internal-loadbalancer/src/org/apache/cloudstack/network/lb/InternalLoadBalancerManager.java
index 0d817de..b869b2a 100644
--- a/plugins/network-elements/internal-loadbalancer/src/org/apache/cloudstack/network/lb/InternalLoadBalancerManager.java
+++ b/plugins/network-elements/internal-loadbalancer/src/org/apache/cloudstack/network/lb/InternalLoadBalancerManager.java
@@ -108,6 +108,12 @@ public interface InternalLoadBalancerManager extends Manager{
             throws ResourceUnavailableException;
 
 
+    /**
+     * Returns existing Internal Load Balancer elements based on guestNetworkId (requried)
and requestedIp (optional)
+     * @param guestNetworkId
+     * @param requestedGuestIp
+     * @return
+     */
     List<DomainRouterVO> findInternalLbVms(long guestNetworkId, Ip requestedGuestIp);
 
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c113ea18/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 85d0d9e..86bcedd 100755
--- a/server/src/com/cloud/network/NetworkManagerImpl.java
+++ b/server/src/com/cloud/network/NetworkManagerImpl.java
@@ -165,7 +165,6 @@ 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.DB;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c113ea18/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 60b700f..c8fa66e 100755
--- a/server/src/com/cloud/network/NetworkServiceImpl.java
+++ b/server/src/com/cloud/network/NetworkServiceImpl.java
@@ -43,6 +43,7 @@ import org.apache.cloudstack.api.command.user.network.CreateNetworkCmd;
 import org.apache.cloudstack.api.command.user.network.ListNetworksCmd;
 import org.apache.cloudstack.api.command.user.network.RestartNetworkCmd;
 import org.apache.cloudstack.api.command.user.vm.ListNicsCmd;
+import org.apache.cloudstack.network.element.InternalLoadBalancerElementService;
 import org.apache.log4j.Logger;
 import org.springframework.stereotype.Component;
 
@@ -258,6 +259,8 @@ public class NetworkServiceImpl extends ManagerBase implements  NetworkService
{
     HostDao _hostDao;
     @Inject
     HostPodDao _hostPodDao;
+    @Inject 
+    InternalLoadBalancerElementService _internalLbElementSvc;
 
     int _cidrLimit;
     boolean _allowSubdomainNetworkAccess;
@@ -2256,6 +2259,9 @@ public class NetworkServiceImpl extends ManagerBase implements  NetworkService
{
             // add baremetal as the defualt network service provider
             /* addDefaultBaremetalProvidersToPhysicalNetwork(pNetwork.getId()); */
             
+            //Add Internal Load Balancer element as a default network service provider
+            addDefaultInternalLbProviderToPhysicalNetwork(pNetwork.getId());
+            
             txn.commit();
             return pNetwork;
         } catch (Exception ex) {
@@ -3081,6 +3087,22 @@ public class NetworkServiceImpl extends ManagerBase implements  NetworkService
{
 
         return nsp;
     }
+    
+    
+    protected PhysicalNetworkServiceProvider addDefaultInternalLbProviderToPhysicalNetwork(long
physicalNetworkId) {
+
+        PhysicalNetworkServiceProvider nsp = addProviderToPhysicalNetwork(physicalNetworkId,

+                Network.Provider.InternalLbVm.getName(), null, null);
+ 
+        NetworkElement networkElement =  _networkModel.getElementImplementingProvider(Network.Provider.InternalLbVm.getName());
+        if (networkElement == null) {
+            throw new CloudRuntimeException("Unable to find the Network Element implementing
the " + Network.Provider.InternalLbVm.getName() + " Provider");
+        }
+        
+        _internalLbElementSvc.addInternalLoadBalancerElement(nsp.getId());
+
+        return nsp;
+    }
 
     protected PhysicalNetworkServiceProvider addDefaultSecurityGroupProviderToPhysicalNetwork(long
physicalNetworkId) {
 


Mime
View raw message