cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ni...@apache.org
Subject [01/55] [abbrv] CLOUDSTACK-747: Internal LB between VPC tiers support
Date Mon, 13 May 2013 11:07:53 GMT
Updated Branches:
  refs/heads/cs2163 941a9a5fb -> 8d53b1ef0


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/2660a6b7/server/test/org/apache/cloudstack/lb/ApplicationLoadBalancerTest.java
----------------------------------------------------------------------
diff --git a/server/test/org/apache/cloudstack/lb/ApplicationLoadBalancerTest.java b/server/test/org/apache/cloudstack/lb/ApplicationLoadBalancerTest.java
new file mode 100644
index 0000000..461cbbd
--- /dev/null
+++ b/server/test/org/apache/cloudstack/lb/ApplicationLoadBalancerTest.java
@@ -0,0 +1,292 @@
+// 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 org.apache.cloudstack.lb;
+
+import java.lang.reflect.Field;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.inject.Inject;
+
+import junit.framework.TestCase;
+
+import org.apache.cloudstack.lb.dao.ApplicationLoadBalancerRuleDao;
+import org.apache.cloudstack.network.lb.ApplicationLoadBalancerManagerImpl;
+import org.apache.cloudstack.network.lb.ApplicationLoadBalancerRule;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mockito;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+import com.cloud.event.dao.UsageEventDao;
+import com.cloud.exception.InsufficientAddressCapacityException;
+import com.cloud.exception.InsufficientVirtualNetworkCapcityException;
+import com.cloud.exception.InvalidParameterValueException;
+import com.cloud.exception.NetworkRuleConflictException;
+import com.cloud.exception.UnsupportedServiceException;
+import com.cloud.network.Network;
+import com.cloud.network.Network.Capability;
+import com.cloud.network.Network.Service;
+import com.cloud.network.NetworkModel;
+import com.cloud.network.Networks.TrafficType;
+import com.cloud.network.dao.FirewallRulesDao;
+import com.cloud.network.dao.NetworkVO;
+import com.cloud.network.lb.LoadBalancingRule;
+import com.cloud.network.lb.LoadBalancingRulesManager;
+import com.cloud.network.rules.FirewallRuleVO;
+import com.cloud.network.rules.LoadBalancerContainer.Scheme;
+import com.cloud.user.AccountManager;
+import com.cloud.user.AccountVO;
+import com.cloud.user.UserContext;
+import com.cloud.user.UserVO;
+import com.cloud.utils.component.ComponentContext;
+import com.cloud.utils.exception.CloudRuntimeException;
+import com.cloud.utils.net.Ip;
+import com.cloud.utils.net.NetUtils;
+
+/**
+ * This class is responsible for unittesting the methods defined in ApplicationLoadBalancerService
+ *
+ */
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(locations="classpath:/appLoadBalancer.xml")
+public class ApplicationLoadBalancerTest extends TestCase{
+    //The interface to test
+    @Inject ApplicationLoadBalancerManagerImpl _appLbSvc;
+    
+    //The interfaces below are mocked
+    @Inject ApplicationLoadBalancerRuleDao _lbDao;
+    @Inject LoadBalancingRulesManager _lbMgr;
+    @Inject NetworkModel _ntwkModel;
+    @Inject AccountManager _accountMgr;
+    @Inject FirewallRulesDao _firewallDao;
+    @Inject UsageEventDao _usageEventDao;
+
+    
+    public static long existingLbId = 1L;
+    public static long nonExistingLbId = 2L;
+    
+    public static long validGuestNetworkId = 1L;
+    public static long invalidGuestNetworkId = 2L;
+    public static long validPublicNetworkId = 3L;
+    
+    public static long validAccountId = 1L;
+    public static long invalidAccountId = 2L;
+    
+    public String validRequestedIp = "10.1.1.1";
+
+
+    
+    @Before
+    public void setUp() {
+        ComponentContext.initComponentsLifeCycle();
+        //mockito for .getApplicationLoadBalancer tests
+        Mockito.when(_lbDao.findById(1L)).thenReturn(new ApplicationLoadBalancerRuleVO());
+        Mockito.when(_lbDao.findById(2L)).thenReturn(null);
+        
+        //mockito for .deleteApplicationLoadBalancer tests
+        Mockito.when(_lbMgr.deleteLoadBalancerRule(existingLbId, true)).thenReturn(true);
+        Mockito.when(_lbMgr.deleteLoadBalancerRule(nonExistingLbId, true)).thenReturn(false);
+        
+        //mockito for .createApplicationLoadBalancer tests
+        NetworkVO guestNetwork = new NetworkVO(TrafficType.Guest, null, null, 1,
+                null, 1, 1L);
+        setId(guestNetwork, validGuestNetworkId);
+        guestNetwork.setCidr("10.1.1.1/24");
+        
+        NetworkVO publicNetwork = new NetworkVO(TrafficType.Public, null, null, 1,
+                null, 1, 1L);
+   
+        Mockito.when(_ntwkModel.getNetwork(validGuestNetworkId)).thenReturn(guestNetwork);
+        Mockito.when(_ntwkModel.getNetwork(invalidGuestNetworkId)).thenReturn(null);
+        Mockito.when(_ntwkModel.getNetwork(validPublicNetworkId)).thenReturn(publicNetwork);
+
+        Mockito.when(_accountMgr.getAccount(validAccountId)).thenReturn(new AccountVO());
+        Mockito.when(_accountMgr.getAccount(invalidAccountId)).thenReturn(null);
+        Mockito.when(_ntwkModel.areServicesSupportedInNetwork(validGuestNetworkId, Service.Lb)).thenReturn(true);
+        Mockito.when(_ntwkModel.areServicesSupportedInNetwork(invalidGuestNetworkId, Service.Lb)).thenReturn(false);
+        
+        ApplicationLoadBalancerRuleVO lbRule = new ApplicationLoadBalancerRuleVO("new", "new", 22, 22, "roundrobin",
+                validGuestNetworkId, validAccountId, 1L, new Ip(validRequestedIp), validGuestNetworkId, Scheme.Internal);
+        Mockito.when(_lbDao.persist(Mockito.any(ApplicationLoadBalancerRuleVO.class))).thenReturn(lbRule);
+        
+        Mockito.when(_lbMgr.validateLbRule(Mockito.any(LoadBalancingRule.class))).thenReturn(true);
+        
+        Mockito.when(_firewallDao.setStateToAdd(Mockito.any(FirewallRuleVO.class))).thenReturn(true);
+        
+        Mockito.when(_accountMgr.getSystemUser()).thenReturn(new UserVO(1));
+        Mockito.when(_accountMgr.getSystemAccount()).thenReturn(new AccountVO(2));
+        UserContext.registerContext(_accountMgr.getSystemUser().getId(), _accountMgr.getSystemAccount(), null, false);
+        
+        Mockito.when(_ntwkModel.areServicesSupportedInNetwork(Mockito.anyLong(), Mockito.any(Network.Service.class))).thenReturn(true);
+        
+        Map<Network.Capability, String> caps = new HashMap<Network.Capability, String>();
+        caps.put(Capability.SupportedProtocols, NetUtils.TCP_PROTO);
+        Mockito.when(_ntwkModel.getNetworkServiceCapabilities(Mockito.anyLong(), Mockito.any(Network.Service.class))).thenReturn(caps);
+        
+        
+        Mockito.when(_lbDao.countBySourceIp(new Ip(validRequestedIp), validGuestNetworkId)).thenReturn(1L);
+        
+    }
+    
+    /**
+     * TESTS FOR .getApplicationLoadBalancer
+     */
+    
+    @Test
+    //Positive test - retrieve existing lb
+    public void searchForExistingLoadBalancer() {
+        ApplicationLoadBalancerRule rule = _appLbSvc.getApplicationLoadBalancer(existingLbId);
+        assertNotNull("Couldn't find existing application load balancer", rule);
+    }
+    
+    @Test
+    //Negative test - try to retrieve non-existing lb
+    public void searchForNonExistingLoadBalancer() {
+        boolean notFound = false;
+        ApplicationLoadBalancerRule rule = null;
+        try {
+            rule = _appLbSvc.getApplicationLoadBalancer(nonExistingLbId);
+            if (rule != null) {
+                notFound = false; 
+            }
+        } catch (InvalidParameterValueException ex) {
+            notFound = true;
+        }
+        
+        assertTrue("Found non-existing load balancer; no invalid parameter value exception was thrown", notFound);
+    }
+    
+    /**
+     * TESTS FOR .deleteApplicationLoadBalancer
+     */
+    
+    
+    @Test
+    //Positive test - delete existing lb
+    public void deleteExistingLoadBalancer() {
+        boolean result = false; 
+        try {
+            result = _appLbSvc.deleteApplicationLoadBalancer(existingLbId);
+        } finally {
+            assertTrue("Couldn't delete existing application load balancer", result);   
+        }
+    }
+    
+    
+    @Test
+    //Negative test - try to delete non-existing lb
+    public void deleteNonExistingLoadBalancer() {
+        boolean result = true;
+        try {
+            result = _appLbSvc.deleteApplicationLoadBalancer(nonExistingLbId);
+        } finally {
+            assertFalse("Didn't fail when try to delete non-existing load balancer", result);
+        }
+    }
+    
+    /**
+     * TESTS FOR .createApplicationLoadBalancer
+     * @throws NetworkRuleConflictException 
+     * @throws InsufficientVirtualNetworkCapcityException 
+     * @throws InsufficientAddressCapacityException 
+     */
+    
+    @Test (expected = CloudRuntimeException.class)
+    //Positive test
+    public void createValidLoadBalancer() throws InsufficientAddressCapacityException,
+        InsufficientVirtualNetworkCapcityException, NetworkRuleConflictException {    
+        _appLbSvc.createApplicationLoadBalancer("alena", "alena", Scheme.Internal, validGuestNetworkId, validRequestedIp,
+                            22, 22, "roundrobin", validGuestNetworkId, validAccountId); 
+    }
+    
+    
+    @Test(expected = UnsupportedServiceException.class)
+    //Negative test - only internal scheme value is supported in the current release
+    public void createPublicLoadBalancer() throws InsufficientAddressCapacityException,
+    InsufficientVirtualNetworkCapcityException, NetworkRuleConflictException {
+        _appLbSvc.createApplicationLoadBalancer("alena", "alena", Scheme.Public, validGuestNetworkId, validRequestedIp,
+                            22, 22, "roundrobin", validGuestNetworkId, validAccountId);
+    }
+    
+    
+    @Test(expected = InvalidParameterValueException.class)
+    //Negative test - invalid SourcePort
+    public void createWithInvalidSourcePort() throws InsufficientAddressCapacityException,
+        InsufficientVirtualNetworkCapcityException, NetworkRuleConflictException {        
+        _appLbSvc.createApplicationLoadBalancer("alena", "alena", Scheme.Internal, validGuestNetworkId, validRequestedIp,
+                    65536, 22, "roundrobin", validGuestNetworkId, validAccountId);
+    }
+    
+    @Test(expected = InvalidParameterValueException.class)
+    //Negative test - invalid instancePort
+    public void createWithInvalidInstandePort() throws InsufficientAddressCapacityException,
+        InsufficientVirtualNetworkCapcityException, NetworkRuleConflictException {
+        _appLbSvc.createApplicationLoadBalancer("alena", "alena", Scheme.Internal, validGuestNetworkId, validRequestedIp,
+                22, 65536, "roundrobin", validGuestNetworkId, validAccountId);
+        
+    }
+    
+    
+    @Test(expected = InvalidParameterValueException.class)
+    //Negative test - invalid algorithm
+    public void createWithInvalidAlgorithm() throws InsufficientAddressCapacityException, InsufficientVirtualNetworkCapcityException, NetworkRuleConflictException {
+        String expectedExcText = null;
+        _appLbSvc.createApplicationLoadBalancer("alena", "alena", Scheme.Internal, validGuestNetworkId, validRequestedIp,
+                22, 22, "invalidalgorithm", validGuestNetworkId, validAccountId);
+        
+    }
+    
+    @Test(expected = InvalidParameterValueException.class)
+    //Negative test - invalid sourceNetworkId (of Public type, which is not supported)
+    public void createWithInvalidSourceIpNtwk() throws InsufficientAddressCapacityException,
+        InsufficientVirtualNetworkCapcityException, NetworkRuleConflictException {
+        _appLbSvc.createApplicationLoadBalancer("alena", "alena", Scheme.Internal, validPublicNetworkId, validRequestedIp,
+                22, 22, "roundrobin", validGuestNetworkId, validAccountId);
+        
+    }
+    
+    
+    @Test(expected = InvalidParameterValueException.class)
+    //Negative test - invalid requested IP (outside of guest network cidr range)
+    public void createWithInvalidRequestedIp() throws InsufficientAddressCapacityException,
+        InsufficientVirtualNetworkCapcityException, NetworkRuleConflictException {
+       
+        _appLbSvc.createApplicationLoadBalancer("alena", "alena", Scheme.Internal, validGuestNetworkId, "10.2.1.1",
+                    22, 22, "roundrobin", validGuestNetworkId, validAccountId);
+    }
+    
+    
+    private static NetworkVO setId(NetworkVO vo, long id) {
+        NetworkVO voToReturn = vo;
+        Class<?> c = voToReturn.getClass();
+        try {
+            Field f = c.getDeclaredField("id");
+            f.setAccessible(true);
+            f.setLong(voToReturn, id);
+        } catch (NoSuchFieldException ex) {
+           return null;
+        } catch (IllegalAccessException ex) {
+            return null;
+        }
+        
+        return voToReturn;
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/2660a6b7/server/test/org/apache/cloudstack/lb/ChildTestConfiguration.java
----------------------------------------------------------------------
diff --git a/server/test/org/apache/cloudstack/lb/ChildTestConfiguration.java b/server/test/org/apache/cloudstack/lb/ChildTestConfiguration.java
new file mode 100644
index 0000000..918de81
--- /dev/null
+++ b/server/test/org/apache/cloudstack/lb/ChildTestConfiguration.java
@@ -0,0 +1,103 @@
+// 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 org.apache.cloudstack.lb;
+
+import java.io.IOException;
+
+import org.apache.cloudstack.lb.dao.ApplicationLoadBalancerRuleDao;
+import org.apache.cloudstack.test.utils.SpringUtils;
+import org.mockito.Mockito;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.context.annotation.ComponentScan.Filter;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.FilterType;
+import org.springframework.core.type.classreading.MetadataReader;
+import org.springframework.core.type.classreading.MetadataReaderFactory;
+import org.springframework.core.type.filter.TypeFilter;
+
+import com.cloud.dc.dao.AccountVlanMapDaoImpl;
+import com.cloud.event.dao.UsageEventDao;
+import com.cloud.network.NetworkManager;
+import com.cloud.network.NetworkModel;
+import com.cloud.network.dao.FirewallRulesDao;
+import com.cloud.network.lb.LoadBalancingRulesManager;
+import com.cloud.tags.dao.ResourceTagDao;
+import com.cloud.user.AccountManager;
+
+@Configuration
+@ComponentScan(
+    basePackageClasses={
+        AccountVlanMapDaoImpl.class
+    },
+    includeFilters={@Filter(value=ChildTestConfiguration.Library.class, type=FilterType.CUSTOM)},
+    useDefaultFilters=false
+    )
+
+    public class ChildTestConfiguration {
+        
+        public static class Library implements TypeFilter {
+            
+            @Bean
+            public ApplicationLoadBalancerRuleDao applicationLoadBalancerDao() {
+                return Mockito.mock(ApplicationLoadBalancerRuleDao.class);
+            }
+            
+            @Bean
+            public NetworkModel networkModel() {
+                return Mockito.mock(NetworkModel.class);
+            }
+            
+            @Bean
+            public AccountManager accountManager() {
+                return Mockito.mock(AccountManager.class);
+            }
+            
+            @Bean
+            public LoadBalancingRulesManager loadBalancingRulesManager() {
+                return Mockito.mock(LoadBalancingRulesManager.class);
+            }
+            
+            @Bean
+            public FirewallRulesDao firewallRulesDao() {
+                return Mockito.mock(FirewallRulesDao.class);
+            }
+            
+            @Bean
+            public ResourceTagDao resourceTagDao() {
+                return Mockito.mock(ResourceTagDao.class);
+            }
+            
+            @Bean
+            public NetworkManager networkManager() {
+                return Mockito.mock(NetworkManager.class);
+            }
+            
+            @Bean
+            public UsageEventDao UsageEventDao() {
+                return Mockito.mock(UsageEventDao.class);
+            }
+            
+            @Override
+            public boolean match(MetadataReader mdr, MetadataReaderFactory arg1) throws IOException {
+                mdr.getClassMetadata().getClassName();
+                ComponentScan cs = ChildTestConfiguration.class.getAnnotation(ComponentScan.class);
+                return SpringUtils.includedInBasePackageClasses(mdr.getClassMetadata().getClassName(), cs);
+            }
+    
+        }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/2660a6b7/server/test/org/apache/cloudstack/networkoffering/CreateNetworkOfferingTest.java
----------------------------------------------------------------------
diff --git a/server/test/org/apache/cloudstack/networkoffering/CreateNetworkOfferingTest.java b/server/test/org/apache/cloudstack/networkoffering/CreateNetworkOfferingTest.java
index 7946c1a..92aa2a2 100644
--- a/server/test/org/apache/cloudstack/networkoffering/CreateNetworkOfferingTest.java
+++ b/server/test/org/apache/cloudstack/networkoffering/CreateNetworkOfferingTest.java
@@ -84,6 +84,7 @@ public class CreateNetworkOfferingTest extends TestCase{
         Mockito.when(configDao.findByName(Mockito.anyString())).thenReturn(configVO);
         
         Mockito.when(offDao.persist(Mockito.any(NetworkOfferingVO.class))).thenReturn(new NetworkOfferingVO());
+        Mockito.when(offDao.persist(Mockito.any(NetworkOfferingVO.class), Mockito.anyMap())).thenReturn(new NetworkOfferingVO());
         Mockito.when(mapDao.persist(Mockito.any(NetworkOfferingServiceMapVO.class))).thenReturn(new NetworkOfferingServiceMapVO());
         Mockito.when(accountMgr.getSystemUser()).thenReturn(new UserVO(1));
         Mockito.when(accountMgr.getSystemAccount()).thenReturn(new AccountVO(2));
@@ -96,7 +97,7 @@ public class CreateNetworkOfferingTest extends TestCase{
     public void createSharedNtwkOffWithVlan() {
         NetworkOfferingVO off = configMgr.createNetworkOffering("shared", "shared", TrafficType.Guest, null, true,
                 Availability.Optional, 200, null, false, Network.GuestType.Shared, false,
-                null, false, null, true, false);
+                null, false, null, true, false, null);
         assertNotNull("Shared network offering with specifyVlan=true failed to create ", off);
     }
     
@@ -105,7 +106,7 @@ public class CreateNetworkOfferingTest extends TestCase{
         try {
             NetworkOfferingVO off = configMgr.createNetworkOffering("shared", "shared", TrafficType.Guest, null, false,
                     Availability.Optional, 200, null, false, Network.GuestType.Shared, false,
-                    null, false, null, true, false);
+                    null, false, null, true, false, null);
             assertNull("Shared network offering with specifyVlan=false was created", off);
         } catch (InvalidParameterValueException ex) {
         }
@@ -115,7 +116,7 @@ public class CreateNetworkOfferingTest extends TestCase{
     public void createSharedNtwkOffWithSpecifyIpRanges() {
         NetworkOfferingVO off = configMgr.createNetworkOffering("shared", "shared", TrafficType.Guest, null, true,
                 Availability.Optional, 200, null, false, Network.GuestType.Shared, false,
-                null, false, null, true, false);
+                null, false, null, true, false, null);
         
         assertNotNull("Shared network offering with specifyIpRanges=true failed to create ", off);
     }
@@ -125,7 +126,7 @@ public class CreateNetworkOfferingTest extends TestCase{
         try {
             NetworkOfferingVO off = configMgr.createNetworkOffering("shared", "shared", TrafficType.Guest, null, true,
                     Availability.Optional, 200, null, false, Network.GuestType.Shared, false,
-                    null, false, null, false, false);
+                    null, false, null, false, false, null);
             assertNull("Shared network offering with specifyIpRanges=false was created", off);
         } catch (InvalidParameterValueException ex) {
         }
@@ -140,7 +141,7 @@ public class CreateNetworkOfferingTest extends TestCase{
         serviceProviderMap.put(Network.Service.SourceNat, vrProvider);
         NetworkOfferingVO off = configMgr.createNetworkOffering("isolated", "isolated", TrafficType.Guest, null, false,
                 Availability.Optional, 200, serviceProviderMap, false, Network.GuestType.Isolated, false,
-                null, false, null, false, false);
+                null, false, null, false, false, null);
         
         assertNotNull("Isolated network offering with specifyIpRanges=false failed to create ", off);
     }
@@ -153,7 +154,7 @@ public class CreateNetworkOfferingTest extends TestCase{
         serviceProviderMap.put(Network.Service.SourceNat, vrProvider);
         NetworkOfferingVO off = configMgr.createNetworkOffering("isolated", "isolated", TrafficType.Guest, null, true,
                 Availability.Optional, 200, serviceProviderMap, false, Network.GuestType.Isolated, false,
-                null, false, null, false, false);
+                null, false, null, false, false, null);
         assertNotNull("Isolated network offering with specifyVlan=true wasn't created", off);
        
     }
@@ -167,7 +168,7 @@ public class CreateNetworkOfferingTest extends TestCase{
             serviceProviderMap.put(Network.Service.SourceNat, vrProvider);
             NetworkOfferingVO off = configMgr.createNetworkOffering("isolated", "isolated", TrafficType.Guest, null, false,
                     Availability.Optional, 200, serviceProviderMap, false, Network.GuestType.Isolated, false,
-                    null, false, null, true, false);
+                    null, false, null, true, false, null);
             assertNull("Isolated network offering with specifyIpRanges=true and source nat service enabled, was created", off);
         } catch (InvalidParameterValueException ex) {
         }
@@ -180,7 +181,7 @@ public class CreateNetworkOfferingTest extends TestCase{
         Set<Network.Provider> vrProvider = new HashSet<Network.Provider>();
         NetworkOfferingVO off = configMgr.createNetworkOffering("isolated", "isolated", TrafficType.Guest, null, false,
                 Availability.Optional, 200, serviceProviderMap, false, Network.GuestType.Isolated, false,
-                null, false, null, true, false);
+                null, false, null, true, false, null);
         assertNotNull("Isolated network offering with specifyIpRanges=true and with no sourceNatService, failed to create", off);
         
     }
@@ -198,7 +199,7 @@ public class CreateNetworkOfferingTest extends TestCase{
         serviceProviderMap.put(Network.Service.Lb , vrProvider);
         NetworkOfferingVO off = configMgr.createNetworkOffering("isolated", "isolated", TrafficType.Guest, null, true,
                 Availability.Optional, 200, serviceProviderMap, false, Network.GuestType.Isolated, false,
-                null, false, null, false, false);
+                null, false, null, false, false, null);
         // System.out.println("Creating Vpc Network Offering");
         assertNotNull("Vpc Isolated network offering with Vpc provider ", off);
     }
@@ -218,7 +219,7 @@ public class CreateNetworkOfferingTest extends TestCase{
         serviceProviderMap.put(Network.Service.Lb, lbProvider);
         NetworkOfferingVO off = configMgr.createNetworkOffering("isolated", "isolated", TrafficType.Guest, null, true,
                 Availability.Optional, 200, serviceProviderMap, false, Network.GuestType.Isolated, false, null, false,
-                null, false, false);
+                null, false, false, null);
         // System.out.println("Creating Vpc Network Offering");
         assertNotNull("Vpc Isolated network offering with Vpc and Netscaler provider ", off);
     }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/2660a6b7/server/test/resources/appLoadBalancer.xml
----------------------------------------------------------------------
diff --git a/server/test/resources/appLoadBalancer.xml b/server/test/resources/appLoadBalancer.xml
new file mode 100644
index 0000000..d7c1502
--- /dev/null
+++ b/server/test/resources/appLoadBalancer.xml
@@ -0,0 +1,43 @@
+<!-- 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. -->
+<beans xmlns="http://www.springframework.org/schema/beans"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
+  xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop"
+  xsi:schemaLocation="http://www.springframework.org/schema/beans
+                      http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
+                      http://www.springframework.org/schema/tx 
+                      http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
+                      http://www.springframework.org/schema/aop
+                      http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
+                      http://www.springframework.org/schema/context
+                      http://www.springframework.org/schema/context/spring-context-3.0.xsd">
+
+     <context:annotation-config />
+
+    <!-- @DB support -->
+      
+  <bean id="componentContext" class="com.cloud.utils.component.ComponentContext" />
+
+  <bean id="transactionContextBuilder" class="com.cloud.utils.db.TransactionContextBuilder" />
+  <bean id="actionEventInterceptor" class="com.cloud.event.ActionEventInterceptor" />
+  <bean id="instantiatePostProcessor" class="com.cloud.utils.component.ComponentInstantiationPostProcessor">
+    <property name="Interceptors">
+        <list>
+            <ref bean="transactionContextBuilder" />
+        </list>
+    </property> </bean> 
+    <bean id="ApplicationLoadBalancerManager" class="org.apache.cloudstack.network.lb.ApplicationLoadBalancerManagerImpl">
+        <property name="name" value="ApplicationLoadBalancerManager"/>
+    </bean>
+  
+    <bean class="org.apache.cloudstack.lb.ChildTestConfiguration" />
+    
+</beans>

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/2660a6b7/setup/db/db/schema-40to410.sql
----------------------------------------------------------------------
diff --git a/setup/db/db/schema-40to410.sql b/setup/db/db/schema-40to410.sql
index a3426e2..b7b1c7a 100644
--- a/setup/db/db/schema-40to410.sql
+++ b/setup/db/db/schema-40to410.sql
@@ -644,6 +644,7 @@ CREATE VIEW `cloud`.`domain_router_view` AS
         data_center.id data_center_id,
         data_center.uuid data_center_uuid,
         data_center.name data_center_name,
+        data_center.networktype data_center_type,
         data_center.dns1 dns1,
         data_center.dns2 dns2,
         data_center.ip6_dns1 ip6_dns1,
@@ -684,7 +685,8 @@ CREATE VIEW `cloud`.`domain_router_view` AS
         domain_router.scripts_version scripts_version,
         domain_router.is_redundant_router is_redundant_router,
         domain_router.redundant_state redundant_state,
-        domain_router.stop_pending stop_pending
+        domain_router.stop_pending stop_pending,
+        domain_router.role role
     from
         `cloud`.`domain_router`
             inner join

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/2660a6b7/setup/db/db/schema-410to420.sql
----------------------------------------------------------------------
diff --git a/setup/db/db/schema-410to420.sql b/setup/db/db/schema-410to420.sql
index c8ac1ec..065b35c 100644
--- a/setup/db/db/schema-410to420.sql
+++ b/setup/db/db/schema-410to420.sql
@@ -339,7 +339,7 @@ CREATE TABLE `cloud`.`vm_snapshots` (
 ALTER TABLE `cloud`.`hypervisor_capabilities` ADD COLUMN `vm_snapshot_enabled` tinyint(1) DEFAULT 0 NOT NULL COMMENT 'Whether VM snapshot is supported by hypervisor';
 UPDATE `cloud`.`hypervisor_capabilities` SET `vm_snapshot_enabled`=1 WHERE `hypervisor_type` in ('VMware', 'XenServer');
 
-			
+      
 DROP VIEW IF EXISTS `cloud`.`user_vm_view`;
 CREATE VIEW `cloud`.`user_vm_view` AS
     select 
@@ -450,7 +450,7 @@ CREATE VIEW `cloud`.`user_vm_view` AS
         async_job.uuid job_uuid,
         async_job.job_status job_status,
         async_job.account_id job_account_id,
-		affinity_group.id affinity_group_id,
+    affinity_group.id affinity_group_id,
         affinity_group.uuid affinity_group_uuid,
         affinity_group.name affinity_group_name,
         affinity_group.description affinity_group_description
@@ -515,7 +515,7 @@ CREATE VIEW `cloud`.`user_vm_view` AS
             and async_job.job_status = 0
             left join
         `cloud`.`affinity_group_vm_map` ON vm_instance.id = affinity_group_vm_map.instance_id
-			left join
+      left join
         `cloud`.`affinity_group` ON affinity_group_vm_map.affinity_group_id = affinity_group.id;
 
 DROP VIEW IF EXISTS `cloud`.`affinity_group_view`;
@@ -844,7 +844,8 @@ CREATE VIEW `cloud`.`domain_router_view` AS
         domain_router.scripts_version scripts_version,
         domain_router.is_redundant_router is_redundant_router,
         domain_router.redundant_state redundant_state,
-        domain_router.stop_pending stop_pending
+        domain_router.stop_pending stop_pending,
+        domain_router.role role
     from
         `cloud`.`domain_router`
             inner join
@@ -919,7 +920,7 @@ CREATE TABLE `cloud`.`network_asa1000v_map` (
 ALTER TABLE `cloud`.`network_offerings` ADD COLUMN `eip_associate_public_ip` int(1) unsigned NOT NULL DEFAULT 0 COMMENT 'true if public IP is associated with user VM creation by default when EIP service is enabled.' AFTER `elastic_ip_service`;
 
 -- Re-enable foreign key checking, at the end of the upgrade path
-SET foreign_key_checks = 1;			
+SET foreign_key_checks = 1;     
 
 
 -- Add "default" field to account/user tables
@@ -1116,6 +1117,40 @@ CREATE VIEW `cloud`.`account_view` AS
             and async_job.job_status = 0;
 
 
+
+ALTER TABLE `cloud`.`load_balancing_rules` ADD COLUMN `source_ip_address` varchar(40) COMMENT 'source ip address for the load balancer rule';
+ALTER TABLE `cloud`.`load_balancing_rules` ADD COLUMN `source_ip_address_network_id` bigint unsigned COMMENT 'the id of the network where source ip belongs to';
+ALTER TABLE `cloud`.`load_balancing_rules` ADD COLUMN `scheme` varchar(40) NOT NULL COMMENT 'load balancer scheme; can be Internal or Public';
+UPDATE `cloud`.`load_balancing_rules` SET `scheme`='Public';
+
+
+
+-- Add details talbe for the network offering
+CREATE TABLE `cloud`.`network_offering_details` (
+  `id` bigint unsigned NOT NULL auto_increment,
+  `network_offering_id` bigint unsigned NOT NULL COMMENT 'network offering id',
+  `name` varchar(255) NOT NULL,
+  `value` varchar(1024) NOT NULL,
+  PRIMARY KEY (`id`),
+  CONSTRAINT `fk_network_offering_details__network_offering_id` FOREIGN KEY `fk_network_offering_details__network_offering_id`(`network_offering_id`) REFERENCES `network_offerings`(`id`) ON DELETE CASCADE
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+
+-- Change the constraint for the network service map table. Now we support multiple provider for the same service
+ALTER TABLE `cloud`.`ntwk_service_map` DROP FOREIGN KEY `fk_ntwk_service_map__network_id`;
+ALTER TABLE `cloud`.`ntwk_service_map` DROP INDEX `network_id`;
+
+ALTER TABLE `cloud`.`ntwk_service_map` ADD UNIQUE `network_id` (`network_id`,`service`,`provider`);
+ALTER TABLE `cloud`.`ntwk_service_map` ADD  CONSTRAINT `fk_ntwk_service_map__network_id` FOREIGN KEY (`network_id`) REFERENCES `networks` (`id`) ON DELETE CASCADE;
+
+
+ALTER TABLE `cloud`.`network_offerings` ADD COLUMN `internal_lb` int(1) unsigned NOT NULL DEFAULT '0' COMMENT 'true if the network offering supports Internal lb service';
+ALTER TABLE `cloud`.`network_offerings` ADD COLUMN `public_lb` int(1) unsigned NOT NULL DEFAULT '0' COMMENT 'true if the network offering supports Public lb service';
+UPDATE `cloud`.`network_offerings` SET public_lb=1 where id IN (SELECT DISTINCT network_offering_id FROM `cloud`.`ntwk_offering_service_map` WHERE service='Lb');
+
+
+INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Advanced', 'DEFAULT', 'NetworkManager', 'internallbvm.service.offering', null, 'Uuid of the service offering used by internal lb vm; if NULL - default system internal lb offering will be used');
+
+
 alter table `cloud_usage`.`usage_network_offering` add column nic_id bigint(20) unsigned NOT NULL;
 ALTER TABLE `cloud`.`data_center_details` MODIFY value varchar(1024);
 ALTER TABLE `cloud`.`cluster_details` MODIFY value varchar(255);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/2660a6b7/setup/dev/advanced.cfg
----------------------------------------------------------------------
diff --git a/setup/dev/advanced.cfg b/setup/dev/advanced.cfg
index 63e435b..8335786 100644
--- a/setup/dev/advanced.cfg
+++ b/setup/dev/advanced.cfg
@@ -45,6 +45,10 @@
                         {
                             "broadcastdomainrange": "ZONE",
                             "name": "VpcVirtualRouter"
+                        },
+                        {
+                            "broadcastdomainrange": "ZONE",
+                            "name": "InternalLbVm"
                         }
                     ],
                     "isolationmethods": [

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/2660a6b7/test/integration/component/test_multiple_ip_ranges.py
----------------------------------------------------------------------
diff --git a/test/integration/component/test_multiple_ip_ranges.py b/test/integration/component/test_multiple_ip_ranges.py
index 7e9eeb1..7e9e712 100644
--- a/test/integration/component/test_multiple_ip_ranges.py
+++ b/test/integration/component/test_multiple_ip_ranges.py
@@ -369,6 +369,7 @@ class TestMultipleIpRanges(cloudstackTestCase):
         self.fail("CS should not accept overlapped ip ranges in guest traffic, but it allowed")
         return
 
+
     @attr(tags=["advanced_sg", "sg"])
     def test_06_add_ip_range_overlapped_with_two_ranges(self):
         """Test adding overlapped ip range in existing cidr

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/2660a6b7/test/integration/smoke/test_guest_vlan_range.py
----------------------------------------------------------------------
diff --git a/test/integration/smoke/test_guest_vlan_range.py b/test/integration/smoke/test_guest_vlan_range.py
index bd53343..704fe59 100644
--- a/test/integration/smoke/test_guest_vlan_range.py
+++ b/test/integration/smoke/test_guest_vlan_range.py
@@ -44,6 +44,7 @@ class Services:
                                     "password": "password",
                          },
                         "name": "testphysicalnetwork",
+
                         "vlan": "2118-2120",
                     }
 
@@ -149,6 +150,19 @@ class TestDedicateGuestVlanRange(cloudstackTestCase):
                         )
 
         self.debug("Releasing guest vlan range");
+<<<<<<< HEAD
+        dedicated_guest_vlan_response.release(self.apiclient)
+        list_dedicated_guest_vlan_range_response = PhysicalNetwork.listDedicated(
+                                                self.apiclient,
+                                                id=dedicate_guest_vlan_range_response.id
+                                        )
+        dedicated_guest_vlan_response = list_dedicated_guest_vlan_range_response[0]
+        self.assertEqual(
+                            dedicated_guest_vlan_response.account,
+                            "system",
+                            "Check account name is system account in listDedicatedGuestVlanRanges"
+                        )
+=======
         dedicate_guest_vlan_range_response.release(self.apiclient)
         list_dedicated_guest_vlan_range_response = PhysicalNetwork.listDedicated(self.apiclient)
         self.assertEqual(
@@ -157,4 +171,5 @@ class TestDedicateGuestVlanRange(cloudstackTestCase):
                         "Check vlan range is not available in listDedicatedGuestVlanRanges"
 
                         )                    
+>>>>>>> master
         

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/2660a6b7/test/integration/smoke/test_internal_lb.py
----------------------------------------------------------------------
diff --git a/test/integration/smoke/test_internal_lb.py b/test/integration/smoke/test_internal_lb.py
new file mode 100644
index 0000000..ae64297
--- /dev/null
+++ b/test/integration/smoke/test_internal_lb.py
@@ -0,0 +1,250 @@
+# 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.
+""" Tests for configuring Internal Load Balancing Rules.
+"""
+#Import Local Modules
+from marvin.cloudstackTestCase import *
+from marvin.cloudstackAPI import *
+from marvin.integration.lib.utils import *
+from marvin.integration.lib.base import *
+from marvin.integration.lib.common import *
+
+
+class TestInternalLb(cloudstackTestCase):
+    networkOfferingId = None
+    networkId = None
+    vmId = None
+    lbId = None
+
+    zoneId = 1
+    serviceOfferingId = 1 
+    templateId = 5
+
+
+    serviceProviderList = [
+        {
+            "provider": "VpcVirtualRouter",
+            "service": "Vpn"
+        },
+        {
+            "provider": "VpcVirtualRouter",
+            "service": "UserData"
+        },
+        {
+            "provider": "VpcVirtualRouter",
+            "service": "Dhcp"
+        },
+        {
+            "provider": "VpcVirtualRouter",
+            "service": "Dns"
+        },
+        {
+            "provider": "InternalLbVM",
+            "service": "Lb"
+        },
+        {
+            "provider": "VpcVirtualRouter",
+            "service": "SourceNat"
+        },
+        {
+            "provider": "VpcVirtualRouter",
+            "service": "StaticNat"
+        },
+        {
+            "provider": "VpcVirtualRouter",
+            "service": "PortForwarding"
+        },
+        {
+            "provider": "VpcVirtualRouter",
+            "service": "NetworkACL"
+        }
+    ]
+
+    serviceCapsList = [
+        {
+            "service": "SourceNat",
+            "capabilitytype": "SupportedSourceNatTypes",
+            "capabilityvalue": "peraccount"
+        },
+        {
+            "service": "Lb",
+            "capabilitytype": "SupportedLbIsolation",
+            "capabilityvalue": "dedicated"
+        },
+        {
+            "service": "Lb",
+            "capabilitytype": "lbSchemes",
+            "capabilityvalue": "internal"
+        }
+    ]
+
+    def setUp(self):
+        self.apiClient = self.testClient.getApiClient()
+
+
+    
+    def test_internallb(self):
+
+        #1) Create and enable network offering with Internal Lb vm service
+        self.createNetworkOffering()
+        
+        #2) Create VPC and network in it
+        self.createNetwork()
+      
+        #3) Deploy a vm 
+        self.deployVm()
+        
+        #4) Create an Internal Load Balancer
+        self.createInternalLoadBalancer()
+
+        #5) Assign the VM to the Internal Load Balancer
+        self.assignToLoadBalancerRule()
+
+        #6) Remove the vm from the Interanl Load Balancer
+        self.removeFromLoadBalancerRule()
+
+        #7) Delete the Load Balancer
+        self.deleteLoadBalancer()
+
+
+    def deployVm(self):
+        deployVirtualMachineCmd = deployVirtualMachine.deployVirtualMachineCmd()
+        deployVirtualMachineCmd.networkids = TestInternalLb.networkId
+        deployVirtualMachineCmd.serviceofferingid = TestInternalLb.serviceOfferingId
+        deployVirtualMachineCmd.zoneid = TestInternalLb.zoneId
+        deployVirtualMachineCmd.templateid = TestInternalLb.templateId
+        deployVirtualMachineCmd.hypervisor = "XenServer"
+        deployVMResponse = self.apiClient.deployVirtualMachine(deployVirtualMachineCmd)
+        TestInternalLb.vmId = deployVMResponse.id
+
+
+    def createInternalLoadBalancer(self):
+        createLoadBalancerCmd = createLoadBalancer.createLoadBalancerCmd()
+        createLoadBalancerCmd.name = "lb rule"
+        createLoadBalancerCmd.sourceport = 22
+        createLoadBalancerCmd.instanceport = 22
+        createLoadBalancerCmd.algorithm = "roundrobin"
+        createLoadBalancerCmd.scheme = "internal"
+        createLoadBalancerCmd.sourceipaddressnetworkid = TestInternalLb.networkId
+        createLoadBalancerCmd.networkid = TestInternalLb.networkId
+        createLoadBalancerResponse = self.apiClient.createLoadBalancer(createLoadBalancerCmd)
+        TestInternalLb.lbId = createLoadBalancerResponse.id
+        self.assertIsNotNone(createLoadBalancerResponse.id, "Failed to create a load balancer")
+
+
+    def assignToLoadBalancerRule(self):
+        assignToLoadBalancerRuleCmd = assignToLoadBalancerRule.assignToLoadBalancerRuleCmd()
+        assignToLoadBalancerRuleCmd.id = TestInternalLb.lbId
+        assignToLoadBalancerRuleCmd.virtualMachineIds = TestInternalLb.vmId
+        assignToLoadBalancerRuleResponse = self.apiClient.assignToLoadBalancerRule(assignToLoadBalancerRuleCmd)
+        self.assertTrue(assignToLoadBalancerRuleResponse.success, "Failed to assign the vm to the load balancer")
+
+
+
+    def removeFromLoadBalancerRule(self):
+        removeFromLoadBalancerRuleCmd = removeFromLoadBalancerRule.removeFromLoadBalancerRuleCmd()
+        removeFromLoadBalancerRuleCmd.id = TestInternalLb.lbId
+        removeFromLoadBalancerRuleCmd.virtualMachineIds = TestInternalLb.vmId
+        removeFromLoadBalancerRuleResponse = self.apiClient.removeFromLoadBalancerRule(removeFromLoadBalancerRuleCmd)
+        self.assertTrue(removeFromLoadBalancerRuleResponse.success, "Failed to remove the vm from the load balancer")
+
+
+
+    #def removeInternalLoadBalancer(self):
+    def deleteLoadBalancer(self):
+        deleteLoadBalancerCmd = deleteLoadBalancer.deleteLoadBalancerCmd()
+        deleteLoadBalancerCmd.id = TestInternalLb.lbId
+        deleteLoadBalancerResponse = self.apiClient.deleteLoadBalancer(deleteLoadBalancerCmd)
+        self.assertTrue(deleteLoadBalancerResponse.success, "Failed to remove the load balancer")
+
+
+
+    def createNetwork(self):
+        createVPCCmd = createVPC.createVPCCmd()
+        createVPCCmd.name = "new vpc"
+        createVPCCmd.cidr = "10.1.1.0/24"
+        createVPCCmd.displaytext = "new vpc"
+        createVPCCmd.vpcofferingid = 1
+        createVPCCmd.zoneid = self.zoneId
+        createVPCResponse = self.apiClient.createVPC(createVPCCmd)
+
+
+        createNetworkCmd = createNetwork.createNetworkCmd()
+        createNetworkCmd.name = "vpc network"
+        createNetworkCmd.displaytext = "vpc network"
+        createNetworkCmd.netmask = "255.255.255.0"
+        createNetworkCmd.gateway = "10.1.1.1"
+        createNetworkCmd.zoneid = self.zoneId
+        createNetworkCmd.vpcid = createVPCResponse.id
+        createNetworkCmd.networkofferingid = TestInternalLb.networkOfferingId
+        createNetworkResponse = self.apiClient.createNetwork(createNetworkCmd)
+        TestInternalLb.networkId = createNetworkResponse.id
+
+        self.assertIsNotNone(createNetworkResponse.id, "Network failed to create")
+
+
+    def createNetworkOffering(self):
+            createNetworkOfferingCmd = createNetworkOffering.createNetworkOfferingCmd()
+            createNetworkOfferingCmd.name = "Network offering for internal lb service - " + str(random.randrange(1,100+1))
+            createNetworkOfferingCmd.displaytext = "Network offering for internal lb service"
+            createNetworkOfferingCmd.guestiptype = "isolated"
+            createNetworkOfferingCmd.traffictype = "Guest"
+            createNetworkOfferingCmd.conservemode = "false"
+            createNetworkOfferingCmd.supportedservices = "Vpn,Dhcp,Dns,Lb,UserData,SourceNat,StaticNat,PortForwarding,NetworkACL"
+
+
+            createNetworkOfferingCmd.serviceproviderlist = []
+            for item in self.serviceProviderList:
+                createNetworkOfferingCmd.serviceproviderlist.append({
+                                                'service': item['service'],
+                                                'provider': item['provider']
+                                               })
+                
+            createNetworkOfferingCmd.servicecapabilitylist = []
+            for item in self.serviceCapsList:
+                createNetworkOfferingCmd.servicecapabilitylist.append({
+                                                'service': item['service'],
+                                                'capabilitytype': item['capabilitytype'],
+                                                'capabilityvalue': item['capabilityvalue']
+                                               })
+
+
+            createNetworkOfferingResponse = self.apiClient.createNetworkOffering(createNetworkOfferingCmd)
+            TestInternalLb.networkOfferingId = createNetworkOfferingResponse.id
+
+            #enable network offering
+            updateNetworkOfferingCmd = updateNetworkOffering.updateNetworkOfferingCmd()
+            updateNetworkOfferingCmd.id = TestInternalLb.networkOfferingId
+            updateNetworkOfferingCmd.state = "Enabled"
+            updateNetworkOfferingResponse = self.apiClient.updateNetworkOffering(updateNetworkOfferingCmd)
+
+
+            #list network offering to see if its enabled
+            listNetworkOfferingsCmd = listNetworkOfferings.listNetworkOfferingsCmd()
+            listNetworkOfferingsCmd.id = TestInternalLb.networkOfferingId
+            listOffResponse = self.apiClient.listNetworkOfferings(listNetworkOfferingsCmd)
+
+            self.assertNotEqual(len(listOffResponse), 0, "Check if the list network offerings API \
+                                returns a non-empty response")
+
+
+    def tearDown(self):
+        #destroy the vm
+        if TestInternalLb.vmId is not None:
+            destroyVirtualMachineCmd = destroyVirtualMachine.destroyVirtualMachineCmd()
+            destroyVirtualMachineCmd.id = TestInternalLb.vmId
+            destroyVirtualMachineResponse = self.apiClient.destroyVirtualMachine(destroyVirtualMachineCmd)

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/2660a6b7/tools/apidoc/gen_toc.py
----------------------------------------------------------------------
diff --git a/tools/apidoc/gen_toc.py b/tools/apidoc/gen_toc.py
index f8bdae2..bd8c0f1 100644
--- a/tools/apidoc/gen_toc.py
+++ b/tools/apidoc/gen_toc.py
@@ -140,6 +140,7 @@ known_categories = {
     'removeIpFromNic': 'Nic',
     'listNics':'Nic',
 	'AffinityGroup': 'Affinity Group',
+    'InternalLoadBalancer': 'Internal LB',
     }
 
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/2660a6b7/tools/marvin/marvin/deployDataCenter.py
----------------------------------------------------------------------
diff --git a/tools/marvin/marvin/deployDataCenter.py b/tools/marvin/marvin/deployDataCenter.py
index 2168592..7059059 100644
--- a/tools/marvin/marvin/deployDataCenter.py
+++ b/tools/marvin/marvin/deployDataCenter.py
@@ -216,6 +216,18 @@ class deployDataCenters():
                     vrconfig.id = vrprovid
                     self.apiClient.configureVirtualRouterElement(vrconfig)
                     self.enableProvider(pnetprovres[0].id)
+                elif provider.name == 'InternalLbVm':
+                    internallbprov = listInternalLoadBalancerElements.listInternalLoadBalancerElementsCmd() 
+                    internallbprov.nspid = pnetprovres[0].id
+                    internallbresponse = self.apiClient.listInternalLoadBalancerElements(internallbprov)
+                    internallbid = internallbresponse[0].id
+
+                    internallbconfig = \
+                            configureInternalLoadBalancerElement.configureInternalLoadBalancerElementCmd()
+                    internallbconfig.enabled = "true"
+                    internallbconfig.id = internallbid
+                    self.apiClient.configureInternalLoadBalancerElement(internallbconfig)
+                    self.enableProvider(pnetprovres[0].id)
                 elif provider.name == 'SecurityGroupProvider':
                     self.enableProvider(pnetprovres[0].id)
             elif provider.name in ['Netscaler', 'JuniperSRX', 'F5BigIp']:

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/2660a6b7/tools/marvin/marvin/sandbox/advanced/advanced_env.py
----------------------------------------------------------------------
diff --git a/tools/marvin/marvin/sandbox/advanced/advanced_env.py b/tools/marvin/marvin/sandbox/advanced/advanced_env.py
index bf880f3..6343293 100644
--- a/tools/marvin/marvin/sandbox/advanced/advanced_env.py
+++ b/tools/marvin/marvin/sandbox/advanced/advanced_env.py
@@ -50,6 +50,9 @@ def describeResources(config):
     
     vpcprovider = provider()
     vpcprovider.name = 'VpcVirtualRouter'
+
+    lbprovider = provider()
+    lbprovider.name = 'InternalLbVm'
     
     pn = physical_network()
     pn.name = "Sandbox-pnet"
@@ -60,6 +63,7 @@ def describeResources(config):
             traffictype("Public", {"simulator":"cloud-simulator-public"})]
     pn.isolationmethods = ["VLAN"]
     pn.providers.append(vpcprovider)
+    pn.providers.append(lbprovider)
 
     pn2 = physical_network()
     pn2.name = "Sandbox-pnet2"
@@ -68,6 +72,7 @@ def describeResources(config):
     pn2.traffictypes = [traffictype('Guest', {'simulator': 'cloud-simulator-guest'})]
     pn2.isolationmethods = ["VLAN"]
     pn2.providers.append(vpcprovider)
+    pn2.providers.append(lbprovider)
     
     z.physical_networks.append(pn)
     z.physical_networks.append(pn2)

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/2660a6b7/tools/marvin/marvin/sandbox/advanced/sandbox.cfg
----------------------------------------------------------------------
diff --git a/tools/marvin/marvin/sandbox/advanced/sandbox.cfg b/tools/marvin/marvin/sandbox/advanced/sandbox.cfg
new file mode 100644
index 0000000..01a8473
--- /dev/null
+++ b/tools/marvin/marvin/sandbox/advanced/sandbox.cfg
@@ -0,0 +1,209 @@
+{
+    "zones": [
+        {
+            "name": "Sandbox-Simulator", 
+            "guestcidraddress": "10.1.1.0/24", 
+            "dns1": "10.147.28.6", 
+            "physical_networks": [
+                {
+                    "providers": [
+                        {
+                            "broadcastdomainrange": "ZONE", 
+                            "name": "VirtualRouter"
+                        }, 
+                        {
+                            "broadcastdomainrange": "ZONE", 
+                            "name": "VpcVirtualRouter"
+                        }, 
+                        {
+                            "broadcastdomainrange": "ZONE", 
+                            "name": "InternalLb"
+                        }
+                    ], 
+                    "name": "Sandbox-pnet", 
+                    "tags": [
+                        "cloud-simulator-public"
+                    ], 
+                    "broadcastdomainrange": "Zone", 
+                    "vlan": "675-679", 
+                    "traffictypes": [
+                        {
+                            "typ": "Guest"
+                        }, 
+                        {
+                            "typ": "Management", 
+                            "simulator": "cloud-simulator-mgmt"
+                        }, 
+                        {
+                            "typ": "Public", 
+                            "simulator": "cloud-simulator-public"
+                        }
+                    ], 
+                    "isolationmethods": [
+                        "VLAN"
+                    ]
+                }, 
+                {
+                    "providers": [
+                        {
+                            "broadcastdomainrange": "ZONE", 
+                            "name": "VirtualRouter"
+                        }, 
+                        {
+                            "broadcastdomainrange": "ZONE", 
+                            "name": "VpcVirtualRouter"
+                        }, 
+                        {
+                            "broadcastdomainrange": "ZONE", 
+                            "name": "InternalLb"
+                        }
+                    ], 
+                    "name": "Sandbox-pnet2", 
+                    "tags": [
+                        "cloud-simulator-guest"
+                    ], 
+                    "broadcastdomainrange": "Zone", 
+                    "vlan": "800-1000", 
+                    "traffictypes": [
+                        {
+                            "typ": "Guest", 
+                            "simulator": "cloud-simulator-guest"
+                        }
+                    ], 
+                    "isolationmethods": [
+                        "VLAN"
+                    ]
+                }
+            ], 
+            "securitygroupenabled": "false", 
+            "ipranges": [
+                {
+                    "startip": "10.147.31.150", 
+                    "endip": "10.147.31.159", 
+                    "netmask": "255.255.255.0", 
+                    "vlan": "31", 
+                    "gateway": "10.147.31.1"
+                }
+            ], 
+            "networktype": "Advanced", 
+            "pods": [
+                {
+                    "endip": "10.147.29.159", 
+                    "name": "POD0", 
+                    "startip": "10.147.29.150", 
+                    "netmask": "255.255.255.0", 
+                    "clusters": [
+                        {
+                            "clustername": "C0", 
+                            "hypervisor": "Simulator", 
+                            "hosts": [
+                                {
+                                    "username": "root", 
+                                    "url": "http://simulator0", 
+                                    "password": "password"
+                                }
+                            ], 
+                            "clustertype": "CloudManaged", 
+                            "primaryStorages": [
+                                {
+                                    "url": "nfs://10.147.28.6:/export/home/sandbox/primary", 
+                                    "name": "PS0"
+                                }
+                            ]
+                        }
+                    ], 
+                    "gateway": "10.147.29.1"
+                }
+            ], 
+            "internaldns1": "10.147.28.6", 
+            "secondaryStorages": [
+                {
+                    "url": "nfs://10.147.28.6:/export/home/sandbox/sstor"
+                }
+            ]
+        }
+    ], 
+    "dbSvr": {
+        "dbSvr": "localhost", 
+        "passwd": "cloud", 
+        "db": "cloud", 
+        "port": 3306, 
+        "user": "cloud"
+    }, 
+    "logger": [
+        {
+            "name": "TestClient", 
+            "file": "testclient.log"
+        }, 
+        {
+            "name": "TestCase", 
+            "file": "testcase.log"
+        }
+    ], 
+    "globalConfig": [
+        {
+            "name": "storage.cleanup.interval", 
+            "value": "300"
+        }, 
+        {
+            "name": "direct.agent.load.size", 
+            "value": "1000"
+        }, 
+        {
+            "name": "default.page.size", 
+            "value": "10000"
+        }, 
+        {
+            "name": "instance.name", 
+            "value": "QA"
+        }, 
+        {
+            "name": "workers", 
+            "value": "10"
+        }, 
+        {
+            "name": "vm.op.wait.interval", 
+            "value": "5"
+        }, 
+        {
+            "name": "account.cleanup.interval", 
+            "value": "600"
+        }, 
+        {
+            "name": "guest.domain.suffix", 
+            "value": "sandbox.simulator"
+        }, 
+        {
+            "name": "expunge.delay", 
+            "value": "60"
+        }, 
+        {
+            "name": "vm.allocation.algorithm", 
+            "value": "random"
+        }, 
+        {
+            "name": "expunge.interval", 
+            "value": "60"
+        }, 
+        {
+            "name": "expunge.workers", 
+            "value": "3"
+        }, 
+        {
+            "name": "secstorage.allowed.internal.sites", 
+            "value": "10.147.28.0/24"
+        }, 
+        {
+            "name": "check.pod.cidrs", 
+            "value": "true"
+        }
+    ], 
+    "mgtSvr": [
+        {
+            "mgtSvrIp": "localhost", 
+            "passwd": "password", 
+            "user": "root", 
+            "port": 8096
+        }
+    ]
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/2660a6b7/ui/scripts/zoneWizard.js
----------------------------------------------------------------------
diff --git a/ui/scripts/zoneWizard.js b/ui/scripts/zoneWizard.js
index b282585..9b28c32 100755
--- a/ui/scripts/zoneWizard.js
+++ b/ui/scripts/zoneWizard.js
@@ -2376,6 +2376,110 @@
                             });
 														// ***** Virtual Router ***** (end) *****
 														
+							// ***** Internal LB ***** (begin) *****
+							var internalLbProviderId;
+							$.ajax({
+								url: createURL("listNetworkServiceProviders&name=Internallbvm&physicalNetworkId=" + thisPhysicalNetwork.id),
+								dataType: "json",
+								async: false,
+								success: function(json) {
+									var items = json.listnetworkserviceprovidersresponse.networkserviceprovider;
+									if(items != null && items.length > 0) {
+										internalLbProviderId = items[0].id;
+									}
+								}
+							});
+							if(internalLbProviderId == null) {
+								alert("error: listNetworkServiceProviders API doesn't return internalLb provider ID");
+								return;
+							}
+
+							var internalLbElementId;
+							$.ajax({
+								url: createURL("listInternalLoadBalancerElements&nspid=" + internalLbProviderId),
+								dataType: "json",
+								async: false,
+								success: function(json) {
+									var items = json.listinternalloadbalancerelementsresponse.internalloadbalancerelement;
+									if(items != null && items.length > 0) {
+										internalLbElementId = items[0].id;
+									}
+								}
+							});
+							if(internalLbElementId == null) {
+								alert("error: listInternalLoadBalancerElements API doesn't return Internal LB Element Id");
+								return;
+							}
+
+							$.ajax({
+								url: createURL("configureInternalLoadBalancerElement&enabled=true&id=" + internalLbElementId),
+								dataType: "json",
+								async: false,
+								success: function(json) {
+									var jobId = json.configureinternalloadbalancerelementresponse.jobid;                                
+									var enableInternalLbElementIntervalID = setInterval(function() { 	
+										$.ajax({
+											url: createURL("queryAsyncJobResult&jobId="+jobId),
+											dataType: "json",
+											success: function(json) {
+												var result = json.queryasyncjobresultresponse;
+												if (result.jobstatus == 0) {
+													return; //Job has not completed
+												}
+												else {                                        
+													clearInterval(enableInternalLbElementIntervalID); 
+													
+													if (result.jobstatus == 1) { //configureVirtualRouterElement succeeded
+														$.ajax({
+															url: createURL("updateNetworkServiceProvider&state=Enabled&id=" + internalLbProviderId),
+															dataType: "json",
+															async: false,
+															success: function(json) {
+																var jobId = json.updatenetworkserviceproviderresponse.jobid;                                             
+																var enableInternalLbProviderIntervalID = setInterval(function() { 	
+																	$.ajax({
+																		url: createURL("queryAsyncJobResult&jobId="+jobId),
+																		dataType: "json",
+																		success: function(json) {
+																			var result = json.queryasyncjobresultresponse;
+																			if (result.jobstatus == 0) {
+																				return; //Job has not completed
+																			}
+																			else {                                                      
+																				clearInterval(enableInternalLbProviderIntervalID); 
+																				
+																				if (result.jobstatus == 1) { //Internal LB has been enabled successfully
+																					//don't need to do anything here
+																				}
+																				else if (result.jobstatus == 2) {
+																					alert("failed to enable Internal LB Provider. Error: " + _s(result.jobresult.errortext));
+																				}
+																			}
+																		},
+																		error: function(XMLHttpResponse) {
+																			var errorMsg = parseXMLHttpResponse(XMLHttpResponse);
+																			alert("failed to enable Internal LB Provider. Error: " + errorMsg);
+																		}
+																	});                                              
+																}, g_queryAsyncJobResultInterval); 	
+															}
+														});
+													}
+													else if (result.jobstatus == 2) {
+														alert("configureVirtualRouterElement failed. Error: " + _s(result.jobresult.errortext));
+													}
+												}
+											},
+											error: function(XMLHttpResponse) {
+												var errorMsg = parseXMLHttpResponse(XMLHttpResponse);
+												alert("configureVirtualRouterElement failed. Error: " + errorMsg);
+											}
+										});                                
+									}, g_queryAsyncJobResultInterval); 	
+								}
+							});
+							// ***** Internal LB ***** (end) *****
+                            
 														if(args.data.zone.sgEnabled != true) { //Advanced SG-disabled zone
 															// ***** VPC Virtual Router ***** (begin) *****
 															var vpcVirtualRouterProviderId;


Mime
View raw message