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;
}
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);
}
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);
}
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();
}
}
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;
}
Aggregations