Jonathan Hart | b7e3d2c | 2013-01-15 18:45:19 -0800 | [diff] [blame] | 1 | package net.floodlightcontroller.linkdiscovery.internal; |
| 2 | |
| 3 | import java.util.Set; |
| 4 | |
| 5 | import com.thinkaurelius.titan.core.TitanGraph; |
| 6 | import com.tinkerpop.blueprints.TransactionalGraph.Conclusion; |
| 7 | import com.tinkerpop.blueprints.Vertex; |
| 8 | |
| 9 | /** |
Jonathan Hart | c86a2ea | 2013-01-15 22:39:42 -0800 | [diff] [blame] | 10 | * Seam that allows me to set up a testable instance of LinkStorageImpl that |
Jonathan Hart | 627f10c | 2013-01-16 14:20:03 -0800 | [diff] [blame] | 11 | * writes to a file database rather than a Cassandra cluster. |
| 12 | * It seems the init() API on LinkStorageImpl might change so I won't rely |
| 13 | * on it yet. |
Jonathan Hart | b7e3d2c | 2013-01-15 18:45:19 -0800 | [diff] [blame] | 14 | * |
| 15 | * @author jono |
| 16 | * |
| 17 | */ |
| 18 | |
Jonathan Hart | c86a2ea | 2013-01-15 22:39:42 -0800 | [diff] [blame] | 19 | public class TestableLinkStorageImpl extends LinkStorageImpl { |
HIGUCHI Yuta | dfdd418 | 2013-06-11 17:00:39 -0700 | [diff] [blame] | 20 | protected TitanGraph graph; |
Jonathan Hart | b7e3d2c | 2013-01-15 18:45:19 -0800 | [diff] [blame] | 21 | |
Jonathan Hart | c86a2ea | 2013-01-15 22:39:42 -0800 | [diff] [blame] | 22 | public TestableLinkStorageImpl(TitanGraph graph){ |
Jonathan Hart | b7e3d2c | 2013-01-15 18:45:19 -0800 | [diff] [blame] | 23 | this.graph = graph; |
| 24 | } |
| 25 | |
| 26 | @Override |
| 27 | public void init(String conf){ |
| 28 | Set<String> s = graph.getIndexedKeys(Vertex.class); |
| 29 | if (!s.contains("dpid")) { |
| 30 | graph.createKeyIndex("dpid", Vertex.class); |
| 31 | graph.stopTransaction(Conclusion.SUCCESS); |
| 32 | } |
| 33 | if (!s.contains("type")) { |
| 34 | graph.createKeyIndex("type", Vertex.class); |
| 35 | graph.stopTransaction(Conclusion.SUCCESS); |
| 36 | } |
| 37 | |
| 38 | } |
| 39 | } |