Skip to content

Commit b072d5d

Browse files
Finding pool by port and name instead of just name.
Fixing case when there is more than on pool for each port. (reverted from commit 7062960)
1 parent 7062960 commit b072d5d

2 files changed

Lines changed: 8 additions & 13 deletions

File tree

plugins/network-elements/globonetwork/src/com/globo/globonetwork/cloudstack/resource/GloboNetworkResource.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -895,10 +895,10 @@ protected LbAlgorithm getBalancingAlgorithm(String methodBal) {
895895
return lbAlgorithm;
896896
}
897897

898-
protected PoolV3 findPoolByPortAndName(Integer port, List<PoolV3> pools, String poolName) {
898+
protected PoolV3 findPoolByPort(Integer port, List<PoolV3> pools) {
899899
if(pools != null) {
900900
for (PoolV3 pool : pools) {
901-
if (port.equals(pool.getDefaultPort()) && pool.getIdentifier().equals(poolName)) {
901+
if (port.equals(pool.getDefaultPort())) {
902902
return pool;
903903
}
904904
}
@@ -1070,9 +1070,7 @@ protected List<VipPoolMap> savePools(List<Long> poolIds, VipInfoHelper vipInfos,
10701070
if(poolIds != null && !poolIds.isEmpty()){
10711071
pools = poolAPI.getByIdsV3(poolIds);
10721072
}
1073-
1074-
String poolName = buildPoolName(cmd.getRegion(), cmd.getHost(), vipPort, realPort);
1075-
PoolV3 poolV3 = findPoolByPortAndName(realPort, pools, poolName);
1073+
PoolV3 poolV3 = findPoolByPort(realPort, pools);
10761074

10771075
//case when user add or remove real, does not need to update pool settings, only reals
10781076
if (poolV3 != null) {

plugins/network-elements/globonetwork/test/com/globo/globonetwork/cloudstack/resource/GloboNetworkResourceTest.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -196,17 +196,16 @@ public void testGetBalancingAlgorithmGivenInvalid(){
196196
public void testFindPoolByPort(){
197197
List<PoolV3> pools = new ArrayList<>();
198198
PoolV3 pool = new PoolV3();
199-
pool.setIdentifier("pool_teste");
200199
pool.setDefaultPort(80);
201200
pools.add(pool);
202201

203-
assertNotNull(_resource.findPoolByPortAndName(80, pools, "pool_teste"));
204-
assertNull(_resource.findPoolByPortAndName(81, pools, "pool_teste_2"));
202+
assertNotNull(_resource.findPoolByPort(80, pools));
203+
assertNull(_resource.findPoolByPort(81, pools));
205204
}
206205

207206
@Test
208207
public void testFindPoolByPorGivenNullVip(){
209-
assertNull(_resource.findPoolByPortAndName(80, null, "pool_teste"));
208+
assertNull(_resource.findPoolByPort(80, null));
210209
}
211210

212211
private PoolV3 mockPoolSave(Long poolId, Long idReturned, Boolean hasPoolMember, Integer vipPort, Integer port, String ip, String healthCheckType, String healthCheck, String expectedHealthCheck, int maxConn, String serviceDAction) throws GloboNetworkException {
@@ -798,7 +797,6 @@ public void testSavePoolAddRealToExistingPool() throws GloboNetworkException {
798797
pool.setDefaultPort(8080);
799798
pool.setId(12L);
800799
pool.setMaxconn(0);
801-
pool.setIdentifier("ACS_POOL_region_vip.domain.com_80_8080");
802800

803801
List<Long> poolIds = Collections.singletonList(pool.getId());
804802
Ipv4 ip = new Ipv4();
@@ -823,18 +821,17 @@ public void testSavePoolAddRealToExistingPool() throws GloboNetworkException {
823821
cmd.setHealthcheckType(build.getHealthCheckType());
824822
cmd.setExpectedHealthcheck(build.getExpectedHealthCheck());
825823
cmd.setHealthcheck(build.getHealthCheck());
826-
cmd.setRegion("region");
827824

828825
//mock 1 - Pool find by id - v3
829-
PoolV3 poolv3GetById = mockPool(12L, "ACS_POOL_region_vip.domain.com_80_8080", 8080, "round-robin", build.getHealthCheckType(), build.getHealthCheck(), build.getExpectedHealthCheck(), "*", 5);
826+
PoolV3 poolv3GetById = mockPool(12L, "ACS_POOL_", 8080, "round-robin", build.getHealthCheckType(), build.getHealthCheck(), build.getExpectedHealthCheck(), "*", 5);
830827
PoolV3.PoolMember poolM = mockPoolMember(200L, 8080, 1L, "10.0.0.1", 1L, "vm-01");
831828
poolv3GetById.getPoolMembers().add(poolM);
832829

833830
when(_resource._globoNetworkApi.getPoolAPI().getById(12L)).thenReturn(poolv3GetById);
834831
when(_resource._globoNetworkApi.getPoolAPI().getByIdsV3(Collections.singletonList(12L))).thenReturn(Collections.singletonList(poolv3GetById));
835832

836833
//mock 2 - Pool save pool
837-
PoolV3 poolToSave = mockPool(12L, "ACS_POOL_region_vip.domain.com_80_8080", 8080, "round-robin", build.getHealthCheckType(), build.getHealthCheck(), build.getExpectedHealthCheck(), "*", 5);
834+
PoolV3 poolToSave = mockPool(12L, "ACS_POOL_", 8080, "round-robin", build.getHealthCheckType(), build.getHealthCheck(), build.getExpectedHealthCheck(), "*", 5);
838835
PoolV3.PoolMember poolMSaved = mockPoolMember(200L, 8080, 1L, "10.0.0.1", 1L, "vm-01");
839836
poolToSave.getPoolMembers().add(poolMSaved);
840837
PoolV3.PoolMember poolM2Saved = mockPoolMember(null, 8080, 2L, "10.0.0.2", 2L, "vm-02");

0 commit comments

Comments
 (0)