Search in sources :

Example 1 with VirtualHost

use of org.apache.qpid.server.model.VirtualHost in project qpid by apache.

the class QmfManagementAgent method childAdded.

/**
 * ConfigurationChangeListener method called when a child ConfiguredObject is added.
 * <p>
 * This method checks the type of the child ConfiguredObject that has been added and creates the equivalent
 * QMF2 Management Object if one doesn't already exist. In most cases it's a one-to-one mapping, but for
 * Binding for example the Binding child is added to both Queue and Exchange so we only create the Binding
 * QMF2 Management Object once and add the queueRef and exchangeRef reference properties referencing the Queue
 * and Exchange parent Objects respectively, Similarly for Consumer (AKA Subscription).
 * <p>
 * This method is also responsible for raising the appropriate QMF2 Events when Management Objects are created.
 * @param object the parent object that the child is being added to.
 * @param child the child object being added.
 */
@Override
public void childAdded(final ConfiguredObject object, final ConfiguredObject child) {
    if (_log.isDebugEnabled()) {
        _log.debug("childAdded: " + child.getClass().getSimpleName() + "." + child.getName());
    }
    QmfAgentData data = null;
    if (child instanceof Broker) {
        data = new org.apache.qpid.server.qmf2.agentdata.Broker((Broker) child);
    } else if (child instanceof Connection) {
        if (!agentConnection && !_objects.containsKey(child)) {
            // If the parent object is the default vhost set it to null so that the Connection ignores it.
            VirtualHost vhost = (object.getName().equals(_defaultVirtualHost)) ? null : (VirtualHost) object;
            data = new org.apache.qpid.server.qmf2.agentdata.Connection(vhost, (Connection) child);
            _objects.put(child, data);
            // Raise a Client Connect Event.
            _agent.raiseEvent(((org.apache.qpid.server.qmf2.agentdata.Connection) data).createClientConnectEvent());
        }
        // Only ignore the first Connection, which is the one from the Agent.
        agentConnection = false;
    } else if (child instanceof Session) {
        if (!_objects.containsKey(child)) {
            // Get the Connection QmfAgentData so we can get connectionRef.
            QmfAgentData ref = _objects.get(object);
            if (ref != null) {
                data = new org.apache.qpid.server.qmf2.agentdata.Session((Session) child, ref.getObjectId());
                _objects.put(child, data);
            }
        }
    } else if (child instanceof Exchange) {
        if (!_objects.containsKey(child)) {
            // If the parent object is the default vhost set it to null so that the Connection ignores it.
            VirtualHost vhost = (object.getName().equals(_defaultVirtualHost)) ? null : (VirtualHost) object;
            data = new org.apache.qpid.server.qmf2.agentdata.Exchange(vhost, (Exchange) child);
            _objects.put(child, data);
            // Raise an Exchange Declare Event.
            _agent.raiseEvent(((org.apache.qpid.server.qmf2.agentdata.Exchange) data).createExchangeDeclareEvent());
        }
    } else if (child instanceof Queue) {
        if (!_objects.containsKey(child)) {
            // If the parent object is the default vhost set it to null so that the Connection ignores it.
            VirtualHost vhost = (object.getName().equals(_defaultVirtualHost)) ? null : (VirtualHost) object;
            data = new org.apache.qpid.server.qmf2.agentdata.Queue(vhost, (Queue) child);
            _objects.put(child, data);
            // Raise a Queue Declare Event.
            _agent.raiseEvent(((org.apache.qpid.server.qmf2.agentdata.Queue) data).createQueueDeclareEvent());
        }
    } else if (child instanceof Binding) {
        // depending on whether Queue or Exchange was the parent of this addChild() call.
        if (!_objects.containsKey(child)) {
            data = new org.apache.qpid.server.qmf2.agentdata.Binding((Binding) child);
            _objects.put(child, data);
            String eName = ((Binding) child).getExchange().getName();
            if (// Don't send Event for Binding to default direct.
            !eName.equals("<<default>>")) {
                // Raise a Bind Event.
                _agent.raiseEvent(((org.apache.qpid.server.qmf2.agentdata.Binding) data).createBindEvent());
            }
        }
        org.apache.qpid.server.qmf2.agentdata.Binding binding = (org.apache.qpid.server.qmf2.agentdata.Binding) _objects.get(child);
        QmfAgentData ref = _objects.get(object);
        if (ref != null) {
            if (object instanceof Queue) {
                binding.setQueueRef(ref.getObjectId());
            } else if (object instanceof Exchange) {
                binding.setExchangeRef(ref.getObjectId());
            }
        }
    } else if (// AKA Subscription
    child instanceof Consumer) {
        // Session reference depending on whether Queue or Session was the parent of this addChild() call.
        if (!_objects.containsKey(child)) {
            data = new org.apache.qpid.server.qmf2.agentdata.Subscription((Consumer) child);
            _objects.put(child, data);
        }
        org.apache.qpid.server.qmf2.agentdata.Subscription subscription = (org.apache.qpid.server.qmf2.agentdata.Subscription) _objects.get(child);
        QmfAgentData ref = _objects.get(object);
        if (ref != null) {
            if (object instanceof Queue) {
                subscription.setQueueRef(ref.getObjectId(), (Queue) object);
                // Raise a Subscribe Event - N.B. Need to do it *after* we've set the queueRef.
                _agent.raiseEvent(subscription.createSubscribeEvent());
            } else if (object instanceof Session) {
                subscription.setSessionRef(ref.getObjectId());
            }
        }
    }
    try {
        // If we've created new QmfAgentData we register it with the Agent.
        if (data != null) {
            _agent.addObject(data);
        }
    } catch (QmfException qmfe) {
        _log.error("QmfException caught in QmfManagementAgent.addObject()", qmfe);
    }
    child.addChangeListener(this);
}
Also used : Binding(org.apache.qpid.server.model.Binding) Broker(org.apache.qpid.server.model.Broker) Connection(org.apache.qpid.server.model.Connection) Exchange(org.apache.qpid.server.model.Exchange) Consumer(org.apache.qpid.server.model.Consumer) QmfAgentData(org.apache.qpid.qmf2.agent.QmfAgentData) VirtualHost(org.apache.qpid.server.model.VirtualHost) Queue(org.apache.qpid.server.model.Queue) Session(org.apache.qpid.server.model.Session) QmfException(org.apache.qpid.qmf2.common.QmfException)

Example 2 with VirtualHost

use of org.apache.qpid.server.model.VirtualHost 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 3 with VirtualHost

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

the class CacheFactoryTest method getCache.

@Test
public void getCache() {
    String cacheName = "test";
    final Cache<Object, Object> cache = new NullCache<>();
    final CacheProvider virtualHost = mock(CacheProvider.class, withSettings().extraInterfaces(VirtualHost.class));
    when(virtualHost.getNamedCache(cacheName)).thenReturn(cache);
    final Subject subject = new Subject();
    subject.getPrincipals().add(new VirtualHostPrincipal((VirtualHost<?>) virtualHost));
    subject.setReadOnly();
    Cache<String, String> actualCache = Subject.doAs(subject, (PrivilegedAction<Cache<String, String>>) () -> CacheFactory.getCache(cacheName, null));
    assertSame(actualCache, cache);
    verify(virtualHost).getNamedCache(cacheName);
}
Also used : VirtualHost(org.apache.qpid.server.model.VirtualHost) Subject(javax.security.auth.Subject) Cache(com.google.common.cache.Cache) Test(org.junit.Test)

Example 4 with VirtualHost

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

the class UpgradeFrom7To8Test method assertConfiguredObjectHierarchy.

private void assertConfiguredObjectHierarchy() {
    Map<UpgradeHierarchyKey, UUID> hierarchy = loadConfiguredObjectHierarchy();
    assertEquals("Unexpected number of configured objects", 13, hierarchy.size());
    UUID vhUuid = UUIDGenerator.generateVhostUUID(getVirtualHost().getName());
    UUID myExchUuid = UUIDGenerator.generateExchangeUUID("myexch", getVirtualHost().getName());
    UUID amqDirectUuid = UUIDGenerator.generateExchangeUUID("amq.direct", getVirtualHost().getName());
    UUID queue1Uuid = UUIDGenerator.generateQueueUUID("queue1", getVirtualHost().getName());
    UUID queue1ToAmqDirectBindingUuid = UUIDGenerator.generateBindingUUID("amq.direct", "queue1", "queue1", getVirtualHost().getName());
    // myexch -> virtualhost
    UpgradeHierarchyKey myExchToVhParent = new UpgradeHierarchyKey(myExchUuid, VirtualHost.class.getSimpleName());
    assertExpectedHierarchyEntry(hierarchy, myExchToVhParent, vhUuid);
    // queue1 -> virtualhost
    UpgradeHierarchyKey queue1ToVhParent = new UpgradeHierarchyKey(queue1Uuid, VirtualHost.class.getSimpleName());
    assertExpectedHierarchyEntry(hierarchy, queue1ToVhParent, vhUuid);
    // queue1binding -> amq.direct
    // queue1binding -> queue1
    UpgradeHierarchyKey queue1BindingToAmqDirect = new UpgradeHierarchyKey(queue1ToAmqDirectBindingUuid, Exchange.class.getSimpleName());
    UpgradeHierarchyKey queue1BindingToQueue1 = new UpgradeHierarchyKey(queue1ToAmqDirectBindingUuid, Queue.class.getSimpleName());
    assertExpectedHierarchyEntry(hierarchy, queue1BindingToAmqDirect, amqDirectUuid);
    assertExpectedHierarchyEntry(hierarchy, queue1BindingToQueue1, queue1Uuid);
    String[] defaultExchanges = { "amq.topic", "amq.fanout", "amq.direct", "amq.match" };
    for (String exchangeName : defaultExchanges) {
        UUID id = UUIDGenerator.generateExchangeUUID(exchangeName, getVirtualHost().getName());
        UpgradeHierarchyKey exchangeParent = new UpgradeHierarchyKey(id, VirtualHost.class.getSimpleName());
        assertExpectedHierarchyEntry(hierarchy, exchangeParent, vhUuid);
    }
}
Also used : Exchange(org.apache.qpid.server.model.Exchange) VirtualHost(org.apache.qpid.server.model.VirtualHost) UUID(java.util.UUID) Queue(org.apache.qpid.server.model.Queue)

Example 5 with VirtualHost

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

the class AbstractUpgradeTestCase method getVirtualHost.

public VirtualHost getVirtualHost() {
    VirtualHost virtualHost = mock(VirtualHost.class);
    when(virtualHost.getName()).thenReturn(getTestName());
    when(virtualHost.getId()).thenReturn(UUID.randomUUID());
    return virtualHost;
}
Also used : VirtualHost(org.apache.qpid.server.model.VirtualHost)

Aggregations

VirtualHost (org.apache.qpid.server.model.VirtualHost)16 Broker (org.apache.qpid.server.model.Broker)5 ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)5 Test (org.junit.Test)4 Exchange (org.apache.qpid.server.model.Exchange)3 Queue (org.apache.qpid.server.model.Queue)3 HashMap (java.util.HashMap)2 QmfAgentData (org.apache.qpid.qmf2.agent.QmfAgentData)2 AbstractConfigurationChangeListener (org.apache.qpid.server.model.AbstractConfigurationChangeListener)2 Binding (org.apache.qpid.server.model.Binding)2 TrustStore (org.apache.qpid.server.model.TrustStore)2 VirtualHostNode (org.apache.qpid.server.model.VirtualHostNode)2 ConfiguredObjectRecord (org.apache.qpid.server.store.ConfiguredObjectRecord)2 MessageStore (org.apache.qpid.server.store.MessageStore)2 TestMemoryMessageStore (org.apache.qpid.server.store.TestMemoryMessageStore)2 Before (org.junit.Before)2 Cache (com.google.common.cache.Cache)1 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 StringReader (java.io.StringReader)1