@Override public S getAutoScope(SharedResourcesBroker<S> broker, ConfigView<S, SharedLimiterKey> config) { return broker.selfScope().getType().rootScope(); } }
@Override public S getAutoScope(SharedResourcesBroker<S> broker, ConfigView<S, MysqlDataSourceKey> config) { return broker.selfScope().getType().rootScope(); } }
@Override public S getAutoScope(SharedResourcesBroker<S> broker, ConfigView<S, FileSystemKey> config) { return broker.selfScope().getType().rootScope(); } }
@Override public S getAutoScope(SharedResourcesBroker<S> broker, ConfigView<S, SharedRestClientKey> config) { return broker.selfScope().getType().rootScope(); } }
@Override public S getAutoScope(SharedResourcesBroker<S> broker, ConfigView<S, SharedHiveConfKey> config) { return broker.selfScope().getType().rootScope(); } }
@Override public S getAutoScope(SharedResourcesBroker<S> broker, ConfigView<S, SharedRestClientKey> config) { return broker.selfScope().getType().rootScope(); }
/** * Create a root {@link SharedResourcesBroker}. Subscoped brokers should be built using * {@link SharedResourcesBroker#newSubscopedBuilder(ScopeInstance)}. * * In general, this method will be called only once per application, and all other brokers will Nbe children of the root * application broker. * * @param config The global configuration of the broker. * @param globalScope The scope of the root broker. * @param <S> The {@link ScopeType} DAG used for this broker tree. */ public static <S extends ScopeType<S>> SharedResourcesBrokerImpl<S> createDefaultTopLevelBroker(Config config, ScopeInstance<S> globalScope) { if (!globalScope.getType().equals(globalScope.getType().rootScope())) { throw new IllegalArgumentException(String.format("The top level broker must be created at the root scope type. " + "%s is not a root scope type.", globalScope.getType())); } ScopeWrapper<S> scopeWrapper = new ScopeWrapper<>(globalScope.getType(), globalScope, Lists.<ScopeWrapper<S>>newArrayList()); return new SharedResourcesBrokerImpl<>(new DefaultBrokerCache<S>(), scopeWrapper, Lists.newArrayList(new SharedResourcesBrokerImpl.ScopedConfig<>(globalScope.getType(), getBrokerConfig(addSystemConfigurationToConfig(config)))), ImmutableMap.of(globalScope.getType(), scopeWrapper)); }
/** * Get a {@link org.apache.gobblin.broker.iface.ConfigView} for the input scope, key, and factory. */ public <K extends SharedResourceKey> KeyedScopedConfigViewImpl<S, K> getConfigView(S scope, K key, String factoryName) { Config config = ConfigFactory.empty(); for (ScopedConfig<S> scopedConfig : this.scopedConfigs) { if (scopedConfig.getScopeType().equals(scopedConfig.getScopeType().rootScope())) { config = ConfigUtils.getConfigOrEmpty(scopedConfig.getConfig(), factoryName).withFallback(config); } else if (scope != null && SharedResourcesBrokerUtils.isScopeTypeAncestor(scope, scopedConfig.getScopeType())) { Config tmpConfig = ConfigUtils.getConfigOrEmpty(scopedConfig.getConfig(), factoryName); tmpConfig = ConfigUtils.getConfigOrEmpty(tmpConfig, scope.name()); config = tmpConfig.atKey(scope.name()).withFallback(config); } } return new KeyedScopedConfigViewImpl<>(scope, key, factoryName, config); }
@Override public SharedResourceFactoryResponse<RestliServiceBasedLimiter> createResource(SharedResourcesBroker<S> broker, ScopedConfigView<S, SharedLimiterKey> config) throws NotConfiguredException { S scope = config.getScope(); if (scope != scope.rootScope()) { return new ResourceCoordinate<>(this, config.getKey(), scope.rootScope()); } String serviceIdentifier = config.getConfig().hasPath(SERVICE_IDENTIFIER_KEY) ? config.getConfig().getString(SERVICE_IDENTIFIER_KEY) : "UNKNOWN"; String resourceLimited = config.getKey().getResourceLimitedPath(); MetricContextKey metricContextKey = new SubTaggedMetricContextKey(RestliServiceBasedLimiter.class.getSimpleName() + "_" + resourceLimited, ImmutableMap.of("resourceLimited", resourceLimited)); return new ResourceInstance<>( RestliServiceBasedLimiter.builder() .resourceLimited(resourceLimited) .serviceIdentifier(serviceIdentifier) .metricContext(broker.getSharedResource(new MetricContextFactory<S>(), metricContextKey)) .requestSender(broker.getSharedResource(new RedirectAwareRestClientRequestSender.Factory<S>(), new SharedRestClientKey(RESTLI_SERVICE_NAME))) .build() ); }
@Override public SharedResourceFactoryResponse<SharedResource> createResource(SharedResourcesBroker broker, ScopedConfigView config) { return new ResourceCoordinate<>(new TestFactory<S>(), (TestResourceKey) config.getKey(), (S) config.getScope().rootScope()); } }
@Override public S getAutoScope(SharedResourcesBroker<S> broker, ConfigView<S, MysqlDataSourceKey> config) { return broker.selfScope().getType().rootScope(); } }
@Override public S getAutoScope(SharedResourcesBroker<S> broker, ConfigView<S, FileSystemKey> config) { return broker.selfScope().getType().rootScope(); } }
@Override public S getAutoScope(SharedResourcesBroker<S> broker, ConfigView<S, SharedHiveConfKey> config) { return broker.selfScope().getType().rootScope(); } }
@Override public S getAutoScope(SharedResourcesBroker<S> broker, ConfigView<S, SharedRestClientKey> config) { return broker.selfScope().getType().rootScope(); }
/** * Create a root {@link SharedResourcesBroker}. Subscoped brokers should be built using * {@link SharedResourcesBroker#newSubscopedBuilder(ScopeInstance)}. * * In general, this method will be called only once per application, and all other brokers will Nbe children of the root * application broker. * * @param config The global configuration of the broker. * @param globalScope The scope of the root broker. * @param <S> The {@link ScopeType} DAG used for this broker tree. */ public static <S extends ScopeType<S>> SharedResourcesBrokerImpl<S> createDefaultTopLevelBroker(Config config, ScopeInstance<S> globalScope) { if (!globalScope.getType().equals(globalScope.getType().rootScope())) { throw new IllegalArgumentException(String.format("The top level broker must be created at the root scope type. " + "%s is not a root scope type.", globalScope.getType())); } ScopeWrapper<S> scopeWrapper = new ScopeWrapper<>(globalScope.getType(), globalScope, Lists.<ScopeWrapper<S>>newArrayList()); return new SharedResourcesBrokerImpl<>(new DefaultBrokerCache<S>(), scopeWrapper, Lists.newArrayList(new SharedResourcesBrokerImpl.ScopedConfig<>(globalScope.getType(), getBrokerConfig(addSystemConfigurationToConfig(config)))), ImmutableMap.of(globalScope.getType(), scopeWrapper)); }
/** * Get a {@link org.apache.gobblin.broker.iface.ConfigView} for the input scope, key, and factory. */ public <K extends SharedResourceKey> KeyedScopedConfigViewImpl<S, K> getConfigView(S scope, K key, String factoryName) { Config config = ConfigFactory.empty(); for (ScopedConfig<S> scopedConfig : this.scopedConfigs) { if (scopedConfig.getScopeType().equals(scopedConfig.getScopeType().rootScope())) { config = ConfigUtils.getConfigOrEmpty(scopedConfig.getConfig(), factoryName).withFallback(config); } else if (scope != null && SharedResourcesBrokerUtils.isScopeTypeAncestor(scope, scopedConfig.getScopeType())) { Config tmpConfig = ConfigUtils.getConfigOrEmpty(scopedConfig.getConfig(), factoryName); tmpConfig = ConfigUtils.getConfigOrEmpty(tmpConfig, scope.name()); config = tmpConfig.atKey(scope.name()).withFallback(config); } } return new KeyedScopedConfigViewImpl<>(scope, key, factoryName, config); }