Search in sources :

Example 71 with Version

use of io.fabric8.api.Version 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 72 with Version

use of io.fabric8.api.Version in project fabric8 by jboss-fuse.

the class ProfileWatcherImpl method getCurrentActiveProfileVersions.

/**
 * Gets the set of active profile ids and versions
 */
protected SortedSet<String> getCurrentActiveProfileVersions() {
    SortedSet<String> answer = new TreeSet<String>();
    Container[] containers = fabricService.get().getContainers();
    for (Container container : containers) {
        container.getProvisionList();
        Profile[] profiles = container.getProfiles();
        // TODO allow filter on a profile here?
        for (Profile profile : profiles) {
            String id = profile.getId();
            String version = profile.getVersion();
            answer.add(id + "/" + version);
        }
    }
    return answer;
}
Also used : Container(io.fabric8.api.Container) TreeSet(java.util.TreeSet) Profile(io.fabric8.api.Profile)

Example 73 with Version

use of io.fabric8.api.Version in project fabric8 by jboss-fuse.

the class Overrides method override.

/**
 * Compute a list of bundles to install, taking into account overrides.
 * <p/>
 * The file containing the overrides will be loaded from the given url.
 * Blank lines and lines starting with a '#' will be ignored, all other lines
 * are considered as urls to override bundles.
 * <p/>
 * The list of resources to resolve will be scanned and for each bundle,
 * if a bundle override matches that resource, it will be used instead.
 * <p/>
 * Matching is done on bundle symbolic name (they have to be the same)
 * and version (the bundle override version needs to be greater than the
 * resource to be resolved, and less than the next minor version.  A range
 * directive can be added to the override url in which case, the matching
 * will succeed if the resource to be resolved is within the given range.
 *
 * @param resources the list of resources to resolve
 * @param overrides list of bundle overrides
 */
public static <T extends Resource> void override(Map<String, T> resources, Collection<String> overrides) {
    // Do override replacement
    for (Clause override : Parser.parseClauses(overrides.toArray(new String[overrides.size()]))) {
        String url = override.getName();
        String vr = override.getAttribute(OVERRIDE_RANGE);
        T over = resources.get(url);
        if (over == null) {
            // Ignore invalid overrides
            continue;
        }
        for (String uri : new ArrayList<String>(resources.keySet())) {
            Resource res = resources.get(uri);
            if (getSymbolicName(res).equals(getSymbolicName(over))) {
                VersionRange range;
                if (vr == null) {
                    // default to micro version compatibility
                    Version v1 = getVersion(res);
                    Version v2 = new Version(v1.getMajor(), v1.getMinor() + 1, 0);
                    range = new VersionRange(false, v1, v2, true);
                } else {
                    range = VersionRange.parseVersionRange(vr);
                }
                // if the override is actually a newer version than what we currently have
                if (range.contains(getVersion(over)) && getVersion(res).compareTo(getVersion(over)) < 0) {
                    resources.put(uri, over);
                }
            }
        }
    }
}
Also used : Version(org.osgi.framework.Version) ResourceUtils.getVersion(io.fabric8.agent.resolver.ResourceUtils.getVersion) ArrayList(java.util.ArrayList) Resource(org.osgi.resource.Resource) VersionRange(org.apache.felix.utils.version.VersionRange) Clause(org.apache.felix.utils.manifest.Clause)

Example 74 with Version

use of io.fabric8.api.Version in project fabric8 by jboss-fuse.

the class ProfileDownloader method downloadVersion.

/**
 * Downloads the bundles, features and FABs for all the profiles in this version
 */
public void downloadVersion(Version version) throws Exception {
    List<Profile> profiles = version.getProfiles();
    Profile[] prfarray = profiles.toArray(new Profile[profiles.size()]);
    if (listener != null) {
        listener.beforeDownloadProfiles(prfarray);
    }
    for (Profile profile : profiles) {
        try {
            downloadProfile(profile);
        } catch (Exception e) {
            if (listener != null) {
                listener.onError(profile, e);
            }
            if (!stopOnFailure) {
                String id = profile.getId();
                errors.put(id, e);
                LOG.error("Failed to download profile " + id + " due " + e.getMessage(), e);
            } else {
                throw e;
            }
        }
    }
    if (listener != null) {
        listener.afterDownloadProfiles(prfarray);
    }
}
Also used : Profile(io.fabric8.api.Profile)

Example 75 with Version

use of io.fabric8.api.Version in project fabric8 by jboss-fuse.

the class WatchAction method doExecute.

@Override
protected Object doExecute() throws Exception {
    if (start && stop) {
        System.err.println("Please use only one of --start and --stop options!");
        return null;
    }
    if (interval > 0) {
        System.out.println("Setting watch interval to " + interval + " ms");
        watcher.setInterval(interval);
    }
    if (stop) {
        System.out.println("Stopping watch");
        watcher.stop();
    }
    watcher.setUpload(upload);
    if (urls != null) {
        if (remove) {
            for (String url : urls) {
                watcher.remove(url);
            }
        } else {
            for (String url : urls) {
                watcher.add(url);
            }
        }
    }
    if (start) {
        System.out.println("Starting watch");
        watcher.start();
    }
    if (list) {
        // list the watched bundles.
        TablePrinter printer = new TablePrinter();
        printer.columns("url", "profile", "version", "bundle");
        for (String url : watcher.getWatchURLs()) {
            Map<ProfileVersionKey, Map<String, Parser>> profileArtifacts = watcher.getProfileArtifacts();
            if (profileArtifacts.size() > 0) {
                Set<Map.Entry<ProfileVersionKey, Map<String, Parser>>> entries = profileArtifacts.entrySet();
                for (Map.Entry<ProfileVersionKey, Map<String, Parser>> entry : entries) {
                    ProfileVersionKey key = entry.getKey();
                    Map<String, Parser> artifactMap = entry.getValue();
                    Set<Map.Entry<String, Parser>> artifactMapEntries = artifactMap.entrySet();
                    for (Map.Entry<String, Parser> artifactMapEntry : artifactMapEntries) {
                        String location = artifactMapEntry.getKey();
                        Parser parser = artifactMapEntry.getValue();
                        if (isSnapshot(parser) || watcher.wildCardMatch(location, url)) {
                            printer.row(url, key.getProfileId(), key.getVersion(), location);
                        }
                    }
                }
            } else {
                printer.row(url, "", "", "");
            }
        }
        printer.print();
    } else {
        List<String> urls = watcher.getWatchURLs();
        if (urls != null && urls.size() > 0) {
            System.out.println("Watched URLs: ");
            for (String url : watcher.getWatchURLs()) {
                System.out.println(url);
            }
        } else {
            System.out.println("No watched URLs");
        }
    }
    return null;
}
Also used : ProfileVersionKey(io.fabric8.agent.commands.support.ProfileVersionKey) Parser(io.fabric8.maven.util.Parser) TablePrinter(io.fabric8.utils.TablePrinter) Map(java.util.Map)

Aggregations

Version (io.fabric8.api.Version)74 Profile (io.fabric8.api.Profile)70 File (java.io.File)52 Test (org.junit.Test)46 IOException (java.io.IOException)41 ArrayList (java.util.ArrayList)36 Container (io.fabric8.api.Container)35 HashMap (java.util.HashMap)34 ProfileService (io.fabric8.api.ProfileService)27 Map (java.util.Map)25 Git (org.eclipse.jgit.api.Git)22 FabricService (io.fabric8.api.FabricService)21 Version (org.osgi.framework.Version)21 ProfileBuilder (io.fabric8.api.ProfileBuilder)18 GitVersion (io.fabric8.api.commands.GitVersion)18 PatchException (io.fabric8.patch.management.PatchException)15 HashSet (java.util.HashSet)15 TreeMap (java.util.TreeMap)14 LinkedList (java.util.LinkedList)13 GitPatchRepository (io.fabric8.patch.management.impl.GitPatchRepository)12