use of org.apache.gobblin.broker.ResourceInstance in project incubator-gobblin by apache.
the class MysqlDataSourceFactory method createResource.
@Override
public SharedResourceFactoryResponse<BasicDataSource> createResource(SharedResourcesBroker<S> broker, ScopedConfigView<S, MysqlDataSourceKey> config) throws NotConfiguredException {
MysqlDataSourceKey key = config.getKey();
Config configuration = key.getConfig();
BasicDataSource dataSource = MysqlStateStore.newDataSource(configuration);
return new ResourceInstance<>(dataSource);
}
use of org.apache.gobblin.broker.ResourceInstance in project incubator-gobblin by apache.
the class MetricContextFactory method createResource.
@Override
public SharedResourceFactoryResponse<MetricContext> createResource(SharedResourcesBroker<S> broker, ScopedConfigView<S, MetricContextKey> config) throws NotConfiguredException {
try {
if (config.getKey() instanceof SubTaggedMetricContextKey) {
SubTaggedMetricContextKey key = (SubTaggedMetricContextKey) config.getKey();
MetricContext parent = broker.getSharedResource(this, new MetricContextKey());
MetricContext.Builder builder = parent.childBuilder(key.getMetricContextName());
for (Map.Entry<String, String> entry : key.getTags().entrySet()) {
builder.addTag(new Tag<>(entry.getKey(), entry.getValue()));
}
return new ResourceInstance<>(builder.build());
}
MetricContext parentMetricContext = RootMetricContext.get();
Collection<S> parents = config.getScope().parentScopes();
if (parents != null && !parents.isEmpty()) {
S parentScope = parents.iterator().next();
parentMetricContext = broker.getSharedResourceAtScope(this, config.getKey(), parentScope);
}
// If this is the root scope, append a UUID to the name. This allows having a separate root context per broker.
String metricContextName = parents == null ? config.getScope().name() + "_" + UUID.randomUUID().toString() : broker.selfScope().getScopeId();
MetricContext.Builder builder = parentMetricContext.childBuilder(metricContextName);
builder.addTag(new Tag<>(config.getScope().name(), broker.getScope(config.getScope()).getScopeId()));
for (Map.Entry<String, ConfigValue> entry : ConfigUtils.getConfigOrEmpty(config.getConfig(), TAG_KEY).entrySet()) {
builder.addTag(new Tag<>(entry.getKey(), entry.getValue().unwrapped()));
}
return new ResourceInstance<>(builder.build());
} catch (NoSuchScopeException nsse) {
throw new RuntimeException("Could not create MetricContext.", nsse);
}
}
use of org.apache.gobblin.broker.ResourceInstance in project incubator-gobblin by apache.
the class RestliLimiterFactory method createResource.
@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());
}
use of org.apache.gobblin.broker.ResourceInstance in project incubator-gobblin by apache.
the class DataPublisherFactory method createResource.
@Override
public SharedResourceFactoryResponse<DataPublisher> createResource(SharedResourcesBroker<S> broker, ScopedConfigView<S, DataPublisherKey> config) throws NotConfiguredException {
try {
DataPublisherKey key = config.getKey();
String publisherClassName = key.getPublisherClassName();
State state = key.getState();
Class<? extends DataPublisher> dataPublisherClass = (Class<? extends DataPublisher>) Class.forName(publisherClassName);
log.info("Creating data publisher with class {} in scope {}. ", publisherClassName, config.getScope().toString());
DataPublisher publisher = DataPublisher.getInstance(dataPublisherClass, state);
// once from the broker.
if (isPublisherCacheable(publisher)) {
return new ResourceInstance<>(publisher);
} else {
return new ImmediatelyInvalidResourceEntry<>(publisher);
}
} catch (ReflectiveOperationException e) {
throw new RuntimeException(e);
}
}
use of org.apache.gobblin.broker.ResourceInstance in project incubator-gobblin by apache.
the class FileSystemFactory method createResource.
@Override
public SharedResourceFactoryResponse<FileSystem> createResource(SharedResourcesBroker<S> broker, ScopedConfigView<S, FileSystemKey> config) throws NotConfiguredException {
try {
FileSystemKey key = config.getKey();
URI uri = key.getUri();
Configuration hadoopConf = key.getConfiguration();
log.info("Creating instrumented FileSystem for uri " + uri);
Class<? extends FileSystem> fsClass = FileSystem.getFileSystemClass(uri.getScheme(), hadoopConf);
if (InstrumentedFileSystem.class.isAssignableFrom(fsClass)) {
InstrumentedFileSystem tmpfs = (InstrumentedFileSystem) fsClass.newInstance();
hadoopConf = new Configuration(hadoopConf);
String schemeKey = "fs." + uri.getScheme() + ".impl";
hadoopConf.set(schemeKey, tmpfs.underlyingFs.getClass().getName());
}
FileSystem fs = FileSystem.newInstance(uri, hadoopConf);
ServiceLoader<FileSystemInstrumentationFactory> loader = ServiceLoader.load(FileSystemInstrumentationFactory.class);
for (FileSystemInstrumentationFactory instrumentationFactory : loader) {
fs = instrumentationFactory.instrumentFileSystem(fs, broker, config);
}
return new ResourceInstance<>(fs);
} catch (IOException | ReflectiveOperationException ioe) {
throw new RuntimeException(ioe);
}
}
Aggregations