use of org.commonjava.indy.model.core.Group in project indy by Commonjava.
the class AutoProxDataManagerDecoratorTest method groupAutoCreatedWithDeployPointAndTwoRepos.
@Test
public void groupAutoCreatedWithDeployPointAndTwoRepos() throws Exception {
simpleCatalog();
final String testUrl = http.formatUrl("target", "test");
http.expect(testUrl + "/", 200, "");
http.expect(http.formatUrl("target", "first/"), 200, "");
http.expect(http.formatUrl("target", "second/"), 200, "");
catalog.setEnabled(false);
assertThat(storeQuery.getGroup("test"), nullValue());
catalog.setEnabled(true);
final Group group = storeQuery.getGroup("test");
assertThat(group, notNullValue());
assertThat(group.getName(), equalTo("test"));
final List<StoreKey> constituents = group.getConstituents();
logger.info("Group constituents: {}", constituents);
assertThat(constituents, notNullValue());
assertThat(constituents.size(), equalTo(4));
int idx = 0;
StoreKey key = constituents.get(idx);
assertThat(key.getType(), equalTo(StoreType.hosted));
assertThat(key.getName(), equalTo("test"));
idx++;
key = constituents.get(idx);
assertThat(key.getType(), equalTo(StoreType.remote));
assertThat(key.getName(), equalTo("test"));
idx++;
key = constituents.get(idx);
assertThat(key.getType(), equalTo(StoreType.remote));
assertThat(key.getName(), equalTo("first"));
idx++;
key = constituents.get(idx);
assertThat(key.getType(), equalTo(StoreType.remote));
assertThat(key.getName(), equalTo("second"));
}
use of org.commonjava.indy.model.core.Group in project indy by Commonjava.
the class RoutedCacheProviderForGroupTest method addGroupAndNFSSetup.
@Test
public void addGroupAndNFSSetup() throws Exception {
final String content = "This is a test: " + System.nanoTime();
final InputStream stream = new ByteArrayInputStream(content.getBytes());
final String path = "/path/to/foo.class";
final String hostedName1 = "test1";
final HostedRepository hostedRepo1 = this.client.stores().create(new HostedRepository(hostedName1), "create group", HostedRepository.class);
final File nfsStorage1 = Paths.get(fixture.getBootOptions().getIndyHome(), NFS_BASE, MAVEN_PKG_KEY, hosted.singularEndpointName() + "-" + hostedName1, path).toFile();
final String gname = newName();
Group g = this.client.stores().create(new Group(gname), "create group", Group.class);
g.addConstituent(hostedRepo1);
this.client.stores().update(g, "update group");
assertThat(client.content().exists(hosted, hostedName1, path), equalTo(false));
assertThat(nfsStorage1.exists(), equalTo(false));
client.content().store(group, gname, path, stream);
assertThat(client.content().exists(hosted, hostedName1, path), equalTo(true));
//TODO: seems that the nfs store is created here even if the store operation is on a group repo with a hosted repo in
// doubt that the store operation is recursively called on the sub constituent of this group, so the hosted repo
// in this group then do the store through the FastLocal, so the nfs one is created. Not sure if this is a right
// case.
assertThat(nfsStorage1.exists(), equalTo(true));
}
use of org.commonjava.indy.model.core.Group in project indy by Commonjava.
the class MavenMetadataGenerator method mergeMissing.
private MetadataIncrementalResult mergeMissing(final Group group, final MetadataIncrementalResult incrementalResult, final String toMergePath, String description, BiFunction<ArtifactStore, String, Callable<MetadataResult>> func) throws IndyWorkflowException {
Set<ArtifactStore> missing = incrementalResult.missing;
Metadata master = incrementalResult.result;
logger.debug("Merge member metadata for {}, {}, missing: {}, size: {}", group.getKey(), description, missing, missing.size());
DrainingExecutorCompletionService<MetadataResult> svc = new DrainingExecutorCompletionService<>(mavenMDGeneratorService);
detectOverloadVoid(() -> missing.forEach(store -> svc.submit(func.apply(store, toMergePath))));
// return stores failed download
Set<ArtifactStore> resultingMissing = new HashSet<>();
Set<StoreKey> included = new HashSet<>();
try {
svc.drain(mr -> {
if (mr != null) {
if (mr.missing) {
resultingMissing.add(mr.store);
} else {
included.add(mr.store.getKey());
merger.merge(master, mr.metadata, group, toMergePath);
putToMetadataCache(mr.store.getKey(), toMergePath, new MetadataInfo(mr.metadata));
}
}
});
} catch (InterruptedException e) {
logger.debug("Interrupted while merging " + description + " member metadata.");
} catch (ExecutionException e) {
throw new IndyWorkflowException("Failed to merge downloaded " + description + " member metadata.", e);
}
return new MetadataIncrementalResult(resultingMissing, included, master);
}
use of org.commonjava.indy.model.core.Group in project indy by Commonjava.
the class MavenMetadataGenerator method mergeProviderMetadata.
private Metadata mergeProviderMetadata(final Group group, final Metadata master, final String toMergePath) throws IndyWorkflowException {
logger.debug("Merge metadata for non-store providers in: {} on path: {}", group.getKey(), toMergePath);
DrainingExecutorCompletionService<Metadata> svc = new DrainingExecutorCompletionService<>(mavenMDGeneratorService);
detectOverloadVoid(() -> metadataProviders.forEach(provider -> svc.submit(() -> {
try {
return provider.getMetadata(group.getKey(), toMergePath);
} catch (IndyWorkflowException e) {
logger.error(String.format("Cannot read metadata: %s from metadata provider: %s. Reason: %s", toMergePath, provider.getClass().getSimpleName(), e.getMessage()), e);
}
return null;
})));
try {
svc.drain(metadata -> {
if (metadata != null) {
merger.merge(master, metadata, group, toMergePath);
}
});
} catch (InterruptedException e) {
logger.debug("Interrupted while merging provider member metadata.");
} catch (ExecutionException e) {
throw new IndyWorkflowException("Failed to merge provider member metadata.", e);
}
return master;
}
use of org.commonjava.indy.model.core.Group in project indy by Commonjava.
the class GroupMetaOverlapWithMetaOfHostedReposTest method run.
@Test
@Category(EventDependent.class)
public void run() throws Exception {
final String repo1 = "repo1";
final String repo2 = "repo2";
final String path = "org/foo/bar/maven-metadata.xml";
/* @formatter:off */
final String repo1Content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<metadata>\n" + " <groupId>org.foo</groupId>\n" + " <artifactId>bar</artifactId>\n" + " <versioning>\n" + " <latest>1.0</latest>\n" + " <release>1.0</release>\n" + " <versions>\n" + " <version>1.0</version>\n" + " </versions>\n" + " <lastUpdated>20150722164334</lastUpdated>\n" + " </versioning>\n" + "</metadata>\n";
/* @formatter:on */
/* @formatter:off */
final String repo2Content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<metadata>\n" + " <groupId>org.foo</groupId>\n" + " <artifactId>bar</artifactId>\n" + " <versioning>\n" + " <latest>1.1</latest>\n" + " <release>1.1</release>\n" + " <versions>\n" + " <version>1.1</version>\n" + " </versions>\n" + " <lastUpdated>20150822164334</lastUpdated>\n" + " </versioning>\n" + "</metadata>\n";
/* @formatter:on */
server.expect(server.formatUrl(repo1, path), 200, repo1Content);
server.expect(server.formatUrl(repo2, path), 200, repo2Content);
RemoteRepository remote1 = new RemoteRepository(repo1, server.formatUrl(repo1));
remote1 = client.stores().create(remote1, "adding remote", RemoteRepository.class);
RemoteRepository remote2 = new RemoteRepository(repo2, server.formatUrl(repo2));
remote2 = client.stores().create(remote2, "adding remote", RemoteRepository.class);
Group g = new Group("test", remote1.getKey(), remote2.getKey());
g = client.stores().create(g, "adding group", Group.class);
System.out.printf("\n\nGroup constituents are:\n %s\n\n", StringUtils.join(g.getConstituents(), "\n "));
InputStream stream = client.content().get(group, g.getName(), path);
assertThat(stream, notNullValue());
String metadata = IOUtils.toString(stream);
/* @formatter:off */
final String groupContent = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<metadata>\n" + " <groupId>org.foo</groupId>\n" + " <artifactId>bar</artifactId>\n" + " <versioning>\n" + " <latest>1.1</latest>\n" + " <release>1.1</release>\n" + " <versions>\n" + " <version>1.0</version>\n" + " <version>1.1</version>\n" + " </versions>\n" + " <lastUpdated>20150822164334</lastUpdated>\n" + " </versioning>\n" + "</metadata>\n";
/* @formatter:on */
assertThat(metadata, equalTo(groupContent));
final String hostedRepo = "hostedRepo";
HostedRepository hostedRepository = new HostedRepository(hostedRepo);
hostedRepository = client.stores().create(hostedRepository, "adding hosted", HostedRepository.class);
/* @formatter:off */
final String hostedMetaContent = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<metadata>\n" + " <groupId>org.foo</groupId>\n" + " <artifactId>bar</artifactId>\n" + " <versioning>\n" + " <latest>1.2</latest>\n" + " <release>1.2</release>\n" + " <versions>\n" + " <version>1.2</version>\n" + " </versions>\n" + " <lastUpdated>20150922164334</lastUpdated>\n" + " </versioning>\n" + "</metadata>\n";
/* @formatter:on */
client.content().store(hostedRepository.getKey(), path, new ByteArrayInputStream(hostedMetaContent.getBytes("UTF-8")));
final PathInfo p = client.content().getInfo(hosted, hostedRepo, path);
assertThat("hosted metadata should exist", p.exists(), equalTo(true));
g.addConstituent(hostedRepository);
client.stores().update(g, "add new hosted");
System.out.printf("\n\nUpdated group constituents are:\n %s\n\n", StringUtils.join(g.getConstituents(), "\n "));
waitForEventPropagation();
final String gpLevelMetaFilePath = String.format("%s/var/lib/indy/storage/%s-%s/%s", fixture.getBootOptions().getHomeDir(), group.name(), g.getName(), path);
assertThat("group metadata should be removed after merging", new File(gpLevelMetaFilePath).exists(), equalTo(false));
stream = client.content().get(group, g.getName(), path);
assertThat(stream, notNullValue());
metadata = IOUtils.toString(stream);
/* @formatter:off */
final String updGroupContent = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<metadata>\n" + " <groupId>org.foo</groupId>\n" + " <artifactId>bar</artifactId>\n" + " <versioning>\n" + " <latest>1.2</latest>\n" + " <release>1.2</release>\n" + " <versions>\n" + " <version>1.0</version>\n" + " <version>1.1</version>\n" + " <version>1.2</version>\n" + " </versions>\n" + " <lastUpdated>20150922164334</lastUpdated>\n" + " </versioning>\n" + "</metadata>\n";
/* @formatter:on */
assertThat(metadata, equalTo(updGroupContent));
}
Aggregations