nickwallen commented on a change in pull request #1458: METRON-2177 Upgrade
Profiler for HBase 2.0.2
URL: https://github.com/apache/metron/pull/1458#discussion_r311274921
##########
File path:
metron-analytics/metron-profiler-spark/src/main/java/org/apache/metron/profiler/spark/function/HBaseWriterFunction.java
##########
@@ -137,35 +150,38 @@ public HBaseWriterFunction(Properties properties) {
}
/**
- * Set the {@link TableProvider} using the class name of the provider.
- * @param providerImpl The name of the class.
- * @return
+ * Creates an {@link HBaseConnectionFactory} based on a class name.
+ * @param factoryImpl The class name of an {@link HBaseConnectionFactory}
implementation.
*/
- public HBaseWriterFunction withTableProviderImpl(String providerImpl) {
- this.tableProvider = createTableProvider(providerImpl);
- return this;
- }
-
- /**
- * Creates a TableProvider based on a class name.
- * @param providerImpl The class name of a TableProvider
- */
- private static TableProvider createTableProvider(String providerImpl) {
- LOG.trace("Creating table provider; className={}", providerImpl);
+ private static HBaseConnectionFactory createConnectionFactory(String
factoryImpl) {
+ LOG.trace("Creating table provider; className={}", factoryImpl);
// if class name not defined, use a reasonable default
- if(StringUtils.isEmpty(providerImpl) || providerImpl.charAt(0) == '$') {
- return new HTableProvider();
+ if(StringUtils.isEmpty(factoryImpl) || factoryImpl.charAt(0) == '$') {
+ return new HBaseConnectionFactory();
}
// instantiate the table provider
- try {
- Class<? extends TableProvider> clazz = (Class<? extends TableProvider>)
Class.forName(providerImpl);
- return clazz.getConstructor().newInstance();
+ return HBaseConnectionFactory.byName(factoryImpl);
+ }
- } catch (InstantiationException | IllegalAccessException |
IllegalStateException |
- InvocationTargetException | NoSuchMethodException |
ClassNotFoundException e) {
- throw new IllegalStateException("Unable to instantiate connector", e);
- }
+ protected HBaseWriterFunction withConnectionFactory(HBaseConnectionFactory
connectionFactory) {
Review comment:
> What happens if you pass in nulls or forget to call all the builder
methods?
I provided sensible defaults now. See 67fe5ab56.
> Which of those builder methods is absolutely required and, as a consumer
of the API...
None are absolutely required thanks to the defaults.
> how do I know which builder method wins where there is overlap in the
underlying options?
Whichever you call last, which seems intuitive to me. In reality,
withProperties() is used in production (see BatchProfiler), whereas the other
methods are used during testing.
The alternative, is to not have `Builder.withProperties` and move that
logic back as a constructor; `HBaseWriterFunction(Properties)`. When I created
the Builder, it seemed logical to move that to the Builder, but maybe you
disagree.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services