This project has retired. For details please refer to its Attic page.
ParseUtilities xref
View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  package org.apache.hadoop.chukwa.analysis.salsa.fsm;
20  
21  import java.util.StringTokenizer;
22  
23  /**
24   * Parse Utilities for Parsing ChukwaRecords for FSMBuilder Mappers
25   *
26   */
27  
28  public class ParseUtilities {
29  	
30  	public static FSMIntermedEntry splitChukwaRecordKey
31  		(String origkey, FSMIntermedEntry rec, String delim) 
32  		throws Exception
33  	{
34  		StringTokenizer st = new StringTokenizer(origkey, delim);
35  		if (st.countTokens() != 3) {
36  			throw new Exception("Expected 3 tokens from ChukwaRecordKey but only found " + st.countTokens() + ".");
37  		}
38  		rec.time_orig_epoch = new String(st.nextToken());
39  		rec.job_id = new String(st.nextToken());
40  		rec.time_orig = new String(st.nextToken());
41  		return rec;
42  	}
43  	
44  	public static String extractHostnameFromTrackerName (String trackerName) 
45  	{
46  		int firstPos = "tracker_".length();
47  		int secondPos;
48  		String hostname = new String("");
49  		
50  		if (trackerName.startsWith("tracker_")) {
51  			secondPos = trackerName.indexOf(":",firstPos);
52  			hostname = trackerName.substring(firstPos, secondPos);
53  		}
54  		
55  		return hostname;
56  	}
57  	
58  	public static String removeRackFromHostname (String origHostname) 
59  	{
60  		int pos = origHostname.lastIndexOf("/");
61  		if (pos > -1) {
62  			return new String(origHostname.substring(pos));
63  		} else {
64  			return new String(origHostname);
65  		}
66  	}
67  	
68  }