From dd26e56c63c785f5fa18bb6c2539f240e218f118 Mon Sep 17 00:00:00 2001 From: Stephen Kitt Date: Fri, 13 Jan 2017 10:09:25 +0100 Subject: [PATCH] General clean-ups Automated refactors: * use List::sort instead of Collections::sort * use foreach loops * use switch statements instead of if/else if constructs * use contains() instead of comparing indexOf() * use Collection::removeIf instead of looping explicitly * use Optional::ifPresent where possible * use Map::computeIfAbsent instead of conditional puts * use try with resources Change-Id: I1f6c2986abb0f151bb4ff1bc262b1c1ae11c523f Signed-off-by: Stephen Kitt --- .../openflow13/PipelineOrchestratorImpl.java | 4 +- .../openflow13/services/EgressAclService.java | 104 +++++++++--------- .../services/IngressAclService.java | 100 +++++++++-------- .../impl/SecurityGroupCacheManagerImpl.java | 23 +--- .../aclservice/utils/AclServiceUtils.java | 13 +-- .../oam/BgpCountersBroadcaster.java | 6 +- .../netvirt/dhcpservice/DhcpPktHandler.java | 9 +- .../elanmanager/utils/ElanL2GwCacheUtils.java | 8 +- .../netvirt/elan/l2gw/ha/HwvtepHAUtil.java | 4 +- .../ha/listeners/HwvtepNodeBaseListener.java | 8 +- .../HwvtepTerminationPointListener.java | 9 +- .../netvirt/elan/utils/ElanUtils.java | 20 +--- .../GlobalAugmentationHelper.java | 13 +-- .../NodeConnectedHandlerUtils.java | 10 +- .../netvirt/fibmanager/NexthopManager.java | 37 ++++--- .../netvirt/ipv6service/VirtualRouter.java | 17 +-- .../netvirt/ipv6service/VirtualSubnet.java | 11 +- .../ipv6service/utils/Ipv6ServiceUtils.java | 11 +- .../org/opendaylight/netvirt/it/PortInfo.java | 8 +- .../neutronvpn/NeutronPortChangeListener.java | 11 +- .../NeutronRouterChangeListener.java | 11 +- .../netvirt/neutronvpn/NeutronvpnManager.java | 8 +- .../netvirt/neutronvpn/NeutronvpnUtils.java | 9 +- .../vpnmanager/ArpMonitorStopTask.java | 6 +- .../TunnelInterfaceStateListener.java | 6 +- .../netvirt/vpnmanager/VpnOpDataSyncer.java | 9 +- .../netvirt/vpnmanager/VpnUtil.java | 16 +-- 27 files changed, 198 insertions(+), 293 deletions(-) diff --git a/openstack/net-virt-providers/src/main/java/org/opendaylight/netvirt/openstack/netvirt/providers/openflow13/PipelineOrchestratorImpl.java b/openstack/net-virt-providers/src/main/java/org/opendaylight/netvirt/openstack/netvirt/providers/openflow13/PipelineOrchestratorImpl.java index 86fc2767dd..9fcbe1f9aa 100644 --- a/openstack/net-virt-providers/src/main/java/org/opendaylight/netvirt/openstack/netvirt/providers/openflow13/PipelineOrchestratorImpl.java +++ b/openstack/net-virt-providers/src/main/java/org/opendaylight/netvirt/openstack/netvirt/providers/openflow13/PipelineOrchestratorImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, 2015 Red Hat, Inc. and others. All rights reserved. + * Copyright © 2014, 2017 Red Hat, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -103,7 +103,7 @@ public class PipelineOrchestratorImpl implements ConfigInterface, NodeCacheListe // insert the service if not already there. The list is ordered based of table ID. if (!staticPipeline.contains(service) && !isTableInPipeline(service.getTable())) { staticPipeline.add(service); - Collections.sort(staticPipeline, Service.insertComparator); + staticPipeline.sort(Service.insertComparator); } LOG.info("registerService: {}", staticPipeline); } diff --git a/openstack/net-virt-providers/src/main/java/org/opendaylight/netvirt/openstack/netvirt/providers/openflow13/services/EgressAclService.java b/openstack/net-virt-providers/src/main/java/org/opendaylight/netvirt/openstack/netvirt/providers/openflow13/services/EgressAclService.java index 0a7bc6751b..a8ef5445f6 100644 --- a/openstack/net-virt-providers/src/main/java/org/opendaylight/netvirt/openstack/netvirt/providers/openflow13/services/EgressAclService.java +++ b/openstack/net-virt-providers/src/main/java/org/opendaylight/netvirt/openstack/netvirt/providers/openflow13/services/EgressAclService.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 - 2016 Red Hat, Inc. and others. All rights reserved. + * Copyright © 2014, 2017 Red Hat, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -247,56 +247,62 @@ public class EgressAclService extends AbstractServiceInstance implements EgressA portSecurityRule.setSecurityRuleProtocol(null); } } else { - if (portSecurityRule.getSecurityRuleProtocol().equals(MatchUtils.TCP_PROTOCOL)) { - portSecurityRule.setSecurityRulePortMin(PORT_RANGE_MIN); - portSecurityRule.setSecurityRulePortMax(PORT_RANGE_MAX); - egressAclTcp(dpidLong, segmentationId, srcMac, - portSecurityRule,dstAddress, write, - Constants.PROTO_PORT_PREFIX_MATCH_PRIORITY, false); - } else if (portSecurityRule.getSecurityRuleProtocol().equals(MatchUtils.UDP_PROTOCOL)) { - portSecurityRule.setSecurityRulePortMin(PORT_RANGE_MIN); - portSecurityRule.setSecurityRulePortMax(PORT_RANGE_MAX); - egressAclUdp(dpidLong, segmentationId, srcMac, - portSecurityRule, dstAddress, write, - Constants.PROTO_PORT_PREFIX_MATCH_PRIORITY, false); - } else if (portSecurityRule.getSecurityRuleProtocol().equals(MatchUtils.ICMP_PROTOCOL)) { - egressAclIcmp(dpidLong, segmentationId, srcMac, - portSecurityRule, dstAddress,write, - Constants.PROTO_PORT_PREFIX_MATCH_PRIORITY, false); - } else { - MatchBuilder matchBuilder = new MatchBuilder(); - String flowId = "Egress_Other_" + segmentationId + "_" + srcMac + "_"; - matchBuilder = MatchUtils.createV4EtherMatchWithType(matchBuilder,srcMac,null,MatchUtils.ETHERTYPE_IPV4); - short proto = 0; - try { - Integer protocol = new Integer(portSecurityRule.getSecurityRuleProtocol()); - proto = protocol.shortValue(); - flowId = flowId + proto; - } catch (NumberFormatException e) { - LOG.error("Protocol vlaue conversion failure", e); - } - matchBuilder = MatchUtils.createIpProtocolAndEthMatch(matchBuilder, proto, srcMac, null); - if (null != dstAddress) { - flowId = flowId + dstAddress; - matchBuilder = MatchUtils.addRemoteIpPrefix(matchBuilder, null, - MatchUtils.iPv4PrefixFromIPv4Address(dstAddress)); - } else if (null != portSecurityRule.getSecurityRuleRemoteIpPrefix()) { - flowId = flowId + portSecurityRule.getSecurityRuleRemoteIpPrefix(); - if(isIpv6) { - matchBuilder = MatchUtils.addRemoteIpv6Prefix(matchBuilder,null, - new Ipv6Prefix(portSecurityRule.getSecurityRuleRemoteIpPrefix())); - } else { - if (!portSecurityRule.getSecurityRuleRemoteIpPrefix().contains("/0")) { - matchBuilder = MatchUtils.addRemoteIpPrefix(matchBuilder, null, - new Ipv4Prefix(portSecurityRule.getSecurityRuleRemoteIpPrefix())); + switch (portSecurityRule.getSecurityRuleProtocol()) { + case MatchUtils.TCP_PROTOCOL: + portSecurityRule.setSecurityRulePortMin(PORT_RANGE_MIN); + portSecurityRule.setSecurityRulePortMax(PORT_RANGE_MAX); + egressAclTcp(dpidLong, segmentationId, srcMac, + portSecurityRule, dstAddress, write, + Constants.PROTO_PORT_PREFIX_MATCH_PRIORITY, false); + break; + case MatchUtils.UDP_PROTOCOL: + portSecurityRule.setSecurityRulePortMin(PORT_RANGE_MIN); + portSecurityRule.setSecurityRulePortMax(PORT_RANGE_MAX); + egressAclUdp(dpidLong, segmentationId, srcMac, + portSecurityRule, dstAddress, write, + Constants.PROTO_PORT_PREFIX_MATCH_PRIORITY, false); + break; + case MatchUtils.ICMP_PROTOCOL: + egressAclIcmp(dpidLong, segmentationId, srcMac, + portSecurityRule, dstAddress, write, + Constants.PROTO_PORT_PREFIX_MATCH_PRIORITY, false); + break; + default: + MatchBuilder matchBuilder = new MatchBuilder(); + String flowId = "Egress_Other_" + segmentationId + "_" + srcMac + "_"; + matchBuilder = MatchUtils.createV4EtherMatchWithType(matchBuilder, srcMac, null, + MatchUtils.ETHERTYPE_IPV4); + short proto = 0; + try { + Integer protocol = new Integer(portSecurityRule.getSecurityRuleProtocol()); + proto = protocol.shortValue(); + flowId = flowId + proto; + } catch (NumberFormatException e) { + LOG.error("Protocol vlaue conversion failure", e); + } + matchBuilder = MatchUtils.createIpProtocolAndEthMatch(matchBuilder, proto, srcMac, null); + if (null != dstAddress) { + flowId = flowId + dstAddress; + matchBuilder = MatchUtils.addRemoteIpPrefix(matchBuilder, null, + MatchUtils.iPv4PrefixFromIPv4Address(dstAddress)); + } else if (null != portSecurityRule.getSecurityRuleRemoteIpPrefix()) { + flowId = flowId + portSecurityRule.getSecurityRuleRemoteIpPrefix(); + if (isIpv6) { + matchBuilder = MatchUtils.addRemoteIpv6Prefix(matchBuilder, null, + new Ipv6Prefix(portSecurityRule.getSecurityRuleRemoteIpPrefix())); + } else { + if (!portSecurityRule.getSecurityRuleRemoteIpPrefix().contains("/0")) { + matchBuilder = MatchUtils.addRemoteIpPrefix(matchBuilder, null, + new Ipv4Prefix(portSecurityRule.getSecurityRuleRemoteIpPrefix())); + } } } - } - flowId = flowId + "_Permit"; - NodeBuilder nodeBuilder = FlowUtils.createNodeBuilder(dpidLong); - FlowBuilder flowBuilder = FlowUtils.createFlowBuilder(flowId, priority, matchBuilder, getTable()); - addInstructionWithConntrackCommit(flowBuilder, false); - syncFlow(flowBuilder ,nodeBuilder, write); + flowId = flowId + "_Permit"; + NodeBuilder nodeBuilder = FlowUtils.createNodeBuilder(dpidLong); + FlowBuilder flowBuilder = FlowUtils.createFlowBuilder(flowId, priority, matchBuilder, getTable()); + addInstructionWithConntrackCommit(flowBuilder, false); + syncFlow(flowBuilder, nodeBuilder, write); + break; } } } diff --git a/openstack/net-virt-providers/src/main/java/org/opendaylight/netvirt/openstack/netvirt/providers/openflow13/services/IngressAclService.java b/openstack/net-virt-providers/src/main/java/org/opendaylight/netvirt/openstack/netvirt/providers/openflow13/services/IngressAclService.java index 2eb144fe2d..2bb5db3926 100644 --- a/openstack/net-virt-providers/src/main/java/org/opendaylight/netvirt/openstack/netvirt/providers/openflow13/services/IngressAclService.java +++ b/openstack/net-virt-providers/src/main/java/org/opendaylight/netvirt/openstack/netvirt/providers/openflow13/services/IngressAclService.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 - 2016 Red Hat, Inc. and others. All rights reserved. + * Copyright © 2014, 2017 Red Hat, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -229,54 +229,60 @@ public class IngressAclService extends AbstractServiceInstance implements Ingres portSecurityRule.setSecurityRuleProtocol(null); } } else { - if (portSecurityRule.getSecurityRuleProtocol().equals(MatchUtils.TCP_PROTOCOL)) { - portSecurityRule.setSecurityRulePortMin(PORT_RANGE_MIN); - portSecurityRule.setSecurityRulePortMax(PORT_RANGE_MAX); - ingressAclTcp(dpidLong, segmentationId, dstMac, portSecurityRule, srcAddress, - write, Constants.PROTO_PORT_PREFIX_MATCH_PRIORITY, false); - } else if (portSecurityRule.getSecurityRuleProtocol().equals(MatchUtils.UDP_PROTOCOL)) { - portSecurityRule.setSecurityRulePortMin(PORT_RANGE_MIN); - portSecurityRule.setSecurityRulePortMax(PORT_RANGE_MAX); - ingressAclUdp(dpidLong, segmentationId, dstMac, portSecurityRule, srcAddress, - write, Constants.PROTO_PORT_PREFIX_MATCH_PRIORITY, false); - } else if (portSecurityRule.getSecurityRuleProtocol().equals(MatchUtils.ICMP_PROTOCOL)) { - ingressAclIcmp(dpidLong, segmentationId, dstMac, portSecurityRule, srcAddress, - write, Constants.PROTO_PORT_PREFIX_MATCH_PRIORITY, false); - } else { - MatchBuilder matchBuilder = new MatchBuilder(); - String flowId = "Ingress_Other_" + segmentationId + "_" + dstMac + "_"; - matchBuilder = MatchUtils.createV4EtherMatchWithType(matchBuilder,null,dstMac,MatchUtils.ETHERTYPE_IPV4); - short proto = 0; - try { - Integer protocol = new Integer(portSecurityRule.getSecurityRuleProtocol()); - proto = protocol.shortValue(); - flowId = flowId + proto; - } catch (NumberFormatException e) { - LOG.error("Protocol vlaue conversion failure", e); - } - matchBuilder = MatchUtils.createIpProtocolAndEthMatch(matchBuilder, proto, null, dstMac); - if (null != srcAddress) { - flowId = flowId + srcAddress; - matchBuilder = MatchUtils.addRemoteIpPrefix(matchBuilder, - MatchUtils.iPv4PrefixFromIPv4Address(srcAddress), null); - } else if (null != portSecurityRule.getSecurityRuleRemoteIpPrefix()) { - flowId = flowId + portSecurityRule.getSecurityRuleRemoteIpPrefix(); - if(isIpv6) { - matchBuilder = MatchUtils.addRemoteIpv6Prefix(matchBuilder,null, - new Ipv6Prefix(portSecurityRule.getSecurityRuleRemoteIpPrefix())); - } else { - if (!portSecurityRule.getSecurityRuleRemoteIpPrefix().contains("/0")) { - matchBuilder = MatchUtils.addRemoteIpPrefix(matchBuilder, - new Ipv4Prefix(portSecurityRule.getSecurityRuleRemoteIpPrefix()),null); + switch (portSecurityRule.getSecurityRuleProtocol()) { + case MatchUtils.TCP_PROTOCOL: + portSecurityRule.setSecurityRulePortMin(PORT_RANGE_MIN); + portSecurityRule.setSecurityRulePortMax(PORT_RANGE_MAX); + ingressAclTcp(dpidLong, segmentationId, dstMac, portSecurityRule, srcAddress, + write, Constants.PROTO_PORT_PREFIX_MATCH_PRIORITY, false); + break; + case MatchUtils.UDP_PROTOCOL: + portSecurityRule.setSecurityRulePortMin(PORT_RANGE_MIN); + portSecurityRule.setSecurityRulePortMax(PORT_RANGE_MAX); + ingressAclUdp(dpidLong, segmentationId, dstMac, portSecurityRule, srcAddress, + write, Constants.PROTO_PORT_PREFIX_MATCH_PRIORITY, false); + break; + case MatchUtils.ICMP_PROTOCOL: + ingressAclIcmp(dpidLong, segmentationId, dstMac, portSecurityRule, srcAddress, + write, Constants.PROTO_PORT_PREFIX_MATCH_PRIORITY, false); + break; + default: + MatchBuilder matchBuilder = new MatchBuilder(); + String flowId = "Ingress_Other_" + segmentationId + "_" + dstMac + "_"; + matchBuilder = MatchUtils.createV4EtherMatchWithType(matchBuilder, null, dstMac, + MatchUtils.ETHERTYPE_IPV4); + short proto = 0; + try { + Integer protocol = new Integer(portSecurityRule.getSecurityRuleProtocol()); + proto = protocol.shortValue(); + flowId = flowId + proto; + } catch (NumberFormatException e) { + LOG.error("Protocol vlaue conversion failure", e); + } + matchBuilder = MatchUtils.createIpProtocolAndEthMatch(matchBuilder, proto, null, dstMac); + if (null != srcAddress) { + flowId = flowId + srcAddress; + matchBuilder = MatchUtils.addRemoteIpPrefix(matchBuilder, + MatchUtils.iPv4PrefixFromIPv4Address(srcAddress), null); + } else if (null != portSecurityRule.getSecurityRuleRemoteIpPrefix()) { + flowId = flowId + portSecurityRule.getSecurityRuleRemoteIpPrefix(); + if (isIpv6) { + matchBuilder = MatchUtils.addRemoteIpv6Prefix(matchBuilder, null, + new Ipv6Prefix(portSecurityRule.getSecurityRuleRemoteIpPrefix())); + } else { + if (!portSecurityRule.getSecurityRuleRemoteIpPrefix().contains("/0")) { + matchBuilder = MatchUtils.addRemoteIpPrefix(matchBuilder, + new Ipv4Prefix(portSecurityRule.getSecurityRuleRemoteIpPrefix()), null); + } } } - } - flowId = flowId + "_Permit"; - NodeBuilder nodeBuilder = FlowUtils.createNodeBuilder(dpidLong); - FlowBuilder flowBuilder = FlowUtils.createFlowBuilder(flowId, protoPortMatchPriority, - matchBuilder, getTable()); - addInstructionWithConntrackCommit(flowBuilder, false); - syncFlow(flowBuilder ,nodeBuilder, write); + flowId = flowId + "_Permit"; + NodeBuilder nodeBuilder = FlowUtils.createNodeBuilder(dpidLong); + FlowBuilder flowBuilder = FlowUtils.createFlowBuilder(flowId, protoPortMatchPriority, + matchBuilder, getTable()); + addInstructionWithConntrackCommit(flowBuilder, false); + syncFlow(flowBuilder, nodeBuilder, write); + break; } } } diff --git a/openstack/net-virt/src/main/java/org/opendaylight/netvirt/openstack/netvirt/impl/SecurityGroupCacheManagerImpl.java b/openstack/net-virt/src/main/java/org/opendaylight/netvirt/openstack/netvirt/impl/SecurityGroupCacheManagerImpl.java index 053399670c..ebae7789f0 100644 --- a/openstack/net-virt/src/main/java/org/opendaylight/netvirt/openstack/netvirt/impl/SecurityGroupCacheManagerImpl.java +++ b/openstack/net-virt/src/main/java/org/opendaylight/netvirt/openstack/netvirt/impl/SecurityGroupCacheManagerImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, 2015 HP, Inc. and others. All rights reserved. + * Copyright © 2014, 2017 HP, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -28,7 +28,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.ArrayList; -import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.HashMap; @@ -83,11 +82,7 @@ public class SecurityGroupCacheManagerImpl implements ConfigInterface, SecurityG @Override public void addToCache(String remoteSgUuid, String portUuid, NodeId nodeId) { LOG.debug("In addToCache remoteSgUuid:" + remoteSgUuid + " portUuid:" + portUuid); - Map remoteSgPorts = securityGroupCache.get(remoteSgUuid); - if (null == remoteSgPorts) { - remoteSgPorts = new HashMap<>(); - securityGroupCache.put(remoteSgUuid, remoteSgPorts); - } + Map remoteSgPorts = securityGroupCache.computeIfAbsent(remoteSgUuid, k -> new HashMap<>()); remoteSgPorts.put(portUuid, nodeId); } @@ -123,10 +118,7 @@ public class SecurityGroupCacheManagerImpl implements ConfigInterface, SecurityG LOG.debug("The port list is empty for security group:" + securityGroupUuid); return; } - Set portSet = portList.entrySet(); - Iterator itr = portSet.iterator(); - while(itr.hasNext()) { - Map.Entry portEntry = (Map.Entry)itr.next(); + for (Map.Entry portEntry : portList.entrySet()) { String cachedportUuid = portEntry.getKey(); NodeId nodeId = portEntry.getValue(); if (cachedportUuid.equals(port.getID())) { @@ -137,7 +129,7 @@ public class SecurityGroupCacheManagerImpl implements ConfigInterface, SecurityG cachedport = neutronL3Adapter.getPortFromCleanupCache(cachedportUuid); if (null == cachedport) { LOG.error("In processPortRemoved cachedport port not found in neuton cache:" - + " cachedportUuid:" + cachedportUuid); + + " cachedportUuid:" + cachedportUuid); continue; } } @@ -164,10 +156,7 @@ public class SecurityGroupCacheManagerImpl implements ConfigInterface, SecurityG LOG.debug("The port list is empty for security group:" + securityGroupUuid); return; } - Set portSet = portList.entrySet(); - Iterator itr = portSet.iterator(); - while(itr.hasNext()) { - Map.Entry portEntry = (Map.Entry)itr.next(); + for (Map.Entry portEntry : portList.entrySet()) { String cachedportUuid = portEntry.getKey(); NodeId nodeId = portEntry.getValue(); if (cachedportUuid.equals(port.getID())) { @@ -178,7 +167,7 @@ public class SecurityGroupCacheManagerImpl implements ConfigInterface, SecurityG cachedport = neutronL3Adapter.getPortFromCleanupCache(cachedportUuid); if (null == cachedport) { LOG.error("In processPortRemoved cachedport port not found in neuton cache:" - + " cachedportUuid:" + cachedportUuid); + + " cachedportUuid:" + cachedportUuid); continue; } } diff --git a/vpnservice/aclservice/impl/src/main/java/org/opendaylight/netvirt/aclservice/utils/AclServiceUtils.java b/vpnservice/aclservice/impl/src/main/java/org/opendaylight/netvirt/aclservice/utils/AclServiceUtils.java index 0a5854d744..6793ffa7f1 100644 --- a/vpnservice/aclservice/impl/src/main/java/org/opendaylight/netvirt/aclservice/utils/AclServiceUtils.java +++ b/vpnservice/aclservice/impl/src/main/java/org/opendaylight/netvirt/aclservice/utils/AclServiceUtils.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Red Hat, Inc. and others. All rights reserved. + * Copyright © 2016, 2017 Red Hat, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -146,17 +146,12 @@ public final class AclServiceUtils { */ public static Optional read( DataBroker broker, LogicalDatastoreType datastoreType, InstanceIdentifier path) { - - Optional result = Optional.absent(); - ReadOnlyTransaction tx = broker.newReadOnlyTransaction(); - try { - result = tx.read(datastoreType, path).checkedGet(); + try (ReadOnlyTransaction tx = broker.newReadOnlyTransaction()) { + return tx.read(datastoreType, path).checkedGet(); } catch (ReadFailedException e) { LOG.warn("Failed to read InstanceIdentifier {} from {}", path, datastoreType, e); - } finally { - tx.close(); + return Optional.absent(); } - return result; } /** diff --git a/vpnservice/bgpmanager/bgpmanager-impl/src/main/java/org/opendaylight/netvirt/bgpmanager/oam/BgpCountersBroadcaster.java b/vpnservice/bgpmanager/bgpmanager-impl/src/main/java/org/opendaylight/netvirt/bgpmanager/oam/BgpCountersBroadcaster.java index cbd8ebcbbe..34d1950abe 100644 --- a/vpnservice/bgpmanager/bgpmanager-impl/src/main/java/org/opendaylight/netvirt/bgpmanager/oam/BgpCountersBroadcaster.java +++ b/vpnservice/bgpmanager/bgpmanager-impl/src/main/java/org/opendaylight/netvirt/bgpmanager/oam/BgpCountersBroadcaster.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. + * Copyright © 2015, 2017 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -27,9 +27,7 @@ public class BgpCountersBroadcaster extends NotificationBroadcasterSupport imple public Map retrieveCounterMap() { LOGGER.trace("Polled retrieveCounterMap"); Map countersVal = new HashMap<>(bgpCountersMap); - Iterator> entries = countersVal.entrySet().iterator(); - while (entries.hasNext()) { - Map.Entry entry = entries.next(); + for (Map.Entry entry : countersVal.entrySet()) { LOGGER.trace(entry.getKey() + ", Value from MBean= " + entry.getValue()); } return countersVal; diff --git a/vpnservice/dhcpservice/dhcpservice-impl/src/main/java/org/opendaylight/netvirt/dhcpservice/DhcpPktHandler.java b/vpnservice/dhcpservice/dhcpservice-impl/src/main/java/org/opendaylight/netvirt/dhcpservice/DhcpPktHandler.java index ef42c3a776..8578d68387 100644 --- a/vpnservice/dhcpservice/dhcpservice-impl/src/main/java/org/opendaylight/netvirt/dhcpservice/DhcpPktHandler.java +++ b/vpnservice/dhcpservice/dhcpservice-impl/src/main/java/org/opendaylight/netvirt/dhcpservice/DhcpPktHandler.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 - 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. + * Copyright © 2015, 2017 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -13,7 +13,6 @@ import java.math.BigInteger; import java.net.InetAddress; import java.net.UnknownHostException; import java.util.Arrays; -import java.util.Iterator; import java.util.List; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; @@ -499,11 +498,9 @@ public class DhcpPktHandler implements PacketProcessingListener { return; } ByteArrayOutputStream result = new ByteArrayOutputStream(); - Iterator iter = hostRoutes.iterator(); - while (iter.hasNext()) { - HostRoutes hostRoute = iter.next(); + for (HostRoutes hostRoute : hostRoutes) { if (hostRoute.getNexthop().getIpv4Address() == null - || hostRoute.getDestination().getIpv4Prefix() == null ) { + || hostRoute.getDestination().getIpv4Prefix() == null) { // we only deal with IPv4 addresses return; } diff --git a/vpnservice/elanmanager/elanmanager-api/src/main/java/org/opendaylight/netvirt/elanmanager/utils/ElanL2GwCacheUtils.java b/vpnservice/elanmanager/elanmanager-api/src/main/java/org/opendaylight/netvirt/elanmanager/utils/ElanL2GwCacheUtils.java index 8cb6269edd..71e569d241 100644 --- a/vpnservice/elanmanager/elanmanager-api/src/main/java/org/opendaylight/netvirt/elanmanager/utils/ElanL2GwCacheUtils.java +++ b/vpnservice/elanmanager/elanmanager-api/src/main/java/org/opendaylight/netvirt/elanmanager/utils/ElanL2GwCacheUtils.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. + * Copyright © 2016, 2017 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -34,11 +34,7 @@ public class ElanL2GwCacheUtils { ConcurrentMap deviceMap = cachedMap.get(elanName); if (deviceMap == null) { synchronized (ElanL2GwCacheUtils.class) { - deviceMap = cachedMap.get(elanName); - if (deviceMap == null) { - deviceMap = new ConcurrentHashMap<>(); - cachedMap.put(elanName, deviceMap); - } + deviceMap = cachedMap.computeIfAbsent(elanName, k -> new ConcurrentHashMap<>()); } } deviceMap.put(l2GwDevice.getHwvtepNodeId(), l2GwDevice); diff --git a/vpnservice/elanmanager/elanmanager-impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/ha/HwvtepHAUtil.java b/vpnservice/elanmanager/elanmanager-impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/ha/HwvtepHAUtil.java index 69cfae232f..ae9b9d0039 100644 --- a/vpnservice/elanmanager/elanmanager-impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/ha/HwvtepHAUtil.java +++ b/vpnservice/elanmanager/elanmanager-impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/ha/HwvtepHAUtil.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. + * Copyright © 2016, 2017 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -365,7 +365,7 @@ public class HwvtepHAUtil { * @return child Switches */ public static Set> getPSChildrenIdsForHAPSNode(String psNodId) { - if (psNodId.indexOf(PHYSICALSWITCH) < 0) { + if (!psNodId.contains(PHYSICALSWITCH)) { return Collections.emptySet(); } String nodeId = convertToGlobalNodeId(psNodId); diff --git a/vpnservice/elanmanager/elanmanager-impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/ha/listeners/HwvtepNodeBaseListener.java b/vpnservice/elanmanager/elanmanager-impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/ha/listeners/HwvtepNodeBaseListener.java index 5912ba8496..b7b4761be6 100644 --- a/vpnservice/elanmanager/elanmanager-impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/ha/listeners/HwvtepNodeBaseListener.java +++ b/vpnservice/elanmanager/elanmanager-impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/ha/listeners/HwvtepNodeBaseListener.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. + * Copyright © 2016, 2017 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -85,7 +85,7 @@ public abstract class HwvtepNodeBaseListener implements DataTreeChangeListener list = waitingJobsList.get(key); - if (list == null) { - list = new ArrayList<>(); - waitingJobsList.put(key, list); - } - list.add(runnable); + waitingJobsList.computeIfAbsent(key, k -> new ArrayList<>()).add(runnable); LOG.debug("added the job to wait list of physical locator {}", key); } } diff --git a/vpnservice/elanmanager/elanmanager-impl/src/main/java/org/opendaylight/netvirt/elan/utils/ElanUtils.java b/vpnservice/elanmanager/elanmanager-impl/src/main/java/org/opendaylight/netvirt/elan/utils/ElanUtils.java index b093bf27b3..8224d0b36e 100755 --- a/vpnservice/elanmanager/elanmanager-impl/src/main/java/org/opendaylight/netvirt/elan/utils/ElanUtils.java +++ b/vpnservice/elanmanager/elanmanager-impl/src/main/java/org/opendaylight/netvirt/elan/utils/ElanUtils.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. + * Copyright © 2016, 2017 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -297,29 +297,19 @@ public class ElanUtils { @SuppressWarnings("checkstyle:IllegalCatch") public Optional read(DataBroker broker, LogicalDatastoreType datastoreType, InstanceIdentifier path) { - ReadOnlyTransaction tx = broker != null ? broker.newReadOnlyTransaction() - : this.broker.newReadOnlyTransaction(); - Optional result = Optional.absent(); - try { - CheckedFuture, ReadFailedException> checkedFuture = tx.read(datastoreType, path); - result = checkedFuture.get(); + try (ReadOnlyTransaction tx = broker != null ? broker.newReadOnlyTransaction() + : this.broker.newReadOnlyTransaction()) { + return tx.read(datastoreType, path).get(); } catch (Exception e) { throw new RuntimeException(e); - } finally { - tx.close(); } - - return result; } public Optional read2(LogicalDatastoreType datastoreType, InstanceIdentifier path) throws ReadFailedException { - ReadOnlyTransaction tx = broker.newReadOnlyTransaction(); - try { + try (ReadOnlyTransaction tx = broker.newReadOnlyTransaction()) { CheckedFuture, ReadFailedException> checkedFuture = tx.read(datastoreType, path); return checkedFuture.checkedGet(); - } finally { - tx.close(); } } diff --git a/vpnservice/elanmanager/elanmanager-impl/src/test/java/org/opendaylight/netvirt/elan/l2gw/nodehandlertest/GlobalAugmentationHelper.java b/vpnservice/elanmanager/elanmanager-impl/src/test/java/org/opendaylight/netvirt/elan/l2gw/nodehandlertest/GlobalAugmentationHelper.java index f9920a9578..9786da41aa 100644 --- a/vpnservice/elanmanager/elanmanager-impl/src/test/java/org/opendaylight/netvirt/elan/l2gw/nodehandlertest/GlobalAugmentationHelper.java +++ b/vpnservice/elanmanager/elanmanager-impl/src/test/java/org/opendaylight/netvirt/elan/l2gw/nodehandlertest/GlobalAugmentationHelper.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. + * Copyright © 2016, 2017 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -9,6 +9,7 @@ package org.opendaylight.netvirt.elan.l2gw.nodehandlertest; import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentationBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepPhysicalSwitchRef; @@ -22,7 +23,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hw import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.SwitchesKey; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder; -import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; /** @@ -102,11 +102,10 @@ public class GlobalAugmentationHelper { //physicallocators public static void addGlobalTerminationPoints(NodeBuilder nodeBuilder, InstanceIdentifier nodeIid, List globalTerminationPointIp) { - List terminationPoints = new ArrayList<>(); - for (int i = 0; i < globalTerminationPointIp.size(); i++) { - terminationPoints.add(TestBuilders.buildTerminationPoint(nodeIid, globalTerminationPointIp.get(i))); - } - nodeBuilder.setTerminationPoint(terminationPoints); + nodeBuilder.setTerminationPoint( + globalTerminationPointIp.stream() + .map(ip -> TestBuilders.buildTerminationPoint(nodeIid, ip)) + .collect(Collectors.toList())); } public static void addSwitches(HwvtepGlobalAugmentationBuilder augmentationBuilder, InstanceIdentifier psId) { diff --git a/vpnservice/elanmanager/elanmanager-impl/src/test/java/org/opendaylight/netvirt/elan/l2gw/nodehandlertest/NodeConnectedHandlerUtils.java b/vpnservice/elanmanager/elanmanager-impl/src/test/java/org/opendaylight/netvirt/elan/l2gw/nodehandlertest/NodeConnectedHandlerUtils.java index 9949923990..976c923d26 100644 --- a/vpnservice/elanmanager/elanmanager-impl/src/test/java/org/opendaylight/netvirt/elan/l2gw/nodehandlertest/NodeConnectedHandlerUtils.java +++ b/vpnservice/elanmanager/elanmanager-impl/src/test/java/org/opendaylight/netvirt/elan/l2gw/nodehandlertest/NodeConnectedHandlerUtils.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. + * Copyright © 2016, 2017 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -10,6 +10,7 @@ package org.opendaylight.netvirt.elan.l2gw.nodehandlertest; import static org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.OPERATIONAL; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.UUID; import org.opendaylight.controller.md.sal.binding.api.WriteTransaction; @@ -99,12 +100,7 @@ public class NodeConnectedHandlerUtils { } public List getData(String data) { - String[] dataArray = data.split(","); - List logicalSwitch = new ArrayList<>(); - for (int i = 0; i < dataArray.length; i++) { - logicalSwitch.add(dataArray[i]); - } - return logicalSwitch; + return Arrays.asList(data.split(",")); } public static Uuid getUUid(String key) { diff --git a/vpnservice/fibmanager/fibmanager-impl/src/main/java/org/opendaylight/netvirt/fibmanager/NexthopManager.java b/vpnservice/fibmanager/fibmanager-impl/src/main/java/org/opendaylight/netvirt/fibmanager/NexthopManager.java index cd47e98e60..1506dd1f04 100644 --- a/vpnservice/fibmanager/fibmanager-impl/src/main/java/org/opendaylight/netvirt/fibmanager/NexthopManager.java +++ b/vpnservice/fibmanager/fibmanager-impl/src/main/java/org/opendaylight/netvirt/fibmanager/NexthopManager.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 - 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. + * Copyright © 2015, 2017 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -627,26 +627,31 @@ public class NexthopManager implements AutoCloseable { private ConfTransportTypeL3vpn createConfTransportType(String type) { ConfTransportTypeL3vpn confTransType; - if (type.equals(ITMConstants.TUNNEL_TYPE_GRE)) { - confTransType = new ConfTransportTypeL3vpnBuilder().setTransportType(TunnelTypeGre.class).build(); - LOG.trace("Setting the confTransportType to GRE."); - } else if (type.equals(ITMConstants.TUNNEL_TYPE_VXLAN)) { - confTransType = new ConfTransportTypeL3vpnBuilder().setTransportType(TunnelTypeVxlan.class).build(); - LOG.trace("Setting the confTransportType to VxLAN."); - } else { - LOG.trace("Invalid transport type {} passed to Config DS ", type); - confTransType = null; + switch (type) { + case ITMConstants.TUNNEL_TYPE_GRE: + confTransType = new ConfTransportTypeL3vpnBuilder().setTransportType(TunnelTypeGre.class).build(); + LOG.trace("Setting the confTransportType to GRE."); + break; + case ITMConstants.TUNNEL_TYPE_VXLAN: + confTransType = new ConfTransportTypeL3vpnBuilder().setTransportType(TunnelTypeVxlan.class).build(); + LOG.trace("Setting the confTransportType to VxLAN."); + break; + default: + LOG.trace("Invalid transport type {} passed to Config DS ", type); + confTransType = null; + break; } return confTransType; } public Class getReqTunType(String transportType) { - if (transportType.equals("VXLAN")) { - return TunnelTypeVxlan.class; - } else if (transportType.equals("GRE")) { - return TunnelTypeGre.class; - } else { - return TunnelTypeMplsOverGre.class; + switch (transportType) { + case "VXLAN": + return TunnelTypeVxlan.class; + case "GRE": + return TunnelTypeGre.class; + default: + return TunnelTypeMplsOverGre.class; } } diff --git a/vpnservice/ipv6service/impl/src/main/java/org/opendaylight/netvirt/ipv6service/VirtualRouter.java b/vpnservice/ipv6service/impl/src/main/java/org/opendaylight/netvirt/ipv6service/VirtualRouter.java index a58265995c..661c4858c4 100644 --- a/vpnservice/ipv6service/impl/src/main/java/org/opendaylight/netvirt/ipv6service/VirtualRouter.java +++ b/vpnservice/ipv6service/impl/src/main/java/org/opendaylight/netvirt/ipv6service/VirtualRouter.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Dell Inc. and others. All rights reserved. + * Copyright © 2015, 2017 Dell Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -8,9 +8,7 @@ package org.opendaylight.netvirt.ipv6service; -import java.util.Collection; import java.util.HashMap; -import java.util.Iterator; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -81,25 +79,16 @@ public class VirtualRouter { } public void removeSelf() { - Collection intfs = interfaces.values(); - - Iterator itr = intfs.iterator(); - while (itr.hasNext()) { - VirtualPort intf = (VirtualPort) itr.next(); + for (VirtualPort intf : interfaces.values()) { if (intf != null) { intf.setRouter(null); } } - Collection snets = subnets.values(); - - Iterator itr2 = snets.iterator(); - while (itr2.hasNext()) { - VirtualSubnet snet = (VirtualSubnet) itr2.next(); + for (VirtualSubnet snet : subnets.values()) { if (snet != null) { snet.setRouter(null); } } - return; } } diff --git a/vpnservice/ipv6service/impl/src/main/java/org/opendaylight/netvirt/ipv6service/VirtualSubnet.java b/vpnservice/ipv6service/impl/src/main/java/org/opendaylight/netvirt/ipv6service/VirtualSubnet.java index 3624ed57f4..84ec72caee 100644 --- a/vpnservice/ipv6service/impl/src/main/java/org/opendaylight/netvirt/ipv6service/VirtualSubnet.java +++ b/vpnservice/ipv6service/impl/src/main/java/org/opendaylight/netvirt/ipv6service/VirtualSubnet.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Dell Inc. and others. All rights reserved. + * Copyright © 2015, 2017 Dell Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -8,9 +8,7 @@ package org.opendaylight.netvirt.ipv6service; -import java.util.Collection; import java.util.HashMap; -import java.util.Iterator; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid; @@ -138,11 +136,7 @@ public class VirtualSubnet { } public void removeSelf() { - Collection intfs = interfaces.values(); - - Iterator itr = intfs.iterator(); - while (itr.hasNext()) { - VirtualPort intf = (VirtualPort) itr.next(); + for (VirtualPort intf : interfaces.values()) { if (intf != null) { intf.removeSubnetInfo(subnetUUID); } @@ -151,6 +145,5 @@ public class VirtualSubnet { if (router != null) { router.removeSubnet(this); } - return; } } diff --git a/vpnservice/ipv6service/impl/src/main/java/org/opendaylight/netvirt/ipv6service/utils/Ipv6ServiceUtils.java b/vpnservice/ipv6service/impl/src/main/java/org/opendaylight/netvirt/ipv6service/utils/Ipv6ServiceUtils.java index 7adebfafbf..f6d894fbef 100644 --- a/vpnservice/ipv6service/impl/src/main/java/org/opendaylight/netvirt/ipv6service/utils/Ipv6ServiceUtils.java +++ b/vpnservice/ipv6service/impl/src/main/java/org/opendaylight/netvirt/ipv6service/utils/Ipv6ServiceUtils.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Red Hat, Inc. and others. All rights reserved. + * Copyright © 2016, 2017 Red Hat, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -95,16 +95,11 @@ public class Ipv6ServiceUtils { */ public static Optional read(DataBroker broker, LogicalDatastoreType datastoreType, InstanceIdentifier path) { - ReadOnlyTransaction tx = broker.newReadOnlyTransaction(); - Optional result = Optional.absent(); - try { - result = tx.read(datastoreType, path).get(); + try (ReadOnlyTransaction tx = broker.newReadOnlyTransaction()) { + return tx.read(datastoreType, path).get(); } catch (InterruptedException | ExecutionException e) { throw new RuntimeException(e); - } finally { - tx.close(); } - return result; } /** diff --git a/vpnservice/it/impl/src/test/java/org/opendaylight/netvirt/it/PortInfo.java b/vpnservice/it/impl/src/test/java/org/opendaylight/netvirt/it/PortInfo.java index d4c2509bd9..259bade7dd 100644 --- a/vpnservice/it/impl/src/test/java/org/opendaylight/netvirt/it/PortInfo.java +++ b/vpnservice/it/impl/src/test/java/org/opendaylight/netvirt/it/PortInfo.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Red Hat, Inc. and others. All rights reserved. + * Copyright © 2016, 2017 Red Hat, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -42,11 +42,7 @@ public class PortInfo { } public PortIp allocateFixedIp(int ipVersion, String ipPfx, String subnetId) { - PortIp portIp = fixedIpList.get(ipPfx); - if (portIp == null) { - portIp = new PortIp(ipVersion, ipPfx, subnetId); - fixedIpList.put(ipPfx, portIp); - } + PortIp portIp = fixedIpList.computeIfAbsent(ipPfx, k -> new PortIp(ipVersion, ipPfx, subnetId)); if (NetvirtITConstants.IPV4 == ipVersion) { portIp.setFixedIp(ipFor(ipPfx, ofPort)); diff --git a/vpnservice/neutronvpn/neutronvpn-impl/src/main/java/org/opendaylight/netvirt/neutronvpn/NeutronPortChangeListener.java b/vpnservice/neutronvpn/neutronvpn-impl/src/main/java/org/opendaylight/netvirt/neutronvpn/NeutronPortChangeListener.java index f05af99793..bb0fd29706 100644 --- a/vpnservice/neutronvpn/neutronvpn-impl/src/main/java/org/opendaylight/netvirt/neutronvpn/NeutronPortChangeListener.java +++ b/vpnservice/neutronvpn/neutronvpn-impl/src/main/java/org/opendaylight/netvirt/neutronvpn/NeutronPortChangeListener.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 - 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. + * Copyright © 2015, 2017 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -12,7 +12,6 @@ import static org.opendaylight.netvirt.neutronvpn.NeutronvpnUtils.buildfloatingI import com.google.common.base.Optional; import com.google.common.util.concurrent.ListenableFuture; import java.util.ArrayList; -import java.util.Iterator; import java.util.List; import org.opendaylight.controller.md.sal.binding.api.DataBroker; import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService; @@ -233,13 +232,7 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase

oldIPs = (original.getFixedIps() != null) ? original.getFixedIps() : new ArrayList<>(); List newIPs = (update.getFixedIps() != null) ? update.getFixedIps() : new ArrayList<>(); if (!oldIPs.equals(newIPs)) { - Iterator iterator = newIPs.iterator(); - while (iterator.hasNext()) { - FixedIps ip = iterator.next(); - if (oldIPs.remove(ip)) { - iterator.remove(); - } - } + newIPs.removeIf(oldIPs::remove); handleNeutronPortUpdated(original, update); } if (NeutronConstants.DEVICE_OWNER_GATEWAY_INF.equals(update.getDeviceOwner())) { diff --git a/vpnservice/neutronvpn/neutronvpn-impl/src/main/java/org/opendaylight/netvirt/neutronvpn/NeutronRouterChangeListener.java b/vpnservice/neutronvpn/neutronvpn-impl/src/main/java/org/opendaylight/netvirt/neutronvpn/NeutronRouterChangeListener.java index 8df269c661..484697ab9a 100644 --- a/vpnservice/neutronvpn/neutronvpn-impl/src/main/java/org/opendaylight/netvirt/neutronvpn/NeutronRouterChangeListener.java +++ b/vpnservice/neutronvpn/neutronvpn-impl/src/main/java/org/opendaylight/netvirt/neutronvpn/NeutronRouterChangeListener.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. + * Copyright © 2016, 2017 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -10,7 +10,6 @@ package org.opendaylight.netvirt.neutronvpn; import com.google.common.base.Optional; import java.util.ArrayList; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import org.opendaylight.controller.md.sal.binding.api.DataBroker; import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; @@ -102,13 +101,7 @@ public class NeutronRouterChangeListener extends AsyncDataTreeChangeListenerBase List oldRoutes = (original.getRoutes() != null) ? original.getRoutes() : new ArrayList<>(); List newRoutes = (update.getRoutes() != null) ? update.getRoutes() : new ArrayList<>(); if (!oldRoutes.equals(newRoutes)) { - Iterator iterator = newRoutes.iterator(); - while (iterator.hasNext()) { - Routes route = iterator.next(); - if (oldRoutes.remove(route)) { - iterator.remove(); - } - } + newRoutes.removeIf(oldRoutes::remove); handleChangedRoutes(vpnId, newRoutes, NwConstants.ADD_FLOW); diff --git a/vpnservice/neutronvpn/neutronvpn-impl/src/main/java/org/opendaylight/netvirt/neutronvpn/NeutronvpnManager.java b/vpnservice/neutronvpn/neutronvpn-impl/src/main/java/org/opendaylight/netvirt/neutronvpn/NeutronvpnManager.java index 24867756d2..406fd81573 100644 --- a/vpnservice/neutronvpn/neutronvpn-impl/src/main/java/org/opendaylight/netvirt/neutronvpn/NeutronvpnManager.java +++ b/vpnservice/neutronvpn/neutronvpn-impl/src/main/java/org/opendaylight/netvirt/neutronvpn/NeutronvpnManager.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 - 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. + * Copyright © 2015, 2017 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -1309,11 +1309,7 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even } LOG.trace("Adding extra route for destination {} onto vpn {} with nexthop {} ", destination, vpnId.getValue(), nextHop); - List hops = adjMap.get(destination); - if (hops == null) { - hops = new ArrayList<>(); - adjMap.put(destination, hops); - } + List hops = adjMap.computeIfAbsent(destination, k -> new ArrayList<>()); if (!hops.contains(nextHop)) { hops.add(nextHop); } diff --git a/vpnservice/neutronvpn/neutronvpn-impl/src/main/java/org/opendaylight/netvirt/neutronvpn/NeutronvpnUtils.java b/vpnservice/neutronvpn/neutronvpn-impl/src/main/java/org/opendaylight/netvirt/neutronvpn/NeutronvpnUtils.java index e58b3b81bc..d257580c90 100644 --- a/vpnservice/neutronvpn/neutronvpn-impl/src/main/java/org/opendaylight/netvirt/neutronvpn/NeutronvpnUtils.java +++ b/vpnservice/neutronvpn/neutronvpn-impl/src/main/java/org/opendaylight/netvirt/neutronvpn/NeutronvpnUtils.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. + * Copyright © 2016, 2017 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -867,12 +867,7 @@ public class NeutronvpnUtils { subnetMap.put(subnet.getUuid(), subnet); IpAddress gatewayIp = subnet.getGatewayIp(); if (gatewayIp != null) { - Set gwIps = subnetGwIpMap.get(gatewayIp); - if (gwIps == null) { - gwIps = Sets.newConcurrentHashSet(); - subnetGwIpMap.put(gatewayIp, gwIps); - } - gwIps.add(subnet.getUuid()); + subnetGwIpMap.computeIfAbsent(gatewayIp, k -> Sets.newConcurrentHashSet()).add(subnet.getUuid()); } } diff --git a/vpnservice/vpnmanager/vpnmanager-impl/src/main/java/org/opendaylight/netvirt/vpnmanager/ArpMonitorStopTask.java b/vpnservice/vpnmanager/vpnmanager-impl/src/main/java/org/opendaylight/netvirt/vpnmanager/ArpMonitorStopTask.java index 3afcb254e5..b51946635c 100644 --- a/vpnservice/vpnmanager/vpnmanager-impl/src/main/java/org/opendaylight/netvirt/vpnmanager/ArpMonitorStopTask.java +++ b/vpnservice/vpnmanager/vpnmanager-impl/src/main/java/org/opendaylight/netvirt/vpnmanager/ArpMonitorStopTask.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. + * Copyright © 2016, 2017 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -46,9 +46,7 @@ public class ArpMonitorStopTask implements Callable> final List> futures = new ArrayList<>(); WriteTransaction tx = dataBroker.newWriteOnlyTransaction(); java.util.Optional monitorIdOptional = AlivenessMonitorUtils.getMonitorIdFromInterface(macEntry); - if (monitorIdOptional.isPresent()) { - AlivenessMonitorUtils.stopArpMonitoring(alivenessManager, monitorIdOptional.get()); - } + monitorIdOptional.ifPresent(aLong -> AlivenessMonitorUtils.stopArpMonitoring(alivenessManager, aLong)); removeMipAdjacency(macEntry.getIpAddress().getHostAddress(), macEntry.getVpnName(), macEntry.getInterfaceName(), tx); VpnUtil.removeLearntVpnVipToPort(dataBroker, macEntry.getVpnName(), diff --git a/vpnservice/vpnmanager/vpnmanager-impl/src/main/java/org/opendaylight/netvirt/vpnmanager/TunnelInterfaceStateListener.java b/vpnservice/vpnmanager/vpnmanager-impl/src/main/java/org/opendaylight/netvirt/vpnmanager/TunnelInterfaceStateListener.java index 54371b6ad3..94a7073df5 100644 --- a/vpnservice/vpnmanager/vpnmanager-impl/src/main/java/org/opendaylight/netvirt/vpnmanager/TunnelInterfaceStateListener.java +++ b/vpnservice/vpnmanager/vpnmanager-impl/src/main/java/org/opendaylight/netvirt/vpnmanager/TunnelInterfaceStateListener.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. + * Copyright © 2016, 2017 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -309,9 +309,7 @@ public class TunnelInterfaceStateListener extends AsyncDataTreeChangeListenerBas } //Iterate over the VpnId-to-Rd map. - Iterator> entries = vpnIdRdMap.entrySet().iterator(); - while (entries.hasNext()) { - Map.Entry entry = entries.next(); + for (Map.Entry entry : vpnIdRdMap.entrySet()) { Long vpnId = entry.getKey(); rd = entry.getValue(); if ((tunnelAction == TunnelAction.TUNNEL_EP_ADD) diff --git a/vpnservice/vpnmanager/vpnmanager-impl/src/main/java/org/opendaylight/netvirt/vpnmanager/VpnOpDataSyncer.java b/vpnservice/vpnmanager/vpnmanager-impl/src/main/java/org/opendaylight/netvirt/vpnmanager/VpnOpDataSyncer.java index 91c1fb2df2..2c6a770f91 100644 --- a/vpnservice/vpnmanager/vpnmanager-impl/src/main/java/org/opendaylight/netvirt/vpnmanager/VpnOpDataSyncer.java +++ b/vpnservice/vpnmanager/vpnmanager-impl/src/main/java/org/opendaylight/netvirt/vpnmanager/VpnOpDataSyncer.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. + * Copyright © 2016, 2017 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -72,12 +72,7 @@ public class VpnOpDataSyncer { List notifieeList = null; try { synchronized (listenerMap) { - notifieeList = listenerMap.get(vpnName); - if (notifieeList == null) { - notifieeList = new ArrayList<>(); - listenerMap.put(vpnName, notifieeList); - } - notifieeList.add(notifyTask); + listenerMap.computeIfAbsent(vpnName, k -> new ArrayList<>()).add(notifyTask); } synchronized (notifyTask) { diff --git a/vpnservice/vpnmanager/vpnmanager-impl/src/main/java/org/opendaylight/netvirt/vpnmanager/VpnUtil.java b/vpnservice/vpnmanager/vpnmanager-impl/src/main/java/org/opendaylight/netvirt/vpnmanager/VpnUtil.java index 2056085870..74504bcd7a 100755 --- a/vpnservice/vpnmanager/vpnmanager-impl/src/main/java/org/opendaylight/netvirt/vpnmanager/VpnUtil.java +++ b/vpnservice/vpnmanager/vpnmanager-impl/src/main/java/org/opendaylight/netvirt/vpnmanager/VpnUtil.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. + * Copyright © 2016, 2017 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -771,20 +771,12 @@ public class VpnUtil { }; public static Optional read(DataBroker broker, LogicalDatastoreType datastoreType, - InstanceIdentifier path) { - - ReadOnlyTransaction tx = broker.newReadOnlyTransaction(); - - Optional result = Optional.absent(); - try { - result = tx.read(datastoreType, path).get(); + InstanceIdentifier path) { + try (ReadOnlyTransaction tx = broker.newReadOnlyTransaction()) { + return tx.read(datastoreType, path).get(); } catch (InterruptedException | ExecutionException e) { throw new RuntimeException(e); - } finally { - tx.close(); } - - return result; } public static void asyncUpdate(DataBroker broker, LogicalDatastoreType datastoreType, -- 2.36.6