use of org.commonjava.indy.model.core.RemoteRepository in project indy by Commonjava.
the class ImpliedReposOriginMigrationAction method migrate.
@Override
public boolean migrate() throws IndyLifecycleException {
List<RemoteRepository> remoteRepositories;
try {
remoteRepositories = storeDataManager.query().getAllRemoteRepositories();
} catch (IndyDataException e) {
throw new IndyLifecycleException("Cannot retrieve all remote repositories. Reason: %s", e, e.getMessage());
}
List<RemoteRepository> toStore = new ArrayList<>();
remoteRepositories.forEach((repo) -> {
if (repo.getName().startsWith("i-")) {
repo.setMetadata(METADATA_ORIGIN, IMPLIED_REPO_ORIGIN);
toStore.add(repo);
}
});
for (RemoteRepository repo : toStore) {
try {
storeDataManager.storeArtifactStore(repo, new ChangeSummary(ChangeSummary.SYSTEM_USER, "Adding implied-repository origin metadata"), false, true, new EventMetadata());
} catch (IndyDataException e) {
throw new IndyLifecycleException("Failed to store %s with implied-repos 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 KojiContentManagerDecorator method getTransfer.
@Override
public Transfer getTransfer(final ArtifactStore store, final String path, final TransferOperation operation) throws IndyWorkflowException {
Logger logger = LoggerFactory.getLogger(getClass());
logger.info("KOJI: Delegating initial getTransfer() attempt for: {}/{}", store.getKey(), path);
Transfer result = delegate.getTransfer(store, path, operation);
if (result == null && TransferOperation.DOWNLOAD == operation && StoreType.group == store.getKey().getType()) {
logger.info("KOJI: Checking for Koji build matching: {}", path);
Group group = (Group) store;
RemoteRepository kojiProxy = findKojiBuildAnd(store, path, new EventMetadata(), null, this::createRemoteRepository);
if (kojiProxy != null) {
adjustTargetGroup(kojiProxy, group);
EventMetadata eventMetadata = new EventMetadata().set(ContentManager.ENTRY_POINT_STORE, store.getKey());
result = delegate.retrieve(kojiProxy, path, eventMetadata);
}
if (result != null && result.exists()) {
nfc.clearMissing(new ConcreteResource(LocationUtils.toLocation(store), path));
}
}
// Finally, pass the Transfer back.
return result;
}
use of org.commonjava.indy.model.core.RemoteRepository in project indy by Commonjava.
the class KojiContentManagerDecorator method createRemoteRepository.
private RemoteRepository createRemoteRepository(StoreKey inStore, ArtifactRef artifactRef, final KojiBuildInfo build, final KojiSessionInfo session) throws KojiClientException {
Logger logger = LoggerFactory.getLogger(getClass());
try {
KojiBuildArchiveCollection archiveCollection = kojiClient.listArchivesForBuild(build, session);
boolean isBinaryBuild = isBinaryBuild(build);
String name = getRepositoryName(build, isBinaryBuild);
// Using a RemoteRepository allows us to use the higher-level APIs in Indy, as opposed to TransferManager
final KojiRepositoryCreator creator = createRepoCreator();
if (creator == null) {
throw new KojiClientException("Cannot proceed without a valid KojiRepositoryCreator instance.");
}
RemoteRepository remote = creator.createRemoteRepository(inStore.getPackageType(), name, formatStorageUrl(build), config.getDownloadTimeoutSeconds());
remote.setServerCertPem(config.getServerPemContent());
if (isBinaryBuild) {
remote.setMetadata(ArtifactStore.METADATA_ORIGIN, KOJI_ORIGIN_BINARY);
} else {
remote.setMetadata(ArtifactStore.METADATA_ORIGIN, KOJI_ORIGIN);
}
// set pathMaskPatterns using build output paths
Set<String> patterns = new HashSet<>();
patterns.addAll(archiveCollection.getArchives().stream().map(a -> a.getGroupId().replace('.', '/') + "/" + a.getArtifactId() + "/" + a.getVersion() + "/" + a.getFilename()).collect(Collectors.toSet()));
remote.setPathMaskPatterns(patterns);
remote.setMetadata(CREATION_TRIGGER_GAV, artifactRef.toString());
remote.setMetadata(NVR, build.getNvr());
final ChangeSummary changeSummary = new ChangeSummary(ChangeSummary.SYSTEM_USER, "Creating remote repository for Koji build: " + build.getNvr());
storeDataManager.storeArtifactStore(remote, changeSummary, false, true, new EventMetadata());
logger.debug("Koji {}, add pathMaskPatterns: {}", name, patterns);
return remote;
} catch (MalformedURLException e) {
throw new KojiClientException("Koji add-on seems misconifigured. Could not generate URL to repo for " + "build: %s\nBase URL: %s\nError: %s", e, build.getNvr(), config.getStorageRootUrl(), e.getMessage());
} catch (IOException e) {
throw new KojiClientException("Failed to read server SSL PEM information from Koji configuration for new hosted repo: %s", e, e.getMessage());
} catch (IndyDataException e) {
throw new KojiClientException("Failed to store temporary remote repo: %s", e, e.getMessage());
}
}
use of org.commonjava.indy.model.core.RemoteRepository in project indy by Commonjava.
the class SetBackSettingsManagerTest method settingsForGroup_OneRemoteOneHosted_HostedOmittedButAddedInComment.
@Test
public void settingsForGroup_OneRemoteOneHosted_HostedOmittedButAddedInComment() throws Exception {
final RemoteRepository remote = new RemoteRepository(MAVEN_PKG_KEY, "test", "http://foo.bar/");
remote.setDescription("Test Repository");
final HostedRepository hosted = new HostedRepository(MAVEN_PKG_KEY, "test-hosted");
store(remote);
store(hosted);
final Group group = new Group(MAVEN_PKG_KEY, "test-group", remote.getKey(), hosted.getKey());
store(group);
System.out.println("Group members:\n " + join(group.getConstituents(), "\n "));
assertThat(readSettings(group.getKey(), false), equalTo(null));
final List<String> lines = generateSettings(group.getKey());
assertThat("No repository with id: " + remote.getName() + " found in settings.xml for group!", lines.contains("<id>" + remote.getName() + "</id>"), equalTo(true));
assertThat("Repository with id: " + hosted.getName() + " Should not be present in settings.xml for group!", lines.contains("<id>" + remote.getName() + "</id>"), equalTo(true));
assertThat("No entry for remote: " + remote.getKey().toString() + " found in settings.xml constituency comment!", lines.contains("* " + remote.getKey()), equalTo(true));
assertThat("No entry for hosted: " + hosted.getKey().toString() + " found in settings.xml constituency comment!", lines.contains("* " + hosted.getKey()), equalTo(true));
}
use of org.commonjava.indy.model.core.RemoteRepository in project indy by Commonjava.
the class SetBackSettingsManagerTest method settingsForGroup_SingleMemberRemote.
@Test
public void settingsForGroup_SingleMemberRemote() throws Exception {
final RemoteRepository remote = new RemoteRepository(MAVEN_PKG_KEY, "test", "http://foo.bar/");
remote.setDescription("Test Repository");
store(remote);
final StoreKey remoteKey = remote.getKey();
final Group group = new Group(MAVEN_PKG_KEY, "test-group", remoteKey);
store(group);
assertThat(readSettings(group.getKey(), false), equalTo(null));
final List<String> lines = generateSettings(group.getKey());
assertThat("No repository with id: " + remote.getName() + " found in settings.xml for remote!", lines.contains("<id>" + remote.getName() + "</id>"), equalTo(true));
}
Aggregations