Search in sources :

Example 1 with IndyLifecycleException

use of org.commonjava.indy.action.IndyLifecycleException in project indy by Commonjava.

the class FoloLifecycleParticipant method start.

@Override
public void start() throws IndyLifecycleException {
    try {
        final DataFile dataFile = dataFileManager.getDataFile(".gitignore");
        final List<String> lines = dataFile.exists() ? dataFile.readLines() : new ArrayList<String>();
        if (!lines.contains(FOLO_DIRECTORY_IGNORE)) {
            lines.add(FOLO_DIRECTORY_IGNORE);
            dataFile.writeLines(lines, new ChangeSummary(ChangeSummary.SYSTEM_USER, "Adding artimon to ignored list."));
        }
    } catch (final IOException e) {
        throw new IndyLifecycleException("Failed while attempting to access .gitignore for data directory (trying to add artimon dir to ignores list).", e);
    }
}
Also used : DataFile(org.commonjava.indy.subsys.datafile.DataFile) IOException(java.io.IOException) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) IndyLifecycleException(org.commonjava.indy.action.IndyLifecycleException)

Example 2 with IndyLifecycleException

use of org.commonjava.indy.action.IndyLifecycleException 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)

Example 3 with IndyLifecycleException

use of org.commonjava.indy.action.IndyLifecycleException in project indy by Commonjava.

the class HttpProxy method start.

@Override
public void start() throws IndyLifecycleException {
    if (!config.isEnabled()) {
        logger.info("HTTProx proxy is disabled.");
        return;
    }
    String bind;
    if (bootOptions.getBind() == null) {
        bind = "0.0.0.0";
    } else {
        bind = bootOptions.getBind();
    }
    logger.info("Starting HTTProx proxy on: {}:{}", bind, config.getPort());
    XnioWorker worker;
    try {
        worker = Xnio.getInstance().createWorker(OptionMap.EMPTY);
        final InetSocketAddress addr;
        if (config.getPort() < 1) {
            ThreadLocal<InetSocketAddress> using = new ThreadLocal<>();
            ThreadLocal<IOException> errorHolder = new ThreadLocal<>();
            server = PortFinder.findPortFor(16, (foundPort) -> {
                InetSocketAddress a = new InetSocketAddress(bind, config.getPort());
                AcceptingChannel<StreamConnection> result = worker.createStreamConnectionServer(a, acceptHandler, OptionMap.EMPTY);
                result.resumeAccepts();
                using.set(a);
                return result;
            });
            addr = using.get();
            config.setPort(addr.getPort());
        } else {
            addr = new InetSocketAddress(bind, config.getPort());
            server = worker.createStreamConnectionServer(addr, acceptHandler, OptionMap.EMPTY);
            server.resumeAccepts();
        }
        logger.info("HTTProxy listening on: {}", addr);
    } catch (IllegalArgumentException | IOException e) {
        throw new IndyLifecycleException("Failed to start HTTProx general content proxy: %s", e, e.getMessage());
    }
}
Also used : Logger(org.slf4j.Logger) Xnio(org.xnio.Xnio) ShutdownAction(org.commonjava.indy.action.ShutdownAction) XnioWorker(org.xnio.XnioWorker) PortFinder(org.commonjava.indy.boot.PortFinder) LoggerFactory(org.slf4j.LoggerFactory) IOException(java.io.IOException) IndyLifecycleException(org.commonjava.indy.action.IndyLifecycleException) BootOptions(org.commonjava.indy.boot.BootOptions) AcceptingChannel(org.xnio.channels.AcceptingChannel) InetSocketAddress(java.net.InetSocketAddress) OptionMap(org.xnio.OptionMap) Inject(javax.inject.Inject) StreamConnection(org.xnio.StreamConnection) HttproxConfig(org.commonjava.indy.httprox.conf.HttproxConfig) StartupAction(org.commonjava.indy.action.StartupAction) ProxyAcceptHandler(org.commonjava.indy.httprox.handler.ProxyAcceptHandler) ApplicationScoped(javax.enterprise.context.ApplicationScoped) XnioWorker(org.xnio.XnioWorker) InetSocketAddress(java.net.InetSocketAddress) IOException(java.io.IOException) IndyLifecycleException(org.commonjava.indy.action.IndyLifecycleException) AcceptingChannel(org.xnio.channels.AcceptingChannel)

Example 4 with IndyLifecycleException

use of org.commonjava.indy.action.IndyLifecycleException in project indy by Commonjava.

the class HttProxOriginMigrationAction method migrate.

@Override
public boolean migrate() throws IndyLifecycleException {
    List<RemoteRepository> repos;
    try {
        repos = storeDataManager.query().noPackageType().getAllRemoteRepositories();
    } catch (IndyDataException e) {
        throw new IndyLifecycleException("Cannot retrieve all remote repositories. Reason: %s", e, e.getMessage());
    }
    List<RemoteRepository> toStore = new ArrayList<>();
    repos.forEach((repo) -> {
        if (repo.getDescription() != null && repo.getDescription().contains("HTTProx proxy")) {
            repo.setMetadata(ArtifactStore.METADATA_ORIGIN, ProxyAcceptHandler.HTTPROX_ORIGIN);
            RemoteRepository store = repo.copyOf(GENERIC_PKG_KEY, repo.getName());
            toStore.add(store);
        }
    });
    final ChangeSummary changeSummary = new ChangeSummary(ChangeSummary.SYSTEM_USER, "Adding HttProx origin metadata");
    for (RemoteRepository repo : toStore) {
        try {
            storeDataManager.storeArtifactStore(repo, changeSummary, false, true, new EventMetadata());
        } catch (IndyDataException e) {
            throw new IndyLifecycleException("Failed to store %s with HttProx 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)

Example 5 with IndyLifecycleException

use of org.commonjava.indy.action.IndyLifecycleException in project indy by Commonjava.

the class KojiOriginMigrationAction method migrate.

@Override
public boolean migrate() throws IndyLifecycleException {
    List<RemoteRepository> repos;
    try {
        repos = storeDataManager.query().noPackageType().getAllRemoteRepositories();
    } catch (IndyDataException e) {
        throw new IndyLifecycleException("Cannot retrieve all remote repositories. Reason: %s", e, e.getMessage());
    }
    List<RemoteRepository> toStore = new ArrayList<>();
    repos.forEach((repo) -> {
        if (repo.getDescription() != null && repo.getDescription().contains("Koji build")) {
            repo.setMetadata(METADATA_ORIGIN, KOJI_ORIGIN);
            toStore.add(repo);
        }
    });
    final ChangeSummary changeSummary = new ChangeSummary(ChangeSummary.SYSTEM_USER, "Adding Koji origin metadata");
    for (RemoteRepository repo : toStore) {
        try {
            storeDataManager.storeArtifactStore(repo, changeSummary, false, true, new EventMetadata());
        } catch (IndyDataException e) {
            throw new IndyLifecycleException("Failed to store %s with Koji 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

IndyLifecycleException (org.commonjava.indy.action.IndyLifecycleException)8 IOException (java.io.IOException)5 ChangeSummary (org.commonjava.indy.audit.ChangeSummary)5 IndyDataException (org.commonjava.indy.data.IndyDataException)5 ArrayList (java.util.ArrayList)3 RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)3 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)3 File (java.io.File)2 HashMap (java.util.HashMap)2 Inject (javax.inject.Inject)2 DataFile (org.commonjava.indy.subsys.datafile.DataFile)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 InetSocketAddress (java.net.InetSocketAddress)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1 Map (java.util.Map)1 Stream (java.util.stream.Stream)1 ApplicationScoped (javax.enterprise.context.ApplicationScoped)1