Search in sources :

Example 1 with LifecycleManager

use of com.google.gerrit.lifecycle.LifecycleManager in project gerrit by GerritCodeReview.

the class AbstractQueryAccountsTest method setUpInjector.

@Before
public void setUpInjector() throws Exception {
    lifecycle = new LifecycleManager();
    injector = createInjector();
    lifecycle.add(injector);
    injector.injectMembers(this);
    lifecycle.start();
    setUpDatabase();
}
Also used : LifecycleManager(com.google.gerrit.lifecycle.LifecycleManager) Before(org.junit.Before)

Example 2 with LifecycleManager

use of com.google.gerrit.lifecycle.LifecycleManager in project gerrit by GerritCodeReview.

the class RebuildNoteDb method run.

@Override
public int run() throws Exception {
    mustHaveValidSite();
    dbInjector = createDbInjector(MULTI_USER);
    threads = ThreadLimiter.limitThreads(dbInjector, threads);
    LifecycleManager dbManager = new LifecycleManager();
    dbManager.add(dbInjector);
    dbManager.start();
    sysInjector = createSysInjector();
    sysInjector.injectMembers(this);
    if (!notesMigration.enabled()) {
        throw die("NoteDb is not enabled.");
    }
    LifecycleManager sysManager = new LifecycleManager();
    sysManager.add(sysInjector);
    sysManager.start();
    ListeningExecutorService executor = newExecutor();
    System.out.println("Rebuilding the NoteDb");
    ImmutableListMultimap<Project.NameKey, Change.Id> changesByProject = getChangesByProject();
    boolean ok;
    Stopwatch sw = Stopwatch.createStarted();
    try (Repository allUsersRepo = repoManager.openRepository(allUsersName)) {
        deleteRefs(RefNames.REFS_DRAFT_COMMENTS, allUsersRepo);
        List<ListenableFuture<Boolean>> futures = new ArrayList<>();
        List<Project.NameKey> projectNames = Ordering.usingToString().sortedCopy(changesByProject.keySet());
        for (Project.NameKey project : projectNames) {
            ListenableFuture<Boolean> future = executor.submit(() -> {
                try (ReviewDb db = unwrapDb(schemaFactory.open())) {
                    return rebuildProject(db, changesByProject, project, allUsersRepo);
                } catch (Exception e) {
                    log.error("Error rebuilding project " + project, e);
                    return false;
                }
            });
            futures.add(future);
        }
        try {
            ok = Iterables.all(Futures.allAsList(futures).get(), Predicates.equalTo(true));
        } catch (InterruptedException | ExecutionException e) {
            log.error("Error rebuilding projects", e);
            ok = false;
        }
    }
    double t = sw.elapsed(TimeUnit.MILLISECONDS) / 1000d;
    System.out.format("Rebuild %d changes in %.01fs (%.01f/s)\n", changesByProject.size(), t, changesByProject.size() / t);
    return ok ? 0 : 1;
}
Also used : LifecycleManager(com.google.gerrit.lifecycle.LifecycleManager) Stopwatch(com.google.common.base.Stopwatch) ArrayList(java.util.ArrayList) OrmException(com.google.gwtorm.server.OrmException) NoPatchSetsException(com.google.gerrit.server.notedb.rebuild.ChangeRebuilder.NoPatchSetsException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) Project(com.google.gerrit.reviewdb.client.Project) Repository(org.eclipse.jgit.lib.Repository) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) ObjectId(org.eclipse.jgit.lib.ObjectId) ExecutionException(java.util.concurrent.ExecutionException) ReviewDb(com.google.gerrit.reviewdb.server.ReviewDb)

Example 3 with LifecycleManager

use of com.google.gerrit.lifecycle.LifecycleManager in project gerrit by GerritCodeReview.

the class JsPlugin method start.

@Override
public void start(PluginGuiceEnvironment env) throws Exception {
    manager = new LifecycleManager();
    String fileName = getSrcFile().getFileName().toString();
    sysInjector = Guice.createInjector(new StandaloneJsPluginModule(getName(), fileName));
    manager.start();
}
Also used : LifecycleManager(com.google.gerrit.lifecycle.LifecycleManager)

Example 4 with LifecycleManager

use of com.google.gerrit.lifecycle.LifecycleManager in project gerrit by GerritCodeReview.

the class ServerPlugin method startPlugin.

private void startPlugin(PluginGuiceEnvironment env) throws Exception {
    Injector root = newRootInjector(env);
    serverManager = new LifecycleManager();
    serverManager.add(root);
    AutoRegisterModules auto = null;
    if (sysModule == null && sshModule == null && httpModule == null) {
        auto = new AutoRegisterModules(getName(), env, scanner, classLoader);
        auto.discover();
    }
    if (sysModule != null) {
        sysInjector = root.createChildInjector(root.getInstance(sysModule));
        serverManager.add(sysInjector);
    } else if (auto != null && auto.sysModule != null) {
        sysInjector = root.createChildInjector(auto.sysModule);
        serverManager.add(sysInjector);
    } else {
        sysInjector = root;
    }
    if (env.hasSshModule()) {
        List<Module> modules = new ArrayList<>();
        if (getApiType() == ApiType.PLUGIN) {
            modules.add(env.getSshModule());
        }
        if (sshModule != null) {
            modules.add(sysInjector.getInstance(sshModule));
            sshInjector = sysInjector.createChildInjector(modules);
            serverManager.add(sshInjector);
        } else if (auto != null && auto.sshModule != null) {
            modules.add(auto.sshModule);
            sshInjector = sysInjector.createChildInjector(modules);
            serverManager.add(sshInjector);
        }
    }
    if (env.hasHttpModule()) {
        List<Module> modules = new ArrayList<>();
        if (getApiType() == ApiType.PLUGIN) {
            modules.add(env.getHttpModule());
        }
        if (httpModule != null) {
            modules.add(sysInjector.getInstance(httpModule));
            httpInjector = sysInjector.createChildInjector(modules);
            serverManager.add(httpInjector);
        } else if (auto != null && auto.httpModule != null) {
            modules.add(auto.httpModule);
            httpInjector = sysInjector.createChildInjector(modules);
            serverManager.add(httpInjector);
        }
    }
    serverManager.start();
}
Also used : Injector(com.google.inject.Injector) LifecycleManager(com.google.gerrit.lifecycle.LifecycleManager) ArrayList(java.util.ArrayList) Module(com.google.inject.Module)

Example 5 with LifecycleManager

use of com.google.gerrit.lifecycle.LifecycleManager in project gerrit by GerritCodeReview.

the class Schema_150_to_151_Test method setUp.

@Before
public void setUp() throws Exception {
    Injector injector = Guice.createInjector(new InMemoryModule());
    injector.injectMembers(this);
    lifecycle = new LifecycleManager();
    lifecycle.add(injector);
    lifecycle.start();
    try (ReviewDb underlyingDb = inMemoryDatabase.getDatabase().open()) {
        schemaCreator.create(underlyingDb);
    }
    db = schemaFactory.open();
    Account.Id userId = accountManager.authenticate(AuthRequest.forUser("user")).getAccountId();
    IdentifiedUser user = userFactory.create(userId);
    requestContext.setContext(new RequestContext() {

        @Override
        public CurrentUser getUser() {
            return user;
        }

        @Override
        public Provider<ReviewDb> getReviewDbProvider() {
            return Providers.of(db);
        }
    });
}
Also used : Account(com.google.gerrit.reviewdb.client.Account) CurrentUser(com.google.gerrit.server.CurrentUser) Injector(com.google.inject.Injector) LifecycleManager(com.google.gerrit.lifecycle.LifecycleManager) RequestContext(com.google.gerrit.server.util.RequestContext) ThreadLocalRequestContext(com.google.gerrit.server.util.ThreadLocalRequestContext) InMemoryModule(com.google.gerrit.testutil.InMemoryModule) IdentifiedUser(com.google.gerrit.server.IdentifiedUser) ReviewDb(com.google.gerrit.reviewdb.server.ReviewDb) Provider(com.google.inject.Provider) Before(org.junit.Before)

Aggregations

LifecycleManager (com.google.gerrit.lifecycle.LifecycleManager)15 Before (org.junit.Before)10 Injector (com.google.inject.Injector)7 CurrentUser (com.google.gerrit.server.CurrentUser)5 RequestContext (com.google.gerrit.server.util.RequestContext)5 ThreadLocalRequestContext (com.google.gerrit.server.util.ThreadLocalRequestContext)5 InMemoryModule (com.google.gerrit.testutil.InMemoryModule)5 Provider (com.google.inject.Provider)5 Account (com.google.gerrit.reviewdb.client.Account)4 Project (com.google.gerrit.reviewdb.client.Project)3 ReviewDb (com.google.gerrit.reviewdb.server.ReviewDb)3 InMemoryRepository (org.eclipse.jgit.internal.storage.dfs.InMemoryRepository)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Stopwatch (com.google.common.base.Stopwatch)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 ListeningExecutorService (com.google.common.util.concurrent.ListeningExecutorService)1 DropWizardMetricMaker (com.google.gerrit.metrics.dropwizard.DropWizardMetricMaker)1 AccountGroup (com.google.gerrit.reviewdb.client.AccountGroup)1 IdentifiedUser (com.google.gerrit.server.IdentifiedUser)1