Search in sources :

Example 51 with ChangeSummary

use of org.commonjava.indy.audit.ChangeSummary in project indy by Commonjava.

the class GroupConsistencyListener method processChanged.

private void processChanged(final ArtifactStore store) {
    final StoreKey key = store.getKey();
    try {
        final Set<Group> groups = storeDataManager.query().getGroupsContaining(key);
        for (final Group group : groups) {
            logger.debug("Removing {} from membership of group: {}", key, group.getKey());
            Group g = group.copyOf();
            g.removeConstituent(key);
            storeDataManager.storeArtifactStore(g, new ChangeSummary(ChangeSummary.SYSTEM_USER, "Auto-update groups containing: " + key + " (to maintain consistency)"), false, false, new EventMetadata().set(StoreDataManager.EVENT_ORIGIN, GROUP_CONSISTENCY_ORIGIN));
        }
    } catch (final IndyDataException e) {
        logger.error(String.format("Failed to remove group constituent listings for: %s. Error: %s", key, e.getMessage()), e);
    }
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) Group(org.commonjava.indy.model.core.Group) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) StoreKey(org.commonjava.indy.model.core.StoreKey) EventMetadata(org.commonjava.maven.galley.event.EventMetadata)

Example 52 with ChangeSummary

use of org.commonjava.indy.audit.ChangeSummary in project indy by Commonjava.

the class AutoProxDataManagerDecorator method getHostedRepository.

private HostedRepository getHostedRepository(final StoreKey key, final StoreKey impliedBy) throws IndyDataException {
    HostedRepository repo = (HostedRepository) dataManager.getArtifactStore(key);
    if (!catalog.isEnabled()) {
        logger.debug("AutoProx decorator disabled; returning: {}", repo);
        return repo;
    }
    logger.debug("AutoProx decorator active");
    if (repo == null) {
        logger.info("AutoProx: creating repository for: {}", key);
        try {
            repo = catalog.createHostedRepository(key);
        } catch (final AutoProxRuleException e) {
            throw new IndyDataException("[AUTOPROX] Failed to create new hosted repository from factory matching: '%s'. Reason: %s", e, key, e.getMessage());
        }
        if (repo != null) {
            final ChangeSummary changeSummary = new ChangeSummary(ChangeSummary.SYSTEM_USER, "AUTOPROX: Creating hosted repository for: '" + key + "'");
            final EventMetadata eventMetadata = new EventMetadata().set(StoreDataManager.EVENT_ORIGIN, AutoProxConstants.STORE_ORIGIN).set(AutoProxConstants.ORIGINATING_STORE, impliedBy == null ? repo.getKey() : impliedBy);
            dataManager.storeArtifactStore(repo, changeSummary, false, true, eventMetadata);
        }
    }
    return repo;
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) HostedRepository(org.commonjava.indy.model.core.HostedRepository) EventMetadata(org.commonjava.maven.galley.event.EventMetadata)

Example 53 with ChangeSummary

use of org.commonjava.indy.audit.ChangeSummary in project indy by Commonjava.

the class LegacyDataMigrationActionTest method dataFileMigrationForExistingHostedRepoJSON.

@Test
public void dataFileMigrationForExistingHostedRepoJSON() throws Exception {
    final DataFile dir = dfm.getDataFile(INDY_STORE, hosted.singularEndpointName());
    dir.mkdirs();
    final DataFile old = dfm.getDataFile(INDY_STORE, hosted.singularEndpointName(), "test.json");
    final DataFile migrated = dfm.getDataFile(INDY_STORE, MAVEN_PKG_KEY, hosted.singularEndpointName(), "test.json");
    String srcJson = "{\"name\": \"test\", \"type\" : \"hosted\", \"packageType\": \"maven\", \"key\": \"maven:hosted:test\"}";
    old.writeString(srcJson, new ChangeSummary(ChangeSummary.SYSTEM_USER, "test repo creation"));
    migrated.writeString(srcJson, new ChangeSummary(ChangeSummary.SYSTEM_USER, "test repo creation"));
    final boolean result = action.migrate();
    assertThat(result, equalTo(false));
}
Also used : DataFile(org.commonjava.indy.subsys.datafile.DataFile) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) Test(org.junit.Test)

Example 54 with ChangeSummary

use of org.commonjava.indy.audit.ChangeSummary in project indy by Commonjava.

the class ConcurrencyTest method deadlockOnListAllDuringDelete.

@BMRules(rules = { @BMRule(name = "init rendezvous", targetClass = "MemoryStoreDataManager", targetMethod = "<init>", targetLocation = "ENTRY", action = "createRendezvous($0, 2)"), @BMRule(name = "delete call", targetClass = "MemoryStoreDataManager", targetMethod = "deleteArtifactStore", targetLocation = "EXIT", action = "rendezvous($0); debug(Thread.currentThread().getName() + \": deletion thread proceeding.\")"), @BMRule(name = "streamArtifactStores call", targetClass = "MemoryStoreDataManager", targetMethod = "streamArtifactStores", targetLocation = "ENTRY", action = "rendezvous($0); debug(Thread.currentThread().getName() + \": streamArtifactStores() thread proceeding.\")") })
@Test
public void deadlockOnListAllDuringDelete() throws IndyDataException, InterruptedException, ExecutionException {
    ExecutorService executor = Executors.newFixedThreadPool(2);
    ExecutorCompletionService<String> completionService = new ExecutorCompletionService<>(executor);
    RemoteRepository repo = new RemoteRepository(MAVEN_PKG_KEY, "central", "http://repo.maven.apache.org/maven2");
    TestDeletingEventDispatcher dispatcher = new TestDeletingEventDispatcher(completionService);
    MemoryStoreDataManager dataManager = new MemoryStoreDataManager(dispatcher, new DefaultIndyConfiguration());
    dispatcher.setDataManager(dataManager);
    ChangeSummary summary = new ChangeSummary(ChangeSummary.SYSTEM_USER, "Test init");
    dataManager.storeArtifactStore(repo, summary, false, false, new EventMetadata());
    dataManager.deleteArtifactStore(repo.getKey(), new ChangeSummary(ChangeSummary.SYSTEM_USER, "Test deletion"), new EventMetadata());
    Future<String> future = completionService.take();
    assertThat(future.get(), nullValue());
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) ExecutorCompletionService(java.util.concurrent.ExecutorCompletionService) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) DefaultIndyConfiguration(org.commonjava.indy.conf.DefaultIndyConfiguration) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) Test(org.junit.Test) BMRules(org.jboss.byteman.contrib.bmunit.BMRules)

Example 55 with ChangeSummary

use of org.commonjava.indy.audit.ChangeSummary in project indy by Commonjava.

the class ReplicationController method replicate.

public Set<StoreKey> replicate(final ReplicationDTO dto, final String user) throws IndyWorkflowException {
    final ReplicationRepositoryCreator creator = createRepoCreator();
    if (creator == null) {
        throw new IndyWorkflowException(500, "Cannot replicate; ReplicationRepositoryCreator could not be instantiated.");
    }
    try {
        dto.validate();
    } catch (final IndyException e) {
        throw new IndyWorkflowException("Invalid replication request DTO: %s", e, e.getMessage());
    }
    List<? extends ArtifactStore> remoteStores = null;
    List<EndpointView> remoteEndpoints = null;
    final boolean overwrite = dto.isOverwrite();
    final Set<StoreKey> replicated = new HashSet<StoreKey>();
    for (final ReplicationAction action : dto) {
        if (action == null) {
            continue;
        }
        logger.info("Processing replication action:\n\n  {}\n\nin DTO: {}\n\n", action, dto);
        final String include = action.getInclude();
        final String exclude = action.getExclude();
        try {
            if (action.getType() == ActionType.PROXY) {
                if (remoteEndpoints == null) {
                    remoteEndpoints = getEndpoints(dto);
                }
                for (final EndpointView view : remoteEndpoints) {
                    final String key = "remote-" + view.getType() + "_" + view.getName();
                    if ((include == null || key.matches(include)) && (exclude == null || !key.matches(exclude))) {
                        final StoreKey sk = new StoreKey(StoreType.remote, key);
                        if (overwrite || !data.hasArtifactStore(sk)) {
                            RemoteRepository repo = creator.createRemoteRepository(key, view);
                            repo.setMetadata(ArtifactStore.METADATA_ORIGIN, REPLICATION_ORIGIN);
                            setProxyAttributes(repo, action);
                            data.storeArtifactStore(repo, new ChangeSummary(user, "REPLICATION: Proxying remote indy repository: " + view.getResourceUri()), true, true, new EventMetadata().set(StoreDataManager.EVENT_ORIGIN, REPLICATION_ORIGIN));
                            replicated.add(repo.getKey());
                        }
                    }
                }
            } else if (action.getType() == ActionType.MIRROR) {
                if (remoteStores == null) {
                    remoteStores = getRemoteStores(dto);
                }
                for (final ArtifactStore store : remoteStores) {
                    final String key = store.getKey().toString();
                    if ((include == null || key.matches(include)) && (exclude == null || !key.matches(exclude))) {
                        if (overwrite || !data.hasArtifactStore(store.getKey())) {
                            if (store instanceof RemoteRepository) {
                                setProxyAttributes(((RemoteRepository) store), action);
                            }
                            data.storeArtifactStore(store, new ChangeSummary(user, "REPLICATION: Mirroring remote indy store: " + store.getKey()), true, true, new EventMetadata().set(StoreDataManager.EVENT_ORIGIN, REPLICATION_ORIGIN));
                            replicated.add(store.getKey());
                        }
                    }
                }
            }
        } catch (final IndyDataException e) {
            logger.error(e.getMessage(), e);
            throw new IndyWorkflowException(e.getMessage(), e);
        }
    }
    return replicated;
}
Also used : EndpointView(org.commonjava.indy.model.core.dto.EndpointView) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) StoreKey(org.commonjava.indy.model.core.StoreKey) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) IndyDataException(org.commonjava.indy.data.IndyDataException) IndyException(org.commonjava.indy.IndyException) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) ReplicationAction(org.commonjava.indy.model.core.dto.ReplicationAction) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) HashSet(java.util.HashSet)

Aggregations

ChangeSummary (org.commonjava.indy.audit.ChangeSummary)68 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)37 Test (org.junit.Test)29 IndyDataException (org.commonjava.indy.data.IndyDataException)24 DataFile (org.commonjava.indy.subsys.datafile.DataFile)21 RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)17 StoreKey (org.commonjava.indy.model.core.StoreKey)14 IOException (java.io.IOException)11 HostedRepository (org.commonjava.indy.model.core.HostedRepository)11 Group (org.commonjava.indy.model.core.Group)10 File (java.io.File)8 ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)8 PathsPromoteRequest (org.commonjava.indy.promote.model.PathsPromoteRequest)8 Transfer (org.commonjava.maven.galley.model.Transfer)8 Logger (org.slf4j.Logger)8 ByteArrayInputStream (java.io.ByteArrayInputStream)7 PathsPromoteResult (org.commonjava.indy.promote.model.PathsPromoteResult)7 ArrayList (java.util.ArrayList)6 IndyLifecycleException (org.commonjava.indy.action.IndyLifecycleException)5 BMRules (org.jboss.byteman.contrib.bmunit.BMRules)5