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