Search in sources :

Example 51 with Feature

use of io.fabric8.agent.model.Feature 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)

Example 52 with Feature

use of io.fabric8.agent.model.Feature in project fabric8 by jboss-fuse.

the class AgentUtils method getProfileArtifacts.

/**
 * Returns the location and parser map (i.e. the location and the parsed maven coordinates and artifact locations) of each bundle and feature
 */
public static Map<String, Parser> getProfileArtifacts(FabricService fabricService, Profile profile, Iterable<String> bundles, Iterable<Feature> features, Callback<String> nonMavenLocationCallback) {
    Set<String> locations = new HashSet<>();
    for (Feature feature : features) {
        List<BundleInfo> bundleList = feature.getBundles();
        if (bundleList == null) {
            LOGGER.warn("No bundles for feature " + feature);
        } else {
            for (BundleInfo bundle : bundleList) {
                locations.add(bundle.getLocation());
            }
        }
    }
    for (String bundle : bundles) {
        locations.add(bundle);
    }
    Map<String, Parser> artifacts = new HashMap<>();
    for (String location : locations) {
        try {
            if (location.contains("$")) {
                ProfileService profileService = fabricService.adapt(ProfileService.class);
                Profile overlay = profileService.getOverlayProfile(profile);
                location = VersionPropertyPointerResolver.replaceVersions(fabricService, overlay.getConfigurations(), location);
            }
            if (location.startsWith("mvn:") || location.contains(":mvn:")) {
                Parser parser = Parser.parsePathWithSchemePrefix(location);
                artifacts.put(location, parser);
            } else {
                if (nonMavenLocationCallback != null) {
                    nonMavenLocationCallback.call(location);
                }
            }
        } catch (MalformedURLException e) {
            LOGGER.error("Failed to parse bundle URL: " + location + ". " + e, e);
        }
    }
    return artifacts;
}
Also used : MalformedURLException(java.net.MalformedURLException) BundleInfo(io.fabric8.agent.model.BundleInfo) ProfileService(io.fabric8.api.ProfileService) HashMap(java.util.HashMap) Feature(io.fabric8.agent.model.Feature) Profile(io.fabric8.api.Profile) HashSet(java.util.HashSet) Parser(io.fabric8.maven.util.Parser)

Example 53 with Feature

use of io.fabric8.agent.model.Feature in project fabric8 by jboss-fuse.

the class AgentUtils method expandFeature.

public static Set<Feature> expandFeature(Feature feature, Map<String, Repository> repositories) {
    Set<Feature> features = new HashSet<>();
    for (Dependency f : feature.getDependencies()) {
        Feature loaded = FeatureUtils.search(f.getName(), repositories.values());
        features.addAll(expandFeature(loaded, repositories));
    }
    features.add(feature);
    return features;
}
Also used : Dependency(io.fabric8.agent.model.Dependency) Feature(io.fabric8.agent.model.Feature) HashSet(java.util.HashSet)

Example 54 with Feature

use of io.fabric8.agent.model.Feature in project fabric8 by jboss-fuse.

the class FeatureUtils method search.

public static Feature search(String name, String version, Collection<Repository> repositories) {
    VersionRange range = new VersionRange(version, false, true);
    Feature bestFeature = null;
    Version bestVersion = null;
    for (Repository repo : repositories) {
        Feature[] features;
        try {
            features = repo.getFeatures();
        } catch (Exception e) {
            // This should not happen as the repository has been loaded already
            throw new IllegalStateException(e);
        }
        for (Feature feature : features) {
            if (name.equals(feature.getName())) {
                Version v = new Version(VersionCleaner.clean(feature.getVersion()));
                if (range.contains(v)) {
                    if (bestVersion == null || bestVersion.compareTo(v) < 0) {
                        bestFeature = feature;
                        bestVersion = v;
                    }
                }
            }
        }
    }
    return bestFeature;
}
Also used : Repository(io.fabric8.agent.model.Repository) Version(org.osgi.framework.Version) VersionRange(org.apache.felix.utils.version.VersionRange) Feature(io.fabric8.agent.model.Feature)

Example 55 with Feature

use of io.fabric8.agent.model.Feature in project fabric8 by jboss-fuse.

the class DeploymentAgentTest method testResolveOptionalImports.

@Test
@SuppressWarnings("unchecked")
public void testResolveOptionalImports() throws Exception {
    CommandSupport.executeCommand("fabric:create --force --clean -n --wait-for-provisioning");
    CommandSupport.executeCommand("fabric:profile-create --parent default test-profile");
    CommandSupport.executeCommand("fabric:profile-edit --pid io.fabric8.agent/resolve.optional.imports=true test-profile");
    CommandSupport.executeCommand("fabric:profile-edit --feature spring-struts test-profile");
    BundleContext moduleContext = ServiceLocator.getSystemContext();
    ServiceProxy<FabricService> fabricProxy = ServiceProxy.createServiceProxy(moduleContext, FabricService.class);
    try {
        FabricService fabricService = fabricProxy.getService();
        Set<Container> containers = ContainerBuilder.create().withName("smoke_cnt_b").withProfiles("test-profile").assertProvisioningResult().build(fabricService);
        try {
            String command = "fabric:container-connect -u admin -p admin " + containers.iterator().next().getId() + " osgi:list -t 0 -s | grep org.apache.servicemix.bundles.struts";
            String result = CommandSupport.executeCommand(command);
            assertTrue("Result contains struts, but was: " + result, result.contains("org.apache.servicemix.bundles.struts"));
        } finally {
            ContainerBuilder.stop(fabricService, containers);
        }
    } finally {
        fabricProxy.close();
    }
}
Also used : Container(io.fabric8.api.Container) FabricService(io.fabric8.api.FabricService) BundleContext(org.osgi.framework.BundleContext) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)20 HashMap (java.util.HashMap)18 FabricService (io.fabric8.api.FabricService)15 IOException (java.io.IOException)13 Feature (io.fabric8.agent.model.Feature)12 Container (io.fabric8.api.Container)11 Profile (io.fabric8.api.Profile)11 ArrayList (java.util.ArrayList)11 File (java.io.File)10 Map (java.util.Map)9 BundleContext (org.osgi.framework.BundleContext)9 HashSet (java.util.HashSet)8 URL (java.net.URL)7 BundleException (org.osgi.framework.BundleException)7 Repository (io.fabric8.agent.model.Repository)6 Version (io.fabric8.api.Version)6 LinkedHashSet (java.util.LinkedHashSet)6 Ignore (org.junit.Ignore)6 BundleInfo (io.fabric8.agent.model.BundleInfo)5 ContainerProxy (io.fabric8.itests.paxexam.support.ContainerProxy)5