use of org.commonjava.indy.audit.ChangeSummary in project indy by Commonjava.
the class FoloLifecycleParticipant method start.
@Override
public void start() throws IndyLifecycleException {
try {
final DataFile dataFile = dataFileManager.getDataFile(".gitignore");
final List<String> lines = dataFile.exists() ? dataFile.readLines() : new ArrayList<String>();
if (!lines.contains(FOLO_DIRECTORY_IGNORE)) {
lines.add(FOLO_DIRECTORY_IGNORE);
dataFile.writeLines(lines, new ChangeSummary(ChangeSummary.SYSTEM_USER, "Adding artimon to ignored list."));
}
} catch (final IOException e) {
throw new IndyLifecycleException("Failed while attempting to access .gitignore for data directory (trying to add artimon dir to ignores list).", e);
}
}
use of org.commonjava.indy.audit.ChangeSummary in project indy by Commonjava.
the class DataFileStoreDataManager method readDefinitions.
@PostConstruct
public void readDefinitions() {
final ChangeSummary summary = new ChangeSummary(ChangeSummary.SYSTEM_USER, "Reading definitions from disk, culling invalid definition files.");
try {
DataFile[] packageDirs = manager.getDataFile(INDY_STORE).listFiles((f) -> true);
for (DataFile pkgDir : packageDirs) {
for (StoreType type : StoreType.values()) {
DataFile[] files = pkgDir.getChild(type.singularEndpointName()).listFiles(f -> true);
if (files != null) {
for (final DataFile f : files) {
try {
final String json = f.readString();
final ArtifactStore store = serializer.readValue(json, type.getStoreClass());
if (store == null) {
f.delete(summary);
} else {
storeArtifactStore(store, summary, false, false, new EventMetadata().set(StoreDataManager.EVENT_ORIGIN, LOAD_FROM_DISK));
}
} catch (final IOException e) {
logger.error(String.format("Failed to load %s store: %s. Reason: %s", type, f, e.getMessage()), e);
}
}
}
}
}
started = true;
} catch (final IndyDataException e) {
throw new IllegalStateException("Failed to start store data manager: " + e.getMessage(), e);
}
}
use of org.commonjava.indy.audit.ChangeSummary in project indy by Commonjava.
the class LegacyDataMigrationActionTest method migrateHostedRepoJSONWithMissingTypeAttribute.
@Test
public void migrateHostedRepoJSONWithMissingTypeAttribute() throws Exception {
final DataFile dir = dfm.getDataFile(INDY_STORE, hosted.singularEndpointName());
dir.mkdirs();
final DataFile file = dir.getChild("test.json");
file.writeString("{\"name\": \"test\", \"packageType\": \"maven\", \"key\": \"maven:hosted:test\"}", new ChangeSummary(ChangeSummary.SYSTEM_USER, "test repo creation"));
final boolean result = action.migrate();
assertThat(result, equalTo(true));
DataFile out = dfm.getDataFile(INDY_STORE, MAVEN_PKG_KEY, hosted.singularEndpointName(), "test.json");
final String json = out.readString();
assertThat(json.contains("\"type\" : \"hosted\""), equalTo(true));
assertThat(json.contains("\"packageType\" : \"maven\""), equalTo(true));
assertThat(json.contains("\"key\" : \"maven:hosted:test\""), equalTo(true));
}
use of org.commonjava.indy.audit.ChangeSummary in project indy by Commonjava.
the class LegacyDataMigrationActionTest method migrateRemoteRepoJSONWithMissingPackageTypeInKey.
@Test
public void migrateRemoteRepoJSONWithMissingPackageTypeInKey() throws Exception {
final DataFile dir = dfm.getDataFile(INDY_STORE, remote.singularEndpointName());
dir.mkdirs();
final DataFile file = dir.getChild("test.json");
file.writeString("{\"name\": \"test\", \"type\": \"remote\", \"key\": \"remote:test\", \"url\": \"http://www.google.com\"}", new ChangeSummary(ChangeSummary.SYSTEM_USER, "test repo creation"));
final boolean result = action.migrate();
assertThat(result, equalTo(true));
DataFile out = dfm.getDataFile(INDY_STORE, MAVEN_PKG_KEY, remote.singularEndpointName(), "test.json");
final String json = out.readString();
assertThat(json.contains("\"type\" : \"remote\""), equalTo(true));
assertThat(json.contains("\"packageType\" : \"maven\""), equalTo(true));
assertThat(json.contains("\"key\" : \"maven:remote:test\""), equalTo(true));
}
use of org.commonjava.indy.audit.ChangeSummary in project indy by Commonjava.
the class ConcurrencyTest method deadlockOnGroupContains.
@BMRules(rules = { @BMRule(name = "init rendezvous", targetClass = "MemoryStoreDataManager", targetMethod = "<init>", targetLocation = "ENTRY", action = "createRendezvous($0, 2, true)"), @BMRule(name = "getGroupsContaining call", targetClass = "MemoryStoreDataManager", targetMethod = "getGroupsContaining", targetLocation = "ENTRY", action = "rendezvous($0); debug(Thread.currentThread().getName() + \": thread proceeding.\")") })
@Test
public void deadlockOnGroupContains() throws IndyDataException, InterruptedException, ExecutionException {
ExecutorService executor = Executors.newFixedThreadPool(2);
ExecutorCompletionService<String> completionService = new ExecutorCompletionService<>(executor);
AtomicInteger count = new AtomicInteger(0);
RemoteRepository repo = new RemoteRepository(MAVEN_PKG_KEY, "central", "http://repo.maven.apache.org/maven2");
TestUpdatingEventDispatcher dispatcher = new TestUpdatingEventDispatcher(repo, completionService, count);
MemoryStoreDataManager dataManager = new MemoryStoreDataManager(dispatcher, new DefaultIndyConfiguration());
dispatcher.setDataManager(dataManager);
ChangeSummary summary = new ChangeSummary(ChangeSummary.SYSTEM_USER, "Test init");
dataManager.storeArtifactStore(repo, summary, false, false, new EventMetadata());
for (int i = 0; i < 2; i++) {
Group group = new Group(MAVEN_PKG_KEY, "group" + i);
if (i % 2 == 0) {
group.addConstituent(repo);
}
dataManager.storeArtifactStore(group, summary, false, false, new EventMetadata());
}
for (int i = 0; i < count.get(); i++) {
Future<String> future = completionService.take();
assertThat(future.get(), nullValue());
}
}
Aggregations