use of org.apache.qpid.server.model.ConfiguredObject in project qpid-broker-j by apache.
the class LatestManagementController method delete.
@Override
public int delete(final ConfiguredObject<?> root, final String category, final List<String> names, final Map<String, List<String>> parameters) throws ManagementException {
int counter = 0;
try {
final Predicate<ConfiguredObject<?>> filterPredicate = buildFilterPredicates(parameters);
final Collection<ConfiguredObject<?>> allObjects = getTargetObjects(root, category, names, filterPredicate);
if (allObjects.isEmpty()) {
throw createNotFoundManagementException("Not Found");
}
for (ConfiguredObject o : allObjects) {
o.delete();
counter++;
}
} catch (RuntimeException e) {
throw ManagementException.toManagementException(e, getCategoryMapping(category), names);
} catch (Error e) {
throw ManagementException.handleError(e);
}
return counter;
}
use of org.apache.qpid.server.model.ConfiguredObject in project qpid-broker-j by apache.
the class LatestManagementController method getRequestType.
@Override
protected RequestType getRequestType(final ManagementRequest request) throws ManagementException {
final ConfiguredObject<?> root = request.getRoot();
if (root == null) {
final String message = String.format("No HTTP Management alias mapping found for '%s'", request.getRequestURL());
LOGGER.info(message);
throw createNotFoundManagementException(message);
}
final ConfiguredObjectFinder finder = getConfiguredObjectFinder(root);
final String category = request.getCategory();
final Class<? extends ConfiguredObject> configuredClass = getRequestCategoryClass(category, root.getModel());
final Class<? extends ConfiguredObject>[] hierarchy = getHierarchy(finder, configuredClass);
return getManagementRequestType(request.getMethod(), category, request.getPath(), hierarchy);
}
use of org.apache.qpid.server.model.ConfiguredObject 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.model.ConfiguredObject 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);
}
use of org.apache.qpid.server.model.ConfiguredObject in project qpid-broker-j by apache.
the class ContentServlet method doGet.
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response, final ConfiguredObject<?> managedObject) throws IOException {
ConfiguredObject root = managedObject;
String pathInfo = request.getPathInfo();
if (managedObject instanceof Broker && null != pathInfo && !pathInfo.isEmpty()) {
final ConfiguredObjectFinder finder = getConfiguredObjectFinder(managedObject);
final ConfiguredObject virtualHost = finder.findObjectFromPath(pathInfo.substring(1), VirtualHost.class);
if (null == virtualHost) {
sendError(response, HttpServletResponse.SC_NOT_FOUND);
return;
} else {
root = virtualHost;
}
} else if (managedObject instanceof VirtualHost && null != pathInfo && !pathInfo.isEmpty()) {
sendError(response, HttpServletResponse.SC_BAD_REQUEST);
return;
}
final Map<String, String[]> parameters = request.getParameterMap();
Content content = _contentFactory.createContent(root, parameters);
try {
writeContent(content, request, response);
} finally {
content.release();
}
}
Aggregations