Search in sources :

Example 6 with Protocol

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

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

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

the class AmqpPortImpl method getInstalledProtocolsAsString.

public static String getInstalledProtocolsAsString() {
    Set<Protocol> installedProtocols = getInstalledProtocols();
    ObjectMapper mapper = new ObjectMapper();
    try (StringWriter output = new StringWriter()) {
        mapper.writeValue(output, installedProtocols);
        return output.toString();
    } catch (IOException e) {
        throw new ServerScopedRuntimeException(e);
    }
}
Also used : StringWriter(java.io.StringWriter) IOException(java.io.IOException) Protocol(org.apache.qpid.server.model.Protocol) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ServerScopedRuntimeException(org.apache.qpid.server.util.ServerScopedRuntimeException)

Example 9 with Protocol

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

the class AmqpPortImpl method getAllAvailableProtocolCombinations.

@SuppressWarnings("unused")
public static Collection<String> getAllAvailableProtocolCombinations() {
    Set<Protocol> protocols = getInstalledProtocols();
    Set<Set<String>> last = new HashSet<>();
    for (Protocol protocol : protocols) {
        last.add(Collections.singleton(protocol.name()));
    }
    Set<Set<String>> protocolCombinations = new HashSet<>(last);
    for (int i = 1; i < protocols.size(); i++) {
        Set<Set<String>> current = new HashSet<>();
        for (Set<String> set : last) {
            for (Protocol p : protocols) {
                if (!set.contains(p.name())) {
                    Set<String> potential = new HashSet<>(set);
                    potential.add(p.name());
                    current.add(potential);
                }
            }
        }
        protocolCombinations.addAll(current);
        last = current;
    }
    Set<String> combinationsAsString = new HashSet<>(protocolCombinations.size());
    ObjectMapper mapper = new ObjectMapper();
    for (Set<String> combination : protocolCombinations) {
        try (StringWriter writer = new StringWriter()) {
            mapper.writeValue(writer, combination);
            combinationsAsString.add(writer.toString());
        } catch (IOException e) {
            throw new IllegalArgumentException("Unexpected IO Exception generating JSON string", e);
        }
    }
    return Collections.unmodifiableSet(combinationsAsString);
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) StringWriter(java.io.StringWriter) IOException(java.io.IOException) Protocol(org.apache.qpid.server.model.Protocol) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) HashSet(java.util.HashSet)

Example 10 with Protocol

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

the class PortFactory method getProtocolType.

private ProtocolType getProtocolType(Map<String, Object> portAttributes, Broker<?> broker) {
    Model model = broker.getModel();
    ConfiguredObjectTypeRegistry typeRegistry = model.getTypeRegistry();
    Map<String, ConfiguredObjectAttribute<?, ?>> attributeTypes = typeRegistry.getAttributeTypes(Port.class);
    ConfiguredSettableAttribute protocolsAttribute = (ConfiguredSettableAttribute) attributeTypes.get(Port.PROTOCOLS);
    Set<Protocol> protocols = (Set<Protocol>) protocolsAttribute.convert(portAttributes.get(Port.PROTOCOLS), broker);
    ProtocolType protocolType = null;
    if (protocols == null || protocols.isEmpty()) {
        // defaulting to AMQP if protocol is not specified
        protocolType = ProtocolType.AMQP;
    } else {
        for (Protocol protocol : protocols) {
            if (protocolType == null) {
                protocolType = protocol.getProtocolType();
            } else if (protocolType != protocol.getProtocolType()) {
                throw new IllegalConfigurationException("Found different protocol types '" + protocolType + "' and '" + protocol.getProtocolType() + "' for port configuration: " + portAttributes);
            }
        }
    }
    return protocolType;
}
Also used : ConfiguredObjectAttribute(org.apache.qpid.server.model.ConfiguredObjectAttribute) Set(java.util.Set) ConfiguredSettableAttribute(org.apache.qpid.server.model.ConfiguredSettableAttribute) ProtocolType(org.apache.qpid.server.model.Protocol.ProtocolType) Model(org.apache.qpid.server.model.Model) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) ConfiguredObjectTypeRegistry(org.apache.qpid.server.model.ConfiguredObjectTypeRegistry) Protocol(org.apache.qpid.server.model.Protocol)

Aggregations

Protocol (org.apache.qpid.server.model.Protocol)10 Set (java.util.Set)4 IllegalConfigurationException (org.apache.qpid.server.configuration.IllegalConfigurationException)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 IOException (java.io.IOException)2 StringWriter (java.io.StringWriter)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)2 QpidServiceLoader (org.apache.qpid.server.plugin.QpidServiceLoader)2 ConfiguredObjectRecord (org.apache.qpid.server.store.ConfiguredObjectRecord)2 TreeSet (java.util.TreeSet)1 UUID (java.util.UUID)1 ConfiguredObjectAttribute (org.apache.qpid.server.model.ConfiguredObjectAttribute)1 ConfiguredObjectTypeRegistry (org.apache.qpid.server.model.ConfiguredObjectTypeRegistry)1 ConfiguredSettableAttribute (org.apache.qpid.server.model.ConfiguredSettableAttribute)1 Model (org.apache.qpid.server.model.Model)1 ProtocolType (org.apache.qpid.server.model.Protocol.ProtocolType)1 SystemConfig (org.apache.qpid.server.model.SystemConfig)1 Transport (org.apache.qpid.server.model.Transport)1