1/*2 * Licensed to the Apache Software Foundation (ASF) under one3 * or more contributor license agreements. See the NOTICE file4 * distributed with this work for additional information5 * regarding copyright ownership. The ASF licenses this file6 * to you under the Apache License, Version 2.0 (the7 * "License"); you may not use this file except in compliance8 * with the License. You may obtain a copy of the License at9 *10 * http://www.apache.org/licenses/LICENSE-2.011 *12 * Unless required by applicable law or agreed to in writing, software13 * 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 and16 * limitations under the License.17 */1819package org.apache.hadoop.chukwa.analysis.salsa.fsm;
2021import java.util.StringTokenizer;
2223/**24 * Parse Utilities for Parsing ChukwaRecords for FSMBuilder Mappers25 *26 */2728publicclassParseUtilities {
2930publicstaticFSMIntermedEntry splitChukwaRecordKey
31 (String origkey, FSMIntermedEntry rec, String delim)
32throws Exception
33 {
34 StringTokenizer st = new StringTokenizer(origkey, delim);
35if (st.countTokens() != 3) {
36thrownew 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());
41return rec;
42 }
4344publicstatic String extractHostnameFromTrackerName (String trackerName)
45 {
46int firstPos = "tracker_".length();
47int secondPos;
48 String hostname = new String("");
4950if (trackerName.startsWith("tracker_")) {
51 secondPos = trackerName.indexOf(":",firstPos);
52 hostname = trackerName.substring(firstPos, secondPos);
53 }
5455return hostname;
56 }
5758publicstatic String removeRackFromHostname (String origHostname)
59 {
60int pos = origHostname.lastIndexOf("/");
61if (pos > -1) {
62returnnew String(origHostname.substring(pos));
63 } else {
64returnnew String(origHostname);
65 }
66 }
6768 }