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());
}
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;
}
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()));
}
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));
}
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));
}
Aggregations