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 | |
Jonathan Hart | c86a2ea | 2013-01-15 22:39:42 -0800 | [diff] [blame] | 21 | public class TestableLinkStorageImpl extends LinkStorageImpl { |
HIGUCHI Yuta | dfdd418 | 2013-06-11 17:00:39 -0700 | [diff] [blame] | 22 | protected TitanGraph graph; |
Jonathan Hart | b7e3d2c | 2013-01-15 18:45:19 -0800 | [diff] [blame] | 23 | |
Jonathan Hart | c86a2ea | 2013-01-15 22:39:42 -0800 | [diff] [blame] | 24 | public TestableLinkStorageImpl(TitanGraph graph){ |
Jonathan Hart | b7e3d2c | 2013-01-15 18:45:19 -0800 | [diff] [blame] | 25 | this.graph = graph; |
| 26 | } |
| 27 | |
| 28 | @Override |
| 29 | public void init(String conf){ |
| 30 | Set<String> s = graph.getIndexedKeys(Vertex.class); |
| 31 | if (!s.contains("dpid")) { |
| 32 | graph.createKeyIndex("dpid", Vertex.class); |
| 33 | graph.stopTransaction(Conclusion.SUCCESS); |
| 34 | } |
| 35 | if (!s.contains("type")) { |
| 36 | graph.createKeyIndex("type", Vertex.class); |
| 37 | graph.stopTransaction(Conclusion.SUCCESS); |
| 38 | } |
| 39 | |
| 40 | } |
| 41 | } |