Search in sources :

Example 16 with Binding

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();
}
Also used : Binding(org.apache.qpid.server.model.Binding) ManagementException.createBadRequestManagementException(org.apache.qpid.server.management.plugin.ManagementException.createBadRequestManagementException) ManagementException(org.apache.qpid.server.management.plugin.ManagementException) GenericLegacyConfiguredObject(org.apache.qpid.server.management.plugin.controller.GenericLegacyConfiguredObject) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) ManagementController(org.apache.qpid.server.management.plugin.ManagementController) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) CategoryController(org.apache.qpid.server.management.plugin.controller.CategoryController) Binding(org.apache.qpid.server.model.Binding) ControllerManagementResponse(org.apache.qpid.server.management.plugin.controller.ControllerManagementResponse) Collection(java.util.Collection) HttpServletResponse(javax.servlet.http.HttpServletResponse) State(org.apache.qpid.server.model.State) ManagementException.createInternalServerErrorManagementException(org.apache.qpid.server.management.plugin.ManagementException.createInternalServerErrorManagementException) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) LegacyConfiguredObject(org.apache.qpid.server.management.plugin.controller.LegacyConfiguredObject) ResponseType(org.apache.qpid.server.management.plugin.ResponseType) List(java.util.List) Stream(java.util.stream.Stream) ManagementResponse(org.apache.qpid.server.management.plugin.ManagementResponse) LegacyManagementController(org.apache.qpid.server.management.plugin.controller.LegacyManagementController) Collections(java.util.Collections) LinkedHashMap(java.util.LinkedHashMap) GenericLegacyConfiguredObject(org.apache.qpid.server.management.plugin.controller.GenericLegacyConfiguredObject) LegacyConfiguredObject(org.apache.qpid.server.management.plugin.controller.LegacyConfiguredObject) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ControllerManagementResponse(org.apache.qpid.server.management.plugin.controller.ControllerManagementResponse) ManagementResponse(org.apache.qpid.server.management.plugin.ManagementResponse) Collection(java.util.Collection) GenericLegacyConfiguredObject(org.apache.qpid.server.management.plugin.controller.GenericLegacyConfiguredObject) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) LegacyConfiguredObject(org.apache.qpid.server.management.plugin.controller.LegacyConfiguredObject) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 17 with Binding

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")));
}
Also used : Binding(org.apache.qpid.server.model.Binding) LegacyConfiguredObject(org.apache.qpid.server.management.plugin.controller.LegacyConfiguredObject) Collection(java.util.Collection) List(java.util.List) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) LegacyConfiguredObject(org.apache.qpid.server.management.plugin.controller.LegacyConfiguredObject) Test(org.junit.Test)

Example 18 with 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)));
}
Also used : AlternateBinding(org.apache.qpid.server.model.AlternateBinding) Binding(org.apache.qpid.server.model.Binding) LegacyConfiguredObject(org.apache.qpid.server.management.plugin.controller.LegacyConfiguredObject) AlternateBinding(org.apache.qpid.server.model.AlternateBinding) Test(org.junit.Test)

Example 19 with Binding

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;
}
Also used : Exchange(org.apache.qpid.server.model.Exchange) Binding(org.apache.qpid.server.model.Binding)

Example 20 with 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()));
}
Also used : Binding(org.apache.qpid.server.model.Binding) Attach(org.apache.qpid.server.protocol.v1_0.type.transport.Attach) Test(org.junit.Test)

Aggregations

Binding (org.apache.qpid.server.model.Binding)20 AlternateBinding (org.apache.qpid.server.model.AlternateBinding)10 ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)9 AbstractConfiguredObject (org.apache.qpid.server.model.AbstractConfiguredObject)6 Exchange (org.apache.qpid.server.model.Exchange)6 Test (org.junit.Test)6 LegacyConfiguredObject (org.apache.qpid.server.management.plugin.controller.LegacyConfiguredObject)5 MessageDestination (org.apache.qpid.server.message.MessageDestination)5 Queue (org.apache.qpid.server.model.Queue)4 ArrayList (java.util.ArrayList)3 Collection (java.util.Collection)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 QmfAgentData (org.apache.qpid.qmf2.agent.QmfAgentData)3 List (java.util.List)2 UUID (java.util.UUID)2 BindingImpl (org.apache.qpid.server.binding.BindingImpl)2 ManagementResponse (org.apache.qpid.server.management.plugin.ManagementResponse)2 ControllerManagementResponse (org.apache.qpid.server.management.plugin.controller.ControllerManagementResponse)2 Connection (org.apache.qpid.server.model.Connection)2