use of org.apache.qpid.server.model.ConfiguredObjectFactory in project qpid-broker-j by apache.
the class GenericRecoverer method resolveObjects.
private void resolveObjects(ConfiguredObject<?> parentObject, List<ConfiguredObjectRecord> records, final boolean isNew) {
ConfiguredObjectFactory factory = parentObject.getObjectFactory();
Map<UUID, ConfiguredObject<?>> resolvedObjects = new HashMap<UUID, ConfiguredObject<?>>();
resolvedObjects.put(parentObject.getId(), parentObject);
Collection<ConfiguredObjectRecord> recordsWithUnresolvedParents = new ArrayList<ConfiguredObjectRecord>(records);
Collection<UnresolvedConfiguredObject<? extends ConfiguredObject>> recordsWithUnresolvedDependencies = new ArrayList<UnresolvedConfiguredObject<? extends ConfiguredObject>>();
boolean updatesMade;
do {
updatesMade = false;
Iterator<ConfiguredObjectRecord> iter = recordsWithUnresolvedParents.iterator();
while (iter.hasNext()) {
ConfiguredObjectRecord record = iter.next();
Collection<ConfiguredObject<?>> parents = new ArrayList<ConfiguredObject<?>>();
boolean foundParents = true;
for (UUID parentId : record.getParents().values()) {
if (!resolvedObjects.containsKey(parentId)) {
foundParents = false;
break;
} else {
parents.add(resolvedObjects.get(parentId));
}
}
if (parents.size() > 1) {
throw new IllegalStateException(String.format("Unexpected number of parents %d for record %s ", parents.size(), record));
}
if (foundParents) {
iter.remove();
ConfiguredObject<?>[] parentArray = parents.toArray(new ConfiguredObject<?>[parents.size()]);
UnresolvedConfiguredObject<? extends ConfiguredObject> recovered = factory.recover(record, parentArray[0]);
Collection<ConfiguredObjectDependency<?>> dependencies = recovered.getUnresolvedDependencies();
if (dependencies.isEmpty()) {
updatesMade = true;
ConfiguredObject<?> resolved = recovered.resolve();
if (!isNew) {
resolved.decryptSecrets();
}
resolvedObjects.put(resolved.getId(), resolved);
} else {
recordsWithUnresolvedDependencies.add(recovered);
}
}
}
Iterator<UnresolvedConfiguredObject<? extends ConfiguredObject>> unresolvedIter = recordsWithUnresolvedDependencies.iterator();
while (unresolvedIter.hasNext()) {
UnresolvedConfiguredObject<? extends ConfiguredObject> unresolvedObject = unresolvedIter.next();
Collection<ConfiguredObjectDependency<?>> dependencies = new ArrayList<ConfiguredObjectDependency<?>>(unresolvedObject.getUnresolvedDependencies());
for (ConfiguredObjectDependency dependency : dependencies) {
if (dependency instanceof ConfiguredObjectIdDependency) {
UUID id = ((ConfiguredObjectIdDependency) dependency).getId();
if (resolvedObjects.containsKey(id)) {
dependency.resolve(resolvedObjects.get(id));
}
} else if (dependency instanceof ConfiguredObjectNameDependency) {
ConfiguredObject<?> dependentObject = null;
ConfiguredObject<?> parent = unresolvedObject.getParent();
dependentObject = parent.findConfiguredObject(dependency.getCategoryClass(), ((ConfiguredObjectNameDependency) dependency).getName());
if (dependentObject != null) {
dependency.resolve(dependentObject);
}
} else {
throw new ServerScopedRuntimeException("Unknown dependency type " + dependency.getClass().getSimpleName());
}
}
if (unresolvedObject.getUnresolvedDependencies().isEmpty()) {
updatesMade = true;
unresolvedIter.remove();
ConfiguredObject<?> resolved = unresolvedObject.resolve();
resolvedObjects.put(resolved.getId(), resolved);
}
}
} while (updatesMade && !(recordsWithUnresolvedDependencies.isEmpty() && recordsWithUnresolvedParents.isEmpty()));
if (!recordsWithUnresolvedDependencies.isEmpty()) {
throw new IllegalArgumentException("Cannot resolve some objects: " + recordsWithUnresolvedDependencies);
}
if (!recordsWithUnresolvedParents.isEmpty()) {
throw new IllegalArgumentException("Cannot resolve object because their parents cannot be found" + recordsWithUnresolvedParents);
}
}
use of org.apache.qpid.server.model.ConfiguredObjectFactory 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.ConfiguredObjectFactory in project qpid-broker-j by apache.
the class VirtualHostQueueCreationTest method setUp.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void setUp() throws Exception {
super.setUp();
EventLogger eventLogger = mock(EventLogger.class);
ConfiguredObjectFactory objectFactory = new ConfiguredObjectFactoryImpl(BrokerModel.getInstance());
_taskExecutor = new CurrentThreadTaskExecutor();
_taskExecutor.start();
SystemConfig<?> context = mock(SystemConfig.class);
when(context.getEventLogger()).thenReturn(eventLogger);
when(context.createPreferenceStore()).thenReturn(mock(PreferenceStore.class));
Principal systemPrincipal = mock(Principal.class);
AccessControl accessControl = BrokerTestHelper.createAccessControlMock();
Broker broker = BrokerTestHelper.mockWithSystemPrincipalAndAccessControl(Broker.class, systemPrincipal, accessControl);
when(broker.getObjectFactory()).thenReturn(objectFactory);
when(broker.getCategoryClass()).thenReturn(Broker.class);
when(broker.getParent()).thenReturn(context);
when(broker.getModel()).thenReturn(objectFactory.getModel());
when(broker.getTaskExecutor()).thenReturn(_taskExecutor);
when(broker.getChildExecutor()).thenReturn(_taskExecutor);
_virtualHostNode = BrokerTestHelper.mockWithSystemPrincipalAndAccessControl(VirtualHostNode.class, systemPrincipal, accessControl);
when(_virtualHostNode.getParent()).thenReturn(broker);
when(_virtualHostNode.getConfigurationStore()).thenReturn(mock(DurableConfigurationStore.class));
when(_virtualHostNode.getObjectFactory()).thenReturn(objectFactory);
when(_virtualHostNode.getModel()).thenReturn(objectFactory.getModel());
when(_virtualHostNode.getTaskExecutor()).thenReturn(_taskExecutor);
when(_virtualHostNode.getChildExecutor()).thenReturn(_taskExecutor);
when(_virtualHostNode.getCategoryClass()).thenReturn(VirtualHostNode.class);
when(_virtualHostNode.createPreferenceStore()).thenReturn(mock(PreferenceStore.class));
_virtualHost = createHost();
}
use of org.apache.qpid.server.model.ConfiguredObjectFactory in project qpid-broker-j by apache.
the class VirtualHostAliasTest method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
_broker = BrokerTestHelper.createBrokerMock();
AuthenticationProvider dummyAuthProvider = mock(AuthenticationProvider.class);
when(dummyAuthProvider.getName()).thenReturn("dummy");
when(dummyAuthProvider.getId()).thenReturn(UUID.randomUUID());
when(dummyAuthProvider.getMechanisms()).thenReturn(Arrays.asList("PLAIN"));
when(_broker.getChildren(eq(AuthenticationProvider.class))).thenReturn(Collections.singleton(dummyAuthProvider));
for (String name : new String[] { "red", "blue", "purple", "black" }) {
boolean defaultVHN = "black".equals(name);
VirtualHost<?> virtualHost = BrokerTestHelper.createVirtualHost(name, _broker, defaultVHN);
VirtualHostNode vhn = (VirtualHostNode) virtualHost.getParent();
assertNotSame(vhn.getName(), virtualHost.getName());
_vhosts.put(name, virtualHost);
if (defaultVHN) {
when(_broker.findDefautVirtualHostNode()).thenReturn(vhn);
}
}
ConfiguredObjectFactory objectFactory = _broker.getObjectFactory();
final Map<String, Object> attributes = new HashMap<>();
attributes.put(Port.NAME, getTestName());
attributes.put(Port.PORT, 0);
attributes.put(Port.AUTHENTICATION_PROVIDER, "dummy");
attributes.put(Port.TYPE, "AMQP");
_port = (AmqpPort) objectFactory.create(Port.class, attributes, _broker);
}
use of org.apache.qpid.server.model.ConfiguredObjectFactory in project qpid-broker-j by apache.
the class HttpManagementTest method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
_id = UUID.randomUUID();
_broker = mock(Broker.class);
ConfiguredObjectFactory objectFactory = new ConfiguredObjectFactoryImpl(BrokerModel.getInstance());
when(_broker.getObjectFactory()).thenReturn(objectFactory);
when(_broker.getModel()).thenReturn(objectFactory.getModel());
when(_broker.getCategoryClass()).thenReturn(Broker.class);
when(_broker.getEventLogger()).thenReturn(mock(EventLogger.class));
TaskExecutor taskExecutor = new TaskExecutorImpl();
taskExecutor.start();
when(_broker.getTaskExecutor()).thenReturn(taskExecutor);
when(_broker.getChildExecutor()).thenReturn(taskExecutor);
Map<String, Object> attributes = new HashMap<String, Object>();
attributes.put(HttpManagement.HTTP_BASIC_AUTHENTICATION_ENABLED, false);
attributes.put(HttpManagement.HTTPS_BASIC_AUTHENTICATION_ENABLED, true);
attributes.put(HttpManagement.HTTP_SASL_AUTHENTICATION_ENABLED, false);
attributes.put(HttpManagement.HTTPS_SASL_AUTHENTICATION_ENABLED, true);
attributes.put(HttpManagement.NAME, getTestName());
attributes.put(HttpManagement.TIME_OUT, 10000l);
attributes.put(ConfiguredObject.ID, _id);
attributes.put(HttpManagement.DESIRED_STATE, State.QUIESCED);
_management = new HttpManagement(attributes, _broker);
_management.open();
}
Aggregations