Search in sources :

Example 11 with Dependency

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

the class JmxFeature method getDependencyIdentifierTable.

private static TabularData getDependencyIdentifierTable(List<Dependency> features) throws OpenDataException {
    TabularDataSupport table = new TabularDataSupport(FEATURE_IDENTIFIER_TABLE);
    Set<String> featureSet = new HashSet<>();
    for (Dependency feature : features) {
        if (featureSet.contains(feature.getName() + feature.getVersion())) {
            continue;
        } else {
            featureSet.add(feature.getName() + feature.getVersion());
        }
        String[] itemNames = new String[] { FeaturesServiceMBean.FEATURE_NAME, FeaturesServiceMBean.FEATURE_VERSION };
        Object[] itemValues = new Object[] { feature.getName(), feature.getVersion() };
        CompositeData ident = new CompositeDataSupport(FEATURE_IDENTIFIER, itemNames, itemValues);
        table.put(ident);
    }
    return table;
}
Also used : TabularDataSupport(javax.management.openmbean.TabularDataSupport) CompositeData(javax.management.openmbean.CompositeData) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) Dependency(org.apache.karaf.features.Dependency) HashSet(java.util.HashSet)

Example 12 with Dependency

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

the class KarServiceImpl method getFeatures.

private Set<Feature> getFeatures(Map<String, Feature> featureMap, List<String> features, int depth) {
    Set<Feature> featureSet = new HashSet<>();
    if (depth > 5) {
        // Break after some recursions to avoid endless loops 
        return featureSet;
    }
    if (features == null) {
        featureSet.addAll(featureMap.values());
        return featureSet;
    }
    for (String featureName : features) {
        Feature feature = featureMap.get(featureName);
        if (feature == null) {
            System.out.println("Feature " + featureName + " not found in repository.");
        //throw new RuntimeException();
        } else {
            featureSet.add(feature);
            List<Dependency> deps = feature.getDependencies();
            List<String> depNames = new ArrayList<>();
            for (Dependency dependency : deps) {
                depNames.add(dependency.getName());
            }
            featureSet.addAll(getFeatures(featureMap, depNames, depth++));
        }
    }
    return featureSet;
}
Also used : ArrayList(java.util.ArrayList) Dependency(org.apache.karaf.features.Dependency) Feature(org.apache.karaf.features.Feature) HashSet(java.util.HashSet)

Example 13 with Dependency

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

the class KarServiceImpl method install.

@Override
public void install(URI karUri, File repoDir, File resourceDir) throws Exception {
    busy.set(true);
    try {
        Kar kar = new Kar(karUri);
        kar.extract(repoDir, resourceDir);
        writeToFile(kar.getFeatureRepos(), new File(repoDir, FEATURE_CONFIG_FILE));
        for (URI uri : kar.getFeatureRepos()) {
            addToFeaturesRepositories(uri);
        }
        if (kar.isShouldInstallFeatures()) {
            List<URI> featureRepos = kar.getFeatureRepos();
            Dependency missingDependency = findMissingDependency(featureRepos);
            if (missingDependency == null) {
                installFeatures(featureRepos);
            } else {
                LOGGER.warn("Feature dependency {} is not available. Kar deployment postponed to see if it is about to be deployed", missingDependency);
                unsatisfiedKars.add(kar);
                if (delayedDeployerThread == null) {
                    delayedDeployerThread = new DelayedDeployerThread();
                    delayedDeployerThread.start();
                }
            }
        }
        if (!unsatisfiedKars.isEmpty()) {
            for (Iterator<Kar> iterator = unsatisfiedKars.iterator(); iterator.hasNext(); ) {
                Kar delayedKar = iterator.next();
                if (findMissingDependency(delayedKar.getFeatureRepos()) == null) {
                    LOGGER.info("Dependencies of kar {} are now satisfied. Installing", delayedKar.getKarName());
                    iterator.remove();
                    installFeatures(delayedKar.getFeatureRepos());
                }
            }
        }
        if (unsatisfiedKars.isEmpty()) {
            if (delayedDeployerThread != null) {
                delayedDeployerThread.cancel();
            }
            delayedDeployerThread = null;
        }
    } finally {
        busy.set(false);
    }
}
Also used : Dependency(org.apache.karaf.features.Dependency) File(java.io.File) URI(java.net.URI)

Example 14 with Dependency

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

the class ProfileInstallCommandTest method createMockDependency.

private Dependency createMockDependency(String name) {
    Dependency dependency = mock(Dependency.class);
    when(dependency.getName()).thenReturn(name);
    when(dependency.getVersion()).thenReturn("0.0.0");
    return dependency;
}
Also used : Dependency(org.apache.karaf.features.Dependency)

Example 15 with Dependency

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

the class ApplicationServiceImpl method startApplication.

@Override
public synchronized void startApplication(Application application) throws ApplicationServiceException {
    try {
        LOGGER.debug("Starting Application {} - {}", application.getName(), application.getVersion());
        Set<Feature> autoInstallFeatures = application.getAutoInstallFeatures();
        if (!autoInstallFeatures.isEmpty()) {
            Set<String> autoFeatureNames = autoInstallFeatures.stream().map(Feature::getName).collect(Collectors.toSet());
            for (Feature feature : autoInstallFeatures) {
                if (featuresService.isInstalled(feature)) {
                    autoFeatureNames.remove(feature.getName());
                } else {
                    for (Dependency dependency : feature.getDependencies()) {
                        if (!application.getName().equals(dependency.getName()) && getApplicationNames().contains(dependency.getName())) {
                            if (!isApplicationStarted(getApplication(dependency.getName()))) {
                                startApplication(dependency.getName());
                            }
                            autoFeatureNames.remove(dependency.getName());
                        }
                    }
                }
            }
            if (!autoFeatureNames.isEmpty()) {
                featuresService.installFeatures(autoFeatureNames, EnumSet.of(Option.NoAutoRefreshBundles));
                waitForApplication(application);
            }
        }
    } catch (Exception e) {
        throw new ApplicationServiceException("Could not start application " + application.getName() + " due to errors.", e);
    }
}
Also used : ApplicationServiceException(org.codice.ddf.admin.application.service.ApplicationServiceException) Dependency(org.apache.karaf.features.Dependency) Feature(org.apache.karaf.features.Feature) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) InvocationTargetException(java.lang.reflect.InvocationTargetException) SecurityServiceException(ddf.security.service.SecurityServiceException) ApplicationServiceException(org.codice.ddf.admin.application.service.ApplicationServiceException)

Aggregations

Dependency (org.apache.karaf.features.Dependency)19 Feature (org.apache.karaf.features.Feature)14 HashSet (java.util.HashSet)6 ArrayList (java.util.ArrayList)5 BundleInfo (org.apache.karaf.features.BundleInfo)4 Conditional (org.apache.karaf.features.Conditional)3 FeaturesService (org.apache.karaf.features.FeaturesService)3 Test (org.junit.Test)3 SecurityServiceException (ddf.security.service.SecurityServiceException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Map (java.util.Map)2 VersionRange (org.apache.felix.utils.version.VersionRange)2 Repository (org.apache.karaf.features.Repository)2 ResourceUtils.addIdentityRequirement (org.apache.karaf.features.internal.resolver.ResourceUtils.addIdentityRequirement)2 ResourceUtils.toFeatureRequirement (org.apache.karaf.features.internal.resolver.ResourceUtils.toFeatureRequirement)2 Application (org.codice.ddf.admin.application.service.Application)2 ApplicationServiceException (org.codice.ddf.admin.application.service.ApplicationServiceException)2 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)2 Requirement (org.osgi.resource.Requirement)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1