Refactor OpenVSwitchUpdateCommand to improve readability. 01/20301/1
authorEd Warnicke <hagbard@gmail.com>
Wed, 13 May 2015 22:20:43 +0000 (15:20 -0700)
committerEd Warnicke <hagbard@gmail.com>
Wed, 13 May 2015 22:20:43 +0000 (15:20 -0700)
Note:  This is *only* extracting methods so we can keep track
of what we are doing.

Change-Id: Ia09180f131c77a6ba9b00fb73009f0c7c3fe3d5b
Signed-off-by: Ed Warnicke <hagbard@gmail.com>
southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/transactions/md/OpenVSwitchUpdateCommand.java

index b68d1fc845b050a1c49d426de5dc70ae2cc87c1c..698eb0798eb3ea85437067d3e630418951192927 100644 (file)
@@ -74,74 +74,12 @@ public class OpenVSwitchUpdateCommand extends AbstractTransactionCommand {
                 OvsdbNodeAugmentation ovsdbNode = SouthboundMapper
                         .createOvsdbAugmentation(getConnectionInfo());
                 OvsdbNodeAugmentationBuilder ovsdbNodeBuilder = new OvsdbNodeAugmentationBuilder();
-                try {
-                    ovsdbNodeBuilder.setOvsVersion(openVSwitch.getOvsVersionColumn().getData().iterator().next());
-                } catch (NoSuchElementException e) {
-                    LOG.debug("ovs_version is not set for this switch",e);
-                }
-                try {
-                    Set<String> dptypes = openVSwitch.getDatapathTypesColumn()
-                            .getData();
-                    List<DatapathTypeEntry> dpEntryList = new ArrayList<DatapathTypeEntry>();
-                    for (String dpType : dptypes) {
-                        DatapathTypeEntry dpEntry = new DatapathTypeEntryBuilder()
-                                .setDatapathType(
-                                        SouthboundMapper.createDatapathType(dpType))
-                                .build();
-                        dpEntryList.add(dpEntry);
-                    }
-                    ovsdbNodeBuilder.setDatapathTypeEntry(dpEntryList);
-                } catch (SchemaVersionMismatchException e) {
-                    LOG.debug("Datapath types not supported by this version of ovsdb",e);
-                }
-                try {
-                    Set<String> iftypes = openVSwitch.getIfaceTypesColumn().getData();
-                    List<InterfaceTypeEntry> ifEntryList = new ArrayList<InterfaceTypeEntry>();
-                    for (String ifType : iftypes) {
-                        InterfaceTypeEntry ifEntry = new InterfaceTypeEntryBuilder()
-                                .setInterfaceType(
-                                        SouthboundMapper.createInterfaceType(ifType))
-                                .build();
-                        ifEntryList.add(ifEntry);
-                    }
-                    ovsdbNodeBuilder.setInterfaceTypeEntry(ifEntryList);
-                } catch (SchemaVersionMismatchException e) {
-                    LOG.debug("Iface types  not supported by this version of ovsdb",e);;
-                }
 
-                Map<String, String> externalIds = openVSwitch.getExternalIdsColumn().getData();
-                if (externalIds != null && !externalIds.isEmpty()) {
-                    Set<String> externalIdKeys = externalIds.keySet();
-                    List<OpenvswitchExternalIds> externalIdsList = new ArrayList<OpenvswitchExternalIds>();
-                    String externalIdValue;
-                    for (String externalIdKey : externalIdKeys) {
-                        externalIdValue = externalIds.get(externalIdKey);
-                        if (externalIdKey != null && externalIdValue != null) {
-                            externalIdsList.add(new OpenvswitchExternalIdsBuilder()
-                                    .setExternalIdKey(externalIdKey)
-                                    .setExternalIdValue(externalIdValue)
-                                    .build());
-                        }
-                    }
-                    ovsdbNodeBuilder.setOpenvswitchExternalIds(externalIdsList);
-                }
-
-                Map<String, String> otherConfigs = openVSwitch.getOtherConfigColumn().getData();
-                if (otherConfigs != null && !otherConfigs.isEmpty()) {
-                    Set<String> otherConfigKeys = otherConfigs.keySet();
-                    List<OpenvswitchOtherConfigs> otherConfigsList = new ArrayList<OpenvswitchOtherConfigs>();
-                    String otherConfigValue;
-                    for (String otherConfigKey : otherConfigKeys) {
-                        otherConfigValue = otherConfigs.get(otherConfigKey);
-                        if (otherConfigKey != null && otherConfigValue != null) {
-                            otherConfigsList.add(new OpenvswitchOtherConfigsBuilder()
-                                    .setOtherConfigKey(otherConfigKey)
-                                    .setOtherConfigValue(otherConfigValue)
-                                    .build());
-                        }
-                    }
-                    ovsdbNodeBuilder.setOpenvswitchOtherConfigs(otherConfigsList);
-                }
+                setVersion(ovsdbNodeBuilder, openVSwitch);
+                setDataPathTypes(ovsdbNodeBuilder, openVSwitch);
+                setInterfaceTypes(ovsdbNodeBuilder, openVSwitch);
+                setExternalIds(ovsdbNodeBuilder, openVSwitch);
+                setOtherConfig(ovsdbNodeBuilder, openVSwitch);
 
                 NodeBuilder nodeBuilder = new NodeBuilder();
                 ConnectionInfo connectionInfo = ovsdbNode.getConnectionInfo();
@@ -154,4 +92,92 @@ public class OpenVSwitchUpdateCommand extends AbstractTransactionCommand {
             }
         }
     }
+
+    private void setOtherConfig(OvsdbNodeAugmentationBuilder ovsdbNodeBuilder,
+            OpenVSwitch openVSwitch) {
+        Map<String, String> otherConfigs = openVSwitch.getOtherConfigColumn().getData();
+        if (otherConfigs != null && !otherConfigs.isEmpty()) {
+            Set<String> otherConfigKeys = otherConfigs.keySet();
+            List<OpenvswitchOtherConfigs> otherConfigsList = new ArrayList<OpenvswitchOtherConfigs>();
+            String otherConfigValue;
+            for (String otherConfigKey : otherConfigKeys) {
+                otherConfigValue = otherConfigs.get(otherConfigKey);
+                if (otherConfigKey != null && otherConfigValue != null) {
+                    otherConfigsList.add(new OpenvswitchOtherConfigsBuilder()
+                            .setOtherConfigKey(otherConfigKey)
+                            .setOtherConfigValue(otherConfigValue)
+                            .build());
+                }
+            }
+            ovsdbNodeBuilder.setOpenvswitchOtherConfigs(otherConfigsList);
+        }
+    }
+
+    private void setExternalIds(OvsdbNodeAugmentationBuilder ovsdbNodeBuilder,
+            OpenVSwitch openVSwitch) {
+        Map<String, String> externalIds = openVSwitch.getExternalIdsColumn().getData();
+        if (externalIds != null && !externalIds.isEmpty()) {
+            Set<String> externalIdKeys = externalIds.keySet();
+            List<OpenvswitchExternalIds> externalIdsList = new ArrayList<OpenvswitchExternalIds>();
+            String externalIdValue;
+            for (String externalIdKey : externalIdKeys) {
+                externalIdValue = externalIds.get(externalIdKey);
+                if (externalIdKey != null && externalIdValue != null) {
+                    externalIdsList.add(new OpenvswitchExternalIdsBuilder()
+                            .setExternalIdKey(externalIdKey)
+                            .setExternalIdValue(externalIdValue)
+                            .build());
+                }
+            }
+            ovsdbNodeBuilder.setOpenvswitchExternalIds(externalIdsList);
+        }
+    }
+
+    private void setInterfaceTypes(
+            OvsdbNodeAugmentationBuilder ovsdbNodeBuilder,
+            OpenVSwitch openVSwitch) {
+        try {
+            Set<String> iftypes = openVSwitch.getIfaceTypesColumn().getData();
+            List<InterfaceTypeEntry> ifEntryList = new ArrayList<InterfaceTypeEntry>();
+            for (String ifType : iftypes) {
+                InterfaceTypeEntry ifEntry = new InterfaceTypeEntryBuilder()
+                        .setInterfaceType(
+                                SouthboundMapper.createInterfaceType(ifType))
+                        .build();
+                ifEntryList.add(ifEntry);
+            }
+            ovsdbNodeBuilder.setInterfaceTypeEntry(ifEntryList);
+        } catch (SchemaVersionMismatchException e) {
+            LOG.debug("Iface types  not supported by this version of ovsdb",e);;
+        }
+    }
+
+    private void setDataPathTypes(
+            OvsdbNodeAugmentationBuilder ovsdbNodeBuilder,
+            OpenVSwitch openVSwitch) {
+        try {
+            Set<String> dptypes = openVSwitch.getDatapathTypesColumn()
+                    .getData();
+            List<DatapathTypeEntry> dpEntryList = new ArrayList<DatapathTypeEntry>();
+            for (String dpType : dptypes) {
+                DatapathTypeEntry dpEntry = new DatapathTypeEntryBuilder()
+                        .setDatapathType(
+                                SouthboundMapper.createDatapathType(dpType))
+                        .build();
+                dpEntryList.add(dpEntry);
+            }
+            ovsdbNodeBuilder.setDatapathTypeEntry(dpEntryList);
+        } catch (SchemaVersionMismatchException e) {
+            LOG.debug("Datapath types not supported by this version of ovsdb",e);
+        }
+    }
+
+    private void setVersion(OvsdbNodeAugmentationBuilder ovsdbNodeBuilder,
+            OpenVSwitch openVSwitch) {
+        try {
+            ovsdbNodeBuilder.setOvsVersion(openVSwitch.getOvsVersionColumn().getData().iterator().next());
+        } catch (NoSuchElementException e) {
+            LOG.debug("ovs_version is not set for this switch",e);
+        }
+    }
 }