Search in sources :

Example 1 with LegacyConfiguredObject

use of org.apache.qpid.server.management.plugin.controller.LegacyConfiguredObject in project qpid-broker-j by apache.

the class BindingControllerTest method invoke.

@Test
public void invoke() {
    final List<String> path = Arrays.asList("my-vhn", "my-vh", "my-exchange", "my-queue", "my-binding");
    final String operationName = "getStatistics";
    final Map<String, Object> parameters = Collections.emptyMap();
    final List<String> hierarchy = Arrays.asList("virtualhostnode", "virtualhost", "exchange", "queue", "binding");
    when(_managementController.getCategoryHierarchy(_root, "Binding")).thenReturn(hierarchy);
    final LegacyConfiguredObject exchange = mock(LegacyConfiguredObject.class);
    when(exchange.getAttribute(LegacyConfiguredObject.NAME)).thenReturn("my-exchange");
    when(exchange.getCategory()).thenReturn("Exchange");
    final LegacyConfiguredObject vh = mock(LegacyConfiguredObject.class);
    when(exchange.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(exchange.getAttribute("bindings")).thenReturn(bindings);
    final Collection<LegacyConfiguredObject> exchanges = Collections.singletonList(exchange);
    doReturn(exchanges).when(_nextVersionManagementController).get(any(), eq("exchange"), any(), any());
    final ManagementResponse result = _controller.invoke(_root, path, operationName, parameters, true, true);
    assertThat(result, is(notNullValue()));
    assertThat(result.getResponseCode(), is(equalTo(200)));
    assertThat(result.getBody(), is(notNullValue()));
    assertThat(result.getBody(), is(equalTo(Collections.emptyMap())));
}
Also used : Binding(org.apache.qpid.server.model.Binding) LegacyConfiguredObject(org.apache.qpid.server.management.plugin.controller.LegacyConfiguredObject) ControllerManagementResponse(org.apache.qpid.server.management.plugin.controller.ControllerManagementResponse) ManagementResponse(org.apache.qpid.server.management.plugin.ManagementResponse) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) LegacyConfiguredObject(org.apache.qpid.server.management.plugin.controller.LegacyConfiguredObject) Test(org.junit.Test)

Example 2 with LegacyConfiguredObject

use of org.apache.qpid.server.management.plugin.controller.LegacyConfiguredObject in project qpid-broker-j by apache.

the class ConsumerControllerTest method convertFromNextVersion.

@Test
public void convertFromNextVersion() {
    final LegacyConfiguredObject session = mock(LegacyConfiguredObject.class);
    when(session.getAttribute(LegacyConfiguredObject.NAME)).thenReturn("my-session");
    when(session.getCategory()).thenReturn("Session");
    final LegacyConfiguredObject queue1 = mock(LegacyConfiguredObject.class);
    when(queue1.getAttribute(LegacyConfiguredObject.NAME)).thenReturn("my-queue1");
    final LegacyConfiguredObject queue2 = mock(LegacyConfiguredObject.class);
    when(queue2.getAttribute(LegacyConfiguredObject.NAME)).thenReturn("my-queue");
    final LegacyConfiguredObject nextVersionConfiguredObject = mock(LegacyConfiguredObject.class);
    when(nextVersionConfiguredObject.getAttribute("session")).thenReturn(session);
    when(nextVersionConfiguredObject.getAttribute("queue")).thenReturn(queue2);
    when(nextVersionConfiguredObject.getAttribute(LegacyConfiguredObject.NAME)).thenReturn("test-consumer");
    when(nextVersionConfiguredObject.getParent(eq("Queue"))).thenReturn(queue2);
    final Collection<LegacyConfiguredObject> consumers = Collections.singletonList(nextVersionConfiguredObject);
    when(queue2.getChildren(ConsumerController.TYPE)).thenReturn(consumers);
    final LegacyConfiguredObject convertedSession = mock(LegacyConfiguredObject.class);
    when(_managementController.convertFromNextVersion(session)).thenReturn(convertedSession);
    final LegacyConfiguredObject convertedQueue = mock(LegacyConfiguredObject.class);
    when(_managementController.convertFromNextVersion(queue2)).thenReturn(convertedQueue);
    final LegacyConfiguredObject converted = _controller.convertFromNextVersion(nextVersionConfiguredObject);
    LegacyConfiguredObject sessionParent = converted.getParent("Session");
    LegacyConfiguredObject queueParent = converted.getParent("Queue");
    assertThat(sessionParent, is(equalTo(convertedSession)));
    assertThat(queueParent, is(equalTo(convertedQueue)));
    LegacyConfiguredObject sessionAttribute = (LegacyConfiguredObject) converted.getAttribute("session");
    LegacyConfiguredObject queueAttribute = (LegacyConfiguredObject) converted.getAttribute("queue");
    assertThat(sessionAttribute, is(equalTo(convertedSession)));
    assertThat(queueAttribute, is(equalTo(convertedQueue)));
}
Also used : LegacyConfiguredObject(org.apache.qpid.server.management.plugin.controller.LegacyConfiguredObject) Test(org.junit.Test)

Example 3 with LegacyConfiguredObject

use of org.apache.qpid.server.management.plugin.controller.LegacyConfiguredObject in project qpid-broker-j by apache.

the class ExchangeControllerTest method convertNextVersionLegacyConfiguredObject.

@Test
public void convertNextVersionLegacyConfiguredObject() {
    final ExchangeController exchangeController = new ExchangeController(_legacyManagementController, Collections.emptySet());
    final String exchangeName = "testExchange";
    final String alternateExchangeName = "altExchange";
    final String queueName = "testQueue";
    final String bindingKey = "testBindingKey";
    final LegacyConfiguredObject nextVersionExchange = mock(LegacyConfiguredObject.class);
    final AlternateBinding alternateBinding = mock(AlternateBinding.class);
    final Binding nextVersionBinding = mock(Binding.class);
    final LegacyConfiguredObject nextVersionAlternateExchange = mock(LegacyConfiguredObject.class);
    final LegacyConfiguredObject nextVersionVirtualHost = mock(LegacyConfiguredObject.class);
    final LegacyConfiguredObject queue = mock(LegacyConfiguredObject.class);
    when(alternateBinding.getDestination()).thenReturn(alternateExchangeName);
    when(nextVersionExchange.getCategory()).thenReturn(ExchangeController.TYPE);
    when(nextVersionExchange.getAttribute("alternateBinding")).thenReturn(alternateBinding);
    when(nextVersionExchange.getAttribute(AbstractConfiguredObject.NAME)).thenReturn(exchangeName);
    when(nextVersionExchange.getAttribute("bindings")).thenReturn(Collections.singletonList(nextVersionBinding));
    when(nextVersionExchange.getParent(VirtualHostController.TYPE)).thenReturn(nextVersionVirtualHost);
    when(nextVersionBinding.getDestination()).thenReturn(queueName);
    when(nextVersionBinding.getBindingKey()).thenReturn(bindingKey);
    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(queue));
    final LegacyConfiguredObject convertedExchange = mock(LegacyConfiguredObject.class);
    final LegacyConfiguredObject convertedAltExchange = mock(LegacyConfiguredObject.class);
    final LegacyConfiguredObject convertedQueue = mock(LegacyConfiguredObject.class);
    when(_legacyManagementController.convertFromNextVersion(nextVersionExchange)).thenReturn(convertedExchange);
    when(_legacyManagementController.convertFromNextVersion(nextVersionAlternateExchange)).thenReturn(convertedAltExchange);
    when(_legacyManagementController.convertFromNextVersion(queue)).thenReturn(convertedQueue);
    final LegacyConfiguredObject destination = exchangeController.convertFromNextVersion(nextVersionExchange);
    assertThat(destination.getAttribute("alternateExchange"), is(equalTo(convertedAltExchange)));
    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 4 with LegacyConfiguredObject

use of org.apache.qpid.server.management.plugin.controller.LegacyConfiguredObject in project qpid-broker-j by apache.

the class DestinationController method convertAttributesToNextVersion.

@Override
@SuppressWarnings("unchecked")
public Map<String, Object> convertAttributesToNextVersion(final ConfiguredObject<?> root, final List<String> path, final Map<String, Object> attributes) {
    if (attributes.containsKey(LegacyDestination.ALTERNATE_EXCHANGE)) {
        final Map<String, Object> converted = new LinkedHashMap<>(attributes);
        final String alternateExchange = (String) converted.remove(LegacyDestination.ALTERNATE_EXCHANGE);
        final LegacyConfiguredObject exchange = findExchange(root, path, object -> alternateExchange.equals(object.getAttribute(LegacyConfiguredObject.ID)) || alternateExchange.equals(object.getAttribute(LegacyConfiguredObject.NAME)));
        if (exchange != null) {
            converted.put(ALTERNATE_BINDING, Collections.singletonMap("destination", exchange.getAttribute(LegacyConfiguredObject.NAME)));
        } else {
            throw createBadRequestManagementException(String.format("Cannot find alternate exchange '%s'", alternateExchange));
        }
        return converted;
    }
    return attributes;
}
Also used : GenericLegacyConfiguredObject(org.apache.qpid.server.management.plugin.controller.GenericLegacyConfiguredObject) LegacyConfiguredObject(org.apache.qpid.server.management.plugin.controller.LegacyConfiguredObject) 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) LinkedHashMap(java.util.LinkedHashMap)

Example 5 with LegacyConfiguredObject

use of org.apache.qpid.server.management.plugin.controller.LegacyConfiguredObject in project qpid-broker-j by apache.

the class ConsumerController method get.

@Override
public Object get(final ConfiguredObject<?> root, final List<String> path, final Map<String, List<String>> parameters) throws ManagementException {
    final Collection<String> hierarchy = _managementController.getCategoryHierarchy(root, TYPE);
    final String consumerName = path.size() == hierarchy.size() ? path.get(hierarchy.size() - 1) : null;
    final String queueName = path.size() >= hierarchy.size() - 1 ? path.get(hierarchy.size() - 2) : null;
    final String sessionName = path.size() >= hierarchy.size() - 2 ? path.get(hierarchy.size() - 3) : null;
    List<String> virtualHostPath = path;
    if (virtualHostPath.size() > hierarchy.size() - 3) {
        virtualHostPath = virtualHostPath.subList(0, hierarchy.size() - 3);
    }
    final Object queues = getNextVersionManagementController().get(root, "Queue", virtualHostPath, Collections.emptyMap());
    Collection<LegacyConfiguredObject> consumers;
    if (queues instanceof LegacyConfiguredObject) {
        consumers = getQueueConsumers(sessionName, queueName, consumerName, (LegacyConfiguredObject) queues);
    } else if (queues instanceof Collection) {
        consumers = ((Collection<?>) queues).stream().map(LegacyConfiguredObject.class::cast).map(q -> getQueueConsumers(sessionName, queueName, consumerName, q)).flatMap(Collection::stream).collect(Collectors.toList());
    } else {
        throw createInternalServerErrorManagementException("Unexpected consumer format from next version");
    }
    return consumers;
}
Also used : GenericLegacyConfiguredObject(org.apache.qpid.server.management.plugin.controller.GenericLegacyConfiguredObject) LegacyConfiguredObject(org.apache.qpid.server.management.plugin.controller.LegacyConfiguredObject) 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)

Aggregations

LegacyConfiguredObject (org.apache.qpid.server.management.plugin.controller.LegacyConfiguredObject)37 Test (org.junit.Test)28 ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)22 Collection (java.util.Collection)11 ManagementResponse (org.apache.qpid.server.management.plugin.ManagementResponse)10 HashMap (java.util.HashMap)9 List (java.util.List)7 Map (java.util.Map)7 ControllerManagementResponse (org.apache.qpid.server.management.plugin.controller.ControllerManagementResponse)7 GenericLegacyConfiguredObject (org.apache.qpid.server.management.plugin.controller.GenericLegacyConfiguredObject)6 Binding (org.apache.qpid.server.model.Binding)5 ManagementRequest (org.apache.qpid.server.management.plugin.ManagementRequest)4 LinkedHashMap (java.util.LinkedHashMap)3 CategoryController (org.apache.qpid.server.management.plugin.controller.CategoryController)3 AlternateBinding (org.apache.qpid.server.model.AlternateBinding)3 Broker (org.apache.qpid.server.model.Broker)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 ArrayList (java.util.ArrayList)2 UUID (java.util.UUID)2 ManagementException (org.apache.qpid.server.management.plugin.ManagementException)2