HBASE-20180 Avoid Class::newInstance
This commit is contained in:
parent
37342220b4
commit
f63a7ff635
|
@ -38,8 +38,9 @@ public final class BackupClientFactory {
|
||||||
try {
|
try {
|
||||||
String clsName = conf.get(TableBackupClient.BACKUP_CLIENT_IMPL_CLASS);
|
String clsName = conf.get(TableBackupClient.BACKUP_CLIENT_IMPL_CLASS);
|
||||||
if (clsName != null) {
|
if (clsName != null) {
|
||||||
Class<?> clientImpl = Class.forName(clsName);
|
Class<? extends TableBackupClient> clientImpl;
|
||||||
TableBackupClient client = (TableBackupClient) clientImpl.newInstance();
|
clientImpl = Class.forName(clsName).asSubclass(TableBackupClient.class);
|
||||||
|
TableBackupClient client = clientImpl.getDeclaredConstructor().newInstance();
|
||||||
client.init(conn, backupId, request);
|
client.init(conn, backupId, request);
|
||||||
return client;
|
return client;
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,6 +82,7 @@
|
||||||
<compilerArgs>
|
<compilerArgs>
|
||||||
<arg>-XepDisableWarningsInGeneratedCode</arg>
|
<arg>-XepDisableWarningsInGeneratedCode</arg>
|
||||||
<arg>-Xep:FallThrough:OFF</arg> <!-- already in findbugs -->
|
<arg>-Xep:FallThrough:OFF</arg> <!-- already in findbugs -->
|
||||||
|
<arg>-Xep:ClassNewInstance:ERROR</arg>
|
||||||
</compilerArgs>
|
</compilerArgs>
|
||||||
<annotationProcessorPaths>
|
<annotationProcessorPaths>
|
||||||
<path>
|
<path>
|
||||||
|
|
|
@ -27,6 +27,7 @@ import com.google.protobuf.RpcController;
|
||||||
import com.google.protobuf.Service;
|
import com.google.protobuf.Service;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
@ -480,21 +481,19 @@ extends AggregateService implements RegionCoprocessor {
|
||||||
ColumnInterpreter<T,S,P,Q,R> constructColumnInterpreterFromRequest(
|
ColumnInterpreter<T,S,P,Q,R> constructColumnInterpreterFromRequest(
|
||||||
AggregateRequest request) throws IOException {
|
AggregateRequest request) throws IOException {
|
||||||
String className = request.getInterpreterClassName();
|
String className = request.getInterpreterClassName();
|
||||||
Class<?> cls;
|
|
||||||
try {
|
try {
|
||||||
cls = Class.forName(className);
|
ColumnInterpreter<T,S,P,Q,R> ci;
|
||||||
ColumnInterpreter<T,S,P,Q,R> ci = (ColumnInterpreter<T, S, P, Q, R>) cls.newInstance();
|
Class<?> cls = Class.forName(className);
|
||||||
|
ci = (ColumnInterpreter<T, S, P, Q, R>) cls.getDeclaredConstructor().newInstance();
|
||||||
|
|
||||||
if (request.hasInterpreterSpecificBytes()) {
|
if (request.hasInterpreterSpecificBytes()) {
|
||||||
ByteString b = request.getInterpreterSpecificBytes();
|
ByteString b = request.getInterpreterSpecificBytes();
|
||||||
P initMsg = getParsedGenericInstance(ci.getClass(), 2, b);
|
P initMsg = getParsedGenericInstance(ci.getClass(), 2, b);
|
||||||
ci.initialize(initMsg);
|
ci.initialize(initMsg);
|
||||||
}
|
}
|
||||||
return ci;
|
return ci;
|
||||||
} catch (ClassNotFoundException e) {
|
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException |
|
||||||
throw new IOException(e);
|
NoSuchMethodException | InvocationTargetException e) {
|
||||||
} catch (InstantiationException e) {
|
|
||||||
throw new IOException(e);
|
|
||||||
} catch (IllegalAccessException e) {
|
|
||||||
throw new IOException(e);
|
throw new IOException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -281,7 +281,8 @@ public class MultithreadedTableMapper<K2, V2> extends TableMapper<K2, V2> {
|
||||||
outer.getInputSplit());
|
outer.getInputSplit());
|
||||||
Class<?> wrappedMapperClass = Class.forName("org.apache.hadoop.mapreduce.lib.map.WrappedMapper");
|
Class<?> wrappedMapperClass = Class.forName("org.apache.hadoop.mapreduce.lib.map.WrappedMapper");
|
||||||
Method getMapContext = wrappedMapperClass.getMethod("getMapContext", MapContext.class);
|
Method getMapContext = wrappedMapperClass.getMethod("getMapContext", MapContext.class);
|
||||||
subcontext = (Context) getMapContext.invoke(wrappedMapperClass.newInstance(), mc);
|
subcontext = (Context) getMapContext.invoke(
|
||||||
|
wrappedMapperClass.getDeclaredConstructor().newInstance(), mc);
|
||||||
} catch (Exception ee) { // FindBugs: REC_CATCH_EXCEPTION
|
} catch (Exception ee) { // FindBugs: REC_CATCH_EXCEPTION
|
||||||
// rethrow as IOE
|
// rethrow as IOE
|
||||||
throw new IOException(e);
|
throw new IOException(e);
|
||||||
|
|
|
@ -22,6 +22,7 @@ import java.io.ByteArrayOutputStream;
|
||||||
import java.io.DataInput;
|
import java.io.DataInput;
|
||||||
import java.io.DataOutput;
|
import java.io.DataOutput;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
@ -300,17 +301,11 @@ public class TableSnapshotInputFormatImpl {
|
||||||
if (splitAlgoClassName == null)
|
if (splitAlgoClassName == null)
|
||||||
return null;
|
return null;
|
||||||
try {
|
try {
|
||||||
return ((Class<? extends RegionSplitter.SplitAlgorithm>)
|
return Class.forName(splitAlgoClassName).asSubclass(RegionSplitter.SplitAlgorithm.class)
|
||||||
Class.forName(splitAlgoClassName)).newInstance();
|
.getDeclaredConstructor().newInstance();
|
||||||
} catch (ClassNotFoundException e) {
|
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException |
|
||||||
throw new IOException("SplitAlgo class " + splitAlgoClassName +
|
NoSuchMethodException | InvocationTargetException e) {
|
||||||
" is not found", e);
|
throw new IOException("SplitAlgo class " + splitAlgoClassName + " is not found", e);
|
||||||
} catch (InstantiationException e) {
|
|
||||||
throw new IOException("SplitAlgo class " + splitAlgoClassName +
|
|
||||||
" is not instantiable", e);
|
|
||||||
} catch (IllegalAccessException e) {
|
|
||||||
throw new IOException("SplitAlgo class " + splitAlgoClassName +
|
|
||||||
" is not instantiable", e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@ import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.DataOutputStream;
|
import java.io.DataOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
@ -593,14 +594,11 @@ public final class Constraints {
|
||||||
// add the constraint, now that we expect it to be valid.
|
// add the constraint, now that we expect it to be valid.
|
||||||
Class<? extends Constraint> clazz = classloader.loadClass(key)
|
Class<? extends Constraint> clazz = classloader.loadClass(key)
|
||||||
.asSubclass(Constraint.class);
|
.asSubclass(Constraint.class);
|
||||||
Constraint constraint = clazz.newInstance();
|
Constraint constraint = clazz.getDeclaredConstructor().newInstance();
|
||||||
constraint.setConf(conf);
|
constraint.setConf(conf);
|
||||||
constraints.add(constraint);
|
constraints.add(constraint);
|
||||||
} catch (ClassNotFoundException e1) {
|
} catch (InvocationTargetException | NoSuchMethodException | ClassNotFoundException |
|
||||||
throw new IOException(e1);
|
InstantiationException | IllegalAccessException e1) {
|
||||||
} catch (InstantiationException e1) {
|
|
||||||
throw new IOException(e1);
|
|
||||||
} catch (IllegalAccessException e1) {
|
|
||||||
throw new IOException(e1);
|
throw new IOException(e1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@ package org.apache.hadoop.hbase.master;
|
||||||
|
|
||||||
import com.google.protobuf.Service;
|
import com.google.protobuf.Service;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import org.apache.hadoop.conf.Configuration;
|
import org.apache.hadoop.conf.Configuration;
|
||||||
|
@ -170,18 +171,23 @@ public class MasterCoprocessorHost
|
||||||
@Override
|
@Override
|
||||||
public MasterCoprocessor checkAndGetInstance(Class<?> implClass)
|
public MasterCoprocessor checkAndGetInstance(Class<?> implClass)
|
||||||
throws InstantiationException, IllegalAccessException {
|
throws InstantiationException, IllegalAccessException {
|
||||||
|
try {
|
||||||
if (MasterCoprocessor.class.isAssignableFrom(implClass)) {
|
if (MasterCoprocessor.class.isAssignableFrom(implClass)) {
|
||||||
return (MasterCoprocessor)implClass.newInstance();
|
return implClass.asSubclass(MasterCoprocessor.class).getDeclaredConstructor().newInstance();
|
||||||
} else if (CoprocessorService.class.isAssignableFrom(implClass)) {
|
} else if (CoprocessorService.class.isAssignableFrom(implClass)) {
|
||||||
// For backward compatibility with old CoprocessorService impl which don't extend
|
// For backward compatibility with old CoprocessorService impl which don't extend
|
||||||
// MasterCoprocessor.
|
// MasterCoprocessor.
|
||||||
return new CoprocessorServiceBackwardCompatiblity.MasterCoprocessorService(
|
CoprocessorService cs;
|
||||||
(CoprocessorService)implClass.newInstance());
|
cs = implClass.asSubclass(CoprocessorService.class).getDeclaredConstructor().newInstance();
|
||||||
|
return new CoprocessorServiceBackwardCompatiblity.MasterCoprocessorService(cs);
|
||||||
} else {
|
} else {
|
||||||
LOG.error(implClass.getName() + " is not of type MasterCoprocessor. Check the "
|
LOG.error("{} is not of type MasterCoprocessor. Check the configuration of {}",
|
||||||
+ "configuration " + CoprocessorHost.MASTER_COPROCESSOR_CONF_KEY);
|
implClass.getName(), CoprocessorHost.MASTER_COPROCESSOR_CONF_KEY);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
} catch (NoSuchMethodException | InvocationTargetException e) {
|
||||||
|
throw (InstantiationException) new InstantiationException(implClass.getName()).initCause(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private ObserverGetter<MasterCoprocessor, MasterObserver> masterObserverGetter =
|
private ObserverGetter<MasterCoprocessor, MasterObserver> masterObserverGetter =
|
||||||
|
|
|
@ -310,10 +310,10 @@ public class ReplicationPeerManager {
|
||||||
String[] filters = filterCSV.split(",");
|
String[] filters = filterCSV.split(",");
|
||||||
for (String filter : filters) {
|
for (String filter : filters) {
|
||||||
try {
|
try {
|
||||||
Class.forName(filter).newInstance();
|
Class.forName(filter).getDeclaredConstructor().newInstance();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new DoNotRetryIOException("Configured WALEntryFilter " + filter +
|
throw new DoNotRetryIOException("Configured WALEntryFilter " + filter +
|
||||||
" could not be created. Failing add/update " + "peer operation.", e);
|
" could not be created. Failing add/update peer operation.", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@ package org.apache.hadoop.hbase.regionserver;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InterruptedIOException;
|
import java.io.InterruptedIOException;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.net.BindException;
|
import java.net.BindException;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
|
@ -1185,11 +1186,13 @@ public class RSRpcServices implements HBaseRPCErrorHandler,
|
||||||
rowSizeWarnThreshold = rs.conf.getInt(BATCH_ROWS_THRESHOLD_NAME, BATCH_ROWS_THRESHOLD_DEFAULT);
|
rowSizeWarnThreshold = rs.conf.getInt(BATCH_ROWS_THRESHOLD_NAME, BATCH_ROWS_THRESHOLD_DEFAULT);
|
||||||
RpcSchedulerFactory rpcSchedulerFactory;
|
RpcSchedulerFactory rpcSchedulerFactory;
|
||||||
try {
|
try {
|
||||||
Class<?> rpcSchedulerFactoryClass = rs.conf.getClass(
|
Class<?> cls = rs.conf.getClass(
|
||||||
REGION_SERVER_RPC_SCHEDULER_FACTORY_CLASS,
|
REGION_SERVER_RPC_SCHEDULER_FACTORY_CLASS,
|
||||||
SimpleRpcSchedulerFactory.class);
|
SimpleRpcSchedulerFactory.class);
|
||||||
rpcSchedulerFactory = ((RpcSchedulerFactory) rpcSchedulerFactoryClass.newInstance());
|
rpcSchedulerFactory = cls.asSubclass(RpcSchedulerFactory.class)
|
||||||
} catch (InstantiationException | IllegalAccessException e) {
|
.getDeclaredConstructor().newInstance();
|
||||||
|
} catch (NoSuchMethodException | InvocationTargetException |
|
||||||
|
InstantiationException | IllegalAccessException e) {
|
||||||
throw new IllegalArgumentException(e);
|
throw new IllegalArgumentException(e);
|
||||||
}
|
}
|
||||||
// Server to handle client requests.
|
// Server to handle client requests.
|
||||||
|
@ -3549,8 +3552,8 @@ public class RSRpcServices implements HBaseRPCErrorHandler,
|
||||||
for (RemoteProcedureRequest req : request.getProcList()) {
|
for (RemoteProcedureRequest req : request.getProcList()) {
|
||||||
RSProcedureCallable callable;
|
RSProcedureCallable callable;
|
||||||
try {
|
try {
|
||||||
callable =
|
callable = Class.forName(req.getProcClass()).asSubclass(RSProcedureCallable.class)
|
||||||
Class.forName(req.getProcClass()).asSubclass(RSProcedureCallable.class).newInstance();
|
.getDeclaredConstructor().newInstance();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
regionServer.remoteProcedureComplete(req.getProcId(), e);
|
regionServer.remoteProcedureComplete(req.getProcId(), e);
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -22,6 +22,7 @@ import com.google.protobuf.Message;
|
||||||
import com.google.protobuf.Service;
|
import com.google.protobuf.Service;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -465,18 +466,23 @@ public class RegionCoprocessorHost
|
||||||
@Override
|
@Override
|
||||||
public RegionCoprocessor checkAndGetInstance(Class<?> implClass)
|
public RegionCoprocessor checkAndGetInstance(Class<?> implClass)
|
||||||
throws InstantiationException, IllegalAccessException {
|
throws InstantiationException, IllegalAccessException {
|
||||||
|
try {
|
||||||
if (RegionCoprocessor.class.isAssignableFrom(implClass)) {
|
if (RegionCoprocessor.class.isAssignableFrom(implClass)) {
|
||||||
return (RegionCoprocessor)implClass.newInstance();
|
return implClass.asSubclass(RegionCoprocessor.class).getDeclaredConstructor().newInstance();
|
||||||
} else if (CoprocessorService.class.isAssignableFrom(implClass)) {
|
} else if (CoprocessorService.class.isAssignableFrom(implClass)) {
|
||||||
// For backward compatibility with old CoprocessorService impl which don't extend
|
// For backward compatibility with old CoprocessorService impl which don't extend
|
||||||
// RegionCoprocessor.
|
// RegionCoprocessor.
|
||||||
return new CoprocessorServiceBackwardCompatiblity.RegionCoprocessorService(
|
CoprocessorService cs;
|
||||||
(CoprocessorService)implClass.newInstance());
|
cs = implClass.asSubclass(CoprocessorService.class).getDeclaredConstructor().newInstance();
|
||||||
|
return new CoprocessorServiceBackwardCompatiblity.RegionCoprocessorService(cs);
|
||||||
} else {
|
} else {
|
||||||
LOG.error(implClass.getName() + " is not of type RegionCoprocessor. Check the "
|
LOG.error("{} is not of type RegionCoprocessor. Check the configuration of {}",
|
||||||
+ "configuration " + CoprocessorHost.REGION_COPROCESSOR_CONF_KEY);
|
implClass.getName(), CoprocessorHost.REGION_COPROCESSOR_CONF_KEY);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
} catch (NoSuchMethodException | InvocationTargetException e) {
|
||||||
|
throw (InstantiationException) new InstantiationException(implClass.getName()).initCause(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private ObserverGetter<RegionCoprocessor, RegionObserver> regionObserverGetter =
|
private ObserverGetter<RegionCoprocessor, RegionObserver> regionObserverGetter =
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
package org.apache.hadoop.hbase.regionserver;
|
package org.apache.hadoop.hbase.regionserver;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
|
||||||
import com.google.protobuf.Service;
|
import com.google.protobuf.Service;
|
||||||
|
|
||||||
|
@ -82,18 +83,24 @@ public class RegionServerCoprocessorHost extends
|
||||||
@Override
|
@Override
|
||||||
public RegionServerCoprocessor checkAndGetInstance(Class<?> implClass)
|
public RegionServerCoprocessor checkAndGetInstance(Class<?> implClass)
|
||||||
throws InstantiationException, IllegalAccessException {
|
throws InstantiationException, IllegalAccessException {
|
||||||
|
try {
|
||||||
if (RegionServerCoprocessor.class.isAssignableFrom(implClass)) {
|
if (RegionServerCoprocessor.class.isAssignableFrom(implClass)) {
|
||||||
return (RegionServerCoprocessor)implClass.newInstance();
|
return implClass.asSubclass(RegionServerCoprocessor.class).getDeclaredConstructor()
|
||||||
|
.newInstance();
|
||||||
} else if (SingletonCoprocessorService.class.isAssignableFrom(implClass)) {
|
} else if (SingletonCoprocessorService.class.isAssignableFrom(implClass)) {
|
||||||
// For backward compatibility with old CoprocessorService impl which don't extend
|
// For backward compatibility with old CoprocessorService impl which don't extend
|
||||||
// RegionCoprocessor.
|
// RegionCoprocessor.
|
||||||
return new CoprocessorServiceBackwardCompatiblity.RegionServerCoprocessorService(
|
SingletonCoprocessorService tmp = implClass.asSubclass(SingletonCoprocessorService.class)
|
||||||
(SingletonCoprocessorService)implClass.newInstance());
|
.getDeclaredConstructor().newInstance();
|
||||||
|
return new CoprocessorServiceBackwardCompatiblity.RegionServerCoprocessorService(tmp);
|
||||||
} else {
|
} else {
|
||||||
LOG.error(implClass.getName() + " is not of type RegionServerCoprocessor. Check the "
|
LOG.error("{} is not of type RegionServerCoprocessor. Check the configuration of {}",
|
||||||
+ "configuration " + CoprocessorHost.REGIONSERVER_COPROCESSOR_CONF_KEY);
|
implClass.getName(), CoprocessorHost.REGIONSERVER_COPROCESSOR_CONF_KEY);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
} catch (NoSuchMethodException | InvocationTargetException e) {
|
||||||
|
throw (InstantiationException) new InstantiationException(implClass.getName()).initCause(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private ObserverGetter<RegionServerCoprocessor, RegionServerObserver> rsObserverGetter =
|
private ObserverGetter<RegionServerCoprocessor, RegionServerObserver> rsObserverGetter =
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
package org.apache.hadoop.hbase.regionserver.wal;
|
package org.apache.hadoop.hbase.regionserver.wal;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
|
||||||
import org.apache.hadoop.conf.Configuration;
|
import org.apache.hadoop.conf.Configuration;
|
||||||
import org.apache.hadoop.fs.Path;
|
import org.apache.hadoop.fs.Path;
|
||||||
|
@ -118,10 +119,14 @@ public class WALCoprocessorHost
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public WALCoprocessor checkAndGetInstance(Class<?> implClass)
|
public WALCoprocessor checkAndGetInstance(Class<?> implClass) throws IllegalAccessException,
|
||||||
throws InstantiationException, IllegalAccessException {
|
InstantiationException {
|
||||||
if (WALCoprocessor.class.isAssignableFrom(implClass)) {
|
if (WALCoprocessor.class.isAssignableFrom(implClass)) {
|
||||||
return (WALCoprocessor)implClass.newInstance();
|
try {
|
||||||
|
return implClass.asSubclass(WALCoprocessor.class).getDeclaredConstructor().newInstance();
|
||||||
|
} catch (NoSuchMethodException | InvocationTargetException e) {
|
||||||
|
throw (InstantiationException) new InstantiationException(implClass.getName()).initCause(e);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
LOG.error(implClass.getName() + " is not of type WALCoprocessor. Check the "
|
LOG.error(implClass.getName() + " is not of type WALCoprocessor. Check the "
|
||||||
+ "configuration " + CoprocessorHost.WAL_COPROCESSOR_CONF_KEY);
|
+ "configuration " + CoprocessorHost.WAL_COPROCESSOR_CONF_KEY);
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
package org.apache.hadoop.hbase.replication.regionserver;
|
package org.apache.hadoop.hbase.replication.regionserver;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
@ -242,12 +243,21 @@ public class ReplicationSource implements ReplicationSourceInterface {
|
||||||
rsServerHost = ((HRegionServer) server).getRegionServerCoprocessorHost();
|
rsServerHost = ((HRegionServer) server).getRegionServerCoprocessorHost();
|
||||||
}
|
}
|
||||||
String replicationEndpointImpl = replicationPeer.getPeerConfig().getReplicationEndpointImpl();
|
String replicationEndpointImpl = replicationPeer.getPeerConfig().getReplicationEndpointImpl();
|
||||||
|
|
||||||
|
ReplicationEndpoint replicationEndpoint;
|
||||||
if (replicationEndpointImpl == null) {
|
if (replicationEndpointImpl == null) {
|
||||||
// Default to HBase inter-cluster replication endpoint
|
// Default to HBase inter-cluster replication endpoint; skip reflection
|
||||||
replicationEndpointImpl = HBaseInterClusterReplicationEndpoint.class.getName();
|
replicationEndpoint = new HBaseInterClusterReplicationEndpoint();
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
replicationEndpoint = Class.forName(replicationEndpointImpl)
|
||||||
|
.asSubclass(ReplicationEndpoint.class)
|
||||||
|
.getDeclaredConstructor()
|
||||||
|
.newInstance();
|
||||||
|
} catch (NoSuchMethodException | InvocationTargetException e) {
|
||||||
|
throw new IllegalArgumentException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ReplicationEndpoint replicationEndpoint =
|
|
||||||
Class.forName(replicationEndpointImpl).asSubclass(ReplicationEndpoint.class).newInstance();
|
|
||||||
if (rsServerHost != null) {
|
if (rsServerHost != null) {
|
||||||
ReplicationEndpoint newReplicationEndPoint =
|
ReplicationEndpoint newReplicationEndPoint =
|
||||||
rsServerHost.postCreateReplicationEndPoint(replicationEndpoint);
|
rsServerHost.postCreateReplicationEndPoint(replicationEndpoint);
|
||||||
|
|
|
@ -40,10 +40,9 @@ public class ReplicationSourceFactory {
|
||||||
String defaultReplicationSourceImpl =
|
String defaultReplicationSourceImpl =
|
||||||
isQueueRecovered ? RecoveredReplicationSource.class.getCanonicalName()
|
isQueueRecovered ? RecoveredReplicationSource.class.getCanonicalName()
|
||||||
: ReplicationSource.class.getCanonicalName();
|
: ReplicationSource.class.getCanonicalName();
|
||||||
@SuppressWarnings("rawtypes")
|
Class<?> c = Class.forName(
|
||||||
Class c = Class.forName(
|
|
||||||
conf.get("replication.replicationsource.implementation", defaultReplicationSourceImpl));
|
conf.get("replication.replicationsource.implementation", defaultReplicationSourceImpl));
|
||||||
src = (ReplicationSourceInterface) c.newInstance();
|
src = c.asSubclass(ReplicationSourceInterface.class).getDeclaredConstructor().newInstance();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOG.warn("Passed replication source implementation throws errors, "
|
LOG.warn("Passed replication source implementation throws errors, "
|
||||||
+ "defaulting to ReplicationSource",
|
+ "defaulting to ReplicationSource",
|
||||||
|
|
|
@ -20,6 +20,8 @@ package org.apache.hadoop.hbase.coprocessor;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
|
||||||
import org.apache.hadoop.conf.Configuration;
|
import org.apache.hadoop.conf.Configuration;
|
||||||
import org.apache.hadoop.hbase.Abortable;
|
import org.apache.hadoop.hbase.Abortable;
|
||||||
import org.apache.hadoop.hbase.Coprocessor;
|
import org.apache.hadoop.hbase.Coprocessor;
|
||||||
|
@ -56,47 +58,61 @@ public class TestCoprocessorHost {
|
||||||
return this.aborted;
|
return this.aborted;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoubleLoadingAndPriorityValue() {
|
public void testDoubleLoadingAndPriorityValue() {
|
||||||
final Configuration conf = HBaseConfiguration.create();
|
final Configuration conf = HBaseConfiguration.create();
|
||||||
CoprocessorHost<RegionCoprocessor, CoprocessorEnvironment<RegionCoprocessor>> host =
|
|
||||||
new CoprocessorHost<RegionCoprocessor, CoprocessorEnvironment<RegionCoprocessor>>(
|
|
||||||
new TestAbortable()) {
|
|
||||||
@Override
|
|
||||||
public RegionCoprocessor checkAndGetInstance(Class<?> implClass)
|
|
||||||
throws InstantiationException, IllegalAccessException {
|
|
||||||
if(RegionCoprocessor.class.isAssignableFrom(implClass)) {
|
|
||||||
return (RegionCoprocessor)implClass.newInstance();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
final Configuration cpHostConf = conf;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CoprocessorEnvironment<RegionCoprocessor> createEnvironment(
|
|
||||||
final RegionCoprocessor instance, final int priority, int sequence, Configuration conf) {
|
|
||||||
return new BaseEnvironment<RegionCoprocessor>(instance, priority, 0, cpHostConf);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
final String key = "KEY";
|
final String key = "KEY";
|
||||||
final String coprocessor = "org.apache.hadoop.hbase.coprocessor.SimpleRegionObserver";
|
final String coprocessor = "org.apache.hadoop.hbase.coprocessor.SimpleRegionObserver";
|
||||||
|
|
||||||
|
CoprocessorHost<RegionCoprocessor, CoprocessorEnvironment<RegionCoprocessor>> host;
|
||||||
|
host = new CoprocessorHostForTest<>(conf);
|
||||||
|
|
||||||
// Try and load a coprocessor three times
|
// Try and load a coprocessor three times
|
||||||
conf.setStrings(key, coprocessor, coprocessor, coprocessor,
|
conf.setStrings(key, coprocessor, coprocessor, coprocessor,
|
||||||
SimpleRegionObserverV2.class.getName());
|
SimpleRegionObserverV2.class.getName());
|
||||||
host.loadSystemCoprocessors(conf, key);
|
host.loadSystemCoprocessors(conf, key);
|
||||||
|
|
||||||
// Two coprocessors(SimpleRegionObserver and SimpleRegionObserverV2) loaded
|
// Two coprocessors(SimpleRegionObserver and SimpleRegionObserverV2) loaded
|
||||||
Assert.assertEquals(2, host.coprocEnvironments.size());
|
Assert.assertEquals(2, host.coprocEnvironments.size());
|
||||||
|
|
||||||
// Check the priority value
|
// Check the priority value
|
||||||
CoprocessorEnvironment simpleEnv = host.findCoprocessorEnvironment(
|
CoprocessorEnvironment<?> simpleEnv = host.findCoprocessorEnvironment(
|
||||||
SimpleRegionObserver.class.getName());
|
SimpleRegionObserver.class.getName());
|
||||||
CoprocessorEnvironment simpleEnv_v2 = host.findCoprocessorEnvironment(
|
CoprocessorEnvironment<?> simpleEnv_v2 = host.findCoprocessorEnvironment(
|
||||||
SimpleRegionObserverV2.class.getName());
|
SimpleRegionObserverV2.class.getName());
|
||||||
|
|
||||||
assertNotNull(simpleEnv);
|
assertNotNull(simpleEnv);
|
||||||
assertNotNull(simpleEnv_v2);
|
assertNotNull(simpleEnv_v2);
|
||||||
assertEquals(Coprocessor.PRIORITY_SYSTEM, simpleEnv.getPriority());
|
assertEquals(Coprocessor.PRIORITY_SYSTEM, simpleEnv.getPriority());
|
||||||
assertEquals(Coprocessor.PRIORITY_SYSTEM + 1, simpleEnv_v2.getPriority());
|
assertEquals(Coprocessor.PRIORITY_SYSTEM + 1, simpleEnv_v2.getPriority());
|
||||||
}
|
}
|
||||||
public static class SimpleRegionObserverV2 extends SimpleRegionObserver {
|
|
||||||
|
public static class SimpleRegionObserverV2 extends SimpleRegionObserver { }
|
||||||
|
|
||||||
|
private static class CoprocessorHostForTest<E extends Coprocessor> extends
|
||||||
|
CoprocessorHost<E, CoprocessorEnvironment<E>> {
|
||||||
|
final Configuration cpHostConf;
|
||||||
|
|
||||||
|
public CoprocessorHostForTest(Configuration conf) {
|
||||||
|
super(new TestAbortable());
|
||||||
|
cpHostConf = conf;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public E checkAndGetInstance(Class<?> implClass)
|
||||||
|
throws InstantiationException, IllegalAccessException {
|
||||||
|
try {
|
||||||
|
return (E) implClass.getDeclaredConstructor().newInstance();
|
||||||
|
} catch (InvocationTargetException | NoSuchMethodException e) {
|
||||||
|
throw (InstantiationException) new InstantiationException().initCause(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CoprocessorEnvironment<E> createEnvironment(final E instance, final int priority,
|
||||||
|
int sequence, Configuration conf) {
|
||||||
|
return new BaseEnvironment<>(instance, priority, 0, cpHostConf);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue