Search in sources :

Example 66 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 67 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 68 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 69 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)

Example 70 with Feature

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

the class JoinTest method testJoin.

@Test
public void testJoin() throws Exception {
    System.err.println(CommandSupport.executeCommand("fabric:create --force --clean -n --wait-for-provisioning"));
    BundleContext moduleContext = ServiceLocator.getSystemContext();
    ServiceProxy<FabricService> fabricProxy = ServiceProxy.createServiceProxy(moduleContext, FabricService.class);
    try {
        FabricService fabricService = fabricProxy.getService();
        AdminService adminService = ServiceLocator.awaitService(AdminService.class);
        String version = System.getProperty("fabric.version");
        System.err.println(CommandSupport.executeCommand("admin:create -o '-server -Xmx1536M -Dcom.sun.management.jmxremote -XX:+UnlockDiagnosticVMOptions -XX:+UnsyncloadClass -Dpatching.disabled=true -Djava.security.egd=file:/dev/./urandom' --featureURL mvn:io.fabric8/fabric8-karaf/" + version + "/xml/features --feature fabric-git --feature fabric-agent --feature fabric-boot-commands smoke_child_d"));
        try {
            System.err.println(CommandSupport.executeCommand("admin:start smoke_child_d"));
            ProvisionSupport.instanceStarted(Arrays.asList("smoke_child_d"), ProvisionSupport.PROVISION_TIMEOUT);
            System.err.println(CommandSupport.executeCommand("admin:list"));
            String joinCommand = "fabric:join -f --zookeeper-password " + fabricService.getZookeeperPassword() + " " + fabricService.getZookeeperUrl();
            String response = "";
            for (int i = 0; i < 10 && !response.contains("true"); i++) {
                response = CommandSupport.executeCommand("ssh:ssh -l karaf -P karaf -p " + adminService.getInstance("smoke_child_d").getSshPort() + " localhost " + WAIT_FOR_JOIN_SERVICE);
                Thread.sleep(1000);
            }
            System.err.println(CommandSupport.executeCommand("ssh:ssh -l karaf -P karaf -p " + adminService.getInstance("smoke_child_d").getSshPort() + " localhost " + joinCommand));
            ProvisionSupport.containersExist(Arrays.asList("smoke_child_d"), ProvisionSupport.PROVISION_TIMEOUT);
            Container childD = fabricService.getContainer("smoke_child_d");
            System.err.println(CommandSupport.executeCommand("fabric:container-list"));
            ProvisionSupport.containerStatus(Arrays.asList(childD), "success", ProvisionSupport.PROVISION_TIMEOUT);
            System.err.println(CommandSupport.executeCommand("fabric:container-list"));
        } finally {
            System.err.println(CommandSupport.executeCommand("admin:stop smoke_child_d"));
        }
    } finally {
        fabricProxy.close();
    }
}
Also used : Container(io.fabric8.api.Container) AdminService(org.apache.karaf.admin.AdminService) FabricService(io.fabric8.api.FabricService) BundleContext(org.osgi.framework.BundleContext) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)20 HashMap (java.util.HashMap)19 ArrayList (java.util.ArrayList)17 FabricService (io.fabric8.api.FabricService)15 IOException (java.io.IOException)15 Feature (io.fabric8.agent.model.Feature)12 Container (io.fabric8.api.Container)11 Profile (io.fabric8.api.Profile)11 File (java.io.File)11 List (java.util.List)11 Map (java.util.Map)10 Kafka (io.strimzi.api.kafka.model.Kafka)8 Repository (io.fabric8.agent.model.Repository)6 Version (io.fabric8.api.Version)6 Role (io.fabric8.kubernetes.api.model.rbac.Role)6 RoleBinding (io.fabric8.kubernetes.api.model.rbac.RoleBinding)6 RoleRef (io.fabric8.kubernetes.api.model.rbac.RoleRef)6 RoleRefBuilder (io.fabric8.kubernetes.api.model.rbac.RoleRefBuilder)6 KafkaBuilder (io.strimzi.api.kafka.model.KafkaBuilder)6 HashSet (java.util.HashSet)6