use of org.commonjava.indy.model.core.RemoteRepository in project indy by Commonjava.
the class PomWithRepoAddsRepoToGroupTest method skimPomForRepoAndAddIt.
@Test
public void skimPomForRepoAndAddIt() throws Exception {
final PomRef ref = loadPom("one-repo", Collections.singletonMap("one-repo.url", server.formatUrl(REPO)));
server.expect(server.formatUrl(TEST_REPO, ref.path), 200, ref.pom);
final InputStream stream = client.content().get(StoreType.group, PUBLIC, ref.path);
final String downloaded = IOUtils.toString(stream);
IOUtils.closeQuietly(stream);
assertThat("SANITY: downloaded POM is wrong!", downloaded, equalTo(ref.pom));
// sleep while event observer runs...
System.out.println("Waiting 5s for events to run.");
Thread.sleep(5000);
final Group g = client.stores().load(StoreType.group, PUBLIC, Group.class);
assertThat("Group membership does not contain implied repository", g.getConstituents().contains(new StoreKey(StoreType.remote, REPO)), equalTo(true));
RemoteRepository r = client.stores().load(StoreType.remote, TEST_REPO, RemoteRepository.class);
String metadata = r.getMetadata(ImpliedRepoMetadataManager.IMPLIED_STORES);
assertThat("Reference to repositories implied by POMs in this repo is missing from metadata.", metadata.contains("remote:" + REPO), equalTo(true));
r = client.stores().load(StoreType.remote, REPO, RemoteRepository.class);
metadata = r.getMetadata(ImpliedRepoMetadataManager.IMPLIED_BY_STORES);
assertThat("Backref to repo with pom that implies this repo is missing from metadata.", metadata.contains("remote:" + TEST_REPO), equalTo(true));
}
use of org.commonjava.indy.model.core.RemoteRepository in project indy by Commonjava.
the class KojiMavenMetadataProviderTest method initKojiClient.
private void initKojiClient(String exchangeName, boolean verifyArtifacts) throws BindException, IOException, GalleyInitException, IndyDataException {
StoreDataManager storeDataManager = new MemoryStoreDataManager(true);
if (verifyArtifacts) {
RemoteRepository verifyRepo = new RemoteRepository(MAVEN_PKG_KEY, VERIFY_REPO, server.formatUrl(VERIFY_BASEPATH));
storeDataManager.storeArtifactStore(verifyRepo, new ChangeSummary(ChangeSummary.SYSTEM_USER, "Adding verification repo"), false, true, new EventMetadata());
kojiConfig.setArtifactAuthorityStore(new StoreKey(MAVEN_PKG_KEY, remote, VERIFY_REPO).toString());
}
String resourceBase = "koji-metadata/" + exchangeName;
configureKojiServer(server, KOJI_BASEPATH, counter, resourceBase, verifyArtifacts, VERIFY_BASEPATH);
kojiClient = new KojiClient(kojiConfig, new MemoryPasswordManager(), Executors.newCachedThreadPool());
GalleyCore galley = new GalleyCoreBuilder(new FileCacheProviderFactory(temp.newFolder("cache"))).withEnabledTransports(new HttpClientTransport(new HttpImpl(new org.commonjava.maven.galley.auth.MemoryPasswordManager()), new IndyObjectMapper(true), new GlobalHttpConfiguration())).build();
DownloadManager downloadManager = new DefaultDownloadManager(storeDataManager, galley.getTransferManager(), new IndyLocationExpander(storeDataManager));
DirectContentAccess directContentAccess = new DefaultDirectContentAccess(downloadManager, Executors.newCachedThreadPool());
DirectContentAccess dca = new DefaultDirectContentAccess(downloadManager, Executors.newSingleThreadExecutor());
ContentDigester contentDigester = new DefaultContentDigester(dca, new CacheHandle<String, TransferMetadata>("content-metadata", contentMetadata));
KojiBuildAuthority buildAuthority = new KojiBuildAuthority(kojiConfig, new StandardTypeMapper(), kojiClient, storeDataManager, contentDigester, directContentAccess);
provider = new KojiMavenMetadataProvider(this.cache, kojiClient, buildAuthority, kojiConfig);
}
use of org.commonjava.indy.model.core.RemoteRepository in project indy by Commonjava.
the class HttProxOriginMigrationAction method migrate.
@Override
public boolean migrate() throws IndyLifecycleException {
List<RemoteRepository> repos;
try {
repos = storeDataManager.query().noPackageType().getAllRemoteRepositories();
} catch (IndyDataException e) {
throw new IndyLifecycleException("Cannot retrieve all remote repositories. Reason: %s", e, e.getMessage());
}
List<RemoteRepository> toStore = new ArrayList<>();
repos.forEach((repo) -> {
if (repo.getDescription() != null && repo.getDescription().contains("HTTProx proxy")) {
repo.setMetadata(ArtifactStore.METADATA_ORIGIN, ProxyAcceptHandler.HTTPROX_ORIGIN);
RemoteRepository store = repo.copyOf(GENERIC_PKG_KEY, repo.getName());
toStore.add(store);
}
});
final ChangeSummary changeSummary = new ChangeSummary(ChangeSummary.SYSTEM_USER, "Adding HttProx origin metadata");
for (RemoteRepository repo : toStore) {
try {
storeDataManager.storeArtifactStore(repo, changeSummary, false, true, new EventMetadata());
} catch (IndyDataException e) {
throw new IndyLifecycleException("Failed to store %s with HttProx origin metadata. Reason: %s", e, repo == null ? "NULL REPO" : repo.getKey(), e.getMessage());
}
}
return !toStore.isEmpty();
}
use of org.commonjava.indy.model.core.RemoteRepository in project indy by Commonjava.
the class ProxyResponseWriter method getRepository.
private RemoteRepository getRepository(final URL url) throws IndyDataException {
int port = url.getPort();
if (port < 1) {
port = url.getDefaultPort();
}
String name = PROXY_REPO_PREFIX + url.getHost().replace('.', '-') + '_' + port;
final String baseUrl = String.format("%s://%s:%s/", url.getProtocol(), url.getHost(), port);
ArtifactStoreQuery<RemoteRepository> query = storeManager.query().packageType(GENERIC_PKG_KEY).storeType(RemoteRepository.class);
RemoteRepository remote = query.getRemoteRepositoryByUrl(baseUrl);
if (remote == null) {
logger.debug("Looking for remote repo with name: {}", name);
remote = query.getByName(name);
// if repo with this name already exists, it has a different url, so we need to use a different name
int i = 1;
while (remote != null) {
name = PROXY_REPO_PREFIX + url.getHost().replace('.', '-') + "_" + i++;
logger.debug("Looking for remote repo with name: {}", name);
remote = query.getByName(name);
}
}
if (remote == null) {
logger.debug("Creating remote repository for HTTProx request: {}", url);
final UrlInfo info = new UrlInfo(url.toExternalForm());
if (repoCreator == null) {
throw new IndyDataException("No valid instance of ProxyRepositoryCreator. Cannot auto-create remote proxy to: '{}'", baseUrl);
}
final UserPass up = UserPass.parse(ApplicationHeader.authorization, httpRequest, url.getAuthority());
remote = repoCreator.create(name, baseUrl, info, up, LoggerFactory.getLogger(repoCreator.getClass()));
remote.setMetadata(ArtifactStore.METADATA_ORIGIN, ProxyAcceptHandler.HTTPROX_ORIGIN);
final ChangeSummary changeSummary = new ChangeSummary(ChangeSummary.SYSTEM_USER, "Creating HTTProx proxy for: " + info.getUrl());
storeManager.storeArtifactStore(remote, changeSummary, false, true, new EventMetadata());
}
return remote;
}
use of org.commonjava.indy.model.core.RemoteRepository in project indy by Commonjava.
the class KojiContentManagerDecorator method exists.
@Override
@IndyMetrics(measure = @Measure(timers = @MetricNamed(name = IndyMetricsKojiNames.METHOD_CONTENTMANAGER_EXISTS + IndyMetricsNames.TIMER), meters = @MetricNamed(name = IndyMetricsKojiNames.METHOD_CONTENTMANAGER_EXISTS + IndyMetricsNames.METER)))
public boolean exists(ArtifactStore store, String path) throws IndyWorkflowException {
Logger logger = LoggerFactory.getLogger(getClass());
logger.info("KOJI: Delegating initial existence check for: {}/{}", store.getKey(), path);
boolean result = delegate.exists(store, path);
if (!result && StoreType.group == store.getKey().getType()) {
Group group = (Group) store;
logger.info("KOJI: Checking whether Koji contains a build matching: {}", path);
RemoteRepository kojiProxy = findKojiBuildAnd(store, path, new EventMetadata(), null, this::createRemoteRepository);
if (kojiProxy != null) {
adjustTargetGroup(kojiProxy, group);
result = delegate.exists(kojiProxy, path);
}
if (result) {
nfc.clearMissing(new ConcreteResource(LocationUtils.toLocation(store), path));
}
}
return result;
}
Aggregations