blob: a4fc6dee857c3b71139c2dc61c7d3f7595991cf0 [file] [log] [blame]
yoshi0451f282013-11-22 15:48:55 -08001/*
2 * To change this template, choose Tools | Templates
3 * and open the template in the editor.
4 */
5package net.onrc.onos.graph;
6
7import com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraph;
8import com.tinkerpop.frames.FramedGraph;
9import java.io.File;
10import org.apache.commons.configuration.Configuration;
11import org.apache.commons.configuration.ConfigurationException;
12import org.apache.commons.configuration.PropertiesConfiguration;
13
14/**
15 *
16 * @author nickkaranatsios
17 */
18public class RamCloudDBConnection extends DBConnection {
19 private RamCloudGraph graph;
20
21 public RamCloudDBConnection(final String dbConfigFile) {
22 System.out.println("dbconfigfile is + "+ dbConfigFile);
23 final String coordinatorURL = open(getConfiguration(new File(dbConfigFile)));
yoshic9358282013-11-26 16:45:06 -080024 System.out.println("coordinatorURL "+ coordinatorURL);
yoshi0451f282013-11-22 15:48:55 -080025 graph = new RamCloudGraph(coordinatorURL);
26 }
27
28 @Override
29 public FramedGraph getFramedGraph() {
30 throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
31 }
32
33 @Override
34 public void addEventListener(LocalGraphChangedListener listener) {
35 throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
36 }
37
38 @Override
39 public Boolean isValid() {
40 throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
41 }
42
43 @Override
44 public void commit() {
45 throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
46 }
47
48 @Override
49 public void rollback() {
50 throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
51 }
52
53 @Override
54 public void close() {
55 throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
56 }
57
58 private static final Configuration getConfiguration(final File dirOrFile) {
59 if (dirOrFile == null) {
60 throw new IllegalArgumentException("Need to specify a configuration file or storage directory");
61 }
62
63 if (!dirOrFile.isFile()) {
64 throw new IllegalArgumentException("Location of configuration must be a file");
65 }
66
67 try {
68 return new PropertiesConfiguration(dirOrFile);
69 } catch (ConfigurationException e) {
70 throw new IllegalArgumentException("Could not load configuration at: " + dirOrFile, e);
71 }
72 }
73
74 private String open(final Configuration configuration) {
75 final String coordinatorURL = configuration.getString("ramcloud.coordinator", null);
76 if (coordinatorURL == null) {
77 throw new RuntimeException("Configuration must contain a valid 'coordinatorURL' setting");
78 }
79 return coordinatorURL;
80 }
81}