yoshi | 0451f28 | 2013-11-22 15:48:55 -0800 | [diff] [blame] | 1 | /* |
| 2 | * To change this template, choose Tools | Templates |
| 3 | * and open the template in the editor. |
| 4 | */ |
| 5 | package net.onrc.onos.graph; |
| 6 | |
| 7 | import com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraph; |
| 8 | import com.tinkerpop.frames.FramedGraph; |
| 9 | import java.io.File; |
| 10 | import org.apache.commons.configuration.Configuration; |
| 11 | import org.apache.commons.configuration.ConfigurationException; |
| 12 | import org.apache.commons.configuration.PropertiesConfiguration; |
| 13 | |
| 14 | /** |
| 15 | * |
| 16 | * @author nickkaranatsios |
| 17 | */ |
| 18 | public 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))); |
yoshi | c935828 | 2013-11-26 16:45:06 -0800 | [diff] [blame] | 24 | System.out.println("coordinatorURL "+ coordinatorURL); |
yoshi | 0451f28 | 2013-11-22 15:48:55 -0800 | [diff] [blame] | 25 | 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 | } |