Package org.apache.hadoop.chukwa.util

Examples of org.apache.hadoop.chukwa.util.DatabaseWriter


      }
    }
  }

  public void tearDown() {
    DatabaseWriter db = null;
    try {
      db = new DatabaseWriter(cluster);
      ResultSet rs = db.query("show tables");
      ArrayList<String> list = new ArrayList<String>();
      while(rs.next()) {
        String table = rs.getString(1);
        list.add(table);
      }
      for(String table : list) {
        db.execute("drop table "+table);
      }
    } catch(Throwable ex) {
    } finally {
      if(db!=null) {
        db.close();
      }
    }
  }
View Full Code Here


    }
    return contents.toString();
  }

  public void testPrepareStatement() {
    DatabaseWriter db = new DatabaseWriter(cluster);
    Date today = new Date();
    long current = today.getTime();
    Timestamp timestamp = new Timestamp(current);
    String hostname="chukwa.example.org";
    String query = "insert into [system_metrics] set timestamp='"+timestamp.toString()+"', host='"+hostname+"', cpu_user_pcnt=100;";
    Macro mp = new Macro(current, current, query);
    query = mp.toString();
    try {
      db.execute(query);
      query = "select timestamp,host,cpu_user_pcnt from [system_metrics] where timestamp=? and host=? and cpu_user_pcnt=?;";
      mp = new Macro(current, current, query);
      query = mp.toString();
      ArrayList<Object> parms = new ArrayList<Object>();
      parms.add(current);
      parms.add(hostname);
      parms.add(100);
      ResultSet rs = db.query(query, parms);
      while(rs.next()) {
        assertTrue(hostname.intern()==rs.getString(2).intern());
        assertTrue(100==rs.getInt(3));
      }
      db.close();
    } catch(SQLException ex) {
      fail("Fail to run SQL statement:"+ExceptionUtil.getStackTrace(ex));
    }
  }
View Full Code Here

  public String cluster = "demo";
  public long current = Calendar.getInstance().getTimeInMillis();

  public void setUpDatabase() throws Exception {
    System.setProperty("CLUSTER","demo");
    DatabaseWriter db = new DatabaseWriter(cluster);
    String buffer = "";
    File aFile = new File(System.getenv("CHUKWA_CONF_DIR")
        + File.separator + "database_create_tables.sql");
    buffer = readFile(aFile);
    String tables[] = buffer.split(";");
    for(String table : tables) {
      if(table.length()>5) {
        db.execute(table);
      }
    }
    db.close();
    for(int i=0;i<timeWindow.length;i++) {
      TableCreator tc = new TableCreator();
      long start = current;
      long end = current + (timeWindow[i]*1440*60*1000);
      tc.createTables(start, end);
View Full Code Here

      tc.createTables(start, end);
    }
  }

  public void tearDownDatabase() {
    DatabaseWriter db = null;
    try {
      db = new DatabaseWriter(cluster);
      ResultSet rs = db.query("show tables");
      ArrayList<String> list = new ArrayList<String>();
      while(rs.next()) {
        String table = rs.getString(1);
        list.add(table);
      }
      for(String table : list) {
        db.execute("drop table "+table);
      }
    } catch(Throwable ex) {
    } finally {
      if(db!=null) {
        db.close();
      }
    }
  }
View Full Code Here

  String cluster = "demo";
  long current = Calendar.getInstance().getTimeInMillis();

  public void setUp() {
    System.setProperty("CLUSTER","demo");
    DatabaseWriter db = new DatabaseWriter(cluster);
    String buffer = "";
    File aFile = new File(System.getenv("CHUKWA_CONF_DIR")
                 + File.separator + "database_create_tables.sql");
    buffer = readFile(aFile);
    String tables[] = buffer.split(";");
    for(String table : tables) {
      if(table.length()>5) {
        try {
          db.execute(table);
        } catch (Exception e) {
          fail("Fail to retrieve meta data for database table:"+table);
        }
      }
    }
    db.close();
    for(int i=0;i<timeWindow.length;i++) {
      TableCreator tc = new TableCreator();
      long start = current;
      long end = current + (timeWindow[i]*1440*60*1000);
      try {
View Full Code Here

      }
    }
  }

  public void tearDown() {
    DatabaseWriter db = null;
    try {
      db = new DatabaseWriter(cluster);
      ResultSet rs = db.query("show tables");
      ArrayList<String> list = new ArrayList<String>();
      while(rs.next()) {
        String table = rs.getString(1);
        list.add(table);
      }
      for(String table : list) {
        db.execute("drop table "+table);
      }
    } catch(Throwable ex) {
    } finally {
      if(db!=null) {
        db.close();
      }
    }
  }
View Full Code Here

    ChukwaConfiguration cc = new ChukwaConfiguration();
    String query = "select * from ["+table+"];";
    Macro mp = new Macro(current,query);
    query = mp.toString();
    try {
      DatabaseWriter db = new DatabaseWriter(cluster);
      ResultSet rs = db.query(query);
      while(rs.next()) {
        int i = 1;
        String value = rs.getString(i);
      }
      db.close();
    } catch(SQLException ex) {
      fail("SQL Exception: "+ExceptionUtil.getStackTrace(ex));
    }
  }
View Full Code Here

  }

  public void testTableCreator() {
    for(int i=0;i<timeWindow.length;i++) {
      try {
        DatabaseWriter db = new DatabaseWriter(cluster);
        for(String table : tables) {
          String query = "select * from ["+table+"];";
          Macro mp = new Macro(current,query);
          query = mp.toString();
          ResultSet rs = db.query(query);
          rs.last();
          int count = rs.getRow();
          assertTrue("Table should exist and return empty result.", count==0);
        }
        db.close();
      } catch(SQLException ex) {
        fail("SQL Exception: "+ExceptionUtil.getStackTrace(ex));
      }
    }
  }
View Full Code Here

    ChukwaConfiguration cc = new ChukwaConfiguration();
    String query = "select * from ["+table+"];";
    Macro mp = new Macro(dbSetup.current,query);
    query = mp.toString();
    try {
      DatabaseWriter db = new DatabaseWriter(dbSetup.cluster);
      ResultSet rs = db.query(query);
      while(rs.next()) {
        int i = 1;
        String value = rs.getString(i);
      }
      db.close();
    } catch(SQLException ex) {
      fail("SQL Exception: "+ExceptionUtil.getStackTrace(ex));
    }
  }
View Full Code Here

    }
  }

  public void testAggregator() {
    Aggregator dba = new Aggregator();
    DatabaseWriter db = new DatabaseWriter(dbSetup.cluster);
    dba.setWriter(db);
    String queries = Aggregator.getContents(new File(System
        .getenv("CHUKWA_CONF_DIR")
        + File.separator + "aggregator.sql"));
    String[] query = queries.split("\n");
    for (int i = 0; i < query.length; i++) {
      if(query[i].indexOf("#")==-1) {
        try {
          dba.process(query[i]);
          assertTrue("Completed query: "+query[i],true);
        } catch(Throwable ex) {
          fail("Exception: "+ExceptionUtil.getStackTrace(ex));
        }
      }
    }
    db.close();
  }
View Full Code Here

TOP

Related Classes of org.apache.hadoop.chukwa.util.DatabaseWriter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.