/** * 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); } } }
public SpecExecutorInstanceProducer getSpecExecutorInstanceProducer() { if (null == specExecutorInstanceProducer) { String specExecutorInstanceProducerClass = DEFAULT_SPEC_EXECUTOR_INSTANCE_PRODUCER; if (config.hasPath(SPEC_EXECUTOR_INSTANCE_PRODUCER_KEY)) { specExecutorInstanceProducerClass = config.getString(SPEC_EXECUTOR_INSTANCE_PRODUCER_KEY); } try { ClassAliasResolver<SpecExecutorInstanceProducer> _aliasResolver = new ClassAliasResolver<>(SpecExecutorInstanceProducer.class); specExecutorInstanceProducer = (SpecExecutorInstanceProducer) ConstructorUtils .invokeConstructor(Class.forName(_aliasResolver .resolve(specExecutorInstanceProducerClass)), config); } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | InstantiationException | ClassNotFoundException e) { throw new RuntimeException(e); } } return specExecutorInstanceProducer; }
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(); }
public ConfigBasedTopologySpecFactory(Config config, Optional<Logger> log) { Preconditions.checkNotNull(config, "Config should not be null"); _log = log.isPresent() ? log.get() : LoggerFactory.getLogger(getClass()); _config = config; _aliasResolver = new ClassAliasResolver<>(SpecExecutorInstanceProducer.class); }
specExecutorInstanceProducer = (SpecExecutorInstanceProducer) ConstructorUtils .invokeConstructor(Class.forName(_aliasResolver .resolve(specExecutorInstanceProducerClass)), topologyConfig); } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | InstantiationException | ClassNotFoundException 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()); } }
@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); } } }));
public RetentionAction(Config actionConfig, FileSystem fs, Config jobConfig) { this.versionSelectionAliasResolver = new ClassAliasResolver<>(VersionSelectionPolicy.class); this.fs = fs; this.isSimulateMode = ConfigUtils.getBoolean(jobConfig, FsCleanableHelper.SIMULATE_KEY, Boolean.valueOf(FsCleanableHelper.SIMULATE_DEFAULT)); }
private CompactorCompletionListener getCompactionCompleteListener () { ClassAliasResolver<CompactorCompletionListenerFactory> classAliasResolver = new ClassAliasResolver<>(CompactorCompletionListenerFactory.class); String listenerName= this.state.getProp(MRCompactor.COMPACTION_COMPLETE_LISTERNER, MRCompactor.DEFAULT_COMPACTION_COMPLETE_LISTERNER); try { CompactorCompletionListenerFactory factory = GobblinConstructorUtils.invokeFirstConstructor( classAliasResolver.resolveClass(listenerName), ImmutableList.of()); return factory.createCompactorCompactionListener(this.state); } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | InstantiationException | ClassNotFoundException e) { throw new IllegalArgumentException(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<>(SpecExecutorInstanceConsumer.class); try { String specExecutorInstanceConsumerClassName = GobblinClusterConfigurationKeys.DEFAULT_SPEC_EXECUTOR_INSTANCE_CONSUMER_CLASS; if (config.hasPath(GobblinClusterConfigurationKeys.SPEC_EXECUTOR_INSTANCE_CONSUMER_CLASS_KEY)) { specExecutorInstanceConsumerClassName = config.getString(GobblinClusterConfigurationKeys.SPEC_EXECUTOR_INSTANCE_CONSUMER_CLASS_KEY); } LOGGER.info("Using SpecExecutorInstanceConsumer ClassNameclass name/alias " + specExecutorInstanceConsumerClassName); this.specExecutorInstanceConsumer = (SpecExecutorInstanceConsumer) ConstructorUtils .invokeConstructor(Class.forName(this.aliasResolver.resolve( specExecutorInstanceConsumerClassName)), 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; }
protected DatasetStateStore createStateStore(Config jobConfig) throws IOException { boolean stateStoreEnabled = !jobConfig.hasPath(ConfigurationKeys.STATE_STORE_ENABLED) || jobConfig .getBoolean(ConfigurationKeys.STATE_STORE_ENABLED); String stateStoreType; if (!stateStoreEnabled) { stateStoreType = ConfigurationKeys.STATE_STORE_TYPE_NOOP; } else { stateStoreType = ConfigUtils .getString(jobConfig, ConfigurationKeys.STATE_STORE_TYPE_KEY, ConfigurationKeys.DEFAULT_STATE_STORE_TYPE); } ClassAliasResolver<DatasetStateStore.Factory> resolver = new ClassAliasResolver<>(DatasetStateStore.Factory.class); try { DatasetStateStore.Factory stateStoreFactory = resolver.resolveClass(stateStoreType).newInstance(); return stateStoreFactory.createStateStore(jobConfig); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new IOException(e); } }
public StreamingJobConfigurationManager(EventBus eventBus, Config config, MutableJobCatalog jobCatalog) { super(eventBus, config); this.stopTimeoutSeconds = ConfigUtils.getLong(config, GobblinClusterConfigurationKeys.STOP_TIMEOUT_SECONDS, GobblinClusterConfigurationKeys.DEFAULT_STOP_TIMEOUT_SECONDS); this.fetchJobSpecExecutor = Executors.newSingleThreadExecutor( ExecutorsUtils.newThreadFactory(Optional.of(LOGGER), Optional.of("FetchJobSpecExecutor"))); String specExecutorInstanceConsumerClassName = ConfigUtils.getString(config, GobblinClusterConfigurationKeys.SPEC_EXECUTOR_INSTANCE_CONSUMER_CLASS_KEY, GobblinClusterConfigurationKeys.DEFAULT_STREAMING_SPEC_EXECUTOR_INSTANCE_CONSUMER_CLASS); LOGGER.info("Using SpecExecutorInstanceConsumer ClassNameclass name/alias " + specExecutorInstanceConsumerClassName); try { ClassAliasResolver<SpecExecutorInstanceConsumer> aliasResolver = new ClassAliasResolver<>(SpecExecutorInstanceConsumer.class); this.specExecutorInstanceConsumer = (SpecExecutorInstanceConsumer) GobblinConstructorUtils.invokeFirstConstructor( Class.forName(aliasResolver.resolve(specExecutorInstanceConsumerClassName)), ImmutableList.<Object>of(config, jobCatalog), ImmutableList.<Object>of(config)); } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | InstantiationException | ClassNotFoundException e) { throw new RuntimeException("Could not construct SpecExecutorInstanceConsumer " + specExecutorInstanceConsumerClassName, e); } }
public Builder withReplicationSource(Config config) throws InstantiationException, IllegalAccessException, ClassNotFoundException { Preconditions.checkArgument(config.hasPath(REPLICATION_SOURCE), "missing required config entry " + REPLICATION_SOURCE); Config sourceConfig = config.getConfig(REPLICATION_SOURCE); String endPointFactory = sourceConfig.hasPath(END_POINT_FACTORY_CLASS) ? sourceConfig.getString(END_POINT_FACTORY_CLASS) : DEFAULT_END_POINT_FACTORY_CLASS; EndPointFactory factory = endPointFactoryResolver.resolveClass(endPointFactory).newInstance(); this.source = factory.buildSource(sourceConfig, this.selectionConfig); return this; }
public static void main(String[] args) { ClassAliasResolver<CliApplication> resolver = new ClassAliasResolver<>(CliApplication.class); if (args.length < 1 || Sets.newHashSet("-h", "--help").contains(args[0])) { printUsage(resolver); return; } String alias = args[0]; try { CliApplication application = resolver.resolveClass(alias).newInstance(); application.run(args); } catch (ReflectiveOperationException roe) { System.err.println("Could not find an application with alias " + alias); printUsage(resolver); } catch (Throwable t) { System.out.println("Error: " + t.getMessage()); t.printStackTrace(); } }
public Orchestrator(Config config, Optional<TopologyCatalog> topologyCatalog, Optional<Logger> log, boolean instrumentationEnabled) { _log = log.isPresent() ? log.get() : LoggerFactory.getLogger(getClass()); if (instrumentationEnabled) { this.metricContext = Instrumented.getMetricContext(ConfigUtils.configToState(config), IdentityFlowToJobSpecCompiler.class); this.flowOrchestrationSuccessFulMeter = Optional.of(this.metricContext.meter(ServiceMetricNames.FLOW_ORCHESTRATION_SUCCESSFUL_METER)); this.flowOrchestrationFailedMeter = Optional.of(this.metricContext.meter(ServiceMetricNames.FLOW_ORCHESTRATION_FAILED_METER)); this.flowOrchestrationTimer = Optional.<Timer>of(this.metricContext.timer(ServiceMetricNames.FLOW_ORCHESTRATION_TIMER)); } else { this.metricContext = null; this.flowOrchestrationSuccessFulMeter = Optional.absent(); this.flowOrchestrationFailedMeter = Optional.absent(); this.flowOrchestrationTimer = Optional.absent(); } this.aliasResolver = new ClassAliasResolver<>(SpecCompiler.class); this.topologyCatalog = topologyCatalog; try { String specCompilerClassName = ServiceConfigKeys.DEFAULT_GOBBLIN_SERVICE_FLOWCOMPILER_CLASS; if (config.hasPath(ServiceConfigKeys.GOBBLIN_SERVICE_FLOWCOMPILER_CLASS_KEY)) { specCompilerClassName = config.getString(ServiceConfigKeys.GOBBLIN_SERVICE_FLOWCOMPILER_CLASS_KEY); } _log.info("Using specCompiler class name/alias " + specCompilerClassName); this.specCompiler = (SpecCompiler) ConstructorUtils.invokeConstructor(Class.forName(this.aliasResolver.resolve( specCompilerClassName)), config); } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | InstantiationException | ClassNotFoundException e) { throw new RuntimeException(e); } }
public Builder withReplicationReplica(Config config) throws InstantiationException, IllegalAccessException, ClassNotFoundException { Preconditions.checkArgument(config.hasPath(REPLICATION_REPLICAS), "missing required config entery " + REPLICATION_REPLICAS); Config replicasConfig = config.getConfig(REPLICATION_REPLICAS); Preconditions.checkArgument(replicasConfig.hasPath(REPLICATOIN_REPLICAS_LIST), "missing required config entery " + REPLICATOIN_REPLICAS_LIST); List<String> replicaNames = replicasConfig.getStringList(REPLICATOIN_REPLICAS_LIST); for (String replicaName : replicaNames) { Preconditions.checkArgument(replicasConfig.hasPath(replicaName), "missing replica name " + replicaName); Config subConfig = replicasConfig.getConfig(replicaName); // each replica could have own EndPointFactory resolver String endPointFactory = subConfig.hasPath(END_POINT_FACTORY_CLASS) ? subConfig.getString(END_POINT_FACTORY_CLASS) : DEFAULT_END_POINT_FACTORY_CLASS; EndPointFactory factory = endPointFactoryResolver.resolveClass(endPointFactory).newInstance(); this.replicas.add(factory.buildReplica(subConfig, replicaName, this.selectionConfig)); } return this; }
/** * Infer and construct a {@link RequestAllocator} from an input {@link Config}. */ public static <T extends Request<T>> RequestAllocator<T> inferFromConfig(RequestAllocatorConfig<T> configuration) { try { String alias = configuration.getLimitedScopeConfig().hasPath(ALLOCATOR_ALIAS_KEY) ? configuration.getLimitedScopeConfig().getString(ALLOCATOR_ALIAS_KEY) : BruteForceAllocator.Factory.class.getName(); RequestAllocator.Factory allocatorFactory = new ClassAliasResolver<>(RequestAllocator.Factory.class). resolveClass(alias).newInstance(); log.info("Using allocator factory " + allocatorFactory.getClass().getName()); return allocatorFactory.createRequestAllocator(configuration); } catch (ReflectiveOperationException roe) { throw new RuntimeException(roe); } } }
this.aliasResolver = new ClassAliasResolver<>(SpecStore.class); try { Config newConfig = config; this.specStore = (SpecStore) ConstructorUtils.invokeConstructor(Class.forName(this.aliasResolver.resolve( specStoreClassName)), newConfig, this); } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | InstantiationException