Search in sources :

Example 1 with VirtualHostNode

use of org.apache.qpid.server.model.VirtualHostNode in project qpid-broker-j by apache.

the class TrustStoreMessageSourceCreator method register.

@Override
public void register(final SystemNodeRegistry registry) {
    final VirtualHost<?> vhost = registry.getVirtualHost();
    VirtualHostNode<?> virtualHostNode = (VirtualHostNode<?>) vhost.getParent();
    final Broker<?> broker = (Broker<?>) virtualHostNode.getParent();
    final Collection<TrustStore> trustStores = broker.getChildren(TrustStore.class);
    final TrustStoreChangeListener trustStoreChangeListener = new TrustStoreChangeListener(registry);
    for (final TrustStore trustStore : trustStores) {
        updateTrustStoreSourceRegistration(registry, trustStore);
        trustStore.addChangeListener(trustStoreChangeListener);
    }
    AbstractConfigurationChangeListener brokerListener = new AbstractConfigurationChangeListener() {

        @Override
        public void childAdded(final ConfiguredObject<?> object, final ConfiguredObject<?> child) {
            if (child instanceof TrustStore) {
                TrustStore<?> trustStore = (TrustStore<?>) child;
                updateTrustStoreSourceRegistration(registry, trustStore);
                trustStore.addChangeListener(trustStoreChangeListener);
            }
        }

        @Override
        public void childRemoved(final ConfiguredObject<?> object, final ConfiguredObject<?> child) {
            if (child instanceof TrustStore) {
                TrustStore<?> trustStore = (TrustStore<?>) child;
                trustStore.removeChangeListener(trustStoreChangeListener);
                registry.removeSystemNode(TrustStoreMessageSource.getSourceNameFromTrustStore(trustStore));
            } else if (child == virtualHostNode) {
                object.removeChangeListener(this);
                broker.getChildren(TrustStore.class).forEach(t -> t.removeChangeListener(trustStoreChangeListener));
            }
        }
    };
    broker.addChangeListener(brokerListener);
    virtualHostNode.addChangeListener(new AbstractConfigurationChangeListener() {

        @Override
        public void childRemoved(final ConfiguredObject<?> object, final ConfiguredObject<?> child) {
            if (child == vhost) {
                broker.removeChangeListener(brokerListener);
                object.removeChangeListener(this);
                broker.getChildren(TrustStore.class).forEach(t -> t.removeChangeListener(trustStoreChangeListener));
            }
        }
    });
}
Also used : TrustStore(org.apache.qpid.server.model.TrustStore) VirtualHost(org.apache.qpid.server.model.VirtualHost) PluggableService(org.apache.qpid.server.plugin.PluggableService) Collection(java.util.Collection) Broker(org.apache.qpid.server.model.Broker) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) State(org.apache.qpid.server.model.State) SystemNodeCreator(org.apache.qpid.server.plugin.SystemNodeCreator) AbstractConfigurationChangeListener(org.apache.qpid.server.model.AbstractConfigurationChangeListener) VirtualHostNode(org.apache.qpid.server.model.VirtualHostNode) Broker(org.apache.qpid.server.model.Broker) TrustStore(org.apache.qpid.server.model.TrustStore) AbstractConfigurationChangeListener(org.apache.qpid.server.model.AbstractConfigurationChangeListener) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) VirtualHostNode(org.apache.qpid.server.model.VirtualHostNode)

Example 2 with VirtualHostNode

use of org.apache.qpid.server.model.VirtualHostNode in project qpid-broker-j by apache.

the class VirtualHostAliasTest method setUp.

@Before
public void setUp() throws Exception {
    _broker = BrokerTestHelper.createBrokerMock();
    AuthenticationProvider dummyAuthProvider = mock(AuthenticationProvider.class);
    when(dummyAuthProvider.getName()).thenReturn("dummy");
    when(dummyAuthProvider.getId()).thenReturn(UUID.randomUUID());
    when(dummyAuthProvider.getMechanisms()).thenReturn(Arrays.asList("PLAIN"));
    when(_broker.getChildren(eq(AuthenticationProvider.class))).thenReturn(Collections.singleton(dummyAuthProvider));
    for (String name : new String[] { "red", "blue", "purple", "black" }) {
        boolean defaultVHN = "black".equals(name);
        VirtualHost<?> virtualHost = BrokerTestHelper.createVirtualHost(name, _broker, defaultVHN, this);
        VirtualHostNode vhn = (VirtualHostNode) virtualHost.getParent();
        assertNotSame(vhn.getName(), virtualHost.getName());
        _vhosts.put(name, virtualHost);
        if (defaultVHN) {
            when(_broker.findDefautVirtualHostNode()).thenReturn(vhn);
        }
    }
    ConfiguredObjectFactory objectFactory = _broker.getObjectFactory();
    final Map<String, Object> attributes = new HashMap<>();
    attributes.put(Port.NAME, getTestName());
    attributes.put(Port.PORT, 0);
    attributes.put(Port.AUTHENTICATION_PROVIDER, "dummy");
    attributes.put(Port.TYPE, "AMQP");
    _port = (AmqpPort) objectFactory.create(Port.class, attributes, _broker);
}
Also used : ConfiguredObjectFactory(org.apache.qpid.server.model.ConfiguredObjectFactory) HashMap(java.util.HashMap) AuthenticationProvider(org.apache.qpid.server.model.AuthenticationProvider) VirtualHostNode(org.apache.qpid.server.model.VirtualHostNode) Before(org.junit.Before)

Example 3 with VirtualHostNode

use of org.apache.qpid.server.model.VirtualHostNode in project qpid-broker-j by apache.

the class JDBCVirtualHostNodeTest method testDeleteAction.

@Test
public void testDeleteAction() {
    _connectionURL = "jdbc:derby:memory:/" + getTestName();
    Map<String, Object> attributes = new HashMap<>();
    attributes.put(ConfiguredObject.NAME, getTestName());
    attributes.put(ConfiguredObject.TYPE, JDBCVirtualHostNodeImpl.VIRTUAL_HOST_NODE_TYPE);
    attributes.put("connectionUrl", _connectionURL + ";create=true");
    Broker<?> broker = BrokerTestHelper.createBrokerMock();
    final VirtualHostNode virtualHostNode = broker.getObjectFactory().create(VirtualHostNode.class, attributes, broker);
    virtualHostNode.start();
    AtomicBoolean deleted = new AtomicBoolean();
    ((JDBCContainer) virtualHostNode).addDeleteAction(object -> deleted.set(true));
    virtualHostNode.delete();
    assertEquals("Delete action was not invoked", true, deleted.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) JDBCContainer(org.apache.qpid.server.store.jdbc.JDBCContainer) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) VirtualHostNode(org.apache.qpid.server.model.VirtualHostNode) Test(org.junit.Test)

Example 4 with VirtualHostNode

use of org.apache.qpid.server.model.VirtualHostNode in project qpid-broker-j by apache.

the class AbstractVirtualHostNode method validateChange.

@Override
protected void validateChange(final ConfiguredObject<?> proxyForValidation, final Set<String> changedAttributes) {
    super.validateChange(proxyForValidation, changedAttributes);
    VirtualHostNode updated = (VirtualHostNode) proxyForValidation;
    if (changedAttributes.contains(DEFAULT_VIRTUAL_HOST_NODE) && updated.isDefaultVirtualHostNode()) {
        VirtualHostNode existingDefault = _broker.findDefautVirtualHostNode();
        if (existingDefault != null && existingDefault != this) {
            throw new IntegrityViolationException("Cannot make '" + getName() + "' the default virtual host node for" + " the Broker as virtual host node '" + existingDefault.getName() + "' is already the default.");
        }
    }
}
Also used : VirtualHostNode(org.apache.qpid.server.model.VirtualHostNode) IntegrityViolationException(org.apache.qpid.server.model.IntegrityViolationException)

Example 5 with VirtualHostNode

use of org.apache.qpid.server.model.VirtualHostNode in project qpid-broker-j by apache.

the class ProvidedStoreVirtualHostImpl method createMessageStore.

@Override
protected MessageStore createMessageStore() {
    VirtualHostNode<?> virtualHostNode = (VirtualHostNode) getParent();
    MessageStoreProvider messageStoreProvider = (MessageStoreProvider) virtualHostNode.getConfigurationStore();
    return messageStoreProvider.getMessageStore();
}
Also used : MessageStoreProvider(org.apache.qpid.server.store.MessageStoreProvider) VirtualHostNode(org.apache.qpid.server.model.VirtualHostNode)

Aggregations

VirtualHostNode (org.apache.qpid.server.model.VirtualHostNode)14 ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)7 HashMap (java.util.HashMap)6 IllegalConfigurationException (org.apache.qpid.server.configuration.IllegalConfigurationException)4 DurableConfigurationStore (org.apache.qpid.server.store.DurableConfigurationStore)4 AbstractConfigurationChangeListener (org.apache.qpid.server.model.AbstractConfigurationChangeListener)3 AbstractConfiguredObject (org.apache.qpid.server.model.AbstractConfiguredObject)3 Broker (org.apache.qpid.server.model.Broker)3 VirtualHost (org.apache.qpid.server.model.VirtualHost)3 Test (org.junit.Test)3 File (java.io.File)2 Principal (java.security.Principal)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 TaskExecutorImpl (org.apache.qpid.server.configuration.updater.TaskExecutorImpl)2 EventLogger (org.apache.qpid.server.logging.EventLogger)2 BrokerModel (org.apache.qpid.server.model.BrokerModel)2 AccessControl (org.apache.qpid.server.security.AccessControl)2 MessageStoreProvider (org.apache.qpid.server.store.MessageStoreProvider)2 PreferenceStore (org.apache.qpid.server.store.preferences.PreferenceStore)2 Cache (com.google.common.cache.Cache)1