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;
}
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;
}
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);
}
}
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;
}
};
}
Aggregations