Author: dlanglais Date: 2010-02-17 13:22:42 +0100 (Wed, 17 Feb 2010) New Revision: 88 Modified: trunk/msm-hbase/src/main/java/org/nuiton/mapstoragemanager/plugins/hbase/HBaseNewBigTable.java Log: Avancement plugin "HBaseNewBigTable"... sera renomm?\195?\169 en HBase, mais nous gardons l'actuel fichier HBase.java pour en extraire le peu de chose que nous avions commenc?\195?\169 ?\195?\160 faire... 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 11:37:47 UTC (rev 87) +++ trunk/msm-hbase/src/main/java/org/nuiton/mapstoragemanager/plugins/hbase/HBaseNewBigTable.java 2010-02-17 12:22:42 UTC (rev 88) @@ -1,12 +1,20 @@ package org.nuiton.mapstoragemanager.plugins.hbase; +import java.io.IOException; +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; import org.nuiton.mapstoragemanager.plugins.NewBigTable; import org.apache.hadoop.hbase.HBaseConfiguration; +import org.apache.hadoop.hbase.HColumnDescriptor; +import org.apache.hadoop.hbase.HTableDescriptor; +import org.apache.hadoop.hbase.client.HBaseAdmin; import org.apache.hadoop.hbase.client.HTable; public class HBaseNewBigTable implements NewBigTable { @@ -16,50 +24,84 @@ */ private static final Log LOG = LogFactory.getLog(NewBigTable.class); + private HBaseAdmin hBaseAdmin; private HBaseConfiguration config; private HTable table; private String familyName = "mylittlecolumnfamily"; private String rowName = "myLittleRow"; private String tableName = "mylittletable"; - public HBaseNewBigTable() { + public HBaseNewBigTable() throws MasterNotRunningException { // You need a configuration object to tell the client where to connect. // When you create a HBaseConfiguration, it reads in whatever you've set // into your hbase-site.xml and in hbase-default.xml, as long as these can // be found on the CLASSPATH - org.apache.hadoop.conf.Configuration conf = new org.apache.hadoop.conf.Configuration(); + org.apache.hadoop.conf.Configuration conf = + new org.apache.hadoop.conf.Configuration(); config = new HBaseConfiguration(conf); + hBaseAdmin = new HBaseAdmin(config); LOG.info("test"); } @Override - public boolean connect(String host, int port, String base, String username, String passwd) { + public boolean connect(String host, int port, String base, String username, + String passwd) { throw new UnsupportedOperationException("Not supported yet."); } @Override public void createTable(String table) { - throw new UnsupportedOperationException("Not supported yet."); + HTableDescriptor hTableDescriptor = new HTableDescriptor(table); + try { + hBaseAdmin.createTable(hTableDescriptor); + } catch (IOException ex) { + LOG.error(ex, ex); + } } @Override public void deleteTable(String table) { - throw new UnsupportedOperationException("Not supported yet."); + try { + hBaseAdmin.deleteTable(table); + } catch (IOException ex) { + LOG.error(ex, ex); + } } @Override public Set<String> getTablesNames() { - throw new UnsupportedOperationException("Not supported yet."); + Set<String> tablesNames = new HashSet<String>(); + try { + HTableDescriptor[] hTablesDescriptor; + hTablesDescriptor = hBaseAdmin.listTables(); + + for (int i = 0 ; i < hTablesDescriptor.length ; i++) { + tablesNames.add(hTablesDescriptor[i].getNameAsString()); + } + + } catch (IOException ex) { + LOG.error(ex, ex); + } + return tablesNames; } @Override public void createColumn(String table, String column) { - throw new UnsupportedOperationException("Not supported yet."); + HColumnDescriptor hColumnDescriptor = new HColumnDescriptor(column); + try { + hBaseAdmin.addColumn(table, hColumnDescriptor); + } catch (IOException ex) { + LOG.error(ex, ex); + } } @Override public void deleteColumn(String table, String column) { - throw new UnsupportedOperationException("Not supported yet."); + try { + hBaseAdmin.deleteColumn(table, column); + } catch (IOException ex) { + LOG.error(ex, ex); + } } @Override