Search in sources :

Example 1 with ConfiguredObjectFactory

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);
    }
}
Also used : ConfiguredObjectFactory(org.apache.qpid.server.model.ConfiguredObjectFactory) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ServerScopedRuntimeException(org.apache.qpid.server.util.ServerScopedRuntimeException) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) UUID(java.util.UUID)

Example 2 with ConfiguredObjectFactory

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;
}
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 3 with ConfiguredObjectFactory

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();
}
Also used : Broker(org.apache.qpid.server.model.Broker) ConfiguredObjectFactory(org.apache.qpid.server.model.ConfiguredObjectFactory) DurableConfigurationStore(org.apache.qpid.server.store.DurableConfigurationStore) EventLogger(org.apache.qpid.server.logging.EventLogger) CurrentThreadTaskExecutor(org.apache.qpid.server.configuration.updater.CurrentThreadTaskExecutor) PreferenceStore(org.apache.qpid.server.store.preferences.PreferenceStore) Principal(java.security.Principal) AccessControl(org.apache.qpid.server.security.AccessControl) VirtualHostNode(org.apache.qpid.server.model.VirtualHostNode) ConfiguredObjectFactoryImpl(org.apache.qpid.server.model.ConfiguredObjectFactoryImpl)

Example 4 with ConfiguredObjectFactory

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);
}
Also used : ConfiguredObjectFactory(org.apache.qpid.server.model.ConfiguredObjectFactory) HashMap(java.util.HashMap) AuthenticationProvider(org.apache.qpid.server.model.AuthenticationProvider) VirtualHostNode(org.apache.qpid.server.model.VirtualHostNode)

Example 5 with ConfiguredObjectFactory

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();
}
Also used : TaskExecutor(org.apache.qpid.server.configuration.updater.TaskExecutor) TaskExecutorImpl(org.apache.qpid.server.configuration.updater.TaskExecutorImpl) Broker(org.apache.qpid.server.model.Broker) ConfiguredObjectFactory(org.apache.qpid.server.model.ConfiguredObjectFactory) EventLogger(org.apache.qpid.server.logging.EventLogger) HashMap(java.util.HashMap) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) ConfiguredObjectFactoryImpl(org.apache.qpid.server.model.ConfiguredObjectFactoryImpl)

Aggregations

ConfiguredObjectFactory (org.apache.qpid.server.model.ConfiguredObjectFactory)9 ConfiguredObjectFactoryImpl (org.apache.qpid.server.model.ConfiguredObjectFactoryImpl)5 HashMap (java.util.HashMap)4 CurrentThreadTaskExecutor (org.apache.qpid.server.configuration.updater.CurrentThreadTaskExecutor)4 EventLogger (org.apache.qpid.server.logging.EventLogger)4 ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)4 TaskExecutor (org.apache.qpid.server.configuration.updater.TaskExecutor)3 Broker (org.apache.qpid.server.model.Broker)3 VirtualHostNode (org.apache.qpid.server.model.VirtualHostNode)3 DurableConfigurationStore (org.apache.qpid.server.store.DurableConfigurationStore)3 AuthenticationProvider (org.apache.qpid.server.model.AuthenticationProvider)2 SystemConfig (org.apache.qpid.server.model.SystemConfig)2 Principal (java.security.Principal)1 ArrayList (java.util.ArrayList)1 UUID (java.util.UUID)1 TaskExecutorImpl (org.apache.qpid.server.configuration.updater.TaskExecutorImpl)1 PasswordCredentialManagingAuthenticationProvider (org.apache.qpid.server.model.PasswordCredentialManagingAuthenticationProvider)1 VirtualHost (org.apache.qpid.server.model.VirtualHost)1 AccessControl (org.apache.qpid.server.security.AccessControl)1 ReplicatedEnvironmentFacade (org.apache.qpid.server.store.berkeleydb.replication.ReplicatedEnvironmentFacade)1