Search in sources :

Example 6 with Downloader

use of io.fabric8.agent.download.Downloader in project fabric8 by jboss-fuse.

the class SubsystemResolver method resolve.

public Map<Resource, List<Wire>> resolve(MetadataBuilder builder, Set<String> overrides, String featureResolutionRange, final org.osgi.service.repository.Repository globalRepository) throws Exception {
    if (root == null) {
        return Collections.emptyMap();
    }
    // Download bundles
    root.downloadBundles(manager, builder, overrides, featureResolutionRange);
    // Populate digraph and resolve
    digraph = new StandardRegionDigraph(null, null);
    populateDigraph(digraph, root);
    Resolver resolver = new ResolverImpl(new Slf4jResolverLog(LOGGER));
    Downloader downloader = manager.createDownloader();
    wiring = resolver.resolve(new SubsystemResolveContext(root, digraph, globalRepository, downloader));
    downloader.await();
    // Remove wiring to the fake environment resource
    if (environmentResource != null) {
        for (List<Wire> wires : wiring.values()) {
            for (Iterator<Wire> iterator = wires.iterator(); iterator.hasNext(); ) {
                Wire wire = iterator.next();
                if (wire.getProvider() == environmentResource) {
                    iterator.remove();
                }
            }
        }
    }
    // Fragments are always wired to their host only, so create fake wiring to
    // the subsystem the host is wired to
    associateFragments();
    return wiring;
}
Also used : Resolver(org.osgi.service.resolver.Resolver) Slf4jResolverLog(io.fabric8.agent.resolver.Slf4jResolverLog) Downloader(io.fabric8.agent.download.Downloader) ResolverImpl(org.apache.felix.resolver.ResolverImpl) Wire(org.osgi.resource.Wire) StandardRegionDigraph(org.eclipse.equinox.internal.region.StandardRegionDigraph)

Example 7 with Downloader

use of io.fabric8.agent.download.Downloader in project fabric8 by jboss-fuse.

the class ProfileDownloadArtifactsAction method doExecute.

@Override
protected Object doExecute() throws Exception {
    Version ver = version != null ? profileService.getVersion(version) : fabricService.getDefaultVersion();
    if (ver == null) {
        if (version != null) {
            System.out.println("version " + version + " does not exist!");
        } else {
            System.out.println("No default version available!");
        }
        return null;
    }
    if (target == null) {
        String karafBase = System.getProperty("karaf.base", ".");
        target = new File(karafBase, ProfileDownloadArtifactsAction.DEFAULT_TARGET);
    }
    target.mkdirs();
    if (!target.exists()) {
        System.out.println("Could not create the target directory " + target);
        return null;
    }
    if (!target.isDirectory()) {
        System.out.println("Target is not a directory " + target);
        return null;
    }
    if (executorService == null) {
        if (threadPoolSize > 1) {
            executorService = Executors.newScheduledThreadPool(threadPoolSize);
        } else {
            executorService = Executors.newSingleThreadScheduledExecutor();
        }
    }
    ProfileDownloader downloader = new ProfileDownloader(fabricService, target, force, executorService);
    downloader.setStopOnFailure(stopOnFailure);
    // we do not want to download the files from within the profile itself, only the dependencies
    downloader.setDownloadFilesFromProfile(false);
    if (verbose) {
        downloader.setListener(new ProgressIndicator());
    }
    if (profile != null) {
        Profile profileObject = null;
        if (ver.hasProfile(profile)) {
            profileObject = ver.getRequiredProfile(profile);
        }
        if (profileObject == null) {
            System.out.println("Source profile " + profile + " not found.");
            return null;
        }
        downloader.downloadProfile(profileObject);
    } else {
        downloader.downloadVersion(ver);
    }
    List<String> failedProfileIDs = downloader.getFailedProfileIDs();
    System.out.println("Downloaded " + downloader.getProcessedFileCount() + " file(s) to " + target);
    if (failedProfileIDs.size() > 0) {
        System.out.println("Failed to download these profiles: " + failedProfileIDs + ". Check the logs for details");
    }
    return null;
}
Also used : Version(io.fabric8.api.Version) ProfileDownloader(io.fabric8.agent.download.ProfileDownloader) File(java.io.File) Profile(io.fabric8.api.Profile)

Example 8 with Downloader

use of io.fabric8.agent.download.Downloader in project fabric8 by jboss-fuse.

the class ArchetypeGenerateAction method fetchArchetype.

/**
 * Fetches archetype from the configured repositories
 * TODO: make this code available to hawt.io/JMX too
 */
private File fetchArchetype(Archetype archetype) throws IOException {
    MavenResolver resolver = MavenResolvers.createMavenResolver(new Hashtable<String, String>(), "org.ops4j.pax.url.mvn");
    DownloadManager dm = DownloadManagers.createDownloadManager(resolver, Executors.newSingleThreadScheduledExecutor());
    final AtomicReference<File> file = new AtomicReference<>();
    String url = String.format("mvn:%s/%s/%s", archetype.groupId, archetype.artifactId, archetype.version);
    Downloader downloader = dm.createDownloader();
    downloader.download(url, new DownloadCallback() {

        @Override
        public void downloaded(StreamProvider provider) throws Exception {
            file.set(provider.getFile());
        }
    });
    // wait for download
    try {
        boolean init = false;
        for (int i = 0; i < 2 * 60 && file.get() == null; i++) {
            // dont do anything in the first 3 seconds as we likely can download it faster
            if (i > 3) {
                if (!init) {
                    System.out.print("Downloading archetype in progress: ");
                    init = true;
                }
                System.out.print(".");
            }
            // only sleep 0.5 sec so we can react faster
            Thread.sleep(500);
        }
    } catch (InterruptedException e) {
        System.err.println("\nFailed to download " + archetype);
        throw new IOException(e.getMessage(), e);
    }
    try {
        downloader.await();
        return file.get();
    } catch (Exception e) {
        System.err.println("\nFailed to download archetype within 60 seconds: " + archetype);
        throw new IOException("Failed to download archetype within 60 seconds: " + archetype);
    }
}
Also used : StreamProvider(io.fabric8.agent.download.StreamProvider) DownloadCallback(io.fabric8.agent.download.DownloadCallback) Downloader(io.fabric8.agent.download.Downloader) AtomicReference(java.util.concurrent.atomic.AtomicReference) IOException(java.io.IOException) DownloadManager(io.fabric8.agent.download.DownloadManager) IOException(java.io.IOException) MavenResolver(io.fabric8.maven.MavenResolver) File(java.io.File)

Example 9 with Downloader

use of io.fabric8.agent.download.Downloader in project fabric8 by jboss-fuse.

the class AgentUtils method downloadRepositories.

public static Callable<Map<String, Repository>> downloadRepositories(DownloadManager manager, Set<String> uris) throws MultiException, InterruptedException, MalformedURLException {
    final Map<String, Repository> repositories = new HashMap<>();
    final Downloader downloader = manager.createDownloader();
    final File targetLocation = getDefaultKarafRepository();
    for (String uri : uris) {
        downloader.download(uri, new DownloadCallback() {

            @Override
            public void downloaded(StreamProvider provider) throws Exception {
                String uri = provider.getUrl();
                Repository repository = new Repository(URI.create(uri));
                repository.load(new FileInputStream(provider.getFile()), true);
                synchronized (repositories) {
                    repositories.put(uri, repository);
                }
                for (URI repo : repository.getRepositories()) {
                    downloader.download(repo.toASCIIString(), this);
                }
                Artifact artifact = Utils.mvnurlToArtifact(uri, true);
                if (artifact == null || artifact.getVersion() == null || !artifact.getVersion().endsWith("-SNAPSHOT")) {
                    // we need a feature repository to be available in ${karaf.home}/${karaf.default.repository}
                    // it makes patching much easier
                    // ENTESB-6931: don't store SNAPSHOT feature repositories in ${karaf.home}/${karaf.default.repository}
                    storeInDefaultKarafRepository(targetLocation, provider.getFile(), uri);
                }
            }
        });
    }
    return new Callable<Map<String, Repository>>() {

        @Override
        public Map<String, Repository> call() throws Exception {
            downloader.await();
            return repositories;
        }
    };
}
Also used : StreamProvider(io.fabric8.agent.download.StreamProvider) HashMap(java.util.HashMap) DownloadCallback(io.fabric8.agent.download.DownloadCallback) Downloader(io.fabric8.agent.download.Downloader) URI(java.net.URI) MalformedURLException(java.net.MalformedURLException) MultiException(io.fabric8.common.util.MultiException) FileInputStream(java.io.FileInputStream) Artifact(io.fabric8.patch.management.Artifact) Callable(java.util.concurrent.Callable) Repository(io.fabric8.agent.model.Repository) File(java.io.File)

Aggregations

Downloader (io.fabric8.agent.download.Downloader)8 StreamProvider (io.fabric8.agent.download.StreamProvider)6 DownloadCallback (io.fabric8.agent.download.DownloadCallback)5 File (java.io.File)5 HashMap (java.util.HashMap)4 MultiException (io.fabric8.common.util.MultiException)3 FileInputStream (java.io.FileInputStream)3 IOException (java.io.IOException)3 URI (java.net.URI)3 DownloadManager (io.fabric8.agent.download.DownloadManager)2 BundleInfo (io.fabric8.agent.model.BundleInfo)2 FeatureResource (io.fabric8.agent.resolver.FeatureResource)2 Profile (io.fabric8.api.Profile)2 MavenResolver (io.fabric8.maven.MavenResolver)2 MalformedURLException (java.net.MalformedURLException)2 Callable (java.util.concurrent.Callable)2 Resource (org.osgi.resource.Resource)2 ProfileDownloader (io.fabric8.agent.download.ProfileDownloader)1 MapUtils.addToMapSet (io.fabric8.agent.internal.MapUtils.addToMapSet)1 MapUtils.removeFromMapSet (io.fabric8.agent.internal.MapUtils.removeFromMapSet)1