Search in sources :

Example 6 with Feature

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

the class FeatureResource method build.

public static FeatureResource build(Feature feature, Conditional conditional, String featureRange, Map<String, ? extends Resource> locToRes) throws BundleException {
    Feature fcond = conditional.asFeature(feature.getName(), feature.getVersion());
    FeatureResource resource = build(fcond, featureRange, locToRes);
    for (String cond : conditional.getCondition()) {
        if (cond.startsWith("req:")) {
            cond = cond.substring("req:".length());
            List<org.osgi.resource.Requirement> reqs = ResourceBuilder.parseRequirement(resource, cond);
            resource.addRequirements(reqs);
        } else {
            Dependency dep = new Dependency();
            String[] p = cond.split("/");
            dep.setName(p[0]);
            if (p.length > 1) {
                dep.setVersion(p[1]);
            }
            addDependency(resource, dep, featureRange, true);
        }
    }
    Dependency dep = new Dependency();
    dep.setName(feature.getName());
    dep.setVersion(feature.getVersion());
    addDependency(resource, dep, featureRange, true);
    return resource;
}
Also used : ResourceUtils.addIdentityRequirement(io.fabric8.agent.resolver.ResourceUtils.addIdentityRequirement) Requirement(io.fabric8.agent.model.Requirement) Dependency(io.fabric8.agent.model.Dependency) Feature(io.fabric8.agent.model.Feature)

Example 7 with Feature

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

the class ContainerImplTest method testRemoveMissingProfile.

// We should be able to remove a profile that doesn't exist from a container.
// A missing profile may be added to a container during startup (not possible to validate) or after an upgrade / rollback operation.
@Test
@Ignore("[FABRIC-1110] Mocked test makes invalid assumption on the implementation")
public void testRemoveMissingProfile() throws Exception {
    String v = "1.0";
    String profile1Id = "feature-camel";
    String profile2Id = "feature-cxf";
    String missing = "missing";
    // new VersionImpl(v, fabricService);
    Version version = null;
    List<String> profiles = Arrays.asList(profile1Id, profile2Id, missing);
    List<String> profilesToSet = Arrays.asList(profile1Id, profile2Id);
    expect(profileService.getRequiredVersion(eq(v))).andReturn(version).anyTimes();
    expect(dataStore.getContainerVersion(eq(CONTAINER_ID))).andReturn(v).anyTimes();
    expect(dataStore.getContainerProfiles(eq(CONTAINER_ID))).andReturn(profiles).anyTimes();
    expect(profileRegistry.hasProfile(v, profile1Id)).andReturn(true).anyTimes();
    expect(profileRegistry.hasProfile(v, profile2Id)).andReturn(true).anyTimes();
    expect(profileRegistry.hasProfile(v, missing)).andReturn(false).anyTimes();
    // expect(profileRegistry.getProfileAttributes(eq(v), EasyMock.<String>anyObject())).andReturn(Maps.<String, String>newHashMap()).anyTimes();
    dataStore.setContainerProfiles(eq(CONTAINER_ID), eq(profilesToSet));
    expectLastCall().once();
    replay(fabricService);
    replay(dataStore);
    container.removeProfiles(missing);
    verify(fabricService);
    verify(dataStore);
}
Also used : Version(io.fabric8.api.Version) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 8 with Feature

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

the class ContainerImplTest method testGetMultipleProfiles.

@Test
@Ignore("[FABRIC-1110] Mocked test makes invalid assumption on the implementation")
public void testGetMultipleProfiles() throws Exception {
    String v = "1.0";
    String profile1Id = "feature-camel";
    String profile2Id = "feature-cxf";
    // new VersionImpl(v, fabricService);
    Version version = null;
    List<String> profiles = Arrays.asList(profile1Id, profile2Id);
    expect(profileService.getRequiredVersion(eq(v))).andReturn(version).anyTimes();
    expect(dataStore.getContainerVersion(eq(CONTAINER_ID))).andReturn(v).anyTimes();
    expect(dataStore.getContainerProfiles(eq(CONTAINER_ID))).andReturn(profiles).anyTimes();
    expect(profileRegistry.hasProfile(v, profile1Id)).andReturn(true).anyTimes();
    expect(profileRegistry.hasProfile(v, profile2Id)).andReturn(true).anyTimes();
    replay(fabricService);
    replay(dataStore);
    Profile[] p = container.getProfiles();
    assertNotNull(p);
    assertEquals(2, p.length);
    assertEquals(profile1Id, p[0].getId());
    assertEquals(profile2Id, p[1].getId());
    verify(fabricService);
    verify(dataStore);
}
Also used : Version(io.fabric8.api.Version) Profile(io.fabric8.api.Profile) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 9 with Feature

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

the class Java2SwaggerJsonMojo method execute.

public void execute() throws MojoExecutionException {
    List<Class<?>> resourceClasses = loadResourceClasses();
    List<Object> resourceObjects = new ArrayList<Object>();
    for (Class<?> resourceClass : resourceClasses) {
        try {
            resourceObjects.add(resourceClass.newInstance());
        } catch (InstantiationException e) {
            throw new MojoExecutionException(e.getMessage(), e);
        } catch (IllegalAccessException e) {
            throw new MojoExecutionException(e.getMessage(), e);
        }
    }
    Thread.currentThread().setContextClassLoader(getClassLoader());
    List<Feature> features = new ArrayList<Feature>();
    features.add(new SwaggerFeature());
    JAXRSServerFactoryBean serverFacBean = new JAXRSServerFactoryBean();
    serverFacBean.setAddress(address);
    serverFacBean.setServiceBeans(resourceObjects);
    serverFacBean.setFeatures(features);
    Server server = serverFacBean.create();
    InputStream in = null;
    try {
        String res = "";
        for (Class<?> resourceClass : resourceClasses) {
            com.wordnik.swagger.annotations.Api api = resourceClass.getAnnotation(com.wordnik.swagger.annotations.Api.class);
            if (api != null) {
                String apiPath = api.value();
                String serverAddress = server.getEndpoint().getEndpointInfo().getAddress();
                String apiDocs = serverAddress + "/api-docs";
                URL url = new URL(apiDocs + apiPath);
                in = url.openStream();
                res = res + getStringFromInputStream(in);
            }
        }
        generateJson(resourceClasses, res);
    } catch (Exception e) {
        throw new MojoExecutionException(e.getMessage(), e);
    } finally {
        server.stop();
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Server(org.apache.cxf.endpoint.Server) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) JAXRSServerFactoryBean(org.apache.cxf.jaxrs.JAXRSServerFactoryBean) SwaggerFeature(io.fabric8.cxf.endpoint.SwaggerFeature) Feature(org.apache.cxf.feature.Feature) URL(java.net.URL) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) SwaggerFeature(io.fabric8.cxf.endpoint.SwaggerFeature)

Example 10 with Feature

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

the class FabricManager method getProfileFeatures.

@Override
public Map<String, Object> getProfileFeatures(String versionId, String profileId) {
    Profile profile = profileService.getVersion(versionId).getRequiredProfile(profileId);
    Profile effectiveProfile = Profiles.getEffectiveProfile(fabricService, profileService.getOverlayProfile(profile));
    Map<String, Boolean> isParentFeature = new HashMap<String, Boolean>();
    for (String feature : profile.getFeatures()) {
        isParentFeature.put(feature, Boolean.FALSE);
    }
    for (String feature : effectiveProfile.getFeatures()) {
        if (isParentFeature.get(feature) == null) {
            isParentFeature.put(feature, Boolean.TRUE);
        }
    }
    Map<String, Object> rc = new HashMap<String, Object>();
    List<Map<String, Object>> featureDefs = new ArrayList<Map<String, Object>>();
    for (Map.Entry<String, Boolean> featureEntry : isParentFeature.entrySet()) {
        Map<String, Object> featureDef = new HashMap<String, Object>();
        featureDef.put("id", featureEntry.getKey());
        featureDef.put("isParentFeature", featureEntry.getValue());
        featureDefs.add(featureDef);
    }
    rc.put("featureDefinitions", featureDefs);
    List<Map<String, Object>> repositoryDefs = new ArrayList<Map<String, Object>>();
    for (String repo : effectiveProfile.getRepositories()) {
        Map<String, Object> repoDef = new HashMap<String, Object>();
        repoDef.put("id", repo);
        Closeable closeable = null;
        try {
            URL url = new URL(repo);
            InputStream os = url.openStream();
            closeable = os;
            InputStream is = new BufferedInputStream(url.openStream());
            closeable = is;
            char[] buffer = new char[8192];
            StringBuilder data = new StringBuilder();
            Reader in = new InputStreamReader(is, "UTF-8");
            closeable = in;
            for (; ; ) {
                int stat = in.read(buffer, 0, buffer.length);
                if (stat < 0) {
                    break;
                }
                data.append(buffer, 0, stat);
            }
            repoDef.put("data", data.toString());
        } catch (Throwable t) {
            repoDef.put("error", t.getMessage());
        } finally {
            try {
                if (closeable != null) {
                    closeable.close();
                }
            } catch (Throwable t) {
            // whatevs, I tried
            }
        }
        repositoryDefs.add(repoDef);
    }
    rc.put("repositoryDefinitions", repositoryDefs);
    return rc;
}
Also used : InputStreamReader(java.io.InputStreamReader) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) Closeable(java.io.Closeable) ArrayList(java.util.ArrayList) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) Profile(io.fabric8.api.Profile) URL(java.net.URL) BufferedInputStream(java.io.BufferedInputStream) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap)

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