Search in sources :

Example 11 with EventMetadata

use of org.commonjava.maven.galley.event.EventMetadata in project indy by Commonjava.

the class StoreEnablementManager method onDisableTimeout.

public void onDisableTimeout(@Observes SchedulerEvent evt) {
    Logger logger = LoggerFactory.getLogger(getClass());
    logger.debug("Checking for store-reenable event in: {} (trigger? {} Disable-Timeout? {})", evt, evt instanceof SchedulerTriggerEvent, DISABLE_TIMEOUT.equals(evt.getJobType()));
    if ((evt instanceof SchedulerTriggerEvent) && DISABLE_TIMEOUT.equals(evt.getJobType())) {
        String keystr = evt.getPayload();
        StoreKey key = null;
        try {
            key = objectMapper.readValue(keystr, StoreKey.class);
        } catch (IOException e) {
            logger.warn("Failed to read StoreKey from JSON string: '{}' in event payload.", keystr);
        }
        logger.debug("Read key: {} from JSON string: '{}' in event payload.", key, keystr);
        if (key != null) {
            try {
                ArtifactStore store = storeDataManager.getArtifactStore(key);
                if (store.isDisabled()) {
                    store.setDisabled(false);
                    storeDataManager.storeArtifactStore(store, new ChangeSummary(ChangeSummary.SYSTEM_USER, "Re-enabling " + key), false, true, new EventMetadata());
                    cancelReEnablementTimeout(key);
                }
            } catch (IndyDataException e) {
                logger.error(String.format("Failed to re-enable %s", key), e);
            } catch (IndySchedulerException e) {
                logger.error(String.format("Failed to delete re-enablement job for %s.", key), e);
            }
        }
    }
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) SchedulerTriggerEvent(org.commonjava.indy.core.expire.SchedulerTriggerEvent) IOException(java.io.IOException) Logger(org.slf4j.Logger) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) StoreKey(org.commonjava.indy.model.core.StoreKey) IndySchedulerException(org.commonjava.indy.core.expire.IndySchedulerException) EventMetadata(org.commonjava.maven.galley.event.EventMetadata)

Example 12 with EventMetadata

use of org.commonjava.maven.galley.event.EventMetadata in project indy by Commonjava.

the class AdminController method store.

public boolean store(final ArtifactStore store, final String user, final boolean skipExisting) throws IndyWorkflowException {
    try {
        String changelog = store.getMetadata(ArtifactStore.METADATA_CHANGELOG);
        if (changelog == null) {
            changelog = "Changelog not provided";
        }
        final ChangeSummary summary = new ChangeSummary(user, changelog);
        logger.info("Persisting artifact store: {} using: {}", store, storeManager);
        return storeManager.storeArtifactStore(store, summary, skipExisting, true, new EventMetadata());
    } catch (final IndyDataException e) {
        throw new IndyWorkflowException(ApplicationStatus.SERVER_ERROR.code(), "Failed to store: {}. Reason: {}", e, store.getKey(), e.getMessage());
    }
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) EventMetadata(org.commonjava.maven.galley.event.EventMetadata)

Example 13 with EventMetadata

use of org.commonjava.maven.galley.event.EventMetadata in project indy by Commonjava.

the class StoreDataSetupAction method migrate.

@Override
public boolean migrate() throws IndyLifecycleException {
    final ChangeSummary summary = new ChangeSummary(ChangeSummary.SYSTEM_USER, "Initializing default data.");
    boolean changed = false;
    try {
        logger.info("Verfiying that Indy basic stores are installed...");
        storeManager.install();
        if (!storeManager.query().packageType(MAVEN_PKG_KEY).storeType(RemoteRepository.class).containsByName("central")) {
            final RemoteRepository central = new RemoteRepository(MAVEN_PKG_KEY, "central", "http://repo.maven.apache.org/maven2/");
            central.setCacheTimeoutSeconds(86400);
            storeManager.storeArtifactStore(central, summary, true, true, new EventMetadata().set(StoreDataManager.EVENT_ORIGIN, DEFAULT_SETUP));
            changed = true;
        }
        if (!storeManager.query().packageType(MAVEN_PKG_KEY).storeType(HostedRepository.class).containsByName("local-deployments")) {
            final HostedRepository local = new HostedRepository(MAVEN_PKG_KEY, "local-deployments");
            local.setAllowReleases(true);
            local.setAllowSnapshots(true);
            local.setSnapshotTimeoutSeconds(86400);
            storeManager.storeArtifactStore(local, summary, true, true, new EventMetadata().set(StoreDataManager.EVENT_ORIGIN, DEFAULT_SETUP));
            changed = true;
        }
        if (!storeManager.query().packageType(MAVEN_PKG_KEY).storeType(Group.class).containsByName("public")) {
            final Group pub = new Group(MAVEN_PKG_KEY, "public");
            pub.addConstituent(new StoreKey(MAVEN_PKG_KEY, StoreType.remote, "central"));
            pub.addConstituent(new StoreKey(MAVEN_PKG_KEY, StoreType.hosted, "local-deployments"));
            storeManager.storeArtifactStore(pub, summary, true, true, new EventMetadata().set(StoreDataManager.EVENT_ORIGIN, DEFAULT_SETUP));
            changed = true;
        }
    } catch (final IndyDataException e) {
        throw new RuntimeException("Failed to boot indy components: " + e.getMessage(), e);
    }
    return changed;
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) Group(org.commonjava.indy.model.core.Group) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) StoreKey(org.commonjava.indy.model.core.StoreKey) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) HostedRepository(org.commonjava.indy.model.core.HostedRepository)

Example 14 with EventMetadata

use of org.commonjava.maven.galley.event.EventMetadata 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().packageType(MAVEN_PKG_KEY).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) {
                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.maven.atlas.ident.util.JoinString) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) JoinString(org.commonjava.maven.atlas.ident.util.JoinString) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) StoreKey(org.commonjava.indy.model.core.StoreKey) EventMetadata(org.commonjava.maven.galley.event.EventMetadata)

Example 15 with EventMetadata

use of org.commonjava.maven.galley.event.EventMetadata in project indy by Commonjava.

the class ImpliedReposOriginMigrationAction method migrate.

@Override
public boolean migrate() throws IndyLifecycleException {
    List<RemoteRepository> remoteRepositories;
    try {
        remoteRepositories = storeDataManager.query().getAllRemoteRepositories();
    } catch (IndyDataException e) {
        throw new IndyLifecycleException("Cannot retrieve all remote repositories. Reason: %s", e, e.getMessage());
    }
    List<RemoteRepository> toStore = new ArrayList<>();
    remoteRepositories.forEach((repo) -> {
        if (repo.getName().startsWith("i-")) {
            repo.setMetadata(METADATA_ORIGIN, IMPLIED_REPO_ORIGIN);
            toStore.add(repo);
        }
    });
    for (RemoteRepository repo : toStore) {
        try {
            storeDataManager.storeArtifactStore(repo, new ChangeSummary(ChangeSummary.SYSTEM_USER, "Adding implied-repository origin metadata"), false, true, new EventMetadata());
        } catch (IndyDataException e) {
            throw new IndyLifecycleException("Failed to store %s with implied-repos origin metadata. Reason: %s", e, repo == null ? "NULL REPO" : repo.getKey(), e.getMessage());
        }
    }
    return !toStore.isEmpty();
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) ArrayList(java.util.ArrayList) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) IndyLifecycleException(org.commonjava.indy.action.IndyLifecycleException) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) EventMetadata(org.commonjava.maven.galley.event.EventMetadata)

Aggregations

EventMetadata (org.commonjava.maven.galley.event.EventMetadata)95 Transfer (org.commonjava.maven.galley.model.Transfer)38 ChangeSummary (org.commonjava.indy.audit.ChangeSummary)37 Test (org.junit.Test)37 IndyDataException (org.commonjava.indy.data.IndyDataException)27 RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)27 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)20 StoreKey (org.commonjava.indy.model.core.StoreKey)18 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)17 Group (org.commonjava.indy.model.core.Group)17 ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)15 Logger (org.slf4j.Logger)15 IOException (java.io.IOException)13 Inject (javax.inject.Inject)11 ApiOperation (io.swagger.annotations.ApiOperation)10 ApiResponses (io.swagger.annotations.ApiResponses)10 InputStream (java.io.InputStream)10 ArrayList (java.util.ArrayList)10 Path (javax.ws.rs.Path)10 SimpleProjectVersionRef (org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef)9