Author: liyin Date: Wed Apr 9 18:18:28 2014 New Revision: 1586065 URL: http://svn.apache.org/r1586065 Log: [HBASE-2000] Move endpoints into separate package for better organization
Author: adela Test Plan: N/A Reviewers: daviddeng Reviewed By: daviddeng CC: hbase-eng@ Differential Revision: https://phabricator.fb.com/D1265777 Added: hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/endpoints/ hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/endpoints/EndpointLib.java - copied, changed from r1586064, hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/EndpointLib.java hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/endpoints/EndpointManager.java - copied, changed from r1586064, hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/EndpointManager.java hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/endpoints/EndpointServer.java - copied, changed from r1586064, hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/EndpointServer.java hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/endpoints/HTableEndpointClient.java - copied, changed from r1586064, hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/HTableEndpointClient.java hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/endpoints/IEndpoint.java - copied, changed from r1586064, hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/IEndpoint.java hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/endpoints/IEndpointClient.java - copied, changed from r1586064, hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/IEndpointClient.java hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/endpoints/IEndpointContext.java - copied, changed from r1586064, hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/IEndpointContext.java hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/endpoints/IEndpointFactory.java - copied, changed from r1586064, hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/IEndpointFactory.java hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/coprocessor/endpoints/ hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/coprocessor/endpoints/TestEndpoint.java - copied, changed from r1586064, hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/coprocessor/TestEndpoint.java Modified: hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/client/HTable.java hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/EndpointLib.java hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/EndpointManager.java hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/EndpointServer.java hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/HTableEndpointClient.java hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/IEndpoint.java hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/IEndpointClient.java hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/IEndpointContext.java hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/IEndpointFactory.java hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/regionserver/ThriftHRegionServer.java hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/coprocessor/TestEndpoint.java Modified: hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/client/HTable.java URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/client/HTable.java?rev=1586065&r1=1586064&r2=1586065&view=diff ============================================================================== --- hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/client/HTable.java (original) +++ hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/client/HTable.java Wed Apr 9 18:18:28 2014 @@ -47,9 +47,9 @@ import org.apache.hadoop.hbase.HServerAd import org.apache.hadoop.hbase.HTableDescriptor; import org.apache.hadoop.hbase.KeyValue; import org.apache.hadoop.hbase.client.MetaScanner.MetaScannerVisitor; -import org.apache.hadoop.hbase.coprocessor.HTableEndpointClient; -import org.apache.hadoop.hbase.coprocessor.IEndpoint; -import org.apache.hadoop.hbase.coprocessor.IEndpointClient; +import org.apache.hadoop.hbase.coprocessor.endpoints.HTableEndpointClient; +import org.apache.hadoop.hbase.coprocessor.endpoints.IEndpoint; +import org.apache.hadoop.hbase.coprocessor.endpoints.IEndpointClient; import org.apache.hadoop.hbase.io.hfile.Compression; import org.apache.hadoop.hbase.io.hfile.PreloadThreadPool; import org.apache.hadoop.hbase.io.hfile.histogram.HFileHistogram.Bucket; Modified: hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/EndpointLib.java URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/EndpointLib.java?rev=1586065&r1=1586064&r2=1586065&view=diff ============================================================================== --- hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/EndpointLib.java (original) +++ hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/EndpointLib.java Wed Apr 9 18:18:28 2014 @@ -1,62 +0,0 @@ -/** - * Copyright 2014 The Apache Software Foundation - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.hadoop.hbase.coprocessor; - -import java.io.IOException; -import java.util.ArrayList; - -import org.apache.hadoop.hbase.KeyValue; -import org.apache.hadoop.hbase.client.Scan; -import org.apache.hadoop.hbase.regionserver.HRegion; -import org.apache.hadoop.hbase.regionserver.InternalScanner; - -/** - * Some algorithm library for implementing endpoints. - * - * Current implemented: - * aggregateScan aggregate key-values defined by a Scan - */ -public class EndpointLib { - /** - * An interface for aggregateScan - */ - interface IAggregator { - void aggregate(KeyValue kv); - } - - /** - * Aggregates all KeyValue's in a region defined by a Scan. - */ - public static void aggregateScan(HRegion region, Scan scan, IAggregator aggr) - throws IOException { - try (InternalScanner scanner = region.getScanner(scan)) { - ArrayList<KeyValue> kvs = new ArrayList<>(); - boolean hasMore = true; - while (hasMore) { - kvs.clear(); - hasMore = scanner.next(kvs); - for (KeyValue kv : kvs) { - aggr.aggregate(kv); - } - } - } - } - -} Modified: hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/EndpointManager.java URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/EndpointManager.java?rev=1586065&r1=1586064&r2=1586065&view=diff ============================================================================== --- hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/EndpointManager.java (original) +++ hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/EndpointManager.java Wed Apr 9 18:18:28 2014 @@ -1,55 +0,0 @@ -/** - * Copyright 2014 The Apache Software Foundation - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.hadoop.hbase.coprocessor; - -import java.util.concurrent.ConcurrentHashMap; - -/** - * The manager holding all endpoint factories in the server. - * - */ -public class EndpointManager { - private static EndpointManager instance = new EndpointManager(); - - /** - * Returns the singleton endpoint-manager - */ - public static EndpointManager get() { - return instance; - } - - private ConcurrentHashMap<String, IEndpointFactory<?>> nameFacts = new ConcurrentHashMap<>(); - - /** - * Returns the factory of an endpoint. - */ - public IEndpointFactory<?> getFactory(String name) { - return nameFacts.get(name); - - } - - /** - * Register an endpoint with its factory - */ - public <T extends IEndpoint> void register(Class<T> iEndpoint, - IEndpointFactory<T> factory) { - nameFacts.put(iEndpoint.getName(), factory); - } -} Modified: hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/EndpointServer.java URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/EndpointServer.java?rev=1586065&r1=1586064&r2=1586065&view=diff ============================================================================== --- hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/EndpointServer.java (original) +++ hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/EndpointServer.java Wed Apr 9 18:18:28 2014 @@ -1,96 +0,0 @@ -/** - * Copyright 2014 The Apache Software Foundation - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.hadoop.hbase.coprocessor; - -import java.lang.reflect.Method; - -import org.apache.hadoop.hbase.DoNotRetryIOException; -import org.apache.hadoop.hbase.NotServingRegionException; -import org.apache.hadoop.hbase.ipc.thrift.exceptions.ThriftHBaseException; -import org.apache.hadoop.hbase.regionserver.HRegion; -import org.apache.hadoop.hbase.regionserver.HRegionServer; - -/** - * A endpoint server. - */ -public class EndpointServer { - - private HRegionServer server; - - public EndpointServer(HRegionServer server) { - this.server = server; - } - - /** - * Calls an endpoint on an region server. - * - * TODO make regionName a list. - * - * @param epName - * the endpoint name. - * @param methodName - * the method name. - * @param regionName - * the name of the region - * @param startRow - * the start row, inclusive - * @param stopRow - * the stop row, exclusive - * @return the computed value. - */ - public byte[] callEndpoint(String epName, String methodName, - final byte[] regionName, final byte[] startRow, final byte[] stopRow) - throws ThriftHBaseException { - try { - IEndpointFactory<?> fact = EndpointManager.get().getFactory(epName); - if (fact == null) { - // TODO daviddeng make a special exception for this - throw new DoNotRetryIOException("Endpoint " + epName - + " does not exists"); - } - IEndpoint ep = fact.create(); - - ep.setContext(new IEndpointContext() { - @Override - public HRegion getRegion() throws NotServingRegionException { - return EndpointServer.this.server.getRegion(regionName); - } - - @Override - public byte[] getStartRow() { - return startRow; - } - - @Override - public byte[] getStopRow() { - return stopRow; - } - }); - - // TODO daviddeng: now we only support methods without any parameters. - Method mth = ep.getClass().getMethod(methodName); - return (byte[]) mth.invoke(ep); - } catch (Exception e) { - // TODO daviddeng if the method is not found, should throw - // DoNotRetryIOException - throw new ThriftHBaseException(e); - } - } -} Modified: hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/HTableEndpointClient.java URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/HTableEndpointClient.java?rev=1586065&r1=1586064&r2=1586065&view=diff ============================================================================== --- hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/HTableEndpointClient.java (original) +++ hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/HTableEndpointClient.java Wed Apr 9 18:18:28 2014 @@ -1,103 +0,0 @@ -/** - * Copyright 2014 The Apache Software Foundation - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.hadoop.hbase.coprocessor; - -import java.io.IOException; -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.Method; -import java.lang.reflect.Proxy; -import java.util.Map; -import java.util.NavigableMap; -import java.util.TreeMap; - -import org.apache.hadoop.hbase.HConstants; -import org.apache.hadoop.hbase.HRegionInfo; -import org.apache.hadoop.hbase.HServerAddress; -import org.apache.hadoop.hbase.client.HConnection; -import org.apache.hadoop.hbase.client.HTable; -import org.apache.hadoop.hbase.client.ServerCallable; -import org.apache.hadoop.hbase.util.Bytes; - -/** - * A IEndpointClient served as part of an HTable. - */ -public class HTableEndpointClient implements IEndpointClient { - private HTable table; - - public HTableEndpointClient(HTable table) { - this.table = table; - } - - /** - * Returns an proxy instance for an IEndpont. - * - * @param clazz - * the class of the endpoint interface to call. - * @param region - * the region info - * @param startRow - * the start row - * @param stopRow - * the end row - */ - @SuppressWarnings("unchecked") - protected <T extends IEndpoint> T getEndpointProxy(final Class<T> clazz, - final HRegionInfo region, final byte[] startRow, final byte[] stopRow) { - - InvocationHandler handler = new InvocationHandler() { - @Override - public Object invoke(Object proxy, final Method method, Object[] args) - throws Throwable { - HConnection conn = table.getConnectionAndResetOperationContext(); - return conn.getRegionServerWithRetries(new ServerCallable<byte[]>( - table.getConnection(), table.getTableNameStringBytes(), - region.getStartKey(), table.getOptions()) { - @Override - public byte[] call() throws IOException { - // TODO support arguments - return server.callEndpoint(clazz.getName(), method.getName(), - region.getRegionName(), startRow, stopRow); - } - }); - } - }; - - return (T) Proxy.newProxyInstance(clazz.getClassLoader(), - new Class<?>[] { clazz }, handler); - } - - @Override - public <T extends IEndpoint> Map<byte[], byte[]> coprocessorEndpoint( - Class<T> clazz, byte[] startRow, byte[] stopRow, Caller<T> caller) - throws IOException { - Map<byte[], byte[]> results = new TreeMap<>(Bytes.BYTES_COMPARATOR); - - NavigableMap<HRegionInfo, HServerAddress> regions = table.getRegionsInfo(); - - for (final HRegionInfo region : regions.keySet()) { - // TODO compute startRow and stopRow - T ep = getEndpointProxy(clazz, region, HConstants.EMPTY_BYTE_ARRAY, - HConstants.EMPTY_BYTE_ARRAY); - results.put(region.getRegionName(), caller.call(ep)); - } - - return results; - } -} Modified: hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/IEndpoint.java URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/IEndpoint.java?rev=1586065&r1=1586064&r2=1586065&view=diff ============================================================================== --- hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/IEndpoint.java (original) +++ hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/IEndpoint.java Wed Apr 9 18:18:28 2014 @@ -1,35 +0,0 @@ -/** - * Copyright 2014 The Apache Software Foundation - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.hadoop.hbase.coprocessor; - -/** - * The common parent of all endpoint interfaces. - */ -public interface IEndpoint { - - /** - * Called to set the endpoint context. The implementation can save the - * instance. - * - * @param a - * non-null IEndpointContext - */ - void setContext(IEndpointContext context); -} Modified: hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/IEndpointClient.java URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/IEndpointClient.java?rev=1586065&r1=1586064&r2=1586065&view=diff ============================================================================== --- hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/IEndpointClient.java (original) +++ hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/IEndpointClient.java Wed Apr 9 18:18:28 2014 @@ -1,66 +0,0 @@ -/** - * Copyright 2014 The Apache Software Foundation - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.hadoop.hbase.coprocessor; - -import java.io.IOException; -import java.util.Map; - -/** - * The interface of a client for calling a endpoint. - */ -public interface IEndpointClient { - - /** - * The interface of a caller for <code>coprocessorEndpoint</code> - * - * @param <T> - * The type of the endpoint interface. (NOT the implementation) - */ - public interface Caller<T extends IEndpoint> { - - /** - * Calls an endpoint. - * - * @param client - * an RPC client. - * @return the result to be put as a value in coprocessorEndpoint's results - */ - byte[] call(T client) throws IOException; - } - - /** - * Calls an endpoint in the server side and returns results. - * - * The <tt>caller</tt> is called for every region provied with an RPC client - * with the same time as the endpoint interface. - * - * @param clazz - * the class of the endpoint interface. - * @param startRow - * the start row. null or empty array means no limit on start. - * @param stopRow - * the stop row. null or empty array means no limit on stop. - * @param caller - * the caller for each region - * @return a map from region name to results. - */ - <T extends IEndpoint> Map<byte[], byte[]> coprocessorEndpoint(Class<T> clazz, - byte[] startRow, byte[] stopRow, Caller<T> caller) throws IOException; -} Modified: hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/IEndpointContext.java URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/IEndpointContext.java?rev=1586065&r1=1586064&r2=1586065&view=diff ============================================================================== --- hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/IEndpointContext.java (original) +++ hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/IEndpointContext.java Wed Apr 9 18:18:28 2014 @@ -1,48 +0,0 @@ -/** - * Copyright 2014 The Apache Software Foundation - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.hadoop.hbase.coprocessor; - -import org.apache.hadoop.hbase.NotServingRegionException; -import org.apache.hadoop.hbase.regionserver.HRegion; - -/** - * The context of an endpoint calling. - * - * TODO add more functions if necessary for access more resource on the server. - */ -public interface IEndpointContext { - /** - * Returns an HRegion instance. - * - * @throws NotServingRegionException - * if the region is not served on this server. - */ - HRegion getRegion() throws NotServingRegionException; - - /** - * The start row, inclusive, within this region of this call. - */ - byte[] getStartRow(); - - /** - * The stop row, exclusive, within this region of this call. - */ - byte[] getStopRow(); -} Modified: hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/IEndpointFactory.java URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/IEndpointFactory.java?rev=1586065&r1=1586064&r2=1586065&view=diff ============================================================================== --- hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/IEndpointFactory.java (original) +++ hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/IEndpointFactory.java Wed Apr 9 18:18:28 2014 @@ -1,33 +0,0 @@ -/** - * Copyright 2014 The Apache Software Foundation - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.hadoop.hbase.coprocessor; - -/** - * The factory for generating IEndpoint instances. - * - * @param <T> - * The type of the endpoint interface - */ -public interface IEndpointFactory<T extends IEndpoint> { - /** - * Creates a new instance of the endpoint instance. - */ - T create(); -} Copied: hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/endpoints/EndpointLib.java (from r1586064, hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/EndpointLib.java) URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/endpoints/EndpointLib.java?p2=hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/endpoints/EndpointLib.java&p1=hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/EndpointLib.java&r1=1586064&r2=1586065&rev=1586065&view=diff ============================================================================== --- hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/EndpointLib.java (original) +++ hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/endpoints/EndpointLib.java Wed Apr 9 18:18:28 2014 @@ -17,7 +17,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.hadoop.hbase.coprocessor; +package org.apache.hadoop.hbase.coprocessor.endpoints; import java.io.IOException; import java.util.ArrayList; @@ -37,7 +37,7 @@ public class EndpointLib { /** * An interface for aggregateScan */ - interface IAggregator { + public interface IAggregator { void aggregate(KeyValue kv); } Copied: hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/endpoints/EndpointManager.java (from r1586064, hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/EndpointManager.java) URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/endpoints/EndpointManager.java?p2=hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/endpoints/EndpointManager.java&p1=hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/EndpointManager.java&r1=1586064&r2=1586065&rev=1586065&view=diff ============================================================================== --- hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/EndpointManager.java (original) +++ hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/endpoints/EndpointManager.java Wed Apr 9 18:18:28 2014 @@ -17,7 +17,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.hadoop.hbase.coprocessor; +package org.apache.hadoop.hbase.coprocessor.endpoints; import java.util.concurrent.ConcurrentHashMap; Copied: hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/endpoints/EndpointServer.java (from r1586064, hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/EndpointServer.java) URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/endpoints/EndpointServer.java?p2=hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/endpoints/EndpointServer.java&p1=hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/EndpointServer.java&r1=1586064&r2=1586065&rev=1586065&view=diff ============================================================================== --- hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/EndpointServer.java (original) +++ hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/endpoints/EndpointServer.java Wed Apr 9 18:18:28 2014 @@ -17,7 +17,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.hadoop.hbase.coprocessor; +package org.apache.hadoop.hbase.coprocessor.endpoints; import java.lang.reflect.Method; Copied: hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/endpoints/HTableEndpointClient.java (from r1586064, hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/HTableEndpointClient.java) URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/endpoints/HTableEndpointClient.java?p2=hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/endpoints/HTableEndpointClient.java&p1=hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/HTableEndpointClient.java&r1=1586064&r2=1586065&rev=1586065&view=diff ============================================================================== --- hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/HTableEndpointClient.java (original) +++ hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/endpoints/HTableEndpointClient.java Wed Apr 9 18:18:28 2014 @@ -17,7 +17,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.hadoop.hbase.coprocessor; +package org.apache.hadoop.hbase.coprocessor.endpoints; import java.io.IOException; import java.lang.reflect.InvocationHandler; Copied: hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/endpoints/IEndpoint.java (from r1586064, hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/IEndpoint.java) URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/endpoints/IEndpoint.java?p2=hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/endpoints/IEndpoint.java&p1=hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/IEndpoint.java&r1=1586064&r2=1586065&rev=1586065&view=diff ============================================================================== --- hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/IEndpoint.java (original) +++ hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/endpoints/IEndpoint.java Wed Apr 9 18:18:28 2014 @@ -17,7 +17,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.hadoop.hbase.coprocessor; +package org.apache.hadoop.hbase.coprocessor.endpoints; /** * The common parent of all endpoint interfaces. Copied: hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/endpoints/IEndpointClient.java (from r1586064, hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/IEndpointClient.java) URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/endpoints/IEndpointClient.java?p2=hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/endpoints/IEndpointClient.java&p1=hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/IEndpointClient.java&r1=1586064&r2=1586065&rev=1586065&view=diff ============================================================================== --- hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/IEndpointClient.java (original) +++ hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/endpoints/IEndpointClient.java Wed Apr 9 18:18:28 2014 @@ -17,7 +17,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.hadoop.hbase.coprocessor; +package org.apache.hadoop.hbase.coprocessor.endpoints; import java.io.IOException; import java.util.Map; Copied: hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/endpoints/IEndpointContext.java (from r1586064, hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/IEndpointContext.java) URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/endpoints/IEndpointContext.java?p2=hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/endpoints/IEndpointContext.java&p1=hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/IEndpointContext.java&r1=1586064&r2=1586065&rev=1586065&view=diff ============================================================================== --- hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/IEndpointContext.java (original) +++ hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/endpoints/IEndpointContext.java Wed Apr 9 18:18:28 2014 @@ -17,7 +17,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.hadoop.hbase.coprocessor; +package org.apache.hadoop.hbase.coprocessor.endpoints; import org.apache.hadoop.hbase.NotServingRegionException; import org.apache.hadoop.hbase.regionserver.HRegion; Copied: hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/endpoints/IEndpointFactory.java (from r1586064, hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/IEndpointFactory.java) URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/endpoints/IEndpointFactory.java?p2=hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/endpoints/IEndpointFactory.java&p1=hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/IEndpointFactory.java&r1=1586064&r2=1586065&rev=1586065&view=diff ============================================================================== --- hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/IEndpointFactory.java (original) +++ hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/coprocessor/endpoints/IEndpointFactory.java Wed Apr 9 18:18:28 2014 @@ -17,7 +17,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.hadoop.hbase.coprocessor; +package org.apache.hadoop.hbase.coprocessor.endpoints; /** * The factory for generating IEndpoint instances. Modified: hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/regionserver/ThriftHRegionServer.java URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/regionserver/ThriftHRegionServer.java?rev=1586065&r1=1586064&r2=1586065&view=diff ============================================================================== --- hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/regionserver/ThriftHRegionServer.java (original) +++ hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/regionserver/ThriftHRegionServer.java Wed Apr 9 18:18:28 2014 @@ -48,7 +48,7 @@ import org.apache.hadoop.hbase.client.Ro import org.apache.hadoop.hbase.client.Scan; import org.apache.hadoop.hbase.client.TMultiResponse; import org.apache.hadoop.hbase.client.TRowMutations; -import org.apache.hadoop.hbase.coprocessor.EndpointServer; +import org.apache.hadoop.hbase.coprocessor.endpoints.EndpointServer; import org.apache.hadoop.hbase.io.hfile.histogram.HFileHistogram.Bucket; import org.apache.hadoop.hbase.ipc.ThriftHRegionInterface; import org.apache.hadoop.hbase.ipc.thrift.exceptions.ThriftHBaseException; Modified: hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/coprocessor/TestEndpoint.java URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/coprocessor/TestEndpoint.java?rev=1586065&r1=1586064&r2=1586065&view=diff ============================================================================== --- hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/coprocessor/TestEndpoint.java (original) +++ hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/coprocessor/TestEndpoint.java Wed Apr 9 18:18:28 2014 @@ -1,136 +0,0 @@ -/* - * Copyright The Apache Software Foundation - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.hadoop.hbase.coprocessor; - -import java.io.IOException; -import java.util.Map; - -import org.apache.hadoop.hbase.HBaseTestingUtility; -import org.apache.hadoop.hbase.KeyValue; -import org.apache.hadoop.hbase.client.HTableInterface; -import org.apache.hadoop.hbase.client.Put; -import org.apache.hadoop.hbase.client.Scan; -import org.apache.hadoop.hbase.coprocessor.EndpointLib.IAggregator; -import org.apache.hadoop.hbase.coprocessor.IEndpointClient.Caller; -import org.apache.hadoop.hbase.regionserver.HRegion; -import org.apache.hadoop.hbase.util.Bytes; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - -/** - * Testcase for endpoint - */ -public class TestEndpoint { - private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(); - private static final byte[] TABLE_NAME = Bytes.toBytes("cp"); - private static final byte[] FAMILY_NAME = Bytes.toBytes("f"); - private static final byte[] QUALITY_NAME = Bytes.toBytes("q"); - - @Before - public void setUp() throws Exception { - TEST_UTIL.startMiniCluster(); - // Register an endpoint in the server side. - EndpointManager.get().register(ISummer.class, - new IEndpointFactory<ISummer>() { - @Override - public ISummer create() { - return new Summer(); - } - }); - } - - @After - public void tearDown() throws Exception { - TEST_UTIL.shutdownMiniCluster(); - } - - /** - * This is an example of an endpoint interface. It computes the total sum of - * all the values of family FAMILY_NAME at quality QUALITY_NAME as longs. - * - */ - public static interface ISummer extends IEndpoint { - byte[] sum() throws IOException; - } - - /** - * The implementation of ISummer. - */ - public static class Summer implements ISummer, IAggregator { - IEndpointContext context; - long result; - - @Override - public void setContext(IEndpointContext context) { - this.context = context; - } - - @Override - public byte[] sum() throws IOException { - HRegion region = context.getRegion(); - Scan scan = new Scan(); - scan.addFamily(FAMILY_NAME); - scan.addColumn(FAMILY_NAME, QUALITY_NAME); - - this.result = 0L; - EndpointLib.aggregateScan(region, scan, this); - return Bytes.toBytes(this.result); - } - - @Override - public void aggregate(KeyValue kv) { - this.result += Bytes.toLong(kv.getBuffer(), kv.getValueOffset(), - kv.getValueLength()); - } - } - - @Test - public void testSummer() throws Exception { - // Create the table - HTableInterface table = TEST_UTIL.createTable(TABLE_NAME, FAMILY_NAME); - - // Put some values - for (int i = 1; i <= 10; i++) { - table.put(new Put(Bytes.toBytes("row" + i)).add(FAMILY_NAME, - QUALITY_NAME, Bytes.toBytes((long) i))); - } - - // Calling endpoints. - IEndpointClient cp = (IEndpointClient) table; - Map<byte[], byte[]> results = cp.coprocessorEndpoint(ISummer.class, null, - null, new Caller<ISummer>() { - @Override - public byte[] call(ISummer client) throws IOException { - return client.sum(); - } - }); - - // Aggregates results from all regions - long sum = 0; - for (byte[] res : results.values()) { - sum += Bytes.toLong(res); - } - - // Check the final results - Assert.assertEquals("sum", 55, sum); - } -} Copied: hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/coprocessor/endpoints/TestEndpoint.java (from r1586064, hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/coprocessor/TestEndpoint.java) URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/coprocessor/endpoints/TestEndpoint.java?p2=hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/coprocessor/endpoints/TestEndpoint.java&p1=hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/coprocessor/TestEndpoint.java&r1=1586064&r2=1586065&rev=1586065&view=diff ============================================================================== --- hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/coprocessor/TestEndpoint.java (original) +++ hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/coprocessor/endpoints/TestEndpoint.java Wed Apr 9 18:18:28 2014 @@ -17,7 +17,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.hadoop.hbase.coprocessor; +package org.apache.hadoop.hbase.coprocessor.endpoints; import java.io.IOException; import java.util.Map; @@ -27,8 +27,14 @@ import org.apache.hadoop.hbase.KeyValue; import org.apache.hadoop.hbase.client.HTableInterface; import org.apache.hadoop.hbase.client.Put; import org.apache.hadoop.hbase.client.Scan; -import org.apache.hadoop.hbase.coprocessor.EndpointLib.IAggregator; -import org.apache.hadoop.hbase.coprocessor.IEndpointClient.Caller; +import org.apache.hadoop.hbase.coprocessor.endpoints.EndpointLib; +import org.apache.hadoop.hbase.coprocessor.endpoints.EndpointLib.IAggregator; +import org.apache.hadoop.hbase.coprocessor.endpoints.EndpointManager; +import org.apache.hadoop.hbase.coprocessor.endpoints.IEndpoint; +import org.apache.hadoop.hbase.coprocessor.endpoints.IEndpointClient; +import org.apache.hadoop.hbase.coprocessor.endpoints.IEndpointClient.Caller; +import org.apache.hadoop.hbase.coprocessor.endpoints.IEndpointContext; +import org.apache.hadoop.hbase.coprocessor.endpoints.IEndpointFactory; import org.apache.hadoop.hbase.regionserver.HRegion; import org.apache.hadoop.hbase.util.Bytes; import org.junit.After;
