Search in sources :

Example 1 with TextProgressMonitor

use of org.eclipse.jgit.lib.TextProgressMonitor in project gerrit by GerritCodeReview.

the class Schema_123 method migrateData.

@Override
protected void migrateData(ReviewDb db, UpdateUI ui) throws OrmException, SQLException {
    ListMultimap<Account.Id, Change.Id> imports = MultimapBuilder.hashKeys().arrayListValues().build();
    try (Statement stmt = ((JdbcSchema) db).getConnection().createStatement();
        ResultSet rs = stmt.executeQuery("SELECT account_id, change_id FROM starred_changes")) {
        while (rs.next()) {
            Account.Id accountId = new Account.Id(rs.getInt(1));
            Change.Id changeId = new Change.Id(rs.getInt(2));
            imports.put(accountId, changeId);
        }
    }
    if (imports.isEmpty()) {
        return;
    }
    try (Repository git = repoManager.openRepository(allUsersName);
        RevWalk rw = new RevWalk(git)) {
        BatchRefUpdate bru = git.getRefDatabase().newBatchUpdate();
        ObjectId id = StarredChangesUtil.writeLabels(git, StarredChangesUtil.DEFAULT_LABELS);
        for (Map.Entry<Account.Id, Change.Id> e : imports.entries()) {
            bru.addCommand(new ReceiveCommand(ObjectId.zeroId(), id, RefNames.refsStarredChanges(e.getValue(), e.getKey())));
        }
        bru.execute(rw, new TextProgressMonitor());
    } catch (IOException ex) {
        throw new OrmException(ex);
    }
}
Also used : Account(com.google.gerrit.reviewdb.client.Account) ReceiveCommand(org.eclipse.jgit.transport.ReceiveCommand) ObjectId(org.eclipse.jgit.lib.ObjectId) Statement(java.sql.Statement) Change(com.google.gerrit.reviewdb.client.Change) IOException(java.io.IOException) RevWalk(org.eclipse.jgit.revwalk.RevWalk) TextProgressMonitor(org.eclipse.jgit.lib.TextProgressMonitor) Repository(org.eclipse.jgit.lib.Repository) OrmException(com.google.gwtorm.server.OrmException) ResultSet(java.sql.ResultSet) ObjectId(org.eclipse.jgit.lib.ObjectId) Map(java.util.Map) BatchRefUpdate(org.eclipse.jgit.lib.BatchRefUpdate)

Example 2 with TextProgressMonitor

use of org.eclipse.jgit.lib.TextProgressMonitor in project gerrit by GerritCodeReview.

the class AllAccountsIndexer method indexAll.

@Override
public SiteIndexer.Result indexAll(AccountIndex index) {
    ProgressMonitor progress = new TextProgressMonitor(newPrintWriter(progressOut));
    progress.start(2);
    Stopwatch sw = Stopwatch.createStarted();
    List<Account.Id> ids;
    try {
        ids = collectAccounts(progress);
    } catch (IOException e) {
        logger.atSevere().withCause(e).log("Error collecting accounts");
        return SiteIndexer.Result.create(sw, false, 0, 0);
    }
    return reindexAccounts(index, ids, progress);
}
Also used : TextProgressMonitor(org.eclipse.jgit.lib.TextProgressMonitor) ProgressMonitor(org.eclipse.jgit.lib.ProgressMonitor) Stopwatch(com.google.common.base.Stopwatch) IOException(java.io.IOException) TextProgressMonitor(org.eclipse.jgit.lib.TextProgressMonitor)

Example 3 with TextProgressMonitor

use of org.eclipse.jgit.lib.TextProgressMonitor in project gerrit by GerritCodeReview.

the class AllGroupsIndexer method indexAll.

@Override
public SiteIndexer.Result indexAll(GroupIndex index) {
    ProgressMonitor progress = new TextProgressMonitor(newPrintWriter(progressOut));
    progress.start(2);
    Stopwatch sw = Stopwatch.createStarted();
    List<AccountGroup.UUID> uuids;
    try {
        uuids = collectGroups(progress);
    } catch (IOException | ConfigInvalidException e) {
        logger.atSevere().withCause(e).log("Error collecting groups");
        return SiteIndexer.Result.create(sw, false, 0, 0);
    }
    return reindexGroups(index, uuids, progress);
}
Also used : ProgressMonitor(org.eclipse.jgit.lib.ProgressMonitor) TextProgressMonitor(org.eclipse.jgit.lib.TextProgressMonitor) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) Stopwatch(com.google.common.base.Stopwatch) IOException(java.io.IOException) TextProgressMonitor(org.eclipse.jgit.lib.TextProgressMonitor)

Example 4 with TextProgressMonitor

use of org.eclipse.jgit.lib.TextProgressMonitor in project gerrit by GerritCodeReview.

the class AllProjectsIndexer method indexAll.

@Override
public SiteIndexer.Result indexAll(final ProjectIndex index) {
    ProgressMonitor progress = new TextProgressMonitor(newPrintWriter(progressOut));
    progress.start(2);
    List<Project.NameKey> names = collectProjects(progress);
    return reindexProjects(index, names, progress);
}
Also used : TextProgressMonitor(org.eclipse.jgit.lib.TextProgressMonitor) ProgressMonitor(org.eclipse.jgit.lib.ProgressMonitor) TextProgressMonitor(org.eclipse.jgit.lib.TextProgressMonitor)

Example 5 with TextProgressMonitor

use of org.eclipse.jgit.lib.TextProgressMonitor in project gerrit by GerritCodeReview.

the class ProtobufImport method run.

@Override
public int run() throws Exception {
    mustHaveValidSite();
    Injector dbInjector = createDbInjector(SINGLE_USER);
    manager.add(dbInjector);
    manager.start();
    RuntimeShutdown.add(manager::stop);
    dbInjector.injectMembers(this);
    ProgressMonitor progress = new TextProgressMonitor();
    progress.beginTask("Importing entities", ProgressMonitor.UNKNOWN);
    try (ReviewDb db = schemaFactory.open()) {
        for (RelationModel model : new JavaSchemaModel(ReviewDb.class).getRelations()) {
            relations.put(model.getRelationID(), Relation.create(model, db));
        }
        Parser<UnknownFieldSet> parser = UnknownFieldSet.getDefaultInstance().getParserForType();
        try (InputStream in = new BufferedInputStream(Files.newInputStream(file.toPath()))) {
            UnknownFieldSet msg;
            while ((msg = parser.parseDelimitedFrom(in)) != null) {
                Map.Entry<Integer, UnknownFieldSet.Field> e = Iterables.getOnlyElement(msg.asMap().entrySet());
                Relation rel = checkNotNull(relations.get(e.getKey()), "unknown relation ID %s in message: %s", e.getKey(), msg);
                List<ByteString> values = e.getValue().getLengthDelimitedList();
                checkState(values.size() == 1, "expected one string field in message: %s", msg);
                upsert(rel, values.get(0));
                progress.update(1);
            }
        }
        progress.endTask();
    }
    return 0;
}
Also used : BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) ByteString(com.google.protobuf.ByteString) TextProgressMonitor(org.eclipse.jgit.lib.TextProgressMonitor) ProgressMonitor(org.eclipse.jgit.lib.ProgressMonitor) TextProgressMonitor(org.eclipse.jgit.lib.TextProgressMonitor) BufferedInputStream(java.io.BufferedInputStream) Injector(com.google.inject.Injector) RelationModel(com.google.gwtorm.schema.RelationModel) UnknownFieldSet(com.google.protobuf.UnknownFieldSet) HashMap(java.util.HashMap) Map(java.util.Map) ReviewDb(com.google.gerrit.reviewdb.server.ReviewDb) JavaSchemaModel(com.google.gwtorm.schema.java.JavaSchemaModel)

Aggregations

TextProgressMonitor (org.eclipse.jgit.lib.TextProgressMonitor)7 ProgressMonitor (org.eclipse.jgit.lib.ProgressMonitor)5 IOException (java.io.IOException)3 Stopwatch (com.google.common.base.Stopwatch)2 Change (com.google.gerrit.reviewdb.client.Change)2 Map (java.util.Map)2 Repository (org.eclipse.jgit.lib.Repository)2 RevWalk (org.eclipse.jgit.revwalk.RevWalk)2 GarbageCollectionResult (com.google.gerrit.common.data.GarbageCollectionResult)1 GcError (com.google.gerrit.common.data.GarbageCollectionResult.GcError)1 Project (com.google.gerrit.entities.Project)1 Account (com.google.gerrit.reviewdb.client.Account)1 ReviewDb (com.google.gerrit.reviewdb.server.ReviewDb)1 NoteDbUpdateManager (com.google.gerrit.server.notedb.NoteDbUpdateManager)1 NoPatchSetsException (com.google.gerrit.server.notedb.rebuild.ChangeRebuilder.NoPatchSetsException)1 ChainedReceiveCommands (com.google.gerrit.server.update.ChainedReceiveCommands)1 RelationModel (com.google.gwtorm.schema.RelationModel)1 JavaSchemaModel (com.google.gwtorm.schema.java.JavaSchemaModel)1 OrmException (com.google.gwtorm.server.OrmException)1 Injector (com.google.inject.Injector)1