Search in sources :

Example 61 with ChangeSummary

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

the class DataFileStoreDataManager method install.

@Override
public void install() throws IndyDataException {
    if (!manager.getDataFile(INDY_STORE).isDirectory()) {
        final ChangeSummary summary = new ChangeSummary(ChangeSummary.SYSTEM_USER, "Initializing defaults");
        storeArtifactStore(new RemoteRepository(MAVEN_PKG_KEY, "central", "http://repo.maven.apache.org/maven2/"), summary, true, false, new EventMetadata());
        storeArtifactStore(new Group(MAVEN_PKG_KEY, "public", new StoreKey(StoreType.remote, "central")), summary, true, false, new EventMetadata());
    }
}
Also used : Group(org.commonjava.indy.model.core.Group) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) StoreKey(org.commonjava.indy.model.core.StoreKey) EventMetadata(org.commonjava.maven.galley.event.EventMetadata)

Example 62 with ChangeSummary

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

the class GitManagerConcurrentTest method addToRepoWhileGettingHeadCommit.

@BMRules(rules = { @BMRule(name = "init rendezvous", targetClass = "GitManager", targetMethod = "<init>", targetLocation = "ENTRY", action = "createRendezvous($0, 2, true)"), @BMRule(name = "getHeadCommit call", targetClass = "GitManager", targetMethod = "getHeadCommit(File)", targetLocation = "ENTRY", action = "debug(\"getHeadCommit() waiting...\"); rendezvous($0); debug(\"getHeadCommit(): thread proceeding.\")"), @BMRule(name = "addAndCommitPaths call", targetClass = "GitManager", targetMethod = "addAndCommitPaths(ChangeSummary,Collection)", targetLocation = "ENTRY", action = "debug(\"addAndCommitPaths() waiting...\"); rendezvous($0); debug(\"addAndCommitPaths(): thread proceeding.\")") })
@Test
public void addToRepoWhileGettingHeadCommit() throws Exception {
    final int threshold = 2;
    final Executor pool = Executors.newFixedThreadPool(threshold);
    CountDownLatch latch = new CountDownLatch(threshold);
    final File f = new File(cloneDir, String.format("test.txt"));
    FileUtils.write(f, "This is a test");
    final String user = "testAddAndCommit";
    git.addAndCommitFiles(new ChangeSummary(user, "first commit"), f);
    pool.execute(() -> {
        try {
            git.getHeadCommit(f);
        } catch (Exception e) {
            e.printStackTrace();
            failed = true;
        } finally {
            latch.countDown();
        }
    });
    pool.execute(() -> {
        try {
            FileUtils.write(f, "This is another test");
            git.addAndCommitFiles(new ChangeSummary(user, "second commit"), 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)

Example 63 with ChangeSummary

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

the class GitManagerConcurrentTest method concurrentDeleteFromRepo.

@BMRules(rules = { @BMRule(name = "init rendezvous", targetClass = "GitManager", targetMethod = "<init>", targetLocation = "ENTRY", action = "createRendezvous($0, 2, true)"), @BMRule(name = "deleteAndCommitPaths call", targetClass = "GitManager", targetMethod = "deleteAndCommitPaths(ChangeSummary,Collection)", targetLocation = "ENTRY", action = "rendezvous($0); debug(Thread.currentThread().getName() + \": thread proceeding.\")") })
@Test
public void concurrentDeleteFromRepo() throws Exception {
    final int threshold = 2;
    for (int i = 0; i < threshold; i++) {
        try {
            final File f = new File(cloneDir, String.format("test%s.txt", i));
            FileUtils.write(f, String.format("This is a test %s", i));
            final String user = "test" + i;
            final String log = "test commit " + i;
            git.addAndCommitFiles(new ChangeSummary(user, log), f);
        } catch (Exception e) {
            e.printStackTrace();
            failed = true;
        }
    }
    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));
                final String user = "test" + j;
                final String log = "delete test" + j + ".txt";
                git.deleteAndCommit(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) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) CountDownLatch(java.util.concurrent.CountDownLatch) File(java.io.File) Test(org.junit.Test) BMRules(org.jboss.byteman.contrib.bmunit.BMRules)

Example 64 with ChangeSummary

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

the class GitManagerTest method addToClonedRepoAndRetrieveCommitLog.

@Test
public void addToClonedRepoAndRetrieveCommitLog() throws Exception {
    final File root = unpackRepo("test-indy-data.zip");
    final File cloneDir = temp.newFolder();
    FileUtils.forceDelete(cloneDir);
    final String email = "me@nowhere.com";
    // NOTE: Leave off generation of file-list changed in commit message (third parameter, below)
    final GitConfig config = new GitConfig(cloneDir, root.toURI().toURL().toExternalForm(), false).setUserEmail(email);
    final GitManager git = new GitManager(config);
    final File f = new File(cloneDir, "test.txt");
    FileUtils.write(f, "This is a test");
    final String user = "test";
    final String log = "test commit";
    git.addAndCommitFiles(new ChangeSummary(user, log), f);
    final List<ChangeSummary> changelog = git.getChangelog(f, 0, 1);
    assertThat(changelog, notNullValue());
    assertThat(changelog.size(), equalTo(1));
    assertThat(changelog.get(0).getUser(), equalTo(user));
    assertThat(changelog.get(0).getSummary(), equalTo(log));
}
Also used : ChangeSummary(org.commonjava.indy.audit.ChangeSummary) File(java.io.File) Test(org.junit.Test)

Example 65 with ChangeSummary

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

the class IndySiteConfigLookupTest method checkServerCertPemIsConfigured.

@Test
public void checkServerCertPemIsConfigured() throws IndyDataException {
    RemoteRepository remote = new RemoteRepository(MAVEN_PKG_KEY, "test", "http://test.com/repo");
    remote.setServerCertPem("AAAAFFFFFSDADFADSFASDFASDFASDFASDFASDFsa");
    remote.setServerTrustPolicy("self-signed");
    MemoryStoreDataManager storeData = new MemoryStoreDataManager(true);
    storeData.storeArtifactStore(remote, new ChangeSummary(ChangeSummary.SYSTEM_USER, "This is a test"), false, false, new EventMetadata());
    IndySiteConfigLookup lookup = new IndySiteConfigLookup(storeData);
    SiteConfig siteConfig = lookup.lookup("remote:test");
    assertThat(siteConfig.getServerCertPem(), equalTo(remote.getServerCertPem()));
}
Also used : MemoryStoreDataManager(org.commonjava.indy.mem.data.MemoryStoreDataManager) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) SiteConfig(org.commonjava.util.jhttpc.model.SiteConfig) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) Test(org.junit.Test)

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