use of org.apache.karaf.features.Repository in project karaf by apache.
the class RepositoryCache method loadDependent.
public synchronized void loadDependent(Set<String> topLevelRepoUris) {
Set<String> loaded = new HashSet<>();
List<String> toLoad = new ArrayList<>(topLevelRepoUris);
while (!toLoad.isEmpty()) {
String uri = toLoad.remove(0);
Repository repo = repositoryCache.get(uri);
try {
if (repo == null) {
repo = load(URI.create(uri));
repositoryCache.put(uri, repo);
}
if (loaded.add(uri)) {
for (URI u : repo.getRepositories()) {
toLoad.add(u.toString());
}
}
} catch (Exception e) {
LOGGER.warn("Can't load features repository {}", uri, e);
}
}
}
use of org.apache.karaf.features.Repository in project karaf by apache.
the class FeaturesPlugin method writeJSON.
private void writeJSON(final PrintWriter pw) throws IOException {
final List<Repository> repositories = this.getRepositories();
final List<ExtendedFeature> features = this.getFeatures(repositories);
final String statusLine = this.getStatusLine(features);
final JSONWriter jw = new JSONWriter(pw);
jw.object();
jw.key("status");
jw.value(statusLine);
jw.key("repositories");
jw.array();
for (Repository r : repositories) {
jw.object();
jw.key("name");
String name = "";
if (r.getName() != null)
name = r.getName();
jw.value(name);
jw.key("url");
String uri = r.getURI().toString();
jw.value(uri);
jw.key("actions");
jw.array();
boolean enable = true;
if (uri.startsWith("bundle")) {
enable = false;
}
action(jw, enable, "refreshRepository", "Refresh", "refresh");
action(jw, enable, "removeRepository", "Remove", "delete");
jw.endArray();
jw.endObject();
}
jw.endArray();
jw.key("features");
jw.array();
for (ExtendedFeature f : features) {
featureInfo(jw, f);
}
jw.endArray();
jw.endObject();
}
use of org.apache.karaf.features.Repository in project ddf by codice.
the class ApplicationServiceImplTest method testRemoveApplicationApplicationServiceException.
/**
* Tests the {@link ApplicationServiceImpl#removeApplication(Application)} method
* for the case where an ApplicationServiceException is thrown within uninstallAllFeatures(..)
*
* @throws Exception
*/
// TODO RAP 29 Aug 16: DDF-2443 - Fix test to not depend on specific log output
@Test
public void testRemoveApplicationApplicationServiceException() 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);
doThrow(new ApplicationServiceException()).when(testApp).getFeatures();
appService.removeApplication(testApp);
verify(mockAppender).doAppend(argThat(new ArgumentMatcher() {
@Override
public boolean matches(final Object argument) {
return ((LoggingEvent) argument).getFormattedMessage().contains(UNINSTALL_ASE);
}
}));
}
use of org.apache.karaf.features.Repository in project ddf by codice.
the class ApplicationServiceImplTest method testFindApplicationFeaturesException.
/**
* Tests the {@link ApplicationServiceImpl#findApplicationFeatures(String)} method
* for the case where an exception is thrown by the featuresService
*
* @throws Exception
*/
// TODO RAP 29 Aug 16: DDF-2443 - Fix test to not depend on specific log output
@Test
public void testFindApplicationFeaturesException() 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 = new ApplicationServiceImpl(bundleStateServices) {
@Override
protected BundleContext getContext() {
return bundleContext;
}
};
doThrow(new NullPointerException()).when(featuresService).listRepositories();
appService.findApplicationFeatures(TEST_APP_NAME);
verify(mockAppender).doAppend(argThat(new ArgumentMatcher() {
@Override
public boolean matches(final Object argument) {
return ((LoggingEvent) argument).getFormattedMessage().contains(NO_REPO_FEATURES);
}
}));
}
use of org.apache.karaf.features.Repository in project ddf by codice.
the class ApplicationServiceImplTest method testGetApplicationStatusCoreFeature.
@Test
public void testGetApplicationStatusCoreFeature() throws Exception {
Set<Repository> activeRepos = new HashSet<Repository>(Arrays.asList(createRepo(TEST_PREREQ_MAIN_FEATURE_FILE_NAME)));
FeaturesService featuresService = createMockFeaturesService(activeRepos, null, null);
when(bundleContext.getService(mockFeatureRef)).thenReturn(featuresService);
when(featuresService.isInstalled(any())).thenReturn(false);
ApplicationService appService = createPermittedApplicationServiceImpl();
Set<Application> applications = appService.getApplications();
assertEquals(1, applications.size());
for (Application curApp : applications) {
ApplicationStatus status = appService.getApplicationStatus(curApp);
assertEquals(curApp, status.getApplication());
assertEquals(ApplicationState.INACTIVE, status.getState());
assertTrue(status.getErrorBundles().isEmpty());
assertTrue(status.getErrorFeatures().isEmpty());
}
}
Aggregations