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)));
}
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;
}
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();
}
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());
}
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);
}
Aggregations