use of org.commonjava.indy.IndyWorkflowException in project indy by Commonjava.
the class KojiContentManagerDecorator method proxyKojiBuild.
private <T> T proxyKojiBuild(final StoreKey inStore, final ArtifactRef artifactRef, final String path, EventMetadata eventMetadata, T defValue, KojiBuildAction<T> consumer) throws IndyWorkflowException {
Logger logger = LoggerFactory.getLogger(getClass());
try {
return kojiClient.withKojiSession((session) -> {
List<KojiBuildInfo> builds = kojiClient.listBuildsContaining(artifactRef, session);
Collections.sort(builds, (build1, build2) -> build2.getCreationTime().compareTo(build1.getCreationTime()));
logger.debug("Got {} builds from koji. Looking for best match.", builds.size());
for (KojiBuildInfo build : builds) {
if (build.getBuildState() != KojiBuildState.COMPLETE) {
logger.debug("Build: {} is not completed. The state is {}. Skipping.", build.getNvr(), build.getBuildState());
continue;
}
boolean buildAllowed = false;
if (isBinaryBuild(build)) {
// This is not a real build, it's a binary import.
if (config.isProxyBinaryBuilds()) {
logger.info("Trying binary build: {} with id: {}", build.getNvr(), build.getId());
buildAllowed = true;
} else {
logger.debug("Skipping binary build: {} with id: {}", build.getNvr(), build.getId());
}
} else {
logger.info("Trying build: {} with id: {}", build.getNvr(), build.getId());
if (!config.isTagPatternsEnabled()) {
buildAllowed = true;
} else {
List<KojiTagInfo> tags = kojiClient.listTags(build.getId(), session);
logger.debug("Build is in {} tags...", tags.size());
for (KojiTagInfo tag : tags) {
// If the tags match patterns configured in whitelist, construct a new remote repo.
if (config.isTagAllowed(tag.getName())) {
logger.info("Koji tag is on whitelist: {}", tag.getName());
buildAllowed = true;
break;
} else {
logger.debug("Tag: {} is not in the whitelist.", tag.getName());
}
}
}
}
if (buildAllowed) {
// or the artifact matches the one in the authoritative store, go ahead.
if (buildAuthority.isAuthorized(path, eventMetadata, artifactRef, build, session)) {
return consumer.execute(inStore, artifactRef, build, session);
}
} else {
logger.debug("No whitelisted tags found for: {}", build.getNvr());
}
}
logger.debug("No builds were found that matched the restrictions.");
return defValue;
});
} catch (KojiClientException e) {
throw new IndyWorkflowException("Cannot retrieve builds for: %s. Error: %s", e, artifactRef, e.getMessage());
}
}
use of org.commonjava.indy.IndyWorkflowException 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.IndyWorkflowException in project indy by Commonjava.
the class MavenMetadataGenerator method generateDirectoryContent.
@Override
public List<StoreResource> generateDirectoryContent(final ArtifactStore store, final String path, final List<StoreResource> existing, final EventMetadata eventMetadata) throws IndyWorkflowException {
final StoreResource mdResource = new StoreResource(LocationUtils.toLocation(store), Paths.get(path, MavenMetadataMerger.METADATA_NAME).toString());
if (existing.contains(mdResource)) {
return null;
}
int pathElementsCount = StringUtils.strip(path, "/").split("/").length;
// if there is a possibility we are listing an artifactId
if (pathElementsCount >= 2) {
// regardless, we will need this first level of listings. What we do with it will depend on the logic below...
final List<StoreResource> firstLevelFiles = fileManager.listRaw(store, path);
ArtifactPathInfo samplePomInfo = null;
for (final StoreResource topResource : firstLevelFiles) {
final String topPath = topResource.getPath();
if (topPath.endsWith(".pom")) {
samplePomInfo = ArtifactPathInfo.parse(topPath);
break;
}
}
// if this dir does not contain a pom check if a subdir contain a pom
if (samplePomInfo == null) {
List<String> firstLevelDirs = firstLevelFiles.stream().map((res) -> res.getPath()).filter((subpath) -> subpath.endsWith("/")).collect(Collectors.toList());
final Map<String, List<StoreResource>> secondLevelMap = fileManager.listRaw(store, firstLevelDirs);
nextTopResource: for (final String topPath : firstLevelDirs) {
final List<StoreResource> secondLevelListing = secondLevelMap.get(topPath);
for (final StoreResource fileResource : secondLevelListing) {
if (fileResource.getPath().endsWith(".pom")) {
if (samplePomInfo == null) {
samplePomInfo = ArtifactPathInfo.parse(fileResource.getPath());
break nextTopResource;
}
continue nextTopResource;
}
}
}
}
// We won't worry about this for now.
if (samplePomInfo != null) {
final List<StoreResource> result = new ArrayList<StoreResource>();
result.add(mdResource);
result.add(new StoreResource(LocationUtils.toLocation(store), Paths.get(path, MavenMetadataMerger.METADATA_MD5_NAME).toString()));
result.add(new StoreResource(LocationUtils.toLocation(store), Paths.get(path, MavenMetadataMerger.METADATA_SHA_NAME).toString()));
return result;
}
}
return null;
}
use of org.commonjava.indy.IndyWorkflowException in project indy by Commonjava.
the class MavenMetadataGenerator method generateGroupFileContent.
@Override
public Transfer generateGroupFileContent(final Group group, final List<ArtifactStore> members, final String path, final EventMetadata eventMetadata) throws IndyWorkflowException {
if (!canProcess(path)) {
return null;
}
final Transfer target = fileManager.getTransfer(group, path);
logger.debug("Working on metadata file: {} (already exists? {})", target, target != null && target.exists());
if (!target.exists()) {
String toMergePath = path;
if (!path.endsWith(MavenMetadataMerger.METADATA_NAME)) {
toMergePath = normalize(normalize(parentPath(toMergePath)), MavenMetadataMerger.METADATA_NAME);
}
final List<Transfer> sources = fileManager.retrieveAllRaw(members, toMergePath, new EventMetadata());
final byte[] merged = merger.merge(sources, group, toMergePath);
if (merged != null) {
OutputStream fos = null;
try {
fos = target.openOutputStream(TransferOperation.GENERATE, true, eventMetadata);
fos.write(merged);
} catch (final IOException e) {
throw new IndyWorkflowException("Failed to write merged metadata to: {}.\nError: {}", e, target, e.getMessage());
} finally {
closeQuietly(fos);
}
helper.writeMergeInfo(merged, sources, group, toMergePath);
}
}
if (target.exists()) {
return target;
}
return null;
}
use of org.commonjava.indy.IndyWorkflowException in project indy by Commonjava.
the class MavenMetadataGenerator method generateFileContent.
@Override
public Transfer generateFileContent(final ArtifactStore store, final String path, final EventMetadata eventMetadata) throws IndyWorkflowException {
// metadata merging is something else...don't handle it here.
if (StoreType.group == store.getKey().getType()) {
return null;
}
if (!canProcess(path)) {
return null;
}
boolean generated = false;
// TODO: Generation of plugin metadata files (groupId-level) is harder, and requires cracking open the jar file
// This is because that's the only place the plugin prefix can be reliably retrieved from.
// regardless, we will need this first level of listings. What we do with it will depend on the logic below...
final String parentPath = Paths.get(path).getParent().toString();
List<StoreResource> firstLevel;
try {
firstLevel = fileManager.listRaw(store, parentPath);
} catch (final IndyWorkflowException e) {
logger.error(String.format("SKIP: Failed to generate maven-metadata.xml from listing of directory contents for: %s under path: %s", store, parentPath), e);
return null;
}
//
// if ( firstLevel == null || firstLevel.isEmpty() )
// {
// logger.error( String.format( "SKIP: Listing is empty for: %s under path: %s", store, parentPath ) );
// return null;
// }
String toGenPath = path;
if (!path.endsWith(MavenMetadataMerger.METADATA_NAME)) {
toGenPath = normalize(normalize(parentPath(toGenPath)), MavenMetadataMerger.METADATA_NAME);
}
ArtifactPathInfo snapshotPomInfo = null;
if (parentPath.endsWith(SnapshotUtils.LOCAL_SNAPSHOT_VERSION_PART)) {
// If we're in a version directory, first-level listing should include a .pom file
for (final StoreResource resource : firstLevel) {
if (resource.getPath().endsWith(".pom")) {
snapshotPomInfo = ArtifactPathInfo.parse(resource.getPath());
break;
}
}
}
if (snapshotPomInfo != null) {
logger.info("Generating maven-metadata.xml for snapshots");
generated = writeSnapshotMetadata(snapshotPomInfo, firstLevel, store, toGenPath, eventMetadata);
} else {
logger.info("Generating maven-metadata.xml for releases");
generated = writeVersionMetadata(firstLevel, store, toGenPath, eventMetadata);
}
return generated ? fileManager.getTransfer(store, path) : null;
}
Aggregations