Merge "OPNFLWPLUG-929 : Remove deprecated guava library"
[openflowplugin.git] / test-provider / src / main / java / org / opendaylight / openflowplugin / test / OpenflowpluginTableFeaturesTestCommandProvider.java
index ca4b11f5142be10d5c3c4dd7baa6c6a037ac2925..847c95f3d328943551c9fd3c180d4c1a2eabb963 100644 (file)
@@ -1,17 +1,16 @@
 /**
- * Copyright (c) 2014 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
+ * Copyright (c) 2014, 2015 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,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributor: hema.gopalkrishnan@ericsson.com
  */
 package org.opendaylight.openflowplugin.test;
 
 import com.google.common.util.concurrent.CheckedFuture;
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.MoreExecutors;
 import java.math.BigInteger;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -31,9 +30,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.acti
 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionKey;
@@ -68,11 +64,13 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table
 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.wildcards.WildcardSetfieldBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeatures;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeaturesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeaturesKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.table.features.TablePropertiesBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.table.features.table.properties.TableFeatureProperties;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.table.features.table.properties.TableFeaturePropertiesBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.table.features.table.properties.TableFeaturePropertiesKey;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
 import org.osgi.framework.BundleContext;
 
 
@@ -81,7 +79,7 @@ public class OpenflowpluginTableFeaturesTestCommandProvider implements CommandPr
     private DataBroker dataBroker;
     private ProviderContext pc;
     private final BundleContext ctx;
-    private Table testTable;
+    private TableFeatures testTable;
     private Node testNode;
     private final String originalTableName = "Foo";
     private final String updatedTableName = "Bar";
@@ -95,7 +93,7 @@ public class OpenflowpluginTableFeaturesTestCommandProvider implements CommandPr
         dataBroker = session.getSALService(DataBroker.class);
         ctx.registerService(CommandProvider.class.getName(), this, null);
         // createTestNode();
-        // createTestTable();
+        // createTestTableFeatures();
     }
 
     private void createUserNode(String nodeRef) {
@@ -116,38 +114,27 @@ public class OpenflowpluginTableFeaturesTestCommandProvider implements CommandPr
         return InstanceIdentifier.create(Nodes.class).child(Node.class, node.getKey());
     }
 
-    private TableBuilder createTestTable(String tableFeatureTypeArg) {
+    private TableFeaturesBuilder createTestTableFeatures(String tableFeatureTypeArg) {
 
         String tableFeatureType = tableFeatureTypeArg;
         if (tableFeatureType == null) {
             tableFeatureType = "t1";
         }
-        // Sample data , committing to DataStore
-        short id = 12;
-        TableKey key = new TableKey(id);
-
-        TableBuilder table = new TableBuilder();
-        table.setId((short) 12);
-        table.setId(id);
-        table.setKey(key);
-
-
-        List<TableFeatures> ofTablefeatures = new ArrayList<TableFeatures>();
 
-        // Skip this to send empty table features
+        final TableFeaturesBuilder tableFeature = new TableFeaturesBuilder();
+        // Sample data , committing to DataStore
         if (!tableFeatureType.equals("t1")) {
 
 
-            TableFeaturesBuilder tableFeature1 = new TableFeaturesBuilder();
-            tableFeature1.setTableId((short) 0);
-            tableFeature1.setName("Table 0");
+            tableFeature.setTableId((short) 0);
+            tableFeature.setName("Table 0");
 
 
-            tableFeature1.setMetadataMatch(BigInteger.valueOf(10));
-            tableFeature1.setMetadataWrite(BigInteger.valueOf(10));
-            tableFeature1.setMaxEntries(10000L);
+            tableFeature.setMetadataMatch(BigInteger.valueOf(10));
+            tableFeature.setMetadataWrite(BigInteger.valueOf(10));
+            tableFeature.setMaxEntries(10000L);
 
-            tableFeature1.setConfig(new TableConfig(false));
+            tableFeature.setConfig(new TableConfig(false));
 
             List<TableFeatureProperties> properties = new ArrayList<TableFeatureProperties>();
 
@@ -214,16 +201,10 @@ public class OpenflowpluginTableFeaturesTestCommandProvider implements CommandPr
 
             TablePropertiesBuilder propertyBld = new TablePropertiesBuilder();
             propertyBld.setTableFeatureProperties(properties);
-            tableFeature1.setTableProperties(propertyBld.build());
-
-
-            ofTablefeatures.add(tableFeature1.build());
-
+            tableFeature.setTableProperties(propertyBld.build());
         }
-        table.setTableFeatures(ofTablefeatures);
-
-        testTable = table.build();
-        return table;
+        testTable = tableFeature.build();
+        return tableFeature;
     }
 
     private TableFeaturePropertiesBuilder createApplyActionsMissTblFeatureProp() {
@@ -595,18 +576,18 @@ public class OpenflowpluginTableFeaturesTestCommandProvider implements CommandPr
     }
 
 
-    private void writeTable(final CommandInterpreter ci, Table table) {
+    private void writeTableFeatures(final CommandInterpreter ci, TableFeatures tableFeatures) {
         ReadWriteTransaction modification = dataBroker.newReadWriteTransaction();
 
-        InstanceIdentifier<Table> path1 = InstanceIdentifier.create(Nodes.class)
+        KeyedInstanceIdentifier<TableFeatures, TableFeaturesKey> path1 = InstanceIdentifier.create(Nodes.class)
                 .child(Node.class, testNode.getKey()).augmentation(FlowCapableNode.class).
-                        child(Table.class, new TableKey(table.getId()));
+                        child(TableFeatures.class, new TableFeaturesKey(tableFeatures.getTableId()));
 
 
         modification.merge(LogicalDatastoreType.OPERATIONAL, nodeToInstanceId(testNode), testNode, true);
-        modification.merge(LogicalDatastoreType.OPERATIONAL, path1, table, true);
+        modification.merge(LogicalDatastoreType.OPERATIONAL, path1, tableFeatures, true);
         modification.merge(LogicalDatastoreType.CONFIGURATION, nodeToInstanceId(testNode), testNode, true);
-        modification.merge(LogicalDatastoreType.CONFIGURATION, path1, table, true);
+        modification.merge(LogicalDatastoreType.CONFIGURATION, path1, tableFeatures, true);
         CheckedFuture<Void, TransactionCommitFailedException> commitFuture = modification.submit();
         Futures.addCallback(commitFuture, new FutureCallback<Void>() {
             @Override
@@ -618,7 +599,7 @@ public class OpenflowpluginTableFeaturesTestCommandProvider implements CommandPr
             public void onFailure(Throwable throwable) {
                 ci.println(String.format("Status of Group Data Loaded Transaction : failure. Reason : %s", throwable));
             }
-        });
+        }, MoreExecutors.directExecutor());
     }
 
     public void _modifyTable(CommandInterpreter ci) {
@@ -633,14 +614,14 @@ public class OpenflowpluginTableFeaturesTestCommandProvider implements CommandPr
             createUserNode(nref);
         }
         String tableFeatureType = ci.nextArgument();
-        TableBuilder table = createTestTable(tableFeatureType);
+        TableFeaturesBuilder tableFeaturesBld = createTestTableFeatures(tableFeatureType);
 
-        writeTable(ci, table.build());
+        writeTableFeatures(ci, tableFeaturesBld.build());
     }
 
     @Override
     public String getHelp() {
-        StringBuffer help = new StringBuffer();
+        StringBuilder help = new StringBuilder();
         help.append("---FRM MD-SAL Table test module---\n");
         help.append("\t modifyTable <node id>        - node ref\n");