Search in sources :

Example 1 with Dependency

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

the class Subsystem method doBuild.

private void doBuild(Collection<Feature> features, boolean mandatory) throws Exception {
    for (Subsystem child : children) {
        child.doBuild(features, true);
    }
    if (feature != null) {
        for (Dependency dep : feature.getDependencies()) {
            Subsystem ss = this;
            while (!ss.isAcceptDependencies()) {
                ss = ss.getParent();
            }
            ss.requireFeature(dep.getName(), dep.getVersion(), false);
        }
        for (Conditional cond : feature.getConditional()) {
            Feature fcond = cond.asFeature();
            String ssName = this.name + "#" + (fcond.hasVersion() ? fcond.getName() + "-" + fcond.getVersion() : fcond.getName());
            Subsystem fs = getChild(ssName);
            if (fs == null) {
                fs = new Subsystem(ssName, fcond, this, true);
                fs.doBuild(features, false);
                installable.add(fs);
                children.add(fs);
            }
        }
    }
    List<Requirement> processed = new ArrayList<>();
    while (true) {
        List<Requirement> requirements = getRequirements(IDENTITY_NAMESPACE);
        requirements.addAll(dependentFeatures);
        requirements.removeAll(processed);
        if (requirements.isEmpty()) {
            break;
        }
        for (Requirement requirement : requirements) {
            String name = (String) requirement.getAttributes().get(IDENTITY_NAMESPACE);
            String type = (String) requirement.getAttributes().get(CAPABILITY_TYPE_ATTRIBUTE);
            VersionRange range = (VersionRange) requirement.getAttributes().get(CAPABILITY_VERSION_ATTRIBUTE);
            if (TYPE_FEATURE.equals(type)) {
                for (Feature feature : features) {
                    if (feature.getName().equals(name) && (range == null || range.contains(VersionTable.getVersion(feature.getVersion())))) {
                        if (feature != this.feature) {
                            String ssName = this.name + "#" + (feature.hasVersion() ? feature.getName() + "-" + feature.getVersion() : feature.getName());
                            Subsystem fs = getChild(ssName);
                            if (fs == null) {
                                fs = new Subsystem(ssName, feature, this, mandatory && !SubsystemResolveContext.isOptional(requirement));
                                fs.build(features);
                                installable.add(fs);
                                children.add(fs);
                            }
                        }
                    }
                }
            }
            processed.add(requirement);
        }
    }
}
Also used : ResourceUtils.addIdentityRequirement(org.apache.karaf.features.internal.resolver.ResourceUtils.addIdentityRequirement) ResourceUtils.toFeatureRequirement(org.apache.karaf.features.internal.resolver.ResourceUtils.toFeatureRequirement) Requirement(org.osgi.resource.Requirement) ArrayList(java.util.ArrayList) Conditional(org.apache.karaf.features.Conditional) VersionRange(org.apache.felix.utils.version.VersionRange) Dependency(org.apache.karaf.features.Dependency) Feature(org.apache.karaf.features.Feature)

Example 2 with Dependency

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

the class ApplicationServiceImpl method getAllDependencyFeatures.

/**
     * Retrieves all of the dependencies for a given feature.
     *
     * @param feature Feature to look for dependencies on.
     * @return A set of all features that are dependencies
     */
private Set<Feature> getAllDependencyFeatures(Feature feature) throws Exception {
    Set<Feature> tmpList = new HashSet<>();
    // get accurate feature reference from service - workaround for
    // KARAF-2896 'RepositoryImpl load method incorrectly populates
    // "features" list'
    Feature curFeature = featuresService.getFeature(feature.getName(), feature.getVersion());
    if (curFeature != null) {
        for (Dependency dependencyFeature : curFeature.getDependencies()) {
            Feature feat = featuresService.getFeature(dependencyFeature.getName(), dependencyFeature.getVersion());
            if (StringUtils.equals(curFeature.getRepositoryUrl(), feat.getRepositoryUrl())) {
                tmpList.addAll(getAllDependencyFeatures(feat));
            }
        }
        tmpList.add(curFeature);
    } else {
        // feature may not be installed
        tmpList.add(feature);
    }
    return tmpList;
}
Also used : Dependency(org.apache.karaf.features.Dependency) Feature(org.apache.karaf.features.Feature) HashSet(java.util.HashSet)

Example 3 with Dependency

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

the class ApplicationServiceImpl method traverseDependencies.

/**
     * Finds a parent and children dependencies for each app.  Needs to be run twice
     * in order to get full dependency correlations.
     *
     * @param appMap               Application Map containing all the application nodes.
     * @param filteredApplications Set containing all the application nodes minus those in the ignored list
     * @param reportDebug          Boolean that allows debug statements to be output or not.  Only reason
     *                             why this exists is because this function will be called twice and only
     *                             the second set of statements will be relevant
     */
private void traverseDependencies(Map<Application, ApplicationNodeImpl> appMap, Set<Application> filteredApplications, boolean reportDebug) {
    // find dependencies in each app and add them into correct node
    for (Entry<Application, ApplicationNodeImpl> curAppNode : appMap.entrySet()) {
        try {
            // main feature will contain dependencies
            Feature mainFeature = curAppNode.getKey().getMainFeature();
            if (null == mainFeature) {
                if (reportDebug) {
                    LOGGER.debug("Application \"{}\" does not contain a main feature", curAppNode.getKey().getName());
                }
                continue;
            }
            // eliminate duplications with a set
            Set<Dependency> dependencies = new HashSet<>(mainFeature.getDependencies());
            // remove any features that are local to the application
            dependencies.removeAll(curAppNode.getKey().getFeatures());
            // loop through all of the features that are left to determine
            // where they are from
            Set<Application> depAppSet = new HashSet<>();
            for (Dependency curDepFeature : dependencies) {
                Application dependencyApp = findFeature(featuresService.getFeature(curDepFeature.getName()), filteredApplications);
                if (dependencyApp != null) {
                    if (dependencyApp.equals(curAppNode.getKey())) {
                        if (reportDebug) {
                            LOGGER.debug("Self-dependency");
                        }
                        continue;
                    } else {
                        if (reportDebug) {
                            LOGGER.debug("Application {} depends on the feature {} which is located in application {}.", curAppNode.getKey().getName(), curDepFeature.getName(), dependencyApp.getName());
                        }
                        depAppSet.add(dependencyApp);
                    }
                }
            }
            if (!depAppSet.isEmpty()) {
                Application parentApp;
                if (depAppSet.size() > 1) {
                    parentApp = findCommonParent(depAppSet, appMap);
                    if (parentApp == null) {
                        if (reportDebug) {
                            LOGGER.debug("Found more than 1 application dependency for application {}. Could not determine which one is the correct parent. Application will be sent back as root application.", curAppNode.getKey().getName());
                        }
                        continue;
                    }
                } else {
                    parentApp = depAppSet.iterator().next();
                }
                // update the dependency app with a new child
                ApplicationNode parentAppNode = appMap.get(parentApp);
                parentAppNode.getChildren().add(curAppNode.getValue());
                curAppNode.getValue().setParent(parentAppNode);
            } else {
                if (reportDebug) {
                    LOGGER.debug("No dependency applications found for {}. This will be sent back as a root application.", curAppNode.getKey().getName());
                }
            }
        // ApplicationServiceException from DDF and Exception from Karaf
        // (FeaturesService)
        } catch (Exception e) {
            if (reportDebug) {
                LOGGER.warn("Encountered error while determining dependencies for \"{}\". This may cause an incomplete application hierarchy to be created.", curAppNode.getKey().getName(), e);
            }
        }
    }
}
Also used : ApplicationNode(org.codice.ddf.admin.application.service.ApplicationNode) Dependency(org.apache.karaf.features.Dependency) Application(org.codice.ddf.admin.application.service.Application) 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) HashSet(java.util.HashSet)

Example 4 with Dependency

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

the class ProfileInstallCommandTest method testValidRegularProfile.

@Test
public void testValidRegularProfile() throws Exception {
    profileInstallCommand.profileName = "standard";
    Feature feature = createMockFeature("standard");
    List<Dependency> deps = Arrays.asList(createMockDependency("app1"), createMockDependency("app2"), createMockDependency("app3"));
    when(feature.getDependencies()).thenReturn(deps);
    when(applicationService.getInstallationProfiles()).thenReturn(Collections.singletonList(feature));
    profileInstallCommand.doExecute(applicationService, featuresService, bundleService);
    verify(applicationService, times(3)).startApplication(anyString());
}
Also used : Dependency(org.apache.karaf.features.Dependency) Feature(org.apache.karaf.features.Feature) Test(org.junit.Test)

Example 5 with Dependency

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

the class Subsystem method doBuild.

private void doBuild(Map<String, List<Feature>> allFeatures, boolean mandatory) throws Exception {
    for (Subsystem child : children) {
        child.doBuild(allFeatures, true);
    }
    if (feature != null) {
        // accepts dependencies
        for (Dependency dep : feature.getDependencies()) {
            if (dep.isBlacklisted()) {
                continue;
            }
            Subsystem ss = this;
            while (!ss.isAcceptDependencies()) {
                ss = ss.getParent();
            }
            ss.requireFeature(dep.getName(), dep.getVersion(), false);
        }
        // each conditional feature becomes a child subsystem of this feature's subsystem
        for (Conditional cond : feature.getConditional()) {
            if (cond.isBlacklisted()) {
                continue;
            }
            Feature fcond = cond.asFeature();
            String ssName = this.name + "#" + (fcond.hasVersion() ? fcond.getName() + "-" + fcond.getVersion() : fcond.getName());
            Subsystem fs = getChild(ssName);
            if (fs == null) {
                fs = new Subsystem(ssName, fcond, this, true);
                fs.doBuild(allFeatures, false);
                installable.add(fs);
                children.add(fs);
            }
        }
    }
    List<Requirement> processed = new ArrayList<>();
    while (true) {
        List<Requirement> requirements = getRequirements(IDENTITY_NAMESPACE);
        requirements.addAll(dependentFeatures);
        requirements.removeAll(processed);
        if (requirements.isEmpty()) {
            break;
        }
        // Subsystem representing mandatory feature.
        for (Requirement requirement : requirements) {
            String name = (String) requirement.getAttributes().get(IDENTITY_NAMESPACE);
            String type = (String) requirement.getAttributes().get(CAPABILITY_TYPE_ATTRIBUTE);
            VersionRange range = (VersionRange) requirement.getAttributes().get(CAPABILITY_VERSION_ATTRIBUTE);
            if (TYPE_FEATURE.equals(type) && allFeatures.containsKey(name)) {
                for (Feature feature : allFeatures.get(name)) {
                    if (range == null || range.contains(VersionTable.getVersion(feature.getVersion()))) {
                        if (feature != this.feature && !feature.isBlacklisted()) {
                            String ssName = this.name + "#" + (feature.hasVersion() ? feature.getName() + "-" + feature.getVersion() : feature.getName());
                            Subsystem fs = getChild(ssName);
                            if (fs == null) {
                                fs = new Subsystem(ssName, feature, this, mandatory && !SubsystemResolveContext.isOptional(requirement));
                                fs.build(allFeatures);
                                installable.add(fs);
                                children.add(fs);
                            }
                        }
                    }
                }
            }
            processed.add(requirement);
        }
    }
}
Also used : ResourceUtils.addIdentityRequirement(org.apache.karaf.features.internal.resolver.ResourceUtils.addIdentityRequirement) ResourceUtils.toFeatureRequirement(org.apache.karaf.features.internal.resolver.ResourceUtils.toFeatureRequirement) Requirement(org.osgi.resource.Requirement) ArrayList(java.util.ArrayList) Conditional(org.apache.karaf.features.Conditional) VersionRange(org.apache.felix.utils.version.VersionRange) Dependency(org.apache.karaf.features.Dependency) Feature(org.apache.karaf.features.Feature)

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