use of org.commonjava.maven.galley.event.EventMetadata 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 {
List<KojiArchiveInfo> archives = kojiContentProvider.listArchivesForBuild(build.getId(), session);
boolean isBinaryBuild = kojiUtils.isBinaryBuild(build);
String name = kojiUtils.getRepositoryName(build);
StoreKey remoteKey = new StoreKey(inStore.getPackageType(), StoreType.remote, name);
RemoteRepository remote = (RemoteRepository) storeDataManager.getArtifactStore(remoteKey);
if (remote == null) {
// Using a RemoteRepository allows us to use the higher-level APIs in Indy, as opposed to TransferManager
final KojiRepositoryCreator creator = kojiUtils.createRepoCreator();
if (creator == null) {
throw new KojiClientException("Cannot proceed without a valid KojiRepositoryCreator instance.");
}
remote = creator.createRemoteRepository(inStore.getPackageType(), name, kojiUtils.formatStorageUrl(config.getStorageRootUrl(), build), config.getDownloadTimeoutSeconds());
if (config.getServerPemEnabled()) {
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 = pathFormatter.getPatterns(inStore, artifactRef, archives);
// pre-index the koji build artifacts and set authoritative index of the remote to let the
// koji remote repo directly go through the content index
patterns.forEach(path -> indexManager.indexPathInStores(path, remoteKey));
remote.setAuthoritativeIndex(true);
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.info("Koji {}: Set path masks {} with artifact {} to repo: {}", name, patterns, artifactRef, remote);
// logger.debug( "Koji {}, add pathMaskPatterns: {}", name, patterns );
} else {
if (remote.isDisabled()) {
logger.info("Remote repository {} already exists, but is currently disabled. Returning null.", remoteKey);
remote = null;
} else {
// this is a strange situation - delegate did not find the requested resource while Koji claims it
// is contained in this repo and it already exists and is enabled. Possibly corrupted list of path
// mask patterns set on the repo or content index
logger.warn("Remote repository {} already exists. Using it as is.", remoteKey);
}
}
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.maven.galley.event.EventMetadata 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.debug("KOJI: Delegating initial getTransfer() attempt for: {}/{}", store.getKey(), path);
Transfer result = delegate.getTransfer(store, path, operation);
if (result == null && kojiUtils.isVersionSignatureAllowedWithPath(path) && 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.maven.galley.event.EventMetadata in project indy by Commonjava.
the class KojiRemovePemMigrationAction method doMigrate.
private boolean doMigrate() throws IndyLifecycleException {
List<RemoteRepository> repos = new ArrayList<>();
try {
Set<String> defaults = PackageTypes.getPackageTypes();
for (String packageType : defaults) {
repos.addAll(storeDataManager.query().getAllRemoteRepositories(packageType));
}
} 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.getName().contains("koji-") && repo.getServerCertPem() != null) {
repo.setServerCertPem(null);
toStore.add(repo);
}
});
final ChangeSummary changeSummary = new ChangeSummary(ChangeSummary.SYSTEM_USER, "Remove the server PEM from Koji repo.");
for (RemoteRepository repo : toStore) {
try {
storeDataManager.storeArtifactStore(repo, changeSummary, false, false, new EventMetadata());
} catch (IndyDataException e) {
throw new IndyLifecycleException("Failed to store %s. Reason: %s", e, repo == null ? "NULL REPO" : repo.getKey(), e.getMessage());
}
}
logger.info("Remove server PEM from Koji repo migration done. Result: {}", toStore.size());
if (logger.isDebugEnabled()) {
toStore.forEach((s) -> logger.debug(s.getKey().toString()));
}
return !toStore.isEmpty();
}
use of org.commonjava.maven.galley.event.EventMetadata in project indy by Commonjava.
the class KojiRepairManager method doRepair.
/**
* Repair one remote repository.
* @param packageType
* @param repository repository to be repaired. If null, the repository name will be retrieved according to
* the buildInfo and the naming format in koji.conf.
* @param buildInfo koji build which this repository proxies
* @param user the user does the repair
* @param isDryRun
* @return
* @throws KojiRepairException
*/
private KojiRepairResult.RepairResult doRepair(String packageType, RemoteRepository repository, KojiBuildInfo buildInfo, String user, boolean isDryRun) throws KojiRepairException {
StoreKey storeKey;
if (repository != null) {
storeKey = repository.getKey();
} else {
String name = kojiUtils.getRepositoryName(buildInfo);
storeKey = new StoreKey(packageType, StoreType.remote, name);
try {
repository = (RemoteRepository) storeManager.getArtifactStore(storeKey);
} catch (IndyDataException e) {
throw new KojiRepairException("Cannot get store: %s. Reason: %s", e, storeKey, e.getMessage());
}
}
KojiRepairResult.RepairResult repairResult = new KojiRepairResult.RepairResult(storeKey);
String url = repository.getUrl();
String newUrl;
try {
// volume is involved
newUrl = kojiUtils.formatStorageUrl(config.getStorageRootUrl(), buildInfo);
} catch (MalformedURLException e) {
throw new KojiRepairException("Failed to format storage Url: %s. Reason: %s", e, storeKey, e.getMessage());
}
boolean changed = !url.equals(newUrl);
if (changed) {
repairResult.withPropertyChange("url", url, newUrl);
if (!isDryRun) {
ChangeSummary changeSummary = new ChangeSummary(user, "Repair " + storeKey + " url with volume: " + buildInfo.getVolumeName());
repository.setUrl(newUrl);
repository.setMetadata(METADATA_KOJI_BUILD_ID, Integer.toString(buildInfo.getId()));
boolean fireEvents = false;
boolean skipIfExists = false;
try {
storeManager.storeArtifactStore(repository, changeSummary, skipIfExists, fireEvents, new EventMetadata());
} catch (IndyDataException e) {
throw new KojiRepairException("Failed to repair store: %s. Reason: %s", e, storeKey, e.getMessage());
}
}
}
return repairResult;
}
use of org.commonjava.maven.galley.event.EventMetadata in project indy by Commonjava.
the class ImpliedReposOriginMigrationAction method doMigrate.
private boolean doMigrate() throws IndyLifecycleException {
List<RemoteRepository> remoteRepositories;
try {
remoteRepositories = storeDataManager.query().getAllRemoteRepositories(PKG_TYPE_MAVEN);
} 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();
}
Aggregations