use of org.commonjava.indy.data.IndyDataException 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.data.IndyDataException in project indy by Commonjava.
the class KojiContentManagerDecorator method adjustTargetGroup.
private Group adjustTargetGroup(final RemoteRepository buildRepo, final Group group) throws IndyWorkflowException {
Logger logger = LoggerFactory.getLogger(getClass());
// try to lookup the group -> targetGroup mapping in config, using the
// entry-point group as the lookup key. If that returns null, the targetGroup is
// the entry-point group.
Group targetGroup = group;
boolean isBinaryBuild = KOJI_ORIGIN_BINARY.equals(buildRepo.getMetadata(ArtifactStore.METADATA_ORIGIN));
String targetName = isBinaryBuild ? config.getTargetBinaryGroup(group.getName()) : config.getTargetGroup(group.getName());
if (targetName != null) {
try {
targetGroup = storeDataManager.query().packageType(group.getPackageType()).getGroup(targetName);
} catch (IndyDataException e) {
throw new IndyWorkflowException("Cannot lookup koji-addition target group: %s (source group: %s). Reason: %s", e, targetName, group.getName(), e.getMessage());
}
}
logger.info("Adding Koji build proxy: {} to group: {}", buildRepo.getKey(), targetGroup.getKey());
// Append the new remote repo as a member of the targetGroup.
targetGroup.addConstituent(buildRepo);
try {
final ChangeSummary changeSummary = new ChangeSummary(ChangeSummary.SYSTEM_USER, "Adding remote repository for Koji build: " + buildRepo.getMetadata(NVR));
storeDataManager.storeArtifactStore(targetGroup, changeSummary, false, true, new EventMetadata());
} catch (IndyDataException e) {
throw new IndyWorkflowException("Cannot store target-group: %s changes for: %s. Error: %s", e, targetGroup.getName(), buildRepo.getMetadata(NVR), e.getMessage());
}
logger.info("Retrieving GAV: {} from: {}", buildRepo.getMetadata(CREATION_TRIGGER_GAV), buildRepo);
return targetGroup;
// TODO: how to index it for the group...?
}
use of org.commonjava.indy.data.IndyDataException in project indy by Commonjava.
the class KojiOriginMigrationAction 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("Koji build")) {
repo.setMetadata(METADATA_ORIGIN, KOJI_ORIGIN);
toStore.add(repo);
}
});
final ChangeSummary changeSummary = new ChangeSummary(ChangeSummary.SYSTEM_USER, "Adding Koji 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 Koji origin metadata. Reason: %s", e, repo == null ? "NULL REPO" : repo.getKey(), e.getMessage());
}
}
return !toStore.isEmpty();
}
use of org.commonjava.indy.data.IndyDataException in project indy by Commonjava.
the class ImpliedRepoMaintainer method processImpliedRepos.
private boolean processImpliedRepos(final ImpliedRepoMaintJob job) {
final Set<StoreKey> processed = new HashSet<>();
// implications. Reachable means they could be in nested groups.
for (final ArtifactStore member : job.reachableMembers) {
processed.add(member.getKey());
}
logger.debug("Preset processed-implications to reachable members:\n {}", new JoinString("\n ", processed));
int lastLen = 0;
boolean changed = false;
job.added = new ArrayList<>();
// As soon as we go an iteration without adding a new member, we've captured everything.
do {
lastLen = job.members.size();
for (final ArtifactStore member : new ArrayList<>(job.members)) {
logger.debug("Processing member: {} for implied repos within group: {}", member.getKey(), job.group.getKey());
processed.add(member.getKey());
List<StoreKey> implied;
try {
implied = metadataManager.getStoresImpliedBy(member);
} catch (final ImpliedReposException e) {
logger.error("Failed to retrieve implied-store metadata for: " + member.getKey(), e);
continue;
}
if (implied == null || implied.isEmpty()) {
continue;
}
implied.removeAll(processed);
for (final StoreKey key : implied) {
logger.debug("Found implied store: {} not already in group: {}", key, job.group.getKey());
ArtifactStore impliedStore;
try {
impliedStore = storeManager.getArtifactStore(key);
} catch (final IndyDataException e) {
logger.error("Failed to retrieve store: " + key + " implied by: " + member.getKey(), e);
continue;
}
logger.info("Adding: {} to group: {} (implied by POMs in: {})", key, job.group.getKey(), member.getKey());
processed.add(key);
job.added.add(key);
job.group.addConstituent(key);
job.members.add(impliedStore);
changed = true;
}
}
} while (job.members.size() > lastLen);
return changed;
}
use of org.commonjava.indy.data.IndyDataException in project indy by Commonjava.
the class ImpliedRepoMaintainer method initJob.
private boolean initJob(final ImpliedRepoMaintJob job) {
// we might be able to fix the repo-removal problem too.
if (!(job.store instanceof Group)) {
logger.debug("ImpliedRepoMaint: Ignoring non-group: {}", job.store.getKey());
return false;
}
if (!config.isEnabledForGroup(job.store.getName())) {
logger.debug("ImpliedRepoMaint: Implied repositories not enabled for group: {}", job.store.getKey());
return false;
}
logger.debug("Processing group: {} for stores implied by membership which are not yet in the membership", job.store.getName());
job.group = (Group) job.store;
try {
// getOrderedStoresInGroup(), but we can't use persisted info...
job.members = loadMemberStores(job.group, job);
// getOrderedConcreteStores(), but we can't use the persisted info...
final LinkedHashSet<ArtifactStore> reachable = new LinkedHashSet<>(job.members.size());
for (final ArtifactStore member : job.members) {
if (member instanceof Group) {
reachable.addAll(loadMemberStores((Group) member, job));
} else {
reachable.add(member);
}
}
job.reachableMembers = new ArrayList<>(reachable);
logger.debug("For group: {}\n Members: {}\n Reachable Concrete Members: {}", job.group.getKey(), job.members, job.reachableMembers);
} catch (final IndyDataException e) {
logger.error("Failed to retrieve member stores for group: " + job.group.getName(), e);
}
if (job.members == null) {
logger.debug("ImpliedRepoMaint: Group: {} has no membership", job.store.getKey());
return false;
}
return true;
}
Aggregations