|
127 | 127 | import java.util.Objects; |
128 | 128 | import java.util.Set; |
129 | 129 | import java.util.function.LongFunction; |
| 130 | +import java.util.stream.Collectors; |
130 | 131 |
|
131 | 132 | @Component |
132 | 133 | public class NsxElement extends AdapterBase implements DhcpServiceProvider, DnsServiceProvider, VpcProvider, |
@@ -403,10 +404,18 @@ private Pair<Boolean, Account> validateVpcConfigurationAndGetAccount(DataCenterV |
403 | 404 | Account account = null; |
404 | 405 | boolean forNsx = false; |
405 | 406 | List<PhysicalNetworkVO> physicalNetworks = physicalNetworkDao.listByZoneAndTrafficType(zone.getId(), Networks.TrafficType.Guest); |
406 | | - if (CollectionUtils.isNullOrEmpty(physicalNetworks) || physicalNetworks.size() > 1 ) { |
407 | | - throw new InvalidConfigurationException(String.format("Desired number of physical networks is not present in the zone %s for traffic type %s. ", zone.getName(), Networks.TrafficType.Guest.name())); |
408 | | - } |
409 | | - if (physicalNetworks.get(0).getIsolationMethods().contains("NSX")) { |
| 407 | + if (CollectionUtils.isNullOrEmpty(physicalNetworks)) { |
| 408 | + String err = String.format("Desired physical network is not present in the zone %s for traffic type %s. ", zone.getName(), Networks.TrafficType.Guest.name()); |
| 409 | + LOGGER.error(err); |
| 410 | + throw new InvalidConfigurationException(err); |
| 411 | + } |
| 412 | + List<PhysicalNetworkVO> filteredPhysicalNetworks = physicalNetworks.stream().filter(x -> x.getIsolationMethods().contains("NSX")).collect(Collectors.toList()); |
| 413 | + if (CollectionUtils.isNullOrEmpty(filteredPhysicalNetworks)) { |
| 414 | + String err = String.format("No physical network with NSX isolation type for traffic type %s is present in the zone %s.", Networks.TrafficType.Guest.name(), zone.getName()); |
| 415 | + LOGGER.error(err); |
| 416 | + throw new InvalidConfigurationException(err); |
| 417 | + } |
| 418 | + if (filteredPhysicalNetworks.get(0).getIsolationMethods().contains("NSX")) { |
410 | 419 | account = accountMgr.getAccount(vpc.getAccountId()); |
411 | 420 | forNsx = true; |
412 | 421 | } |
@@ -585,9 +594,9 @@ protected synchronized boolean applyPFRulesInternal(Network network, List<PortFo |
585 | 594 | result &= pfRuleResult; |
586 | 595 | } |
587 | 596 | } else if (rule.getState() == FirewallRule.State.Revoke) { |
588 | | - if (ruleDetail != null && ruleDetail.getValue().equalsIgnoreCase("true")) { |
| 597 | + if (ruleDetail == null || (ruleDetail != null && ruleDetail.getValue().equalsIgnoreCase("true"))) { |
589 | 598 | boolean pfRuleResult = nsxService.deletePortForwardRule(networkRule); |
590 | | - if (pfRuleResult) { |
| 599 | + if (pfRuleResult && ruleDetail != null) { |
591 | 600 | LOGGER.debug(String.format("Updating firewall rule detail %s for rule %s, set to false", ruleDetail.getId(), rule.getId())); |
592 | 601 | ruleDetail.setValue("false"); |
593 | 602 | firewallRuleDetailsDao.update(ruleDetail.getId(), ruleDetail); |
|
0 commit comments