Search in sources :

Example 51 with ConfiguredObject

use of org.apache.qpid.server.model.ConfiguredObject in project qpid-broker-j by apache.

the class ConfiguredObjectQuery method filterObjects.

private List<ConfiguredObject<?>> filterObjects(final List<ConfiguredObject<?>> objects, final String whereClause) {
    List<ConfiguredObject<?>> filteredObjects = new ArrayList<>();
    ConfiguredObjectFilterParser parser = new ConfiguredObjectFilterParser();
    parser.setConfiguredObjectExpressionFactory(_expressionFactory);
    try {
        final BooleanExpression<ConfiguredObject> expression = parser.parseWhere(whereClause);
        for (ConfiguredObject<?> object : objects) {
            try {
                if (expression.matches(object)) {
                    filteredObjects.add(object);
                }
            } catch (RuntimeException e) {
                throw new EvaluationException("Error while evaluating object against where clause", e);
            }
        }
    } catch (ParseException | TokenMgrError e) {
        throw new SelectorParsingException("Unable to parse where clause", e);
    }
    return filteredObjects;
}
Also used : SelectorParsingException(org.apache.qpid.server.filter.SelectorParsingException) ArrayList(java.util.ArrayList) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject)

Example 52 with ConfiguredObject

use of org.apache.qpid.server.model.ConfiguredObject in project qpid-broker-j by apache.

the class AbstractServlet method getConfiguredObjectFinder.

protected final ConfiguredObjectFinder getConfiguredObjectFinder(final ConfiguredObject<?> root) {
    ConfiguredObjectFinder finder = _configuredObjectFinders.get(root);
    if (finder == null) {
        finder = new ConfiguredObjectFinder(root);
        final ConfiguredObjectFinder existingValue = _configuredObjectFinders.putIfAbsent(root, finder);
        if (existingValue != null) {
            finder = existingValue;
        } else {
            final AbstractConfigurationChangeListener deletionListener = new AbstractConfigurationChangeListener() {

                @Override
                public void stateChanged(final ConfiguredObject<?> object, final State oldState, final State newState) {
                    if (newState == State.DELETED) {
                        _configuredObjectFinders.remove(root);
                    }
                }
            };
            root.addChangeListener(deletionListener);
            if (root.getState() == State.DELETED) {
                _configuredObjectFinders.remove(root);
                root.removeChangeListener(deletionListener);
            }
        }
    }
    return finder;
}
Also used : State(org.apache.qpid.server.model.State) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) ConfiguredObjectFinder(org.apache.qpid.server.model.ConfiguredObjectFinder) AbstractConfigurationChangeListener(org.apache.qpid.server.model.AbstractConfigurationChangeListener)

Example 53 with ConfiguredObject

use of org.apache.qpid.server.model.ConfiguredObject in project qpid-broker-j by apache.

the class ApiDocsServlet method doGet.

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response, final ConfiguredObject<?> managedObject) throws IOException {
    final ConfiguredObjectFinder finder = getConfiguredObjectFinder(managedObject);
    final Class<? extends ConfiguredObject> configuredClass;
    final Class<? extends ConfiguredObject>[] hierarchy;
    final String[] servletPathParts = request.getServletPath().split("/");
    final Model model = managedObject.getModel();
    if (servletPathParts.length < 4) {
        configuredClass = null;
        hierarchy = null;
    } else {
        configuredClass = getConfiguredClass(request, managedObject);
        if (configuredClass == null) {
            sendError(response, HttpServletResponse.SC_NOT_FOUND);
            return;
        }
        hierarchy = finder.getHierarchy(configuredClass);
        if (hierarchy == null) {
            sendError(response, HttpServletResponse.SC_NOT_FOUND);
            return;
        }
        if (!_typeSpecialisations.containsKey(configuredClass)) {
            final List<Class<? extends ConfiguredObject>> types = new ArrayList<>(model.getTypeRegistry().getTypeSpecialisations(configuredClass));
            _typeSpecialisations.putIfAbsent(configuredClass, types);
        }
    }
    response.setContentType("text/html");
    response.setStatus(HttpServletResponse.SC_OK);
    final PrintWriter writer = response.getWriter();
    writePreamble(writer);
    writeHead(writer, hierarchy, configuredClass);
    if (hierarchy == null) {
        writer.println("<table class=\"api\">");
        writer.println("<thead>");
        writer.println("<tr>");
        writer.println("<th class=\"type\">Type</th>");
        writer.println("<th class=\"path\">Path</th>");
        writer.println("<th class=\"description\">Description</th>");
        writer.println("</tr>");
        writer.println("</thead>");
        writer.println("<tbody>");
        final SortedSet<Class<? extends ConfiguredObject>> managedCategories = new TreeSet<>(CLASS_COMPARATOR);
        managedCategories.addAll(finder.getManagedCategories());
        final String pathStem = "/" + servletPathParts[1] + "/" + (servletPathParts.length == 2 ? "latest" : servletPathParts[2]) + "/";
        for (final Class<? extends ConfiguredObject> category : managedCategories) {
            final String path = pathStem + category.getSimpleName().toLowerCase();
            writer.println("<tr>");
            writer.println("<td class=\"type\"><a href=" + path + ">" + category.getSimpleName() + "</a></td>");
            writer.println("<td class=\"path\">" + path + "</td>");
            writer.println("<td class=\"description\">" + category.getAnnotation(ManagedObject.class).description() + "</td>");
            writer.println("</tr>");
        }
        writer.println("</tbody>");
        writer.println("</table>");
    } else {
        final List<Class<? extends ConfiguredObject>> types = _typeSpecialisations.get(configuredClass);
        writeCategoryDescription(writer, configuredClass);
        writeUsage(writer, request, hierarchy, configuredClass);
        writeTypes(writer, model, types);
        writeAttributes(writer, configuredClass, model, types);
        writeStatistics(writer, configuredClass, model, types);
        writeOperations(writer, configuredClass, model, types);
        writeContext(writer, configuredClass, model, types);
    }
    writeFoot(writer);
}
Also used : ArrayList(java.util.ArrayList) TreeSet(java.util.TreeSet) Model(org.apache.qpid.server.model.Model) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) ConfiguredObjectFinder(org.apache.qpid.server.model.ConfiguredObjectFinder) PrintWriter(java.io.PrintWriter)

Example 54 with ConfiguredObject

use of org.apache.qpid.server.model.ConfiguredObject in project qpid-broker-j by apache.

the class RestServlet method getTargetObjects.

private Collection<ConfiguredObject<?>> getTargetObjects(final Class<? extends ConfiguredObject> configuredClass, final ConfiguredObjectFinder finder, RequestInfo requestInfo, List<Predicate<ConfiguredObject<?>>> filterPredicateList) {
    List<String> names = requestInfo.getModelParts();
    Collection<ConfiguredObject<?>> targetObjects = finder.findObjectsFromPath(names, finder.getHierarchy(configuredClass), true);
    if (!(targetObjects == null || filterPredicateList.isEmpty())) {
        Iterator<ConfiguredObject<?>> iter = targetObjects.iterator();
        while (iter.hasNext()) {
            ConfiguredObject obj = iter.next();
            for (Predicate<ConfiguredObject<?>> predicate : filterPredicateList) {
                if (!predicate.apply(obj)) {
                    iter.remove();
                    break;
                }
            }
        }
    }
    return targetObjects;
}
Also used : ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) AbstractConfiguredObject(org.apache.qpid.server.model.AbstractConfiguredObject)

Example 55 with ConfiguredObject

use of org.apache.qpid.server.model.ConfiguredObject in project qpid-broker-j by apache.

the class BDBHAVirtualHostNodeOperationalLoggingTest method testRemoteNodeDetached.

@Test
public void testRemoteNodeDetached() throws Exception {
    int node1PortNumber = _portHelper.getNextAvailable();
    int node2PortNumber = _portHelper.getNextAvailable();
    String helperAddress = "localhost:" + node1PortNumber;
    String groupName = "group";
    String nodeName = "node1";
    Map<String, Object> node1Attributes = _helper.createNodeAttributes(nodeName, groupName, helperAddress, helperAddress, nodeName, node1PortNumber, node2PortNumber);
    node1Attributes.put(BDBHAVirtualHostNode.DESIGNATED_PRIMARY, true);
    BDBHAVirtualHostNodeImpl node1 = (BDBHAVirtualHostNodeImpl) _helper.createHaVHN(node1Attributes);
    final CountDownLatch remoteNodeAdded = new CountDownLatch(1);
    node1.addChangeListener(new AbstractConfigurationChangeListener() {

        @Override
        public void childAdded(ConfiguredObject<?> object, ConfiguredObject<?> child) {
            if (child instanceof BDBHARemoteReplicationNode) {
                remoteNodeAdded.countDown();
            }
        }
    });
    Map<String, Object> node2Attributes = _helper.createNodeAttributes("node2", groupName, "localhost:" + node2PortNumber, helperAddress, nodeName);
    BDBHAVirtualHostNodeImpl node2 = (BDBHAVirtualHostNodeImpl) _helper.createHaVHN(node2Attributes);
    assertTrue("Remote node was not added during expected period of time", remoteNodeAdded.await(10, TimeUnit.SECONDS));
    BDBHARemoteReplicationNodeImpl remoteNode = (BDBHARemoteReplicationNodeImpl) node1.getRemoteReplicationNodes().iterator().next();
    waitForRemoteNodeToAttainRole(remoteNode, EnumSet.of(NodeRole.REPLICA));
    reset(_eventLogger);
    // close remote node
    node2.close();
    waitForRemoteNodeToAttainRole(remoteNode, EnumSet.of(NodeRole.UNREACHABLE));
    // make sure that task executor thread finishes all scheduled tasks
    node1.stop();
    // verify that remaining node issues the DETACHED operational logging for remote node
    String expectedMessage = HighAvailabilityMessages.LEFT(node2.getName(), node2.getAddress()).toString();
    verify(_eventLogger).message(argThat(new LogSubjectMatcher(node1.getGroupLogSubject())), argThat(new LogMessageMatcher(expectedMessage, HighAvailabilityMessages.LEFT_LOG_HIERARCHY)));
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) AbstractConfigurationChangeListener(org.apache.qpid.server.model.AbstractConfigurationChangeListener) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) Test(org.junit.Test)

Aggregations

ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)117 ArrayList (java.util.ArrayList)43 HashMap (java.util.HashMap)35 Test (org.junit.Test)33 Map (java.util.Map)29 List (java.util.List)27 LinkedHashMap (java.util.LinkedHashMap)25 UUID (java.util.UUID)21 AbstractConfiguredObject (org.apache.qpid.server.model.AbstractConfiguredObject)21 AbstractConfigurationChangeListener (org.apache.qpid.server.model.AbstractConfigurationChangeListener)15 Collection (java.util.Collection)12 LegacyConfiguredObject (org.apache.qpid.server.management.plugin.controller.LegacyConfiguredObject)12 ConfiguredObjectFinder (org.apache.qpid.server.model.ConfiguredObjectFinder)12 ManagedObject (org.apache.qpid.server.model.ManagedObject)11 State (org.apache.qpid.server.model.State)10 Date (java.util.Date)7 TreeMap (java.util.TreeMap)6 CountDownLatch (java.util.concurrent.CountDownLatch)6 GenericLegacyConfiguredObject (org.apache.qpid.server.management.plugin.controller.GenericLegacyConfiguredObject)6 InternalMessageHeader (org.apache.qpid.server.message.internal.InternalMessageHeader)6