Search in sources :

Example 16 with Group

use of org.wildfly.clustering.group.Group in project wildfly by wildfly.

the class AbstractLocalGroupServiceConfigurator method build.

@Override
public ServiceBuilder<?> build(ServiceTarget target) {
    ServiceBuilder<?> builder = target.addService(this.getServiceName());
    this.environment = builder.requires(ServerEnvironmentService.SERVICE_NAME);
    Consumer<Group> group = builder.provides(this.getServiceName());
    Service service = new FunctionalService<>(group, this, this.environment);
    return builder.setInstance(service).setInitialMode(ServiceController.Mode.ON_DEMAND);
}
Also used : Group(org.wildfly.clustering.group.Group) FunctionalService(org.wildfly.clustering.service.FunctionalService) FunctionalService(org.wildfly.clustering.service.FunctionalService) Service(org.jboss.msc.Service) ServerEnvironmentService(org.jboss.as.server.ServerEnvironmentService)

Example 17 with Group

use of org.wildfly.clustering.group.Group in project wildfly by wildfly.

the class RankedRouteLocatorTestCase method test.

@Test
public void test() {
    KeyDistribution distribution = mock(KeyDistribution.class);
    NodeFactory<Address> factory = mock(NodeFactory.class);
    Registry<String, Void> registry = mock(Registry.class);
    Group group = mock(Group.class);
    Address owner1 = mock(Address.class);
    Address owner2 = mock(Address.class);
    Address owner3 = mock(Address.class);
    Address owner4 = mock(Address.class);
    Address unregistered = mock(Address.class);
    Address local = mock(Address.class);
    Node member1 = mock(Node.class);
    Node member2 = mock(Node.class);
    Node member3 = mock(Node.class);
    Node member4 = mock(Node.class);
    Node unregisteredMember = mock(Node.class);
    Node localMember = mock(Node.class);
    when(registry.getGroup()).thenReturn(group);
    when(group.getLocalMember()).thenReturn(localMember);
    when(registry.getEntry(member1)).thenReturn(new SimpleImmutableEntry<>("member1", null));
    when(registry.getEntry(member2)).thenReturn(new SimpleImmutableEntry<>("member2", null));
    when(registry.getEntry(member3)).thenReturn(new SimpleImmutableEntry<>("member3", null));
    when(registry.getEntry(member4)).thenReturn(new SimpleImmutableEntry<>("member4", null));
    when(registry.getEntry(localMember)).thenReturn(new SimpleImmutableEntry<>("local", null));
    when(registry.getEntry(unregisteredMember)).thenReturn(null);
    when(factory.createNode(owner1)).thenReturn(member1);
    when(factory.createNode(owner2)).thenReturn(member2);
    when(factory.createNode(owner3)).thenReturn(member3);
    when(factory.createNode(owner4)).thenReturn(member4);
    when(factory.createNode(local)).thenReturn(localMember);
    when(factory.createNode(unregistered)).thenReturn(unregisteredMember);
    RouteLocator locator = new RankedRouteLocator(distribution, registry, factory, ".", 3);
    when(distribution.getOwners(new GroupedKey<>("key"))).thenReturn(Arrays.asList(owner1, owner2, owner3, owner4));
    assertEquals("member1.member2.member3", locator.locate("key"));
    when(distribution.getOwners(new GroupedKey<>("key"))).thenReturn(Arrays.asList(owner1, owner2, owner3, local));
    assertEquals("member1.member2.member3", locator.locate("key"));
    when(distribution.getOwners(new GroupedKey<>("key"))).thenReturn(Arrays.asList(owner1, owner2, unregistered, owner4));
    assertEquals("member1.member2.member4", locator.locate("key"));
    when(distribution.getOwners(new GroupedKey<>("key"))).thenReturn(Arrays.asList(owner1, local, owner3));
    assertEquals("member1.local.member3", locator.locate("key"));
    when(distribution.getOwners(new GroupedKey<>("key"))).thenReturn(Arrays.asList(owner1, owner2));
    assertEquals("member1.member2.local", locator.locate("key"));
    when(distribution.getOwners(new GroupedKey<>("key"))).thenReturn(Arrays.asList(local, owner2));
    assertEquals("local.member2", locator.locate("key"));
    when(distribution.getOwners(new GroupedKey<>("key"))).thenReturn(Arrays.asList(owner1));
    assertEquals("member1.local", locator.locate("key"));
    when(distribution.getOwners(new GroupedKey<>("key"))).thenReturn(Arrays.asList(local));
    assertEquals("local", locator.locate("key"));
    when(distribution.getOwners(new GroupedKey<>("key"))).thenReturn(Arrays.asList(unregistered));
    assertEquals("local", locator.locate("key"));
    when(distribution.getOwners(new GroupedKey<>("key"))).thenReturn(Collections.emptyList());
    assertEquals("local", locator.locate("key"));
}
Also used : Group(org.wildfly.clustering.group.Group) RouteLocator(org.wildfly.clustering.web.routing.RouteLocator) Address(org.infinispan.remoting.transport.Address) Node(org.wildfly.clustering.group.Node) KeyDistribution(org.wildfly.clustering.infinispan.spi.distribution.KeyDistribution) Test(org.junit.Test)

Example 18 with Group

use of org.wildfly.clustering.group.Group in project wildfly by wildfly.

the class PrimaryOwnerRouteLocatorTestCase method test.

@Test
public void test() {
    Function<GroupedKey<String>, Node> locator = mock(Function.class);
    Registry<String, Void> registry = mock(Registry.class);
    Group group = mock(Group.class);
    Node primary = mock(Node.class);
    Node local = mock(Node.class);
    Node missing = mock(Node.class);
    String primaryRoute = "primary";
    String localRoute = "local";
    when(registry.getGroup()).thenReturn(group);
    when(group.getLocalMember()).thenReturn(local);
    when(registry.getEntry(local)).thenReturn(new SimpleImmutableEntry<>(localRoute, null));
    RouteLocator routeLocator = new PrimaryOwnerRouteLocator(locator, registry);
    when(locator.apply(new GroupedKey<>("session"))).thenReturn(primary);
    when(registry.getEntry(primary)).thenReturn(new SimpleImmutableEntry<>(primaryRoute, null));
    String result = routeLocator.locate("session");
    assertSame(primaryRoute, result);
    when(locator.apply(new GroupedKey<>("missing"))).thenReturn(missing);
    when(registry.getEntry(missing)).thenReturn(null);
    result = routeLocator.locate("missing");
    assertSame(localRoute, result);
}
Also used : Group(org.wildfly.clustering.group.Group) RouteLocator(org.wildfly.clustering.web.routing.RouteLocator) Node(org.wildfly.clustering.group.Node) GroupedKey(org.wildfly.clustering.ee.infinispan.GroupedKey) Test(org.junit.Test)

Example 19 with Group

use of org.wildfly.clustering.group.Group in project wildfly by wildfly.

the class AssociationService method start.

@Override
public void start(final StartContext context) throws StartException {
    // todo suspendController
    // noinspection unchecked
    List<Map.Entry<ProtocolSocketBinding, Registry<String, List<ClientMapping>>>> clientMappingsRegistries = this.clientMappingsRegistries.isEmpty() ? Collections.emptyList() : new ArrayList<>(this.clientMappingsRegistries.size());
    for (Map.Entry<Value<ProtocolSocketBinding>, Value<Registry>> entry : this.clientMappingsRegistries) {
        clientMappingsRegistries.add(new SimpleImmutableEntry<>(entry.getKey().getValue(), entry.getValue().getValue()));
    }
    value = new AssociationImpl(deploymentRepositoryInjector.getValue(), clientMappingsRegistries);
    String ourNodeName = serverEnvironmentServiceInjector.getValue().getNodeName();
    // track deployments at an association level for local dispatchers to utilize
    moduleAvailabilityListener = value.registerModuleAvailabilityListener(new ModuleAvailabilityListener() {

        public void moduleAvailable(final List<EJBModuleIdentifier> modules) {
            synchronized (serviceLock) {
                ourModules.addAll(modules);
                cachedServiceURL = null;
            }
        }

        public void moduleUnavailable(final List<EJBModuleIdentifier> modules) {
            synchronized (serviceLock) {
                ourModules.removeAll(modules);
                cachedServiceURL = null;
            }
        }
    });
    // do this last
    mutableDiscoveryProvider.setDiscoveryProvider((serviceType, filterSpec, result) -> {
        ServiceURL serviceURL = this.cachedServiceURL;
        if (serviceURL == null) {
            synchronized (serviceLock) {
                serviceURL = this.cachedServiceURL;
                if (serviceURL == null) {
                    ServiceURL.Builder b = new ServiceURL.Builder();
                    b.setUri(Affinity.LOCAL.getUri()).setAbstractType("ejb").setAbstractTypeAuthority("jboss");
                    b.addAttribute(EJBClientContext.FILTER_ATTR_NODE, AttributeValue.fromString(ourNodeName));
                    for (Map.Entry<ProtocolSocketBinding, Registry<String, List<ClientMapping>>> entry : clientMappingsRegistries) {
                        Group group = entry.getValue().getGroup();
                        if (!group.isSingleton()) {
                            b.addAttribute(EJBClientContext.FILTER_ATTR_CLUSTER, AttributeValue.fromString(group.getName()));
                        }
                    }
                    for (EJBModuleIdentifier moduleIdentifier : ourModules) {
                        final String appName = moduleIdentifier.getAppName();
                        final String moduleName = moduleIdentifier.getModuleName();
                        final String distinctName = moduleIdentifier.getDistinctName();
                        if (distinctName.isEmpty()) {
                            if (appName.isEmpty()) {
                                b.addAttribute(EJBClientContext.FILTER_ATTR_EJB_MODULE, AttributeValue.fromString(moduleName));
                            } else {
                                b.addAttribute(EJBClientContext.FILTER_ATTR_EJB_MODULE, AttributeValue.fromString(appName + '/' + moduleName));
                            }
                        } else {
                            if (appName.isEmpty()) {
                                b.addAttribute(EJBClientContext.FILTER_ATTR_EJB_MODULE_DISTINCT, AttributeValue.fromString(moduleName + '/' + distinctName));
                            } else {
                                b.addAttribute(EJBClientContext.FILTER_ATTR_EJB_MODULE_DISTINCT, AttributeValue.fromString(appName + '/' + moduleName + '/' + distinctName));
                            }
                        }
                    }
                    serviceURL = this.cachedServiceURL = b.create();
                }
            }
        }
        if (serviceURL.satisfies(filterSpec)) {
            result.addMatch(serviceURL);
        }
        result.complete();
        return DiscoveryRequest.NULL;
    });
}
Also used : Group(org.wildfly.clustering.group.Group) EJBModuleIdentifier(org.jboss.ejb.client.EJBModuleIdentifier) Registry(org.wildfly.clustering.registry.Registry) ModuleAvailabilityListener(org.jboss.ejb.server.ModuleAvailabilityListener) SimpleImmutableEntry(java.util.AbstractMap.SimpleImmutableEntry) ProtocolSocketBinding(org.jboss.as.network.ProtocolSocketBinding) Value(org.jboss.msc.value.Value) AttributeValue(org.wildfly.discovery.AttributeValue) InjectedValue(org.jboss.msc.value.InjectedValue) ServiceURL(org.wildfly.discovery.ServiceURL) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) ClientMapping(org.jboss.as.network.ClientMapping) Map(java.util.Map) AbstractMap(java.util.AbstractMap)

Aggregations

Group (org.wildfly.clustering.group.Group)19 Test (org.junit.Test)7 InjectedValue (org.jboss.msc.value.InjectedValue)6 Node (org.wildfly.clustering.group.Node)6 TransactionBatch (org.wildfly.clustering.ee.cache.tx.TransactionBatch)4 Duration (java.time.Duration)3 Service (org.jboss.msc.Service)3 ServiceRegistryException (org.jboss.msc.service.ServiceRegistryException)3 FunctionalService (org.wildfly.clustering.service.FunctionalService)3 SingletonPolicy (org.wildfly.clustering.singleton.SingletonPolicy)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 CommandDispatcherException (org.wildfly.clustering.dispatcher.CommandDispatcherException)2 NamePreference (org.wildfly.clustering.singleton.election.NamePreference)2 PreferredSingletonElectionPolicy (org.wildfly.clustering.singleton.election.PreferredSingletonElectionPolicy)2 SimpleSingletonElectionPolicy (org.wildfly.clustering.singleton.election.SimpleSingletonElectionPolicy)2 RouteLocator (org.wildfly.clustering.web.routing.RouteLocator)2 AbstractMap (java.util.AbstractMap)1 SimpleImmutableEntry (java.util.AbstractMap.SimpleImmutableEntry)1 LinkedList (java.util.LinkedList)1