Search in sources :

Example 16 with Pair

use of org.apache.activemq.artemis.api.core.Pair in project activemq-artemis by apache.

the class JournalStorageManager method recoverPendingLargeMessages.

/**
 * Sets a list of large message files into the replicationManager for synchronization.
 * <p>
 * Collects a list of existing large messages and their current size, passing re.
 * <p>
 * So we know how much of a given message to sync with the backup. Further data appends to the
 * messages will be replicated normally.
 *
 * @throws Exception
 */
private Map<Long, Pair<String, Long>> recoverPendingLargeMessages() throws Exception {
    Map<Long, Pair<String, Long>> largeMessages = new HashMap<>();
    // only send durable messages... // listFiles append a "." to anything...
    List<String> filenames = largeMessagesFactory.listFiles("msg");
    List<Long> idList = new ArrayList<>();
    for (String filename : filenames) {
        Long id = getLargeMessageIdFromFilename(filename);
        if (!largeMessagesToDelete.contains(id)) {
            idList.add(id);
            SequentialFile seqFile = largeMessagesFactory.createSequentialFile(filename);
            long size = seqFile.size();
            largeMessages.put(id, new Pair<>(filename, size));
        }
    }
    return largeMessages;
}
Also used : SequentialFile(org.apache.activemq.artemis.core.io.SequentialFile) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Pair(org.apache.activemq.artemis.api.core.Pair)

Example 17 with Pair

use of org.apache.activemq.artemis.api.core.Pair in project activemq-artemis by apache.

the class FileConfigurationParser method parseSecuritySettingPlugins.

private Pair<SecuritySettingPlugin, Map<String, String>> parseSecuritySettingPlugins(Node item) {
    final String clazz = item.getAttributes().getNamedItem("class-name").getNodeValue();
    final Map<String, String> settings = new HashMap<>();
    NodeList children = item.getChildNodes();
    for (int j = 0; j < children.getLength(); j++) {
        Node child = children.item(j);
        final String nodeName = child.getNodeName();
        if (SETTING_ELEMENT_NAME.equalsIgnoreCase(nodeName)) {
            final String settingName = getAttributeValue(child, NAME_ATTR_NAME);
            final String settingValue = getAttributeValue(child, VALUE_ATTR_NAME);
            settings.put(settingName, settingValue);
        }
    }
    SecuritySettingPlugin securitySettingPlugin = AccessController.doPrivileged(new PrivilegedAction<SecuritySettingPlugin>() {

        @Override
        public SecuritySettingPlugin run() {
            return (SecuritySettingPlugin) ClassloadingUtil.newInstanceFromClassLoader(clazz);
        }
    });
    return new Pair<>(securitySettingPlugin, settings);
}
Also used : HashMap(java.util.HashMap) SecuritySettingPlugin(org.apache.activemq.artemis.core.server.SecuritySettingPlugin) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Pair(org.apache.activemq.artemis.api.core.Pair)

Example 18 with Pair

use of org.apache.activemq.artemis.api.core.Pair in project activemq-artemis by apache.

the class FileConfigurationParser method parseSecurityRoles.

/**
 * @param node
 * @return
 */
protected Pair<String, Set<Role>> parseSecurityRoles(final Node node, final Map<String, Set<String>> roleMappings) {
    final String match = node.getAttributes().getNamedItem("match").getNodeValue();
    Set<Role> securityRoles = new HashSet<>();
    Pair<String, Set<Role>> securityMatch = new Pair<>(match, securityRoles);
    ArrayList<String> send = new ArrayList<>();
    ArrayList<String> consume = new ArrayList<>();
    ArrayList<String> createDurableQueue = new ArrayList<>();
    ArrayList<String> deleteDurableQueue = new ArrayList<>();
    ArrayList<String> createNonDurableQueue = new ArrayList<>();
    ArrayList<String> deleteNonDurableQueue = new ArrayList<>();
    ArrayList<String> manageRoles = new ArrayList<>();
    ArrayList<String> browseRoles = new ArrayList<>();
    ArrayList<String> createAddressRoles = new ArrayList<>();
    ArrayList<String> deleteAddressRoles = new ArrayList<>();
    ArrayList<String> allRoles = new ArrayList<>();
    NodeList children = node.getChildNodes();
    for (int i = 0; i < children.getLength(); i++) {
        Node child = children.item(i);
        final String name = child.getNodeName();
        if (PERMISSION_ELEMENT_NAME.equalsIgnoreCase(name)) {
            final String type = getAttributeValue(child, TYPE_ATTR_NAME);
            final String roleString = getAttributeValue(child, ROLES_ATTR_NAME);
            String[] roles = roleString.split(",");
            String[] mappedRoles = getMappedRoleNames(roles, roleMappings);
            for (String role : mappedRoles) {
                if (SEND_NAME.equals(type)) {
                    send.add(role.trim());
                } else if (CONSUME_NAME.equals(type)) {
                    consume.add(role.trim());
                } else if (CREATEDURABLEQUEUE_NAME.equals(type)) {
                    createDurableQueue.add(role.trim());
                } else if (DELETEDURABLEQUEUE_NAME.equals(type)) {
                    deleteDurableQueue.add(role.trim());
                } else if (CREATE_NON_DURABLE_QUEUE_NAME.equals(type)) {
                    createNonDurableQueue.add(role.trim());
                } else if (DELETE_NON_DURABLE_QUEUE_NAME.equals(type)) {
                    deleteNonDurableQueue.add(role.trim());
                } else if (CREATETEMPQUEUE_NAME.equals(type)) {
                    createNonDurableQueue.add(role.trim());
                } else if (DELETETEMPQUEUE_NAME.equals(type)) {
                    deleteNonDurableQueue.add(role.trim());
                } else if (MANAGE_NAME.equals(type)) {
                    manageRoles.add(role.trim());
                } else if (BROWSE_NAME.equals(type)) {
                    browseRoles.add(role.trim());
                } else if (CREATEADDRESS_NAME.equals(type)) {
                    createAddressRoles.add(role.trim());
                } else if (DELETEADDRESS_NAME.equals(type)) {
                    deleteAddressRoles.add(role.trim());
                } else {
                    ActiveMQServerLogger.LOGGER.rolePermissionConfigurationError(type);
                }
                if (!allRoles.contains(role.trim())) {
                    allRoles.add(role.trim());
                }
            }
        }
    }
    for (String role : allRoles) {
        securityRoles.add(new Role(role, send.contains(role), consume.contains(role), createDurableQueue.contains(role), deleteDurableQueue.contains(role), createNonDurableQueue.contains(role), deleteNonDurableQueue.contains(role), manageRoles.contains(role), browseRoles.contains(role), createAddressRoles.contains(role), deleteAddressRoles.contains(role)));
    }
    return securityMatch;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Role(org.apache.activemq.artemis.core.security.Role) HashSet(java.util.HashSet) Pair(org.apache.activemq.artemis.api.core.Pair)

Example 19 with Pair

use of org.apache.activemq.artemis.api.core.Pair in project activemq-artemis by apache.

the class DuplicateDetectionUnitTest method testReloadDuplication.

// Public --------------------------------------------------------
@Test
public void testReloadDuplication() throws Exception {
    JournalStorageManager journal = null;
    try {
        clearDataRecreateServerDirs();
        SimpleString ADDRESS = new SimpleString("address");
        Configuration configuration = createDefaultInVMConfig();
        PostOffice postOffice = new FakePostOffice();
        ScheduledExecutorService scheduledThreadPool = Executors.newScheduledThreadPool(ActiveMQDefaultConfiguration.getDefaultScheduledThreadPoolMaxSize(), ActiveMQThreadFactory.defaultThreadFactory());
        journal = new JournalStorageManager(configuration, EmptyCriticalAnalyzer.getInstance(), factory, factory);
        journal.start();
        journal.loadBindingJournal(new ArrayList<QueueBindingInfo>(), new ArrayList<GroupingInfo>(), new ArrayList<AddressBindingInfo>());
        HashMap<SimpleString, List<Pair<byte[], Long>>> mapDups = new HashMap<>();
        FakePagingManager pagingManager = new FakePagingManager();
        journal.loadMessageJournal(postOffice, pagingManager, new ResourceManagerImpl(0, 0, scheduledThreadPool), null, mapDups, null, null, new PostOfficeJournalLoader(postOffice, pagingManager, null, null, null, null, null, null));
        Assert.assertEquals(0, mapDups.size());
        DuplicateIDCacheImpl cacheID = new DuplicateIDCacheImpl(ADDRESS, 10, journal, true);
        for (int i = 0; i < 100; i++) {
            cacheID.addToCache(RandomUtil.randomBytes());
        }
        journal.stop();
        journal = new JournalStorageManager(configuration, EmptyCriticalAnalyzer.getInstance(), factory, factory);
        journal.start();
        journal.loadBindingJournal(new ArrayList<QueueBindingInfo>(), new ArrayList<GroupingInfo>(), new ArrayList<AddressBindingInfo>());
        journal.loadMessageJournal(postOffice, pagingManager, new ResourceManagerImpl(0, 0, scheduledThreadPool), null, mapDups, null, null, new PostOfficeJournalLoader(postOffice, pagingManager, null, null, null, null, null, null));
        Assert.assertEquals(1, mapDups.size());
        List<Pair<byte[], Long>> values = mapDups.get(ADDRESS);
        Assert.assertEquals(10, values.size());
        cacheID = new DuplicateIDCacheImpl(ADDRESS, 10, journal, true);
        cacheID.load(values);
        for (int i = 0; i < 100; i++) {
            cacheID.addToCache(RandomUtil.randomBytes(), null);
        }
        journal.stop();
        mapDups.clear();
        journal = new JournalStorageManager(configuration, EmptyCriticalAnalyzer.getInstance(), factory, factory);
        journal.start();
        journal.loadBindingJournal(new ArrayList<QueueBindingInfo>(), new ArrayList<GroupingInfo>(), new ArrayList<AddressBindingInfo>());
        journal.loadMessageJournal(postOffice, pagingManager, new ResourceManagerImpl(0, 0, scheduledThreadPool), null, mapDups, null, null, new PostOfficeJournalLoader(postOffice, pagingManager, null, null, null, null, null, null));
        Assert.assertEquals(1, mapDups.size());
        values = mapDups.get(ADDRESS);
        Assert.assertEquals(10, values.size());
        scheduledThreadPool.shutdown();
    } finally {
        if (journal != null) {
            try {
                journal.stop();
            } catch (Throwable ignored) {
            }
        }
    }
}
Also used : PostOfficeJournalLoader(org.apache.activemq.artemis.core.server.impl.PostOfficeJournalLoader) GroupingInfo(org.apache.activemq.artemis.core.persistence.GroupingInfo) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Configuration(org.apache.activemq.artemis.core.config.Configuration) ActiveMQDefaultConfiguration(org.apache.activemq.artemis.api.config.ActiveMQDefaultConfiguration) HashMap(java.util.HashMap) ResourceManagerImpl(org.apache.activemq.artemis.core.transaction.impl.ResourceManagerImpl) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) FakePostOffice(org.apache.activemq.artemis.tests.unit.core.server.impl.fakes.FakePostOffice) PostOffice(org.apache.activemq.artemis.core.postoffice.PostOffice) QueueBindingInfo(org.apache.activemq.artemis.core.persistence.QueueBindingInfo) FakePostOffice(org.apache.activemq.artemis.tests.unit.core.server.impl.fakes.FakePostOffice) JournalStorageManager(org.apache.activemq.artemis.core.persistence.impl.journal.JournalStorageManager) DuplicateIDCacheImpl(org.apache.activemq.artemis.core.postoffice.impl.DuplicateIDCacheImpl) FakePagingManager(org.apache.activemq.artemis.tests.unit.util.FakePagingManager) ArrayList(java.util.ArrayList) List(java.util.List) AddressBindingInfo(org.apache.activemq.artemis.core.persistence.AddressBindingInfo) Pair(org.apache.activemq.artemis.api.core.Pair) Test(org.junit.Test)

Example 20 with Pair

use of org.apache.activemq.artemis.api.core.Pair in project activemq-artemis by apache.

the class MultiServerTestBase method setupLiveServer.

protected Pair<ActiveMQServer, NodeManager> setupLiveServer(final int node, final boolean realFiles, final boolean sharedStorage) throws Exception {
    NodeManager nodeManager = null;
    TransportConfiguration serverConfigAcceptor = createTransportConfiguration(useNetty(), true, generateParams(node, useNetty()));
    TransportConfiguration thisConnector = createTransportConfiguration(useNetty(), false, generateParams(node, useNetty()));
    if (sharedStorage) {
        nodeManager = new InVMNodeManager(false);
    }
    Configuration configuration = createBasicConfig(node).setJournalMaxIO_AIO(1000).setThreadPoolMaxSize(10).clearAcceptorConfigurations().addAcceptorConfiguration(serverConfigAcceptor).addConnectorConfiguration("thisConnector", thisConnector).setHAPolicyConfiguration(sharedStorage ? new SharedStoreMasterPolicyConfiguration() : new ReplicatedPolicyConfiguration());
    List<String> targetServersOnConnection = new ArrayList<>();
    for (int targetNode = 0; targetNode < getNumberOfServers(); targetNode++) {
        if (targetNode == node) {
            continue;
        }
        String targetConnectorName = "target-" + targetNode;
        TransportConfiguration targetServer = createTransportConfiguration(useNetty(), false, generateParams(targetNode, useNetty()));
        configuration.getConnectorConfigurations().put(targetConnectorName, targetServer);
        targetServersOnConnection.add(targetConnectorName);
        // The connector towards a backup.. just to have a reference so bridges can connect to backups on their configs
        String backupConnectorName = "backup-" + targetNode;
        TransportConfiguration backupConnector = createTransportConfiguration(useNetty(), false, generateParams(targetNode + getNumberOfServers(), useNetty()));
        configuration.getConnectorConfigurations().put(backupConnectorName, backupConnector);
    }
    ClusterConnectionConfiguration clusterConf = new ClusterConnectionConfiguration().setName("localCluster" + node).setAddress("cluster-queues").setConnectorName("thisConnector").setRetryInterval(100).setConfirmationWindowSize(1024).setMessageLoadBalancingType(MessageLoadBalancingType.ON_DEMAND).setStaticConnectors(targetServersOnConnection);
    configuration.getClusterConfigurations().add(clusterConf);
    ActiveMQServer server;
    if (sharedStorage) {
        server = createInVMFailoverServer(realFiles, configuration, nodeManager, node);
    } else {
        server = createServer(realFiles, configuration);
    }
    server.setIdentity(this.getClass().getSimpleName() + "/Live(" + node + ")");
    addServer(server);
    return new Pair<>(server, nodeManager);
}
Also used : ClusterConnectionConfiguration(org.apache.activemq.artemis.core.config.ClusterConnectionConfiguration) InVMNodeManager(org.apache.activemq.artemis.core.server.impl.InVMNodeManager) Configuration(org.apache.activemq.artemis.core.config.Configuration) ReplicaPolicyConfiguration(org.apache.activemq.artemis.core.config.ha.ReplicaPolicyConfiguration) SharedStoreMasterPolicyConfiguration(org.apache.activemq.artemis.core.config.ha.SharedStoreMasterPolicyConfiguration) SharedStoreSlavePolicyConfiguration(org.apache.activemq.artemis.core.config.ha.SharedStoreSlavePolicyConfiguration) ClusterConnectionConfiguration(org.apache.activemq.artemis.core.config.ClusterConnectionConfiguration) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) ReplicatedPolicyConfiguration(org.apache.activemq.artemis.core.config.ha.ReplicatedPolicyConfiguration) ArrayList(java.util.ArrayList) SharedStoreMasterPolicyConfiguration(org.apache.activemq.artemis.core.config.ha.SharedStoreMasterPolicyConfiguration) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) InVMNodeManager(org.apache.activemq.artemis.core.server.impl.InVMNodeManager) NodeManager(org.apache.activemq.artemis.core.server.NodeManager) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) ReplicatedPolicyConfiguration(org.apache.activemq.artemis.core.config.ha.ReplicatedPolicyConfiguration) Pair(org.apache.activemq.artemis.api.core.Pair)

Aggregations

Pair (org.apache.activemq.artemis.api.core.Pair)29 ArrayList (java.util.ArrayList)16 HashMap (java.util.HashMap)12 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)12 List (java.util.List)6 Map (java.util.Map)6 SequentialFile (org.apache.activemq.artemis.core.io.SequentialFile)5 JournalFile (org.apache.activemq.artemis.core.journal.impl.JournalFile)5 HashSet (java.util.HashSet)4 TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)4 JournalImpl (org.apache.activemq.artemis.core.journal.impl.JournalImpl)4 Test (org.junit.Test)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)3 Message (org.apache.activemq.artemis.api.core.Message)3 PreparedTransactionInfo (org.apache.activemq.artemis.core.journal.PreparedTransactionInfo)3 RecordInfo (org.apache.activemq.artemis.core.journal.RecordInfo)3 LargeServerMessage (org.apache.activemq.artemis.core.server.LargeServerMessage)3 PersistedBindings (org.apache.activemq.artemis.jms.persistence.config.PersistedBindings)3 PersistedType (org.apache.activemq.artemis.jms.persistence.config.PersistedType)3