Fix logging issues in neutronvpn 48/69148/3
authorStephen Kitt <skitt@redhat.com>
Tue, 6 Mar 2018 16:55:12 +0000 (17:55 +0100)
committerSam Hague <shague@redhat.com>
Fri, 9 Mar 2018 01:30:03 +0000 (01:30 +0000)
Change-Id: Ib1a7e63a5bef3158ad73f632acf825548ab66fcc
Signed-off-by: Stephen Kitt <skitt@redhat.com>
neutronvpn/api/src/main/java/org/opendaylight/netvirt/neutronvpn/api/utils/NeutronUtils.java
neutronvpn/impl/src/main/java/org/opendaylight/netvirt/neutronvpn/NeutronBgpvpnChangeListener.java
neutronvpn/impl/src/main/java/org/opendaylight/netvirt/neutronvpn/NeutronFloatingToFixedIpMappingChangeListener.java
neutronvpn/impl/src/main/java/org/opendaylight/netvirt/neutronvpn/NeutronHostConfigChangeListener.java
neutronvpn/impl/src/main/java/org/opendaylight/netvirt/neutronvpn/NeutronNetworkChangeListener.java
neutronvpn/impl/src/main/java/org/opendaylight/netvirt/neutronvpn/NeutronSubnetChangeListener.java
neutronvpn/impl/src/main/java/org/opendaylight/netvirt/neutronvpn/NeutronvpnManager.java
neutronvpn/impl/src/main/java/org/opendaylight/netvirt/neutronvpn/NeutronvpnNatManager.java
neutronvpn/impl/src/main/java/org/opendaylight/netvirt/neutronvpn/NeutronvpnUtils.java
neutronvpn/impl/src/main/java/org/opendaylight/netvirt/neutronvpn/evpn/manager/NeutronEvpnManager.java
neutronvpn/impl/src/main/java/org/opendaylight/netvirt/neutronvpn/l2gw/L2GatewayUtils.java

index 3f772eff08533cad228f751070db1680a8a54fea..2f35b8878fce29b5d7b8f26f48a31103cdbf023f 100644 (file)
@@ -83,7 +83,7 @@ public final class NeutronUtils {
                 tx.syncUpdate(LogicalDatastoreType.OPERATIONAL, iid, portBuilder.build());
             }
         } catch (TransactionCommitFailedException e) {
-            LOG.error("writePortStatus: failed neutron port status write. isCreate ? " + create, e);
+            LOG.error("writePortStatus: failed neutron port status write. isCreate: {}", create, e);
             return false;
         }
 
index 81a80bd6cf3b4b9ef8b6b161250d75ec3bfee41f..36aa0dd57970287ba03161305eb057dd4913b1ec 100644 (file)
@@ -149,7 +149,7 @@ public class NeutronBgpvpnChangeListener extends AsyncDataTreeChangeListenerBase
                                 importRouteTargets, exportRouteTargets, router, input.getNetworks(),
                                 vpnInstanceType, 0 /*l3vni*/);
                     } catch (Exception e) {
-                        LOG.error("Creation of BGPVPN {} failed with error {} ", vpnName, e);
+                        LOG.error("Creation of BGPVPN {} failed", vpnName, e);
                     }
                 } else {
                     LOG.error("Create BgpVPN with id {} failed due to missing RD value", vpnName);
index 40ec8553b076606b36ba0c6d4cea44ce9705fdbd..701628feb276c8dab338e963b379f00d3f695315 100644 (file)
@@ -135,11 +135,11 @@ public class NeutronFloatingToFixedIpMappingChangeListener extends AsyncDataTree
                     SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION,
                             routerPortsIdentifier);
             if (optionalRouterPorts.isPresent()) {
-                LOG.debug("Updating routerPorts node {} in floatingIpInfo DS for floating IP () on fixed "
+                LOG.debug("Updating routerPorts node {} in floatingIpInfo DS for floating IP {} on fixed "
                     + "neutron port {} : ", routerName, floatingIpAddress, fixedNeutronPortName);
                 routerPortsBuilder = new RouterPortsBuilder(optionalRouterPorts.get());
             } else {
-                LOG.debug("Creating new routerPorts node {} in floatingIpInfo DS for floating IP () on fixed "
+                LOG.debug("Creating new routerPorts node {} in floatingIpInfo DS for floating IP {} on fixed "
                     + "neutron port {} : ", routerName, floatingIpAddress, fixedNeutronPortName);
                 routerPortsBuilder =
                     new RouterPortsBuilder().setKey(new RouterPortsKey(routerName)).setRouterId(routerName);
@@ -179,7 +179,7 @@ public class NeutronFloatingToFixedIpMappingChangeListener extends AsyncDataTree
                 routerPortsBuilder.setPorts(portsList);
             }
             isLockAcquired = routerLock.tryLock(routerName, LOCK_WAIT_TIME, TimeUnit.SECONDS);
-            LOG.debug("Creating/Updating routerPorts node {} in floatingIpInfo DS for floating IP () on fixed "
+            LOG.debug("Creating/Updating routerPorts node {} in floatingIpInfo DS for floating IP {} on fixed "
                 + "neutron port {} : ", routerName, floatingIpAddress, fixedNeutronPortName);
             MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, routerPortsIdentifier,
                 routerPortsBuilder.build());
index f54b007ed3aecdc00abd070ebc6c6d6a0d949391..46a8b6a9ae88e0c96d2930e29fba43bafd229121 100644 (file)
@@ -150,7 +150,7 @@ public class NeutronHostConfigChangeListener
                 LOG.trace("Delete Node: result: {}", result);
                 break;
             default:
-                LOG.warn("Invalid action: %s", action);
+                LOG.warn("Invalid action: {}", action);
                 break;
         }
     }
index 9e8ed751295b8b744c75b8794833ea3e20931944..bfe85571e3c644120b53c29a1947736ee734fd2f 100644 (file)
@@ -211,7 +211,7 @@ public class NeutronNetworkChangeListener
             }
             elanSegmentsBuilder.setSegmentationIndex(index);
             segments.add(elanSegmentsBuilder.build());
-            LOG.debug("Added segment {} to ELANInstance{}", segments.get((int)index - 1));
+            LOG.debug("Added segment {} to ELANInstance", segments.get((int)index - 1));
         }
         return segments;
     }
index 0c1cd469890d64f1223df93841e3e3f577869104..f8ef3167e8d39109724ef21522f3c4ebeae0bb88 100644 (file)
@@ -175,8 +175,8 @@ public class NeutronSubnetChangeListener extends AsyncDataTreeChangeListenerBase
                 if (subnetIdList.remove(subnetId)) {
                     if (subnetIdList.isEmpty()) {
                         MDSALUtil.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION, networkMapIdentifier);
-                        LOG.debug("Deleted network node in NetworkMaps DS for network {}", subnetId.getValue(),
-                                networkId.getValue());
+                        LOG.debug("Deleted network node in NetworkMaps DS for subnet {} network {}",
+                                subnetId.getValue(), networkId.getValue());
                     } else {
                         nwMapBuilder.setSubnetIdList(subnetIdList);
                         MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, networkMapIdentifier,
index 4dd0b7a3582c06fb7619bcaa58b8bb1ba0231937..001653bc78d621b1466310ffd7b2ba421bc26764 100644 (file)
@@ -34,6 +34,7 @@ import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Future;
 import java.util.concurrent.TimeUnit;
+import java.util.function.Consumer;
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 import javax.annotation.PreDestroy;
@@ -170,6 +171,8 @@ import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.slf4j.helpers.FormattingTuple;
+import org.slf4j.helpers.MessageFormatter;
 
 @Singleton
 public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, EventListener {
@@ -471,7 +474,7 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
                 }
             }
         } catch (ReadFailedException | TransactionCommitFailedException e) {
-            LOG.error("Removing a port from port list of a subnetmap failed for node: {} with expection {}",
+            LOG.error("Removing a port from port list of a subnetmap failed for node: {}",
                     subnetId.getValue(), e);
         }
         return subnetmap;
@@ -908,7 +911,7 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
                 SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION,
                             vpnIfIdentifier);
         } catch (ReadFailedException ex) {
-            LOG.error("Error during deletion of vpninterface {} have thrown {}", infName, ex);
+            LOG.error("Error during deletion of vpninterface {}", infName, ex);
             return false;
         }
         if (!optionalVpnInterface.isPresent()) {
@@ -989,8 +992,8 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
                             adjacencyIter.remove();
                         }
                         neutronvpnUtils.removeLearntVpnVipToPort(vpnId.getValue(), mipToQuery);
-                        LOG.trace("Entry for fixedIP {} for port {} on VPN removed from "
-                            + "VpnPortFixedIPToPortData", mipToQuery, infName, vpnId.getValue());
+                        LOG.trace("Entry for fixedIP {} for port {} on VPN {} removed from VpnPortFixedIPToPortData",
+                                mipToQuery, infName, vpnId.getValue());
                     }
                 }
                 List<FixedIps> ips = port.getFixedIps();
@@ -1063,8 +1066,9 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
                                 + "from VPN {}", infName, vpnId, oldVpnId);
                             adjacencyIter.remove();
                             neutronvpnUtils.removeLearntVpnVipToPort(oldVpnId.getValue(), mipToQuery);
-                            LOG.trace("Entry for fixedIP {} for port {} on VPN removed from "
-                                + "VpnPortFixedIPToPortData", mipToQuery, infName, vpnId.getValue());
+                            LOG.trace(
+                                    "Entry for fixedIP {} for port {} on VPN {} removed from VpnPortFixedIPToPortData",
+                                    mipToQuery, infName, vpnId.getValue());
                         }
                     }
                     Adjacencies adjacencies = new AdjacenciesBuilder().setAdjacency(adjacencyList).build();
@@ -1184,23 +1188,19 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
 
         List<L3vpn> vpns = input.getL3vpn();
         for (L3vpn vpn : vpns) {
-            RpcError error = null;
-            String msg;
             if (neutronvpnUtils.doesVpnExist(vpn.getId())) {
-                msg = String.format("Creation of L3VPN failed for VPN %s due to VPN with the same ID already present",
-                                vpn.getId().getValue());
-                LOG.warn(msg);
-                error = RpcResultBuilder.newWarning(ErrorType.PROTOCOL, "invalid-input", msg);
-                errorList.add(error);
+                errorList.add(RpcResultBuilder.newWarning(ErrorType.PROTOCOL, "invalid-input",
+                        formatAndLog(LOG::warn,
+                                "Creation of L3VPN failed for VPN {} due to VPN with the same ID already present",
+                                vpn.getId().getValue())));
                 warningcount++;
                 continue;
             }
             if (vpn.getRouteDistinguisher() == null || vpn.getImportRT() == null || vpn.getExportRT() == null) {
-                msg = String.format("Creation of L3VPN failed for VPN %s due to absence of RD/iRT/eRT input",
-                        vpn.getId().getValue());
-                LOG.warn(msg);
-                error = RpcResultBuilder.newWarning(ErrorType.PROTOCOL, "invalid-input", msg);
-                errorList.add(error);
+                errorList.add(RpcResultBuilder.newWarning(ErrorType.PROTOCOL, "invalid-input",
+                        formatAndLog(LOG::warn,
+                                "Creation of L3VPN failed for VPN {} due to absence of RD/iRT/eRT input",
+                                vpn.getId().getValue())));
                 warningcount++;
                 continue;
             }
@@ -1212,71 +1212,65 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
 
             List<String> existingRDs = neutronvpnUtils.getExistingRDs();
             if (existingRDs.contains(vpn.getRouteDistinguisher().get(0))) {
-                msg = String.format("Creation of L3VPN failed for VPN %s as another VPN with the same RD %s "
-                    + "is already configured",
-                    vpn.getId().getValue(), vpn.getRouteDistinguisher().get(0));
-                LOG.warn(msg);
-                error = RpcResultBuilder.newWarning(ErrorType.PROTOCOL, "invalid-input", msg);
-                errorList.add(error);
+                errorList.add(RpcResultBuilder.newWarning(ErrorType.PROTOCOL, "invalid-input",
+                        formatAndLog(LOG::warn,
+                                "Creation of L3VPN failed for VPN {} as another VPN with the same RD {} "
+                                        + "is already configured",
+                                vpn.getId().getValue(), vpn.getRouteDistinguisher().get(0))));
                 warningcount++;
                 continue;
             }
             Optional<String> operationalVpn = getExistingOperationalVpn(vpn.getRouteDistinguisher().get(0));
             if (operationalVpn.isPresent()) {
-                msg = String.format("Creation of L3VPN failed for VPN %s as another VPN %s with the same RD %s "
-                        + "is still available. Please retry creation of a new vpn with the same RD"
-                        + " after a couple of minutes.", vpn.getId().getValue(), operationalVpn.get(),
-                        vpn.getRouteDistinguisher().get(0));
-                LOG.error(msg);
-                error = RpcResultBuilder.newError(ErrorType.APPLICATION, "application-error", msg);
-                errorList.add(error);
+                errorList.add(RpcResultBuilder.newError(ErrorType.APPLICATION, "application-error",
+                        formatAndLog(LOG::error,
+                                "Creation of L3VPN failed for VPN {} as another VPN {} with the same RD {} "
+                                        + "is still available. Please retry creation of a new vpn with the same RD"
+                                        + " after a couple of minutes.", vpn.getId().getValue(), operationalVpn.get(),
+                                vpn.getRouteDistinguisher().get(0))));
                 warningcount++;
                 continue;
             }
             if (vpn.getRouterId() != null) {
                 if (neutronvpnUtils.getNeutronRouter(vpn.getRouterId()) == null) {
-                    msg = String.format("Creation of L3VPN failed for VPN %s due to router not found %s",
-                            vpn.getId().getValue(), vpn.getRouterId().getValue());
-                    LOG.warn(msg);
-                    error = RpcResultBuilder.newWarning(ErrorType.PROTOCOL, "invalid-input", msg);
-                    errorList.add(error);
+                    errorList.add(RpcResultBuilder.newWarning(ErrorType.PROTOCOL, "invalid-input",
+                            formatAndLog(LOG::warn, "Creation of L3VPN failed for VPN {} due to router not found {}",
+                                    vpn.getId().getValue(), vpn.getRouterId().getValue())));
                     warningcount++;
                     continue;
                 }
                 Uuid vpnId = neutronvpnUtils.getVpnForRouter(vpn.getRouterId(), true);
                 if (vpnId != null) {
-                    msg = String.format("Creation of L3VPN failed for VPN %s due to router %s already associated to "
-                            + "another VPN %s", vpn.getId().getValue(), vpn.getRouterId().getValue(),
-                                vpnId.getValue());
-                    LOG.warn(msg);
-                    error = RpcResultBuilder.newWarning(ErrorType.PROTOCOL, "invalid-input", msg);
-                    errorList.add(error);
+                    errorList.add(RpcResultBuilder.newWarning(ErrorType.PROTOCOL, "invalid-input",
+                            formatAndLog(LOG::warn,
+                                    "Creation of L3VPN failed for VPN {} due to router {} already associated to "
+                                            + "another VPN {}", vpn.getId().getValue(), vpn.getRouterId().getValue(),
+                                    vpnId.getValue())));
                     warningcount++;
                     continue;
                 }
             }
             if (vpn.getNetworkIds() != null) {
+                int initialWarningCount = warningcount;
                 for (Uuid nw : vpn.getNetworkIds()) {
                     Network network = neutronvpnUtils.getNeutronNetwork(nw);
                     Uuid vpnId = neutronvpnUtils.getVpnForNetwork(nw);
                     if (network == null) {
-                        msg = String.format("Creation of L3VPN failed for VPN %s due to network not found %s",
-                                vpn.getId().getValue(), nw.getValue());
-                        LOG.warn(msg);
-                        error = RpcResultBuilder.newWarning(ErrorType.PROTOCOL, "invalid-input", msg);
-                        errorList.add(error);
+                        errorList.add(RpcResultBuilder.newWarning(ErrorType.PROTOCOL, "invalid-input",
+                                formatAndLog(LOG::warn,
+                                        "Creation of L3VPN failed for VPN {} due to network not found {}",
+                                        vpn.getId().getValue(), nw.getValue())));
                         warningcount++;
                     } else if (vpnId != null) {
-                        msg = String.format("Creation of L3VPN failed for VPN %s due to network %s already associated"
-                                        + " to another VPN %s", vpn.getId().getValue(), nw.getValue(),
-                                vpnId.getValue());
-                        LOG.warn(msg);
-                        error = RpcResultBuilder.newWarning(ErrorType.PROTOCOL, "invalid-input", msg);
-                        errorList.add(error);
+                        errorList.add(RpcResultBuilder.newWarning(ErrorType.PROTOCOL, "invalid-input",
+                                formatAndLog(LOG::warn,
+                                        "Creation of L3VPN failed for VPN {} due to network {} already associated"
+                                                + " to another VPN {}", vpn.getId().getValue(), nw.getValue(),
+                                        vpnId.getValue())));
                         warningcount++;
                     }
                 }
-                if (error != null) {
+                if (warningcount != initialWarningCount) {
                     continue;
                 }
             }
@@ -1285,10 +1279,9 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
                         vpn.getImportRT(), vpn.getExportRT(), vpn.getRouterId(), vpn.getNetworkIds(),
                         vpnInstanceType, l3vni);
             } catch (Exception ex) {
-                msg = String.format("Creation of VPN failed for VPN %s", vpn.getId().getValue());
-                LOG.error(msg, ex);
-                error = RpcResultBuilder.newError(ErrorType.APPLICATION, msg, ex.getMessage());
-                errorList.add(error);
+                errorList.add(RpcResultBuilder.newError(ErrorType.APPLICATION,
+                        formatAndLog(LOG::error, "Creation of VPN failed for VPN {}", vpn.getId().getValue(), ex),
+                        ex.getMessage()));
                 failurecount++;
             }
         }
@@ -1300,9 +1293,8 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
             List<String> errorResponseList = new ArrayList<>();
             if (!errorList.isEmpty()) {
                 for (RpcError rpcError : errorList) {
-                    String errorResponse = String.format("ErrorType: %s, ErrorTag: %s, ErrorMessage: %s", rpcError
-                            .getErrorType(), rpcError.getTag(), rpcError.getMessage());
-                    errorResponseList.add(errorResponse);
+                    errorResponseList.add("ErrorType: " + rpcError.getErrorType() + ", ErrorTag: " + rpcError.getTag()
+                            + ", ErrorMessage: " + rpcError.getMessage());
                 }
             } else {
                 errorResponseList.add("Operation successful with no errors");
@@ -1360,10 +1352,10 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
                 if (optionalVpn.isPresent() && optionalVpn.get().getIpv4Family().getRouteDistinguisher() != null) {
                     vpns.add(optionalVpn.get());
                 } else {
-                    String message = String.format("GetL3VPN failed because VPN %s is not present", name);
-                    LOG.error(message);
-                    result.set(RpcResultBuilder.<GetL3VPNOutput>failed().withWarning(ErrorType.PROTOCOL,
-                            "invalid-value", message).build());
+                    result.set(
+                            RpcResultBuilder.<GetL3VPNOutput>failed().withWarning(ErrorType.PROTOCOL, "invalid-value",
+                                    formatAndLog(LOG::error, "GetL3VPN failed because VPN {} is not present",
+                                            name)).build());
                 }
             }
             for (VpnInstance vpnInstance : vpns) {
@@ -1412,9 +1404,8 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
             result.set(RpcResultBuilder.<GetL3VPNOutput>success().withResult(opBuilder.build()).build());
 
         } catch (ReadFailedException ex) {
-            String message = String.format("GetVPN failed due to %s", ex.getMessage());
-            LOG.error(message, ex);
-            result.set(RpcResultBuilder.<GetL3VPNOutput>failed().withError(ErrorType.APPLICATION, message).build());
+            result.set(RpcResultBuilder.<GetL3VPNOutput>failed().withError(ErrorType.APPLICATION,
+                    formatAndLog(LOG::error, "GetVPN failed due to {}", ex.getMessage())).build());
         }
         return result;
     }
@@ -1445,17 +1436,14 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
                 if (optionalVpn.isPresent()) {
                     removeVpn(vpn);
                 } else {
-                    msg = String.format("VPN with vpnid: %s does not exist", vpn.getValue());
-                    LOG.warn(msg);
-                    error = RpcResultBuilder.newWarning(ErrorType.PROTOCOL, "invalid-value", msg);
-                    errorList.add(error);
+                    errorList.add(RpcResultBuilder.newWarning(ErrorType.PROTOCOL, "invalid-value",
+                            formatAndLog(LOG::warn, "VPN with vpnid: {} does not exist", vpn.getValue())));
                     warningcount++;
                 }
             } catch (ReadFailedException ex) {
-                msg = String.format("Deletion of L3VPN failed when deleting for uuid %s", vpn.getValue());
-                LOG.error(msg, ex);
-                error = RpcResultBuilder.newError(ErrorType.APPLICATION, msg, ex.getMessage());
-                errorList.add(error);
+                errorList.add(RpcResultBuilder.newError(ErrorType.APPLICATION,
+                        formatAndLog(LOG::error, "Deletion of L3VPN failed when deleting for uuid {}", vpn.getValue()),
+                        ex.getMessage()));
                 failurecount++;
             }
         }
@@ -1467,9 +1455,8 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
             List<String> errorResponseList = new ArrayList<>();
             if (!errorList.isEmpty()) {
                 for (RpcError rpcError : errorList) {
-                    String errorResponse = String.format("ErrorType: %s, ErrorTag: %s, ErrorMessage: %s", rpcError
-                            .getErrorType(), rpcError.getTag(), rpcError.getMessage());
-                    errorResponseList.add(errorResponse);
+                    errorResponseList.add("ErrorType: " + rpcError.getErrorType() + ", ErrorTag: " + rpcError.getTag()
+                            + ", ErrorMessage: " + rpcError.getMessage());
                 }
             } else {
                 errorResponseList.add("Operation successful with no errors");
@@ -1697,7 +1684,7 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
                 oldVpnId.getValue(), newVpnId.getValue());
         Uuid networkUuid = neutronvpnUtils.getSubnetmap(subnet).getNetworkId();
         Network network = neutronvpnUtils.getNeutronNetwork(networkUuid);
-        boolean netIsExternal = neutronvpnUtils.getIsExternal(network);
+        boolean netIsExternal = NeutronvpnUtils.getIsExternal(network);
         Uuid vpnExtUuid = netIsExternal ? null
                 : neutronvpnUtils.getInternetvpnUuidBoundToSubnetRouter(subnet);
         Subnetmap sn = updateSubnetNode(subnet, null, newVpnId, vpnExtUuid);
@@ -2184,7 +2171,7 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
             Subnetmap sn = updateVpnForSubnet(routerId, vpnId, subnetId, true);
             if (neutronvpnUtils.shouldVpnHandleIpVersionChangeToAdd(sn, vpnId)) {
                 neutronvpnUtils.updateVpnInstanceWithIpFamily(vpnId.getValue(),
-                          neutronvpnUtils.getIpVersionFromString(sn.getSubnetIp()), true);
+                          NeutronvpnUtils.getIpVersionFromString(sn.getSubnetIp()), true);
             }
         }
 
@@ -2203,7 +2190,7 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
         Uuid internetVpnId = neutronvpnUtils.getInternetvpnUuidBoundToRouterId(routerId);
         LOG.debug("Adding subnets to internal vpn {}", vpnId.getValue());
         for (Uuid subnet : routerSubnets) {
-            IpVersionChoice version = neutronvpnUtils
+            IpVersionChoice version = NeutronvpnUtils
                    .getIpVersionFromSubnet(neutronvpnUtils.getSubnetmap(subnet));
             if (version.isIpVersionChosen(IpVersionChoice.IPV4)) {
                 addSubnetToVpn(vpnId, subnet, null);
@@ -2252,32 +2239,30 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
         if (!networks.isEmpty()) {
             VpnInstance vpnInstance = VpnHelper.getVpnInstance(dataBroker, vpn.getValue());
             if (vpnInstance == null) {
-                LOG.error("VPN %s not present when associating network to it", vpn.getValue());
-                failedNwList.add(String.format("Failed to associate network on vpn %s as vpn is not present",
-                        vpn.getValue()));
-                return failedNwList;
+                return Collections.singletonList(
+                        formatAndLog(LOG::error, "Failed to associate network on vpn {} as vpn is not present",
+                                vpn.getValue()));
             }
             // process corresponding subnets for VPN
             for (Uuid nw : networks) {
                 Network network = neutronvpnUtils.getNeutronNetwork(nw);
                 if (network == null) {
-                    failedNwList.add(String.format("network %s not found", nw.getValue()));
+                    failedNwList.add("network " + nw.getValue() + " not found");
                     continue;
                 }
 
                 NetworkProviderExtension providerExtension = network.getAugmentation(NetworkProviderExtension.class);
                 if (providerExtension.getSegments() != null && providerExtension.getSegments().size() > 1) {
-                    LOG.error("MultiSegmented networks not supported in VPN. Failed to associate network {} on vpn {}",
-                            nw.getValue(), vpn.getValue());
-                    failedNwList.add(String.format("Failed to associate network %s on vpn %s as it is multisegmented.",
-                            nw.getValue(), vpn.getValue()));
+                    failedNwList.add(formatAndLog(LOG::error,
+                            "Failed to associate network {} on vpn {} as it is multisegmented.", nw.getValue(),
+                            vpn.getValue()));
                     continue;
                 }
                 try {
                     Uuid vpnId = neutronvpnUtils.getVpnForNetwork(nw);
                     if (vpnId != null) {
-                        failedNwList.add(String.format("network %s already associated to another VPN %s", nw.getValue(),
-                                vpnId.getValue()));
+                        failedNwList.add(
+                                "network " + nw.getValue() + " already associated to another VPN " + vpnId.getValue());
                     } else if (isVpnOfTypeL2(vpnInstance)
                             && neutronEvpnUtils.isVpnAssociatedWithNetwork(vpnInstance)) {
                         LOG.error("EVPN supports only one network to be associated");
@@ -2300,7 +2285,7 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
                                                             sn.getInternetVpnId())) {
                                             neutronvpnUtils.updateVpnInstanceWithIpFamily(sn
                                                             .getInternetVpnId().getValue(),
-                                                   neutronvpnUtils.getIpVersionFromString(sn
+                                                   NeutronvpnUtils.getIpVersionFromString(sn
                                                             .getSubnetIp()), true);
                                             neutronvpnUtils.updateVpnInstanceWithFallback(
                                                           sn.getInternetVpnId().getValue(), true);
@@ -2309,14 +2294,13 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
                                     addSubnetToVpn(vpn, subnet, sn != null ? sn.getInternetVpnId() : null);
                                     passedNwList.add(nw);
                                 } else {
-                                    failedNwList.add(
-                                            String.format("subnet %s already added as router interface bound to "
-                                                            + "internal/external VPN %s", subnet.getValue(),
-                                                    subnetVpnId.getValue()));
+                                    failedNwList.add("subnet " + subnet.getValue()
+                                            + " already added as router interface bound to internal/external VPN "
+                                            + subnetVpnId.getValue());
                                 }
                             }
                         }
-                        if (neutronvpnUtils.getIsExternal(network)) {
+                        if (NeutronvpnUtils.getIsExternal(network)) {
                             VpnMap vpnMap = neutronvpnUtils.getVpnMap(vpn);
                             if (vpnMap == null) {
                                 LOG.error("associateNetworksToVpn: external network assoc to vpnId {}"
@@ -2336,7 +2320,7 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
                                         updateVpnInternetForSubnet(sm, vpn, true);
                                         if (neutronvpnUtils.shouldVpnHandleIpVersionChangeToAdd(sm, vpn)) {
                                             neutronvpnUtils.updateVpnInstanceWithIpFamily(vpn.getValue(),
-                                                    neutronvpnUtils.getIpVersionFromString(sm.getSubnetIp()), true);
+                                                    NeutronvpnUtils.getIpVersionFromString(sm.getSubnetIp()), true);
                                             neutronvpnUtils.updateVpnInstanceWithFallback(vpn.getValue(),
                                                     true);
                                         }
@@ -2349,8 +2333,9 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
                         }
                     }
                 } catch (ReadFailedException e) {
-                    LOG.error("Error determining whether {} is associated", vpnInstance, e);
-                    failedNwList.add("Error determining whether VPN " + vpn.getValue() + " is associated");
+                    failedNwList.add(
+                            formatAndLog(LOG::error, "Error determining whether VPN {} is associated", vpn.getValue(),
+                                    e));
                 }
             }
             updateVpnMaps(vpn, null, null, null, passedNwList);
@@ -2366,7 +2351,7 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
             for (Uuid nw : networks) {
                 Network network = neutronvpnUtils.getNeutronNetwork(nw);
                 if (network == null) {
-                    failedNwList.add(String.format("network %s not found", nw.getValue()));
+                    failedNwList.add("network " + nw.getValue() + " not found");
                 } else {
                     Uuid vpnId = neutronvpnUtils.getVpnForNetwork(nw);
                     if (vpn.equals(vpnId)) {
@@ -2381,7 +2366,7 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
                                 Subnetmap sn = neutronvpnUtils.getSubnetmap(subnet);
                                 if (neutronvpnUtils.shouldVpnHandleIpVersionChangeToRemove(sn, vpn)) {
                                     vpnInstanceIpVersionsToRemove = vpnInstanceIpVersionsToRemove.addVersion(
-                                            neutronvpnUtils.getIpVersionFromString(sn.getSubnetIp()));
+                                            NeutronvpnUtils.getIpVersionFromString(sn.getSubnetIp()));
                                     vpnInstanceIpVersionsRemoved = true;
                                 }
                                 if (sn.getInternetVpnId() != null
@@ -2404,7 +2389,7 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
                                                    IpVersionChoice.IPV6, false);
                             }
                         }
-                        if (neutronvpnUtils.getIsExternal(network)) {
+                        if (NeutronvpnUtils.getIsExternal(network)) {
                             neutronvpnUtils.updateVpnInstanceWithFallback(vpn.getValue(),
                                                     false);
                             neutronvpnUtils.updateVpnInstanceOpWithType(VpnInstanceOpDataEntry
@@ -2430,11 +2415,10 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
                         }
                     } else {
                         if (vpnId == null) {
-                            failedNwList.add(String.format("input network %s not associated to any vpn yet", nw
-                                    .getValue()));
+                            failedNwList.add("input network " + nw.getValue() + " not associated to any vpn yet");
                         } else {
-                            failedNwList.add(String.format("input network %s associated to a another vpn %s instead "
-                                + "of the one given as input", nw.getValue(), vpnId.getValue()));
+                            failedNwList.add("input network " + nw.getValue() + " associated to a another vpn "
+                                    + vpnId.getValue() + " instead of the one given as input");
                         }
                     }
                     if (NeutronvpnUtils.getIsExternal(network)) {
@@ -2474,22 +2458,17 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
                 returnMsg.append("VPN not found : ").append(vpnId.getValue());
             }
             if (returnMsg.length() != 0) {
-                String message = String.format("associate Networks to vpn %s failed due to %s",
-                        vpnId.getValue(), returnMsg);
-                LOG.error(message);
-                String errorResponse = String.format("ErrorType: PROTOCOL, ErrorTag: invalid-value, ErrorMessage: %s",
-                        message);
-                opBuilder.setResponse(errorResponse);
+                opBuilder.setResponse(
+                        "ErrorType: PROTOCOL, ErrorTag: invalid-value, ErrorMessage: " + formatAndLog(LOG::error,
+                                "associate Networks to vpn {} failed due to {}", vpnId.getValue(), returnMsg));
                 result.set(RpcResultBuilder.<AssociateNetworksOutput>success().withResult(opBuilder.build()).build());
             } else {
                 result.set(RpcResultBuilder.<AssociateNetworksOutput>success().build());
             }
         } catch (Exception ex) {
-            String message = String.format("associate Networks to vpn %s failed due to %s",
-                    input.getVpnId().getValue(), ex.getMessage());
-            LOG.error(message, ex);
-            result.set(RpcResultBuilder.<AssociateNetworksOutput>failed().withError(ErrorType.APPLICATION, message)
-                    .build());
+            result.set(RpcResultBuilder.<AssociateNetworksOutput>failed().withError(ErrorType.APPLICATION,
+                    formatAndLog(LOG::error, "associate Networks to vpn {} failed due to {}",
+                            input.getVpnId().getValue(), ex.getMessage(), ex)).build());
         }
         LOG.debug("associateNetworks returns..");
         return result;
@@ -2530,19 +2509,16 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
                 returnMsg.append("VPN not found : ").append(vpnId.getValue());
             }
             if (returnMsg.length() != 0) {
-                String message = String.format("associate router to vpn %s failed due to %s", routerId.getValue(),
-                        returnMsg);
-                LOG.error(message);
-                result.set(RpcResultBuilder.<Void>failed().withWarning(ErrorType.PROTOCOL, "invalid-value", message)
-                        .build());
+                result.set(RpcResultBuilder.<Void>failed().withWarning(ErrorType.PROTOCOL, "invalid-value",
+                        formatAndLog(LOG::error, "associate router to vpn {} failed due to {}", routerId.getValue(),
+                                returnMsg)).build());
             } else {
                 result.set(RpcResultBuilder.<Void>success().build());
             }
         } catch (Exception ex) {
-            String message = String.format("associate router %s to vpn %s failed due to %s", routerId.getValue(),
-                    vpnId.getValue(), ex.getMessage());
-            LOG.error(message, ex);
-            result.set(RpcResultBuilder.<Void>failed().withError(ErrorType.APPLICATION, message).build());
+            result.set(RpcResultBuilder.<Void>failed().withError(ErrorType.APPLICATION,
+                    formatAndLog(LOG::error, "associate router {} to vpn {} failed due to {}", routerId.getValue(),
+                            vpnId.getValue(), ex.getMessage(), ex)).build());
         }
         LOG.debug("associateRouter returns..");
         return result;
@@ -2571,10 +2547,10 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
                 returnMsg.append("neutron port: ").append(portId.getValue()).append(" not found");
             }
             if (returnMsg.length() != 0) {
-                String message = String.format("Retrieval of FixedIPList for neutron port failed due to %s", returnMsg);
-                LOG.error(message);
-                result.set(RpcResultBuilder.<GetFixedIPsForNeutronPortOutput>failed()
-                        .withWarning(ErrorType.PROTOCOL, "invalid-value", message).build());
+                result.set(RpcResultBuilder.<GetFixedIPsForNeutronPortOutput>failed().withWarning(ErrorType.PROTOCOL,
+                        "invalid-value",
+                        formatAndLog(LOG::error, "Retrieval of FixedIPList for neutron port failed due to {}",
+                                returnMsg)).build());
             } else {
                 opBuilder.setFixedIPs(fixedIPList);
                 result.set(RpcResultBuilder.<GetFixedIPsForNeutronPortOutput>success().withResult(opBuilder.build())
@@ -2582,11 +2558,9 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
                 result.set(RpcResultBuilder.<GetFixedIPsForNeutronPortOutput>success().build());
             }
         } catch (Exception ex) {
-            String message = String.format("Retrieval of FixedIPList for neutron port %s failed due to %s",
-                    portId.getValue(), ex.getMessage());
-            LOG.error(message, ex);
-            result.set(RpcResultBuilder.<GetFixedIPsForNeutronPortOutput>failed()
-                    .withError(ErrorType.APPLICATION, message).build());
+            result.set(RpcResultBuilder.<GetFixedIPsForNeutronPortOutput>failed().withError(ErrorType.APPLICATION,
+                    formatAndLog(LOG::error, "Retrieval of FixedIPList for neutron port {} failed due to {}",
+                            portId.getValue(), ex.getMessage(), ex)).build());
         }
         return result;
     }
@@ -2619,22 +2593,17 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
                 returnMsg.append("VPN not found : ").append(vpnId.getValue());
             }
             if (returnMsg.length() != 0) {
-                String message = String.format("dissociate Networks to vpn %s failed due to %s", vpnId.getValue(),
-                        returnMsg);
-                LOG.error(message);
-                String errorResponse = String.format("ErrorType: PROTOCOL, ErrorTag: invalid-value, ErrorMessage: "
-                        + message);
-                opBuilder.setResponse(errorResponse);
+                opBuilder.setResponse(
+                        "ErrorType: PROTOCOL, ErrorTag: invalid-value, ErrorMessage: " + formatAndLog(LOG::error,
+                                "dissociate Networks to vpn {} failed due to {}", vpnId.getValue(), returnMsg));
                 result.set(RpcResultBuilder.<DissociateNetworksOutput>success().withResult(opBuilder.build()).build());
             } else {
                 result.set(RpcResultBuilder.<DissociateNetworksOutput>success().build());
             }
         } catch (Exception ex) {
-            String message = String.format("dissociate Networks to vpn %s failed due to %s",
-                    input.getVpnId().getValue(), ex.getMessage());
-            LOG.error(message, ex);
-            result.set(RpcResultBuilder.<DissociateNetworksOutput>failed().withError(ErrorType.APPLICATION, message)
-                    .build());
+            result.set(RpcResultBuilder.<DissociateNetworksOutput>failed().withError(ErrorType.APPLICATION,
+                    formatAndLog(LOG::error, "dissociate Networks to vpn {} failed due to {}",
+                            input.getVpnId().getValue(), ex.getMessage(), ex)).build());
         }
         LOG.debug("dissociateNetworks returns..");
         return result;
@@ -2680,19 +2649,16 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
                 returnMsg.append("VPN not found : ").append(vpnId.getValue());
             }
             if (returnMsg.length() != 0) {
-                String message = String.format("dissociate router %s to vpn %s failed due to %s", routerId.getValue(),
-                        vpnId.getValue(), returnMsg);
-                LOG.error(message);
-                result.set(RpcResultBuilder.<Void>failed().withWarning(ErrorType.PROTOCOL, "invalid-value", message)
-                        .build());
+                result.set(RpcResultBuilder.<Void>failed().withWarning(ErrorType.PROTOCOL, "invalid-value",
+                        formatAndLog(LOG::error, "dissociate router {} to vpn {} failed due to {}", routerId.getValue(),
+                                vpnId.getValue(), returnMsg)).build());
             } else {
                 result.set(RpcResultBuilder.<Void>success().build());
             }
         } catch (Exception ex) {
-            String message = String.format("disssociate router %s to vpn %s failed due to %s", routerId.getValue(),
-                    vpnId.getValue(), ex.getMessage());
-            LOG.error(message, ex);
-            result.set(RpcResultBuilder.<Void>failed().withError(ErrorType.APPLICATION, message).build());
+            result.set(RpcResultBuilder.<Void>failed().withError(ErrorType.APPLICATION,
+                    formatAndLog(LOG::error, "disssociate router {} to vpn {} failed due to {}", routerId.getValue(),
+                            vpnId.getValue(), ex.getMessage(), ex)).build());
         }
         LOG.debug("dissociateRouter returns..");
 
@@ -3138,4 +3104,22 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
         }
         return existingVpnName;
     }
+
+    private String formatAndLog(Consumer<String> logger, String template, Object arg) {
+        return logAndReturnMessage(logger, MessageFormatter.format(template, arg));
+    }
+
+    private String formatAndLog(Consumer<String> logger, String template, Object arg1, Object arg2) {
+        return logAndReturnMessage(logger, MessageFormatter.format(template, arg1, arg2));
+    }
+
+    private String formatAndLog(Consumer<String> logger, String template, Object... args) {
+        return logAndReturnMessage(logger, MessageFormatter.arrayFormat(template, args));
+    }
+
+    private String logAndReturnMessage(Consumer<String> logger, FormattingTuple tuple) {
+        String message = tuple.getMessage();
+        logger.accept(message);
+        return message;
+    }
 }
index bd6e8a1d10a45a309e5758f28f7a683f14b2fb98..edfe2afacfe18c0ab74b3d1c2b65f64dc783adb2 100644 (file)
@@ -89,7 +89,7 @@ public class NeutronvpnNatManager implements AutoCloseable {
         if (extNetChanged != EXTERNAL_NO_CHANGE) {
             if (extNetChanged == EXTERNAL_ADDED) {
                 updExtNetId = update.getExternalGatewayInfo().getExternalNetworkId();
-                LOG.trace("External Network {} addition detected for router", updExtNetId.getValue(),
+                LOG.trace("External Network {} addition detected for router {}", updExtNetId.getValue(),
                         routerId.getValue());
                 addExternalNetworkToRouter(update);
                 return;
@@ -678,8 +678,7 @@ public class NeutronvpnNatManager implements AutoCloseable {
 
             if (subnets.getExternalNetworkId() != null
                     && subnets.getExternalNetworkId().equals(networkId) && !routerIds.contains(routerId)) {
-                LOG.debug("Will add routerID {} for external subnet.",
-                        routerId, subnetId);
+                LOG.debug("Will add routerID {} for external subnet {}.", routerId, subnetId);
                 routerIds.add(routerId);
                 updateExternalSubnet(networkId, subnetId, routerIds);
             }
@@ -724,7 +723,7 @@ public class NeutronvpnNatManager implements AutoCloseable {
                         && routerIds.contains(routerId)) {
                     routerIds.remove(routerId);
                     LOG.debug("Will remove routerIDs {} from external subnet {} router ID {}",
-                        subnetId, routerId);
+                        routerIds, subnetId, routerId);
                     addExternalSubnet(externalNetworkId, subnetId, routerIds);
                 }
             }
index 1fa27868d7e092db85b035b8af72b17bef15a2e2..3af9c815b040d04b4e51953700507394f749d746 100644 (file)
@@ -1159,7 +1159,7 @@ public class NeutronvpnUtils {
             Future<RpcResult<Void>> result = idManager.releaseId(idInput);
             RpcResult<Void> rpcResult = result.get();
             if (!rpcResult.isSuccessful()) {
-                LOG.error("RPC Call to Get Unique Id returned with errors for poolname {} and ID Key {}",
+                LOG.error("RPC Call to Get Unique Id returned with errors for poolname {} and ID Key {}: {}",
                         poolName, idKey, rpcResult.getErrors());
             } else {
                 LOG.info("ID {} for RD released successfully", idKey);
@@ -1408,21 +1408,21 @@ public class NeutronvpnUtils {
             return false;
         }
         if (vpnInstanceOpDataEntry.getType() == VpnInstanceOpDataEntry.Type.L2) {
-            LOG.error("shouldVpnHandleIpVersionChangeToAdd: "
+            LOG.error("shouldVpnHandleIpVersionChangeToAdd: {} "
                     + "VpnInstanceOpDataEntry is L2 instance. Do nothing.", vpnId.getValue());
             return false;
         }
         boolean isIpv4Configured = vpnInstanceOpDataEntry.isIpv4Configured();
         boolean isVpnInstanceIpv4Changed = false;
-        if (ipVersion.isIpVersionChosen(IpVersionChoice.IPV4) && isIpv4Configured == false) {
+        if (ipVersion.isIpVersionChosen(IpVersionChoice.IPV4) && !isIpv4Configured) {
             isVpnInstanceIpv4Changed = true;
         }
         boolean isIpv6Configured = vpnInstanceOpDataEntry.isIpv6Configured();
         boolean isVpnInstanceIpv6Changed = false;
-        if (ipVersion.isIpVersionChosen(IpVersionChoice.IPV6) && isIpv6Configured == false) {
+        if (ipVersion.isIpVersionChosen(IpVersionChoice.IPV6) && !isIpv6Configured) {
             isVpnInstanceIpv6Changed = true;
         }
-        if (isVpnInstanceIpv4Changed == false && isVpnInstanceIpv6Changed == false) {
+        if (!isVpnInstanceIpv4Changed && !isVpnInstanceIpv6Changed) {
             LOG.debug("shouldVpnHandleIpVersionChangeToAdd: VPN {} did not change with IpFamily {}",
                   vpnId.getValue(), ipVersion.toString());
             return false;
@@ -1487,7 +1487,7 @@ public class NeutronvpnUtils {
                             new VpnInstanceOpDataEntryKey(vpnInstanceOpDataEntry.getVrfId())).build();
             writeTxn.merge(LogicalDatastoreType.OPERATIONAL, id, builder.build(), false);
             LOG.info("updateVpnInstanceWithIpFamily: Successfully {} {} to Vpn {}",
-                    add == true ? "added" : "removed",
+                    add ? "added" : "removed",
                     ipVersion.toString(), vpnName);
             return Collections.singletonList(writeTxn.submit());
         });
index c452fa1facc284838cccd4ffcedba635f87fa963..c5ec9a1c5ef2fae78ebe32ad13483e70c942848d 100644 (file)
@@ -12,6 +12,7 @@ import com.google.common.util.concurrent.SettableFuture;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.concurrent.Future;
+import java.util.function.Consumer;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
@@ -43,6 +44,8 @@ import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.slf4j.helpers.FormattingTuple;
+import org.slf4j.helpers.MessageFormatter;
 
 
 public class NeutronEvpnManager {
@@ -70,31 +73,26 @@ public class NeutronEvpnManager {
         List<Evpn> vpns = input.getEvpn();
         for (Evpn vpn : vpns) {
             if (vpn.getRouteDistinguisher() == null || vpn.getImportRT() == null || vpn.getExportRT() == null) {
-                String msg = String.format("Creation of EVPN failed for VPN %s due to absence of RD/iRT/eRT input",
-                        vpn.getId().getValue());
-                LOG.warn(msg);
-                RpcError error = RpcResultBuilder.newWarning(RpcError.ErrorType.PROTOCOL, "invalid-input", msg);
-                errorList.add(error);
+                errorList.add(RpcResultBuilder.newWarning(RpcError.ErrorType.PROTOCOL, "invalid-input",
+                        formatAndLog(LOG::warn, "Creation of EVPN failed for VPN {} due to absence of RD/iRT/eRT input",
+                                vpn.getId().getValue())));
                 warningcount++;
                 continue;
             }
             VpnInstance.Type vpnInstanceType = VpnInstance.Type.L2;
             if (vpn.getRouteDistinguisher().size() > 1) {
-                String msg = String.format("Creation of EVPN failed for VPN %s due to multiple RD input %s",
-                        vpn.getId().getValue(), vpn.getRouteDistinguisher());
-                LOG.warn(msg);
-                RpcError error = RpcResultBuilder.newWarning(RpcError.ErrorType.PROTOCOL, "invalid-input", msg);
-                errorList.add(error);
+                errorList.add(RpcResultBuilder.newWarning(RpcError.ErrorType.PROTOCOL, "invalid-input",
+                        formatAndLog(LOG::warn, "Creation of EVPN failed for VPN {} due to multiple RD input {}",
+                                vpn.getId().getValue(), vpn.getRouteDistinguisher())));
                 warningcount++;
                 continue;
             }
             if (existingRDs.contains(vpn.getRouteDistinguisher().get(0))) {
-                String msg = String.format("Creation of EVPN failed for VPN %s as another VPN with "
-                        + "the same RD %s is already configured",
-                        vpn.getId().getValue(), vpn.getRouteDistinguisher().get(0));
-                LOG.warn(msg);
-                RpcError error = RpcResultBuilder.newWarning(RpcError.ErrorType.PROTOCOL, "invalid-input", msg);
-                errorList.add(error);
+                errorList.add(RpcResultBuilder.newWarning(RpcError.ErrorType.PROTOCOL, "invalid-input",
+                        formatAndLog(LOG::warn,
+                                "Creation of EVPN failed for VPN {} as another VPN with the same RD {} is already "
+                                        + "configured",
+                                vpn.getId().getValue(), vpn.getRouteDistinguisher().get(0))));
                 warningcount++;
                 continue;
             }
@@ -103,10 +101,9 @@ public class NeutronEvpnManager {
                         vpn.getImportRT(), vpn.getExportRT(), null /*router-id*/, null /*network-id*/,
                         vpnInstanceType, 0 /*l2vni*/);
             } catch (Exception ex) {
-                String msg = String.format("Creation of EVPN failed for VPN %s", vpn.getId().getValue());
-                LOG.error(msg, ex);
-                RpcError error = RpcResultBuilder.newError(RpcError.ErrorType.APPLICATION, msg, ex.getMessage());
-                errorList.add(error);
+                errorList.add(RpcResultBuilder.newError(RpcError.ErrorType.APPLICATION,
+                        formatAndLog(LOG::error, "Creation of EVPN failed for VPN {}", vpn.getId().getValue(), ex),
+                        ex.getMessage()));
                 failurecount++;
             }
         }
@@ -116,9 +113,8 @@ public class NeutronEvpnManager {
             List<String> errorResponseList = new ArrayList<>();
             if (!errorList.isEmpty()) {
                 for (RpcError rpcError : errorList) {
-                    String errorResponse = String.format("ErrorType: %s, ErrorTag: %s, ErrorMessage: %s", rpcError
-                            .getErrorType(), rpcError.getTag(), rpcError.getMessage());
-                    errorResponseList.add(errorResponse);
+                    errorResponseList.add("ErrorType: " + rpcError.getErrorType() + ", ErrorTag: " + rpcError.getTag()
+                            + ", ErrorMessage: " + rpcError.getMessage());
                 }
             } else {
                 errorResponseList.add("EVPN creation successful with no errors");
@@ -155,10 +151,9 @@ public class NeutronEvpnManager {
                     && vpnInstance.getType() == VpnInstance.Type.L2) {
                 vpns.add(vpnInstance);
             } else {
-                String message = String.format("GetEVPN failed because VPN %s is not present", name);
-                LOG.error(message);
                 result.set(RpcResultBuilder.<GetEVPNOutput>failed().withWarning(RpcError.ErrorType.PROTOCOL,
-                        "invalid-value", message).build());
+                        "invalid-value",
+                        formatAndLog(LOG::error, "GetEVPN failed because VPN {} is not present", name)).build());
             }
         }
         List<EvpnInstances> evpnList = new ArrayList<>();
@@ -221,10 +216,8 @@ public class NeutronEvpnManager {
             if (vpnInstance != null) {
                 neutronvpnManager.removeVpn(vpn);
             } else {
-                msg = String.format("EVPN with vpnid: %s does not exist", vpn.getValue());
-                LOG.warn(msg);
-                error = RpcResultBuilder.newWarning(RpcError.ErrorType.PROTOCOL, "invalid-value", msg);
-                errorList.add(error);
+                errorList.add(RpcResultBuilder.newWarning(RpcError.ErrorType.PROTOCOL, "invalid-value",
+                        formatAndLog(LOG::warn, "EVPN with vpnid: {} does not exist", vpn.getValue())));
                 warningcount++;
             }
         }
@@ -234,9 +227,8 @@ public class NeutronEvpnManager {
             List<String> errorResponseList = new ArrayList<>();
             if (!errorList.isEmpty()) {
                 for (RpcError rpcError : errorList) {
-                    String errorResponse = String.format("ErrorType: %s, ErrorTag: %s, ErrorMessage: %s", rpcError
-                            .getErrorType(), rpcError.getTag(), rpcError.getMessage());
-                    errorResponseList.add(errorResponse);
+                    errorResponseList.add("ErrorType: " + rpcError.getErrorType() + ", ErrorTag: " + rpcError.getTag()
+                            + ", ErrorMessage: " + rpcError.getMessage());
                 }
             } else {
                 errorResponseList.add("Deletion of EVPN operation successful");
@@ -246,4 +238,18 @@ public class NeutronEvpnManager {
         }
         return result;
     }
+
+    private String formatAndLog(Consumer<String> logger, String template, Object arg) {
+        return logAndReturnMessage(logger, MessageFormatter.format(template, arg));
+    }
+
+    private String formatAndLog(Consumer<String> logger, String template, Object arg1, Object arg2) {
+        return logAndReturnMessage(logger, MessageFormatter.format(template, arg1, arg2));
+    }
+
+    private String logAndReturnMessage(Consumer<String> logger, FormattingTuple tuple) {
+        String message = tuple.getMessage();
+        logger.accept(message);
+        return message;
+    }
 }
index 35f36f12f2c3aea3a49271e8cb6e5b9dc6a46f44..7392ff4b2c841076024790e26e37ed26338e6b16 100644 (file)
@@ -51,7 +51,7 @@ public final class L2GatewayUtils {
             if (rpcResult.isSuccessful()) {
                 LOG.info("Created ITM tunnels for {}", hwvtepId);
             } else {
-                LOG.error("Failed to create ITM Tunnels: ", rpcResult.getErrors());
+                LOG.error("Failed to create ITM Tunnels: {}", rpcResult.getErrors());
             }
         } catch (InterruptedException | ExecutionException e) {
             LOG.error("RPC to create ITM tunnels failed", e);
@@ -70,7 +70,7 @@ public final class L2GatewayUtils {
             if (rpcResult.isSuccessful()) {
                 LOG.info("Deleted ITM tunnels for {}", hwvtepId);
             } else {
-                LOG.error("Failed to delete ITM Tunnels: ", rpcResult.getErrors());
+                LOG.error("Failed to delete ITM Tunnels: {}", rpcResult.getErrors());
             }
         } catch (InterruptedException | ExecutionException e) {
             LOG.error("RPC to delete ITM tunnels failed", e);