Search in sources :

Example 21 with Repository

use of org.apache.karaf.features.Repository in project ddf by codice.

the class ApplicationImplTest method testMissingVersionInName.

@Test
public void testMissingVersionInName() throws Exception {
    String expectedName = "test-dependencies";
    Repository repo = mock(Repository.class);
    when(repo.getName()).thenReturn(expectedName);
    when(repo.getFeatures()).thenReturn(new Feature[0]);
    ApplicationImpl application = new ApplicationImpl(repo);
    assertThat("Application name is wrong", application.getName(), equalTo(expectedName));
    assertThat("Version number is wrong", application.getVersion(), equalTo("0.0.0"));
}
Also used : Repository(org.apache.karaf.features.Repository) Test(org.junit.Test)

Example 22 with Repository

use of org.apache.karaf.features.Repository in project ddf by codice.

the class ApplicationImplTest method testComplexApplicationName.

@Test
public void testComplexApplicationName() throws Exception {
    String name = "test-dependencies-1.2.3-1a";
    Repository repo = mock(Repository.class);
    when(repo.getName()).thenReturn(name);
    when(repo.getFeatures()).thenReturn(new Feature[0]);
    ApplicationImpl application = new ApplicationImpl(repo);
    assertThat("Application name is wrong", application.getName(), equalTo("test-dependencies"));
    assertThat("Version number is wrong", application.getVersion(), equalTo("1.2.3-1a"));
}
Also used : Repository(org.apache.karaf.features.Repository) Test(org.junit.Test)

Example 23 with Repository

use of org.apache.karaf.features.Repository in project karaf by apache.

the class FeaturesServiceImpl method registerListener.

// 
// Listeners support
// 
@Override
public void registerListener(FeaturesListener listener) {
    listeners.add(listener);
    try {
        Set<String> repositoriesList = new TreeSet<>();
        Map<String, Set<String>> installedFeatures = new TreeMap<>();
        synchronized (lock) {
            repositoriesList.addAll(state.repositories);
            installedFeatures.putAll(copy(state.installedFeatures));
        }
        for (String uri : repositoriesList) {
            Repository repository = repositories.create(URI.create(uri), false);
            listener.repositoryEvent(new RepositoryEvent(repository, RepositoryEvent.EventType.RepositoryAdded, true));
        }
        for (Map.Entry<String, Set<String>> entry : installedFeatures.entrySet()) {
            for (String id : entry.getValue()) {
                Feature feature = org.apache.karaf.features.internal.model.Feature.valueOf(id);
                listener.featureEvent(new FeatureEvent(FeatureEvent.EventType.FeatureInstalled, feature, entry.getKey(), true));
            }
        }
    } catch (Exception e) {
        LOGGER.error("Error notifying listener about the current state", e);
    }
}
Also used : EnumSet(java.util.EnumSet) Collectors.toSet(java.util.stream.Collectors.toSet) Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) TreeMap(java.util.TreeMap) Feature(org.apache.karaf.features.Feature) BundleException(org.osgi.framework.BundleException) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) JAXBException(javax.xml.bind.JAXBException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) Repository(org.apache.karaf.features.Repository) FeatureEvent(org.apache.karaf.features.FeatureEvent) TreeSet(java.util.TreeSet) RepositoryEvent(org.apache.karaf.features.RepositoryEvent) StateStorage.toStringStringSetMap(org.apache.karaf.features.internal.service.StateStorage.toStringStringSetMap) Map(java.util.Map) HashMap(java.util.HashMap) Collections.emptyMap(java.util.Collections.emptyMap) TreeMap(java.util.TreeMap)

Example 24 with Repository

use of org.apache.karaf.features.Repository in project karaf by apache.

the class FeaturesServiceImpl method removeRepository.

@Override
public void removeRepository(URI uri, boolean uninstall) throws Exception {
    // This will also ensure the cache is loaded
    Repository repo = getRepository(uri);
    if (repo == null) {
        return;
    }
    Map<String, Set<String>> reqsToRemove;
    Set<String> features;
    synchronized (lock) {
        getFeatureCache();
        features = new HashSet<>();
        for (Set<String> reqs : state.requirements.values()) {
            features.addAll(reqs);
        }
        Set<Repository> repos = new HashSet<>();
        for (String r : state.repositories) {
            if (!uri.toString().equals(r)) {
                Repository rep = repositories.getRepository(r);
                repos.addAll(repositories.getRepositoryClosure(rep));
            }
        }
        for (Repository rep : repos) {
            for (Feature f : rep.getFeatures()) {
                features.remove(new FeatureReq(f).toRequirement());
            }
        }
        reqsToRemove = new HashMap<>();
        for (Map.Entry<String, Set<String>> entry : state.requirements.entrySet()) {
            Set<String> reqs = new HashSet<>(entry.getValue());
            reqs.retainAll(features);
            if (!reqs.isEmpty()) {
                reqsToRemove.put(entry.getKey(), reqs);
            }
        }
    }
    if (!features.isEmpty()) {
        if (uninstall) {
            removeRequirements(reqsToRemove, EnumSet.noneOf(Option.class));
        } else {
            throw new IllegalStateException("The following features are required from the repository: " + String.join(", ", features));
        }
    }
    synchronized (lock) {
        // Remove repo
        if (!state.repositories.remove(uri.toString())) {
            return;
        }
        // Clean cache
        featureCache = null;
        repositories.removeRepository(uri);
        saveState();
    }
    callListeners(new RepositoryEvent(repo, RepositoryEvent.EventType.RepositoryRemoved, false));
}
Also used : EnumSet(java.util.EnumSet) Collectors.toSet(java.util.stream.Collectors.toSet) Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Feature(org.apache.karaf.features.Feature) Repository(org.apache.karaf.features.Repository) RepositoryEvent(org.apache.karaf.features.RepositoryEvent) StateStorage.toStringStringSetMap(org.apache.karaf.features.internal.service.StateStorage.toStringStringSetMap) Map(java.util.Map) HashMap(java.util.HashMap) Collections.emptyMap(java.util.Collections.emptyMap) TreeMap(java.util.TreeMap) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 25 with Repository

use of org.apache.karaf.features.Repository in project karaf by apache.

the class FeaturesServiceMBeanImpl method getRepositories.

/**
 * {@inheritDoc}
 */
public TabularData getRepositories() throws Exception {
    try {
        List<Repository> allRepositories = Arrays.asList(featuresService.listRepositories());
        ArrayList<JmxRepository> repositories = new ArrayList<>();
        for (Repository repository : allRepositories) {
            try {
                repositories.add(new JmxRepository(repository));
            } catch (Throwable t) {
                t.printStackTrace();
            }
        }
        return JmxRepository.tableFrom(repositories);
    } catch (Throwable t) {
        t.printStackTrace();
        return null;
    }
}
Also used : JmxRepository(org.apache.karaf.features.management.codec.JmxRepository) Repository(org.apache.karaf.features.Repository) JmxRepository(org.apache.karaf.features.management.codec.JmxRepository)

Aggregations

Repository (org.apache.karaf.features.Repository)84 Test (org.junit.Test)52 HashSet (java.util.HashSet)51 FeaturesService (org.apache.karaf.features.FeaturesService)44 Feature (org.apache.karaf.features.Feature)38 ApplicationService (org.codice.ddf.admin.application.service.ApplicationService)37 URI (java.net.URI)20 Application (org.codice.ddf.admin.application.service.Application)20 LinkedHashSet (java.util.LinkedHashSet)9 ArrayList (java.util.ArrayList)8 ApplicationServiceException (org.codice.ddf.admin.application.service.ApplicationServiceException)8 Logger (org.slf4j.Logger)7 Appender (ch.qos.logback.core.Appender)6 IOException (java.io.IOException)6 HashMap (java.util.HashMap)6 ArgumentMatcher (org.mockito.ArgumentMatcher)6 Mockito.anyString (org.mockito.Mockito.anyString)6 EnumSet (java.util.EnumSet)5 Map (java.util.Map)5 TreeMap (java.util.TreeMap)4