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