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;
}
use of org.commonjava.indy.model.core.RemoteRepository in project indy by Commonjava.
the class KojiContentManagerDecorator method retrieve.
@Override
@IndyMetrics(measure = @Measure(timers = @MetricNamed(name = IndyMetricsKojiNames.METHOD_CONTENTMANAGER_RETRIEVE + IndyMetricsNames.TIMER), meters = @MetricNamed(name = IndyMetricsKojiNames.METHOD_CONTENTMANAGER_RETRIEVE + IndyMetricsNames.METER)))
public Transfer retrieve(final ArtifactStore store, final String path, final EventMetadata eventMetadata) throws IndyWorkflowException {
Logger logger = LoggerFactory.getLogger(getClass());
logger.info("KOJI: Delegating initial retrieval attempt for: {}/{}", store.getKey(), path);
Transfer result = delegate.retrieve(store, path, eventMetadata);
if (result == null && StoreType.group == store.getKey().getType()) {
logger.info("KOJI: Checking for Koji build matching: {}", path);
Group group = (Group) store;
RemoteRepository kojiProxy = findKojiBuildAnd(store, path, eventMetadata, null, this::createRemoteRepository);
if (kojiProxy != null) {
adjustTargetGroup(kojiProxy, group);
result = delegate.retrieve(kojiProxy, path, eventMetadata);
}
if (result != null) {
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 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();
}
Aggregations