Search in sources :

Example 41 with Filter

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

the class DependencyFilters method parse.

/**
 * Creates a filter from the given String
 */
public static Filter<Dependency> parse(String dependencyFilterText) {
    List<Filter<Dependency>> filters = new ArrayList<Filter<Dependency>>();
    StringTokenizer iter = new StringTokenizer(dependencyFilterText);
    while (iter.hasMoreElements()) {
        String text = iter.nextToken();
        Filter<Dependency> filter = parseSingleFilter(text);
        if (filter != null) {
            filters.add(filter);
        }
    }
    return Filters.compositeFilter(filters);
}
Also used : StringTokenizer(java.util.StringTokenizer) Filter(io.fabric8.common.util.Filter) ArrayList(java.util.ArrayList) Dependency(org.eclipse.aether.graph.Dependency)

Example 42 with Filter

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

the class Manager method init.

public void init() throws Exception {
    // Create client and server
    this.client = new ClientInvokerImpl(queue, timeout, serializationStrategies);
    this.server = new ServerInvokerImpl(uri, queue, serializationStrategies);
    this.client.start();
    this.server.start();
    // ZooKeeper tracking
    try {
        create(curator, DOSGI_REGISTRY, CreateMode.PERSISTENT);
    } catch (KeeperException.NodeExistsException e) {
    // The node already exists, that's fine
    }
    this.tree = new TreeCacheExtended(curator, DOSGI_REGISTRY, true);
    this.tree.getListenable().addListener(this);
    this.tree.start();
    // UUID
    this.uuid = Utils.getUUID(this.bundleContext);
    // Service listener filter
    String filter = "(" + RemoteConstants.SERVICE_EXPORTED_INTERFACES + "=*)";
    // Initialization
    this.bundleContext.addServiceListener(this, filter);
    // Service registration
    this.registration = this.bundleContext.registerService(new String[] { ListenerHook.class.getName(), EventHook.class.getName(), FindHook.class.getName() }, this, null);
    // Check existing services
    ServiceReference[] references = this.bundleContext.getServiceReferences((String) null, filter);
    if (references != null) {
        for (ServiceReference reference : references) {
            exportService(reference);
        }
    }
}
Also used : ClientInvokerImpl(io.fabric8.dosgi.tcp.ClientInvokerImpl) ServerInvokerImpl(io.fabric8.dosgi.tcp.ServerInvokerImpl) TreeCacheExtended(org.apache.curator.framework.recipes.cache.TreeCacheExtended) KeeperException(org.apache.zookeeper.KeeperException) ServiceReference(org.osgi.framework.ServiceReference)

Example 43 with Filter

use of io.fabric8.common.util.Filter in project strimzi by strimzi.

the class AbstractAssemblyOperator method reconcileAll.

/**
 * Reconcile assembly resources in the given namespace having the given selector.
 * Reconciliation works by getting the assembly ConfigMaps in the given namespace with the given selector and
 * comparing with the corresponding {@linkplain #getResources(String) resource}.
 * <ul>
 * <li>An assembly will be {@linkplain #createOrUpdate(Reconciliation, ConfigMap, Handler) created} for all ConfigMaps without same-named resources</li>
 * <li>An assembly will be {@linkplain #delete(Reconciliation, Handler) deleted} for all resources without same-named ConfigMaps</li>
 * </ul>
 *
 * @param trigger A description of the triggering event (timer or watch), used for logging
 * @param namespace The namespace
 * @param selector The selector
 */
public final CountDownLatch reconcileAll(String trigger, String namespace, Labels selector) {
    Labels selectorWithCluster = selector.withType(assemblyType);
    // get ConfigMaps with kind=cluster&type=kafka (or connect, or connect-s2i) for the corresponding cluster type
    List<ConfigMap> cms = configMapOperations.list(namespace, selectorWithCluster);
    Set<String> cmsNames = cms.stream().map(cm -> cm.getMetadata().getName()).collect(Collectors.toSet());
    log.debug("reconcileAll({}, {}): ConfigMaps with labels {}: {}", assemblyType, trigger, selectorWithCluster, cmsNames);
    // get resources with kind=cluster&type=kafka (or connect, or connect-s2i)
    List<? extends HasMetadata> resources = getResources(namespace);
    // now extract the cluster name from those
    Set<String> resourceNames = resources.stream().filter(// exclude Cluster CM, which won't have a cluster label
    r -> Labels.kind(r) == null).map(Labels::cluster).collect(Collectors.toSet());
    log.debug("reconcileAll({}, {}): Other resources with labels {}: {}", assemblyType, trigger, selectorWithCluster, resourceNames);
    cmsNames.addAll(resourceNames);
    // We use a latch so that callers (specifically, test callers) know when the reconciliation is complete
    // Using futures would be more complex for no benefit
    CountDownLatch latch = new CountDownLatch(cmsNames.size());
    for (String name : cmsNames) {
        Reconciliation reconciliation = new Reconciliation(trigger, assemblyType, namespace, name);
        reconcileAssembly(reconciliation, result -> {
            if (result.succeeded()) {
                log.info("{}: Assembly reconciled", reconciliation);
            } else {
                log.error("{}: Failed to reconcile", reconciliation);
            }
            latch.countDown();
        });
    }
    return latch;
}
Also used : AssemblyType(io.strimzi.controller.cluster.model.AssemblyType) Logger(org.slf4j.Logger) Vertx(io.vertx.core.Vertx) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) ConfigMapOperator(io.strimzi.controller.cluster.operator.resource.ConfigMapOperator) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Labels(io.strimzi.controller.cluster.model.Labels) Future(io.vertx.core.Future) Collectors(java.util.stream.Collectors) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) Lock(io.vertx.core.shareddata.Lock) ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) Reconciliation(io.strimzi.controller.cluster.Reconciliation) AsyncResult(io.vertx.core.AsyncResult) Handler(io.vertx.core.Handler) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) Reconciliation(io.strimzi.controller.cluster.Reconciliation) Labels(io.strimzi.controller.cluster.model.Labels) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 44 with Filter

use of io.fabric8.common.util.Filter in project halyard by spinnaker.

the class BakeDebianServiceProvider method getInstallCommand.

@Override
public String getInstallCommand(DeploymentDetails deploymentDetails, GenerateService.ResolvedConfiguration resolvedConfiguration, Map<String, String> installCommands, String startupCommand) {
    Map<String, Object> bindings = new HashMap<>();
    List<SpinnakerService.Type> serviceTypes = new ArrayList<>(installCommands.keySet()).stream().map(SpinnakerService.Type::fromCanonicalName).collect(Collectors.toList());
    List<String> upstartNames = getPrioritizedBakeableServices(serviceTypes).stream().filter(i -> resolvedConfiguration.getServiceSettings(i.getService()).getEnabled()).map(i -> ((BakeDebianService) i).getUpstartServiceName()).filter(Objects::nonNull).collect(Collectors.toList());
    List<String> systemdServiceConfigs = upstartNames.stream().map(n -> n + ".service").collect(Collectors.toList());
    List<String> serviceInstalls = serviceTypes.stream().map(t -> installCommands.get(t.getCanonicalName())).collect(Collectors.toList());
    TemplatedResource resource = new StringReplaceJarResource("/debian/init.sh");
    bindings.put("services", Strings.join(upstartNames, " "));
    bindings.put("systemd-service-configs", Strings.join(systemdServiceConfigs, " "));
    String upstartInit = resource.setBindings(bindings).toString();
    BillOfMaterials.ArtifactSources artifactSources = artifactService.getArtifactSources(deploymentDetails.getDeploymentName());
    resource = new StringReplaceJarResource("/debian/pre-bake.sh");
    bindings = new HashMap<>();
    bindings.put("debian-repository", artifactSourcesConfig.mergeWithBomSources(artifactSources).getDebianRepository());
    bindings.put("install-commands", String.join("\n", serviceInstalls));
    bindings.put("upstart-init", upstartInit);
    bindings.put("startup-file", Paths.get(startupScriptPath, "startup.sh").toString());
    bindings.put("startup-command", startupCommand);
    return resource.setBindings(bindings).toString();
}
Also used : DeploymentDetails(com.netflix.spinnaker.halyard.deploy.deployment.v1.DeploymentDetails) ArtifactSourcesConfig(com.netflix.spinnaker.halyard.config.config.v1.ArtifactSourcesConfig) Autowired(org.springframework.beans.factory.annotation.Autowired) HalException(com.netflix.spinnaker.halyard.core.error.v1.HalException) HashMap(java.util.HashMap) ArtifactService(com.netflix.spinnaker.halyard.deploy.services.v1.ArtifactService) GenerateService(com.netflix.spinnaker.halyard.deploy.services.v1.GenerateService) SpinnakerRuntimeSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.SpinnakerRuntimeSettings) BakeServiceProvider(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.bake.BakeServiceProvider) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) Objects(java.util.Objects) Component(org.springframework.stereotype.Component) List(java.util.List) Paths(java.nio.file.Paths) StringReplaceJarResource(com.netflix.spinnaker.halyard.core.resource.v1.StringReplaceJarResource) Map(java.util.Map) Problem(com.netflix.spinnaker.halyard.core.problem.v1.Problem) RemoteAction(com.netflix.spinnaker.halyard.core.RemoteAction) BillOfMaterials(com.netflix.spinnaker.halyard.core.registry.v1.BillOfMaterials) SpinnakerService(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.SpinnakerService) Strings(io.fabric8.utils.Strings) TemplatedResource(com.netflix.spinnaker.halyard.core.resource.v1.TemplatedResource) HashMap(java.util.HashMap) TemplatedResource(com.netflix.spinnaker.halyard.core.resource.v1.TemplatedResource) SpinnakerService(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.SpinnakerService) BillOfMaterials(com.netflix.spinnaker.halyard.core.registry.v1.BillOfMaterials) StringReplaceJarResource(com.netflix.spinnaker.halyard.core.resource.v1.StringReplaceJarResource)

Example 45 with Filter

use of io.fabric8.common.util.Filter in project halyard by spinnaker.

the class LocalDebianServiceProvider method clean.

@Override
public RemoteAction clean(DeploymentDetails details, SpinnakerRuntimeSettings runtimeSettings) {
    String uninstallArtifacts = String.join("\n", getServices().stream().filter(s -> s != null && runtimeSettings.getServiceSettings(s).getEnabled()).map(s -> ((LocalDebianService) s).uninstallArtifactCommand()).collect(Collectors.toList()));
    Map<String, Object> bindings = new HashMap<>();
    TemplatedResource resource = new StringReplaceJarResource("/debian/uninstall.sh");
    bindings.put("uninstall-artifacts", uninstallArtifacts);
    return new RemoteAction().setScript(resource.setBindings(bindings).toString()).setAutoRun(true).setScriptDescription("This script apt-get purges all spinnaker components & deletes their config");
}
Also used : DeploymentDetails(com.netflix.spinnaker.halyard.deploy.deployment.v1.DeploymentDetails) java.util(java.util) ArtifactSourcesConfig(com.netflix.spinnaker.halyard.config.config.v1.ArtifactSourcesConfig) Autowired(org.springframework.beans.factory.annotation.Autowired) ArtifactService(com.netflix.spinnaker.halyard.deploy.services.v1.ArtifactService) GenerateService(com.netflix.spinnaker.halyard.deploy.services.v1.GenerateService) SpinnakerRuntimeSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.SpinnakerRuntimeSettings) Collectors(java.util.stream.Collectors) Component(org.springframework.stereotype.Component) LocalServiceProvider(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.local.LocalServiceProvider) StringReplaceJarResource(com.netflix.spinnaker.halyard.core.resource.v1.StringReplaceJarResource) RemoteAction(com.netflix.spinnaker.halyard.core.RemoteAction) BillOfMaterials(com.netflix.spinnaker.halyard.core.registry.v1.BillOfMaterials) SpinnakerService(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.SpinnakerService) Strings(io.fabric8.utils.Strings) TemplatedResource(com.netflix.spinnaker.halyard.core.resource.v1.TemplatedResource) StringReplaceJarResource(com.netflix.spinnaker.halyard.core.resource.v1.StringReplaceJarResource) TemplatedResource(com.netflix.spinnaker.halyard.core.resource.v1.TemplatedResource) RemoteAction(com.netflix.spinnaker.halyard.core.RemoteAction)

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