use of org.apache.karaf.features.FeaturesService in project ddf by codice.
the class ApplicationServiceImplTest method testStopApplicationStringParamASE.
/**
* Tests the {@link ApplicationServiceImpl#stopApplication(String)} method
* for the case where the application cannot be found
*/
@Test(expected = ApplicationServiceException.class)
public void testStopApplicationStringParamASE() throws Exception {
Set<Repository> activeRepos = new HashSet<Repository>(Arrays.asList(mainFeatureRepo, noMainFeatureRepo1, noMainFeatureRepo2));
FeaturesService featuresService = createMockFeaturesService(activeRepos, null, null);
when(bundleContext.getService(mockFeatureRef)).thenReturn(featuresService);
ApplicationService appService = createPermittedApplicationServiceImpl();
appService.stopApplication("");
}
use of org.apache.karaf.features.FeaturesService in project opennms by OpenNMS.
the class KarafExtender method init.
public void init() throws InterruptedException {
Objects.requireNonNull(m_configurationAdmin, "configurationAdmin");
Objects.requireNonNull(m_mavenResolver, "mavenResolver");
Objects.requireNonNull(m_featuresService, "featuresService");
List<Repository> repositories;
try {
repositories = getRepositories();
} catch (IOException e) {
LOG.error("Failed to retrieve the list of repositories. Aborting.", e);
return;
}
// Prepend the featuresBoot from the repository definitions
List<Feature> featuresBoot = repositories.stream().flatMap(r -> r.getFeaturesBoot().stream()).collect(Collectors.toList());
try {
featuresBoot.addAll(getFeaturesBoot());
} catch (IOException e) {
LOG.error("Failed to retrieve the list of features to boot. Aborting.", e);
return;
}
// Filter the list of features
filterFeatures(featuresBoot);
// Build a comma separated list of our Maven repositories
final StringBuilder mavenReposSb = new StringBuilder();
for (Repository repository : repositories) {
if (mavenReposSb.length() != 0) {
mavenReposSb.append(",");
}
mavenReposSb.append(repository.toMavenUri());
}
final String mavenRepos = mavenReposSb.toString();
LOG.info("Updating Maven repositories to include: {}", mavenRepos);
try {
final Configuration config = m_configurationAdmin.getConfiguration(PAX_MVN_PID);
if (config == null) {
throw new IOException("The OSGi configuration (admin) registry was found for pid " + PAX_MVN_PID + ", but a configuration could not be located/generated. This shouldn't happen.");
}
final Dictionary<String, Object> props = config.getProperties();
if (!mavenRepos.equals(props.get(PAX_MVN_REPOSITORIES))) {
props.put(PAX_MVN_REPOSITORIES, mavenRepos);
config.update(props);
}
} catch (IOException e) {
LOG.error("Failed to update the list of Maven repositories to '{}'. Aborting.", mavenRepos, e);
return;
}
// The configuration update is async, we need to wait for the feature URLs to be resolvable before we use them
LOG.info("Waiting up-to 30 seconds for the Maven repositories to be updated...");
// Attempting to resolve a missing features writes an exception to the log
// We sleep fix a fixed amount of time before our first try in order to help minimize the logged
// exceptions, even if we catch them
Thread.sleep(2000);
for (int i = 28; i > 0 && !canResolveAllFeatureUris(repositories); i--) {
Thread.sleep(1000);
}
for (Repository repository : repositories) {
for (URI featureUri : repository.getFeatureUris()) {
try {
LOG.info("Adding feature repository: {}", featureUri);
m_featuresService.addRepository(featureUri);
} catch (Exception e) {
LOG.error("Failed to add feature repository '{}'. Skipping.", featureUri, e);
}
}
}
final Set<String> featuresToInstall = featuresBoot.stream().map(f -> f.getVersion() != null ? f.getName() + "/" + f.getVersion() : f.getName()).collect(Collectors.toCollection(LinkedHashSet::new));
// Because of the fix for the following issue, we need to call the
// feature installation in another thread since this method is invoked
// during a feature installation itself and feature installations are
// now single-threaded.
//
// https://issues.apache.org/jira/browse/KARAF-3798
// https://github.com/apache/karaf/pull/138
//
CompletableFuture.runAsync(new Runnable() {
@Override
public void run() {
try {
LOG.info("Installing features: {}", featuresToInstall);
m_featuresService.installFeatures(featuresToInstall, EnumSet.noneOf(Option.class));
} catch (Exception e) {
LOG.error("Failed to install one or more features.", e);
}
}
});
}
use of org.apache.karaf.features.FeaturesService in project karaf by apache.
the class FeaturesServiceImplTest method testRemoveRepo2.
@Test
public void testRemoveRepo2() throws Exception {
final FeaturesService featureService = createTestFeatureService();
URI repoA = URI.create("custom:remove/a.xml");
URI repoB = URI.create("custom:remove/b.xml");
featureService.addRepository(repoA);
featureService.addRepository(repoB);
Feature a1Feature = featureService.getFeature("a1");
installFeature(featureService, a1Feature);
Feature b1Feature = featureService.getFeature("b1");
installFeature(featureService, b1Feature);
featureService.removeRepository(repoA);
assertNotInstalled(featureService, a1Feature);
assertInstalled(featureService, b1Feature);
}
use of org.apache.karaf.features.FeaturesService in project karaf by apache.
the class Activator method doStart.
@Override
protected void doStart() throws Exception {
FeaturesService service = getTrackedService(FeaturesService.class);
if (service == null) {
return;
}
Hashtable<String, Object> props = new Hashtable<>();
props.put("url.handler.protocol", "feature");
FeatureURLHandler handler = new FeatureURLHandler();
register(URLStreamHandlerService.class, handler, props);
listener = new FeatureDeploymentListener();
listener.setFeaturesService(service);
listener.setBundleContext(bundleContext);
listener.init();
register(new Class[] { ArtifactUrlTransformer.class, ArtifactListener.class }, listener);
}
use of org.apache.karaf.features.FeaturesService in project ddf by codice.
the class ProfileInstallCommandTest method testPostInstallWithInstallerInstalled.
@Test
public void testPostInstallWithInstallerInstalled() throws Exception {
Feature installerFeature = createMockFeature("admin-modules-installer");
this.featuresService = mock(FeaturesService.class);
when(featuresService.getFeature(anyString())).thenReturn(installerFeature);
when(featuresService.isInstalled(installerFeature)).thenReturn(true);
profileInstallCommand.profileName = "invalidStopBundles";
profileInstallCommand.doExecute(applicationService, featuresService, bundleService);
verify(featuresService).uninstallFeature(eq("admin-modules-installer"), eq(NO_AUTO_REFRESH));
}
Aggregations