Search in sources :

Example 71 with IllegalConfigurationException

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

the class FileBasedGroupProviderImpl method addChildAsync.

@Override
protected <C extends ConfiguredObject> ListenableFuture<C> addChildAsync(Class<C> childClass, Map<String, Object> attributes) {
    if (childClass == Group.class) {
        String groupName = (String) attributes.get(ConfiguredObject.NAME);
        if (getState() != State.ACTIVE) {
            throw new IllegalConfigurationException(String.format("Group provider '%s' is not activated. Cannot create a group.", getName()));
        }
        _groupDatabase.createGroup(groupName);
        Map<String, Object> attrMap = new HashMap<String, Object>();
        UUID id = UUID.randomUUID();
        attrMap.put(ConfiguredObject.ID, id);
        attrMap.put(ConfiguredObject.NAME, groupName);
        GroupAdapter groupAdapter = new GroupAdapter(attrMap);
        groupAdapter.create();
        return Futures.immediateFuture((C) groupAdapter);
    } else {
        return super.addChildAsync(childClass, attributes);
    }
}
Also used : HashMap(java.util.HashMap) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) AbstractConfiguredObject(org.apache.qpid.server.model.AbstractConfiguredObject) UUID(java.util.UUID)

Example 72 with IllegalConfigurationException

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

the class FileBasedGroupProviderImpl method onOpen.

@Override
protected void onOpen() {
    super.onOpen();
    FileGroupDatabase groupDatabase = new FileGroupDatabase();
    try {
        groupDatabase.setGroupFile(getPath());
    } catch (IOException | RuntimeException e) {
        if (e instanceof IllegalConfigurationException) {
            throw (IllegalConfigurationException) e;
        }
        throw new IllegalConfigurationException(String.format("Cannot load groups from '%s'", getPath()), e);
    }
    _groupDatabase = groupDatabase;
    Set<Principal> groups = getGroupPrincipals();
    Collection<Group> principals = new ArrayList<>(groups.size());
    for (Principal group : groups) {
        Map<String, Object> attrMap = new HashMap<String, Object>();
        UUID id = UUID.randomUUID();
        attrMap.put(ConfiguredObject.ID, id);
        attrMap.put(ConfiguredObject.NAME, group.getName());
        GroupAdapter groupAdapter = new GroupAdapter(attrMap);
        principals.add(groupAdapter);
        groupAdapter.registerWithParents();
        // TODO - we know this is safe, but the sync method shouldn't really be called from the management thread
        groupAdapter.openAsync();
    }
}
Also used : Group(org.apache.qpid.server.model.Group) HashMap(java.util.HashMap) FileGroupDatabase(org.apache.qpid.server.security.group.FileGroupDatabase) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) AbstractConfiguredObject(org.apache.qpid.server.model.AbstractConfiguredObject) UUID(java.util.UUID) GroupPrincipal(org.apache.qpid.server.security.group.GroupPrincipal) Principal(java.security.Principal)

Example 73 with IllegalConfigurationException

use of org.apache.qpid.server.configuration.IllegalConfigurationException 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)

Example 74 with IllegalConfigurationException

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

the class AbstractVirtualHost method importMessageStore.

@Override
public void importMessageStore(final String source) {
    try {
        final URL url = convertStringToURL(source);
        try (InputStream input = url.openStream();
            BufferedInputStream bufferedInputStream = new BufferedInputStream(input);
            DataInputStream data = new DataInputStream(bufferedInputStream)) {
            final MessageStoreSerializer serializer = MessageStoreSerializer.FACTORY.newInstance(data);
            doSync(doOnConfigThread(new Task<ListenableFuture<Void>, IOException>() {

                @Override
                public ListenableFuture<Void> execute() throws IOException {
                    if (getState() != State.STOPPED) {
                        throw new IllegalArgumentException("The importMessageStore operation can only be called when the virtual host is stopped");
                    }
                    try {
                        _messageStore.openMessageStore(AbstractVirtualHost.this);
                        checkMessageStoreEmpty();
                        final Map<String, UUID> queueMap = new HashMap<>();
                        getDurableConfigurationStore().reload(new ConfiguredObjectRecordHandler() {

                            @Override
                            public void handle(final ConfiguredObjectRecord record) {
                                if (record.getType().equals(Queue.class.getSimpleName())) {
                                    queueMap.put((String) record.getAttributes().get(ConfiguredObject.NAME), record.getId());
                                }
                            }
                        });
                        serializer.deserialize(queueMap, _messageStore, data);
                    } finally {
                        _messageStore.closeMessageStore();
                    }
                    return Futures.immediateFuture(null);
                }

                @Override
                public String getObject() {
                    return AbstractVirtualHost.this.toString();
                }

                @Override
                public String getAction() {
                    return "importMessageStore";
                }

                @Override
                public String getArguments() {
                    if (url.getProtocol().equalsIgnoreCase("http") || url.getProtocol().equalsIgnoreCase("https") || url.getProtocol().equalsIgnoreCase("file")) {
                        return "source=" + source;
                    } else if (url.getProtocol().equalsIgnoreCase("data")) {
                        return "source=<data stream>";
                    } else {
                        return "source=<unknown source type>";
                    }
                }
            }));
        }
    } catch (IOException e) {
        throw new IllegalConfigurationException("Cannot convert '" + source + "' to a readable resource", e);
    }
}
Also used : Task(org.apache.qpid.server.configuration.updater.Task) StatisticsReportingTask(org.apache.qpid.server.stats.StatisticsReportingTask) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) BufferedInputStream(java.io.BufferedInputStream) DataInputStream(java.io.DataInputStream) InputStream(java.io.InputStream) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) URL(java.net.URL) BufferedInputStream(java.io.BufferedInputStream) ConfiguredObjectRecord(org.apache.qpid.server.store.ConfiguredObjectRecord) MessageStoreSerializer(org.apache.qpid.server.store.serializer.MessageStoreSerializer) UUID(java.util.UUID) ConfiguredObjectRecordHandler(org.apache.qpid.server.store.handler.ConfiguredObjectRecordHandler)

Example 75 with IllegalConfigurationException

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

the class ManagementModeStoreHandlerTest method testRemoveCLIPort.

public void testRemoveCLIPort() {
    _systemConfigAttributes.put(SystemConfig.MANAGEMENT_MODE_HTTP_PORT_OVERRIDE, 1000);
    _handler = createManagementModeStoreHandler();
    _handler.init(_systemConfig);
    Collection<ConfiguredObjectRecord> records = openAndGetRecords();
    UUID portId = getOptionsPortId(records);
    ConfiguredObjectRecord record = mock(ConfiguredObjectRecord.class);
    when(record.getId()).thenReturn(portId);
    try {
        _handler.remove(record);
        fail("Exception should be thrown on trying to remove CLI port");
    } catch (IllegalConfigurationException e) {
    // pass
    }
}
Also used : IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) ConfiguredObjectRecord(org.apache.qpid.server.store.ConfiguredObjectRecord) UUID(java.util.UUID)

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