Search in sources :

Example 31 with Singleton

use of com.google.inject.Singleton in project ovirt-engine by oVirt.

the class DataCenterModule method getDataCenterStorageListProvider.

// Search-able Detail Models
@Provides
@Singleton
public SearchableDetailModelProvider<StorageDomain, DataCenterListModel, DataCenterStorageListModel> getDataCenterStorageListProvider(EventBus eventBus, Provider<DefaultConfirmationPopupPresenterWidget> defaultConfirmPopupProvider, final Provider<FindSingleStoragePopupPresenterWidget> singlePopupProvider, final Provider<FindMultiStoragePopupPresenterWidget> multiPopupProvider, final Provider<RemoveConfirmationPopupPresenterWidget> removeConfirmPopupProvider, final Provider<DataCenterListModel> mainModelProvider, final Provider<DataCenterStorageListModel> modelProvider) {
    SearchableDetailTabModelProvider<StorageDomain, DataCenterListModel, DataCenterStorageListModel> result = new SearchableDetailTabModelProvider<StorageDomain, DataCenterListModel, DataCenterStorageListModel>(eventBus, defaultConfirmPopupProvider) {

        @Override
        public AbstractModelBoundPopupPresenterWidget<? extends Model, ?> getModelPopup(DataCenterStorageListModel source, UICommand lastExecutedCommand, Model windowModel) {
            DataCenterStorageListModel model = getModel();
            if (lastExecutedCommand == model.getAttachStorageCommand()) {
                return multiPopupProvider.get();
            } else if (lastExecutedCommand == model.getAttachISOCommand() || lastExecutedCommand == model.getAttachBackupCommand()) {
                return singlePopupProvider.get();
            } else {
                return super.getModelPopup(source, lastExecutedCommand, windowModel);
            }
        }

        @Override
        public AbstractModelBoundPopupPresenterWidget<? extends ConfirmationModel, ?> getConfirmModelPopup(DataCenterStorageListModel source, UICommand lastExecutedCommand) {
            if (lastExecutedCommand == getModel().getDetachCommand() || lastExecutedCommand.getName().equals("OnAttach")) {
                // $NON-NLS-1$ ) {
                return removeConfirmPopupProvider.get();
            } else if (lastExecutedCommand == getModel().getMaintenanceCommand() || lastExecutedCommand.getName().equals("OnMaintenance")) {
                // $NON-NLS-1$) {
                return removeConfirmPopupProvider.get();
            } else {
                return super.getConfirmModelPopup(source, lastExecutedCommand);
            }
        }
    };
    result.setMainModelProvider(mainModelProvider);
    result.setModelProvider(modelProvider);
    return result;
}
Also used : StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) DataCenterListModel(org.ovirt.engine.ui.uicommonweb.models.datacenters.DataCenterListModel) DataCenterIscsiBondListModel(org.ovirt.engine.ui.uicommonweb.models.datacenters.DataCenterIscsiBondListModel) DataCenterQuotaListModel(org.ovirt.engine.ui.uicommonweb.models.datacenters.DataCenterQuotaListModel) DataCenterListModel(org.ovirt.engine.ui.uicommonweb.models.datacenters.DataCenterListModel) DataCenterNetworkListModel(org.ovirt.engine.ui.uicommonweb.models.datacenters.DataCenterNetworkListModel) DataCenterStorageListModel(org.ovirt.engine.ui.uicommonweb.models.datacenters.DataCenterStorageListModel) DataCenterCpuQosListModel(org.ovirt.engine.ui.uicommonweb.models.datacenters.qos.DataCenterCpuQosListModel) NewHostNetworkQosModel(org.ovirt.engine.ui.uicommonweb.models.datacenters.qos.NewHostNetworkQosModel) PermissionListModel(org.ovirt.engine.ui.uicommonweb.models.configure.PermissionListModel) ConfirmationModel(org.ovirt.engine.ui.uicommonweb.models.ConfirmationModel) DataCenterClusterListModel(org.ovirt.engine.ui.uicommonweb.models.datacenters.DataCenterClusterListModel) DataCenterHostNetworkQosListModel(org.ovirt.engine.ui.uicommonweb.models.datacenters.qos.DataCenterHostNetworkQosListModel) DataCenterStorageQosListModel(org.ovirt.engine.ui.uicommonweb.models.datacenters.qos.DataCenterStorageQosListModel) Model(org.ovirt.engine.ui.uicommonweb.models.Model) DataCenterNetworkQoSListModel(org.ovirt.engine.ui.uicommonweb.models.datacenters.DataCenterNetworkQoSListModel) DataCenterEventListModel(org.ovirt.engine.ui.uicommonweb.models.datacenters.DataCenterEventListModel) DataCenterStorageListModel(org.ovirt.engine.ui.uicommonweb.models.datacenters.DataCenterStorageListModel) UICommand(org.ovirt.engine.ui.uicommonweb.UICommand) SearchableDetailTabModelProvider(org.ovirt.engine.ui.common.uicommon.model.SearchableDetailTabModelProvider) Singleton(com.google.inject.Singleton) Provides(com.google.inject.Provides)

Example 32 with Singleton

use of com.google.inject.Singleton in project ovirt-engine by oVirt.

the class EventModule method getEventModelProvider.

@Provides
@Singleton
@Named("notification")
public EventModelProvider getEventModelProvider(EventBus eventBus, Provider<DefaultConfirmationPopupPresenterWidget> defaultConfirmPopupProvider, @Named("notification") final Provider<EventListModel<Void>> modelProvider) {
    EventModelProvider result = new EventModelProvider(eventBus, defaultConfirmPopupProvider);
    result.setModelProvider(modelProvider);
    return result;
}
Also used : EventModelProvider(org.ovirt.engine.ui.webadmin.uicommon.model.EventModelProvider) Named(com.google.inject.name.Named) Singleton(com.google.inject.Singleton) Provides(com.google.inject.Provides)

Example 33 with Singleton

use of com.google.inject.Singleton in project stdlib by petergeneric.

the class FreemarkerModule method createFreemarker.

@Provides
@Singleton
public FreemarkerTemplater createFreemarker(ServletContext context, FreemarkerURLHelper urlHelper, GuiceConfig configuration) {
    Configuration freemarker = new Configuration(FREEMARKER_COMPATIBILITY_VERSION);
    freemarker.setServletContextForTemplateLoading(context, "/WEB-INF/template/");
    freemarker.setObjectWrapper(new DefaultObjectWrapper(FREEMARKER_COMPATIBILITY_VERSION));
    FreemarkerTemplater templater = new FreemarkerTemplater(freemarker);
    templater.set("urls", urlHelper);
    templater.set("config", configuration);
    return templater;
}
Also used : Configuration(freemarker.template.Configuration) DefaultObjectWrapper(freemarker.template.DefaultObjectWrapper) Singleton(com.google.inject.Singleton) Provides(com.google.inject.Provides)

Example 34 with Singleton

use of com.google.inject.Singleton in project stdlib by petergeneric.

the class HibernateModule method getHibernateConfiguration.

@Provides
@Singleton
public Configuration getHibernateConfiguration(GuiceConfig guiceConfig, @Named(GuiceProperties.HIBERNATE_PROPERTIES) String propertyFileName, HibernateObservingInterceptor interceptor) {
    final Properties properties = extractHibernateProperties(guiceConfig, propertyFileName);
    validateHibernateProperties(guiceConfig, properties);
    // Set up the hibernate Configuration
    Configuration config = new Configuration();
    // Set up the interceptor
    config.setInterceptor(interceptor.getInterceptor());
    config.addProperties(properties);
    configure(config);
    registerTypes(config);
    {
        ServiceLoader<HibernateConfigurationValidator> services = ServiceLoader.load(HibernateConfigurationValidator.class);
        final Iterator<HibernateConfigurationValidator> it = services.iterator();
        if (log.isTraceEnabled())
            log.trace("Evaluate HibernateConfigurationValidators. has at least one=" + it.hasNext());
        while (it.hasNext()) {
            final HibernateConfigurationValidator validator = it.next();
            if (log.isTraceEnabled())
                log.trace("Validating hibernate configuration with " + validator);
            // Have the validator check the hibernate/database configuration
            validator.validate(config, properties, guiceConfig);
        }
    }
    return config;
}
Also used : ServiceLoader(java.util.ServiceLoader) HibernateConfigurationValidator(com.peterphi.std.guice.hibernate.module.ext.HibernateConfigurationValidator) Configuration(org.hibernate.cfg.Configuration) Iterator(java.util.Iterator) Properties(java.util.Properties) GuiceProperties(com.peterphi.std.guice.apploader.GuiceProperties) Singleton(com.google.inject.Singleton) Provides(com.google.inject.Provides)

Example 35 with Singleton

use of com.google.inject.Singleton in project stdlib by petergeneric.

the class ConfigGuiceModule method getRepository.

@Provides
@Singleton
@Named("config")
public ConfigRepository getRepository(@Named("repo.config.path") final File workingDirectory, @Named("repo.config.force-reclone-on-startup") final boolean reclone, @Named("repo.config.remote") final String remote) throws IOException, URISyntaxException, GitAPIException {
    log.info("Repo path " + workingDirectory + ", reclone: " + reclone);
    if (reclone && workingDirectory.exists()) {
        log.info("Recloning " + workingDirectory);
        File[] files = workingDirectory.listFiles();
        if (files != null)
            for (File file : files) {
                FileUtils.deleteQuietly(file);
                if (!file.exists()) {
                    throw new RuntimeException("Tried to delete local checkout contents but did not succeed. File was: " + file);
                }
            }
    }
    final File gitDir = new File(workingDirectory, ".git");
    final boolean newlyCreated;
    // Create the git repository if it doesn't already exist
    if (!gitDir.exists()) {
        log.info("Initialising new git dir at: " + workingDirectory);
        FileUtils.forceMkdir(workingDirectory);
        InitCommand init = new InitCommand();
        init.setBare(false).setDirectory(workingDirectory).setGitDir(gitDir).call();
        newlyCreated = true;
    } else {
        newlyCreated = false;
    }
    FileRepositoryBuilder frb = new FileRepositoryBuilder();
    Repository repo = frb.setGitDir(gitDir).readEnvironment().findGitDir().build();
    final boolean hasRemote = !remote.equalsIgnoreCase("none");
    final CredentialsProvider credentials;
    if (hasRemote) {
        // Try to extract username/password from the remote URL
        final URIish uri = new URIish(remote);
        if (uri.getUser() != null && uri.getPass() != null)
            credentials = new UsernamePasswordCredentialsProvider(uri.getUser(), uri.getPass());
        else
            credentials = null;
    } else {
        credentials = null;
    }
    if (newlyCreated) {
        // Add the remote and pull from it
        if (hasRemote) {
            RepoHelper.addRemote(repo, "origin", remote);
            RepoHelper.pull(repo, "origin", credentials);
        }
        Git git = new Git(repo);
        // If there are no commits in this repository, create one
        if (!git.log().setMaxCount(1).call().iterator().hasNext()) {
            git.commit().setAll(true).setAuthor("system", "system@localhost").setMessage("initial commit").call();
            if (hasRemote)
                RepoHelper.push(repo, "origin", credentials);
        }
    }
    return new ConfigRepository(repo, hasRemote, credentials);
}
Also used : URIish(org.eclipse.jgit.transport.URIish) ConfigRepository(com.peterphi.configuration.service.git.ConfigRepository) Repository(org.eclipse.jgit.lib.Repository) UsernamePasswordCredentialsProvider(org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider) Git(org.eclipse.jgit.api.Git) InitCommand(org.eclipse.jgit.api.InitCommand) ConfigRepository(com.peterphi.configuration.service.git.ConfigRepository) UsernamePasswordCredentialsProvider(org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider) CredentialsProvider(org.eclipse.jgit.transport.CredentialsProvider) File(java.io.File) FileRepositoryBuilder(org.eclipse.jgit.storage.file.FileRepositoryBuilder) Named(com.google.inject.name.Named) Singleton(com.google.inject.Singleton) Provides(com.google.inject.Provides)

Aggregations

Singleton (com.google.inject.Singleton)80 Provides (com.google.inject.Provides)77 AbstractModule (com.google.inject.AbstractModule)8 Injector (com.google.inject.Injector)8 Named (com.google.inject.name.Named)7 UICommand (org.ovirt.engine.ui.uicommonweb.UICommand)7 ConfirmationModel (org.ovirt.engine.ui.uicommonweb.models.ConfirmationModel)7 Model (org.ovirt.engine.ui.uicommonweb.models.Model)7 IOException (java.io.IOException)5 SearchableDetailTabModelProvider (org.ovirt.engine.ui.common.uicommon.model.SearchableDetailTabModelProvider)5 PermissionListModel (org.ovirt.engine.ui.uicommonweb.models.configure.PermissionListModel)5 DataSourceFactory (io.dropwizard.db.DataSourceFactory)4 ManagedDataSource (io.dropwizard.db.ManagedDataSource)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 File (java.io.File)3 InetSocketAddress (java.net.InetSocketAddress)3 SocketAddress (java.net.SocketAddress)3 Properties (java.util.Properties)3 Test (org.junit.Test)3 ConfigModule (co.cask.cdap.common.guice.ConfigModule)2