Search in sources :

Example 11 with Filter

use of io.fabric8.common.util.Filter in project fabric8 by jboss-fuse.

the class BaseRepository method findProviders.

@Override
public Map<Requirement, Collection<Capability>> findProviders(Collection<? extends Requirement> requirements) {
    Map<Requirement, Collection<Capability>> result = new HashMap<Requirement, Collection<Capability>>();
    for (Requirement requirement : requirements) {
        CapabilitySet set = capSets.get(requirement.getNamespace());
        if (set != null) {
            SimpleFilter sf;
            if (requirement instanceof RequirementImpl) {
                sf = ((RequirementImpl) requirement).getFilter();
            } else {
                String filter = requirement.getDirectives().get(Constants.FILTER_DIRECTIVE);
                sf = (filter != null) ? SimpleFilter.parse(filter) : new SimpleFilter(null, null, SimpleFilter.MATCH_ALL);
            }
            result.put(requirement, set.match(sf, true));
        } else {
            result.put(requirement, Collections.<Capability>emptyList());
        }
    }
    return result;
}
Also used : Requirement(org.osgi.resource.Requirement) RequirementImpl(io.fabric8.agent.resolver.RequirementImpl) Capability(org.osgi.resource.Capability) HashMap(java.util.HashMap) SimpleFilter(io.fabric8.agent.resolver.SimpleFilter) Collection(java.util.Collection) CapabilitySet(io.fabric8.agent.resolver.CapabilitySet)

Example 12 with Filter

use of io.fabric8.common.util.Filter in project fabric8 by jboss-fuse.

the class ProfileWatcherImpl method findProfileArifacts.

// For each profile and version return the map of bundle locations to parsers
private Map<ProfileVersionKey, Map<String, Parser>> findProfileArifacts() throws Exception {
    Map<ProfileVersionKey, Map<String, Parser>> profileArtifacts = new HashMap<ProfileVersionKey, Map<String, Parser>>();
    ProfileService profileService = fabricService.get().adapt(ProfileService.class);
    DownloadManager downloadManager = DownloadManagers.createDownloadManager(fabricService.get(), executorService);
    Container[] containers = fabricService.get().getContainers();
    for (Container container : containers) {
        Profile[] profiles = container.getProfiles();
        boolean javaOrProcessContainer = ChildContainers.isJavaOrProcessContainer(fabricService.get(), container);
        // TODO allow filter on a profile here?
        for (Profile profile : profiles) {
            Profile overlay = profileService.getOverlayProfile(profile);
            ProfileVersionKey key = new ProfileVersionKey(profile);
            // if (!profileArtifacts.containsKey(key)) {
            Map<String, Parser> artifacts = null;
            if (javaOrProcessContainer) {
                List<Profile> singletonList = Collections.singletonList(profile);
                artifacts = JavaContainers.getJavaContainerArtifacts(fabricService.get(), singletonList, executorService);
            } else {
                artifacts = AgentUtils.getProfileArtifacts(fabricService.get(), downloadManager, overlay);
            }
            if (artifacts != null) {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Profile " + profile.getId() + " maps to artefacts: " + artifacts.keySet());
                }
                profileArtifacts.put(key, artifacts);
            }
        // }
        }
    }
    return profileArtifacts;
}
Also used : HashMap(java.util.HashMap) DownloadManager(io.fabric8.agent.download.DownloadManager) Profile(io.fabric8.api.Profile) Parser(io.fabric8.maven.util.Parser) Container(io.fabric8.api.Container) ProfileService(io.fabric8.api.ProfileService) Map(java.util.Map) HashMap(java.util.HashMap)

Example 13 with Filter

use of io.fabric8.common.util.Filter in project fabric8 by jboss-fuse.

the class ProfileWatcherImpl method getCurrentActiveProfileVersions.

/**
 * Gets the set of active profile ids and versions
 */
protected SortedSet<String> getCurrentActiveProfileVersions() {
    SortedSet<String> answer = new TreeSet<String>();
    Container[] containers = fabricService.get().getContainers();
    for (Container container : containers) {
        container.getProvisionList();
        Profile[] profiles = container.getProfiles();
        // TODO allow filter on a profile here?
        for (Profile profile : profiles) {
            String id = profile.getId();
            String version = profile.getVersion();
            answer.add(id + "/" + version);
        }
    }
    return answer;
}
Also used : Container(io.fabric8.api.Container) TreeSet(java.util.TreeSet) Profile(io.fabric8.api.Profile)

Example 14 with Filter

use of io.fabric8.common.util.Filter in project fabric8 by jboss-fuse.

the class Manager method removed.

@SuppressWarnings("unchecked")
public void removed(final Collection listenerInfos) {
    for (ListenerInfo listenerInfo : (Collection<ListenerInfo>) listenerInfos) {
        // Ignore our own listeners or those that don't have any filter
        if (listenerInfo.getBundleContext() == bundleContext || listenerInfo.getFilter() == null) {
            continue;
        }
        SimpleFilter exFilter = listeners.remove(listenerInfo);
        // Iterate through known services and dereference them if needed
        Set<EndpointDescription> matches = remoteEndpoints.match(exFilter);
        for (EndpointDescription endpoint : matches) {
            Map<Long, ImportRegistration> registrations = importedServices.get(endpoint);
            if (registrations != null) {
                ImportRegistration registration = registrations.get(listenerInfo.getBundleContext().getBundle().getBundleId());
                if (registration != null) {
                    registration.removeReference(listenerInfo);
                    if (!registration.hasReferences()) {
                        registration.getImportedService().unregister();
                        registrations.remove(listenerInfo.getBundleContext().getBundle().getBundleId());
                    }
                }
            }
        }
    }
}
Also used : SimpleFilter(io.fabric8.dosgi.capset.SimpleFilter) Collection(java.util.Collection)

Example 15 with Filter

use of io.fabric8.common.util.Filter in project fabric8 by jboss-fuse.

the class Manager method added.

// 
// ListenerHook
// 
@SuppressWarnings("unchecked")
public void added(final Collection listenerInfos) {
    for (ListenerInfo listenerInfo : (Collection<ListenerInfo>) listenerInfos) {
        // Ignore our own listeners or those that don't have any filter
        if (listenerInfo.getBundleContext() == bundleContext || listenerInfo.getFilter() == null) {
            continue;
        }
        // Make sure we only import remote services
        String filter = "(&" + listenerInfo.getFilter() + "(!(" + ENDPOINT_FRAMEWORK_UUID + "=" + this.uuid + ")))";
        SimpleFilter exFilter = SimpleFilter.parse(filter);
        listeners.put(listenerInfo, exFilter);
        // Iterate through known services and import them if needed
        Set<EndpointDescription> matches = remoteEndpoints.match(exFilter);
        for (EndpointDescription endpoint : matches) {
            doImportService(endpoint, listenerInfo);
        }
    }
}
Also used : SimpleFilter(io.fabric8.dosgi.capset.SimpleFilter) Collection(java.util.Collection)

Aggregations

List (java.util.List)18 Map (java.util.Map)18 Collectors (java.util.stream.Collectors)18 IOException (java.io.IOException)16 Pod (io.fabric8.kubernetes.api.model.Pod)12 ArrayList (java.util.ArrayList)12 File (java.io.File)11 HashMap (java.util.HashMap)11 Optional (java.util.Optional)11 TimeUnit (java.util.concurrent.TimeUnit)10 Logger (org.slf4j.Logger)10 LoggerFactory (org.slf4j.LoggerFactory)10 InputStream (java.io.InputStream)8 DeploymentConfig (io.fabric8.openshift.api.model.DeploymentConfig)7 Test (org.junit.Test)7 Volume (io.fabric8.kubernetes.api.model.Volume)6 Arrays (java.util.Arrays)6 PodList (io.fabric8.kubernetes.api.model.PodList)5 VolumeMount (io.fabric8.kubernetes.api.model.VolumeMount)5 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)5