Search in sources :

Example 61 with Group

use of org.commonjava.indy.model.core.Group in project indy by Commonjava.

the class MaintenanceHandler method affectedBy.

@ApiOperation("Get groups affected by specified repo.")
@ApiResponse(code = 200, message = "Complete.")
@Produces("application/json")
@Path("/store/affected/{key}")
@GET
public Response affectedBy(@ApiParam("The store key") @PathParam("key") final String key) {
    Response response;
    try {
        Set<StoreKey> storeKeys = new HashSet<>();
        storeKeys.add(StoreKey.fromString(key));
        Set<Group> groups = storeDataManager.affectedBy(storeKeys);
        response = Response.ok(mapper.writeValueAsString(groups)).build();
    } catch (final Exception e) {
        logger.error(String.format("Failed to export: %s. Reason: %s", key, e.getMessage()), e);
        response = responseHelper.formatResponse(e);
    }
    return response;
}
Also used : Response(javax.ws.rs.core.Response) ApiResponse(io.swagger.annotations.ApiResponse) Group(org.commonjava.indy.model.core.Group) StoreKey(org.commonjava.indy.model.core.StoreKey) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) IOException(java.io.IOException) HashSet(java.util.HashSet) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponse(io.swagger.annotations.ApiResponse)

Example 62 with Group

use of org.commonjava.indy.model.core.Group in project indy by Commonjava.

the class GroupDataManagerTCK method createSameGroupTwiceAndRetrieveOne.

@Test
public void createSameGroupTwiceAndRetrieveOne() throws Exception {
    final StoreDataManager manager = getFixtureProvider().getDataManager();
    final Group grp = new Group("test");
    store(grp, grp);
    final List<Group> result = manager.query().getAllGroups(MAVEN_PKG_KEY);
    assertThat(result, notNullValue());
    assertThat(result.size(), equalTo(1));
}
Also used : Group(org.commonjava.indy.model.core.Group) StoreDataManager(org.commonjava.indy.data.StoreDataManager) Test(org.junit.Test)

Example 63 with Group

use of org.commonjava.indy.model.core.Group in project indy by Commonjava.

the class GroupDataManagerTCK method createTwoGroupsAndAffectedByForOneLevel.

@Test
public void createTwoGroupsAndAffectedByForOneLevel() throws Exception {
    final StoreDataManager manager = getFixtureProvider().getDataManager();
    final StoreKey central = new StoreKey(remote, "central");
    final StoreKey repo2 = new StoreKey(remote, "repo2");
    Group g1 = new Group("g1", central);
    Group g2 = new Group("g2", repo2);
    store(g1, g2);
    List<StoreKey> keys = asList(central, repo2);
    Set<StoreKey> gKeys = manager.query().getGroupsAffectedBy(keys).stream().map(Group::getKey).collect(Collectors.toSet());
    assertThat(gKeys.contains(g1.getKey()), equalTo(Boolean.TRUE));
    assertThat(gKeys.contains(g2.getKey()), equalTo(Boolean.TRUE));
}
Also used : Group(org.commonjava.indy.model.core.Group) StoreDataManager(org.commonjava.indy.data.StoreDataManager) StoreKey(org.commonjava.indy.model.core.StoreKey) Test(org.junit.Test)

Example 64 with Group

use of org.commonjava.indy.model.core.Group in project indy by Commonjava.

the class GroupDataManagerTCK method createTwoGroupsAndRetrieveBoth.

@Test
public void createTwoGroupsAndRetrieveBoth() throws Exception {
    final StoreDataManager manager = getFixtureProvider().getDataManager();
    final Group grp = new Group("test");
    final Group grp2 = new Group("test2");
    store(grp, grp2);
    final List<Group> result = manager.query().getAllGroups(MAVEN_PKG_KEY);
    assertThat(result, notNullValue());
    assertThat(result.size(), equalTo(2));
    Collections.sort(result, new Comparator<Group>() {

        @Override
        public int compare(final Group g1, final Group g2) {
            return g1.getName().compareTo(g2.getName());
        }
    });
    Group g = result.get(0);
    assertThat(g.getName(), equalTo(grp.getName()));
    g = result.get(1);
    assertThat(g.getName(), equalTo(grp2.getName()));
}
Also used : Group(org.commonjava.indy.model.core.Group) StoreDataManager(org.commonjava.indy.data.StoreDataManager) Test(org.junit.Test)

Example 65 with Group

use of org.commonjava.indy.model.core.Group 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)

Aggregations

Group (org.commonjava.indy.model.core.Group)211 Test (org.junit.Test)111 HostedRepository (org.commonjava.indy.model.core.HostedRepository)89 RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)82 StoreKey (org.commonjava.indy.model.core.StoreKey)76 ByteArrayInputStream (java.io.ByteArrayInputStream)67 InputStream (java.io.InputStream)62 IndyDataException (org.commonjava.indy.data.IndyDataException)44 AbstractContentManagementTest (org.commonjava.indy.ftest.core.AbstractContentManagementTest)42 ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)42 Transfer (org.commonjava.maven.galley.model.Transfer)31 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)30 Logger (org.slf4j.Logger)30 Before (org.junit.Before)29 StoreDataManager (org.commonjava.indy.data.StoreDataManager)27 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)27 HashSet (java.util.HashSet)26 ArrayList (java.util.ArrayList)25 List (java.util.List)22 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)22