chukwa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From asrab...@apache.org
Subject svn commit: r752666 [11/16] - in /hadoop/chukwa/trunk: ./ src/java/org/apache/hadoop/chukwa/ src/java/org/apache/hadoop/chukwa/conf/ src/java/org/apache/hadoop/chukwa/database/ src/java/org/apache/hadoop/chukwa/datacollection/ src/java/org/apache/hadoo...
Date Wed, 11 Mar 2009 22:39:32 GMT
Modified: hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/extraction/engine/datasource/record/ChukwaRecordDataSource.java
URL: http://svn.apache.org/viewvc/hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/extraction/engine/datasource/record/ChukwaRecordDataSource.java?rev=752666&r1=752665&r2=752666&view=diff
==============================================================================
--- hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/extraction/engine/datasource/record/ChukwaRecordDataSource.java (original)
+++ hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/extraction/engine/datasource/record/ChukwaRecordDataSource.java Wed Mar 11 22:39:26 2009
@@ -1,5 +1,6 @@
 package org.apache.hadoop.chukwa.extraction.engine.datasource.record;
 
+
 import java.io.IOException;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
@@ -9,7 +10,6 @@
 import java.util.LinkedList;
 import java.util.List;
 import java.util.TreeMap;
-
 import org.apache.hadoop.chukwa.conf.ChukwaConfiguration;
 import org.apache.hadoop.chukwa.extraction.engine.ChukwaRecord;
 import org.apache.hadoop.chukwa.extraction.engine.ChukwaRecordKey;
@@ -25,496 +25,450 @@
 import org.apache.hadoop.io.SequenceFile;
 import org.apache.log4j.Logger;
 
-public class ChukwaRecordDataSource implements DataSource
-{
-	//TODO need some cleanup after 1st production
-	// First implementation to get it working with the new directory structure
-	
-	static Logger log = Logger.getLogger(ChukwaRecordDataSource.class);
-	
-	private static final int dayFolder = 100;
-	private static final int hourFolder = 200;
-	private static final int rawFolder = 300;
-	
-	static final String[] raws = {"0","5","10","15","20","25","30","35","40","45","50","55"};
-	
-	private static FileSystem fs = null;
-	private static ChukwaConfiguration conf = null;
-	
-	private static String rootDsFolder = null;
-	private static DataConfig dataConfig = null;
-	
-	static
-	{
-		dataConfig = new DataConfig();
-		rootDsFolder = dataConfig.get("chukwa.engine.dsDirectory.rootFolder");
-		conf = new ChukwaConfiguration();
-		try
-		{
-			fs = FileSystem.get(conf);
-		} catch (IOException e)
-		{
-			e.printStackTrace();
-		}
-	}
-	
-	@Override
-	public boolean isThreadSafe()
-	{
-		return true;
-	}
-
-
-	@Override
-	public SearchResult search(SearchResult result, String cluster,
-			String dataSource, long t0, long t1, String filter,Token token)
-			throws DataSourceException
-	{
-		String filePath = rootDsFolder + "/" + cluster + "/";
-
-		log.debug("filePath [" + filePath + "]");	
-		Calendar calendar = Calendar.getInstance();
-		calendar.setTimeInMillis(t0);
-		SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyyMMdd");
-		int maxCount = 200;
-		
-		List<Record> records = new ArrayList<Record>();
-
-		ChukwaDSInternalResult res =  new ChukwaDSInternalResult();
-		
-		if (token != null)
-		{
-			// token.key = day + "|" + hour + "|" + raw + "|" + spill + "|" + res.currentTs + "|"+ res.position + "|"+ res.fileName;
-			try
-			{
-				String[] vars = token.key.split("\\|");
-				res.day = vars[0];
-				res.hour = Integer.parseInt(vars[1]);
-				res.rawIndex = Integer.parseInt(vars[2]);
-				res.spill = Integer.parseInt(vars[3]);
-				res.currentTs = Long.parseLong(vars[4]);
-				res.position = Long.parseLong(vars[5]);
-				res.fileName = vars[5];
-				log.info("Token is not null! :" + token.key);
-			}
-			catch(Exception e)
-			{
-				log.error("Incalid Key: [" + token.key + "] exception: ", e);
-			}
-		}
-		else
-		{
-			log.debug("Token is  null!" );
-		}
-		
-		try
-		{
-			do
-			{
-				log.debug("start Date [" + calendar.getTime() + "]");
-				String workingDay = sdf.format(calendar.getTime());
-				int workingHour = calendar.get(Calendar.HOUR_OF_DAY);
-				int startRawIndex = 0;
-				if (token !=null)
-				{
-					workingDay = res.day ;
-					workingHour = res.hour;
-					startRawIndex = res.rawIndex;
-				}
-				else
-				{
-					token = new Token();
-				}
-				
-				log.debug("workingDay " + workingDay);
-				log.debug("workingHour " + workingHour);
-				
-				if (exist(dayFolder,filePath,dataSource,workingDay,null,null))
-				{
-					// Extract Data for Day
-					if (containsRotateFlag(dayFolder,filePath,dataSource,workingDay,null))
-					{
-						// read data from day
-						// SystemMetrics/20080922/SystemMetrics_20080922.1.evt
-						log.debug("fs.exists(workingDayRotatePath) ");
-						extractRecords(res,ChukwaRecordDataSource.dayFolder,filePath,dataSource,workingDay, null, -1,
-								 token, records, maxCount, t0, t1, filter);
-						maxCount = maxCount - records.size();
-						if ( (maxCount <= 0) || (res.currentTs > t1))
-						 { break; }
-						
-					} // End process Day File
-					else // check for hours
-					{
-						log.debug("check for hours");
-						for (int hour = 0; hour<24;hour ++)
-						{
-							if ( workingDay == res.day && hour<workingHour)
-							{
-								continue;
-							}
-							log.debug(" Hour?  -->" + filePath + dataSource + "/"+ workingDay+ "/" + hour);
-							if (exist(dayFolder,filePath,dataSource,workingDay,""+hour,null))
-							{
-								if (containsRotateFlag(dayFolder,filePath,dataSource,workingDay,""+hour))
-								{
-									// read data from Hour
-									// SystemMetrics/20080922/12/SystemMetrics_20080922_12.1.evt
-									extractRecords(res,ChukwaRecordDataSource.hourFolder,filePath,dataSource,workingDay, ""+hour, -1,
-											 token, records, maxCount, t0, t1, filter);
-								}
-								else // check for raw
-								{
-									log.debug("Working on Raw");
-									
-									for(int rawIndex=startRawIndex;rawIndex<12;rawIndex++)
-									{
-										// read data from Raw
-										// SystemMetrics/20080922/0/25/SystemMetrics_20080922_0_25.1.evt
-										if (exist(dayFolder,filePath,dataSource,workingDay,""+hour,raws[rawIndex]))
-										{
-											extractRecords(res,ChukwaRecordDataSource.rawFolder,filePath,dataSource,workingDay, ""+hour, rawIndex,
-													 token, records, maxCount, t0, t1, filter);
-											maxCount = maxCount - records.size();
-											if ( (maxCount <= 0) || (res.currentTs > t1))
-											 { break; }
-										}
-										else
-										{
-											log.debug("<<<<<<<<<Working on Raw Not exist--> "
-													+ filePath + dataSource + "/" + workingDay+ "/" + workingHour + "/" + raws[rawIndex] );
-										}
-										res.spill = 1;
-									}
-								}
-							} // End if (fs.exists(new Path(filePath + workingDay+ "/" + hour)))
-							 
-							maxCount = maxCount - records.size();
-							if ( (maxCount <= 0) || (res.currentTs > t1))
-							 { break; }
-
-						} // End process all Hourly/raw files
-					}
-				}	
-				
-				maxCount = maxCount - records.size();
-				if ( (maxCount <= 0) || (res.currentTs > t1))
-				 { break; }
-			
-				// move to the next day
-				calendar.add(Calendar.DAY_OF_MONTH, +1);
-				calendar.set(Calendar.HOUR_OF_DAY, 0);
-				calendar.set(Calendar.MINUTE, 0);
-				calendar.set(Calendar.SECOND, 0);
-				
-			}
-			while (calendar.getTimeInMillis() < t1); 
-			
-		}
-		catch(Exception e)
-		{
-			e.printStackTrace();
-			throw new DataSourceException(e);
-		}
-	
-		TreeMap<Long, List<Record>> recordsInResult = result.getRecords();
-		for (Record record : records)
-		{
-			long timestamp = record.getTime();
-			if (recordsInResult.containsKey(timestamp))
-			   {
-				recordsInResult.get(timestamp).add(record);
-			   }
-			   else
-			   {
-				   List<Record> list = new LinkedList<Record>();
-				   list.add(record);
-				   recordsInResult.put(timestamp, list);
-			   }   
-		}
-		result.setToken(token);
-		return result;
-
-	}
-
-	public void extractRecords(ChukwaDSInternalResult res,int directoryType,String rootFolder,String dataSource,String day,String hour,int rawIndex,
-								Token token,List<Record> records,int maxRows,long t0,long t1,String filter) throws Exception
-	{
-		// for each spill file
-		// extract records
-		int spill = res.spill;
-		
-		boolean workdone = false;
-		do
-		{
-			String fileName = buildFileName(directoryType,rootFolder,dataSource,spill,day,hour,rawIndex);
-			log.debug("extractRecords : " + fileName);
-			
-			if (fs.exists(new Path(fileName)))
-			{
-				 readData(res,token,fileName,maxRows,t0,t1,filter);
-				 res.spill = spill;
-				 List<Record> localRecords = res.records;
-				log.debug("localRecords size : " + localRecords.size());
-				maxRows = maxRows - localRecords.size();
-				if (maxRows <= 0)
-				{
-					workdone = true;
-				}
-				records.addAll(localRecords);
-				log.debug("AFTER fileName  [" +fileName + "] count=" + localRecords.size() + " maxCount=" + maxRows);
-				spill ++;
-			}
-			else
-			{
-				// no more spill
-				workdone = true;
-			}
-		}
-		while(!workdone);
-		token.key = day + "|" + hour + "|" + rawIndex + "|" + spill + "|" + res.currentTs + "|"+ res.position + "|" + res.fileName;
-	}
-	
-	
-	public  void readData(ChukwaDSInternalResult res,Token token,String fileName,int maxRows,long t0, long t1,String filter) throws
-			Exception
-	{
-		List<Record> records = new LinkedList<Record>();
-		res.records = records;	
-		SequenceFile.Reader r= null;
-		if (filter != null)
-			{ filter = filter.toLowerCase();}
-		
-		try
-		{
-			
-			if (!fs.exists(new Path(fileName)))
-			{
-				log.debug("fileName not there!");
-				return;
-			}
-			log.debug("Parser Open [" +fileName + "]");
-			
-			long timestamp = 0;
-			int listSize = 0;
-			ChukwaRecordKey key = new ChukwaRecordKey();
-		    ChukwaRecord record = new ChukwaRecord();
-		    
-			r= new SequenceFile.Reader(fs, new Path(fileName), conf);
-			
-			log.debug("readData Open2 [" +fileName + "]");
-			if ( (fileName.equals(res.fileName)) && (res.position != -1))
-			{
-				r.seek(res.position);
-			}
-			res.fileName = 	fileName;
-			
-			while(r.next(key, record))
-			{	
-				if (record != null)
-				{
-					res.position = r.getPosition();
-					
-					timestamp = record.getTime();
-					res.currentTs = timestamp;
-					log.debug("\nSearch for startDate: " + new Date(t0) + " is :" + new Date(timestamp));
-					
-					if (timestamp < t0) 
-					{
-						 //log.debug("Line not in range. Skipping: " +record);
-						 continue;
-					} 
-					else if (timestamp < t1) 
-					{
-						log.debug("In Range: " + record.toString());
-						boolean valid = false;
-						
-						 if ( (filter == null || filter.equals("") ))
-						 {
-							 valid = true;
-						 }
-						 else if ( isValid(record,filter))
-						 {
-							 valid = true;
-						 }
-						 
-						 if (valid)
-						 {
-							records.add(record);
-							record = new ChukwaRecord();
-							listSize = records.size();
-							if (listSize >= maxRows)
-							{
-								// maxRow so stop here
-								//Update token
-								token.key = key.getKey();
-								token.hasMore = true;
-								break;
-							}
-						 }
-						else 
-						{
-							log.debug("In Range ==================>>>>>>>>> OUT Regex: " + record);
-						}
-					}
-					else
-					{
-						 log.debug("Line out of range. Stopping now: " +record);
-						 // Update Token
-						 token.key = key.getKey();
-						 token.hasMore = false;
-						 break;
-					}
-				}
-			}
-			
-		}
-		catch(Exception e)
-		{
-			e.printStackTrace();
-		}
-		finally
-		{
-			try
-			{
-				r.close();
-			}
-			catch(Exception e){}
-		}
-	}
-	
-	public boolean containsRotateFlag(int directoryType,String rootFolder,String dataSource,String workingDay,String workingHour) throws Exception
-	{
-		boolean contains = false;
-		switch(directoryType)
-		{
-			case	ChukwaRecordDataSource.dayFolder:
-				//	SystemMetrics/20080922/rotateDone	
-				contains = fs.exists(new Path( rootFolder + dataSource + "/" + workingDay+"/rotateDone"));
-			break;
-			
-			case	ChukwaRecordDataSource.hourFolder:
-				// SystemMetrics/20080922/12/rotateDone
-				contains =  fs.exists(new Path( rootFolder + dataSource + "/" + workingDay+ "/" + workingHour +"/rotateDone"));
-			break;
-			
-		}
-		return contains;
-	}
-	
-	public boolean exist(int directoryType,String rootFolder,String dataSource,String workingDay,String workingHour,String raw) throws Exception
-	{
-		boolean contains = false;
-		switch(directoryType)
-		{
-			case	ChukwaRecordDataSource.dayFolder:
-				//	SystemMetrics/20080922/rotateDone	
-				contains = fs.exists(new Path( rootFolder + dataSource + "/" + workingDay));
-			break;
-			
-			case	ChukwaRecordDataSource.hourFolder:
-				// SystemMetrics/20080922/12/rotateDone
-				contains =  fs.exists(new Path( rootFolder + dataSource + "/" + workingDay+ "/" + workingHour ));
-			break;
-			case	ChukwaRecordDataSource.rawFolder:
-				// SystemMetrics/20080922/12/rotateDone
-				contains =  fs.exists(new Path( rootFolder + dataSource + "/" + workingDay+ "/" + workingHour + "/" + raw));
-			break;
-			
-		}
-		return contains;
-	}
-	
-	
-	protected boolean isValid(ChukwaRecord record, String filter)
-	{
-		String[] fields = record.getFields();
-		for(String field: fields)
-		{
-			if ( record.getValue(field).toLowerCase().indexOf(filter) >= 0)
-			{
-				return true;
-			}
-		}
-		return false;
-	}
-	
-	public String buildFileName(int directoryType,String rootFolder,String dataSource,int spill,String day,String hour,int rawIndex)
-	{
-		String fileName = null;
-		// TODO use StringBuilder
-		// TODO revisit the way we're building fileName
-		
-		switch(directoryType)
-		{
-			case	ChukwaRecordDataSource.dayFolder:
-				//	SystemMetrics/20080922/SystemMetrics_20080922.1.evt	
-				fileName = rootFolder + "/" + dataSource + "/" + day + "/" 
-					+ dataSource + "_" +  day + "." + spill + ".evt";
-			break;
-			
-			case	ChukwaRecordDataSource.hourFolder:
-				// SystemMetrics/20080922/12/SystemMetrics_20080922_12.1.evt
-				fileName = rootFolder + "/" + dataSource + "/" + day + "/" + hour + "/" 
-					+ dataSource + "_" +  day + "_" + hour + "." + spill + ".evt";
-			break;
-			
-			case	ChukwaRecordDataSource.rawFolder:
-				// SystemMetrics/20080922/0/25/SystemMetrics_20080922_0_25.1.evt	
-				fileName = rootFolder + "/" + dataSource + "/" + day + "/" + hour + "/"  + raws[rawIndex] + "/"
-					+ dataSource + "_" +  day + "_" + hour + "_" + raws[rawIndex] + "." + spill + ".evt";
-			break;
-		}
-		log.debug("buildFileName :" + fileName);
-		return fileName;
-	}
-	
-	public static void main(String[] args) throws DataSourceException
-	{
-		ChukwaRecordDataSource ds = new ChukwaRecordDataSource();
-		SearchResult result = new ChukwaSearchResult();
-		result.setRecords( new TreeMap<Long,List<Record>>());
-		String cluster = args[0];
-		String dataSource = args[1];
-		long t0 = Long.parseLong(args[2]);
-		long t1 = Long.parseLong(args[3]);
-		String filter = null;
-		Token token = null;
-		
-		if (args.length >= 5 && !args[4].equalsIgnoreCase("null"))
-		{
-			filter = args[4];
-		}
-		if (args.length == 6)
-		{
-			token = new Token();
-			token.key = args[5];
-			System.out.println("token :" + token.key);
-		}
-		
-		System.out.println("cluster :" + cluster);
-		System.out.println("dataSource :" + dataSource);
-		System.out.println("t0 :" + t0);
-		System.out.println("t1 :" + t1);
-		System.out.println("filter :" +filter );
-		
-		
-		ds.search(result, cluster, dataSource, t0, t1, filter,token);
-		TreeMap<Long, List<Record>> records = result.getRecords();
-		Iterator<Long> it = records.keySet().iterator();
-		
-		while(it.hasNext())
-		{
-			long ts = it.next();
-			System.out.println("\n\nTimestamp: " + new Date(ts));
-			List<Record> list = records.get(ts);
-			for (int i=0;i<list.size();i++)
-			{
-				System.out.println(list.get(i));
-			}
-		}
-		
-		if (result.getToken() != null)
-		 { System.out.println("Key -->" + result.getToken().key);}
-	}
+public class ChukwaRecordDataSource implements DataSource {
+  // TODO need some cleanup after 1st production
+  // First implementation to get it working with the new directory structure
+
+  static Logger log = Logger.getLogger(ChukwaRecordDataSource.class);
+
+  private static final int dayFolder = 100;
+  private static final int hourFolder = 200;
+  private static final int rawFolder = 300;
+
+  static final String[] raws = { "0", "5", "10", "15", "20", "25", "30", "35",
+      "40", "45", "50", "55" };
+
+  private static FileSystem fs = null;
+  private static ChukwaConfiguration conf = null;
+
+  private static String rootDsFolder = null;
+  private static DataConfig dataConfig = null;
+
+  static {
+    dataConfig = new DataConfig();
+    rootDsFolder = dataConfig.get("chukwa.engine.dsDirectory.rootFolder");
+    conf = new ChukwaConfiguration();
+    try {
+      fs = FileSystem.get(conf);
+    } catch (IOException e) {
+      e.printStackTrace();
+    }
+  }
+
+  @Override
+  public boolean isThreadSafe() {
+    return true;
+  }
+
+  @Override
+  public SearchResult search(SearchResult result, String cluster,
+      String dataSource, long t0, long t1, String filter, Token token)
+      throws DataSourceException {
+    String filePath = rootDsFolder + "/" + cluster + "/";
+
+    log.debug("filePath [" + filePath + "]");
+    Calendar calendar = Calendar.getInstance();
+    calendar.setTimeInMillis(t0);
+    SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyyMMdd");
+    int maxCount = 200;
+
+    List<Record> records = new ArrayList<Record>();
+
+    ChukwaDSInternalResult res = new ChukwaDSInternalResult();
+
+    if (token != null) {
+      // token.key = day + "|" + hour + "|" + raw + "|" + spill + "|" +
+      // res.currentTs + "|"+ res.position + "|"+ res.fileName;
+      try {
+        String[] vars = token.key.split("\\|");
+        res.day = vars[0];
+        res.hour = Integer.parseInt(vars[1]);
+        res.rawIndex = Integer.parseInt(vars[2]);
+        res.spill = Integer.parseInt(vars[3]);
+        res.currentTs = Long.parseLong(vars[4]);
+        res.position = Long.parseLong(vars[5]);
+        res.fileName = vars[5];
+        log.info("Token is not null! :" + token.key);
+      } catch (Exception e) {
+        log.error("Incalid Key: [" + token.key + "] exception: ", e);
+      }
+    } else {
+      log.debug("Token is  null!");
+    }
+
+    try {
+      do {
+        log.debug("start Date [" + calendar.getTime() + "]");
+        String workingDay = sdf.format(calendar.getTime());
+        int workingHour = calendar.get(Calendar.HOUR_OF_DAY);
+        int startRawIndex = 0;
+        if (token != null) {
+          workingDay = res.day;
+          workingHour = res.hour;
+          startRawIndex = res.rawIndex;
+        } else {
+          token = new Token();
+        }
+
+        log.debug("workingDay " + workingDay);
+        log.debug("workingHour " + workingHour);
+
+        if (exist(dayFolder, filePath, dataSource, workingDay, null, null)) {
+          // Extract Data for Day
+          if (containsRotateFlag(dayFolder, filePath, dataSource, workingDay,
+              null)) {
+            // read data from day
+            // SystemMetrics/20080922/SystemMetrics_20080922.1.evt
+            log.debug("fs.exists(workingDayRotatePath) ");
+            extractRecords(res, ChukwaRecordDataSource.dayFolder, filePath,
+                dataSource, workingDay, null, -1, token, records, maxCount, t0,
+                t1, filter);
+            maxCount = maxCount - records.size();
+            if ((maxCount <= 0) || (res.currentTs > t1)) {
+              break;
+            }
+
+          } // End process Day File
+          else // check for hours
+          {
+            log.debug("check for hours");
+            for (int hour = 0; hour < 24; hour++) {
+              if (workingDay == res.day && hour < workingHour) {
+                continue;
+              }
+              log.debug(" Hour?  -->" + filePath + dataSource + "/"
+                  + workingDay + "/" + hour);
+              if (exist(dayFolder, filePath, dataSource, workingDay, "" + hour,
+                  null)) {
+                if (containsRotateFlag(dayFolder, filePath, dataSource,
+                    workingDay, "" + hour)) {
+                  // read data from Hour
+                  // SystemMetrics/20080922/12/SystemMetrics_20080922_12.1.evt
+                  extractRecords(res, ChukwaRecordDataSource.hourFolder,
+                      filePath, dataSource, workingDay, "" + hour, -1, token,
+                      records, maxCount, t0, t1, filter);
+                } else // check for raw
+                {
+                  log.debug("Working on Raw");
+
+                  for (int rawIndex = startRawIndex; rawIndex < 12; rawIndex++) {
+                    // read data from Raw
+                    //SystemMetrics/20080922/0/25/SystemMetrics_20080922_0_25.1.
+                    // evt
+                    if (exist(dayFolder, filePath, dataSource, workingDay, ""
+                        + hour, raws[rawIndex])) {
+                      extractRecords(res, ChukwaRecordDataSource.rawFolder,
+                          filePath, dataSource, workingDay, "" + hour,
+                          rawIndex, token, records, maxCount, t0, t1, filter);
+                      maxCount = maxCount - records.size();
+                      if ((maxCount <= 0) || (res.currentTs > t1)) {
+                        break;
+                      }
+                    } else {
+                      log.debug("<<<<<<<<<Working on Raw Not exist--> "
+                          + filePath + dataSource + "/" + workingDay + "/"
+                          + workingHour + "/" + raws[rawIndex]);
+                    }
+                    res.spill = 1;
+                  }
+                }
+              } // End if (fs.exists(new Path(filePath + workingDay+ "/" +
+                // hour)))
+
+              maxCount = maxCount - records.size();
+              if ((maxCount <= 0) || (res.currentTs > t1)) {
+                break;
+              }
+
+            } // End process all Hourly/raw files
+          }
+        }
+
+        maxCount = maxCount - records.size();
+        if ((maxCount <= 0) || (res.currentTs > t1)) {
+          break;
+        }
+
+        // move to the next day
+        calendar.add(Calendar.DAY_OF_MONTH, +1);
+        calendar.set(Calendar.HOUR_OF_DAY, 0);
+        calendar.set(Calendar.MINUTE, 0);
+        calendar.set(Calendar.SECOND, 0);
+
+      } while (calendar.getTimeInMillis() < t1);
+
+    } catch (Exception e) {
+      e.printStackTrace();
+      throw new DataSourceException(e);
+    }
+
+    TreeMap<Long, List<Record>> recordsInResult = result.getRecords();
+    for (Record record : records) {
+      long timestamp = record.getTime();
+      if (recordsInResult.containsKey(timestamp)) {
+        recordsInResult.get(timestamp).add(record);
+      } else {
+        List<Record> list = new LinkedList<Record>();
+        list.add(record);
+        recordsInResult.put(timestamp, list);
+      }
+    }
+    result.setToken(token);
+    return result;
+
+  }
+
+  public void extractRecords(ChukwaDSInternalResult res, int directoryType,
+      String rootFolder, String dataSource, String day, String hour,
+      int rawIndex, Token token, List<Record> records, int maxRows, long t0,
+      long t1, String filter) throws Exception {
+    // for each spill file
+    // extract records
+    int spill = res.spill;
+
+    boolean workdone = false;
+    do {
+      String fileName = buildFileName(directoryType, rootFolder, dataSource,
+          spill, day, hour, rawIndex);
+      log.debug("extractRecords : " + fileName);
+
+      if (fs.exists(new Path(fileName))) {
+        readData(res, token, fileName, maxRows, t0, t1, filter);
+        res.spill = spill;
+        List<Record> localRecords = res.records;
+        log.debug("localRecords size : " + localRecords.size());
+        maxRows = maxRows - localRecords.size();
+        if (maxRows <= 0) {
+          workdone = true;
+        }
+        records.addAll(localRecords);
+        log.debug("AFTER fileName  [" + fileName + "] count="
+            + localRecords.size() + " maxCount=" + maxRows);
+        spill++;
+      } else {
+        // no more spill
+        workdone = true;
+      }
+    } while (!workdone);
+    token.key = day + "|" + hour + "|" + rawIndex + "|" + spill + "|"
+        + res.currentTs + "|" + res.position + "|" + res.fileName;
+  }
+
+  public void readData(ChukwaDSInternalResult res, Token token,
+      String fileName, int maxRows, long t0, long t1, String filter)
+      throws Exception {
+    List<Record> records = new LinkedList<Record>();
+    res.records = records;
+    SequenceFile.Reader r = null;
+    if (filter != null) {
+      filter = filter.toLowerCase();
+    }
+
+    try {
+
+      if (!fs.exists(new Path(fileName))) {
+        log.debug("fileName not there!");
+        return;
+      }
+      log.debug("Parser Open [" + fileName + "]");
+
+      long timestamp = 0;
+      int listSize = 0;
+      ChukwaRecordKey key = new ChukwaRecordKey();
+      ChukwaRecord record = new ChukwaRecord();
+
+      r = new SequenceFile.Reader(fs, new Path(fileName), conf);
+
+      log.debug("readData Open2 [" + fileName + "]");
+      if ((fileName.equals(res.fileName)) && (res.position != -1)) {
+        r.seek(res.position);
+      }
+      res.fileName = fileName;
+
+      while (r.next(key, record)) {
+        if (record != null) {
+          res.position = r.getPosition();
+
+          timestamp = record.getTime();
+          res.currentTs = timestamp;
+          log.debug("\nSearch for startDate: " + new Date(t0) + " is :"
+              + new Date(timestamp));
+
+          if (timestamp < t0) {
+            // log.debug("Line not in range. Skipping: " +record);
+            continue;
+          } else if (timestamp < t1) {
+            log.debug("In Range: " + record.toString());
+            boolean valid = false;
+
+            if ((filter == null || filter.equals(""))) {
+              valid = true;
+            } else if (isValid(record, filter)) {
+              valid = true;
+            }
+
+            if (valid) {
+              records.add(record);
+              record = new ChukwaRecord();
+              listSize = records.size();
+              if (listSize >= maxRows) {
+                // maxRow so stop here
+                // Update token
+                token.key = key.getKey();
+                token.hasMore = true;
+                break;
+              }
+            } else {
+              log.debug("In Range ==================>>>>>>>>> OUT Regex: "
+                  + record);
+            }
+          } else {
+            log.debug("Line out of range. Stopping now: " + record);
+            // Update Token
+            token.key = key.getKey();
+            token.hasMore = false;
+            break;
+          }
+        }
+      }
+
+    } catch (Exception e) {
+      e.printStackTrace();
+    } finally {
+      try {
+        r.close();
+      } catch (Exception e) {
+      }
+    }
+  }
+
+  public boolean containsRotateFlag(int directoryType, String rootFolder,
+      String dataSource, String workingDay, String workingHour)
+      throws Exception {
+    boolean contains = false;
+    switch (directoryType) {
+    case ChukwaRecordDataSource.dayFolder:
+      // SystemMetrics/20080922/rotateDone
+      contains = fs.exists(new Path(rootFolder + dataSource + "/" + workingDay
+          + "/rotateDone"));
+      break;
+
+    case ChukwaRecordDataSource.hourFolder:
+      // SystemMetrics/20080922/12/rotateDone
+      contains = fs.exists(new Path(rootFolder + dataSource + "/" + workingDay
+          + "/" + workingHour + "/rotateDone"));
+      break;
+
+    }
+    return contains;
+  }
+
+  public boolean exist(int directoryType, String rootFolder, String dataSource,
+      String workingDay, String workingHour, String raw) throws Exception {
+    boolean contains = false;
+    switch (directoryType) {
+    case ChukwaRecordDataSource.dayFolder:
+      // SystemMetrics/20080922/rotateDone
+      contains = fs
+          .exists(new Path(rootFolder + dataSource + "/" + workingDay));
+      break;
+
+    case ChukwaRecordDataSource.hourFolder:
+      // SystemMetrics/20080922/12/rotateDone
+      contains = fs.exists(new Path(rootFolder + dataSource + "/" + workingDay
+          + "/" + workingHour));
+      break;
+    case ChukwaRecordDataSource.rawFolder:
+      // SystemMetrics/20080922/12/rotateDone
+      contains = fs.exists(new Path(rootFolder + dataSource + "/" + workingDay
+          + "/" + workingHour + "/" + raw));
+      break;
+
+    }
+    return contains;
+  }
+
+  protected boolean isValid(ChukwaRecord record, String filter) {
+    String[] fields = record.getFields();
+    for (String field : fields) {
+      if (record.getValue(field).toLowerCase().indexOf(filter) >= 0) {
+        return true;
+      }
+    }
+    return false;
+  }
+
+  public String buildFileName(int directoryType, String rootFolder,
+      String dataSource, int spill, String day, String hour, int rawIndex) {
+    String fileName = null;
+    // TODO use StringBuilder
+    // TODO revisit the way we're building fileName
+
+    switch (directoryType) {
+    case ChukwaRecordDataSource.dayFolder:
+      // SystemMetrics/20080922/SystemMetrics_20080922.1.evt
+      fileName = rootFolder + "/" + dataSource + "/" + day + "/" + dataSource
+          + "_" + day + "." + spill + ".evt";
+      break;
+
+    case ChukwaRecordDataSource.hourFolder:
+      // SystemMetrics/20080922/12/SystemMetrics_20080922_12.1.evt
+      fileName = rootFolder + "/" + dataSource + "/" + day + "/" + hour + "/"
+          + dataSource + "_" + day + "_" + hour + "." + spill + ".evt";
+      break;
+
+    case ChukwaRecordDataSource.rawFolder:
+      // SystemMetrics/20080922/0/25/SystemMetrics_20080922_0_25.1.evt
+      fileName = rootFolder + "/" + dataSource + "/" + day + "/" + hour + "/"
+          + raws[rawIndex] + "/" + dataSource + "_" + day + "_" + hour + "_"
+          + raws[rawIndex] + "." + spill + ".evt";
+      break;
+    }
+    log.debug("buildFileName :" + fileName);
+    return fileName;
+  }
+
+  public static void main(String[] args) throws DataSourceException {
+    ChukwaRecordDataSource ds = new ChukwaRecordDataSource();
+    SearchResult result = new ChukwaSearchResult();
+    result.setRecords(new TreeMap<Long, List<Record>>());
+    String cluster = args[0];
+    String dataSource = args[1];
+    long t0 = Long.parseLong(args[2]);
+    long t1 = Long.parseLong(args[3]);
+    String filter = null;
+    Token token = null;
+
+    if (args.length >= 5 && !args[4].equalsIgnoreCase("null")) {
+      filter = args[4];
+    }
+    if (args.length == 6) {
+      token = new Token();
+      token.key = args[5];
+      System.out.println("token :" + token.key);
+    }
+
+    System.out.println("cluster :" + cluster);
+    System.out.println("dataSource :" + dataSource);
+    System.out.println("t0 :" + t0);
+    System.out.println("t1 :" + t1);
+    System.out.println("filter :" + filter);
+
+    ds.search(result, cluster, dataSource, t0, t1, filter, token);
+    TreeMap<Long, List<Record>> records = result.getRecords();
+    Iterator<Long> it = records.keySet().iterator();
+
+    while (it.hasNext()) {
+      long ts = it.next();
+      System.out.println("\n\nTimestamp: " + new Date(ts));
+      List<Record> list = records.get(ts);
+      for (int i = 0; i < list.size(); i++) {
+        System.out.println(list.get(i));
+      }
+    }
+
+    if (result.getToken() != null) {
+      System.out.println("Key -->" + result.getToken().key);
+    }
+  }
 }

Modified: hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/extraction/engine/datasource/record/ChukwaSequenceFileParser.java
URL: http://svn.apache.org/viewvc/hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/extraction/engine/datasource/record/ChukwaSequenceFileParser.java?rev=752666&r1=752665&r2=752666&view=diff
==============================================================================
--- hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/extraction/engine/datasource/record/ChukwaSequenceFileParser.java (original)
+++ hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/extraction/engine/datasource/record/ChukwaSequenceFileParser.java Wed Mar 11 22:39:26 2009
@@ -18,11 +18,11 @@
 
 package org.apache.hadoop.chukwa.extraction.engine.datasource.record;
 
+
 import java.io.IOException;
 import java.util.Date;
 import java.util.LinkedList;
 import java.util.List;
-
 import org.apache.hadoop.chukwa.extraction.engine.ChukwaRecord;
 import org.apache.hadoop.chukwa.extraction.engine.ChukwaRecordKey;
 import org.apache.hadoop.chukwa.extraction.engine.Record;
@@ -31,130 +31,115 @@
 import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.io.SequenceFile;
 
-public class ChukwaSequenceFileParser
-{
+public class ChukwaSequenceFileParser {
 
-	public static  List<Record> readData(String cluster,String dataSource,int maxRows,long t1, long t0,
-			long maxOffset,String filter,String fileName,FileSystem fs,Configuration conf  ) throws
-			MalformedFileFormat
-	{
-	
-		//String source = "NameNode." + fileName;
-		List<Record> records = new LinkedList<Record>();
-		SequenceFile.Reader r= null;
-		
-		int lineCount = 0;
-		if (filter != null)
-			{ filter = filter.toLowerCase();}
-		
-		try
-		{
-			
-			if (!fs.exists(new Path(fileName)))
-			{
-				System.out.println("fileName not there!");
-				return records;
-			}
-			System.out.println("NameNodeParser Open [" +fileName + "]");
-			
-			r= new SequenceFile.Reader(fs, new Path(fileName), conf);
-			System.out.println("NameNodeParser Open2 [" +fileName + "]");
-			
-			long timestamp = 0;
-			int listSize = 0;
-
-			long offset = 0;
-			
-//			HdfsWriter.HdfsWriterKey key = new HdfsWriter.HdfsWriterKey();
-			ChukwaRecordKey key = new ChukwaRecordKey();
-		    ChukwaRecord record = new ChukwaRecord();
-		    
-			while(r.next(key, record))
-			{	
-				lineCount ++;
-				
-				System.out.println("NameNodeParser Line [" +record.getValue(Record.bodyField) + "]");	
-				
-				if (record != null)
-				{
-					timestamp = record.getTime();
-					if (timestamp < t0) 
-					{
-						 System.out.println("Line not in range. Skipping: " +record.getValue(Record.bodyField));
-						 System.out.println("Search for: " + new Date(t0) + " is :" + new Date(timestamp));
-						 continue;
-					} 
-					else if ((timestamp < t1) && (offset < maxOffset )) //JB (epochTS < maxDate)
-					{
-						
-						System.out.println("In Range: " + record.getValue(Record.bodyField));
-						boolean valid = false;
-						
-						 if ( (filter == null || filter.equals("") ))
-						 {
-							 valid = true;
-						 }
-						 else if ( isValid(record,filter))
-						 {
-							 valid = true;
-						 }
-						 
-						 if (valid)
-						 {
-							records.add(record);
-							record = new ChukwaRecord();
-							listSize = records.size();
-							if (listSize > maxRows)
-							{
-								records.remove(0);
-								System.out.println("==========>>>>>REMOVING: " + record.getValue(Record.bodyField));
-							}
-						 }
-						else 
-						{
-							System.out.println("In Range ==================>>>>>>>>> OUT Regex: " + record.getValue(Record.bodyField));
-						}
-
-					}
-					else
-					{
-						 System.out.println("Line out of range. Stopping now: " +record.getValue(Record.bodyField));
-						break;
-					}
-				}
-
-			}
-		}
-		catch(Exception e)
-		{
-			e.printStackTrace();
-		}
-		finally
-		{
-			System.out.println("File: " +fileName +" Line count: " + lineCount);
-			if (r != null)
-			{
-				try
-				{r.close();} 
-				catch (IOException e)
-				{}	
-			}
-			
-		}
-		return records;
-	}
-	
-	
-	protected static boolean isValid(ChukwaRecord record, String filter)
-	{
-		String[] fields = record.getFields();
-		for(String field: fields)
-		{
-			if ( record.getValue(field).toLowerCase().indexOf(filter) >= 0)
-			{
-				return true;
-			}
-		}
-		return false;
-	}
+  public static List<Record> readData(String cluster, String dataSource,
+      int maxRows, long t1, long t0, long maxOffset, String filter,
+      String fileName, FileSystem fs, Configuration conf)
+      throws MalformedFileFormat {
+
+    // String source = "NameNode." + fileName;
+    List<Record> records = new LinkedList<Record>();
+    SequenceFile.Reader r = null;
+
+    int lineCount = 0;
+    if (filter != null) {
+      filter = filter.toLowerCase();
+    }
+
+    try {
+
+      if (!fs.exists(new Path(fileName))) {
+        System.out.println("fileName not there!");
+        return records;
+      }
+      System.out.println("NameNodeParser Open [" + fileName + "]");
+
+      r = new SequenceFile.Reader(fs, new Path(fileName), conf);
+      System.out.println("NameNodeParser Open2 [" + fileName + "]");
+
+      long timestamp = 0;
+      int listSize = 0;
+
+      long offset = 0;
+
+      // HdfsWriter.HdfsWriterKey key = new HdfsWriter.HdfsWriterKey();
+      ChukwaRecordKey key = new ChukwaRecordKey();
+      ChukwaRecord record = new ChukwaRecord();
+
+      while (r.next(key, record)) {
+        lineCount++;
+
+        System.out.println("NameNodeParser Line ["
+            + record.getValue(Record.bodyField) + "]");
+
+        if (record != null) {
+          timestamp = record.getTime();
+          if (timestamp < t0) {
+            System.out.println("Line not in range. Skipping: "
+                + record.getValue(Record.bodyField));
+            System.out.println("Search for: " + new Date(t0) + " is :"
+                + new Date(timestamp));
+            continue;
+          } else if ((timestamp < t1) && (offset < maxOffset)) // JB (epochTS <
+                                                               // maxDate)
+          {
+
+            System.out
+                .println("In Range: " + record.getValue(Record.bodyField));
+            boolean valid = false;
+
+            if ((filter == null || filter.equals(""))) {
+              valid = true;
+            } else if (isValid(record, filter)) {
+              valid = true;
+            }
+
+            if (valid) {
+              records.add(record);
+              record = new ChukwaRecord();
+              listSize = records.size();
+              if (listSize > maxRows) {
+                records.remove(0);
+                System.out.println("==========>>>>>REMOVING: "
+                    + record.getValue(Record.bodyField));
+              }
+            } else {
+              System.out
+                  .println("In Range ==================>>>>>>>>> OUT Regex: "
+                      + record.getValue(Record.bodyField));
+            }
+
+          } else {
+            System.out.println("Line out of range. Stopping now: "
+                + record.getValue(Record.bodyField));
+            break;
+          }
+        }
+
+      }
+    } catch (Exception e) {
+      e.printStackTrace();
+    } finally {
+      System.out.println("File: " + fileName + " Line count: " + lineCount);
+      if (r != null) {
+        try {
+          r.close();
+        } catch (IOException e) {
+        }
+      }
+
+    }
+    return records;
+  }
+
+  protected static boolean isValid(ChukwaRecord record, String filter) {
+    String[] fields = record.getFields();
+    for (String field : fields) {
+      if (record.getValue(field).toLowerCase().indexOf(filter) >= 0) {
+        return true;
+      }
+    }
+    return false;
+  }
 }

Modified: hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/extraction/engine/datasource/record/MalformedFileFormat.java
URL: http://svn.apache.org/viewvc/hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/extraction/engine/datasource/record/MalformedFileFormat.java?rev=752666&r1=752665&r2=752666&view=diff
==============================================================================
--- hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/extraction/engine/datasource/record/MalformedFileFormat.java (original)
+++ hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/extraction/engine/datasource/record/MalformedFileFormat.java Wed Mar 11 22:39:26 2009
@@ -18,34 +18,30 @@
 
 package org.apache.hadoop.chukwa.extraction.engine.datasource.record;
 
+
 import org.apache.hadoop.chukwa.extraction.engine.datasource.DataSourceException;
 
-public class MalformedFileFormat extends DataSourceException
-{
+public class MalformedFileFormat extends DataSourceException {
 
-	/**
+  /**
 	 * 
 	 */
-	private static final long serialVersionUID = 2180898410952691571L;
+  private static final long serialVersionUID = 2180898410952691571L;
 
-	public MalformedFileFormat()
-	{
-		super();
-	}
-
-	public MalformedFileFormat(String message, Throwable cause)
-	{
-		super(message, cause);
-	}
-
-	public MalformedFileFormat(String message)
-	{
-		super(message);
-	}
-
-	public MalformedFileFormat(Throwable cause)
-	{
-		super(cause);
-	}
+  public MalformedFileFormat() {
+    super();
+  }
+
+  public MalformedFileFormat(String message, Throwable cause) {
+    super(message, cause);
+  }
+
+  public MalformedFileFormat(String message) {
+    super(message);
+  }
+
+  public MalformedFileFormat(Throwable cause) {
+    super(cause);
+  }
 
 }

Modified: hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/extraction/engine/datasource/record/RecordDS.java
URL: http://svn.apache.org/viewvc/hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/extraction/engine/datasource/record/RecordDS.java?rev=752666&r1=752665&r2=752666&view=diff
==============================================================================
--- hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/extraction/engine/datasource/record/RecordDS.java (original)
+++ hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/extraction/engine/datasource/record/RecordDS.java Wed Mar 11 22:39:26 2009
@@ -18,13 +18,13 @@
 
 package org.apache.hadoop.chukwa.extraction.engine.datasource.record;
 
+
 import java.io.IOException;
 import java.text.SimpleDateFormat;
 import java.util.Calendar;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.TreeMap;
-
 import org.apache.hadoop.chukwa.conf.ChukwaConfiguration;
 import org.apache.hadoop.chukwa.extraction.engine.Record;
 import org.apache.hadoop.chukwa.extraction.engine.SearchResult;
@@ -34,119 +34,102 @@
 import org.apache.hadoop.chukwa.inputtools.mdl.DataConfig;
 import org.apache.hadoop.fs.FileSystem;
 
-public class RecordDS implements DataSource
-{
-	
-	private static FileSystem fs = null;
-	private static ChukwaConfiguration conf = null;
-	
-	private static String rootFolder = null;
-	private static DataConfig dataConfig = null;
-	
-	static
-	{
-		dataConfig = new DataConfig();
-		rootFolder = dataConfig.get("chukwa.engine.dsDirectory.rootFolder");
-		conf = new ChukwaConfiguration();
-		try
-		{
-			fs = FileSystem.get(conf);
-		} catch (IOException e)
-		{
-			e.printStackTrace();
-		}
-	}
-	
-	public SearchResult search(
-									SearchResult result, 
-									String cluster,
-									String dataSource, 
-									long t0, 
-									long t1, 
-									String filter,Token token)
-			throws DataSourceException
-	{
-		
-		String filePath = rootFolder + "/" +  
-				cluster + "/" + dataSource;
-		
-		System.out.println("filePath [" + filePath + "]");	
-		Calendar calendar = Calendar.getInstance();
-		calendar.setTimeInMillis(t1);
-		
-		TreeMap<Long, List<Record>> records = result.getRecords();
-		int maxCount = 200;
-		SimpleDateFormat sdf = new java.text.SimpleDateFormat("_yyyyMMdd_HH_");
-		do
-		{
-			System.out.println("start Date [" + calendar.getTime() + "]");
-			String fileName = sdf.format(calendar.getTime());
-			int minutes = calendar.get(Calendar.MINUTE);
-			int dec = minutes/10;
-			fileName +=  dec ;
-			
-			int m = minutes - (dec*10);
-			if (m < 5)
-			{ fileName += "0.1.evt";}
-			else
-			{ fileName += "5.1.evt";}
-			
-			fileName = filePath + "/" + dataSource + fileName;
-			
-			//System.out.println("JB fileName  [" +fileName + "]");
-			
-			
-			try
-			{
-				System.out.println("BEFORE fileName  [" +fileName + "]");
-				
-//				List<Record> evts = ChukwaFileParser.readData(cluster,dataSource,maxCount, t1, t0, Long.MAX_VALUE, filter, fileName, fs);
-				List<Record> evts = ChukwaSequenceFileParser.readData(cluster,dataSource,maxCount, t1, t0, Long.MAX_VALUE, filter, fileName, fs,conf);
-				
-				maxCount = maxCount - evts.size();
-				System.out.println("AFTER fileName  [" +fileName + "] count=" + evts.size() + " maxCount=" + maxCount);
-				for (Record evt : evts)
-				{
-					System.out.println("AFTER Loop  [" +evt.toString() + "]");
-					long timestamp = evt.getTime();
-					if (records.containsKey(timestamp))
-					   {
-						records.get(timestamp).add(evt);
-					   }
-					   else
-					   {
-						   List<Record> list = new LinkedList<Record>();
-						   list.add(evt);
-						   records.put(timestamp, list);
-					   }   
-				}
-			}
-			catch (Exception e)
-			{
-				e.printStackTrace();
-			}
-			
-			if (maxCount <= 0)
-			{
-				System.out.println("BREAKING LOOP AFTER [" +fileName + "] maxCount=" + maxCount);
-				break;
-			}
-			
-			calendar.add(Calendar.MINUTE, -5);
-			
-			System.out.println("calendar  [" +calendar.getTimeInMillis() + "] ");
-			System.out.println("end       [" +(t0-1000*60*5 ) + "] ");
-		} while (calendar.getTimeInMillis() > (t0-1000*60*5 )); // <= need some code here
-		// Need more than this to compute the end
-		
-		
-
-		
-		return result;
-	}
-	
-	public boolean isThreadSafe()
-	{
-		return true;
-	}
+public class RecordDS implements DataSource {
+
+  private static FileSystem fs = null;
+  private static ChukwaConfiguration conf = null;
+
+  private static String rootFolder = null;
+  private static DataConfig dataConfig = null;
+
+  static {
+    dataConfig = new DataConfig();
+    rootFolder = dataConfig.get("chukwa.engine.dsDirectory.rootFolder");
+    conf = new ChukwaConfiguration();
+    try {
+      fs = FileSystem.get(conf);
+    } catch (IOException e) {
+      e.printStackTrace();
+    }
+  }
+
+  public SearchResult search(SearchResult result, String cluster,
+      String dataSource, long t0, long t1, String filter, Token token)
+      throws DataSourceException {
+
+    String filePath = rootFolder + "/" + cluster + "/" + dataSource;
+
+    System.out.println("filePath [" + filePath + "]");
+    Calendar calendar = Calendar.getInstance();
+    calendar.setTimeInMillis(t1);
+
+    TreeMap<Long, List<Record>> records = result.getRecords();
+    int maxCount = 200;
+    SimpleDateFormat sdf = new java.text.SimpleDateFormat("_yyyyMMdd_HH_");
+    do {
+      System.out.println("start Date [" + calendar.getTime() + "]");
+      String fileName = sdf.format(calendar.getTime());
+      int minutes = calendar.get(Calendar.MINUTE);
+      int dec = minutes / 10;
+      fileName += dec;
+
+      int m = minutes - (dec * 10);
+      if (m < 5) {
+        fileName += "0.1.evt";
+      } else {
+        fileName += "5.1.evt";
+      }
+
+      fileName = filePath + "/" + dataSource + fileName;
+
+      // System.out.println("JB fileName  [" +fileName + "]");
+
+      try {
+        System.out.println("BEFORE fileName  [" + fileName + "]");
+
+        // List<Record> evts =
+        // ChukwaFileParser.readData(cluster,dataSource,maxCount, t1, t0,
+        // Long.MAX_VALUE, filter, fileName, fs);
+        List<Record> evts = ChukwaSequenceFileParser.readData(cluster,
+            dataSource, maxCount, t1, t0, Long.MAX_VALUE, filter, fileName, fs,
+            conf);
+
+        maxCount = maxCount - evts.size();
+        System.out.println("AFTER fileName  [" + fileName + "] count="
+            + evts.size() + " maxCount=" + maxCount);
+        for (Record evt : evts) {
+          System.out.println("AFTER Loop  [" + evt.toString() + "]");
+          long timestamp = evt.getTime();
+          if (records.containsKey(timestamp)) {
+            records.get(timestamp).add(evt);
+          } else {
+            List<Record> list = new LinkedList<Record>();
+            list.add(evt);
+            records.put(timestamp, list);
+          }
+        }
+      } catch (Exception e) {
+        e.printStackTrace();
+      }
+
+      if (maxCount <= 0) {
+        System.out.println("BREAKING LOOP AFTER [" + fileName + "] maxCount="
+            + maxCount);
+        break;
+      }
+
+      calendar.add(Calendar.MINUTE, -5);
+
+      System.out.println("calendar  [" + calendar.getTimeInMillis() + "] ");
+      System.out.println("end       [" + (t0 - 1000 * 60 * 5) + "] ");
+    } while (calendar.getTimeInMillis() > (t0 - 1000 * 60 * 5)); // <= need some
+                                                                 // code here
+    // Need more than this to compute the end
+
+    return result;
+  }
+
+  public boolean isThreadSafe() {
+    return true;
+  }
 }

Modified: hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/hicc/Chart.java
URL: http://svn.apache.org/viewvc/hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/hicc/Chart.java?rev=752666&r1=752665&r2=752666&view=diff
==============================================================================
--- hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/hicc/Chart.java (original)
+++ hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/hicc/Chart.java Wed Mar 11 22:39:26 2009
@@ -18,6 +18,7 @@
 
 package org.apache.hadoop.chukwa.hicc;
 
+
 import java.io.PrintWriter;
 import java.io.IOException;
 import java.util.ArrayList;
@@ -32,348 +33,376 @@
 import javax.servlet.http.HttpServletRequest;
 import org.apache.hadoop.chukwa.hicc.ColorPicker;
 
-
 public class Chart {
-    private String id;
-    private String title;
-    private String graphType;
-    private ArrayList<TreeMap<String, TreeMap<String, Double>>> dataset;
-    private ArrayList<String> chartType;
-	private boolean xLabelOn;
-	private boolean yLabelOn;
-	private boolean yRightLabelOn;
-	private int width;
-	private int height;
-	private List<String> xLabelRange;
-	private HashMap<String, Long> xLabelRangeHash;
-	private HttpServletRequest request = null;
-    private boolean legend;
-    private String xLabel="";
-    private String yLabel="";
-    private String yRightLabel="";
-    private int datasetCounter=0;
-    private double max=0;
-    private int seriesCounter=0;
-    private List<String> rightList;
-    private boolean userDefinedMax = false;
-    private String[] seriesOrder=null;
-    
-	public Chart(HttpServletRequest request) {
-		if(request!=null && request.getParameter("boxId")!=null) {
-			this.id=request.getParameter("boxId");
-		} else {
-			this.id="0";
-		}
-        this.title="Untitled Chart";
-        this.graphType="image";
-        this.xLabelOn=true;
-        this.yLabelOn=true;
-        this.width=400;
-        this.height=200;
-        this.request=request;
-        this.legend=true;
-        this.max=0;
-        this.datasetCounter=0;
-        this.seriesCounter=0;
-        this.rightList = new ArrayList<String>();
-        this.userDefinedMax=false;
-        this.seriesOrder=null;
-    }
-	
-	public void setYMax(double max) {
-		this.max=max;
-		this.userDefinedMax=true;
-	}
-	
-	public void setSize(int width, int height) {
-		this.width=width;
-		this.height=height;
-	}
-    public void setGraphType(String graphType) {
-    	if(graphType!=null) {
-            this.graphType = graphType;
-    	}
-    }
-    
-    public void setTitle(String title) {
-    	this.title=title;    	
-    }
-    
-    public void setId(String id) {
-    	this.id=id;
-    }
-    
-    public void setDataSet(String chartType, TreeMap<String, TreeMap<String, Double>> data) {
-    	if(this.dataset==null) {
-    		this.dataset = new ArrayList<TreeMap<String, TreeMap<String, Double>>>();
-    		this.chartType = new ArrayList<String>();
-    	}
-   		this.dataset.add(data);
-   		this.chartType.add(chartType);
-    }
-
-	public void setSeriesOrder(String[] metrics) {
-		this.seriesOrder = metrics;
-	}
-
-    public void setXAxisLabels(boolean toggle) {
-    	xLabelOn = toggle;
-    }
-
-    public void setYAxisLabels(boolean toggle) {
-    	yLabelOn = toggle;    	
-    }
-
-    public void setYAxisRightLabels(boolean toggle) {
-    	yRightLabelOn = toggle;    	
-    }
-
-    public void setXAxisLabel(String label) {
-    	xLabel = label;
-    }
-
-    public void setYAxisLabel(String label) {
-    	yLabel = label;
-    }
-
-    public void setYAxisRightLabel(String label) {
-    	yRightLabel = label;
-    }
-
-    public void setXLabelsRange(List<String> range) {
-    	xLabelRange = range;
-        xLabelRangeHash = new HashMap<String, Long>();
-        long value = 0;
-        for(String label : range) {
-            xLabelRangeHash.put(label,value);
-            value++;
-        }
-    }
-
-    public void setLegend(boolean toggle) {
-    	legend = toggle;
-    }
-    public String plot() {
-        SimpleDateFormat format = new SimpleDateFormat("m:s:S");
-    	StringBuilder output= new StringBuilder();
-    	if(dataset==null) {
-    		output.append("No Data available.");
-    		return output.toString();
-        }
-        String dateFormat="%H:%M";
-        if(xLabel.intern()=="Time".intern()) {
-            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-            long xMin;
-            try {
-                xMin = Long.parseLong(xLabelRange.get(0));
-                long xMax = Long.parseLong(xLabelRange.get(xLabelRange.size()-1));
-                if(xMax-xMin>31536000000L) {
-                    dateFormat="%y";
-                } else if(xMax-xMin>2592000000L) {
-                    dateFormat="%y-%m";
-                } else if(xMax-xMin>604800000L) {
-                    dateFormat="%m-%d";
-    	        } else if(xMax-xMin>86400000L) {
-                    dateFormat="%m-%d %H:%M";
-    	        }
-            } catch (NumberFormatException e) {
-                dateFormat="%y-%m-%d %H:%M";
-            }
-        }
-        StringBuilder xAxisOptions = new StringBuilder();
-        if(xLabel.intern()=="Time".intern()) {
-            xAxisOptions.append("timeformat: \"");
-            xAxisOptions.append(dateFormat);
-            xAxisOptions.append("\",mode: \"time\"");
-        } else {
-            xAxisOptions.append("tickFormatter: function (val, axis) { return xLabels[Math.round(val)]; }, ticks: 0");
-        }
-        if(request!=null && request.getParameter("format")==null) {
-            output.append("<html><link href=\"/hicc/css/default.css\" rel=\"stylesheet\" type=\"text/css\">\n");
-            output.append("<body onresize=\"wholePeriod()\"><script type=\"text/javascript\" src=\"/hicc/js/jquery-1.2.6.min.js\"></script>\n");
-            output.append("<script type=\"text/javascript\" src=\"/hicc/js/jquery.flot.pack.js\"></script>\n");
-            output.append("<script type=\"text/javascript\" src=\"/hicc/js/excanvas.pack.js\"></script>\n");
-            output.append("<div id=\"placeholderTitle\"><center>"+title+"</center></div>\n");
-            output.append("<div id=\"placeholder\" style=\"width:"+this.width+"px;height:"+this.height+"px;\"></div>\n");
-            output.append("<center><div id=\"placeholderLegend\"></div></center>\n");
-            output.append("<input type=\"hidden\" id=\"boxId\" value=\"iframe"+this.id+"\">\n");
-            output.append("<script type=\"text/javascript\" src=\"/hicc/js/flot.extend.js\">\n");
-            output.append("</script>\n");
-            output.append("<script type=\"text/javascript\">\n");
-            output.append("var chartTitle=\"<center>"+title+"</center>\";\n");
-            output.append("var height="+this.height+";\n");
-            output.append("var xLabels=new Array();\n");
-            output.append("var cw = document.body.clientWidth-70;\n");
-            output.append("var ch = document.body.clientHeight-50;\n");
-            output.append("document.getElementById('placeholder').style.width=cw+'px';\n");
-            output.append("document.getElementById('placeholder').style.height=ch+'px';\n");
-        }
-        output.append("_options={\n");
-        output.append("        points: { show: false },\n");
-        output.append("        xaxis: { "+xAxisOptions+" },\n");
-        output.append("	  selection: { mode: \"x\" },\n");
-        output.append("	  grid: {\n");
-        output.append("	           clickable: true,\n");
-        output.append("	           hoverable: true,\n");
-        output.append("	           tickColor: \"#C0C0C0\",\n");
-        output.append("	           backgroundColor:\"#FFFFFF\"\n");
-        output.append("	  },\n");
-        output.append("	  legend: { show: "+this.legend+", noColumns: 3, container: $(\"#placeholderLegend\") },\n");
-        output.append("        yaxis: { ");
-        boolean stack = false;
-        for(String type : this.chartType) {
-            if(type.startsWith("stack")) {
-                stack=true;
-            }
-        }
-        if(stack) {
-            output.append("mode: \"stack\", ");
-        }
-        if(userDefinedMax) {
-            output.append("tickFormatter: function(val, axis) { return val.toFixed(axis.tickDecimals) + \" %\"; }");
-        } else {
-            output.append("tickFormatter: function(val, axis) { ");
-            output.append("if (val >= 1000000000000000) return (val / 1000000000000000).toFixed(2) + \"x10<sup>15</sup>\";");
-            output.append("else if (val >= 100000000000000) return (val / 100000000000000).toFixed(2) + \"x10<sup>14</sup>\";");
-            output.append("else if (val >= 10000000000000) return (val / 10000000000000).toFixed(2) + \"x10<sup>13</sup>\";");
-            output.append("else if (val >= 1000000000000) return (val / 1000000000000).toFixed(2) + \"x10<sup>12</sup>\";");
-            output.append("else if (val >= 100000000000) return (val / 100000000000).toFixed(2) + \"x10<sup>11</sup>\";");
-            output.append("else if (val >= 10000000000) return (val / 10000000000).toFixed(2) + \"x10<sup>10</sup>\";");
-            output.append("else if (val >= 1000000000) return (val / 1000000000).toFixed(2) + \"x10<sup>9</sup>\";");
-            output.append("else if (val >= 100000000) return (val / 100000000).toFixed(2) + \"x10<sup>8</sup>\";");
-            output.append("else if (val >= 10000000) return (val / 10000000).toFixed(2) + \"x10<sup>7</sup>\";");
-            output.append("else if (val >= 1000000) return (val / 1000000).toFixed(2) + \"x10<sup>6</sup>\";");
-            output.append("else if (val >= 100000) return (val / 100000).toFixed(2) + \"x10<sup>5</sup>\";");
-            output.append("else if (val >= 10000) return (val / 10000).toFixed(2) + \"x10<sup>4</sup>\";");
-            output.append("else if (val >= 2000) return (val / 1000).toFixed(2) + \"x10<sup>3</sup>\";");
-            output.append("else return val.toFixed(2) + \"\"; }");
-        }
-        if(userDefinedMax) {
-            output.append(", min:0, max:");
-            output.append(this.max);
-        }
-        output.append("}\n");
-        output.append("	};\n");
-        if(!xLabel.equals("Time")) {
-            output.append("xLabels = [\"");
-            for(int i=0;i<xLabelRange.size();i++) {
-                if(i>0) {
-                    output.append("\",\"");
-                }
-                output.append(xLabelRange.get(i));
-            }
-            output.append("\"];\n");
-        }
-        output.append("_series=[\n");
-        ColorPicker cp = new ColorPicker();
-        int i=0;
-        for(TreeMap<String, TreeMap<String, Double>> dataMap : this.dataset) {
-		   	String[] keyNames = null;
-            if (this.seriesOrder != null) {
-                keyNames = this.seriesOrder;
+  private String id;
+  private String title;
+  private String graphType;
+  private ArrayList<TreeMap<String, TreeMap<String, Double>>> dataset;
+  private ArrayList<String> chartType;
+  private boolean xLabelOn;
+  private boolean yLabelOn;
+  private boolean yRightLabelOn;
+  private int width;
+  private int height;
+  private List<String> xLabelRange;
+  private HashMap<String, Long> xLabelRangeHash;
+  private HttpServletRequest request = null;
+  private boolean legend;
+  private String xLabel = "";
+  private String yLabel = "";
+  private String yRightLabel = "";
+  private int datasetCounter = 0;
+  private double max = 0;
+  private int seriesCounter = 0;
+  private List<String> rightList;
+  private boolean userDefinedMax = false;
+  private String[] seriesOrder = null;
+
+  public Chart(HttpServletRequest request) {
+    if (request != null && request.getParameter("boxId") != null) {
+      this.id = request.getParameter("boxId");
+    } else {
+      this.id = "0";
+    }
+    this.title = "Untitled Chart";
+    this.graphType = "image";
+    this.xLabelOn = true;
+    this.yLabelOn = true;
+    this.width = 400;
+    this.height = 200;
+    this.request = request;
+    this.legend = true;
+    this.max = 0;
+    this.datasetCounter = 0;
+    this.seriesCounter = 0;
+    this.rightList = new ArrayList<String>();
+    this.userDefinedMax = false;
+    this.seriesOrder = null;
+  }
+
+  public void setYMax(double max) {
+    this.max = max;
+    this.userDefinedMax = true;
+  }
+
+  public void setSize(int width, int height) {
+    this.width = width;
+    this.height = height;
+  }
+
+  public void setGraphType(String graphType) {
+    if (graphType != null) {
+      this.graphType = graphType;
+    }
+  }
+
+  public void setTitle(String title) {
+    this.title = title;
+  }
+
+  public void setId(String id) {
+    this.id = id;
+  }
+
+  public void setDataSet(String chartType,
+      TreeMap<String, TreeMap<String, Double>> data) {
+    if (this.dataset == null) {
+      this.dataset = new ArrayList<TreeMap<String, TreeMap<String, Double>>>();
+      this.chartType = new ArrayList<String>();
+    }
+    this.dataset.add(data);
+    this.chartType.add(chartType);
+  }
+
+  public void setSeriesOrder(String[] metrics) {
+    this.seriesOrder = metrics;
+  }
+
+  public void setXAxisLabels(boolean toggle) {
+    xLabelOn = toggle;
+  }
+
+  public void setYAxisLabels(boolean toggle) {
+    yLabelOn = toggle;
+  }
+
+  public void setYAxisRightLabels(boolean toggle) {
+    yRightLabelOn = toggle;
+  }
+
+  public void setXAxisLabel(String label) {
+    xLabel = label;
+  }
+
+  public void setYAxisLabel(String label) {
+    yLabel = label;
+  }
+
+  public void setYAxisRightLabel(String label) {
+    yRightLabel = label;
+  }
+
+  public void setXLabelsRange(List<String> range) {
+    xLabelRange = range;
+    xLabelRangeHash = new HashMap<String, Long>();
+    long value = 0;
+    for (String label : range) {
+      xLabelRangeHash.put(label, value);
+      value++;
+    }
+  }
+
+  public void setLegend(boolean toggle) {
+    legend = toggle;
+  }
+
+  public String plot() {
+    SimpleDateFormat format = new SimpleDateFormat("m:s:S");
+    StringBuilder output = new StringBuilder();
+    if (dataset == null) {
+      output.append("No Data available.");
+      return output.toString();
+    }
+    String dateFormat = "%H:%M";
+    if (xLabel.intern() == "Time".intern()) {
+      SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+      long xMin;
+      try {
+        xMin = Long.parseLong(xLabelRange.get(0));
+        long xMax = Long.parseLong(xLabelRange.get(xLabelRange.size() - 1));
+        if (xMax - xMin > 31536000000L) {
+          dateFormat = "%y";
+        } else if (xMax - xMin > 2592000000L) {
+          dateFormat = "%y-%m";
+        } else if (xMax - xMin > 604800000L) {
+          dateFormat = "%m-%d";
+        } else if (xMax - xMin > 86400000L) {
+          dateFormat = "%m-%d %H:%M";
+        }
+      } catch (NumberFormatException e) {
+        dateFormat = "%y-%m-%d %H:%M";
+      }
+    }
+    StringBuilder xAxisOptions = new StringBuilder();
+    if (xLabel.intern() == "Time".intern()) {
+      xAxisOptions.append("timeformat: \"");
+      xAxisOptions.append(dateFormat);
+      xAxisOptions.append("\",mode: \"time\"");
+    } else {
+      xAxisOptions
+          .append("tickFormatter: function (val, axis) { return xLabels[Math.round(val)]; }, ticks: 0");
+    }
+    if (request != null && request.getParameter("format") == null) {
+      output
+          .append("<html><link href=\"/hicc/css/default.css\" rel=\"stylesheet\" type=\"text/css\">\n");
+      output
+          .append("<body onresize=\"wholePeriod()\"><script type=\"text/javascript\" src=\"/hicc/js/jquery-1.2.6.min.js\"></script>\n");
+      output
+          .append("<script type=\"text/javascript\" src=\"/hicc/js/jquery.flot.pack.js\"></script>\n");
+      output
+          .append("<script type=\"text/javascript\" src=\"/hicc/js/excanvas.pack.js\"></script>\n");
+      output.append("<div id=\"placeholderTitle\"><center>" + title
+          + "</center></div>\n");
+      output.append("<div id=\"placeholder\" style=\"width:" + this.width
+          + "px;height:" + this.height + "px;\"></div>\n");
+      output.append("<center><div id=\"placeholderLegend\"></div></center>\n");
+      output.append("<input type=\"hidden\" id=\"boxId\" value=\"iframe"
+          + this.id + "\">\n");
+      output
+          .append("<script type=\"text/javascript\" src=\"/hicc/js/flot.extend.js\">\n");
+      output.append("</script>\n");
+      output.append("<script type=\"text/javascript\">\n");
+      output.append("var chartTitle=\"<center>" + title + "</center>\";\n");
+      output.append("var height=" + this.height + ";\n");
+      output.append("var xLabels=new Array();\n");
+      output.append("var cw = document.body.clientWidth-70;\n");
+      output.append("var ch = document.body.clientHeight-50;\n");
+      output
+          .append("document.getElementById('placeholder').style.width=cw+'px';\n");
+      output
+          .append("document.getElementById('placeholder').style.height=ch+'px';\n");
+    }
+    output.append("_options={\n");
+    output.append("        points: { show: false },\n");
+    output.append("        xaxis: { " + xAxisOptions + " },\n");
+    output.append("	  selection: { mode: \"x\" },\n");
+    output.append("	  grid: {\n");
+    output.append("	           clickable: true,\n");
+    output.append("	           hoverable: true,\n");
+    output.append("	           tickColor: \"#C0C0C0\",\n");
+    output.append("	           backgroundColor:\"#FFFFFF\"\n");
+    output.append("	  },\n");
+    output.append("	  legend: { show: " + this.legend
+        + ", noColumns: 3, container: $(\"#placeholderLegend\") },\n");
+    output.append("        yaxis: { ");
+    boolean stack = false;
+    for (String type : this.chartType) {
+      if (type.startsWith("stack")) {
+        stack = true;
+      }
+    }
+    if (stack) {
+      output.append("mode: \"stack\", ");
+    }
+    if (userDefinedMax) {
+      output
+          .append("tickFormatter: function(val, axis) { return val.toFixed(axis.tickDecimals) + \" %\"; }");
+    } else {
+      output.append("tickFormatter: function(val, axis) { ");
+      output
+          .append("if (val >= 1000000000000000) return (val / 1000000000000000).toFixed(2) + \"x10<sup>15</sup>\";");
+      output
+          .append("else if (val >= 100000000000000) return (val / 100000000000000).toFixed(2) + \"x10<sup>14</sup>\";");
+      output
+          .append("else if (val >= 10000000000000) return (val / 10000000000000).toFixed(2) + \"x10<sup>13</sup>\";");
+      output
+          .append("else if (val >= 1000000000000) return (val / 1000000000000).toFixed(2) + \"x10<sup>12</sup>\";");
+      output
+          .append("else if (val >= 100000000000) return (val / 100000000000).toFixed(2) + \"x10<sup>11</sup>\";");
+      output
+          .append("else if (val >= 10000000000) return (val / 10000000000).toFixed(2) + \"x10<sup>10</sup>\";");
+      output
+          .append("else if (val >= 1000000000) return (val / 1000000000).toFixed(2) + \"x10<sup>9</sup>\";");
+      output
+          .append("else if (val >= 100000000) return (val / 100000000).toFixed(2) + \"x10<sup>8</sup>\";");
+      output
+          .append("else if (val >= 10000000) return (val / 10000000).toFixed(2) + \"x10<sup>7</sup>\";");
+      output
+          .append("else if (val >= 1000000) return (val / 1000000).toFixed(2) + \"x10<sup>6</sup>\";");
+      output
+          .append("else if (val >= 100000) return (val / 100000).toFixed(2) + \"x10<sup>5</sup>\";");
+      output
+          .append("else if (val >= 10000) return (val / 10000).toFixed(2) + \"x10<sup>4</sup>\";");
+      output
+          .append("else if (val >= 2000) return (val / 1000).toFixed(2) + \"x10<sup>3</sup>\";");
+      output.append("else return val.toFixed(2) + \"\"; }");
+    }
+    if (userDefinedMax) {
+      output.append(", min:0, max:");
+      output.append(this.max);
+    }
+    output.append("}\n");
+    output.append("	};\n");
+    if (!xLabel.equals("Time")) {
+      output.append("xLabels = [\"");
+      for (int i = 0; i < xLabelRange.size(); i++) {
+        if (i > 0) {
+          output.append("\",\"");
+        }
+        output.append(xLabelRange.get(i));
+      }
+      output.append("\"];\n");
+    }
+    output.append("_series=[\n");
+    ColorPicker cp = new ColorPicker();
+    int i = 0;
+    for (TreeMap<String, TreeMap<String, Double>> dataMap : this.dataset) {
+      String[] keyNames = null;
+      if (this.seriesOrder != null) {
+        keyNames = this.seriesOrder;
+      } else {
+        keyNames = ((String[]) dataMap.keySet().toArray(
+            new String[dataMap.size()]));
+      }
+      int counter = 0;
+      if (i != 0) {
+        if (!this.userDefinedMax) {
+          this.max = 0;
+        }
+      }
+      for (String seriesName : keyNames) {
+        int counter2 = 0;
+        if (counter != 0) {
+          output.append(",");
+        }
+        String param = "fill: false";
+        String type = "lines";
+        if (this.chartType.get(i).intern() == "stack-area".intern()
+            || this.chartType.get(i).intern() == "area".intern()) {
+          param = "fill: true";
+        }
+        if (this.chartType.get(i).intern() == "bar".intern()) {
+          type = "bars";
+          param = "stepByStep: true";
+        }
+        if (this.chartType.get(i).intern() == "point".intern()) {
+          type = "points";
+          param = "fill: false";
+        }
+        output.append("  {");
+        output.append(type);
+        output.append(": { show: true, ");
+        output.append(param);
+        output.append(" }, color: \"");
+        output.append(cp.get(counter + 1));
+        output.append("\", label: \"");
+        output.append(seriesName);
+        output.append("\", ");
+        String showYAxis = "false";
+        String shortRow = "false";
+        if (counter == 0 || i > 0) {
+          showYAxis = "true";
+          shortRow = "false";
+        }
+        output.append(" row: { show: ");
+        output.append(showYAxis);
+        output.append(",shortRow:");
+        output.append(shortRow);
+        output.append(", showYAxis:");
+        output.append(showYAxis);
+        output.append("}, data:[");
+        TreeMap<String, Double> data = dataMap.get(seriesName);
+        for (String dp : data.keySet()) {
+          int rangeLabel = 0;
+          if (counter2 != 0) {
+            output.append(",");
+          }
+          if (xLabel.equals("Time")) {
+            if (data.get(dp) == Double.NaN) {
+              output.append("[\"");
+              output.append(dp);
+              output.append("\",NULL]");
             } else {
-                keyNames = ((String[]) dataMap.keySet().toArray(
-                        new String[dataMap.size()]));
-            }
-            int counter = 0;
-            if (i != 0) {
-                if (!this.userDefinedMax) {
-                    this.max = 0;
-                }
+              output.append("[\"");
+              output.append(dp);
+              output.append("\",");
+              output.append(data.get(dp));
+              output.append("]");
             }
-            for (String seriesName : keyNames) {
-                int counter2 = 0;
-                if (counter != 0) {
-                    output.append(",");
-                }
-                String param = "fill: false";
-                String type = "lines";
-                if (this.chartType.get(i).intern() == "stack-area".intern()
-                        || this.chartType.get(i).intern() == "area".intern()) {
-                    param = "fill: true";
-                }
-                if (this.chartType.get(i).intern() == "bar".intern()) {
-                    type = "bars";
-                    param = "stepByStep: true";
-                }
-                if (this.chartType.get(i).intern() == "point".intern()) {
-                    type = "points";
-                    param = "fill: false";
-                }
-                output.append("  {");
-                output.append(type);
-                output.append(": { show: true, ");
-                output.append(param);
-                output.append(" }, color: \"");
-                output.append(cp.get(counter + 1));
-                output.append("\", label: \"");
-                output.append(seriesName);
-                output.append("\", ");
-                String showYAxis = "false";
-                String shortRow = "false";
-                if (counter == 0 || i > 0) {
-                    showYAxis = "true";
-                    shortRow = "false";
-                }
-                output.append(" row: { show: ");
-                output.append(showYAxis);
-                output.append(",shortRow:");
-                output.append(shortRow);
-                output.append(", showYAxis:");
-                output.append(showYAxis);
-                output.append("}, data:[");
-                TreeMap<String, Double> data = dataMap.get(seriesName);
-                for (String dp : data.keySet()) {
-                    int rangeLabel = 0;
-                    if (counter2 != 0) {
-                        output.append(",");
-                    }
-                    if (xLabel.equals("Time")) {
-                        if (data.get(dp) == Double.NaN) {
-                            output.append("[\"");
-                            output.append(dp);
-                            output.append("\",NULL]");
-                        } else {
-                            output.append("[\"");
-                            output.append(dp);
-                            output.append("\",");
-                            output.append(data.get(dp));
-                            output.append("]");
-                        }
-                    } else {
-                        long value = xLabelRangeHash.get(dp);
-                        if (data.get(dp) == Double.NaN) {
-                            output.append("[\"");
-                            output.append(value);
-                            output.append("\",NULL]");
-                        } else {
-                            output.append("[\"");
-                            output.append(value);
-                            output.append("\",");
-                            output.append(data.get(dp));
-                            output.append("]");
-                        }
-                        rangeLabel++;
-                    }
-                    counter2++;
-                }
-                output.append("], min:0");
-                if (this.userDefinedMax) {
-                    output.append(", max:");
-                    output.append(this.max);
-                }
-                output.append("}");
-                counter++;
+          } else {
+            long value = xLabelRangeHash.get(dp);
+            if (data.get(dp) == Double.NaN) {
+              output.append("[\"");
+              output.append(value);
+              output.append("\",NULL]");
+            } else {
+              output.append("[\"");
+              output.append(value);
+              output.append("\",");
+              output.append(data.get(dp));
+              output.append("]");
             }
-            i++;
-        }          
-        output.append(" ];\n");
-        if(request!=null && request.getParameter("format")==null) {
-            output.append(" wholePeriod();</script></body></html>\n");
-        } else {
-            output.append("chartTitle=\"<center>"+this.title+"</center>\";");
-            output.append("height="+this.height+";");
-        }
-    	return output.toString();
-    }            
+            rangeLabel++;
+          }
+          counter2++;
+        }
+        output.append("], min:0");
+        if (this.userDefinedMax) {
+          output.append(", max:");
+          output.append(this.max);
+        }
+        output.append("}");
+        counter++;
+      }
+      i++;
+    }
+    output.append(" ];\n");
+    if (request != null && request.getParameter("format") == null) {
+      output.append(" wholePeriod();</script></body></html>\n");
+    } else {
+      output.append("chartTitle=\"<center>" + this.title + "</center>\";");
+      output.append("height=" + this.height + ";");
+    }
+    return output.toString();
+  }
 }

Modified: hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/hicc/ClusterConfig.java
URL: http://svn.apache.org/viewvc/hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/hicc/ClusterConfig.java?rev=752666&r1=752665&r2=752666&view=diff
==============================================================================
--- hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/hicc/ClusterConfig.java (original)
+++ hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/hicc/ClusterConfig.java Wed Mar 11 22:39:26 2009
@@ -18,61 +18,61 @@
 
 package org.apache.hadoop.chukwa.hicc;
 
+
 import java.io.*;
 import java.util.*;
 
 public class ClusterConfig {
-    public static HashMap<String, String> clusterMap = new HashMap<String, String>();
-    private String path=System.getenv("CHUKWA_CONF_DIR")+File.separator;
-    static public String getContents(File aFile) {
-        //...checks on aFile are elided
-        StringBuffer contents = new StringBuffer();
-   
-        try {
-          //use buffering, reading one line at a time
-          //FileReader always assumes default encoding is OK!
-          BufferedReader input =  new BufferedReader(new FileReader(aFile));
-          try {
-             String line = null; //not declared within while loop
-             /*
-              * readLine is a bit quirky :
-              * it returns the content of a line MINUS the newline.
-              * it returns null only for the END of the stream.
-              * it returns an empty String if two newlines appear in a row.
-              */
-             while (( line = input.readLine()) != null){
-                contents.append(line);
-                contents.append(System.getProperty("line.separator"));
-             }
-          } finally {
-             input.close();
-          }
-        }
-          catch (IOException ex){
-          ex.printStackTrace();
-        }
+  public static HashMap<String, String> clusterMap = new HashMap<String, String>();
+  private String path = System.getenv("CHUKWA_CONF_DIR") + File.separator;
 
-        return contents.toString();
-    }
-
-    public ClusterConfig() {
-        File cc = new File(path+"jdbc.conf");
-        String buffer = getContents(cc);
-        String[] lines = buffer.split("\n");
-        for(String line: lines) {
-            String[] data = line.split("=",2);
-            clusterMap.put(data[0],data[1]);
+  static public String getContents(File aFile) {
+    // ...checks on aFile are elided
+    StringBuffer contents = new StringBuffer();
+
+    try {
+      // use buffering, reading one line at a time
+      // FileReader always assumes default encoding is OK!
+      BufferedReader input = new BufferedReader(new FileReader(aFile));
+      try {
+        String line = null; // not declared within while loop
+        /*
+         * readLine is a bit quirky : it returns the content of a line MINUS the
+         * newline. it returns null only for the END of the stream. it returns
+         * an empty String if two newlines appear in a row.
+         */
+        while ((line = input.readLine()) != null) {
+          contents.append(line);
+          contents.append(System.getProperty("line.separator"));
         }
+      } finally {
+        input.close();
+      }
+    } catch (IOException ex) {
+      ex.printStackTrace();
     }
 
-    public String getURL(String cluster) {
-        String url = clusterMap.get(cluster);
-        return url; 
+    return contents.toString();
+  }
+
+  public ClusterConfig() {
+    File cc = new File(path + "jdbc.conf");
+    String buffer = getContents(cc);
+    String[] lines = buffer.split("\n");
+    for (String line : lines) {
+      String[] data = line.split("=", 2);
+      clusterMap.put(data[0], data[1]);
     }
+  }
 
-    public Iterator<String> getClusters() {
-        Set<String> keys = clusterMap.keySet();
-        Iterator<String> i = keys.iterator();
-        return i;
-    }    
+  public String getURL(String cluster) {
+    String url = clusterMap.get(cluster);
+    return url;
+  }
+
+  public Iterator<String> getClusters() {
+    Set<String> keys = clusterMap.keySet();
+    Iterator<String> i = keys.iterator();
+    return i;
+  }
 }

Modified: hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/hicc/ColorPicker.java
URL: http://svn.apache.org/viewvc/hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/hicc/ColorPicker.java?rev=752666&r1=752665&r2=752666&view=diff
==============================================================================
--- hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/hicc/ColorPicker.java (original)
+++ hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/hicc/ColorPicker.java Wed Mar 11 22:39:26 2009
@@ -18,32 +18,33 @@
 
 package org.apache.hadoop.chukwa.hicc;
 
+
 public class ColorPicker {
-	private String color = "#ff5757";
+  private String color = "#ff5757";
 
-	public ColorPicker() {
-    	color = "#ff5757";
-    }
-	
-    public String get(int counter) {
-        if((counter % 6)==0) {
-            String cyan = Integer.toHexString(256-(counter % 255));
-            color = "#57"+cyan+cyan;
-        } else if((counter % 5)==0) {
-            String purple = Integer.toHexString(256-(counter % 255));
-            color = "#"+purple+"57"+purple;
-        } else if((counter % 4)==0) {
-            String yellow = Integer.toHexString(256-(counter % 255 * 20));
-            color = "#FF"+yellow+"00";
-        } else if((counter % 3)==0) {
-            String green = Integer.toHexString(256-(counter % 255));
-            color = "#57"+green+"57";
-        } else if((counter % 2)==0) {
-            String blue = Integer.toHexString(256-(counter % 255));
-            color = "#5757"+blue+"";
-        } else {
-            color = "#ff5757";
-        }
-        return this.color;
+  public ColorPicker() {
+    color = "#ff5757";
+  }
+
+  public String get(int counter) {
+    if ((counter % 6) == 0) {
+      String cyan = Integer.toHexString(256 - (counter % 255));
+      color = "#57" + cyan + cyan;
+    } else if ((counter % 5) == 0) {
+      String purple = Integer.toHexString(256 - (counter % 255));
+      color = "#" + purple + "57" + purple;
+    } else if ((counter % 4) == 0) {
+      String yellow = Integer.toHexString(256 - (counter % 255 * 20));
+      color = "#FF" + yellow + "00";
+    } else if ((counter % 3) == 0) {
+      String green = Integer.toHexString(256 - (counter % 255));
+      color = "#57" + green + "57";
+    } else if ((counter % 2) == 0) {
+      String blue = Integer.toHexString(256 - (counter % 255));
+      color = "#5757" + blue + "";
+    } else {
+      color = "#ff5757";
     }
+    return this.color;
+  }
 }

Modified: hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/hicc/Config.java
URL: http://svn.apache.org/viewvc/hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/hicc/Config.java?rev=752666&r1=752665&r2=752666&view=diff
==============================================================================
--- hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/hicc/Config.java (original)
+++ hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/hicc/Config.java Wed Mar 11 22:39:26 2009
@@ -18,6 +18,7 @@
 
 package org.apache.hadoop.chukwa.hicc;
 
+
 public class Config {
 
 }



Mime
View raw message