indy-repository-manager/src/main/java/org/jboss/pnc/indyrepositorymanager/IndyRepositorySession.java
public void promoteToBuildContentSet(List<Artifact> uploads) throws RepositoryManagerException {
        IndyPromoteClientModule promoter;
        try {
            promoter = serviceAccountIndy.module(IndyPromoteClientModule.class);
        } catch (IndyClientException e) {
            throw new RepositoryManagerException("Failed to retrieve Indy promote client module. Reason: %s", e, e.getMessage());
        }

        StoreKey buildRepoKey = new StoreKey(packageType, StoreType.hosted, buildContentId);
        PromoteRequest<?> request = null;
        try {
            if (isTempBuild) {
                request = new GroupPromoteRequest(buildRepoKey, buildPromotionTarget);
                GroupPromoteRequest gpReq = (GroupPromoteRequest) request;
                GroupPromoteResult result = promoter.promoteToGroup(gpReq);
                if (!result.succeeded()) {
                    String reason = result.getError();
                    if (reason == null) {
                        ValidationResult validations = result.getValidations();
                        if (validations != null) {
                            StringBuilder sb = new StringBuilder();
                            sb.append("One or more validation rules failed in rule-set ").append(validations.getRuleSet()).append(":\n");

                            validations.getValidatorErrors().forEach((rule, error) -> {
                                sb.append("- ").append(rule).append(":\n").append(error).append("\n\n");
                            });

                            reason = sb.toString();
                        }
                    }

                    throw new RepositoryManagerException("Failed to promote: %s to group: %s. Reason given was: %s",
                            request.getSource(), gpReq.getTargetGroup(), reason);
                }
            } else {
                StoreKey buildTarget = new StoreKey(packageType, StoreType.hosted, buildPromotionTarget);
                Set<String> paths = new HashSet<>();
                for (Artifact a : uploads) {
                    paths.add(a.getDeployPath());
                    paths.add(a.getDeployPath() + ".md5");
                    paths.add(a.getDeployPath() + ".sha1");
                }
                request = new PathsPromoteRequest(buildRepoKey, buildTarget, paths);
                PathsPromoteRequest ppReq = (PathsPromoteRequest) request;
                // TODO request.setPurgeSource(true);

                PathsPromoteResult result = promoter.promoteByPath(ppReq);
                if (result.getError() == null) {
                    HostedRepository buildRepo = serviceAccountIndy.stores().load(buildRepoKey, HostedRepository.class);
                    buildRepo.setReadonly(true);
                    try {
                        serviceAccountIndy.stores().update(buildRepo,
                                "Setting readonly after successful build and promotion.");
                    } catch (IndyClientException ex) {
                        logger.error("Failed to set readonly flag on repo: %s. Reason given was: %s."
                                + " But the promotion to consolidated repo %s succeeded.", ex, buildRepoKey,
                                ex.getMessage(), buildPromotionTarget);
                    }
                } else {
                    String reason = result.getError();
                    if (reason == null) {
                        ValidationResult validations = result.getValidations();
                        if (validations != null) {
                            StringBuilder sb = new StringBuilder();
                            sb.append("One or more validation rules failed in rule-set ").append(validations.getRuleSet()).append(":\n");

                            validations.getValidatorErrors().forEach((rule, error) -> {
                                sb.append("- ").append(rule).append(":\n").append(error).append("\n\n");
                            });

                            reason = sb.toString();
                        }
                    }

                    throw new RepositoryManagerException("Failed to promote files from %s to target %s. Reason given was: %s",
                            request.getSource(), ppReq.getTarget(), reason);
                }
            }
        } catch (IndyClientException e) {
            throw new RepositoryManagerException("Failed to promote: %s. Reason: %s", e, request, e.getMessage());
        }
    }
public void promoteToBuildContentSet(List<Artifact> uploads) throws RepositoryManagerException {
        IndyPromoteClientModule promoter;
        try {
            promoter = serviceAccountIndy.module(IndyPromoteClientModule.class);
        } catch (IndyClientException e) {
            throw new RepositoryManagerException("Failed to retrieve Indy promote client module. Reason: %s", e, e.getMessage());
        }

        StoreKey buildRepoKey = new StoreKey(packageType, StoreType.hosted, buildContentId);
        PromoteRequest<?> request = null;
        try {
            if (isTempBuild) {
                request = new GroupPromoteRequest(buildRepoKey, buildPromotionTarget);
                GroupPromoteRequest gpReq = (GroupPromoteRequest) request;
                GroupPromoteResult result = promoter.promoteToGroup(gpReq);
                if (!result.succeeded()) {
                    String reason = result.getError();
                    if (reason == null) {
                        ValidationResult validations = result.getValidations();
                        if (validations != null) {
                            StringBuilder sb = new StringBuilder();
                            sb.append("One or more validation rules failed in rule-set ").append(validations.getRuleSet()).append(":\n");

                            validations.getValidatorErrors().forEach((rule, error) -> {
                                sb.append("- ").append(rule).append(":\n").append(error).append("\n\n");
                            });

                            reason = sb.toString();
                        }
                    }

                    throw new RepositoryManagerException("Failed to promote: %s to group: %s. Reason given was: %s",
                            request.getSource(), gpReq.getTargetGroup(), reason);
                }
            } else {
                StoreKey buildTarget = new StoreKey(packageType, StoreType.hosted, buildPromotionTarget);
                Set<String> paths = new HashSet<>();
                for (Artifact a : uploads) {
                    paths.add(a.getDeployPath());
                    paths.add(a.getDeployPath() + ".md5");
                    paths.add(a.getDeployPath() + ".sha1");
                }
                request = new PathsPromoteRequest(buildRepoKey, buildTarget, paths);
                PathsPromoteRequest ppReq = (PathsPromoteRequest) request;
                // TODO request.setPurgeSource(true);

                PathsPromoteResult result = promoter.promoteByPath(ppReq);
                if (result.getError() == null) {
                    HostedRepository buildRepo = serviceAccountIndy.stores().load(buildRepoKey, HostedRepository.class);
                    buildRepo.setReadonly(true);
                    try {
                        serviceAccountIndy.stores().update(buildRepo,
                                "Setting readonly after successful build and promotion.");
                    } catch (IndyClientException ex) {
                        logger.error("Failed to set readonly flag on repo: %s. Reason given was: %s."
                                + " But the promotion to consolidated repo %s succeeded.", ex, buildRepoKey,
                                ex.getMessage(), buildPromotionTarget);
                    }
                } else {
                    String reason = result.getError();
                    if (reason == null) {
                        ValidationResult validations = result.getValidations();
                        if (validations != null) {
                            StringBuilder sb = new StringBuilder();
                            sb.append("One or more validation rules failed in rule-set ").append(validations.getRuleSet()).append(":\n");

                            validations.getValidatorErrors().forEach((rule, error) -> {
                                sb.append("- ").append(rule).append(":\n").append(error).append("\n\n");
                            });

                            reason = sb.toString();
                        }
                    }

                    throw new RepositoryManagerException("Failed to promote files from %s to target %s. Reason given was: %s",
                            request.getSource(), ppReq.getTarget(), reason);
                }
            }
        } catch (IndyClientException e) {
            throw new RepositoryManagerException("Failed to promote: %s. Reason: %s", e, request, e.getMessage());
        }
    }
public void promoteToBuildContentSet ( List < Artifact > uploads ) throws RepositoryManagerException { IndyPromoteClientModule promoter ; try { promoter = serviceAccountIndy . module ( IndyPromoteClientModule . class ) ; } catch ( IndyClientException e ) { throw new RepositoryManagerException ( "Failed to retrieve Indy promote client module. Reason: %s" , e , e . getMessage ( ) ) ; } StoreKey buildRepoKey = new StoreKey ( packageType , StoreType . hosted , buildContentId ) ; PromoteRequest < ? > request = null ; try { if ( isTempBuild ) { request = new GroupPromoteRequest ( buildRepoKey , buildPromotionTarget ) ; GroupPromoteRequest gpReq = ( GroupPromoteRequest ) request ; GroupPromoteResult result = promoter . promoteToGroup ( gpReq ) ; if ( ! result . succeeded ( ) ) { String reason = result . getError ( ) ; if ( reason == null ) { ValidationResult validations = result . getValidations ( ) ; if ( validations != null ) { StringBuilder sb = new StringBuilder ( ) ; sb . append ( "One or more validation rules failed in rule-set " ) . append ( validations . getRuleSet ( ) ) . append ( ":\n" ) ; validations . getValidatorErrors ( ) . forEach ( ( rule , error ) -> { sb . append ( "- " ) . append ( rule ) . append ( ":\n" ) . append ( error ) . append ( "\n\n" ) ; } ) ; reason = sb . toString ( ) ; } } throw new RepositoryManagerException ( "Failed to promote: %s to group: %s. Reason given was: %s" , request . getSource ( ) , gpReq . getTargetGroup ( ) , reason ) ; } } else { StoreKey buildTarget = new StoreKey ( packageType , StoreType . hosted , buildPromotionTarget ) ; Set < String > paths = new HashSet <> ( ) ; for ( Artifact a : uploads ) { paths . add ( a . getDeployPath ( ) ) ; paths . add ( a . getDeployPath ( ) + ".md5" ) ; paths . add ( a . getDeployPath ( ) + ".sha1" ) ; } request = new PathsPromoteRequest ( buildRepoKey , buildTarget , paths ) ; PathsPromoteRequest ppReq = ( PathsPromoteRequest ) request ; // TODO request.setPurgeSource(true); PathsPromoteResult result = promoter . promoteByPath ( ppReq ) ; if ( result . getError ( ) == null ) { HostedRepository buildRepo = serviceAccountIndy . stores ( ) . load ( buildRepoKey , HostedRepository . class ) ; buildRepo . setReadonly ( true ) ; try { serviceAccountIndy . stores ( ) . update ( buildRepo , "Setting readonly after successful build and promotion." ) ; } catch ( IndyClientException ex ) { logger . error ( "Failed to set readonly flag on repo: %s. Reason given was: %s." + " But the promotion to consolidated repo %s succeeded." , ex , buildRepoKey , ex . getMessage ( ) , buildPromotionTarget ) ; } } else { String reason = result . getError ( ) ; if ( reason == null ) { ValidationResult validations = result . getValidations ( ) ; if ( validations != null ) { StringBuilder sb = new StringBuilder ( ) ; sb . append ( "One or more validation rules failed in rule-set " ) . append ( validations . getRuleSet ( ) ) . append ( ":\n" ) ; validations . getValidatorErrors ( ) . forEach ( ( rule , error ) -> { sb . append ( "- " ) . append ( rule ) . append ( ":\n" ) . append ( error ) . append ( "\n\n" ) ; } ) ; reason = sb . toString ( ) ; } } throw new RepositoryManagerException ( "Failed to promote files from %s to target %s. Reason given was: %s" , request . getSource ( ) , ppReq . getTarget ( ) , reason ) ; } } } catch ( IndyClientException e ) { throw new RepositoryManagerException ( "Failed to promote: %s. Reason: %s" , e , request , e . getMessage ( ) ) ; } }
Promote the build output to the consolidated build repo (using path promotion, where the build
repo contents are added to the repo's contents) and marks the build output as readonly.

@param uploads artifacts to be promoted
Promote the build output to the consolidated build repo ( using path promotion where the build repo contents are added to the repo s contents ) and marks the build output as readonly .