Search in sources :

Example 6 with VirtualHost

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

the class AbstractVirtualHostNode method getInitialRecords.

protected final ConfiguredObjectRecord[] getInitialRecords() throws IOException {
    final ConfiguredObjectRecordConverter converter = new ConfiguredObjectRecordConverter(getModel());
    final Collection<ConfiguredObjectRecord> records;
    try (final Reader initialConfigReader = getInitialConfigReader()) {
        records = new ArrayList<>(converter.readFromJson(VirtualHost.class, this, initialConfigReader));
    }
    if (!records.isEmpty()) {
        ConfiguredObjectRecord vhostRecord = null;
        for (ConfiguredObjectRecord record : records) {
            if (record.getType().equals(VirtualHost.class.getSimpleName())) {
                vhostRecord = record;
                break;
            }
        }
        if (vhostRecord != null) {
            records.remove(vhostRecord);
            vhostRecord = enrichInitialVirtualHostRootRecord(vhostRecord);
            records.add(vhostRecord);
        } else {
            // this should be impossible as the converter should always generate a parent record
            throw new IllegalConfigurationException("Somehow the initial configuration has records but " + "not a VirtualHost. This must be a coding error in Qpid");
        }
        addStandardExchangesIfNecessary(records, vhostRecord);
        enrichWithAuditInformation(records);
    }
    return records.toArray(new ConfiguredObjectRecord[records.size()]);
}
Also used : ConfiguredObjectRecordConverter(org.apache.qpid.server.store.ConfiguredObjectRecordConverter) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) StringReader(java.io.StringReader) ConfiguredObjectRecord(org.apache.qpid.server.store.ConfiguredObjectRecord) VirtualHost(org.apache.qpid.server.model.VirtualHost) NonStandardVirtualHost(org.apache.qpid.server.virtualhost.NonStandardVirtualHost)

Example 7 with VirtualHost

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

the class VirtualHostAliasTest method tearDown.

@Override
protected void tearDown() throws Exception {
    _port.close();
    for (VirtualHost vhost : _vhosts.values()) {
        vhost.close();
    }
    super.tearDown();
}
Also used : VirtualHost(org.apache.qpid.server.model.VirtualHost)

Example 8 with VirtualHost

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

the class Broker method invokeMethod.

/**
 * This method acts as a single entry point for QMF methods invoked on the Broker Object.
 *
 * @param agent the org.apache.qpid.qmf2.agent.Agent instance that we call methodResponse() and raiseException() on.
 * @param handle the reply handle used by methodResponse() and raiseException().
 * @param methodName the name of the QMF method being invoked.
 * @param inArgs a Map of input arguments wrapped in a QmfData Object.
 */
@SuppressWarnings("unchecked")
public void invokeMethod(Agent agent, Handle handle, String methodName, QmfData inArgs) {
    if (methodName.equals("create") || methodName.equals("delete")) {
        QmfData outArgs = new QmfData();
        String name = inArgs.getStringValue("name");
        String type = inArgs.getStringValue("type");
        NameParser nameParser = new NameParser(name, type);
        String vhostName = nameParser.getVirtualHostName();
        VirtualHost vhost = nameParser.getVirtualHost();
        if (vhost == null) {
            if (vhostName == null) {
                agent.raiseException(handle, "VirtualHost names for exchange and queue must match.");
            } else {
                agent.raiseException(handle, "VirtualHost " + vhostName + " not found.");
            }
        } else {
            if (// method = create
            methodName.equals("create")) {
                try {
                    // boolean strict = inArgs.getBooleanValue("strict");
                    Map<String, Object> properties = inArgs.getValue("properties");
                    boolean durable = false;
                    Object property = properties.get("durable");
                    if (property != null && property instanceof Boolean) {
                        Boolean durableProperty = (Boolean) property;
                        durable = durableProperty.booleanValue();
                        properties.remove("durable");
                    }
                    if (// create exchange.
                    type.equals("exchange")) {
                        /*
System.out.println("Create Exchange");
System.out.println("vhostName = " + vhostName);
System.out.println("exchange name = " + nameParser.getExchangeName());
System.out.println("properties = " + properties);
*/
                        String exchangeType = "";
                        property = properties.get("exchange-type");
                        if (property != null && property instanceof String) {
                            exchangeType = property.toString();
                            properties.remove("exchange-type");
                        }
                        String alternateExchange = parseAlternateExchange(vhostName, properties);
                        if (alternateExchange != null && alternateExchange.equals("invalid")) {
                            agent.raiseException(handle, "Alternate Exchange must belong to the same Virtual Host as the Exchange being added.");
                            return;
                        }
                        // Note that for Qpid 0.20 the "qpid.msg_sequence=1" and "qpid.ive=1" properties are
                        // not suppored, indeed no exchange properties seem to be supported yet.
                        Map<String, Object> attributes = new HashMap<>();
                        attributes.put(Exchange.NAME, nameParser.getExchangeName());
                        attributes.put(Exchange.STATE, State.ACTIVE);
                        attributes.put(Exchange.DURABLE, durable);
                        attributes.put(Exchange.LIFETIME_POLICY, LifetimePolicy.PERMANENT);
                        attributes.put(Exchange.TYPE, exchangeType);
                        attributes.put(Exchange.ALTERNATE_EXCHANGE, alternateExchange);
                        vhost.createExchange(attributes);
                    } else // End of create exchange.
                    if (// create queue.
                    type.equals("queue")) {
                        /*
System.out.println("Create Queue");
System.out.println("vhostName = " + vhostName);
System.out.println("queue name = " + nameParser.getQueueName());
System.out.println("properties = " + properties);
*/
                        // TODO Try to map from the QMF create queue properties to the closest equivalents on
                        // the Java Broker. Unfortunately there are a *lot* of frustrating little differences.
                        String alternateExchange = parseAlternateExchange(vhostName, properties);
                        if (alternateExchange != null && alternateExchange.equals("invalid")) {
                            agent.raiseException(handle, "Alternate Exchange must belong to the same Virtual Host as the Queue being added.");
                            return;
                        }
                        // I don't *think* that it make sense to allow setting exclusive or autoDelete to
                        // a queue created from config.
                        Map<String, Object> attributes = new HashMap<String, Object>(properties);
                        attributes.put(Queue.NAME, nameParser.getQueueName());
                        attributes.put(Queue.DURABLE, durable);
                        attributes.put(Queue.LIFETIME_POLICY, LifetimePolicy.PERMANENT);
                        // to work, so we may as well make use of this convenience here too.
                        if (alternateExchange != null) {
                            ObjectId objectId = new ObjectId("", "org.apache.qpid.broker:exchange:" + alternateExchange, 0);
                            // Look up Exchange QmfAgentData by ObjectId from the Agent's internal Object store.
                            QmfAgentData object = agent.getObject(objectId);
                            if (object != null) {
                                org.apache.qpid.server.qmf2.agentdata.Exchange ex = (org.apache.qpid.server.qmf2.agentdata.Exchange) object;
                                Exchange altEx = ex.getExchange();
                                attributes.put(Queue.ALTERNATE_EXCHANGE, altEx.getId());
                            }
                        }
                        Queue queue = vhost.createQueue(attributes);
                    } else if (// create binding.
                    type.equals("binding")) {
                        Exchange exchange = nameParser.getExchange();
                        if (exchange == null) {
                            agent.raiseException(handle, "Cannot create binding on Exchange " + nameParser.getExchangeName());
                            return;
                        } else {
                            Map<String, Object> attributes = Collections.emptyMap();
                            exchange.createBinding(nameParser.getBindingKey(), nameParser.getQueue(), properties, attributes);
                        }
                    }
                    agent.methodResponse(methodName, handle, outArgs, null);
                } catch (Exception e) {
                    agent.raiseException(handle, e.getMessage());
                }
            } else // method = delete
            {
                try {
                    if (// delete exchange.
                    type.equals("exchange")) {
                        Exchange exchange = nameParser.getExchange();
                        if (exchange != null) {
                            exchange.delete();
                        }
                    } else if (// delete queue.
                    type.equals("queue")) {
                        Queue queue = nameParser.getQueue();
                        if (queue != null) {
                            queue.deleteAndReturnCount();
                        }
                    } else if (// delete binding.
                    type.equals("binding")) {
                        Binding binding = nameParser.getBinding();
                        if (binding != null) {
                            binding.delete();
                        }
                    }
                    agent.methodResponse(methodName, handle, outArgs, null);
                } catch (Exception e) {
                    agent.raiseException(handle, e.getMessage());
                }
            }
        }
    } else // If methodName is not create or delete.
    {
        agent.raiseException(handle, methodName + " not yet implemented on Broker.");
    }
}
Also used : Binding(org.apache.qpid.server.model.Binding) QmfData(org.apache.qpid.qmf2.common.QmfData) HashMap(java.util.HashMap) ObjectId(org.apache.qpid.qmf2.common.ObjectId) Exchange(org.apache.qpid.server.model.Exchange) QmfAgentData(org.apache.qpid.qmf2.agent.QmfAgentData) VirtualHost(org.apache.qpid.server.model.VirtualHost) HashMap(java.util.HashMap) Map(java.util.Map) Queue(org.apache.qpid.server.model.Queue)

Example 9 with VirtualHost

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

the class VirtualHostStoreUpgraderAndRecoverer method recover.

private void recover(final ConfiguredObject<?> recoveryRoot, final DurableConfigurationStore durableConfigurationStore, final List<ConfiguredObjectRecord> records, final boolean isNew) {
    new GenericRecoverer(recoveryRoot).recover(records, isNew);
    final StoreConfigurationChangeListener configChangeListener = new StoreConfigurationChangeListener(durableConfigurationStore);
    if (_virtualHostNode.getVirtualHost() != null) {
        applyRecursively(_virtualHostNode.getVirtualHost(), new RecursiveAction<ConfiguredObject<?>>() {

            @Override
            public boolean applyToChildren(final ConfiguredObject<?> object) {
                return object.isDurable();
            }

            @Override
            public void performAction(final ConfiguredObject<?> object) {
                object.addChangeListener(configChangeListener);
            }
        });
    }
    if (recoveryRoot instanceof VirtualHostNode) {
        _virtualHostNode.addChangeListener(new AbstractConfigurationChangeListener() {

            @Override
            public void childAdded(final ConfiguredObject<?> object, final ConfiguredObject<?> child) {
                if (child instanceof VirtualHost) {
                    applyRecursively(child, new RecursiveAction<ConfiguredObject<?>>() {

                        @Override
                        public boolean applyToChildren(final ConfiguredObject<?> object) {
                            return object.isDurable();
                        }

                        @Override
                        public void performAction(final ConfiguredObject<?> object) {
                            if (object.isDurable()) {
                                durableConfigurationStore.update(true, object.asObjectRecord());
                                object.addChangeListener(configChangeListener);
                            }
                        }
                    });
                }
            }

            @Override
            public void childRemoved(final ConfiguredObject<?> object, final ConfiguredObject<?> child) {
                if (child instanceof VirtualHost) {
                    child.removeChangeListener(configChangeListener);
                }
            }
        });
        if (isNew) {
            if (_virtualHostNode instanceof AbstractConfiguredObject) {
                ((AbstractConfiguredObject) _virtualHostNode).forceUpdateAllSecureAttributes();
            }
        }
    }
}
Also used : AbstractConfiguredObject(org.apache.qpid.server.model.AbstractConfiguredObject) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) AbstractConfiguredObject(org.apache.qpid.server.model.AbstractConfiguredObject) VirtualHost(org.apache.qpid.server.model.VirtualHost) VirtualHostNode(org.apache.qpid.server.model.VirtualHostNode) StoreConfigurationChangeListener(org.apache.qpid.server.configuration.store.StoreConfigurationChangeListener) AbstractConfigurationChangeListener(org.apache.qpid.server.model.AbstractConfigurationChangeListener)

Example 10 with VirtualHost

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

the class StoreConfigurationChangeListenerTest method testChildAdded.

@Test
public void testChildAdded() {
    notifyBrokerStarted();
    Broker broker = mock(Broker.class);
    when(broker.getCategoryClass()).thenReturn(Broker.class);
    when(broker.isDurable()).thenReturn(true);
    VirtualHost child = mock(VirtualHost.class);
    when(child.getCategoryClass()).thenReturn(VirtualHost.class);
    Model model = mock(Model.class);
    when(model.getChildTypes(any(Class.class))).thenReturn(Collections.<Class<? extends ConfiguredObject>>emptyList());
    when(model.getParentType(eq(VirtualHost.class))).thenReturn((Class) Broker.class);
    when(child.getModel()).thenReturn(model);
    when(child.isDurable()).thenReturn(true);
    final ConfiguredObjectRecord childRecord = mock(ConfiguredObjectRecord.class);
    when(child.asObjectRecord()).thenReturn(childRecord);
    _listener.childAdded(broker, child);
    verify(_store).update(eq(true), eq(childRecord));
}
Also used : Broker(org.apache.qpid.server.model.Broker) Model(org.apache.qpid.server.model.Model) VirtualHost(org.apache.qpid.server.model.VirtualHost) ConfiguredObjectRecord(org.apache.qpid.server.store.ConfiguredObjectRecord) Test(org.junit.Test)

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