Search in sources :

Example 6 with ArtifactStore

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

the class ScheduleManager method rescheduleDisableTimeout.

public synchronized void rescheduleDisableTimeout(final StoreKey key) throws IndySchedulerException {
    if (!schedulerConfig.isEnabled()) {
        logger.debug("Scheduler disabled.");
        return;
    }
    ArtifactStore store = null;
    try {
        store = dataManager.getArtifactStore(key);
    } catch (final IndyDataException e) {
        logger.error(String.format("Failed to retrieve store for: %s. Reason: %s", key, e.getMessage()), e);
    }
    if (store == null) {
        return;
    }
    int timeout = store.getDisableTimeout();
    if (timeout == TIMEOUT_USE_DEFAULT) {
        // case TIMEOUT_USE_DEFAULT: will use default timeout configuration
        timeout = config.getStoreDisableTimeoutSeconds();
    }
    if (timeout > TIMEOUT_USE_DEFAULT && store.isDisabled()) {
        final StoreKey sk = store.getKey();
        logger.debug("Set/Reschedule disable timeout for store:{}", sk);
        scheduleForStore(sk, DISABLE_TIMEOUT, DISABLE_TIMEOUT, sk, timeout);
    }
// Will never consider the TIMEOUT_NEVER_DISABLE case here, will consider this in the calling object(StoreEnablementManager)
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) StoreKey(org.commonjava.indy.model.core.StoreKey)

Example 7 with ArtifactStore

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

the class StoreContentListener method onStoreUpdate.

public void onStoreUpdate(@Observes final ArtifactStorePreUpdateEvent event) {
    Logger logger = LoggerFactory.getLogger(getClass());
    logger.trace("Got store-update event: {}", event);
    // we're only interested in existing stores, since new stores cannot have indexed keys
    if (ArtifactStoreUpdateType.UPDATE == event.getType()) {
        for (ArtifactStore store : event) {
            removeAllSupercededMemberContent(store, event.getChangeMap());
        }
    }
}
Also used : ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) Logger(org.slf4j.Logger)

Example 8 with ArtifactStore

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

the class StoreContentListener method removeAllSupercededMemberContent.

// TODO: If we find points where a new HostedRepository is added, we should be using its comprehensive index to minimize the index damage to the group.
private void removeAllSupercededMemberContent(final ArtifactStore store, final Map<ArtifactStore, ArtifactStore> changeMap) {
    Logger logger = LoggerFactory.getLogger(getClass());
    StoreKey key = store.getKey();
    // we're only interested in groups, since only adjustments to group memberships can invalidate indexed content.
    if (StoreType.group == key.getType()) {
        List<StoreKey> newMembers = ((Group) store).getConstituents();
        logger.debug("New members of: {} are: {}", store, newMembers);
        Group group = (Group) changeMap.get(store);
        List<StoreKey> oldMembers = group.getConstituents();
        logger.debug("Old members of: {} are: {}", group, oldMembers);
        int commonSize = Math.min(newMembers.size(), oldMembers.size());
        int divergencePoint;
        // look in the members that overlap in new/old groups and see if there are changes that would
        // indicate member reordering. If so, it might lead previously suppressed results to be prioritized,
        // which would invalidate part of the content index for the group.
        boolean foundDivergence = false;
        for (divergencePoint = 0; divergencePoint < commonSize; divergencePoint++) {
            logger.debug("Checking for common member at index: {}", divergencePoint);
            if (!oldMembers.get(divergencePoint).equals(newMembers.get(divergencePoint))) {
                foundDivergence = true;
                break;
            }
        }
        //      that include the one we're affecting directly here...using clearIndexedPathFrom() to do this.
        if (!foundDivergence) {
            if (newMembers.size() < oldMembers.size()) {
                divergencePoint = commonSize;
            } else {
                divergencePoint = newMembers.size();
            }
        }
        logger.debug("group membership divergence point: {}", divergencePoint);
        Set<StoreKey> affectedMembers = new HashSet<>();
        boolean removeMergableOnly = divergencePoint >= oldMembers.size();
        // group content index entries for those.
        if (divergencePoint < oldMembers.size()) {
            for (int i = divergencePoint; i < oldMembers.size(); i++) {
                affectedMembers.add(oldMembers.get(i));
            }
        } else {
            // See [NOS-128]
            for (int i = divergencePoint - 1; i >= commonSize; i--) {
                affectedMembers.add(newMembers.get(i));
            }
        }
        logger.debug("Got members affected by membership divergence: {}", affectedMembers);
        if (!affectedMembers.isEmpty()) {
            Set<Group> groups = new HashSet<>();
            groups.add(group);
            try {
                groups.addAll(storeDataManager.query().packageType(group.getPackageType()).getGroupsAffectedBy(group.getKey()));
            } catch (IndyDataException e) {
                logger.error(String.format("Cannot retrieve groups affected by: %s. Reason: %s", group.getKey(), e.getMessage()), e);
            }
            logger.debug("Got affected groups: {}", groups);
            affectedMembers.parallelStream().forEach((memberKey) -> {
                logger.debug("Listing all {}paths in: {}", (removeMergableOnly ? "mergeable " : ""), memberKey);
                Set<String> paths = listPaths(memberKey, removeMergableOnly ? mergablePathStrings() : (p) -> true);
                logger.debug("Got mergable transfers from diverged portion of membership: {}", paths);
                clearPaths(paths, memberKey, groups, false);
            });
        }
    }
}
Also used : LoggerFactory(org.slf4j.LoggerFactory) SpecialPathInfo(org.commonjava.maven.galley.model.SpecialPathInfo) Group(org.commonjava.indy.model.core.Group) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) HashSet(java.util.HashSet) Transfer(org.commonjava.maven.galley.model.Transfer) ArtifactStoreEnablementEvent(org.commonjava.indy.change.event.ArtifactStoreEnablementEvent) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) Observes(javax.enterprise.event.Observes) Map(java.util.Map) StreamSupport(java.util.stream.StreamSupport) ArtifactStoreDeletePreEvent(org.commonjava.indy.change.event.ArtifactStoreDeletePreEvent) StoreKey(org.commonjava.indy.model.core.StoreKey) Instance(javax.enterprise.inject.Instance) ROOT(org.commonjava.maven.galley.util.PathUtils.ROOT) Logger(org.slf4j.Logger) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) StoreContentAction(org.commonjava.indy.content.StoreContentAction) Predicate(java.util.function.Predicate) StoreType(org.commonjava.indy.model.core.StoreType) Set(java.util.Set) SpecialPathManager(org.commonjava.maven.galley.spi.io.SpecialPathManager) IOException(java.io.IOException) List(java.util.List) Stream(java.util.stream.Stream) ArtifactStorePreUpdateEvent(org.commonjava.indy.change.event.ArtifactStorePreUpdateEvent) ApplicationScoped(javax.enterprise.context.ApplicationScoped) Collections(java.util.Collections) ArtifactStoreUpdateType(org.commonjava.indy.change.event.ArtifactStoreUpdateType) DirectContentAccess(org.commonjava.indy.content.DirectContentAccess) IndyDataException(org.commonjava.indy.data.IndyDataException) StoreDataManager(org.commonjava.indy.data.StoreDataManager) Group(org.commonjava.indy.model.core.Group) Logger(org.slf4j.Logger) StoreKey(org.commonjava.indy.model.core.StoreKey) IndyDataException(org.commonjava.indy.data.IndyDataException) HashSet(java.util.HashSet)

Example 9 with ArtifactStore

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

the class SetBackSettingsManagerTest method settingsForSingleRemoteRepository_GenerateDeleteAndProveNonExistent.

@Test
public void settingsForSingleRemoteRepository_GenerateDeleteAndProveNonExistent() throws Exception {
    final RemoteRepository remote = new RemoteRepository(MAVEN_PKG_KEY, "test", "http://foo.bar/");
    remote.setDescription("Test Repository");
    store(remote);
    final StoreKey key = remote.getKey();
    final List<String> lines = generateSettings(key);
    assertThat("No repository with id: " + remote.getName() + " found in settings.xml", lines.contains("<id>" + remote.getName() + "</id>"), equalTo(true));
    final ArtifactStore store = storeManager.getArtifactStore(key);
    manager.deleteStoreSettings(store);
    assertThat("Settings.xml for: " + key + " should have been deleted!", manager.getSetBackSettings(key), nullValue());
}
Also used : ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) StoreKey(org.commonjava.indy.model.core.StoreKey) Test(org.junit.Test)

Example 10 with ArtifactStore

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

the class AutoProxDataManagerDecorator method getGroup.

private Group getGroup(final StoreKey key, final StoreKey impliedBy) throws IndyDataException {
    logger.debug("DECORATED (getGroup: {})", key);
    Group g = (Group) dataManager.getArtifactStore(key);
    if (!catalog.isEnabled()) {
        logger.debug("AutoProx decorator disabled; returning: {}", g);
        return g;
    }
    logger.debug("AutoProx decorator active");
    if (g == null) {
        logger.debug("AutoProx: creating repository for: {}", key);
        if (!checkValidity(key)) {
            return null;
        }
        try {
            g = catalog.createGroup(key);
        } catch (final AutoProxRuleException e) {
            throw new IndyDataException("[AUTOPROX] Failed to create new group from factory matching: '%s'. Reason: %s", e, key, e.getMessage());
        }
        if (g != null) {
            logger.info("Validating group: {}", g);
            for (final StoreKey memberKey : new ArrayList<>(g.getConstituents())) {
                final ArtifactStore store = getArtifactStore(memberKey, impliedBy == null ? g.getKey() : impliedBy);
                if (store == null) {
                    g.removeConstituent(memberKey);
                }
            }
            if (g.getConstituents().isEmpty()) {
                return null;
            }
            final EventMetadata eventMetadata = new EventMetadata().set(StoreDataManager.EVENT_ORIGIN, AutoProxConstants.STORE_ORIGIN).set(AutoProxConstants.ORIGINATING_STORE, impliedBy == null ? g.getKey() : impliedBy);
            dataManager.storeArtifactStore(g, new ChangeSummary(ChangeSummary.SYSTEM_USER, "AUTOPROX: Creating group for: '" + key + "'"), false, true, eventMetadata);
        }
    }
    return g;
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) Group(org.commonjava.indy.model.core.Group) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) ArrayList(java.util.ArrayList) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) StoreKey(org.commonjava.indy.model.core.StoreKey) EventMetadata(org.commonjava.maven.galley.event.EventMetadata)

Aggregations

ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)168 IndyDataException (org.commonjava.indy.data.IndyDataException)90 StoreKey (org.commonjava.indy.model.core.StoreKey)83 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)54 Logger (org.slf4j.Logger)45 ArrayList (java.util.ArrayList)43 Group (org.commonjava.indy.model.core.Group)42 StoreType (org.commonjava.indy.model.core.StoreType)38 Transfer (org.commonjava.maven.galley.model.Transfer)38 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)33 IOException (java.io.IOException)29 HashSet (java.util.HashSet)29 List (java.util.List)28 Measure (org.commonjava.o11yphant.metrics.annotation.Measure)26 LoggerFactory (org.slf4j.LoggerFactory)25 StoreDataManager (org.commonjava.indy.data.StoreDataManager)24 Set (java.util.Set)23 Inject (javax.inject.Inject)22 HostedRepository (org.commonjava.indy.model.core.HostedRepository)21 RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)17