Search in sources :

Example 11 with Dependency

use of io.fabric8.agent.model.Dependency in project fabric8-maven-plugin by fabric8io.

the class OpenShiftDependencyResources method convertKubernetesItemToOpenShift.

/**
 * Returns the OpenShift dependency for the given resource if there is one
 */
public HasMetadata convertKubernetesItemToOpenShift(HasMetadata item) {
    KindAndName key = new KindAndName(item);
    HasMetadata answer = openshiftDependencyResources.get(key);
    if (answer == null && item instanceof Deployment) {
        key = new KindAndName("DeploymentConfig", getName(item));
        answer = openshiftDependencyResources.get(key);
    }
    return answer;
}
Also used : HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Deployment(io.fabric8.kubernetes.api.model.extensions.Deployment)

Example 12 with Dependency

use of io.fabric8.agent.model.Dependency in project fabric8 by fabric8io.

the class SessionListener method loadDependency.

public void loadDependency(Logger log, List<KubernetesList> kubeConfigs, String dependency, Controller controller, Configuration configuration, String namespace) throws Exception {
    // lets test if the dependency is a local string
    String baseDir = System.getProperty("basedir", ".");
    String path = baseDir + "/" + dependency;
    File file = new File(path);
    if (file.exists()) {
        loadDependency(log, kubeConfigs, file, controller, configuration, log, namespace);
    } else {
        String text = readAsString(createURL(dependency));
        Object resources;
        if (text.trim().startsWith("---") || dependency.endsWith(".yml") || dependency.endsWith(".yaml")) {
            resources = loadYaml(text);
        } else {
            resources = loadJson(text);
        }
        addConfig(kubeConfigs, resources, controller, configuration, log, namespace, dependency);
    }
}
Also used : Util.readAsString(io.fabric8.arquillian.utils.Util.readAsString) File(java.io.File)

Example 13 with Dependency

use of io.fabric8.agent.model.Dependency in project fabric8 by jboss-fuse.

the class Subsystem method downloadBundles.

@SuppressWarnings("InfiniteLoopStatement")
public void downloadBundles(DownloadManager manager, MetadataBuilder builder, Set<String> overrides, String featureResolutionRange) throws Exception {
    for (Subsystem child : children) {
        child.downloadBundles(manager, builder, overrides, featureResolutionRange);
    }
    final Map<String, ResourceImpl> bundles = new ConcurrentHashMap<>();
    final Downloader downloader = manager.createDownloader();
    final Map<BundleInfo, Conditional> infos = new HashMap<>();
    if (feature != null) {
        for (Conditional cond : feature.getConditional()) {
            for (final BundleInfo bi : cond.getBundles()) {
                infos.put(bi, cond);
            }
        }
        for (BundleInfo bi : feature.getBundles()) {
            infos.put(bi, null);
        }
    }
    ResourceBuilderCallback callback = new ResourceBuilderCallback(bundles, builder);
    for (Map.Entry<BundleInfo, Conditional> entry : infos.entrySet()) {
        final BundleInfo bi = entry.getKey();
        final String loc = bi.getLocation();
        downloader.download(loc, callback);
    }
    for (Clause bundle : Parser.parseClauses(this.bundles.toArray(new String[this.bundles.size()]))) {
        final String loc = bundle.getName();
        downloader.download(loc, callback);
    }
    for (final FabricBundle fabricBundle : fabricBundles) {
        final String loc = fabricBundle.getLocation();
        downloader.download(loc, callback);
    }
    for (String override : overrides) {
        final String loc = Overrides.extractUrl(override);
        downloader.download(loc, callback);
    }
    downloader.await();
    Overrides.override(bundles, overrides);
    if (feature != null) {
        // Add conditionals
        Map<Conditional, Resource> resConds = new HashMap<>();
        for (Conditional cond : feature.getConditional()) {
            FeatureResource resCond = FeatureResource.build(feature, cond, featureResolutionRange, bundles);
            addIdentityRequirement(this, resCond, false);
            addIdentityRequirement(resCond, this, true);
            installable.add(resCond);
            resConds.put(cond, resCond);
        }
        // Add features
        FeatureResource resFeature = FeatureResource.build(feature, featureResolutionRange, bundles);
        addIdentityRequirement(resFeature, this);
        installable.add(resFeature);
        // Add dependencies
        for (Map.Entry<BundleInfo, Conditional> entry : infos.entrySet()) {
            final BundleInfo bi = entry.getKey();
            final String loc = bi.getLocation();
            final Conditional cond = entry.getValue();
            ResourceImpl res = bundles.get(loc);
            int sl = bi.getStartLevel() <= 0 ? feature.getStartLevel() : bi.getStartLevel();
            if (bi.isDependency()) {
                addDependency(res, false, bi.isStart(), sl);
            } else {
                doAddDependency(res, cond == null, bi.isStart(), sl);
            }
            if (cond != null) {
                addIdentityRequirement(res, resConds.get(cond), true);
            }
        }
    }
    for (Clause bundle : Parser.parseClauses(this.bundles.toArray(new String[this.bundles.size()]))) {
        final String loc = bundle.getName();
        boolean dependency = Boolean.parseBoolean(bundle.getAttribute("dependency"));
        boolean start = bundle.getAttribute("start") == null || Boolean.parseBoolean(bundle.getAttribute("start"));
        int startLevel = 0;
        try {
            startLevel = Integer.parseInt(bundle.getAttribute("start-level"));
        } catch (NumberFormatException e) {
        // Ignore
        }
        if (dependency) {
            addDependency(bundles.get(loc), false, start, startLevel);
        } else {
            doAddDependency(bundles.get(loc), true, start, startLevel);
            addIdentityRequirement(this, bundles.get(loc));
        }
    }
    for (final FabricBundle fabricBundle : fabricBundles) {
        final String loc = fabricBundle.getLocation();
        boolean dependency = Boolean.parseBoolean(fabricBundle.getProperty("dependency"));
        boolean start = fabricBundle.getProperty("start") == null || Boolean.parseBoolean(fabricBundle.getProperty("start"));
        int startLevel = 0;
        try {
            startLevel = Integer.parseInt(fabricBundle.getProperty("start-level"));
        } catch (NumberFormatException e) {
        // Ignore
        }
        if (dependency) {
            addDependency(bundles.get(loc), false, start, startLevel);
        } else {
            doAddDependency(bundles.get(loc), true, start, startLevel);
            addIdentityRequirement(this, bundles.get(loc));
        }
    }
    // Compute dependencies
    for (DependencyInfo info : dependencies.values()) {
        installable.add(info.resource);
        addIdentityRequirement(info.resource, this, info.mandatory);
    }
}
Also used : FeatureResource(io.fabric8.agent.resolver.FeatureResource) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Resource(org.osgi.resource.Resource) FeatureResource(io.fabric8.agent.resolver.FeatureResource) Downloader(io.fabric8.agent.download.Downloader) Conditional(io.fabric8.agent.model.Conditional) ResourceImpl(io.fabric8.agent.resolver.ResourceImpl) BundleInfo(io.fabric8.agent.model.BundleInfo) Clause(org.apache.felix.utils.manifest.Clause) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 14 with Dependency

use of io.fabric8.agent.model.Dependency in project fabric8 by jboss-fuse.

the class CamelXjcTest method setUp.

public void setUp() throws Exception {
    // this would typically be done by dependency injection...
    dataFormat.setCompiler(new DefaultDynamicCompiler(XjcTest.getSchemaURL("xsds/report.xsd")));
    super.setUp();
}
Also used : DefaultDynamicCompiler(io.fabric8.jaxb.dynamic.DefaultDynamicCompiler)

Example 15 with Dependency

use of io.fabric8.agent.model.Dependency in project fabric8 by jboss-fuse.

the class AgentUtils method expandFeature.

public static Set<Feature> expandFeature(Feature feature, Map<String, Repository> repositories) {
    Set<Feature> features = new HashSet<>();
    for (Dependency f : feature.getDependencies()) {
        Feature loaded = FeatureUtils.search(f.getName(), repositories.values());
        features.addAll(expandFeature(loaded, repositories));
    }
    features.add(feature);
    return features;
}
Also used : Dependency(io.fabric8.agent.model.Dependency) Feature(io.fabric8.agent.model.Feature) HashSet(java.util.HashSet)

Aggregations

ArrayList (java.util.ArrayList)6 Dependency (io.fabric8.agent.model.Dependency)4 Feature (io.fabric8.agent.model.Feature)4 File (java.io.File)4 IOException (java.io.IOException)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 ResourceUtils.addIdentityRequirement (io.fabric8.agent.resolver.ResourceUtils.addIdentityRequirement)3 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)3 Parser (io.fabric8.maven.util.Parser)3 HashSet (java.util.HashSet)3 BundleInfo (io.fabric8.agent.model.BundleInfo)2 Requirement (io.fabric8.agent.model.Requirement)2 Util.readAsString (io.fabric8.arquillian.utils.Util.readAsString)2 DependencyDTO (io.fabric8.deployer.dto.DependencyDTO)2 FailedToResolveDependency (io.fabric8.maven.FailedToResolveDependency)2 URL (java.net.URL)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 DefaultDependencyNode (org.eclipse.aether.graph.DefaultDependencyNode)2 Element (org.w3c.dom.Element)2