Search in sources :

Example 1 with ControllerManagementResponse

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

the class SessionControllerTest method convertNextVersionLegacyConfiguredObject.

@Test
public void convertNextVersionLegacyConfiguredObject() {
    final UUID sessionID = UUID.randomUUID();
    final LegacyConfiguredObject nextVersionSession = mock(LegacyConfiguredObject.class);
    final LegacyConfiguredObject nextVersionConsumer = mock(LegacyConfiguredObject.class);
    when(nextVersionSession.getCategory()).thenReturn(SessionController.TYPE);
    when(nextVersionSession.getAttribute(LegacyConfiguredObject.ID)).thenReturn(sessionID);
    final ManagementResponse operationResult = new ControllerManagementResponse(ResponseType.MODEL_OBJECT, Collections.singletonList(nextVersionConsumer));
    when(nextVersionSession.invoke(eq("getConsumers"), eq(Collections.emptyMap()), eq(true))).thenReturn(operationResult);
    final LegacyConfiguredObject convertedConsumer = mock(LegacyConfiguredObject.class);
    when(_legacyManagementController.convertFromNextVersion(nextVersionConsumer)).thenReturn(convertedConsumer);
    final LegacyConfiguredObject convertedSession = _sessionController.convertNextVersionLegacyConfiguredObject(nextVersionSession);
    assertThat(convertedSession.getAttribute(LegacyConfiguredObject.ID), is(equalTo(sessionID)));
    final Collection<LegacyConfiguredObject> consumers = convertedSession.getChildren(ConsumerController.TYPE);
    assertThat(consumers, is(notNullValue()));
    assertThat(consumers.size(), is(equalTo(1)));
    assertThat(consumers.iterator().next(), is(equalTo(convertedConsumer)));
}
Also used : 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) ControllerManagementResponse(org.apache.qpid.server.management.plugin.controller.ControllerManagementResponse) UUID(java.util.UUID) Test(org.junit.Test)

Example 2 with ControllerManagementResponse

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

the class LatestManagementController method invoke.

@Override
@SuppressWarnings("unchecked")
public ManagementResponse invoke(final ConfiguredObject<?> root, final String category, final List<String> names, final String operationName, final Map<String, Object> operationArguments, final boolean isPost, final boolean isSecureOrAllowedOnInsecureChannel) throws ManagementException {
    ResponseType responseType = ResponseType.DATA;
    Object returnValue;
    try {
        final ConfiguredObject<?> target = getTarget(root, category, names);
        final Map<String, ConfiguredObjectOperation<?>> availableOperations = root.getModel().getTypeRegistry().getOperations(target.getClass());
        final ConfiguredObjectOperation operation = availableOperations.get(operationName);
        if (operation == null) {
            throw createNotFoundManagementException(String.format("No such operation '%s' in '%s'", operationName, category));
        }
        final Map<String, Object> arguments;
        if (isPost) {
            arguments = operationArguments;
        } else {
            final Set<String> supported = ((List<OperationParameter>) operation.getParameters()).stream().map(OperationParameter::getName).collect(Collectors.toSet());
            arguments = operationArguments.entrySet().stream().filter(e -> !RESERVED_PARAMS.contains(e.getKey()) || supported.contains(e.getKey())).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
        }
        if (operation.isSecure(target, arguments) && !isSecureOrAllowedOnInsecureChannel) {
            throw createForbiddenManagementException(String.format("Operation '%s' can only be performed over a secure (HTTPS) connection", operationName));
        }
        if (!isPost && !operation.isNonModifying()) {
            throw createNotAllowedManagementException(String.format("Operation '%s' modifies the object so you must use POST.", operationName), Collections.singletonMap("Allow", "POST"));
        }
        returnValue = operation.perform(target, arguments);
        if (ConfiguredObject.class.isAssignableFrom(operation.getReturnType()) || returnsCollectionOfConfiguredObjects(operation)) {
            responseType = ResponseType.MODEL_OBJECT;
        }
    } catch (RuntimeException e) {
        throw ManagementException.toManagementException(e, getCategoryMapping(category), names);
    } catch (Error e) {
        throw ManagementException.handleError(e);
    }
    return new ControllerManagementResponse(responseType, returnValue);
}
Also used : ResponseType(org.apache.qpid.server.management.plugin.ResponseType) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) ArrayList(java.util.ArrayList) List(java.util.List) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) ConfiguredObjectOperation(org.apache.qpid.server.model.ConfiguredObjectOperation) ControllerManagementResponse(org.apache.qpid.server.management.plugin.controller.ControllerManagementResponse)

Example 3 with ControllerManagementResponse

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

the class ConsumerControllerTest method invoke.

@Test
public void invoke() {
    final List<String> path = Arrays.asList("my-vhn", "my-vh", "my-session", "my-queue", "my-consumer");
    final List<String> hierarchy = Arrays.asList("virtualhostnode", "virtualhost", "session", "queue", "consumer");
    when(_managementController.getCategoryHierarchy(_root, "Consumer")).thenReturn(hierarchy);
    final LegacyConfiguredObject consumer = mock(LegacyConfiguredObject.class);
    final LegacyConfiguredObject queue = mock(LegacyConfiguredObject.class);
    final LegacyConfiguredObject session = mock(LegacyConfiguredObject.class);
    when(queue.getAttribute(LegacyConfiguredObject.NAME)).thenReturn("my-queue");
    when(consumer.getAttribute(LegacyConfiguredObject.NAME)).thenReturn("my-consumer");
    when(consumer.getAttribute("session")).thenReturn(session);
    when(session.getAttribute(LegacyConfiguredObject.NAME)).thenReturn("my-session");
    final Object stats = mock(Object.class);
    final ManagementResponse statistics = new ControllerManagementResponse(ResponseType.DATA, stats);
    when(consumer.invoke(eq("getStatistics"), eq(Collections.emptyMap()), eq(false))).thenReturn(statistics);
    final Collection<LegacyConfiguredObject> consumers = Collections.singletonList(consumer);
    when(queue.getChildren(ConsumerController.TYPE)).thenReturn(consumers);
    final Collection<LegacyConfiguredObject> queues = Collections.singletonList(queue);
    doReturn(queues).when(_nextVersionManagementController).get(eq(_root), eq("Queue"), eq(Arrays.asList("my-vhn", "my-vh")), eq(Collections.emptyMap()));
    ManagementResponse response = _controller.invoke(_root, path, "getStatistics", Collections.emptyMap(), false, false);
    assertThat(response, is(notNullValue()));
    assertThat(response.getResponseCode(), is(equalTo(200)));
    assertThat(response.getBody(), is(notNullValue()));
    assertThat(response.getBody(), is(equalTo(stats)));
}
Also used : 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) ControllerManagementResponse(org.apache.qpid.server.management.plugin.controller.ControllerManagementResponse) Test(org.junit.Test)

Example 4 with ControllerManagementResponse

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

the class BindingControllerTest method delete.

@Test
public void delete() {
    final List<String> path = Arrays.asList("my-vhn", "my-vh", "my-exchange", "my-queue", "my-binding");
    final List<String> hierarchy = Arrays.asList("virtualhostnode", "virtualhost", "exchange", "queue", "binding");
    doReturn(hierarchy).when(_managementController).getCategoryHierarchy(_root, "Binding");
    final LegacyConfiguredObject exchange = mock(LegacyConfiguredObject.class);
    when(exchange.getCategory()).thenReturn("Exchange");
    when(exchange.getAttribute(LegacyConfiguredObject.NAME)).thenReturn("my-exchange");
    final ManagementResponse unbindingResult = new ControllerManagementResponse(ResponseType.DATA, Boolean.TRUE);
    when(exchange.invoke(eq("unbind"), any(), eq(true))).thenReturn(unbindingResult);
    doReturn(exchange).when(_nextVersionManagementController).get(any(), eq("exchange"), any(), any());
    int result = _controller.delete(_root, path, Collections.emptyMap());
    assertThat(result, is(equalTo(1)));
    verify(exchange).invoke(eq("unbind"), any(), eq(true));
}
Also used : 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) ControllerManagementResponse(org.apache.qpid.server.management.plugin.controller.ControllerManagementResponse) Test(org.junit.Test)

Example 5 with ControllerManagementResponse

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

the class BindingControllerTest method createOrUpdate.

@Test
public void createOrUpdate() {
    final List<String> path = Arrays.asList("my-vhn", "my-vh", "my-exchange");
    final Map<String, Object> attributes = new HashMap<>();
    attributes.put("name", "my-binding");
    attributes.put("queue", "my-queue");
    final List<String> hierarchy = Arrays.asList("virtualhostnode", "virtualhost", "exchange", "queue", "binding");
    doReturn(hierarchy).when(_managementController).getCategoryHierarchy(_root, "Binding");
    final LegacyConfiguredObject exchange = mock(LegacyConfiguredObject.class);
    when(exchange.getCategory()).thenReturn("Exchange");
    when(exchange.getAttribute(LegacyConfiguredObject.NAME)).thenReturn("my-exchange");
    final ManagementResponse bindingResult = new ControllerManagementResponse(ResponseType.DATA, Boolean.TRUE);
    when(exchange.invoke(eq("bind"), any(), eq(true))).thenReturn(bindingResult);
    final LegacyConfiguredObject queue = mock(LegacyConfiguredObject.class);
    when(queue.getCategory()).thenReturn("Queue");
    when(queue.getAttribute(LegacyConfiguredObject.NAME)).thenReturn("my-queue");
    doReturn(exchange).when(_nextVersionManagementController).get(any(), eq("exchange"), any(), any());
    doReturn(queue).when(_nextVersionManagementController).get(any(), eq("queue"), any(), any());
    when(_managementController.convertFromNextVersion(exchange)).thenReturn(exchange);
    when(_managementController.convertFromNextVersion(queue)).thenReturn(queue);
    final LegacyConfiguredObject binding = _controller.createOrUpdate(_root, path, attributes, true);
    assertThat(binding, is(notNullValue()));
    assertThat(binding.getAttribute(LegacyConfiguredObject.NAME), is(equalTo("my-binding")));
    Object queueObject = binding.getAttribute("queue");
    Object exchangeObject = binding.getAttribute("exchange");
    assertThat(queueObject, is(instanceOf(LegacyConfiguredObject.class)));
    assertThat(exchangeObject, is(instanceOf(LegacyConfiguredObject.class)));
    assertThat(((LegacyConfiguredObject) queueObject).getAttribute(LegacyConfiguredObject.NAME), is(equalTo("my-queue")));
    assertThat(((LegacyConfiguredObject) exchangeObject).getAttribute(LegacyConfiguredObject.NAME), is(equalTo("my-exchange")));
}
Also used : LegacyConfiguredObject(org.apache.qpid.server.management.plugin.controller.LegacyConfiguredObject) HashMap(java.util.HashMap) 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) ControllerManagementResponse(org.apache.qpid.server.management.plugin.controller.ControllerManagementResponse) Test(org.junit.Test)

Aggregations

ControllerManagementResponse (org.apache.qpid.server.management.plugin.controller.ControllerManagementResponse)5 ManagementResponse (org.apache.qpid.server.management.plugin.ManagementResponse)4 LegacyConfiguredObject (org.apache.qpid.server.management.plugin.controller.LegacyConfiguredObject)4 Test (org.junit.Test)4 ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)3 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 UUID (java.util.UUID)1 ResponseType (org.apache.qpid.server.management.plugin.ResponseType)1 ConfiguredObjectOperation (org.apache.qpid.server.model.ConfiguredObjectOperation)1