Search in sources :

Example 56 with ChangeSummary

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

the class DefaultDownloadManagerTest method getTransferFromStoreList_DownloadOp_SkipIfDoesntExist.

@Test
public void getTransferFromStoreList_DownloadOp_SkipIfDoesntExist() throws IndyDataException, IndyWorkflowException {
    ChangeSummary summary = new ChangeSummary(ChangeSummary.SYSTEM_USER, "Test setup");
    HostedRepository hosted1 = new HostedRepository(MAVEN_PKG_KEY, "one");
    HostedRepository hosted2 = new HostedRepository(MAVEN_PKG_KEY, "two");
    storeManager.storeArtifactStore(hosted1, summary, false, true, new EventMetadata());
    storeManager.storeArtifactStore(hosted2, summary, false, true, new EventMetadata());
    String path = "/some/path.txt";
    Transfer transfer = downloadManager.getStorageReference(Arrays.asList(hosted1, hosted2), path, TransferOperation.DOWNLOAD);
    assertThat(transfer, nullValue());
}
Also used : Transfer(org.commonjava.maven.galley.model.Transfer) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) HostedRepository(org.commonjava.indy.model.core.HostedRepository) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) Test(org.junit.Test)

Example 57 with ChangeSummary

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

the class LegacyDataMigrationAction method migrate.

@Override
public boolean migrate() throws IndyLifecycleException {
    if (!(storeDataManager instanceof DataFileStoreDataManager)) {
        logger.info("Store manager: {} is not based on DataFile's. Skipping migration.", storeDataManager.getClass().getName());
        return false;
    }
    final DataFile basedir = dataFileManager.getDataFile(INDY_STORE);
    final ChangeSummary summary = new ChangeSummary(ChangeSummary.SYSTEM_USER, "Migrating legacy store definitions.");
    if (!basedir.exists()) {
        return false;
    }
    StoreType[] storeTypes = StoreType.values();
    final String[] dirs = basedir.list();
    if (dirs == null || dirs.length < 1) {
        return false;
    }
    Map<String, String> migrationCandidates = new HashMap<>();
    //noinspection ConstantConditions
    Stream.of(storeTypes).forEach(type -> {
        File[] files = basedir.getDetachedFile().toPath().resolve(type.singularEndpointName()).toFile().listFiles((dir, fname) -> fname.endsWith(".json"));
        if (files != null) {
            Stream.of(files).forEach((f) -> {
                String src = Paths.get(type.singularEndpointName(), f.getName()).toString();
                String target = Paths.get(MAVEN_PKG_KEY, type.singularEndpointName(), f.getName()).toString();
                migrationCandidates.put(src, target);
            });
        }
    });
    boolean changed = false;
    for (Map.Entry<String, String> entry : migrationCandidates.entrySet()) {
        DataFile src = dataFileManager.getDataFile(INDY_STORE, entry.getKey());
        DataFile target = dataFileManager.getDataFile(INDY_STORE, entry.getValue());
        if (target.exists()) {
            continue;
        }
        DataFile targetDir = target.getParent();
        if (!targetDir.exists() && !targetDir.mkdirs()) {
            throw new IndyLifecycleException("Cannot make directory: %s.", targetDir.getPath());
        } else if (!targetDir.isDirectory()) {
            throw new IndyLifecycleException("Not a directory: %s.", targetDir.getPath());
        }
        try {
            logger.info("Migrating definition {}", src.getPath());
            final String json = src.readString();
            final String migrated = objectMapper.patchLegacyStoreJson(json);
            target.writeString(migrated, summary);
            changed = true;
        } catch (final IOException e) {
            throw new IndyLifecycleException("Failed to migrate artifact-store definition from: %s to: %s. Reason: %s", e, src, target, e.getMessage(), e);
        }
    }
    if (changed) {
        try {
            storeDataManager.reload();
        } catch (IndyDataException e) {
            throw new IndyLifecycleException("Failed to reload migrated store definitions: %s", e, e.getMessage());
        }
    }
    return changed;
}
Also used : HashMap(java.util.HashMap) IOException(java.io.IOException) DataFile(org.commonjava.indy.subsys.datafile.DataFile) StoreType(org.commonjava.indy.model.core.StoreType) IndyDataException(org.commonjava.indy.data.IndyDataException) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) IndyLifecycleException(org.commonjava.indy.action.IndyLifecycleException) DataFile(org.commonjava.indy.subsys.datafile.DataFile) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map)

Example 58 with ChangeSummary

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

the class DataFileStoreDataManagerTest method getDataFileReturnsRemoteRepoJsonFile.

@Test
public void getDataFileReturnsRemoteRepoJsonFile() throws Exception {
    final String name = "foo";
    final boolean success = mgr.storeArtifactStore(new RemoteRepository(MAVEN_PKG_KEY, name, "http://www.foo.com/"), new ChangeSummary("test-user", "init"), false, true, new EventMetadata());
    assertThat(success, equalTo(true));
    final DataFile dataFile = mgr.getDataFile(new StoreKey(StoreType.remote, name));
    assertThat(dataFile.getDetachedFile().getAbsolutePath(), equalTo(new File(fileCfg.getDataBasedir(), "indy/remote/" + name + ".json").getAbsolutePath()));
}
Also used : DataFile(org.commonjava.indy.subsys.datafile.DataFile) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) StoreKey(org.commonjava.indy.model.core.StoreKey) File(java.io.File) DataFile(org.commonjava.indy.subsys.datafile.DataFile) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) Test(org.junit.Test)

Example 59 with ChangeSummary

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

the class LegacyDataMigrationActionTest method migrateGroupJSONWithMissingTypeAttribute.

@Test
public void migrateGroupJSONWithMissingTypeAttribute() throws Exception {
    final DataFile dir = dfm.getDataFile(INDY_STORE, group.singularEndpointName());
    dir.mkdirs();
    DataFile in = dfm.getDataFile(INDY_STORE, group.singularEndpointName(), "test.json");
    in.writeString("{\"name\": \"test\", \"packageType\": \"maven\", \"key\": \"maven:group:test\"}", new ChangeSummary(ChangeSummary.SYSTEM_USER, "test group creation"));
    System.out.println("Wrote: " + in.getPath());
    final boolean result = action.migrate();
    assertThat(result, equalTo(true));
    DataFile out = dfm.getDataFile(INDY_STORE, MAVEN_PKG_KEY, group.singularEndpointName(), "test.json");
    final String json = out.readString();
    assertThat(json.contains("\"type\" : \"group\""), equalTo(true));
    assertThat(json.contains("\"packageType\" : \"maven\""), equalTo(true));
    assertThat(json.contains("\"key\" : \"maven:group:test\""), equalTo(true));
}
Also used : DataFile(org.commonjava.indy.subsys.datafile.DataFile) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) Test(org.junit.Test)

Example 60 with ChangeSummary

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

the class LegacyDataMigrationActionTest method dataFileMigrationForGroupJSONWithExistingTypeAttribute.

@Test
public void dataFileMigrationForGroupJSONWithExistingTypeAttribute() throws Exception {
    final DataFile dir = dfm.getDataFile(INDY_STORE, group.singularEndpointName());
    dir.mkdirs();
    final DataFile file = dir.getChild("test.json");
    file.writeString("{\"name\": \"test\", \"packageType\": \"maven\", \"type\" : \"group\", \"key\": \"maven:group:test\"}", new ChangeSummary(ChangeSummary.SYSTEM_USER, "test group creation"));
    String json = file.readString();
    assertThat(json.contains("\"type\" : \"group\""), equalTo(true));
    final boolean result = action.migrate();
    assertThat(result, equalTo(true));
    DataFile out = dfm.getDataFile(INDY_STORE, MAVEN_PKG_KEY, group.singularEndpointName(), "test.json");
    json = out.readString();
    assertThat(json.contains("\"type\" : \"group\""), equalTo(true));
    assertThat(json.contains("\"packageType\" : \"maven\""), equalTo(true));
    assertThat(json.contains("\"key\" : \"maven:group:test\""), equalTo(true));
}
Also used : DataFile(org.commonjava.indy.subsys.datafile.DataFile) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) 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