Search in sources :

Example 21 with Notification

use of org.apache.activemq.artemis.core.server.management.Notification in project activemq-artemis by apache.

the class ClusteredGroupingTest method testTimeoutOnSending.

@Test
public void testTimeoutOnSending() throws Exception {
    setupServer(0, isFileStorage(), isNetty());
    setupServer(1, isFileStorage(), isNetty());
    setupServer(2, isFileStorage(), isNetty());
    setupClusterConnection("cluster0", "queues", MessageLoadBalancingType.ON_DEMAND, 1, isNetty(), 0, 1, 2);
    setupClusterConnection("cluster1", "queues", MessageLoadBalancingType.ON_DEMAND, 1, isNetty(), 1, 0, 2);
    setupClusterConnection("cluster2", "queues", MessageLoadBalancingType.ON_DEMAND, 1, isNetty(), 2, 0, 1);
    setUpGroupHandler(GroupingHandlerConfiguration.TYPE.REMOTE, 1, 0);
    setUpGroupHandler(GroupingHandlerConfiguration.TYPE.REMOTE, 2, 0);
    final CountDownLatch latch = new CountDownLatch(BindingsImpl.MAX_GROUP_RETRY);
    setUpGroupHandler(new GroupingHandler() {

        @Override
        public void awaitBindings() throws Exception {
        }

        @Override
        public void addListener(UnproposalListener listener) {
        }

        @Override
        public void resendPending() throws Exception {
        }

        @Override
        public void remove(SimpleString groupid, SimpleString clusterName) throws Exception {
        }

        @Override
        public void forceRemove(SimpleString groupid, SimpleString clusterName) throws Exception {
        }

        @Override
        public SimpleString getName() {
            return null;
        }

        @Override
        public void remove(SimpleString id, SimpleString groupId, int distance) {
        // To change body of implemented methods use File | Settings | File Templates.
        }

        @Override
        public void start() throws Exception {
        // To change body of implemented methods use File | Settings | File Templates.
        }

        @Override
        public void stop() throws Exception {
        // To change body of implemented methods use File | Settings | File Templates.
        }

        @Override
        public boolean isStarted() {
            return false;
        }

        @Override
        public Response propose(final Proposal proposal) throws Exception {
            return null;
        }

        @Override
        public void proposed(final Response response) throws Exception {
            System.out.println("ClusteredGroupingTest.proposed");
        }

        @Override
        public void sendProposalResponse(final Response response, final int distance) throws Exception {
            System.out.println("ClusteredGroupingTest.send");
        }

        @Override
        public Response receive(final Proposal proposal, final int distance) throws Exception {
            latch.countDown();
            return null;
        }

        @Override
        public void onNotification(final Notification notification) {
            System.out.println("ClusteredGroupingTest.onNotification " + notification);
        }

        @Override
        public void addGroupBinding(final GroupBinding groupBinding) {
            System.out.println("ClusteredGroupingTest.addGroupBinding");
        }

        @Override
        public Response getProposal(final SimpleString fullID, boolean touchTime) {
            return null;
        }
    }, 0);
    startServers(0, 1, 2);
    setupSessionFactory(0, isNetty());
    setupSessionFactory(1, isNetty());
    setupSessionFactory(2, isNetty());
    createQueue(0, "queues.testaddress", "queue0", null, false);
    createQueue(1, "queues.testaddress", "queue0", null, false);
    createQueue(2, "queues.testaddress", "queue0", null, false);
    addConsumer(0, 0, "queue0", null);
    addConsumer(1, 1, "queue0", null);
    addConsumer(2, 2, "queue0", null);
    waitForBindings(0, "queues.testaddress", 1, 1, true);
    waitForBindings(1, "queues.testaddress", 1, 1, true);
    waitForBindings(2, "queues.testaddress", 1, 1, true);
    waitForBindings(0, "queues.testaddress", 2, 2, false);
    waitForBindings(1, "queues.testaddress", 2, 2, false);
    waitForBindings(2, "queues.testaddress", 2, 2, false);
    try {
        sendWithProperty(1, "queues.testaddress", 1, false, Message.HDR_GROUP_ID, new SimpleString("id1"));
        // it should get the Retries on the latch
        assertTrue(latch.await(10, TimeUnit.SECONDS));
    } catch (Exception e) {
        // To change body of catch statement use File | Settings | File Templates.
        e.printStackTrace();
    }
}
Also used : Response(org.apache.activemq.artemis.core.server.group.impl.Response) UnproposalListener(org.apache.activemq.artemis.core.server.group.UnproposalListener) GroupBinding(org.apache.activemq.artemis.core.server.group.impl.GroupBinding) GroupingHandler(org.apache.activemq.artemis.core.server.group.GroupingHandler) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) CountDownLatch(java.util.concurrent.CountDownLatch) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) Proposal(org.apache.activemq.artemis.core.server.group.impl.Proposal) Notification(org.apache.activemq.artemis.core.server.management.Notification) Test(org.junit.Test)

Example 22 with Notification

use of org.apache.activemq.artemis.core.server.management.Notification in project activemq-artemis by apache.

the class ClusteredResetMockTest method testMultipleSenders.

@Test
public void testMultipleSenders() throws Throwable {
    int NUMBER_OF_SENDERS = 100;
    ReusableLatch latchSends = new ReusableLatch(NUMBER_OF_SENDERS);
    FakeManagement fake = new FakeManagement(latchSends);
    RemoteGroupingHandler handler = new RemoteGroupingHandler(fake, SimpleString.toSimpleString("tst1"), SimpleString.toSimpleString("tst2"), 50000, 499);
    handler.start();
    Sender[] sn = new Sender[NUMBER_OF_SENDERS];
    for (int i = 0; i < sn.length; i++) {
        sn[i] = new Sender("grp" + i, handler);
        sn[i].start();
    }
    try {
        // Waiting two requests to arrive
        Assert.assertTrue(latchSends.await(1, TimeUnit.MINUTES));
        // we will ask a resend.. need to add 2 back
        for (int i = 0; i < NUMBER_OF_SENDERS; i++) {
            // There is no countUp(NUMBER_OF_SENDERS); adding two back on the reusable latch
            latchSends.countUp();
        }
        fake.pendingNotifications.clear();
        handler.resendPending();
        assertTrue(latchSends.await(10, TimeUnit.SECONDS));
        HashSet<SimpleString> codesAsked = new HashSet<>();
        for (Notification notification : fake.pendingNotifications) {
            codesAsked.add(notification.getProperties().getSimpleStringProperty(ManagementHelper.HDR_PROPOSAL_GROUP_ID));
        }
        for (Sender snItem : sn) {
            assertTrue(codesAsked.contains(snItem.code));
        }
        for (int i = NUMBER_OF_SENDERS - 1; i >= 0; i--) {
            // Sending back the response as Notifications would be doing
            Response response = new Response(sn[i].code, ANYCLUSTER);
            handler.proposed(response);
        }
        for (Sender sni : sn) {
            sni.join();
            if (sni.ex != null) {
                throw sni.ex;
            }
        }
    } finally {
        for (Sender sni : sn) {
            sni.interrupt();
        }
    }
}
Also used : ReusableLatch(org.apache.activemq.artemis.utils.ReusableLatch) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Notification(org.apache.activemq.artemis.core.server.management.Notification) HashSet(java.util.HashSet) ConcurrentHashSet(org.apache.activemq.artemis.utils.collections.ConcurrentHashSet) Test(org.junit.Test)

Example 23 with Notification

use of org.apache.activemq.artemis.core.server.management.Notification in project activemq-artemis by apache.

the class DiscoveryGroup method start.

@Override
public synchronized void start() throws Exception {
    if (started) {
        return;
    }
    endpoint.openClient();
    started = true;
    thread = new Thread(new DiscoveryRunnable(), "activemq-discovery-group-thread-" + name);
    thread.setDaemon(true);
    thread.start();
    if (notificationService != null) {
        TypedProperties props = new TypedProperties();
        props.putSimpleStringProperty(new SimpleString("name"), new SimpleString(name));
        Notification notification = new Notification(nodeID, CoreNotificationType.DISCOVERY_GROUP_STARTED, props);
        notificationService.sendNotification(notification);
    }
}
Also used : SimpleString(org.apache.activemq.artemis.api.core.SimpleString) TypedProperties(org.apache.activemq.artemis.utils.collections.TypedProperties) Notification(org.apache.activemq.artemis.core.server.management.Notification)

Example 24 with Notification

use of org.apache.activemq.artemis.core.server.management.Notification in project activemq-artemis by apache.

the class SecurityStoreImpl method check.

@Override
public void check(final SimpleString address, final SimpleString queue, final CheckType checkType, final SecurityAuth session) throws Exception {
    if (securityEnabled) {
        if (logger.isTraceEnabled()) {
            logger.trace("checking access permissions to " + address);
        }
        String user = session.getUsername();
        if (checkCached(address, user, checkType)) {
            // OK
            return;
        }
        String saddress = address.toString();
        Set<Role> roles = securityRepository.getMatch(saddress);
        // bypass permission checks for management cluster user
        if (managementClusterUser.equals(user) && session.getPassword().equals(managementClusterPassword)) {
            return;
        }
        final boolean validated;
        if (securityManager instanceof ActiveMQSecurityManager3) {
            final ActiveMQSecurityManager3 securityManager3 = (ActiveMQSecurityManager3) securityManager;
            validated = securityManager3.validateUserAndRole(user, session.getPassword(), roles, checkType, saddress, session.getRemotingConnection()) != null;
        } else if (securityManager instanceof ActiveMQSecurityManager2) {
            final ActiveMQSecurityManager2 securityManager2 = (ActiveMQSecurityManager2) securityManager;
            validated = securityManager2.validateUserAndRole(user, session.getPassword(), roles, checkType, saddress, session.getRemotingConnection());
        } else {
            validated = securityManager.validateUserAndRole(user, session.getPassword(), roles, checkType);
        }
        if (!validated) {
            if (notificationService != null) {
                TypedProperties props = new TypedProperties();
                props.putSimpleStringProperty(ManagementHelper.HDR_ADDRESS, address);
                props.putSimpleStringProperty(ManagementHelper.HDR_CHECK_TYPE, new SimpleString(checkType.toString()));
                props.putSimpleStringProperty(ManagementHelper.HDR_USER, SimpleString.toSimpleString(user));
                Notification notification = new Notification(null, CoreNotificationType.SECURITY_PERMISSION_VIOLATION, props);
                notificationService.sendNotification(notification);
            }
            if (queue == null) {
                throw ActiveMQMessageBundle.BUNDLE.userNoPermissions(session.getUsername(), checkType, saddress);
            } else {
                throw ActiveMQMessageBundle.BUNDLE.userNoPermissionsQueue(session.getUsername(), checkType, queue.toString(), saddress);
            }
        }
        // if we get here we're granted, add to the cache
        ConcurrentHashSet<SimpleString> set = new ConcurrentHashSet<>();
        ConcurrentHashSet<SimpleString> act = cache.putIfAbsent(user + "." + checkType.name(), set);
        if (act != null) {
            set = act;
        }
        set.add(address);
    }
}
Also used : Role(org.apache.activemq.artemis.core.security.Role) ActiveMQSecurityManager2(org.apache.activemq.artemis.spi.core.security.ActiveMQSecurityManager2) ConcurrentHashSet(org.apache.activemq.artemis.utils.collections.ConcurrentHashSet) ActiveMQSecurityManager3(org.apache.activemq.artemis.spi.core.security.ActiveMQSecurityManager3) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) TypedProperties(org.apache.activemq.artemis.utils.collections.TypedProperties) Notification(org.apache.activemq.artemis.core.server.management.Notification)

Example 25 with Notification

use of org.apache.activemq.artemis.core.server.management.Notification in project activemq-artemis by apache.

the class BridgeImpl method stop.

@Override
public void stop() throws Exception {
    if (stopping) {
        return;
    }
    stopping = true;
    if (logger.isDebugEnabled()) {
        logger.debug("Bridge " + this.name + " being stopped");
    }
    if (futureScheduledReconnection != null) {
        futureScheduledReconnection.cancel(true);
    }
    executor.execute(new StopRunnable());
    if (notificationService != null) {
        TypedProperties props = new TypedProperties();
        props.putSimpleStringProperty(new SimpleString("name"), name);
        Notification notification = new Notification(nodeUUID.toString(), CoreNotificationType.BRIDGE_STOPPED, props);
        try {
            notificationService.sendNotification(notification);
        } catch (Exception e) {
            ActiveMQServerLogger.LOGGER.broadcastBridgeStoppedError(e);
        }
    }
}
Also used : SimpleString(org.apache.activemq.artemis.api.core.SimpleString) TypedProperties(org.apache.activemq.artemis.utils.collections.TypedProperties) Notification(org.apache.activemq.artemis.core.server.management.Notification) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQInterruptedException(org.apache.activemq.artemis.api.core.ActiveMQInterruptedException)

Aggregations

Notification (org.apache.activemq.artemis.core.server.management.Notification)35 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)26 TypedProperties (org.apache.activemq.artemis.utils.collections.TypedProperties)24 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)9 Test (org.junit.Test)9 SimpleNotificationService (org.apache.activemq.artemis.tests.integration.SimpleNotificationService)5 CountDownLatch (java.util.concurrent.CountDownLatch)3 ActiveMQInterruptedException (org.apache.activemq.artemis.api.core.ActiveMQInterruptedException)3 Channel (io.netty.channel.Channel)2 ServerChannel (io.netty.channel.ServerChannel)2 EpollServerSocketChannel (io.netty.channel.epoll.EpollServerSocketChannel)2 KQueueServerSocketChannel (io.netty.channel.kqueue.KQueueServerSocketChannel)2 LocalServerChannel (io.netty.channel.local.LocalServerChannel)2 NioServerSocketChannel (io.netty.channel.socket.nio.NioServerSocketChannel)2 InetAddress (java.net.InetAddress)2 ActiveMQIllegalStateException (org.apache.activemq.artemis.api.core.ActiveMQIllegalStateException)2 ActiveMQNonExistentQueueException (org.apache.activemq.artemis.api.core.ActiveMQNonExistentQueueException)2 BroadcastEndpoint (org.apache.activemq.artemis.api.core.BroadcastEndpoint)2 CoreNotificationType (org.apache.activemq.artemis.api.core.management.CoreNotificationType)2 ClusterConnection (org.apache.activemq.artemis.core.server.cluster.ClusterConnection)2