/** * Instantiate a {@link GobblinInstancePluginFactory} by alias. */ public static GobblinInstancePluginFactory instantiatePluginByAlias(String alias) throws ClassNotFoundException, InstantiationException, IllegalAccessException { return RESOLVER.resolveClass(alias).newInstance(); }
@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 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; }
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 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; }
/** * 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); } } }
@Override public Extractor getExtractor(WorkUnitState state) throws IOException { try { return classAliasResolver.resolveClass(state.getProp(HIVE_SOURCE_EXTRACTOR_TYPE, DEFAULT_HIVE_SOURCE_EXTRACTOR_TYPE)) .newInstance().createExtractor(state, getSourceFs(state)); } catch (Exception e) { throw new IOException(e); } }
@SuppressWarnings("unchecked") protected VersionSelectionPolicy<DatasetVersion> createSelectionPolicy(Config selectionConfig, Config jobConfig) { try { String selectionPolicyKey = StringUtils.substringAfter(ConfigurableCleanableDataset.SELECTION_POLICY_CLASS_KEY, ConfigurableCleanableDataset.CONFIGURATION_KEY_PREFIX); Preconditions.checkArgument(selectionConfig.hasPath(selectionPolicyKey)); String className = selectionConfig.getString(selectionPolicyKey); return (VersionSelectionPolicy<DatasetVersion>) GobblinConstructorUtils.invokeFirstConstructor( this.versionSelectionAliasResolver.resolveClass(className), ImmutableList.<Object> of(selectionConfig), ImmutableList.<Object> of(selectionConfig, ConfigUtils.configToProperties(jobConfig)), ImmutableList.<Object> of(ConfigUtils.configToProperties(jobConfig))); } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | InstantiationException | ClassNotFoundException e) { throw new IllegalArgumentException(e); } } }
/** * 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); } } }
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(); } }
protected KafkaReporter(Builder<?> builder, Config config) throws IOException { super(builder, config); SchemaVersionWriter versionWriter; if (config.hasPath(SCHEMA_VERSION_WRITER_TYPE)) { try { ClassAliasResolver<SchemaVersionWriter> resolver = new ClassAliasResolver<>(SchemaVersionWriter.class); Class<? extends SchemaVersionWriter> klazz = resolver.resolveClass(config.getString(SCHEMA_VERSION_WRITER_TYPE)); versionWriter = klazz.newInstance(); } catch (ReflectiveOperationException roe) { throw new IOException("Could not instantiate version writer.", roe); } } else { versionWriter = new FixedSchemaVersionWriter(); } log.info("Schema version writer: " + versionWriter.getClass().getName()); this.serializer = this.closer.register(createSerializer(versionWriter)); if (builder.kafkaPusher.isPresent()) { this.kafkaPusher = builder.kafkaPusher.get(); } else { this.kafkaPusher = this.closer.register(new KafkaPusher(builder.brokers, builder.topic)); } }
@Override public ThrottlingPolicy createPolicy(SharedLimiterKey key, SharedResourcesBroker<ThrottlingServerScopes> broker, Config config) { try { Config resourceConfig = getConfigClient().getConfig(new URI(config.getString(CONFIG_KEY_URI_PREFIX_KEY) + key.getResourceLimitedPath())); ThrottlingPolicyFactory.SpecificPolicyFactory factory = ThrottlingPolicyFactory.POLICY_CLASS_RESOLVER.resolveClass(resourceConfig.getString(POLICY_KEY)).newInstance(); return factory.createPolicy(key, broker, ConfigUtils.getConfigOrEmpty(resourceConfig, THROTTLING_CONFIG_PREFIX)); } catch (URISyntaxException | ConfigStoreFactoryDoesNotExistsException | ConfigStoreCreationException | ReflectiveOperationException exc) { throw new RuntimeException(exc); } }
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 StateStoreBasedWatermarkStorage(State taskState) { Preconditions.checkArgument(taskState != null); Preconditions.checkArgument(!taskState.getProp(ConfigurationKeys.JOB_NAME_KEY).isEmpty()); String watermarkStateStoreType = taskState.getProp(WATERMARK_STORAGE_TYPE_KEY, WATERMARK_STORAGE_TYPE_DEFAULT); ClassAliasResolver<StateStore.Factory> resolver = new ClassAliasResolver<>(StateStore.Factory.class); StateStore.Factory stateStoreFactory; try { stateStoreFactory = resolver.resolveClass(watermarkStateStoreType).newInstance(); } catch (ClassNotFoundException cnfe) { throw new RuntimeException(cnfe); } catch (InstantiationException ie) { throw new RuntimeException(ie); } catch (IllegalAccessException iae) { throw new RuntimeException(iae); } Config config = getStateStoreConfig(taskState); _stateStore = stateStoreFactory.createStateStore(config, CheckpointableWatermarkState.class); _storeName = WATERMARK_STORAGE_PREFIX + taskState.getProp(ConfigurationKeys.JOB_NAME_KEY); log.info("State Store directory configured as : {}", config.getString(ConfigurationKeys.STATE_STORE_ROOT_DIR_KEY)); log.info("Configured the StateStoreBasedWatermarkStorage with storeName: {}", _storeName); }
private ImmutableList<RecompactionCondition> getConditionsFromProperties (Dataset dataset) { ClassAliasResolver<RecompactionConditionFactory> conditionClassAliasResolver = new ClassAliasResolver<>(RecompactionConditionFactory.class); List<String> factoryNames = dataset.jobProps().getPropAsList(MRCompactor.COMPACTION_RECOMPACT_COMBINE_CONDITIONS, MRCompactor.DEFAULT_COMPACTION_RECOMPACT_CONDITION); ImmutableList.Builder<RecompactionCondition> builder = ImmutableList.builder(); for (String factoryName : factoryNames) { try { RecompactionConditionFactory factory = GobblinConstructorUtils.invokeFirstConstructor( conditionClassAliasResolver.resolveClass(factoryName), ImmutableList.of()); RecompactionCondition condition = factory.createRecompactionCondition(dataset); builder.add(condition); } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | InstantiationException | ClassNotFoundException e) { throw new IllegalArgumentException(e); } } return builder.build(); }
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); } }
private RecompactionCondition createRecompactionCondition () { ClassAliasResolver<RecompactionConditionFactory> conditionClassAliasResolver = new ClassAliasResolver<>(RecompactionConditionFactory.class); String factoryName = this.dataset.jobProps().getProp(MRCompactor.COMPACTION_RECOMPACT_CONDITION, MRCompactor.DEFAULT_COMPACTION_RECOMPACT_CONDITION); try { RecompactionConditionFactory factory = GobblinConstructorUtils.invokeFirstConstructor( conditionClassAliasResolver.resolveClass(factoryName), ImmutableList.of()); return factory.createRecompactionCondition(dataset); } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | InstantiationException | ClassNotFoundException e) { throw new IllegalArgumentException(e); } }
/** * Obtain a client factory * @param state job state * @return a factory which creates {@link AuditCountClient}. * If no factory is set or an error occurred, a {@link EmptyAuditCountClientFactory} is * returned which creates a <code>null</code> {@link AuditCountClient} */ private static AuditCountClientFactory getClientFactory (State state) { if (!state.contains(AuditCountClientFactory.AUDIT_COUNT_CLIENT_FACTORY)) { return new EmptyAuditCountClientFactory (); } try { String factoryName = state.getProp(AuditCountClientFactory.AUDIT_COUNT_CLIENT_FACTORY); ClassAliasResolver<AuditCountClientFactory> conditionClassAliasResolver = new ClassAliasResolver<>(AuditCountClientFactory.class); AuditCountClientFactory factory = conditionClassAliasResolver.resolveClass(factoryName).newInstance(); return factory; } catch (Exception e) { throw new RuntimeException(e); } }
private DatasetStateStore getDatasetStateStore() throws IOException { if (this.stateStore == null) { ClassAliasResolver<DatasetStateStore.Factory> resolver = new ClassAliasResolver<>(DatasetStateStore.Factory.class); String stateStoreType = this.props.getProp(ConfigurationKeys.STATE_STORE_TYPE_KEY, ConfigurationKeys.DEFAULT_STATE_STORE_TYPE); try { DatasetStateStore.Factory stateStoreFactory = resolver.resolveClass(stateStoreType).newInstance(); this.stateStore = stateStoreFactory.createStateStore(ConfigFactory.parseProperties(props.getProperties())); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new IOException(e); } } return this.stateStore; }
@Override public SharedResourceFactoryResponse<ThrottlingPolicy> createResource(SharedResourcesBroker<ThrottlingServerScopes> broker, ScopedConfigView<ThrottlingServerScopes, SharedLimiterKey> configView) throws NotConfiguredException { Config config = configView.getConfig(); if (!config.hasPath(POLICY_KEY)) { if (config.hasPath(FAIL_ON_UNKNOWN_RESOURCE_ID) && config.getBoolean(FAIL_ON_UNKNOWN_RESOURCE_ID)) { throw new NotConfiguredException("Missing key " + POLICY_KEY); } else { return new TTLResourceEntry<ThrottlingPolicy>(new NoopPolicy(), ConfigUtils.getLong(config, RELOAD_FREQUENCY_KEY, DEFAULT_RELOAD_FREQUENCY), false); } } try { SpecificPolicyFactory factory = POLICY_CLASS_RESOLVER.resolveClass(config.getString(POLICY_KEY)).newInstance(); return new TTLResourceEntry<>(factory.createPolicy(configView.getKey(), broker, config), ConfigUtils.getLong(config, RELOAD_FREQUENCY_KEY, DEFAULT_RELOAD_FREQUENCY), false); } catch (ReflectiveOperationException roe) { throw new RuntimeException(roe); } }