/** * Return an {@link CompactionSuiteFactory} based on the configuration * @return A concrete suite factory instance. By default {@link CompactionAvroSuiteFactory} is used. */ public static CompactionSuiteFactory getCompactionSuiteFactory (State state) { try { String factoryName = state.getProp(ConfigurationKeys.COMPACTION_SUITE_FACTORY, ConfigurationKeys.DEFAULT_COMPACTION_SUITE_FACTORY); ClassAliasResolver<CompactionSuiteFactory> conditionClassAliasResolver = new ClassAliasResolver<>(CompactionSuiteFactory.class); CompactionSuiteFactory factory = conditionClassAliasResolver.resolveClass(factoryName).newInstance(); return factory; } catch (IllegalAccessException | InstantiationException | ClassNotFoundException e) { throw new IllegalArgumentException(e); } } }
/** * @return A {@link SpecExecutor}'s instance defined by <Technology, Location, Communication Mechanism> */ public synchronized SpecExecutor getSpecExecutor() { if (null == specExecutorInstance) { String specExecutorClass = DEFAULT_SPEC_EXECUTOR_INSTANCE; if (config.hasPath(SPEC_EXECUTOR_INSTANCE_KEY)) { specExecutorClass = config.getString(SPEC_EXECUTOR_INSTANCE_KEY); } try { ClassAliasResolver<SpecExecutor> _aliasResolver = new ClassAliasResolver<>(SpecExecutor.class); specExecutorInstance = (SpecExecutor) ConstructorUtils .invokeConstructor(Class.forName(_aliasResolver .resolve(specExecutorClass)), config); } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | InstantiationException | ClassNotFoundException e) { throw new RuntimeException(e); } } return specExecutorInstance; }
private List<Alias> getAllAliases() { ClassAliasResolver<EmbeddedGobblinCliFactory> resolver = new ClassAliasResolver<>(EmbeddedGobblinCliFactory.class); return resolver.getAliasObjects(); }
/** * Instantiate a {@link GobblinInstancePluginFactory} by alias. */ public static GobblinInstancePluginFactory instantiatePluginByAlias(String alias) throws ClassNotFoundException, InstantiationException, IllegalAccessException { return RESOLVER.resolveClass(alias).newInstance(); }
private DefaultAuditSinkFactory() { this.aliasResolver = new ClassAliasResolver<>(AuditSink.class); }
/** * Create a new {@link ColumnProjectionPolicy} using the alias or cannonical classname specified at {@value #COLUMN_PROJECTION_POLICY_CLASS_NAME_KEY} in the <code>config</code> * The {@link ColumnProjectionPolicy} class MUST have an accessible constructor <code>abc(Config config, TableMetadata tableMetadata)</code> * <b>Note : Must have the key {@value #COLUMN_PROJECTION_POLICY_CLASS_NAME_KEY} set in <code>config</code> to create the {@link ColumnProjectionPolicy}</b> * * @param config job configs, Must have the key {@value #COLUMN_PROJECTION_POLICY_CLASS_NAME_KEY} set to create the {@link ColumnProjectionPolicy} * @param tableMetadata runtime table metadata * * @return a new instance of {@link ColumnProjectionPolicy} */ public ColumnProjectionPolicy create(Config config, ValueAuditRuntimeMetadata.TableMetadata tableMetadata) { Preconditions.checkArgument(config.hasPath(COLUMN_PROJECTION_POLICY_CLASS_NAME_KEY)); log.info("Using column projection class name/alias " + config.getString(COLUMN_PROJECTION_POLICY_CLASS_NAME_KEY)); try { return (ColumnProjectionPolicy)ConstructorUtils.invokeConstructor(Class.forName(this.aliasResolver.resolve( config.getString(COLUMN_PROJECTION_POLICY_CLASS_NAME_KEY))), config, tableMetadata); } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | InstantiationException | ClassNotFoundException e) { throw new RuntimeException(e); } }
private static void printUsage(ClassAliasResolver<CliApplication> resolver) { System.out.println("Usage: gobblin <command>"); System.out.println("Available commands:"); for (Alias alias : resolver.getAliasObjects()) { System.out.println("\t" + alias.value() + "\t" + alias.description()); } }
private static Class<? extends HttpClientConfigurator> getConfiguratorClass(Optional<String> configuratorType) throws ClassNotFoundException { return configuratorType.isPresent() ? TYPE_RESOLVER.resolveClass(configuratorType.get()) : DEFAULT_CONFIGURATOR_CLASS; }
private DefaultRowSelectionPolicyFactory() { this.aliasResolver = new ClassAliasResolver<>(RowSelectionPolicy.class); }
/** * Create a new {@link RowSelectionPolicy} using the alias or cannonical classname specified at {@value #ROW_SELECTION_POLICY_CLASS_NAME_KEY} in the <code>config</code> * The {@link RowSelectionPolicy} class MUST have an accessible constructor <code>abc(Config config, TableMetadata tableMetadata, ColumnProjectionPolicy columnProjectionPolicy)</code> * <b>Note : must have the key {@value #ROW_SELECTION_POLICY_CLASS_NAME_KEY} set in <code>config</code> to create the {@link RowSelectionPolicy}</b> * * @param config job configs, must have the key {@value #ROW_SELECTION_POLICY_CLASS_NAME_KEY} set to create the {@link RowSelectionPolicy} * @param tableMetadata runtime table metadata * @param columnProjectionPolicy used by the {@link ValueAuditGenerator} * * @return a new instance of {@link RowSelectionPolicy} */ public RowSelectionPolicy create(Config config, ValueAuditRuntimeMetadata.TableMetadata tableMetadata, ColumnProjectionPolicy columnProjectionPolicy) { Preconditions.checkArgument(config.hasPath(ROW_SELECTION_POLICY_CLASS_NAME_KEY)); log.info("Using row selection class name/alias " + config.getString(ROW_SELECTION_POLICY_CLASS_NAME_KEY)); try { return (RowSelectionPolicy)ConstructorUtils.invokeConstructor(Class.forName(this.aliasResolver.resolve( config.getString(ROW_SELECTION_POLICY_CLASS_NAME_KEY))), config, tableMetadata, columnProjectionPolicy); } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | InstantiationException | ClassNotFoundException e) { throw new RuntimeException(e); } }
private static void printUsage(ClassAliasResolver<CliApplication> resolver) { System.out.println("Usage: gobblin <command>"); System.out.println("Available commands:"); for (Alias alias : resolver.getAliasObjects()) { System.out.println("\t" + alias.value() + "\t" + alias.description()); } }
public static Service createAdminServer(Properties properties, URI executionInfoServerURI) { String factoryClassName = properties.getProperty(ConfigurationKeys.ADMIN_SERVER_FACTORY_CLASS_KEY, ConfigurationKeys.DEFAULT_ADMIN_SERVER_FACTORY_CLASS); ClassAliasResolver<AdminWebServerFactory> classResolver = new ClassAliasResolver<>(AdminWebServerFactory.class); try { AdminWebServerFactory factoryInstance = classResolver.resolveClass(factoryClassName).newInstance(); return factoryInstance.createInstance(properties, executionInfoServerURI); } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) { throw new RuntimeException("Unable to instantiate the AdminWebServer factory. " + "Have you included the module in the gobblin distribution? :" + e, e); } }
@Test public void testResolveComGobblinPackage() { ClassAliasResolver<IDummyAliasCom> resolver = new ClassAliasResolver<>(IDummyAliasCom.class); Assert.assertEquals(resolver.resolve("com.alias"), DummyAliasCom.class.getName()); // Resolve returns the passed string if alias mapping does not exist Assert.assertEquals(resolver.resolve("abcd"), "abcd"); }
@Override public GobblinInstancePluginFactory apply(String input) { Class<? extends GobblinInstancePluginFactory> factoryClass; try { factoryClass = _aliasResolver.resolveClass(input); return factoryClass.newInstance(); } catch (ClassNotFoundException|InstantiationException|IllegalAccessException e) { throw new RuntimeException("Unable to instantiate plugin factory " + input + ": " + e, e); } } }));
private DefaultColumnProjectionPolicyFactory() { this.aliasResolver = new ClassAliasResolver<>(ColumnProjectionPolicy.class); }
private List<Alias> getAllAliases() { ClassAliasResolver<EmbeddedGobblinCliFactory> resolver = new ClassAliasResolver<>(EmbeddedGobblinCliFactory.class); return resolver.getAliasObjects(); }
/** * Create a new {@link AuditSink} using the alias or cannonical classname specified at {@value #AUDIT_SINK_CLASS_NAME_KEY} in the <code>config</code> * The {@link AuditSink} class MUST have an accessible constructor <code>abc(Config config, TableMetadata tableMetadata)</code> * <br> * If {@value #AUDIT_SINK_CLASS_NAME_KEY} is not set in <code>config</code>, a default {@link #DEFAULT_AUDIT_SINK_CLASS} is used * * @param config job configs * @param auditRuntimeMetadata runtime table metadata * * @return a new instance of {@link AuditSink} */ public AuditSink create(Config config, ValueAuditRuntimeMetadata auditRuntimeMetadata) { String sinkClassName = DEFAULT_AUDIT_SINK_CLASS; if (config.hasPath(AUDIT_SINK_CLASS_NAME_KEY)) { sinkClassName = config.getString(AUDIT_SINK_CLASS_NAME_KEY); } log.info("Using audit sink class name/alias " + sinkClassName); try { return (AuditSink)ConstructorUtils.invokeConstructor(Class.forName(this.aliasResolver.resolve( sinkClassName)), config, auditRuntimeMetadata); } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | InstantiationException | ClassNotFoundException e) { throw new RuntimeException(e); } }
@Nullable @Override public Callable<Void> apply(FileSet<CopyEntity> input) { try { return GobblinConstructorUtils.<FileSetWorkUnitGenerator>invokeLongestConstructor( new ClassAliasResolver(FileSetWorkUnitGenerator.class).resolveClass(filesetWuGeneratorAlias), input.getDataset(), input, state, targetFs, workUnitsMap, watermarkGenerator, minWorkUnitWeight, lineageInfo); } catch (Exception e) { throw new RuntimeException("Cannot create workunits generator", e); } } });
public ScheduledJobConfigurationManager(EventBus eventBus, Config config) { super(eventBus, config); this.jobSpecs = Maps.newHashMap(); this.refreshIntervalInSeconds = ConfigUtils.getLong(config, GobblinClusterConfigurationKeys.JOB_SPEC_REFRESH_INTERVAL, DEFAULT_JOB_SPEC_REFRESH_INTERVAL); this.fetchJobSpecExecutor = Executors.newSingleThreadScheduledExecutor( ExecutorsUtils.newThreadFactory(Optional.of(LOGGER), Optional.of("FetchJobSpecExecutor"))); this.aliasResolver = new ClassAliasResolver<>(SpecConsumer.class); try { String specConsumerClassName = GobblinClusterConfigurationKeys.DEFAULT_SPEC_CONSUMER_CLASS; if (config.hasPath(GobblinClusterConfigurationKeys.SPEC_CONSUMER_CLASS_KEY)) { specConsumerClassName = config.getString(GobblinClusterConfigurationKeys.SPEC_CONSUMER_CLASS_KEY); } LOGGER.info("Using SpecConsumer ClassNameclass name/alias " + specConsumerClassName); this._specConsumer = (SpecConsumer) ConstructorUtils .invokeConstructor(Class.forName(this.aliasResolver.resolve(specConsumerClassName)), config); } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | InstantiationException | ClassNotFoundException e) { throw new RuntimeException(e); } }
public Builder withCopyRouteGenerator(Config config) throws InstantiationException, IllegalAccessException, ClassNotFoundException { String copyRouteGeneratorStr = config.hasPath(COPYROUTE_OPTIMIZER_CLASS)? config.getString(COPYROUTE_OPTIMIZER_CLASS): DEFAULT_COPYROUTE_OPTIMIZER_CLASS; this.copyRouteGenerator = copyRouteGeneratorResolver.resolveClass(copyRouteGeneratorStr).newInstance(); return this; }