Search in sources :

Example 21 with ChangeSummary

use of org.commonjava.indy.audit.ChangeSummary in project indy by Commonjava.

the class AutoProxDataManagerDecorator method getRemoteRepository.

private RemoteRepository getRemoteRepository(final StoreKey key, final StoreKey impliedBy) throws IndyDataException {
    logger.debug("DECORATED (getRemoteRepository: {})", key);
    RemoteRepository repo = (RemoteRepository) dataManager.getArtifactStore(key);
    if (!catalog.isEnabled()) {
        logger.debug("AutoProx decorator disabled; returning: {}", repo);
        return repo;
    }
    logger.debug("AutoProx decorator active");
    if (repo == null) {
        logger.info("AutoProx: creating repository for: {}", key);
        try {
            repo = catalog.createRemoteRepository(key);
            if (repo != null) {
                if (!checkValidity(key)) {
                    return null;
                }
                final EventMetadata eventMetadata = new EventMetadata().set(StoreDataManager.EVENT_ORIGIN, AutoProxConstants.STORE_ORIGIN).set(AutoProxConstants.ORIGINATING_STORE, impliedBy == null ? repo.getKey() : impliedBy);
                dataManager.storeArtifactStore(repo, new ChangeSummary(ChangeSummary.SYSTEM_USER, "AUTOPROX: Creating remote repository for: '" + key + "'"), false, true, eventMetadata);
            }
        } catch (final AutoProxRuleException e) {
            throw new IndyDataException("[AUTOPROX] Failed to create new remote repository from factory matching: '%s'. Reason: %s", e, key, e.getMessage());
        }
    }
    return repo;
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) EventMetadata(org.commonjava.maven.galley.event.EventMetadata)

Example 22 with ChangeSummary

use of org.commonjava.indy.audit.ChangeSummary in project indy by Commonjava.

the class AutoProxDataManagerDecorator method getGroup.

private Group getGroup(final StoreKey key, final StoreKey impliedBy) throws IndyDataException {
    logger.debug("DECORATED (getGroup: {})", key);
    Group g = (Group) dataManager.getArtifactStore(key);
    if (!catalog.isEnabled()) {
        logger.debug("AutoProx decorator disabled; returning: {}", g);
        return g;
    }
    logger.debug("AutoProx decorator active");
    if (g == null) {
        logger.debug("AutoProx: creating repository for: {}", key);
        if (!checkValidity(key)) {
            return null;
        }
        try {
            g = catalog.createGroup(key);
        } catch (final AutoProxRuleException e) {
            throw new IndyDataException("[AUTOPROX] Failed to create new group from factory matching: '%s'. Reason: %s", e, key, e.getMessage());
        }
        if (g != null) {
            logger.info("Validating group: {}", g);
            for (final StoreKey memberKey : new ArrayList<>(g.getConstituents())) {
                final ArtifactStore store = getArtifactStore(memberKey, impliedBy == null ? g.getKey() : impliedBy);
                if (store == null) {
                    g.removeConstituent(memberKey);
                }
            }
            if (g.getConstituents().isEmpty()) {
                return null;
            }
            final EventMetadata eventMetadata = new EventMetadata().set(StoreDataManager.EVENT_ORIGIN, AutoProxConstants.STORE_ORIGIN).set(AutoProxConstants.ORIGINATING_STORE, impliedBy == null ? g.getKey() : impliedBy);
            dataManager.storeArtifactStore(g, new ChangeSummary(ChangeSummary.SYSTEM_USER, "AUTOPROX: Creating group for: '" + key + "'"), false, true, eventMetadata);
        }
    }
    return g;
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) Group(org.commonjava.indy.model.core.Group) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) ArrayList(java.util.ArrayList) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) StoreKey(org.commonjava.indy.model.core.StoreKey) EventMetadata(org.commonjava.maven.galley.event.EventMetadata)

Example 23 with ChangeSummary

use of org.commonjava.indy.audit.ChangeSummary in project indy by Commonjava.

the class AutoProxAproxMigrationAction method migrate.

@Override
public boolean migrate() throws IndyLifecycleException {
    final DataFile dataDir = ffManager.getDataFile(config.getBasedir());
    Logger logger = LoggerFactory.getLogger(getClass());
    logger.debug("Scanning {} for autoprox rules...", dataDir);
    int changed = 0;
    if (dataDir.exists()) {
        final DataFile[] scripts = dataDir.listFiles((pathname) -> {
            logger.trace("Checking for autoprox rule in: {}", pathname);
            return pathname.getName().endsWith(".groovy");
        });
        logger.info("Migrating autoprox rules.");
        for (final DataFile script : scripts) {
            try {
                String scriptContent = script.readString();
                String migrated = scriptContent.replaceAll("A[Pp]rox", "Indy").replaceAll("aprox", "indy");
                if (!migrated.equals(scriptContent)) {
                    logger.info("Migrating autoprox rule in: {}", script.getPath());
                    script.writeString(migrated, new ChangeSummary(ChangeSummary.SYSTEM_USER, "Migrating to Indy packages / naming"));
                    changed++;
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    return changed != 0;
}
Also used : DataFile(org.commonjava.indy.subsys.datafile.DataFile) IOException(java.io.IOException) Logger(org.slf4j.Logger) ChangeSummary(org.commonjava.indy.audit.ChangeSummary)

Example 24 with ChangeSummary

use of org.commonjava.indy.audit.ChangeSummary in project indy by Commonjava.

the class GitManager method toChangeSummary.

//    private void printFiles( final RevCommit commit )
//        throws IOException
//    {
//        final RevWalk tree = new RevWalk( repo );
//        final RevCommit parent = commit.getParentCount() > 0 ? tree.parseCommit( commit.getParent( 0 )
//                                                                                       .getId() ) : null;
//
//        final DiffFormatter df = new DiffFormatter( DisabledOutputStream.INSTANCE );
//        df.setRepository( repo );
//        df.setDiffComparator( RawTextComparator.DEFAULT );
//        df.setDetectRenames( true );
//
//        final List<DiffEntry> diffs;
//        if ( parent == null )
//        {
//            diffs =
//                df.scan( new EmptyTreeIterator(),
//                         new CanonicalTreeParser( null, tree.getObjectReader(), commit.getTree() ) );
//        }
//        else
//        {
//            diffs = df.scan( parent.getTree(), commit.getTree() );
//        }
//
//        for ( final DiffEntry diff : diffs )
//        {
//            logger.info( "({} {} {}", diff.getChangeType()
//                                          .name(), diff.getNewMode()
//                                                       .getBits(), diff.getNewPath() );
//        }
//    }
private ChangeSummary toChangeSummary(final RevCommit commit) {
    final PersonIdent who = commit.getAuthorIdent();
    final Date when = new Date(TimeUnit.MILLISECONDS.convert(commit.getCommitTime(), TimeUnit.SECONDS));
    return new ChangeSummary(who.getName(), commit.getFullMessage(), when, commit.getId().name());
}
Also used : PersonIdent(org.eclipse.jgit.lib.PersonIdent) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) Date(java.util.Date)

Example 25 with ChangeSummary

use of org.commonjava.indy.audit.ChangeSummary in project indy by Commonjava.

the class GitManagerConcurrentTest method concurrentAddToRepo.

@BMRules(rules = { @BMRule(name = "init rendezvous", targetClass = "GitManager", targetMethod = "<init>", targetLocation = "ENTRY", action = "createRendezvous($0, 2, true)"), @BMRule(name = "addAndCommitPaths call", targetClass = "GitManager", targetMethod = "addAndCommitPaths(ChangeSummary,Collection)", targetLocation = "ENTRY", action = "rendezvous($0); debug(Thread.currentThread().getName() + \": thread proceeding.\")") })
@Test
public void concurrentAddToRepo() throws Exception {
    final int threshold = 2;
    final Executor pool = Executors.newFixedThreadPool(threshold);
    CountDownLatch latch = new CountDownLatch(threshold);
    for (int i = 0; i < threshold; i++) {
        final int j = i;
        pool.execute(() -> {
            try {
                final File f = new File(cloneDir, String.format("test%s.txt", j));
                FileUtils.write(f, String.format("This is a test %s", j));
                final String user = "test" + j;
                final String log = "test commit " + j;
                git.addAndCommitFiles(new ChangeSummary(user, log), f);
            } catch (Exception e) {
                e.printStackTrace();
                failed = true;
            } finally {
                latch.countDown();
            }
        });
    }
    latch.await();
    if (failed) {
        fail();
    }
}
Also used : Executor(java.util.concurrent.Executor) CountDownLatch(java.util.concurrent.CountDownLatch) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) File(java.io.File) Test(org.junit.Test) BMRules(org.jboss.byteman.contrib.bmunit.BMRules)

Aggregations

ChangeSummary (org.commonjava.indy.audit.ChangeSummary)68 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)37 Test (org.junit.Test)29 IndyDataException (org.commonjava.indy.data.IndyDataException)24 DataFile (org.commonjava.indy.subsys.datafile.DataFile)21 RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)17 StoreKey (org.commonjava.indy.model.core.StoreKey)14 IOException (java.io.IOException)11 HostedRepository (org.commonjava.indy.model.core.HostedRepository)11 Group (org.commonjava.indy.model.core.Group)10 File (java.io.File)8 ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)8 PathsPromoteRequest (org.commonjava.indy.promote.model.PathsPromoteRequest)8 Transfer (org.commonjava.maven.galley.model.Transfer)8 Logger (org.slf4j.Logger)8 ByteArrayInputStream (java.io.ByteArrayInputStream)7 PathsPromoteResult (org.commonjava.indy.promote.model.PathsPromoteResult)7 ArrayList (java.util.ArrayList)6 IndyLifecycleException (org.commonjava.indy.action.IndyLifecycleException)5 BMRules (org.jboss.byteman.contrib.bmunit.BMRules)5