Search in sources :

Example 16 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 17 with LegacyConfiguredObject

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

the class LegacyManagementController method formatConfiguredObject.

@Override
public Object formatConfiguredObject(final Object content, final Map<String, List<String>> parameters, final boolean isSecureOrAllowedOnInsecureChannel) {
    final int depth = getIntParameterFromRequest(parameters, DEPTH_PARAM, DEFAULT_DEPTH);
    final int oversizeThreshold = getIntParameterFromRequest(parameters, OVERSIZE_PARAM, DEFAULT_OVERSIZE);
    final boolean actuals = Boolean.parseBoolean(getParameter(ACTUALS_PARAM, parameters));
    final boolean excludeInheritedContext = isInheritedContextExcluded(parameters);
    if (content instanceof LegacyConfiguredObject) {
        LegacyConfiguredObject legacyConfiguredObjectObject = (LegacyConfiguredObject) content;
        return convertManageableToMap(legacyConfiguredObjectObject, depth, actuals, oversizeThreshold, excludeInheritedContext);
    } else if (content instanceof Collection) {
        return ((Collection<?>) content).stream().filter(o -> o instanceof LegacyConfiguredObject).map(LegacyConfiguredObject.class::cast).map(o -> convertManageableToMap(o, depth, actuals, oversizeThreshold, excludeInheritedContext)).collect(Collectors.toSet());
    }
    return content;
}
Also used : LegacyConfiguredObject(org.apache.qpid.server.management.plugin.controller.LegacyConfiguredObject) Collection(java.util.Collection)

Example 18 with LegacyConfiguredObject

use of org.apache.qpid.server.management.plugin.controller.LegacyConfiguredObject 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 19 with LegacyConfiguredObject

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

the class BindingController method createManageableBinding.

private LegacyConfiguredObject createManageableBinding(final Binding binding, final LegacyConfiguredObject nextVersionExchange) {
    final LegacyConfiguredObject nextVersionVirtualHost = nextVersionExchange.getParent(VirtualHostController.TYPE);
    final LegacyConfiguredObject queue = findNextVersionQueue(binding.getDestination(), nextVersionVirtualHost);
    return new LegacyBinding(_managementController, nextVersionExchange, queue, binding.getBindingKey(), binding.getArguments());
}
Also used : GenericLegacyConfiguredObject(org.apache.qpid.server.management.plugin.controller.GenericLegacyConfiguredObject) LegacyConfiguredObject(org.apache.qpid.server.management.plugin.controller.LegacyConfiguredObject)

Example 20 with LegacyConfiguredObject

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

the class BindingController method createOrUpdate.

@Override
public LegacyConfiguredObject createOrUpdate(final ConfiguredObject<?> root, final List<String> path, final Map<String, Object> attributes, final boolean isPost) throws ManagementException {
    if (path.contains("*")) {
        throw createBadRequestManagementException("Wildcards in path are not supported for post and put requests");
    }
    final Collection<String> hierarchy = _managementController.getCategoryHierarchy(root, getCategory());
    if (path.size() < hierarchy.size() - 2) {
        throw createBadRequestManagementException(String.format("Cannot create binding for path %s", String.join("/" + path)));
    }
    String queueName = null;
    if (path.size() > hierarchy.size() - 2) {
        queueName = path.get(hierarchy.size() - 2);
    }
    if (queueName == null) {
        queueName = (String) attributes.get("queue");
    }
    if (queueName == null) {
        throw createBadRequestManagementException("Queue is required for binding creation. Please specify queue either in path or in binding attributes");
    }
    final List<String> exchangePath = path.subList(0, hierarchy.size() - 2);
    final LegacyConfiguredObject nextVersionExchange = getNextVersionObject(root, exchangePath, ExchangeController.TYPE);
    final List<String> queuePath = new ArrayList<>(path.subList(0, hierarchy.size() - 3));
    queuePath.add(queueName);
    final LegacyConfiguredObject nextVersionQueue = getNextVersionObject(root, queuePath, QueueController.TYPE);
    String bindingKey = (String) attributes.get(GenericLegacyConfiguredObject.NAME);
    if (bindingKey == null) {
        bindingKey = path.size() == hierarchy.size() ? path.get(hierarchy.size() - 1) : null;
    }
    if (bindingKey == null) {
        bindingKey = "";
    }
    final Map<String, Object> parameters = new LinkedHashMap<>();
    parameters.put("bindingKey", bindingKey);
    parameters.put("destination", queueName);
    Map<String, Object> arguments = null;
    if (attributes.containsKey("arguments")) {
        Object args = attributes.get("arguments");
        if (args instanceof Map) {
            @SuppressWarnings("unchecked") Map<String, Object> argumentsMap = (Map<String, Object>) args;
            arguments = new HashMap<>(argumentsMap);
            if (!arguments.isEmpty()) {
                parameters.put("arguments", arguments);
            }
        } else {
            throw createBadRequestManagementException(String.format("Unexpected attributes specified : %s", args));
        }
    }
    parameters.put("replaceExistingArguments", !isPost);
    ManagementResponse response = nextVersionExchange.invoke("bind", parameters, true);
    final boolean newBindings = Boolean.TRUE.equals(response.getBody());
    if (!newBindings) {
        return null;
    }
    return new LegacyBinding(_managementController, nextVersionExchange, nextVersionQueue, bindingKey, arguments);
}
Also used : ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) GenericLegacyConfiguredObject(org.apache.qpid.server.management.plugin.controller.GenericLegacyConfiguredObject) 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) 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)

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