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);
}
}
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();
}
}
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;
}
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);
}
}
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
}
}
Aggregations