Search in sources :

Example 11 with DurableConfigurationStore

use of org.apache.qpid.server.store.DurableConfigurationStore in project qpid-broker-j by apache.

the class BrokerTestHelper method createVirtualHost.

private static QueueManagingVirtualHost<?> createVirtualHost(final Map<String, Object> attributes, final Broker<?> broker, boolean defaultVHN, AccessControl accessControl) {
    ConfiguredObjectFactory objectFactory = broker.getObjectFactory();
    VirtualHostNode virtualHostNode = mockWithSystemPrincipalAndAccessControl(VirtualHostNode.class, SYSTEM_PRINCIPAL, accessControl);
    String virtualHostNodeName = String.format("%s_%s", attributes.get(VirtualHostNode.NAME), "_node");
    when(virtualHostNode.getName()).thenReturn(virtualHostNodeName);
    when(virtualHostNode.getTaskExecutor()).thenReturn(TASK_EXECUTOR);
    when(virtualHostNode.getChildExecutor()).thenReturn(TASK_EXECUTOR);
    when(virtualHostNode.isDefaultVirtualHostNode()).thenReturn(defaultVHN);
    when(virtualHostNode.getParent()).thenReturn(broker);
    Collection<VirtualHostNode<?>> nodes = broker.getVirtualHostNodes();
    nodes = new ArrayList<>(nodes != null ? nodes : Collections.<VirtualHostNode<?>>emptyList());
    nodes.add(virtualHostNode);
    when(broker.getVirtualHostNodes()).thenReturn(nodes);
    DurableConfigurationStore dcs = mock(DurableConfigurationStore.class);
    when(virtualHostNode.getConfigurationStore()).thenReturn(dcs);
    when(virtualHostNode.getModel()).thenReturn(objectFactory.getModel());
    when(virtualHostNode.getObjectFactory()).thenReturn(objectFactory);
    when(virtualHostNode.getCategoryClass()).thenReturn(VirtualHostNode.class);
    when(virtualHostNode.getTaskExecutor()).thenReturn(TASK_EXECUTOR);
    when(virtualHostNode.getChildExecutor()).thenReturn(TASK_EXECUTOR);
    when(virtualHostNode.createPreferenceStore()).thenReturn(mock(PreferenceStore.class));
    AbstractVirtualHost host = (AbstractVirtualHost) objectFactory.create(VirtualHost.class, attributes, virtualHostNode);
    host.start();
    when(virtualHostNode.getVirtualHost()).thenReturn(host);
    _createdVirtualHosts.add(host);
    QpidTestCase testCase = QpidTestCase.getCurrentInstance();
    testCase.registerTearDown(_closeVirtualHosts);
    return host;
}
Also used : DurableConfigurationStore(org.apache.qpid.server.store.DurableConfigurationStore) AbstractVirtualHost(org.apache.qpid.server.virtualhost.AbstractVirtualHost) QpidTestCase(org.apache.qpid.test.utils.QpidTestCase) AbstractVirtualHost(org.apache.qpid.server.virtualhost.AbstractVirtualHost) TestMemoryVirtualHost(org.apache.qpid.server.virtualhost.TestMemoryVirtualHost) QueueManagingVirtualHost(org.apache.qpid.server.virtualhost.QueueManagingVirtualHost) PreferenceStore(org.apache.qpid.server.store.preferences.PreferenceStore)

Example 12 with DurableConfigurationStore

use of org.apache.qpid.server.store.DurableConfigurationStore in project qpid-broker-j by apache.

the class TestBrokerConfiguration method save.

public boolean save(File configFile) {
    Map<String, Object> attributes = new HashMap<>();
    attributes.put("storePath", configFile.getAbsolutePath());
    SystemConfigFactory configFactory = (new PluggableFactoryLoader<>(SystemConfigFactory.class)).get(_storeType);
    attributes.put(SystemConfig.STARTUP_LOGGED_TO_SYSTEM_OUT, false);
    attributes.put(ConfiguredObject.DESIRED_STATE, State.QUIESCED);
    final SystemConfig parentObject = configFactory.newInstance(_taskExecutor, mock(EventLogger.class), null, attributes);
    parentObject.open();
    DurableConfigurationStore configurationStore = parentObject.getConfigurationStore();
    configurationStore.closeConfigurationStore();
    final List<ConfiguredObjectRecord> records = getConfiguredObjectRecords();
    configurationStore.init(parentObject);
    clearStore(configurationStore);
    configurationStore.update(true, records.toArray(new ConfiguredObjectRecord[records.size()]));
    configurationStore.closeConfigurationStore();
    parentObject.close();
    return true;
}
Also used : SystemConfig(org.apache.qpid.server.model.SystemConfig) AbstractSystemConfig(org.apache.qpid.server.model.AbstractSystemConfig) DurableConfigurationStore(org.apache.qpid.server.store.DurableConfigurationStore) HashMap(java.util.HashMap) EventLogger(org.apache.qpid.server.logging.EventLogger) SystemConfigFactory(org.apache.qpid.server.plugin.SystemConfigFactory) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) ConfiguredObjectRecord(org.apache.qpid.server.store.ConfiguredObjectRecord) PluggableFactoryLoader(org.apache.qpid.server.plugin.PluggableFactoryLoader)

Example 13 with DurableConfigurationStore

use of org.apache.qpid.server.store.DurableConfigurationStore in project qpid-broker-j by apache.

the class BDBHAVirtualHostNodeImpl method onDelete.

@Override
protected ListenableFuture<Void> onDelete() {
    final Set<InetSocketAddress> helpers = getRemoteNodeAddresses();
    return doAfterAlways(closeVirtualHostIfExists(), () -> {
        closeEnvironment();
        DurableConfigurationStore configurationStore = getConfigurationStore();
        if (configurationStore != null) {
            configurationStore.closeConfigurationStore();
            configurationStore.onDelete(BDBHAVirtualHostNodeImpl.this);
            getEventLogger().message(getVirtualHostNodeLogSubject(), HighAvailabilityMessages.DELETE(getName(), String.valueOf(Outcome.SUCCESS)));
        }
        if (!helpers.isEmpty()) {
            try {
                new ReplicationGroupAdmin(_groupName, helpers).removeMember(getName());
            } catch (DatabaseException e) {
                LOGGER.warn(String.format("The deletion of node %s on remote nodes failed due to: %s. To finish deletion a " + "removal of the node from any of remote nodes (%s) is required.", this, e.getMessage(), helpers));
            }
        }
        onCloseOrDelete();
    });
}
Also used : DurableConfigurationStore(org.apache.qpid.server.store.DurableConfigurationStore) InetSocketAddress(java.net.InetSocketAddress) ReplicationGroupAdmin(com.sleepycat.je.rep.util.ReplicationGroupAdmin) DatabaseException(com.sleepycat.je.DatabaseException)

Example 14 with DurableConfigurationStore

use of org.apache.qpid.server.store.DurableConfigurationStore in project qpid-broker-j by apache.

the class BDBHAVirtualHostNodeTest method testCreateAndActivateVirtualHostNode.

@Test
public void testCreateAndActivateVirtualHostNode() throws Exception {
    int node1PortNumber = _portHelper.getNextAvailable();
    String helperAddress = "localhost:" + node1PortNumber;
    String groupName = "group";
    String nodeName = "node1";
    Map<String, Object> attributes = _helper.createNodeAttributes(nodeName, groupName, helperAddress, helperAddress, nodeName, node1PortNumber);
    String messageStorePath = (String) attributes.get(BDBHAVirtualHostNode.STORE_PATH);
    String repStreamTimeout = "2 h";
    Map<String, String> context = (Map<String, String>) attributes.get(BDBHAVirtualHostNode.CONTEXT);
    context.put(ReplicationConfig.REP_STREAM_TIMEOUT, repStreamTimeout);
    context.put(EnvironmentConfig.ENV_IS_TRANSACTIONAL, "false");
    try {
        _helper.createHaVHN(attributes);
        fail("Exception was not thrown.");
    } catch (RuntimeException e) {
        final boolean condition = e.getCause() instanceof IllegalArgumentException;
        assertTrue("Unexpected Exception being thrown.", condition);
    }
    context.put(EnvironmentConfig.ENV_IS_TRANSACTIONAL, "true");
    BDBHAVirtualHostNode<?> node = _helper.createHaVHN(attributes);
    node.start();
    _helper.assertNodeRole(node, NodeRole.MASTER, NodeRole.REPLICA);
    assertEquals("Unexpected node state", State.ACTIVE, node.getState());
    DurableConfigurationStore store = node.getConfigurationStore();
    assertNotNull(store);
    BDBConfigurationStore bdbConfigurationStore = (BDBConfigurationStore) store;
    ReplicatedEnvironmentFacade environmentFacade = (ReplicatedEnvironmentFacade) bdbConfigurationStore.getEnvironmentFacade();
    assertEquals(nodeName, environmentFacade.getNodeName());
    assertEquals(groupName, environmentFacade.getGroupName());
    assertEquals(helperAddress, environmentFacade.getHostPort());
    assertEquals(helperAddress, environmentFacade.getHelperHostPort());
    assertEquals("SYNC,NO_SYNC,SIMPLE_MAJORITY", environmentFacade.getMessageStoreDurability().toString());
    _helper.awaitForVirtualhost(node);
    VirtualHost<?> virtualHost = node.getVirtualHost();
    assertNotNull("Virtual host child was not added", virtualHost);
    assertEquals("Unexpected virtual host name", groupName, virtualHost.getName());
    assertEquals("Unexpected virtual host store", bdbConfigurationStore.getMessageStore(), virtualHost.getMessageStore());
    assertEquals("Unexpected virtual host state", State.ACTIVE, virtualHost.getState());
    node.stop();
    assertEquals("Unexpected state returned after stop", State.STOPPED, node.getState());
    assertEquals("Unexpected state", State.STOPPED, node.getState());
    assertNull("Virtual host is not destroyed", node.getVirtualHost());
    node.delete();
    assertEquals("Unexpected state returned after delete", State.DELETED, node.getState());
    assertEquals("Unexpected state", State.DELETED, node.getState());
    assertFalse("Store still exists " + messageStorePath, new File(messageStorePath).exists());
}
Also used : DurableConfigurationStore(org.apache.qpid.server.store.DurableConfigurationStore) ReplicatedEnvironmentFacade(org.apache.qpid.server.store.berkeleydb.replication.ReplicatedEnvironmentFacade) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) Map(java.util.Map) HashMap(java.util.HashMap) File(java.io.File) Test(org.junit.Test)

Example 15 with DurableConfigurationStore

use of org.apache.qpid.server.store.DurableConfigurationStore in project qpid-broker-j by apache.

the class AbstractVirtualHostNode method closeConfigurationStore.

private void closeConfigurationStore() {
    DurableConfigurationStore configurationStore = getConfigurationStore();
    if (configurationStore != null) {
        configurationStore.closeConfigurationStore();
        getEventLogger().message(getConfigurationStoreLogSubject(), ConfigStoreMessages.CLOSE());
    }
}
Also used : DurableConfigurationStore(org.apache.qpid.server.store.DurableConfigurationStore)

Aggregations

DurableConfigurationStore (org.apache.qpid.server.store.DurableConfigurationStore)30 ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)21 Test (org.junit.Test)18 HashMap (java.util.HashMap)14 IllegalConfigurationException (org.apache.qpid.server.configuration.IllegalConfigurationException)5 ConfiguredObjectRecord (org.apache.qpid.server.store.ConfiguredObjectRecord)4 AccessControlException (java.security.AccessControlException)3 AccessControl (org.apache.qpid.server.security.AccessControl)3 PreferenceStore (org.apache.qpid.server.store.preferences.PreferenceStore)3 UUID (java.util.UUID)2 AbstractSystemConfig (org.apache.qpid.server.model.AbstractSystemConfig)2 VirtualHostNode (org.apache.qpid.server.model.VirtualHostNode)2 TestMemoryVirtualHost (org.apache.qpid.server.virtualhost.TestMemoryVirtualHost)2 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 DatabaseException (com.sleepycat.je.DatabaseException)1 ReplicationGroupAdmin (com.sleepycat.je.rep.util.ReplicationGroupAdmin)1 File (java.io.File)1 IOException (java.io.IOException)1 InetSocketAddress (java.net.InetSocketAddress)1 ArrayList (java.util.ArrayList)1