use of org.apache.karaf.features.Repository in project karaf by apache.
the class FeaturesServiceMBeanImpl method removeRepository.
public void removeRepository(String uri, boolean uninstall) throws Exception {
List<URI> uris = new ArrayList<>();
Pattern pattern = Pattern.compile(uri);
for (Repository repository : featuresService.listRepositories()) {
if (repository.getName() != null && !repository.getName().isEmpty()) {
// first regex on the repository name
Matcher nameMatcher = pattern.matcher(repository.getName());
if (nameMatcher.matches()) {
uris.add(repository.getURI());
} else {
// fallback to repository URI regex
Matcher uriMatcher = pattern.matcher(repository.getURI().toString());
if (uriMatcher.matches()) {
uris.add(repository.getURI());
}
}
} else {
// repository name is not defined, fallback to repository URI regex
Matcher uriMatcher = pattern.matcher(repository.getURI().toString());
if (uriMatcher.matches()) {
uris.add(repository.getURI());
}
}
}
for (URI u : uris) {
featuresService.removeRepository(u, uninstall);
}
}
use of org.apache.karaf.features.Repository in project karaf by apache.
the class FeaturesServiceMBeanImpl method refreshRepository.
public void refreshRepository(String uri) throws Exception {
if (uri == null || uri.isEmpty()) {
for (Repository repository : featuresService.listRepositories()) {
featuresService.refreshRepository(repository.getURI());
}
} else {
// regex support
Pattern pattern = Pattern.compile(uri);
List<URI> uris = new ArrayList<>();
for (Repository repository : featuresService.listRepositories()) {
URI u = repository.getURI();
Matcher matcher = pattern.matcher(u.toString());
if (matcher.matches()) {
uris.add(u);
}
}
for (URI u : uris) {
featuresService.refreshRepository(u);
}
}
}
use of org.apache.karaf.features.Repository in project ddf by codice.
the class ApplicationServiceImplTest method testGetApplicationStatusReturnsFailedStatusWhenOneFeatureConsistingOfInactiveBundlesIsNotInstalled.
/**
* Test method for
* {@link ApplicationService#getApplicationStatus(Application)}
* <p>
* Verifies method returns an {@link ApplicationState#FAILED } state for an
* {@code Application} under the following conditions:
* <p>
* <ul>
* <li>Main feature is installed</li>
* <li>One dependency feature is not installed</li>
* <li>Dependency feature that is not installed contains Bundle(s) whose
* states and extended states are inactive</li>
* </ul>
*
* @throws Exception
*/
@Test
public void testGetApplicationStatusReturnsFailedStatusWhenOneFeatureConsistingOfInactiveBundlesIsNotInstalled() throws Exception {
Set<Repository> mainFeaturesRepoSet = new HashSet<Repository>();
Set<Feature> notInstalledFeatures = new HashSet<Feature>();
Set<BundleInfo> inactiveBundles = new HashSet<BundleInfo>();
for (Feature feature : mainFeatureRepo2.getFeatures()) {
if (feature.getName().equals(TEST_MAIN_FEATURES_2_MAIN_FEATURE_NAME)) {
notInstalledFeatures.add(feature);
inactiveBundles.addAll(feature.getBundles());
break;
}
}
assertEquals("Feature is not included in repository the expected number of times", 1, notInstalledFeatures.size());
assertTrue("No bundles included in Feature", inactiveBundles.size() > 0);
mainFeaturesRepoSet.add(mainFeatureRepo2);
FeaturesService featuresService = createMockFeaturesService(mainFeaturesRepoSet, notInstalledFeatures, inactiveBundles);
when(bundleContext.getService(mockFeatureRef)).thenReturn(featuresService);
ApplicationService appService = createPermittedApplicationServiceImpl();
assertEquals(ApplicationService.class.getName() + " does not contain the expected number of Applications", 1, appService.getApplications().size());
assertEquals(mainFeatureRepo2.getName() + " returned unexpected state", ApplicationState.FAILED, appService.getApplicationStatus(appService.getApplications().toArray(new Application[] {})[0]).getState());
}
use of org.apache.karaf.features.Repository in project ddf by codice.
the class ApplicationServiceImplTest method testRemoveApplicationUninstallAllFeaturesException.
/**
* Tests the {@link ApplicationServiceImpl#removeApplication(Application)} method
* for the case where an exception is thrown within uninstallAllFeatures(Application)
*
* @throws Exception
*/
// TODO RAP 29 Aug 16: DDF-2443 - Fix test to not depend on specific log output
@Test
public void testRemoveApplicationUninstallAllFeaturesException() throws Exception {
ch.qos.logback.classic.Logger root = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
final Appender mockAppender = mock(Appender.class);
when(mockAppender.getName()).thenReturn("MOCK");
root.addAppender(mockAppender);
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();
Application testApp = mock(ApplicationImpl.class);
Feature testFeature1 = mock(Feature.class);
Feature testFeature2 = mock(Feature.class);
Set<Feature> featureSet = new HashSet<>();
featureSet.add(testFeature1);
featureSet.add(testFeature2);
when(featuresService.isInstalled(any(Feature.class))).thenReturn(true);
when(testApp.getFeatures()).thenReturn(featureSet);
doThrow(new Exception()).when(featuresService).uninstallFeature(anyString(), anyString(), any(EnumSet.class));
appService.removeApplication(testApp);
verify(mockAppender, times(2)).doAppend(argThat(new ArgumentMatcher() {
@Override
public boolean matches(final Object argument) {
return ((LoggingEvent) argument).getFormattedMessage().contains(UNINSTALL_FAIL);
}
}));
}
use of org.apache.karaf.features.Repository in project ddf by codice.
the class ApplicationServiceImplTest method testRemoveApplicationStringParam.
/**
* Tests the {@link ApplicationServiceImpl#removeApplication(String)} method
*
* @throws Exception
*/
@Test
public void testRemoveApplicationStringParam() throws Exception {
Set<Repository> activeRepos = new HashSet<Repository>(Arrays.asList(mainFeatureRepo, noMainFeatureRepo1));
FeaturesService featuresService = createMockFeaturesService(activeRepos, null, null);
when(bundleContext.getService(mockFeatureRef)).thenReturn(featuresService);
ApplicationService appService = createPermittedApplicationServiceImpl();
Feature[] featureList = mainFeatureRepo.getFeatures();
appService.removeApplication(TEST_APP);
verify(featuresService).uninstallFeature(featureList[0].getName(), featureList[0].getVersion(), EnumSet.of(Option.NoAutoRefreshBundles));
verify(featuresService).uninstallFeature(featureList[1].getName(), featureList[1].getVersion(), EnumSet.of(Option.NoAutoRefreshBundles));
}
Aggregations