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.hicc;
20
21
22 import java.io.*;
23 import java.util.*;
24
25 import org.apache.hadoop.chukwa.datastore.ChukwaHBaseStore;
26
27 public class ClusterConfig {
28 private static Set<String> clusterMap = null;
29
30 static public String getContents(File aFile) {
31 // ...checks on aFile are elided
32 StringBuffer contents = new StringBuffer();
33
34 try {
35 // use buffering, reading one line at a time
36 // FileReader always assumes default encoding is OK!
37 BufferedReader input = new BufferedReader(new FileReader(aFile));
38 try {
39 String line = null; // not declared within while loop
40 /*
41 * readLine is a bit quirky : it returns the content of a line MINUS the
42 * newline. it returns null only for the END of the stream. it returns
43 * an empty String if two newlines appear in a row.
44 */
45 while ((line = input.readLine()) != null) {
46 contents.append(line);
47 contents.append(System.getProperty("line.separator"));
48 }
49 } finally {
50 input.close();
51 }
52 } catch (IOException ex) {
53 ex.printStackTrace();
54 }
55
56 return contents.toString();
57 }
58
59 public ClusterConfig() {
60 long end = System.currentTimeMillis();
61 long start = end - 3600000L;
62 if(clusterMap==null) {
63 clusterMap = ChukwaHBaseStore.getClusterNames(start, end);
64 }
65 }
66
67 public Iterator<String> getClusters() {
68 Iterator<String> i = clusterMap.iterator();
69 return i;
70 }
71 }