Search in sources :

Example 6 with DownloadManager

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

the class AgentUtils method downloadLocations.

public static Map<String, File> downloadLocations(DownloadManager manager, Collection<String> uris, final boolean storeInDefaultKarafRepository) throws MultiException, InterruptedException, MalformedURLException {
    final Map<String, File> files = new HashMap<>();
    final Downloader downloader = manager.createDownloader();
    final File targetLocation = storeInDefaultKarafRepository ? getDefaultKarafRepository() : null;
    for (String uri : uris) {
        downloader.download(uri, new DownloadCallback() {

            @Override
            public void downloaded(StreamProvider provider) throws Exception {
                String uri = provider.getUrl();
                File file = provider.getFile();
                synchronized (files) {
                    files.put(uri, file);
                    if (storeInDefaultKarafRepository) {
                        storeInDefaultKarafRepository(targetLocation, file, uri);
                    }
                }
            }
        });
    }
    downloader.await();
    return files;
}
Also used : StreamProvider(io.fabric8.agent.download.StreamProvider) HashMap(java.util.HashMap) DownloadCallback(io.fabric8.agent.download.DownloadCallback) Downloader(io.fabric8.agent.download.Downloader) File(java.io.File) MalformedURLException(java.net.MalformedURLException) MultiException(io.fabric8.common.util.MultiException)

Example 7 with DownloadManager

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

the class ProfileWatcherImpl method findProfileArifacts.

// For each profile and version return the map of bundle locations to parsers
private Map<ProfileVersionKey, Map<String, Parser>> findProfileArifacts() throws Exception {
    Map<ProfileVersionKey, Map<String, Parser>> profileArtifacts = new HashMap<ProfileVersionKey, Map<String, Parser>>();
    ProfileService profileService = fabricService.get().adapt(ProfileService.class);
    DownloadManager downloadManager = DownloadManagers.createDownloadManager(fabricService.get(), executorService);
    Container[] containers = fabricService.get().getContainers();
    for (Container container : containers) {
        Profile[] profiles = container.getProfiles();
        boolean javaOrProcessContainer = ChildContainers.isJavaOrProcessContainer(fabricService.get(), container);
        // TODO allow filter on a profile here?
        for (Profile profile : profiles) {
            Profile overlay = profileService.getOverlayProfile(profile);
            ProfileVersionKey key = new ProfileVersionKey(profile);
            // if (!profileArtifacts.containsKey(key)) {
            Map<String, Parser> artifacts = null;
            if (javaOrProcessContainer) {
                List<Profile> singletonList = Collections.singletonList(profile);
                artifacts = JavaContainers.getJavaContainerArtifacts(fabricService.get(), singletonList, executorService);
            } else {
                artifacts = AgentUtils.getProfileArtifacts(fabricService.get(), downloadManager, overlay);
            }
            if (artifacts != null) {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Profile " + profile.getId() + " maps to artefacts: " + artifacts.keySet());
                }
                profileArtifacts.put(key, artifacts);
            }
        // }
        }
    }
    return profileArtifacts;
}
Also used : HashMap(java.util.HashMap) DownloadManager(io.fabric8.agent.download.DownloadManager) Profile(io.fabric8.api.Profile) Parser(io.fabric8.maven.util.Parser) Container(io.fabric8.api.Container) ProfileService(io.fabric8.api.ProfileService) Map(java.util.Map) HashMap(java.util.HashMap)

Example 8 with DownloadManager

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

the class DownloadManagers method createDownloadManager.

/**
 * Creates a DownloadManager
 */
public static DownloadManager createDownloadManager(FabricService fabricService, Profile profile, ScheduledExecutorService executorService) {
    Map<String, String> configuration = profile.getConfiguration(Constants.AGENT_PID);
    if (configuration == null) {
        configuration = new HashMap<>();
    }
    Dictionary<String, String> properties = mapToDictionary(configuration);
    Mirror mirror = AgentUtils.getMavenProxy(fabricService);
    MavenResolver resolver = MavenResolvers.createMavenResolver(mirror, properties, "org.ops4j.pax.url.mvn");
    return createDownloadManager(resolver, executorService);
}
Also used : MavenResolver(io.fabric8.maven.MavenResolver) Mirror(org.apache.maven.settings.Mirror)

Example 9 with DownloadManager

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

the class DownloadManagers method createDownloadManager.

/**
 * Creates a download manager using the current container's maven configuration
 */
public static DownloadManager createDownloadManager(FabricService fabricService, ScheduledExecutorService executorService) {
    Profile overlayProfile = fabricService.getCurrentContainer().getOverlayProfile();
    Profile effectiveProfile = Profiles.getEffectiveProfile(fabricService, overlayProfile);
    return createDownloadManager(fabricService, effectiveProfile, executorService);
}
Also used : Profile(io.fabric8.api.Profile)

Example 10 with DownloadManager

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

the class ProfileMetadata method findMetadataForProfile.

protected void findMetadataForProfile(String versionId, String profileId, MetadataHandler handler) throws Exception {
    FabricService service = fabricService.get();
    Objects.notNull(service, "FabricService");
    ProfileService profileService = service.adapt(ProfileService.class);
    Objects.notNull(profileService, "ProfileService");
    DownloadManager downloadManager = DownloadManagers.createDownloadManager(service, executorService);
    Objects.notNull(downloadManager, "DownloadManager");
    Profile immediateProfile = profileService.getProfile(versionId, profileId);
    Objects.notNull(immediateProfile, "Profile for versionId: " + versionId + ", profileId: " + profileId);
    Profile profile = profileService.getOverlayProfile(immediateProfile);
    Set<String> pids = new HashSet<>();
    Map<String, File> fileMap = AgentUtils.downloadProfileArtifacts(service, downloadManager, profile);
    Set<Map.Entry<String, File>> entries = fileMap.entrySet();
    for (Map.Entry<String, File> entry : entries) {
        String uri = entry.getKey();
        File file = entry.getValue();
        if (!file.exists() || !file.isFile()) {
            LOG.warn("File " + file + " is not an existing file for " + uri + ". Ignoring");
            continue;
        }
        addMetaTypeInformation(handler, uri, file);
        pids.add(uri);
    }
    // lets check if the MetaType folder exists
    if (metaTypeFolder != null && metaTypeFolder.exists() && metaTypeFolder.isDirectory()) {
        Set<String> configurationFileNames = profile.getConfigurationFileNames();
        for (String configName : configurationFileNames) {
            if (configName.endsWith(PROPERTIES_SUFFIX) && configName.indexOf('/') < 0) {
                String pid = configName.substring(0, configName.length() - PROPERTIES_SUFFIX.length());
                addMetaTypeInformation(pids, handler, pid);
                String factoryPid = getFactoryPid(pid);
                addMetaTypeInformation(pids, handler, factoryPid);
            }
        }
    }
}
Also used : DownloadManager(io.fabric8.agent.download.DownloadManager) Profile(io.fabric8.api.Profile) JarEntry(java.util.jar.JarEntry) ProfileService(io.fabric8.api.ProfileService) FabricService(io.fabric8.api.FabricService) JarFile(java.util.jar.JarFile) File(java.io.File) Map(java.util.Map) HashMap(java.util.HashMap) HashSet(java.util.HashSet)

Aggregations

HashMap (java.util.HashMap)9 DownloadManager (io.fabric8.agent.download.DownloadManager)8 Profile (io.fabric8.api.Profile)8 File (java.io.File)8 Downloader (io.fabric8.agent.download.Downloader)6 DownloadCallback (io.fabric8.agent.download.DownloadCallback)5 StreamProvider (io.fabric8.agent.download.StreamProvider)5 Feature (io.fabric8.agent.model.Feature)5 ProfileService (io.fabric8.api.ProfileService)5 MavenResolver (io.fabric8.maven.MavenResolver)5 Map (java.util.Map)5 MultiException (io.fabric8.common.util.MultiException)4 Parser (io.fabric8.maven.util.Parser)4 IOException (java.io.IOException)4 Repository (io.fabric8.agent.model.Repository)3 FabricService (io.fabric8.api.FabricService)3 ArrayList (java.util.ArrayList)3 Hashtable (java.util.Hashtable)3 BundleInfo (io.fabric8.agent.model.BundleInfo)2 Agent (io.fabric8.agent.service.Agent)2