Search in sources :

Example 31 with Resource

use of io.fabric8.kubernetes.client.dsl.Resource in project fabric8 by jboss-fuse.

the class BaseRepository method addResource.

protected void addResource(Resource resource) {
    for (Capability cap : resource.getCapabilities(null)) {
        String ns = cap.getNamespace();
        CapabilitySet set = capSets.get(ns);
        if (set == null) {
            if ("service-reference".equals(ns) || "osgi.service".equals(ns)) {
                set = new CapabilitySet(Collections.singletonList("objectClass"));
            } else {
                set = new CapabilitySet(Collections.singletonList(ns));
            }
            capSets.put(ns, set);
        }
        set.addCapability(cap);
    }
    resources.add(resource);
}
Also used : Capability(org.osgi.resource.Capability) CapabilitySet(io.fabric8.agent.resolver.CapabilitySet)

Example 32 with Resource

use of io.fabric8.kubernetes.client.dsl.Resource in project fabric8 by jboss-fuse.

the class Overrides method override.

/**
 * Compute a list of bundles to install, taking into account overrides.
 * <p/>
 * The file containing the overrides will be loaded from the given url.
 * Blank lines and lines starting with a '#' will be ignored, all other lines
 * are considered as urls to override bundles.
 * <p/>
 * The list of resources to resolve will be scanned and for each bundle,
 * if a bundle override matches that resource, it will be used instead.
 * <p/>
 * Matching is done on bundle symbolic name (they have to be the same)
 * and version (the bundle override version needs to be greater than the
 * resource to be resolved, and less than the next minor version.  A range
 * directive can be added to the override url in which case, the matching
 * will succeed if the resource to be resolved is within the given range.
 *
 * @param resources the list of resources to resolve
 * @param overrides list of bundle overrides
 */
public static <T extends Resource> void override(Map<String, T> resources, Collection<String> overrides) {
    // Do override replacement
    for (Clause override : Parser.parseClauses(overrides.toArray(new String[overrides.size()]))) {
        String url = override.getName();
        String vr = override.getAttribute(OVERRIDE_RANGE);
        T over = resources.get(url);
        if (over == null) {
            // Ignore invalid overrides
            continue;
        }
        for (String uri : new ArrayList<String>(resources.keySet())) {
            Resource res = resources.get(uri);
            if (getSymbolicName(res).equals(getSymbolicName(over))) {
                VersionRange range;
                if (vr == null) {
                    // default to micro version compatibility
                    Version v1 = getVersion(res);
                    Version v2 = new Version(v1.getMajor(), v1.getMinor() + 1, 0);
                    range = new VersionRange(false, v1, v2, true);
                } else {
                    range = VersionRange.parseVersionRange(vr);
                }
                // if the override is actually a newer version than what we currently have
                if (range.contains(getVersion(over)) && getVersion(res).compareTo(getVersion(over)) < 0) {
                    resources.put(uri, over);
                }
            }
        }
    }
}
Also used : Version(org.osgi.framework.Version) ResourceUtils.getVersion(io.fabric8.agent.resolver.ResourceUtils.getVersion) ArrayList(java.util.ArrayList) Resource(org.osgi.resource.Resource) VersionRange(org.apache.felix.utils.version.VersionRange) Clause(org.apache.felix.utils.manifest.Clause)

Example 33 with Resource

use of io.fabric8.kubernetes.client.dsl.Resource in project fabric8 by jboss-fuse.

the class FabricResource method version.

/**
 * Accesses a version resource
 */
@Path("version/{versionId}")
public VersionResource version(@PathParam("versionId") String versionId) {
    FabricService fabricService = getFabricService();
    if (fabricService != null && Strings.isNotBlank(versionId)) {
        ProfileService profileService = fabricService.adapt(ProfileService.class);
        Version version = profileService.getRequiredVersion(versionId);
        if (version != null) {
            return new VersionResource(this, version);
        } else {
            LOG.warn("No version found for: {}", version);
        }
    }
    return null;
}
Also used : ProfileService(io.fabric8.api.ProfileService) Version(io.fabric8.api.Version) FabricService(io.fabric8.api.FabricService) Path(javax.ws.rs.Path)

Example 34 with Resource

use of io.fabric8.kubernetes.client.dsl.Resource in project fabric8 by jboss-fuse.

the class SupportServiceImpl method collect.

@Override
public File collect() {
    String name = String.format("%s-%s", "SUPPORT", DATE_TIME_SUFFIX.format(new Date()));
    File result = null;
    ZipOutputStream file = null;
    try {
        result = File.createTempFile(name, ".zip");
        LOGGER.info("Collecting information for support in file {}", result.getAbsolutePath());
        file = new ZipOutputStream(new FileOutputStream(result));
        for (Collector collector : collectors) {
            for (Resource resource : collector.collect(resourceFactory)) {
                collectFromResource(file, resource);
            }
        }
    } catch (IOException e) {
        LOGGER.error("Exception occured while collecting support information - resulting support file may not be usable", e);
    } finally {
        IOHelpers.close(file);
    }
    return result;
}
Also used : ZipOutputStream(java.util.zip.ZipOutputStream) FileOutputStream(java.io.FileOutputStream) Collector(io.fabric8.support.api.Collector) Resource(io.fabric8.support.api.Resource) IOException(java.io.IOException) File(java.io.File) Date(java.util.Date)

Example 35 with Resource

use of io.fabric8.kubernetes.client.dsl.Resource in project fabric8 by jboss-fuse.

the class PatchThePatchServiceTest method createdeployment.

@Deployment
public static JavaArchive createdeployment() throws Exception {
    final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "test.jar");
    archive.addClass(ServiceLocator.class);
    archive.addClass(IOHelpers.class);
    archive.addPackage(ServiceTracker.class.getPackage());
    archive.addPackages(true, OSGiManifestBuilder.class.getPackage());
    archive.addPackage(CommandSupport.class.getPackage());
    archive.addClass(VersionCleaner.class);
    archive.setManifest(new Asset() {

        public InputStream openStream() {
            OSGiManifestBuilder builder = OSGiManifestBuilder.newInstance();
            builder.addBundleSymbolicName(archive.getName());
            builder.addBundleManifestVersion(2);
            builder.addImportPackages(Bundle.class, Logger.class);
            builder.addImportPackages(AbstractCommand.class, Action.class, Function.class, Validatable.class);
            builder.addImportPackages(InvalidComponentException.class);
            builder.addImportPackage("org.apache.felix.service.command;status=provisional");
            return builder.openStream();
        }
    });
    // add the patch zip files as resource
    archive.add(createPatchZipFile(PATCH_ID), "/patches", ZipExporter.class);
    return archive;
}
Also used : Action(org.apache.felix.gogo.commands.Action) ServiceTracker(org.osgi.util.tracker.ServiceTracker) Bundle(org.osgi.framework.Bundle) AbstractCommand(org.apache.felix.gogo.commands.basic.AbstractCommand) Logger(org.slf4j.Logger) JavaArchive(org.jboss.shrinkwrap.api.spec.JavaArchive) Validatable(io.fabric8.api.scr.Validatable) Function(org.apache.felix.service.command.Function) InvalidComponentException(io.fabric8.api.InvalidComponentException) OSGiManifestBuilder(org.jboss.osgi.metadata.OSGiManifestBuilder) Asset(org.jboss.shrinkwrap.api.asset.Asset) CommandSupport(io.fabric8.itests.support.CommandSupport) Deployment(org.jboss.arquillian.container.test.api.Deployment)

Aggregations

HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)28 Test (org.junit.Test)28 Resource (io.fabric8.kubernetes.client.dsl.Resource)25 IOException (java.io.IOException)24 Map (java.util.Map)23 HashMap (java.util.HashMap)19 ArrayList (java.util.ArrayList)16 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)14 Deployment (io.fabric8.kubernetes.api.model.extensions.Deployment)14 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)14 MixedOperation (io.fabric8.kubernetes.client.dsl.MixedOperation)14 File (java.io.File)14 Resource (org.osgi.resource.Resource)14 Async (io.vertx.ext.unit.Async)12 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)11 List (java.util.List)11 Service (io.fabric8.kubernetes.api.model.Service)10 NonNamespaceOperation (io.fabric8.kubernetes.client.dsl.NonNamespaceOperation)10 ReplicationController (io.fabric8.kubernetes.api.model.ReplicationController)9 DeploymentConfig (io.fabric8.openshift.api.model.DeploymentConfig)9