Search in sources :

Example 56 with IllegalConfigurationException

use of org.apache.qpid.server.configuration.IllegalConfigurationException in project qpid-broker-j by apache.

the class ManagementModeStoreHandler method quiesceEntries.

private Map<UUID, Object> quiesceEntries(final SystemConfig<?> options, List<ConfiguredObjectRecord> records) {
    final Map<UUID, Object> quiescedEntries = new HashMap<UUID, Object>();
    final int managementModeHttpPortOverride = options.getManagementModeHttpPortOverride();
    for (ConfiguredObjectRecord entry : records) {
        String entryType = entry.getType();
        Map<String, Object> attributes = entry.getAttributes();
        boolean quiesce = false;
        if (VIRTUAL_HOST_TYPE.equals(entryType) && options.isManagementModeQuiesceVirtualHosts()) {
            quiesce = true;
        } else if (PORT_TYPE.equals(entryType)) {
            if (attributes == null) {
                throw new IllegalConfigurationException("Port attributes are not set in " + entry);
            }
            Set<Protocol> protocols = getPortProtocolsAttribute(attributes);
            if (protocols == null) {
                quiesce = true;
            } else {
                for (Protocol protocol : protocols) {
                    switch(protocol) {
                        case HTTP:
                            quiesce = managementModeHttpPortOverride > 0;
                            break;
                        default:
                            quiesce = true;
                    }
                }
            }
        }
        if (quiesce) {
            LOGGER.debug("Management mode quiescing entry {}", entry);
            // save original state
            quiescedEntries.put(entry.getId(), attributes.get(ATTRIBUTE_STATE));
        }
    }
    return quiescedEntries;
}
Also used : Set(java.util.Set) HashMap(java.util.HashMap) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) ConfiguredObjectRecord(org.apache.qpid.server.store.ConfiguredObjectRecord) UUID(java.util.UUID) Protocol(org.apache.qpid.server.model.Protocol)

Example 57 with IllegalConfigurationException

use of org.apache.qpid.server.configuration.IllegalConfigurationException in project qpid-broker-j by apache.

the class ManagementModeStoreHandler method createPortsFromCommandLineOptions.

private Map<UUID, ConfiguredObjectRecord> createPortsFromCommandLineOptions(SystemConfig<?> options) {
    int managementModeHttpPortOverride = options.getManagementModeHttpPortOverride();
    if (managementModeHttpPortOverride < 0) {
        throw new IllegalConfigurationException("Invalid http port is specified: " + managementModeHttpPortOverride);
    }
    Map<UUID, ConfiguredObjectRecord> cliEntries = new HashMap<UUID, ConfiguredObjectRecord>();
    if (managementModeHttpPortOverride != 0) {
        ConfiguredObjectRecord entry = createCLIPortEntry(managementModeHttpPortOverride, Protocol.HTTP);
        cliEntries.put(entry.getId(), entry);
    }
    return cliEntries;
}
Also used : HashMap(java.util.HashMap) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) ConfiguredObjectRecord(org.apache.qpid.server.store.ConfiguredObjectRecord) UUID(java.util.UUID)

Example 58 with IllegalConfigurationException

use of org.apache.qpid.server.configuration.IllegalConfigurationException in project qpid-broker-j by apache.

the class ManagementModeStoreHandler method recoverRecords.

public void recoverRecords(final List<ConfiguredObjectRecord> records) {
    boolean b = _systemConfig.getManagementModeHttpPortOverride() > 0;
    for (ConfiguredObjectRecord object : records) {
        String entryType = object.getType();
        Map<String, Object> attributes = object.getAttributes();
        boolean quiesce = false;
        if (VIRTUAL_HOST_TYPE.equals(entryType) && _systemConfig.isManagementModeQuiesceVirtualHosts()) {
            quiesce = true;
        } else if (PORT_TYPE.equals(entryType)) {
            if (attributes == null) {
                throw new IllegalConfigurationException("Port attributes are not set in " + object);
            }
            Set<Protocol> protocols = getPortProtocolsAttribute(attributes);
            if (protocols == null) {
                quiesce = true;
            } else {
                for (Protocol protocol : protocols) {
                    switch(protocol) {
                        case HTTP:
                            quiesce = b;
                            break;
                        default:
                            quiesce = true;
                    }
                }
            }
        }
        if (quiesce) {
            LOGGER.debug("Management mode quiescing entry {}", object);
            // save original state
            _quiescedEntriesOriginalState.put(object.getId(), attributes.get(ATTRIBUTE_STATE));
            Map<String, Object> modifiedAttributes = new HashMap<String, Object>(attributes);
            modifiedAttributes.put(ATTRIBUTE_STATE, State.QUIESCED);
            ConfiguredObjectRecord record = new ConfiguredObjectRecordImpl(object.getId(), object.getType(), modifiedAttributes, object.getParents());
            _records.put(record.getId(), record);
        } else {
            _records.put(object.getId(), object);
        }
    }
}
Also used : ConfiguredObjectRecordImpl(org.apache.qpid.server.store.ConfiguredObjectRecordImpl) Set(java.util.Set) HashMap(java.util.HashMap) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) ConfiguredObjectRecord(org.apache.qpid.server.store.ConfiguredObjectRecord) Protocol(org.apache.qpid.server.model.Protocol)

Example 59 with IllegalConfigurationException

use of org.apache.qpid.server.configuration.IllegalConfigurationException in project qpid-broker-j by apache.

the class AbstractExchange method validateOrCreateAlternateBinding.

private void validateOrCreateAlternateBinding(final Exchange<?> exchange, final boolean mayCreate) {
    Object value = exchange.getAttribute(ALTERNATE_BINDING);
    if (value instanceof AlternateBinding) {
        AlternateBinding alternateBinding = (AlternateBinding) value;
        String destinationName = alternateBinding.getDestination();
        MessageDestination messageDestination = _virtualHost.getAttainedMessageDestination(destinationName, mayCreate);
        if (messageDestination == null) {
            throw new UnknownAlternateBindingException(destinationName);
        } else if (messageDestination == this) {
            throw new IllegalConfigurationException(String.format("Cannot create alternate binding for '%s' : Alternate binding destination cannot refer to self.", getName()));
        } else if (isDurable() && !messageDestination.isDurable()) {
            throw new IllegalConfigurationException(String.format("Cannot create alternate binding for '%s' : Alternate binding destination '%s' is not durable.", getName(), destinationName));
        }
    }
}
Also used : MessageDestination(org.apache.qpid.server.message.MessageDestination) AlternateBinding(org.apache.qpid.server.model.AlternateBinding) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) AbstractConfiguredObject(org.apache.qpid.server.model.AbstractConfiguredObject) UnknownAlternateBindingException(org.apache.qpid.server.virtualhost.UnknownAlternateBindingException)

Example 60 with IllegalConfigurationException

use of org.apache.qpid.server.configuration.IllegalConfigurationException in project qpid-broker-j by apache.

the class BDBVirtualHostImplTest method testValidateOnCreateForInvalidStorePath.

public void testValidateOnCreateForInvalidStorePath() throws Exception {
    String hostName = getTestName();
    File file = new File(_storePath + File.separator + hostName);
    assertTrue("Empty file is not created", file.createNewFile());
    Map<String, Object> attributes = new HashMap<>();
    attributes.put(BDBVirtualHost.ID, UUID.randomUUID());
    attributes.put(BDBVirtualHost.TYPE, BDBVirtualHostImpl.VIRTUAL_HOST_TYPE);
    attributes.put(BDBVirtualHost.NAME, hostName);
    attributes.put(BDBVirtualHost.STORE_PATH, file.getAbsoluteFile());
    BDBVirtualHostImpl host = new BDBVirtualHostImpl(attributes, _node);
    try {
        host.create();
        fail("Cannot create DBD virtual host from existing empty file");
    } catch (IllegalConfigurationException e) {
        assertTrue("Unexpected exception " + e.getMessage(), e.getMessage().startsWith("Cannot open virtual host message store"));
    }
}
Also used : HashMap(java.util.HashMap) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) File(java.io.File)

Aggregations

IllegalConfigurationException (org.apache.qpid.server.configuration.IllegalConfigurationException)87 HashMap (java.util.HashMap)31 IOException (java.io.IOException)25 ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)20 File (java.io.File)15 UUID (java.util.UUID)12 ConfiguredObjectRecord (org.apache.qpid.server.store.ConfiguredObjectRecord)12 GeneralSecurityException (java.security.GeneralSecurityException)10 AbstractConfiguredObject (org.apache.qpid.server.model.AbstractConfiguredObject)9 LinkedHashMap (java.util.LinkedHashMap)7 Map (java.util.Map)7 ServerScopedRuntimeException (org.apache.qpid.server.util.ServerScopedRuntimeException)7 AccessControlException (java.security.AccessControlException)6 ArrayList (java.util.ArrayList)6 Protocol (org.apache.qpid.server.model.Protocol)5 UnknownAlternateBindingException (org.apache.qpid.server.virtualhost.UnknownAlternateBindingException)5 MalformedURLException (java.net.MalformedURLException)4 URL (java.net.URL)4 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)4 HashSet (java.util.HashSet)4