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.datacollection.writer.hbase;
2021import java.io.IOException;
22import java.util.ArrayList;
23import java.util.List;
2425import org.apache.hadoop.chukwa.extraction.engine.ChukwaRecord;
26import org.apache.hadoop.chukwa.extraction.engine.ChukwaRecordKey;
27import org.apache.hadoop.hbase.client.Put;
2829publicclassOutputCollectorimplements30 org.apache.hadoop.mapred.OutputCollector<ChukwaRecordKey, ChukwaRecord> {
3132private List<Put> buffers;
33private StringBuffer s = new StringBuffer();
34private byte[] rowKey = null;
35private byte[] cf = null;
36privatelong now = 0L;
3738publicOutputCollector() {
39 buffers = new ArrayList<Put>();
40 }
4142 @Override
43publicvoid collect(ChukwaRecordKey key, ChukwaRecord value) throws IOException {
44 String[] keyParts = key.getKey().split("/");
45 s.setLength(0);
46 s.append(keyParts[2]);
47 s.append("-");
48 s.append(keyParts[1]);
4950 rowKey = s.toString().getBytes();
5152 cf = key.getReduceType().getBytes();
53 now = value.getTime();
5455 Put kv = new Put(rowKey);
56for(String field : value.getFields()) {
57 kv.add(cf, field.getBytes(), now , value.getValue(field).getBytes());
58 }
59 buffers.add(kv);
60 }
6162public List<Put> getKeyValues() {
63return buffers;
64 }
6566publicvoid clear() {
67 s.setLength(0);
68 rowKey = null;
69 cf = null;
70 buffers.clear();
71 }
7273 }