Search in sources :

Example 71 with ConfiguredObject

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

the class ManagementNode method performQuery.

private Map<?, ?> performQuery(final Map<String, Object> headerMap, final Map messageBody) {
    @SuppressWarnings("unchecked") List<Object> attributeNameObjects = (List<Object>) _managementInputConverter.convert(List.class, messageBody.get(ATTRIBUTE_NAMES));
    List<String> attributeNames;
    if (attributeNameObjects == null) {
        attributeNames = Collections.emptyList();
    } else {
        attributeNames = new ArrayList<>(attributeNameObjects.size());
        for (Object nameObject : attributeNameObjects) {
            if (nameObject == null) {
                throw new IllegalArgumentException("All attribute names must be non-null");
            } else {
                attributeNames.add(nameObject.toString());
            }
        }
    }
    String entityType = (String) headerMap.get(ENTITY_TYPE_HEADER);
    if (attributeNames.isEmpty()) {
        attributeNames = generateAttributeNames(entityType);
    }
    List<ConfiguredObject<?>> objects = getObjects(entityType);
    objects.sort(OBJECT_COMPARATOR);
    if (headerMap.containsKey(OFFSET_HEADER)) {
        int offset;
        if (headerMap.get(OFFSET_HEADER) instanceof Number) {
            offset = ((Number) headerMap.get(OFFSET_HEADER)).intValue();
        } else {
            offset = Integer.parseInt(headerMap.get(OFFSET_HEADER).toString());
        }
        if (offset >= 0) {
            if (offset < objects.size()) {
                objects = objects.subList(offset, objects.size());
            } else {
                objects = Collections.emptyList();
            }
        } else if (objects.size() + offset > 0) {
            objects = objects.subList(objects.size() + offset, objects.size());
        }
    }
    if (headerMap.containsKey(COUNT_HEADER)) {
        int count;
        if (headerMap.get(COUNT_HEADER) instanceof Number) {
            count = ((Number) headerMap.get(COUNT_HEADER)).intValue();
        } else {
            count = Integer.parseInt(headerMap.get(OFFSET_HEADER).toString());
        }
        if (count >= 0) {
            if (count < objects.size()) {
                objects = objects.subList(0, count);
            } else {
                objects = Collections.emptyList();
            }
        } else if (objects.size() + count > 0) {
            objects = objects.subList(0, objects.size() + count);
        }
    }
    List<List<Object>> resultList = new ArrayList<>(objects.size());
    for (ConfiguredObject<?> object : objects) {
        List<Object> attributes = new ArrayList<>(attributeNames.size());
        Map<?, ?> convertedObject = _managementOutputConverter.convertToOutput(object, true);
        for (String attributeName : attributeNames) {
            attributes.add(convertedObject.get(attributeName));
        }
        resultList.add(attributes);
    }
    Map<Object, Object> result = new LinkedHashMap<>();
    result.put(ATTRIBUTE_NAMES, attributeNames);
    result.put(RESULTS, resultList);
    return result;
}
Also used : CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) ManagedObject(org.apache.qpid.server.model.ManagedObject) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) AbstractConfiguredObject(org.apache.qpid.server.model.AbstractConfiguredObject) List(java.util.List) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) AbstractConfiguredObject(org.apache.qpid.server.model.AbstractConfiguredObject)

Example 72 with ConfiguredObject

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

the class ManagementNode method performCreateOperation.

private InternalMessage performCreateOperation(final Class<? extends ConfiguredObject> clazz, final InternalMessage message) {
    InternalMessageHeader requestHeader = message.getMessageHeader();
    final MutableMessageHeader responseHeader = new MutableMessageHeader();
    responseHeader.setCorrelationId(requestHeader.getCorrelationId() == null ? requestHeader.getMessageId() : requestHeader.getCorrelationId());
    responseHeader.setMessageId(UUID.randomUUID().toString());
    responseHeader.setHeader(STATUS_CODE_HEADER, STATUS_CODE_CREATED);
    if (message.getMessageBody() instanceof Map) {
        @SuppressWarnings("unchecked") Map<String, Object> attributes = (Map<String, Object>) message.getMessageBody();
        if (attributes.containsKey(IDENTITY_ATTRIBUTE)) {
            return createFailureResponse(message, STATUS_CODE_BAD_REQUEST, "The '" + IDENTITY_ATTRIBUTE + "' cannot be set when creating an object");
        }
        if (attributes.containsKey(ConfiguredObject.ID)) {
            return createFailureResponse(message, STATUS_CODE_BAD_REQUEST, "The '" + ConfiguredObject.ID + "' cannot be set when creating an object");
        }
        if (!attributes.containsKey(QPID_TYPE) && ConfiguredObjectTypeRegistry.getCategory(clazz) != clazz) {
            Class<? extends ConfiguredObject> typeClass = _model.getTypeRegistry().getTypeClass(clazz);
            String type = typeClass.getAnnotation(ManagedObject.class).type();
            if (!"".equals(type)) {
                attributes.put(QPID_TYPE, type);
            }
        }
        if (attributes.containsKey(OBJECT_PATH)) {
            String path = String.valueOf(attributes.remove(OBJECT_PATH));
            ConfiguredObject theParent = _managedObject;
            final Class<? extends ConfiguredObject>[] hierarchy = _configuredObjectFinder.getHierarchy(clazz);
            if (hierarchy.length > 1) {
                ConfiguredObject parent = _configuredObjectFinder.findObjectParentsFromPath(Arrays.asList(getPathElements(path)), hierarchy, ConfiguredObjectTypeRegistry.getCategory(clazz));
                if (parent == null) {
                    return createFailureResponse(message, STATUS_CODE_NOT_FOUND, "The '" + OBJECT_PATH + "' " + path + " does not identify a valid parent");
                }
                theParent = parent;
            }
            return doCreate(clazz, message, responseHeader, attributes, theParent);
        } else if (_configuredObjectFinder.getHierarchy(clazz).length == 1 && attributes.containsKey(ConfiguredObject.NAME)) {
            return doCreate(clazz, message, responseHeader, attributes, _managedObject);
        } else {
            return createFailureResponse(message, STATUS_CODE_BAD_REQUEST, "The '" + OBJECT_PATH + "' must be supplied");
        }
    } else {
        return createFailureResponse(message, STATUS_CODE_BAD_REQUEST, "Message body must be a map");
    }
}
Also used : InternalMessageHeader(org.apache.qpid.server.message.internal.InternalMessageHeader) ManagedObject(org.apache.qpid.server.model.ManagedObject) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) AbstractConfiguredObject(org.apache.qpid.server.model.AbstractConfiguredObject) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) AbstractConfiguredObject(org.apache.qpid.server.model.AbstractConfiguredObject) ManagedObject(org.apache.qpid.server.model.ManagedObject) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 73 with ConfiguredObject

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

the class ManagementNode method findAllChildren.

private Set<ConfiguredObject<?>> findAllChildren() {
    final Set<ConfiguredObject<?>> foundObjects;
    foundObjects = new HashSet<>();
    Set<ConfiguredObject<?>> parents = new HashSet<>();
    Set<ConfiguredObject<?>> children;
    parents.add(_managedObject);
    for (ConfiguredObjectOperation op : _associatedChildrenOperations.values()) {
        @SuppressWarnings("unchecked") final Collection<ConfiguredObject<?>> associated = getAssociatedChildren(op, _managedObject);
        parents.addAll(associated);
    }
    foundObjects.addAll(parents);
    do {
        children = new HashSet<>();
        for (ConfiguredObject<?> parent : parents) {
            for (Class<? extends ConfiguredObject> childClass : _model.getChildTypes(parent.getCategoryClass())) {
                children.addAll((Collection<? extends ConfiguredObject<?>>) parent.getChildren(childClass));
            }
        }
        parents = children;
    } while (foundObjects.addAll(parents));
    return foundObjects;
}
Also used : ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) AbstractConfiguredObject(org.apache.qpid.server.model.AbstractConfiguredObject) ConfiguredObjectOperation(org.apache.qpid.server.model.ConfiguredObjectOperation) HashSet(java.util.HashSet)

Example 74 with ConfiguredObject

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

the class ManagementNode method performOperation.

private InternalMessage performOperation(final Class<? extends ConfiguredObject> clazz, final String operation, InternalMessage message) {
    try {
        if (STANDARD_OPERATIONS.contains(operation)) {
            StandardOperation standardOperation;
            if ((standardOperation = _standardOperations.get(clazz).get(operation)) != null) {
                return standardOperation.performOperation(clazz, message);
            }
        } else {
            final InternalMessageHeader requestHeader = message.getMessageHeader();
            final Map<String, Object> headers = requestHeader.getHeaderMap();
            ConfiguredObject<?> object = findObject(clazz, headers);
            if (object == null) {
                return createFailureResponse(message, STATUS_CODE_NOT_FOUND, "Not found");
            }
            final Map<String, ConfiguredObjectOperation<?>> operations = _model.getTypeRegistry().getOperations(object.getClass());
            @SuppressWarnings("unchecked") final ConfiguredObjectOperation<ConfiguredObject<?>> method = (ConfiguredObjectOperation<ConfiguredObject<?>>) operations.get(operation);
            if (method != null) {
                return performConfiguredObjectOperation(object, message, method);
            }
        }
        return createFailureResponse(message, STATUS_CODE_NOT_IMPLEMENTED, "Not implemented");
    } catch (RuntimeException e) {
        return createFailureResponse(message, STATUS_CODE_INTERNAL_ERROR, e.getMessage());
    }
}
Also used : InternalMessageHeader(org.apache.qpid.server.message.internal.InternalMessageHeader) ManagedObject(org.apache.qpid.server.model.ManagedObject) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) AbstractConfiguredObject(org.apache.qpid.server.model.AbstractConfiguredObject) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) AbstractConfiguredObject(org.apache.qpid.server.model.AbstractConfiguredObject) ConfiguredObjectOperation(org.apache.qpid.server.model.ConfiguredObjectOperation)

Example 75 with ConfiguredObject

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

the class ManagementOutputConverter method convertToOutput.

Map<?, ?> convertToOutput(final ConfiguredObject<?> object, final boolean actuals) {
    Map<String, Object> attributes = new LinkedHashMap<>();
    attributes.put(ManagementNode.IDENTITY_ATTRIBUTE, object.getId());
    attributes.put(ManagementNode.OBJECT_PATH, _managementNode.generatePath(object));
    attributes.put(ManagementNode.TYPE_ATTRIBUTE, _managementNode.getAmqpName(object.getTypeClass()));
    attributes.put(ManagementNode.QPID_TYPE, object.getType());
    if (object != _managementNode.getManagedObject() && !_managementNode.isSyntheticChildClass(object.getCategoryClass())) {
        Class<? extends ConfiguredObject> parentType = object.getModel().getParentType(object.getCategoryClass());
        if (parentType != _managementNode.getManagedObject().getCategoryClass()) {
            attributes.put(parentType.getSimpleName().toLowerCase(), object.getParent());
        }
    }
    for (String name : object.getAttributeNames()) {
        if (!ID_AND_TYPE.contains(name)) {
            ConfiguredObjectAttribute<?, ?> attribute = object.getModel().getTypeRegistry().getAttributeTypes(object.getClass()).get(name);
            Object value = actuals ? object.getActualAttributes().get(name) : object.getAttribute(name);
            if (attribute.isSecureValue(value)) {
                value = object.getAttribute(name);
            }
            if (value != null) {
                attributes.put(name, value);
            }
        }
    }
    return convertMapToOutput(attributes);
}
Also used : ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) LinkedHashMap(java.util.LinkedHashMap)

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