Search in sources :

Example 1 with Registration

use of org.wildfly.swarm.topology.runtime.Registration in project wildfly-swarm by wildfly-swarm.

the class ServiceWatcher method registrationsForService.

private Set<Registration> registrationsForService(IService service) {
    Set<Registration> newEntries = new HashSet<>();
    // Only expose the service's default port and anything running on the https port
    service.getPorts().stream().filter(servicePort -> servicePort.getPort() == service.getPort() || servicePort.getPort() == DEFAULT_HTTPS_PORT).forEach(servicePort -> {
        Registration registration = new Registration(TOPOLOGY_SOURCE_KEY, service.getName(), service.getName(), servicePort.getPort());
        if (servicePort.getPort() == DEFAULT_HTTPS_PORT) {
            registration.addTags(Collections.singletonList("https"));
        } else if (servicePort.getPort() == service.getPort()) {
            registration.addTags(Collections.singletonList("http"));
        }
        newEntries.add(registration);
    });
    return newEntries;
}
Also used : Registration(org.wildfly.swarm.topology.runtime.Registration) IResource(com.openshift.restclient.model.IResource) Service(org.jboss.msc.service.Service) ResourceKind(com.openshift.restclient.ResourceKind) IOpenShiftWatchListener(com.openshift.restclient.IOpenShiftWatchListener) StopContext(org.jboss.msc.service.StopContext) Set(java.util.Set) StartContext(org.jboss.msc.service.StartContext) TopologyManager(org.wildfly.swarm.topology.runtime.TopologyManager) AtomicReference(java.util.concurrent.atomic.AtomicReference) HashSet(java.util.HashSet) List(java.util.List) IClient(com.openshift.restclient.IClient) ServiceName(org.jboss.msc.service.ServiceName) Collections(java.util.Collections) IWatcher(com.openshift.restclient.IWatcher) InjectedValue(org.jboss.msc.value.InjectedValue) IService(com.openshift.restclient.model.IService) Injector(org.jboss.msc.inject.Injector) StartException(org.jboss.msc.service.StartException) Registration(org.wildfly.swarm.topology.runtime.Registration) HashSet(java.util.HashSet)

Example 2 with Registration

use of org.wildfly.swarm.topology.runtime.Registration in project wildfly-swarm by wildfly-swarm.

the class Advertiser method unadvertise.

public void unadvertise(String name, String address, int port) {
    AgentClient client = this.agentClientInjector.getValue();
    Registration r = new Registration("consul", name, address, port, "");
    this.advertisements.stream().filter(e -> e.equals(r)).forEach(e -> {
        String serviceId = serviceId(e);
        log.info("Deregister service " + serviceId);
        client.deregister(serviceId);
    });
    this.advertisements.removeIf(e -> e.equals(r));
}
Also used : Registration(org.wildfly.swarm.topology.runtime.Registration) Service(org.jboss.msc.service.Service) StopContext(org.jboss.msc.service.StopContext) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) StartContext(org.jboss.msc.service.StartContext) Logger(java.util.logging.Logger) NotRegisteredException(com.orbitz.consul.NotRegisteredException) TopologyMessages(org.wildfly.swarm.topology.TopologyMessages) ImmutableRegistration(com.orbitz.consul.model.agent.ImmutableRegistration) ServiceName(org.jboss.msc.service.ServiceName) AgentClient(com.orbitz.consul.AgentClient) Collections(java.util.Collections) InjectedValue(org.jboss.msc.value.InjectedValue) Injector(org.jboss.msc.inject.Injector) StartException(org.jboss.msc.service.StartException) Registration(org.wildfly.swarm.topology.runtime.Registration) ImmutableRegistration(com.orbitz.consul.model.agent.ImmutableRegistration) AgentClient(com.orbitz.consul.AgentClient)

Example 3 with Registration

use of org.wildfly.swarm.topology.runtime.Registration in project wildfly-swarm by wildfly-swarm.

the class ConsulTopologyConnector method advertise.

@Override
public void advertise(String name, SocketBinding binding, String... tags) {
    Registration registration = new Registration("consul", name, binding.getAddress().getHostAddress(), binding.getAbsolutePort(), tags);
    getAdvertiser().advertise(registration);
}
Also used : Registration(org.wildfly.swarm.topology.runtime.Registration)

Example 4 with Registration

use of org.wildfly.swarm.topology.runtime.Registration in project wildfly-swarm by wildfly-swarm.

the class ServiceCacheListener method notify.

@Override
public void notify(Map<HostAndPort, ServiceHealth> newValues) {
    Set<Registration> previousEntries = topologyManager.registrationsForService(this.name);
    Set<Registration> newEntries = newValues.values().stream().map(e -> new Registration("consul", this.name, e.getService().getAddress(), e.getService().getPort()).addTags(e.getService().getTags())).collect(Collectors.toSet());
    previousEntries.stream().filter(e -> !newEntries.contains(e)).forEach(e -> {
        this.topologyManager.unregister(e);
    });
    newEntries.stream().filter(e -> !previousEntries.contains(e)).forEach(e -> {
        this.topologyManager.register(e);
    });
}
Also used : Registration(org.wildfly.swarm.topology.runtime.Registration) ServiceHealth(com.orbitz.consul.model.health.ServiceHealth) Listener(com.orbitz.consul.cache.ConsulCache.Listener) Map(java.util.Map) Set(java.util.Set) TopologyManager(org.wildfly.swarm.topology.runtime.TopologyManager) Collectors(java.util.stream.Collectors) HostAndPort(com.google.common.net.HostAndPort) Registration(org.wildfly.swarm.topology.runtime.Registration)

Example 5 with Registration

use of org.wildfly.swarm.topology.runtime.Registration in project wildfly-swarm by wildfly-swarm.

the class JGroupsTopologyConnector method advertise.

public synchronized void advertise(String name, SocketBinding binding, String... tags) throws Exception {
    Registration registration = new Registration(sourceKey(this.node), name, binding.getAddress().getHostAddress(), binding.getAbsolutePort(), tags);
    this.registrations.put(name + ":" + binding.getName(), registration);
    advertise(registration);
}
Also used : Registration(org.wildfly.swarm.topology.runtime.Registration)

Aggregations

Registration (org.wildfly.swarm.topology.runtime.Registration)5 Set (java.util.Set)3 Collections (java.util.Collections)2 Injector (org.jboss.msc.inject.Injector)2 Service (org.jboss.msc.service.Service)2 ServiceName (org.jboss.msc.service.ServiceName)2 StartContext (org.jboss.msc.service.StartContext)2 StartException (org.jboss.msc.service.StartException)2 StopContext (org.jboss.msc.service.StopContext)2 InjectedValue (org.jboss.msc.value.InjectedValue)2 TopologyManager (org.wildfly.swarm.topology.runtime.TopologyManager)2 HostAndPort (com.google.common.net.HostAndPort)1 IClient (com.openshift.restclient.IClient)1 IOpenShiftWatchListener (com.openshift.restclient.IOpenShiftWatchListener)1 IWatcher (com.openshift.restclient.IWatcher)1 ResourceKind (com.openshift.restclient.ResourceKind)1 IResource (com.openshift.restclient.model.IResource)1 IService (com.openshift.restclient.model.IService)1 AgentClient (com.orbitz.consul.AgentClient)1 NotRegisteredException (com.orbitz.consul.NotRegisteredException)1