Search in sources :

Example 1 with JoinString

use of org.commonjava.atlas.maven.ident.util.JoinString in project indy by Commonjava.

the class GitManager method getStatus.

private Status getStatus() throws GitSubsystemException {
    Status status;
    try {
        status = git.status().call();
    } catch (NoWorkTreeException | GitAPIException e) {
        throw new GitSubsystemException("Failed to retrieve status of: %s. Reason: %s", e, rootDir, e.getMessage());
    }
    final Map<String, StageState> css = status.getConflictingStageState();
    if (!css.isEmpty()) {
        throw new GitSubsystemException("%s contains conflicts. Cannot auto-commit.\n  %s", rootDir, new JoinString("\n  ", css.entrySet()));
    }
    return status;
}
Also used : Status(org.eclipse.jgit.api.Status) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) JoinString(org.commonjava.atlas.maven.ident.util.JoinString) NoWorkTreeException(org.eclipse.jgit.errors.NoWorkTreeException) StageState(org.eclipse.jgit.lib.IndexDiff.StageState) JoinString(org.commonjava.atlas.maven.ident.util.JoinString)

Example 2 with JoinString

use of org.commonjava.atlas.maven.ident.util.JoinString in project indy by Commonjava.

the class DeprecatedStoreAdminHandler method getAll.

@ApiOperation("Retrieve the definitions of all artifact stores of a given type on the system")
@ApiResponses({ @ApiResponse(code = 200, response = StoreListingDTO.class, message = "The store definitions") })
@GET
@Produces(ApplicationContent.application_json)
public Response getAll(@ApiParam(allowableValues = "hosted,group,remote", required = true) @PathParam("type") final String type) {
    String altPath = Paths.get(MavenPackageTypeDescriptor.MAVEN_ADMIN_REST_BASE_PATH, type).toString();
    Consumer<Response.ResponseBuilder> modifier = (rb) -> responseHelper.markDeprecated(rb, altPath);
    final StoreType st = StoreType.get(type);
    Response response;
    try {
        final List<ArtifactStore> stores = adminController.getAllOfType(st);
        logger.info("Returning listing containing stores:\n\t{}", new JoinString("\n\t", stores));
        final StoreListingDTO<ArtifactStore> dto = new StoreListingDTO<>(stores);
        response = responseHelper.formatOkResponseWithJsonEntity(dto, modifier);
    } catch (final IndyWorkflowException e) {
        logger.error(e.getMessage(), e);
        response = responseHelper.formatResponse(e, modifier);
    }
    return response;
}
Also used : Produces(javax.ws.rs.Produces) LoggerFactory(org.slf4j.LoggerFactory) Path(javax.ws.rs.Path) SecurityContext(javax.ws.rs.core.SecurityContext) ApiParam(io.swagger.annotations.ApiParam) StoreListingDTO(org.commonjava.indy.model.core.dto.StoreListingDTO) ApiOperation(io.swagger.annotations.ApiOperation) Consumes(javax.ws.rs.Consumes) Response.noContent(javax.ws.rs.core.Response.noContent) Response.status(javax.ws.rs.core.Response.status) URI(java.net.URI) StringUtils.isEmpty(org.apache.commons.lang3.StringUtils.isEmpty) StoreKey(org.commonjava.indy.model.core.StoreKey) DELETE(javax.ws.rs.DELETE) Context(javax.ws.rs.core.Context) IndyObjectMapper(org.commonjava.indy.model.core.io.IndyObjectMapper) ResponseHelper(org.commonjava.indy.bind.jaxrs.util.ResponseHelper) ApiImplicitParam(io.swagger.annotations.ApiImplicitParam) CONFLICT(javax.ws.rs.core.Response.Status.CONFLICT) StoreType(org.commonjava.indy.model.core.StoreType) IndyResources(org.commonjava.indy.bind.jaxrs.IndyResources) Response.notModified(javax.ws.rs.core.Response.notModified) IOUtils(org.apache.commons.io.IOUtils) ApplicationContent(org.commonjava.indy.util.ApplicationContent) List(java.util.List) Response(javax.ws.rs.core.Response) Response.ok(javax.ws.rs.core.Response.ok) ApplicationScoped(javax.enterprise.context.ApplicationScoped) UriInfo(javax.ws.rs.core.UriInfo) ApiImplicitParams(io.swagger.annotations.ApiImplicitParams) HEAD(javax.ws.rs.HEAD) PathParam(javax.ws.rs.PathParam) REST(org.commonjava.indy.bind.jaxrs.util.REST) GET(javax.ws.rs.GET) ApplicationContent.application_json(org.commonjava.indy.util.ApplicationContent.application_json) JoinString(org.commonjava.atlas.maven.ident.util.JoinString) ApiResponses(io.swagger.annotations.ApiResponses) Inject(javax.inject.Inject) HttpServletRequest(javax.servlet.http.HttpServletRequest) MavenPackageTypeDescriptor(org.commonjava.indy.pkg.maven.model.MavenPackageTypeDescriptor) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) SecurityManager(org.commonjava.indy.bind.jaxrs.SecurityManager) Api(io.swagger.annotations.Api) Status(javax.ws.rs.core.Response.Status) Logger(org.slf4j.Logger) POST(javax.ws.rs.POST) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) METADATA_CHANGELOG(org.commonjava.indy.model.core.ArtifactStore.METADATA_CHANGELOG) IOException(java.io.IOException) Consumer(java.util.function.Consumer) Paths(java.nio.file.Paths) ApiResponse(io.swagger.annotations.ApiResponse) AdminController(org.commonjava.indy.core.ctl.AdminController) PUT(javax.ws.rs.PUT) InputStream(java.io.InputStream) StoreType(org.commonjava.indy.model.core.StoreType) Response(javax.ws.rs.core.Response) ApiResponse(io.swagger.annotations.ApiResponse) StoreListingDTO(org.commonjava.indy.model.core.dto.StoreListingDTO) JoinString(org.commonjava.atlas.maven.ident.util.JoinString) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) JoinString(org.commonjava.atlas.maven.ident.util.JoinString) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 3 with JoinString

use of org.commonjava.atlas.maven.ident.util.JoinString in project indy by Commonjava.

the class ImpliedRepositoryDetector method updateExistingGroups.

private boolean updateExistingGroups(final ImplicationsJob job) {
    final StoreKey key = job.store.getKey();
    boolean anyChanged = false;
    try {
        final Set<Group> groups = storeManager.query().getGroupsContaining(key);
        if (groups != null) {
            logger.debug("{} groups contain: {}\n  {}", groups.size(), key, new JoinString("\n  ", groups));
            final String message = String.format("Adding repositories implied by: %s\n\n  %s", key, StringUtils.join(job.implied, "\n  "));
            final ChangeSummary summary = new ChangeSummary(ChangeSummary.SYSTEM_USER, message);
            for (final Group g : groups) {
                if (config.isEnabledForGroup(g.getName())) {
                    Group group = g.copyOf();
                    boolean changed = false;
                    for (final ArtifactStore implied : job.implied) {
                        boolean groupChanged = group.addConstituent(implied);
                        changed = groupChanged || changed;
                        logger.debug("After attempting to add: {} to group: {}, changed status is: {}", implied, group, changed);
                    }
                    if (changed) {
                        storeManager.storeArtifactStore(group, summary, false, false, new EventMetadata().set(StoreDataManager.EVENT_ORIGIN, IMPLIED_REPOS_DETECTION).set(IMPLIED_REPOS, job.implied));
                    }
                    anyChanged = changed || anyChanged;
                }
            }
        }
    } catch (final IndyDataException e) {
        logger.error("Failed to lookup groups containing: " + key, e);
    }
    return anyChanged;
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) Group(org.commonjava.indy.model.core.Group) JoinString(org.commonjava.atlas.maven.ident.util.JoinString) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) JoinString(org.commonjava.atlas.maven.ident.util.JoinString) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) StoreKey(org.commonjava.indy.model.core.StoreKey) EventMetadata(org.commonjava.maven.galley.event.EventMetadata)

Example 4 with JoinString

use of org.commonjava.atlas.maven.ident.util.JoinString 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;
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) JoinString(org.commonjava.atlas.maven.ident.util.JoinString) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) ArrayList(java.util.ArrayList) StoreKey(org.commonjava.indy.model.core.StoreKey) ImpliedReposException(org.commonjava.indy.implrepo.ImpliedReposException) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 5 with JoinString

use of org.commonjava.atlas.maven.ident.util.JoinString in project indy by Commonjava.

the class ImpliedRepositoryDetector method addImpliedMetadata.

private boolean addImpliedMetadata(final ImplicationsJob job) {
    try {
        logger.debug("Adding implied-repo metadata to: {} and {}", job.store, new JoinString(", ", job.implied));
        metadataManager.addImpliedMetadata(job.store, job.implied);
        ChangeSummary summary = new ChangeSummary(ChangeSummary.SYSTEM_USER, "Update " + IMPLIED_STORES);
        storeManager.storeArtifactStore(job.store, summary, false, false, null);
        return true;
    } catch (final ImpliedReposException e) {
        logger.error("Failed to store list of implied stores in: " + job.store.getKey(), e);
    } catch (IndyDataException e) {
        logger.error("Failed to update ArtifactStore {}", job.store);
    }
    return false;
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) JoinString(org.commonjava.atlas.maven.ident.util.JoinString) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) ImpliedReposException(org.commonjava.indy.implrepo.ImpliedReposException)

Aggregations

JoinString (org.commonjava.atlas.maven.ident.util.JoinString)9 ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)6 StoreKey (org.commonjava.indy.model.core.StoreKey)5 IndyDataException (org.commonjava.indy.data.IndyDataException)4 ArrayList (java.util.ArrayList)3 ImpliedReposException (org.commonjava.indy.implrepo.ImpliedReposException)3 ApiOperation (io.swagger.annotations.ApiOperation)2 ApiResponse (io.swagger.annotations.ApiResponse)2 ApiResponses (io.swagger.annotations.ApiResponses)2 MalformedURLException (java.net.MalformedURLException)2 List (java.util.List)2 Inject (javax.inject.Inject)2 GET (javax.ws.rs.GET)2 Produces (javax.ws.rs.Produces)2 Response (javax.ws.rs.core.Response)2 ChangeSummary (org.commonjava.indy.audit.ChangeSummary)2 KeyedLocation (org.commonjava.indy.model.galley.KeyedLocation)2 Location (org.commonjava.maven.galley.model.Location)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 Api (io.swagger.annotations.Api)1