use of org.apache.qpid.server.model.Binding in project qpid-broker-j by apache.
the class BindingController method delete.
@Override
public int delete(final ConfiguredObject<?> root, final List<String> path, final Map<String, List<String>> parameters) throws ManagementException {
if (path.contains("*")) {
throw createBadRequestManagementException("Wildcards in path are not supported for delete requests");
}
final Collection<String> hierarchy = _managementController.getCategoryHierarchy(root, getCategory());
if (path.size() < hierarchy.size() - 2) {
throw createBadRequestManagementException(String.format("Cannot delete binding for path %s", String.join("/", path)));
}
final String bindingName = path.size() == hierarchy.size() ? path.get(hierarchy.size() - 1) : null;
final String queueName = path.get(hierarchy.size() - 2);
final List<String> ids = parameters.get(GenericLegacyConfiguredObject.ID);
final List<String> exchangePath = path.subList(0, hierarchy.size() - 2);
final LegacyConfiguredObject exchange = getNextVersionObject(root, exchangePath, ExchangeController.TYPE);
final AtomicInteger counter = new AtomicInteger();
if (ids != null && !ids.isEmpty()) {
@SuppressWarnings("unchecked") Collection<Binding> bindings = (Collection<Binding>) exchange.getAttribute("bindings");
if (bindings != null) {
bindings.stream().filter(b -> ids.contains(String.valueOf(generateBindingId(exchange, b.getDestination(), b.getBindingKey())))).forEach(b -> {
Map<String, Object> params = new LinkedHashMap<>();
params.put("bindingKey", b.getBindingKey());
params.put("destination", b.getDestination());
ManagementResponse r = exchange.invoke("unbind", params, true);
if (Boolean.TRUE.equals(r.getBody())) {
counter.incrementAndGet();
}
});
}
} else if (bindingName != null) {
Map<String, Object> params = new LinkedHashMap<>();
params.put("bindingKey", bindingName);
params.put("destination", queueName);
ManagementResponse response = exchange.invoke("unbind", params, true);
if (Boolean.TRUE.equals(response.getBody())) {
counter.incrementAndGet();
}
} else {
throw createBadRequestManagementException("Only deletion by binding full path or ids is supported");
}
return counter.get();
}
use of org.apache.qpid.server.model.Binding in project qpid-broker-j by apache.
the class BindingControllerTest method get.
@Test
public void get() {
final List<String> path = Arrays.asList("my-vhn", "my-vh", "my-exchange", "my-queue", "my-binding");
final Map<String, List<String>> parameters = Collections.singletonMap("actuals", Collections.singletonList("true"));
final List<String> hierarchy = Arrays.asList("virtualhostnode", "virtualhost", "exchange", "queue", "binding");
when(_managementController.getCategoryHierarchy(_root, "Binding")).thenReturn(hierarchy);
final LegacyConfiguredObject exchange1 = mock(LegacyConfiguredObject.class);
when(exchange1.getAttribute(LegacyConfiguredObject.NAME)).thenReturn("foo");
when(exchange1.getCategory()).thenReturn("Exchange");
final LegacyConfiguredObject exchange2 = mock(LegacyConfiguredObject.class);
when(exchange2.getAttribute(LegacyConfiguredObject.NAME)).thenReturn("my-exchange");
when(exchange2.getCategory()).thenReturn("Exchange");
final LegacyConfiguredObject vh = mock(LegacyConfiguredObject.class);
when(exchange2.getParent("VirtualHost")).thenReturn(vh);
final LegacyConfiguredObject queue = mock(LegacyConfiguredObject.class);
when(queue.getAttribute(LegacyConfiguredObject.NAME)).thenReturn("my-queue");
final Collection<LegacyConfiguredObject> queues = Collections.singletonList(queue);
when(vh.getChildren("Queue")).thenReturn(queues);
final Binding binding = mock(Binding.class);
when(binding.getName()).thenReturn("my-binding");
when(binding.getDestination()).thenReturn("my-queue");
when(binding.getBindingKey()).thenReturn("my-binding");
final Collection<Binding> bindings = Collections.singletonList(binding);
when(exchange2.getAttribute("bindings")).thenReturn(bindings);
final Collection<LegacyConfiguredObject> exchanges = Arrays.asList(exchange1, exchange2);
doReturn(exchanges).when(_nextVersionManagementController).get(any(), eq("exchange"), any(), any());
final Object readResult = _controller.get(_root, path, parameters);
assertThat(readResult, is(instanceOf(Collection.class)));
final Collection<?> exchangeBindings = (Collection<?>) readResult;
assertThat(exchangeBindings.size(), is(equalTo(1)));
final Object object = exchangeBindings.iterator().next();
assertThat(object, is(instanceOf(LegacyConfiguredObject.class)));
final LegacyConfiguredObject bindingObject = (LegacyConfiguredObject) object;
assertThat(bindingObject.getAttribute(LegacyConfiguredObject.NAME), is(equalTo("my-binding")));
}
use of org.apache.qpid.server.model.Binding in project qpid-broker-j by apache.
the class QueueControllerTest method convertNextVersionLegacyConfiguredObject.
@Test
public void convertNextVersionLegacyConfiguredObject() {
final String exchangeName = "testExchange";
final String alternateExchangeName = "altExchange";
final String queueName = "testQueue";
final String bindingKey = "testBindingKey";
final LegacyConfiguredObject nextVersionQueue = mock(LegacyConfiguredObject.class);
final Binding nextVersionBinding = mock(Binding.class);
final LegacyConfiguredObject nextVersionVirtualHost = mock(LegacyConfiguredObject.class);
final LegacyConfiguredObject nextVersionAlternateExchange = mock(LegacyConfiguredObject.class);
final LegacyConfiguredObject nextVersionExchange = mock(LegacyConfiguredObject.class);
final AlternateBinding alternateDestination = mock(AlternateBinding.class);
when(alternateDestination.getDestination()).thenReturn(alternateExchangeName);
when(nextVersionQueue.getCategory()).thenReturn(QueueController.TYPE);
when(nextVersionQueue.getParent(VirtualHostController.TYPE)).thenReturn(nextVersionVirtualHost);
when(nextVersionQueue.getAttribute("alternateBinding")).thenReturn(alternateDestination);
when(nextVersionQueue.getAttribute(AbstractConfiguredObject.NAME)).thenReturn(queueName);
when(nextVersionQueue.getAttribute("overflowPolicy")).thenReturn("PRODUCER_FLOW_CONTROL");
when(nextVersionQueue.getAttribute("maximumQueueDepthBytes")).thenReturn(10000L);
when(nextVersionQueue.getAttribute("context")).thenReturn(Collections.singletonMap("queue.queueFlowResumeLimit", "70"));
when(nextVersionQueue.getAttribute("messageGroupType")).thenReturn("SHARED_GROUPS");
when(nextVersionQueue.getAttribute("messageGroupKeyOverride")).thenReturn("test");
when(nextVersionBinding.getDestination()).thenReturn(queueName);
when(nextVersionBinding.getBindingKey()).thenReturn(bindingKey);
when(nextVersionExchange.getAttribute(AbstractConfiguredObject.NAME)).thenReturn(exchangeName);
when(nextVersionExchange.getCategory()).thenReturn(ExchangeController.TYPE);
when(nextVersionExchange.getAttribute("bindings")).thenReturn(Collections.singletonList(nextVersionBinding));
when(nextVersionAlternateExchange.getCategory()).thenReturn(ExchangeController.TYPE);
when(nextVersionAlternateExchange.getCategory()).thenReturn(ExchangeController.TYPE);
when(nextVersionAlternateExchange.getAttribute(LegacyConfiguredObject.NAME)).thenReturn(alternateExchangeName);
when(nextVersionVirtualHost.getChildren(ExchangeController.TYPE)).thenReturn(Arrays.asList(nextVersionExchange, nextVersionAlternateExchange));
when(nextVersionVirtualHost.getChildren(QueueController.TYPE)).thenReturn(Collections.singletonList(nextVersionExchange));
final LegacyConfiguredObject convertedExchange = mock(LegacyConfiguredObject.class);
final LegacyConfiguredObject convertedAltExchange = mock(LegacyConfiguredObject.class);
final LegacyConfiguredObject convertedQueue = mock(LegacyConfiguredObject.class);
when(_legacyVersionManagementController.convertFromNextVersion(nextVersionQueue)).thenReturn(convertedQueue);
when(_legacyVersionManagementController.convertFromNextVersion(nextVersionAlternateExchange)).thenReturn(convertedAltExchange);
when(_legacyVersionManagementController.convertFromNextVersion(nextVersionExchange)).thenReturn(convertedExchange);
final LegacyConfiguredObject destination = _queueController.convertFromNextVersion(nextVersionQueue);
assertThat(destination.getAttribute("alternateExchange"), is(equalTo(convertedAltExchange)));
assertThat(destination.getAttribute("queueFlowControlSizeBytes"), is(equalTo(10000L)));
assertThat(destination.getAttribute("queueFlowResumeSizeBytes"), is(equalTo(7000L)));
assertThat(destination.getAttribute("messageGroupSharedGroups"), is(equalTo(true)));
assertThat(destination.getAttribute("messageGroupKey"), is(equalTo("test")));
final Collection<LegacyConfiguredObject> children = destination.getChildren(BindingController.TYPE);
assertThat(children.size(), is(equalTo(1)));
final LegacyConfiguredObject o = children.iterator().next();
assertThat(o.getCategory(), is(equalTo(BindingController.TYPE)));
assertThat(o.getAttribute(AbstractConfiguredObject.NAME), is(equalTo(bindingKey)));
assertThat(o.getAttribute("queue"), is(equalTo(convertedQueue)));
assertThat(o.getAttribute("exchange"), is(equalTo(convertedExchange)));
}
use of org.apache.qpid.server.model.Binding in project qpid-broker-j by apache.
the class Session_1_0Test method findBinding.
private Binding findBinding(final String exchangeName, final String bindingName) {
Exchange exchange = _virtualHost.findConfiguredObject(Exchange.class, exchangeName);
Collection<Binding> bindings = exchange.getBindings();
Binding binding = null;
for (Binding b : bindings) {
if (bindingName.equals(b.getName())) {
binding = b;
break;
}
}
return binding;
}
use of org.apache.qpid.server.model.Binding in project qpid-broker-j by apache.
the class Session_1_0Test method testReceiveAttachTopicNonDurableNoContainerWithValidSelector.
@Test
public void testReceiveAttachTopicNonDurableNoContainerWithValidSelector() throws Exception {
final String linkName = "testLink";
final String address = "amq.direct/" + TOPIC_NAME;
final String selectorExpression = "test='test'";
Attach attach = createTopicAttach(false, linkName, address, true);
setSelector(attach, selectorExpression);
_session.receiveAttach(attach);
Attach sentAttach = captureAttach(_connection, _session, 0);
assertEquals("Unexpected name", attach.getName(), sentAttach.getName());
assertEquals("Unexpected role", Role.SENDER, sentAttach.getRole());
assertFilter(sentAttach, selectorExpression);
assertQueues(TOPIC_NAME, LifetimePolicy.DELETE_ON_NO_OUTBOUND_LINKS);
Binding binding = findBinding("amq.direct", TOPIC_NAME);
assertNotNull("Binding is not found", binding);
Map<String, Object> arguments = binding.getArguments();
assertNotNull("Unexpected arguments", arguments);
assertEquals("Unexpected filter on binding", selectorExpression, arguments.get(AMQPFilterTypes.JMS_SELECTOR.toString()));
}
Aggregations