Skip to content

Commit 7c6c9e6

Browse files
Pearl1594nvazquez
authored andcommitted
NSX: Improve NSX resource cleanup process (#3)
1 parent 9313d39 commit 7c6c9e6

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/service/NsxApiClient.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
import static org.apache.cloudstack.utils.NsxControllerUtils.getLoadBalancerName;
101101
import static org.apache.cloudstack.utils.NsxControllerUtils.getLoadBalancerAlgorithm;
102102
import static org.apache.cloudstack.utils.NsxControllerUtils.getActiveMonitorProfileName;
103+
import static org.apache.cloudstack.utils.NsxControllerUtils.getTier1GatewayName;
103104

104105
public class NsxApiClient {
105106

@@ -429,6 +430,10 @@ public void createSegment(String segmentName, String tier1GatewayName, String ga
429430
public void deleteSegment(long zoneId, long domainId, long accountId, Long vpcId, long networkId, String segmentName) {
430431
try {
431432
removeSegmentDistributedFirewallRules(segmentName);
433+
if (Objects.isNull(vpcId)) {
434+
String t1GatewayName = getTier1GatewayName(domainId, accountId, zoneId, networkId, false);
435+
deleteLoadBalancer(getLoadBalancerName(t1GatewayName));
436+
}
432437
removeSegment(segmentName);
433438
DhcpRelayConfigs dhcpRelayConfig = (DhcpRelayConfigs) nsxService.apply(DhcpRelayConfigs.class);
434439
String dhcpRelayConfigId = NsxControllerUtils.getNsxDhcpRelayConfigId(zoneId, domainId, accountId, vpcId, networkId);
@@ -445,9 +450,15 @@ public void deleteSegment(long zoneId, long domainId, long accountId, Long vpcId
445450
protected void removeSegment(String segmentName) {
446451
LOGGER.debug(String.format("Removing the segment with ID %s", segmentName));
447452
Segments segmentService = (Segments) nsxService.apply(Segments.class);
448-
Segment segment = segmentService.get(segmentName);
449-
if (segment == null) {
450-
LOGGER.error(String.format("The segment with ID %s is not found, skipping removal", segmentName));
453+
String errMsg = String.format("The segment with ID %s is not found, skipping removal", segmentName);
454+
try {
455+
Segment segment = segmentService.get(segmentName);
456+
if (segment == null) {
457+
LOGGER.warn(errMsg);
458+
return;
459+
}
460+
} catch (Exception e) {
461+
LOGGER.warn(errMsg);
451462
return;
452463
}
453464
String siteId = getDefaultSiteId();

server/src/main/java/com/cloud/network/firewall/FirewallManagerImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,8 @@ private void validateNsxConstraints(long networkId, FirewallRuleVO rule) {
732732
return;
733733
}
734734

735-
if (NetUtils.ICMP_PROTO.equals(protocol.toLowerCase(Locale.ROOT)) && (rule.getIcmpType() == -1 || rule.getIcmpCode() == -1)) {
735+
if (NetUtils.ICMP_PROTO.equals(protocol.toLowerCase(Locale.ROOT)) && (rule.getIcmpType() == -1 || rule.getIcmpCode() == -1)
736+
&& State.Add.equals(rule.getState())) {
736737
String errorMsg = "Passing -1 for ICMP type is not supported for NSX enabled zones";
737738
s_logger.error(errorMsg);
738739
throw new InvalidParameterValueException(errorMsg);

0 commit comments

Comments
 (0)