use of com.google.inject.Singleton in project cdap by caskdata.
the class UpgradeTool method createInjector.
@VisibleForTesting
Injector createInjector() throws Exception {
return Guice.createInjector(new ConfigModule(cConf, hConf), new LocationRuntimeModule().getDistributedModules(), new ZKClientModule(), new DiscoveryRuntimeModule().getDistributedModules(), new MessagingClientModule(), Modules.override(new DataSetsModules().getDistributedModules()).with(new AbstractModule() {
@Override
protected void configure() {
bind(DatasetFramework.class).to(InMemoryDatasetFramework.class).in(Scopes.SINGLETON);
// the DataSetsModules().getDistributedModules() binds to RemoteDatasetFramework so override that to
// the same InMemoryDatasetFramework
bind(DatasetFramework.class).annotatedWith(Names.named(DataSetsModules.BASE_DATASET_FRAMEWORK)).to(DatasetFramework.class);
install(new FactoryModuleBuilder().implement(DatasetDefinitionRegistry.class, DefaultDatasetDefinitionRegistry.class).build(DatasetDefinitionRegistryFactory.class));
// CDAP-5954 Upgrade tool does not need to record lineage and metadata changes for now.
bind(LineageWriter.class).to(NoOpLineageWriter.class);
}
}), new ViewAdminModules().getDistributedModules(), new StreamAdminModules().getDistributedModules(), new NotificationFeedClientModule(), new TwillModule(), new ExploreClientModule(), new ProgramRunnerRuntimeModule().getDistributedModules(), new ServiceStoreModules().getDistributedModules(), new SystemDatasetRuntimeModule().getDistributedModules(), // don't need real notifications for upgrade, so use the in-memory implementations
new NotificationServiceRuntimeModule().getInMemoryModules(), new KafkaClientModule(), new NamespaceStoreModule().getDistributedModules(), new AuthenticationContextModules().getMasterModule(), new AuthorizationModule(), new AuthorizationEnforcementModule().getMasterModule(), new SecureStoreModules().getDistributedModules(), new DataFabricModules(UpgradeTool.class.getName()).getDistributedModules(), new AppFabricServiceRuntimeModule().getDistributedModules(), new AbstractModule() {
@Override
protected void configure() {
// the DataFabricDistributedModule needs MetricsCollectionService binding and since Upgrade tool does not do
// anything with Metrics we just bind it to NoOpMetricsCollectionService
bind(MetricsCollectionService.class).to(NoOpMetricsCollectionService.class).in(Scopes.SINGLETON);
bind(MetricDatasetFactory.class).to(DefaultMetricDatasetFactory.class).in(Scopes.SINGLETON);
bind(MetricStore.class).to(DefaultMetricStore.class);
}
@Provides
@Singleton
@Named("datasetInstanceManager")
@SuppressWarnings("unused")
public DatasetInstanceManager getDatasetInstanceManager(TransactionSystemClientService txClient, TransactionExecutorFactory txExecutorFactory, @Named("datasetMDS") DatasetFramework framework) {
return new DatasetInstanceManager(txClient, txExecutorFactory, framework);
}
// This is needed because the LocalApplicationManager
// expects a dsframework injection named datasetMDS
@Provides
@Singleton
@Named("datasetMDS")
@SuppressWarnings("unused")
public DatasetFramework getInDsFramework(DatasetFramework dsFramework) {
return dsFramework;
}
});
}
use of com.google.inject.Singleton in project cdap by caskdata.
the class CoprocessorBuildTool method main.
public static void main(final String[] args) throws ParseException {
Options options = new Options().addOption(new Option("h", "help", false, "Print this usage message.")).addOption(new Option("f", "force", false, "Overwrites any coprocessors that already exist."));
CommandLineParser parser = new BasicParser();
CommandLine commandLine = parser.parse(options, args);
String[] commandArgs = commandLine.getArgs();
// if help is an option, or if there isn't a single 'ensure' command, print usage and exit.
if (commandLine.hasOption("h") || commandArgs.length != 1 || !"check".equalsIgnoreCase(commandArgs[0])) {
HelpFormatter helpFormatter = new HelpFormatter();
helpFormatter.printHelp(CoprocessorBuildTool.class.getName() + " check", "Checks that HBase coprocessors required by CDAP are loaded onto HDFS. " + "If not, the coprocessors are built and placed on HDFS.", options, "");
System.exit(0);
}
boolean overwrite = commandLine.hasOption("f");
CConfiguration cConf = CConfiguration.create();
Configuration hConf = HBaseConfiguration.create();
Injector injector = Guice.createInjector(new ConfigModule(cConf, hConf), // for LocationFactory
new PrivateModule() {
@Override
protected void configure() {
bind(FileContext.class).toProvider(FileContextProvider.class).in(Scopes.SINGLETON);
expose(LocationFactory.class);
}
@Provides
@Singleton
private LocationFactory providesLocationFactory(Configuration hConf, CConfiguration cConf, FileContext fc) {
final String namespace = cConf.get(Constants.CFG_HDFS_NAMESPACE);
if (UserGroupInformation.isSecurityEnabled()) {
return new FileContextLocationFactory(hConf, namespace);
}
return new InsecureFileContextLocationFactory(hConf, namespace, fc);
}
});
try {
SecurityUtil.loginForMasterService(cConf);
} catch (Exception e) {
LOG.error("Failed to login as CDAP user", e);
System.exit(1);
}
LocationFactory locationFactory = injector.getInstance(LocationFactory.class);
HBaseTableUtil tableUtil = new HBaseTableUtilFactory(cConf).get();
CoprocessorManager coprocessorManager = new CoprocessorManager(cConf, locationFactory, tableUtil);
try {
Location location = coprocessorManager.ensureCoprocessorExists(overwrite);
LOG.info("coprocessor exists at {}.", location);
} catch (IOException e) {
LOG.error("Unable to build and upload coprocessor jars.", e);
System.exit(1);
}
}
use of com.google.inject.Singleton in project stdlib by petergeneric.
the class ThymeleafModule method getTemplateEngine.
@Provides
@Singleton
public TemplateEngine getTemplateEngine(ITemplateResolver resolver) {
TemplateEngine engine = new TemplateEngine();
engine.setTemplateResolver(resolver);
return engine;
}
use of com.google.inject.Singleton in project Singularity by HubSpot.
the class SingularityExecutorModule method providesHttpClient.
@Provides
@Singleton
@Named(LOCAL_DOWNLOAD_HTTP_CLIENT)
public AsyncHttpClient providesHttpClient(SingularityExecutorConfiguration configuration) {
AsyncHttpClientConfig.Builder configBldr = new AsyncHttpClientConfig.Builder();
configBldr.setRequestTimeoutInMs((int) configuration.getLocalDownloadServiceTimeoutMillis());
configBldr.setIdleConnectionTimeoutInMs((int) configuration.getLocalDownloadServiceTimeoutMillis());
configBldr.addRequestFilter(new ThrottleRequestFilter(configuration.getLocalDownloadServiceMaxConnections()));
return new AsyncHttpClient(configBldr.build());
}
use of com.google.inject.Singleton in project apollo by spotify.
the class MetricsModule method semanticMetricRegistry.
@Provides
@Singleton
public SemanticMetricRegistry semanticMetricRegistry() {
final SemanticMetricRegistry metricRegistry = new SemanticMetricRegistry();
LOG.info("Creating SemanticMetricRegistry");
// register JVM metricSets, using an empty MetricId as the FastForwardReporter will prepend
// the injected MetricId.
metricRegistry.register(MetricId.EMPTY, new MemoryUsageGaugeSet());
metricRegistry.register(MetricId.EMPTY, new GarbageCollectorMetricSet());
metricRegistry.register(MetricId.EMPTY, new ThreadStatesMetricSet());
metricRegistry.register(MetricId.EMPTY, CpuGaugeSet.create());
metricRegistry.register(MetricId.EMPTY, new FileDescriptorGaugeSet());
return metricRegistry;
}
Aggregations