Search in sources :

Example 1 with ProfileDownloader

use of io.fabric8.agent.download.ProfileDownloader 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)

Aggregations

ProfileDownloader (io.fabric8.agent.download.ProfileDownloader)1 Profile (io.fabric8.api.Profile)1 Version (io.fabric8.api.Version)1 File (java.io.File)1