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