Search in sources :

Example 71 with Repository

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

the class FeaturesServiceImpl method refreshFeatures.

@Override
public void refreshFeatures(EnumSet<Option> options) throws Exception {
    Set<URI> uris = new LinkedHashSet<>();
    for (Repository r : this.repositories.listRepositories()) {
        uris.add(r.getURI());
    }
    this.refreshRepositories(uris);
    this.featuresProcessor = new FeaturesProcessorImpl(cfg);
    this.repositories = new RepositoryCacheImpl(featuresProcessor);
    State state = copyState();
    doProvisionInThread(state.requirements, emptyMap(), state, getFeaturesById(), options);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Repository(org.apache.karaf.features.Repository) FeatureState(org.apache.karaf.features.FeatureState) URI(java.net.URI)

Example 72 with Repository

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

the class FeaturesServiceImpl method addRepository.

@Override
public void addRepository(URI uri, boolean install) throws Exception {
    Repository repository = repositories.create(uri, true);
    synchronized (lock) {
        repositories.addRepository(repository);
        featureCache = null;
        // Add repo
        if (!state.repositories.add(uri.toString())) {
            return;
        }
        saveState();
    }
    callListeners(new RepositoryEvent(repository, RepositoryEvent.EventType.RepositoryAdded, false));
    // install the features in the repo
    if (install) {
        HashSet<String> features = new HashSet<>();
        for (Feature feature : repository.getFeatures()) {
            features.add(feature.getId());
        }
        installFeatures(features, EnumSet.noneOf(FeaturesService.Option.class));
    }
}
Also used : Repository(org.apache.karaf.features.Repository) RepositoryEvent(org.apache.karaf.features.RepositoryEvent) Feature(org.apache.karaf.features.Feature) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 73 with Repository

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

the class FeaturesServiceImpl method getFeatureCache.

/**
 * Should not be called while holding a lock.
 * @return map from feature name to map from feature version to Feature
 */
protected Map<String, Map<String, Feature>> getFeatureCache() throws Exception {
    Set<String> uris;
    synchronized (lock) {
        if (featureCache != null) {
            return featureCache;
        }
        uris = new TreeSet<>(state.repositories);
    }
    // the outer map's key is feature name, the inner map's key is feature version
    Map<String, Map<String, Feature>> map = new HashMap<>();
    // Two phase load:
    // * first load dependent repositories
    Set<String> loaded = new HashSet<>();
    Queue<String> toLoad = new ArrayDeque<>(uris);
    while (!toLoad.isEmpty()) {
        String uri = toLoad.remove();
        Repository repo;
        synchronized (lock) {
            repo = repositories.getRepository(uri);
        }
        try {
            if (repo == null) {
                repo = repositories.create(URI.create(uri), false);
                synchronized (lock) {
                    repositories.addRepository(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);
        }
    }
    List<Repository> repos;
    synchronized (lock) {
        repos = Arrays.asList(repositories.listRepositories());
    }
    // * then load all features
    for (Repository repo : repos) {
        for (Feature f : repo.getFeatures()) {
            Map<String, Feature> versionMap = map.computeIfAbsent(f.getName(), key -> new HashMap<>());
            versionMap.put(f.getVersion(), f);
        }
    }
    synchronized (lock) {
        if (uris.equals(state.repositories)) {
            featureCache = map;
        }
    }
    return map;
}
Also used : HashMap(java.util.HashMap) URI(java.net.URI) Feature(org.apache.karaf.features.Feature) ArrayDeque(java.util.ArrayDeque) 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) 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 74 with Repository

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

the class FeaturesValidationTest method testNs12Unmarshall.

@Test
public void testNs12Unmarshall() throws Exception {
    Repository features = unmarshalAndValidate("f06.xml");
    assertNotNull(features);
}
Also used : Repository(org.apache.karaf.features.Repository) Test(org.junit.Test)

Example 75 with Repository

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

the class FeaturesValidationTest method testNs10NoName.

@Test
public void testNs10NoName() throws Exception {
    Repository features = unmarshalAndValidate("f03.xml");
    assertNotNull(features);
}
Also used : Repository(org.apache.karaf.features.Repository) Test(org.junit.Test)

Aggregations

Repository (org.apache.karaf.features.Repository)85 Test (org.junit.Test)53 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)21 Application (org.codice.ddf.admin.application.service.Application)20 ArrayList (java.util.ArrayList)8 LinkedHashSet (java.util.LinkedHashSet)8 ApplicationServiceException (org.codice.ddf.admin.application.service.ApplicationServiceException)8 Logger (org.slf4j.Logger)7 Appender (ch.qos.logback.core.Appender)6 HashMap (java.util.HashMap)6 ArgumentMatcher (org.mockito.ArgumentMatcher)6 Mockito.anyString (org.mockito.Mockito.anyString)6 IOException (java.io.IOException)5 EnumSet (java.util.EnumSet)5 Map (java.util.Map)5 TreeMap (java.util.TreeMap)4