r95 - in trunk/msm-hbase/src: main/java/org/nuiton/mapstoragemanager/plugins/hbase site
Author: dlanglais Date: 2010-02-17 21:44:44 +0100 (Wed, 17 Feb 2010) New Revision: 95 Added: trunk/msm-hbase/src/main/java/org/nuiton/mapstoragemanager/plugins/hbase/NoSuchTableException.java trunk/msm-hbase/src/site/todo.rst Modified: trunk/msm-hbase/src/main/java/org/nuiton/mapstoragemanager/plugins/hbase/HBaseNewBigTable.java Log: Avancement plugin HBase, todo.rst -> commente l'avancement. Pour le moment, ce que j'ai impl?\195?\169ment?\195?\169 est fait en "suivant" l'API HBase. Modified: trunk/msm-hbase/src/main/java/org/nuiton/mapstoragemanager/plugins/hbase/HBaseNewBigTable.java =================================================================== --- trunk/msm-hbase/src/main/java/org/nuiton/mapstoragemanager/plugins/hbase/HBaseNewBigTable.java 2010-02-17 18:51:10 UTC (rev 94) +++ trunk/msm-hbase/src/main/java/org/nuiton/mapstoragemanager/plugins/hbase/HBaseNewBigTable.java 2010-02-17 20:44:44 UTC (rev 95) @@ -4,6 +4,8 @@ import java.util.HashSet; import java.util.Map; import java.util.Set; +import java.util.logging.Level; +import java.util.logging.Logger; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.hadoop.hbase.MasterNotRunningException; @@ -12,8 +14,12 @@ import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.HColumnDescriptor; import org.apache.hadoop.hbase.HTableDescriptor; +import org.apache.hadoop.hbase.KeyValue; +import org.apache.hadoop.hbase.client.Get; import org.apache.hadoop.hbase.client.HBaseAdmin; import org.apache.hadoop.hbase.client.HTable; +import org.apache.hadoop.hbase.client.Put; +import org.apache.hadoop.hbase.client.Result; /** * A plugin for MSM using HBase API. @@ -28,6 +34,7 @@ private HBaseAdmin hBaseAdmin; private HBaseConfiguration config; + private HTable hTable; // private HTable table; // private String familyName = "mylittlecolumnfamily"; // private String rowName = "myLittleRow"; @@ -60,6 +67,7 @@ HTableDescriptor hTableDescriptor = new HTableDescriptor(table); try { hBaseAdmin.createTable(hTableDescriptor); + LOG.trace("table " + table + " created."); } catch (IOException ex) { LOG.error(ex, ex); } @@ -71,6 +79,7 @@ public void deleteTable(String table) { try { hBaseAdmin.deleteTable(table); + LOG.trace("table " + table + " deleted."); } catch (IOException ex) { LOG.error(ex, ex); } @@ -102,6 +111,7 @@ HColumnDescriptor hColumnDescriptor = new HColumnDescriptor(column); try { hBaseAdmin.addColumn(table, hColumnDescriptor); + LOG.trace("colum " + column + " created in table " + table + "."); } catch (IOException ex) { LOG.error(ex, ex); } @@ -113,6 +123,7 @@ public void deleteColumn(String table, String column) { try { hBaseAdmin.deleteColumn(table, column); + LOG.trace("colum " + column + " deleted from table " + table + "."); } catch (IOException ex) { LOG.error(ex, ex); } @@ -122,21 +133,71 @@ * {@inheritDoc} */ public Set<String> getColumnsNames(String table) { - throw new UnsupportedOperationException("Not supported yet."); + Set<String> columnsNames = new HashSet<String>(); + try { + if (hBaseAdmin.tableExists(table)) { + HTableDescriptor hTableDescriptor; + hTableDescriptor = + hBaseAdmin.getTableDescriptor(table.getBytes()); + + HColumnDescriptor[] hColumnsDescriptor; + hColumnsDescriptor = hTableDescriptor.getColumnFamilies(); + + for (int i = 0 ; i < hColumnsDescriptor.length ; i++) { + columnsNames.add(hColumnsDescriptor[i].getNameAsString()); + } + + } else { + try { + throw new NoSuchTableException(table); + } catch (NoSuchTableException ex) { + LOG.error(ex, ex); + } + } + } catch (MasterNotRunningException ex) { + LOG.error(ex, ex); + } catch (IOException ex) { + LOG.error(ex, ex); + } + return columnsNames; } /** * {@inheritDoc} */ public void put(String table, String column, String key, String content) { - throw new UnsupportedOperationException("Not supported yet."); + try { + Put put = new Put(key.getBytes()); + put.add(column.getBytes(), key.getBytes(), content.getBytes()); + + HTable hTable = new HTable(config, table); + hTable.put(put); + + LOG.trace("put " + table + " " + column + " " + key + " " + content); + } catch (IOException ex) { + LOG.error(ex, ex); + } } /** * {@inheritDoc} */ public String get(String table, String column, String key) { - throw new UnsupportedOperationException("Not supported yet."); + String ret = ""; + try { + Get get = new Get(key.getBytes()); + get = get.addColumn(column.getBytes()); + + HTable hTable = new HTable(config, table); + Result result = hTable.get(get); + + ret = result.getCellValue().toString(); + + LOG.trace("put " + table + " " + column + " " + key + " " + ret); + } catch (IOException ex) { + LOG.error(ex, ex); + } + return ret; } /** Added: trunk/msm-hbase/src/main/java/org/nuiton/mapstoragemanager/plugins/hbase/NoSuchTableException.java =================================================================== --- trunk/msm-hbase/src/main/java/org/nuiton/mapstoragemanager/plugins/hbase/NoSuchTableException.java (rev 0) +++ trunk/msm-hbase/src/main/java/org/nuiton/mapstoragemanager/plugins/hbase/NoSuchTableException.java 2010-02-17 20:44:44 UTC (rev 95) @@ -0,0 +1,16 @@ +package org.nuiton.mapstoragemanager.plugins.hbase; + +/** + * Exception thrown when the plugin try to access to an inexistant table. + * @author Dorian Langlais + */ +public class NoSuchTableException extends Exception { + + /** + * Exception constructor. + * @param table the name of the inexistant table. + */ + public NoSuchTableException(String table) { + super("Table " + table + "doesn't exist !"); + } +} Added: trunk/msm-hbase/src/site/todo.rst =================================================================== --- trunk/msm-hbase/src/site/todo.rst (rev 0) +++ trunk/msm-hbase/src/site/todo.rst 2010-02-17 20:44:44 UTC (rev 95) @@ -0,0 +1,17 @@ + +Function to implement in HBaseNewBigTable +========================================= + + - connect [pending] + - createTable [to test] + - deleteTable [to test] + - getTablesNames [to test] + - createColumn [to test] + - deleteColumn [to test] + - getColumnsNames [to test] + - put [to test] + - get [to test] + - get (version) [pending] + - getRow [pending] + - getKeys [pending] + - selectTable [pending] \ No newline at end of file
participants (1)
-
dlanglais@users.nuiton.org