Search in sources :

Example 41 with ConfiguredObject

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

the class BDBHAVirtualHostNodeTest method testIntruderConnected.

public void testIntruderConnected() 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);
    BDBHAVirtualHostNode<?> node1 = _helper.createAndStartHaVHN(node1Attributes);
    final CountDownLatch stopLatch = new CountDownLatch(1);
    ConfigurationChangeListener listener = new AbstractConfigurationChangeListener() {

        @Override
        public void stateChanged(ConfiguredObject<?> object, State oldState, State newState) {
            if (newState == State.ERRORED) {
                stopLatch.countDown();
            }
        }
    };
    node1.addChangeListener(listener);
    String node2Name = "node2";
    File environmentPathFile = new File(_helper.getMessageStorePath() + File.separator + node2Name);
    Durability durability = Durability.parse((String) node1Attributes.get(BDBHAVirtualHostNode.DURABILITY));
    joinIntruder(node2PortNumber, node2Name, groupName, helperAddress, durability, environmentPathFile);
    assertTrue("Intruder protection was not triggered during expected timeout", stopLatch.await(20, TimeUnit.SECONDS));
}
Also used : ConfigurationChangeListener(org.apache.qpid.server.model.ConfigurationChangeListener) AbstractConfigurationChangeListener(org.apache.qpid.server.model.AbstractConfigurationChangeListener) State(org.apache.qpid.server.model.State) Durability(com.sleepycat.je.Durability) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) CountDownLatch(java.util.concurrent.CountDownLatch) File(java.io.File) AbstractConfigurationChangeListener(org.apache.qpid.server.model.AbstractConfigurationChangeListener)

Example 42 with ConfiguredObject

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

the class ScramNegotiatorTest method createTestAuthenticationManager.

private AuthenticationProvider createTestAuthenticationManager(String type) {
    Map<String, Object> attributes = new HashMap<>();
    attributes.put(ConfiguredObject.NAME, getTestName());
    attributes.put(ConfiguredObject.ID, UUID.randomUUID());
    attributes.put(ConfiguredObject.TYPE, type);
    ConfiguredObjectFactory objectFactory = _broker.getObjectFactory();
    @SuppressWarnings("unchecked") AuthenticationProvider<?> configuredObject = objectFactory.create(AuthenticationProvider.class, attributes, _broker);
    assertEquals("Unexpected state", State.ACTIVE, configuredObject.getState());
    PasswordCredentialManagingAuthenticationProvider<?> authenticationProvider = (PasswordCredentialManagingAuthenticationProvider<?>) configuredObject;
    authenticationProvider.createUser(VALID_USER_NAME, VALID_USER_PASSWORD, Collections.<String, String>emptyMap());
    return configuredObject;
}
Also used : ConfiguredObjectFactory(org.apache.qpid.server.model.ConfiguredObjectFactory) HashMap(java.util.HashMap) PasswordCredentialManagingAuthenticationProvider(org.apache.qpid.server.model.PasswordCredentialManagingAuthenticationProvider) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject)

Example 43 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 44 with ConfiguredObject

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

the class ManagementNode method generateAttributeNames.

private List<String> generateAttributeNames(String entityType) {
    Set<String> attrNameSet = new HashSet<>();
    List<String> attributeNames = new ArrayList<>();
    for (String standardAttribute : Arrays.asList(IDENTITY_ATTRIBUTE, TYPE_ATTRIBUTE, QPID_TYPE, OBJECT_PATH)) {
        attrNameSet.add(standardAttribute);
        attributeNames.add(standardAttribute);
    }
    final ConfiguredObjectTypeRegistry typeRegistry = _model.getTypeRegistry();
    List<Class<? extends ConfiguredObject>> classes = new ArrayList<>();
    if (entityType != null && !entityType.trim().equals("")) {
        Class<? extends ConfiguredObject> clazz = _managedTypes.get(entityType);
        if (clazz != null) {
            classes.add(clazz);
            if (ConfiguredObjectTypeRegistry.getCategory(clazz) == clazz) {
                classes.addAll(_model.getTypeRegistry().getTypeSpecialisations(clazz));
            }
        }
    } else {
        for (Class<? extends ConfiguredObject> clazz : _managedCategories) {
            classes.add(clazz);
            classes.addAll(_model.getTypeRegistry().getTypeSpecialisations(clazz));
        }
    }
    for (Class<? extends ConfiguredObject> clazz : classes) {
        for (String name : typeRegistry.getAttributeNames(clazz)) {
            if (!ConfiguredObject.ID.equals(name) && attrNameSet.add(name)) {
                attributeNames.add(name);
            }
        }
        final Class<? extends ConfiguredObject> category = ConfiguredObjectTypeRegistry.getCategory(clazz);
        if (category != _managedObject.getCategoryClass() && !isSyntheticChildClass(category)) {
            Class<? extends ConfiguredObject> parentType = _model.getParentType(category);
            if (parentType != _managedObject.getCategoryClass()) {
                attributeNames.add(parentType.getSimpleName().toLowerCase());
            }
        }
    }
    return attributeNames;
}
Also used : CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) AbstractConfiguredObject(org.apache.qpid.server.model.AbstractConfiguredObject) ConfiguredObjectTypeRegistry(org.apache.qpid.server.model.ConfiguredObjectTypeRegistry) HashSet(java.util.HashSet)

Example 45 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)

Aggregations

ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)91 ArrayList (java.util.ArrayList)37 HashMap (java.util.HashMap)28 List (java.util.List)23 AbstractConfiguredObject (org.apache.qpid.server.model.AbstractConfiguredObject)22 LinkedHashMap (java.util.LinkedHashMap)20 UUID (java.util.UUID)20 Map (java.util.Map)18 AbstractConfigurationChangeListener (org.apache.qpid.server.model.AbstractConfigurationChangeListener)12 ManagedObject (org.apache.qpid.server.model.ManagedObject)11 Date (java.util.Date)7 TreeMap (java.util.TreeMap)6 CountDownLatch (java.util.concurrent.CountDownLatch)6 InternalMessageHeader (org.apache.qpid.server.message.internal.InternalMessageHeader)6 State (org.apache.qpid.server.model.State)6 Collection (java.util.Collection)5 ConfiguredObjectFinder (org.apache.qpid.server.model.ConfiguredObjectFinder)5 Model (org.apache.qpid.server.model.Model)5 Preference (org.apache.qpid.server.model.preferences.Preference)5 IllegalConfigurationException (org.apache.qpid.server.configuration.IllegalConfigurationException)4