Search in sources :

Example 11 with PreferenceRecord

use of org.apache.qpid.server.store.preferences.PreferenceRecord in project qpid-broker-j by apache.

the class AbstractJDBCPreferenceStore method updateOrCreateInternal.

private void updateOrCreateInternal(final Connection conn, final Collection<PreferenceRecord> preferenceRecords) throws SQLException, JsonProcessingException {
    for (PreferenceRecord record : preferenceRecords) {
        try (PreparedStatement stmt = conn.prepareStatement(String.format(FIND_PREFERENCE, getPreferencesTableName()))) {
            stmt.setString(1, record.getId().toString());
            try (ResultSet rs = stmt.executeQuery()) {
                if (rs.next()) {
                    try (PreparedStatement updateStatement = conn.prepareStatement(String.format(UPDATE_PREFERENCES, getPreferencesTableName()))) {
                        setAttributesAsBlob(updateStatement, 1, record.getAttributes());
                        updateStatement.setString(2, record.getId().toString());
                        updateStatement.execute();
                    }
                } else {
                    try (PreparedStatement insertStatement = conn.prepareStatement(String.format(INSERT_INTO_PREFERENCES, getPreferencesTableName()))) {
                        insertStatement.setString(1, record.getId().toString());
                        setAttributesAsBlob(insertStatement, 2, record.getAttributes());
                        insertStatement.execute();
                    }
                }
            }
        }
    }
}
Also used : PreferenceRecord(org.apache.qpid.server.store.preferences.PreferenceRecord) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 12 with PreferenceRecord

use of org.apache.qpid.server.store.preferences.PreferenceRecord in project qpid-broker-j by apache.

the class BDBPreferenceStoreTest method populateTestData.

private void populateTestData(final List<PreferenceRecord> records, final String modelVersion) {
    EnvironmentConfig envConfig = new EnvironmentConfig();
    envConfig.setAllowCreate(true);
    envConfig.setTransactional(false);
    try (Environment environment = new Environment(_storeFile, envConfig)) {
        DatabaseConfig dbConfig = new DatabaseConfig();
        dbConfig.setAllowCreate(true);
        try (Database versionDb = environment.openDatabase(null, "USER_PREFERENCES_VERSION", dbConfig);
            Database preferencesDb = environment.openDatabase(null, "USER_PREFERENCES", dbConfig)) {
            DatabaseEntry key = new DatabaseEntry();
            DatabaseEntry value = new DatabaseEntry();
            UUIDTupleBinding keyBinding = UUIDTupleBinding.getInstance();
            MapBinding valueBinding = MapBinding.getInstance();
            for (PreferenceRecord record : records) {
                keyBinding.objectToEntry(record.getId(), key);
                valueBinding.objectToEntry(record.getAttributes(), value);
                preferencesDb.put(null, key, value);
            }
            ByteBinding.byteToEntry((byte) 0, value);
            StringBinding.stringToEntry(modelVersion, key);
            versionDb.put(null, key, value);
        }
    }
}
Also used : MapBinding(org.apache.qpid.server.store.berkeleydb.tuple.MapBinding) EnvironmentConfig(com.sleepycat.je.EnvironmentConfig) Database(com.sleepycat.je.Database) PreferenceRecord(org.apache.qpid.server.store.preferences.PreferenceRecord) Environment(com.sleepycat.je.Environment) UUIDTupleBinding(org.apache.qpid.server.store.berkeleydb.tuple.UUIDTupleBinding) DatabaseEntry(com.sleepycat.je.DatabaseEntry) DatabaseConfig(com.sleepycat.je.DatabaseConfig)

Example 13 with PreferenceRecord

use of org.apache.qpid.server.store.preferences.PreferenceRecord in project qpid-broker-j by apache.

the class BrokerImpl method performActivation.

private void performActivation() {
    final DescendantScope descendantScope = getContextValue(DescendantScope.class, BROKER_FAIL_STARTUP_WITH_ERRORED_CHILD_SCOPE);
    List<ConfiguredObject<?>> failedChildren = getChildrenInState(this, State.ERRORED, descendantScope);
    if (!failedChildren.isEmpty()) {
        for (ConfiguredObject<?> o : failedChildren) {
            LOGGER.warn("{} child object '{}' of type '{}' is {}", o.getParent().getCategoryClass().getSimpleName(), o.getName(), o.getClass().getSimpleName(), State.ERRORED);
        }
        getEventLogger().message(BrokerMessages.FAILED_CHILDREN(failedChildren.toString()));
    }
    _documentationUrl = getContextValue(String.class, QPID_DOCUMENTATION_URL);
    final boolean brokerShutdownOnErroredChild = getContextValue(Boolean.class, BROKER_FAIL_STARTUP_WITH_ERRORED_CHILD);
    if (!_parent.isManagementMode() && brokerShutdownOnErroredChild && !failedChildren.isEmpty()) {
        throw new IllegalStateException(String.format("Broker context variable %s is set and the broker has %s children", BROKER_FAIL_STARTUP_WITH_ERRORED_CHILD, State.ERRORED));
    }
    updateAccessControl();
    _houseKeepingTaskExecutor = new HousekeepingExecutor("broker-" + getName() + "-pool", getHousekeepingThreadCount(), getSystemTaskSubject("Housekeeping", _principal));
    initialiseStatisticsReporting();
    scheduleDirectMemoryCheck();
    _assignTargetSizeSchedulingFuture = scheduleHouseKeepingTask(getHousekeepingCheckPeriod(), TimeUnit.MILLISECONDS, this::assignTargetSizes);
    final PreferenceStoreUpdaterImpl updater = new PreferenceStoreUpdaterImpl();
    final Collection<PreferenceRecord> preferenceRecords = _preferenceStore.openAndLoad(updater);
    _preferenceTaskExecutor = new TaskExecutorImpl("broker-" + getName() + "-preferences", null);
    _preferenceTaskExecutor.start();
    PreferencesRecoverer preferencesRecoverer = new PreferencesRecoverer(_preferenceTaskExecutor);
    preferencesRecoverer.recoverPreferences(this, preferenceRecords, _preferenceStore);
    if (isManagementMode()) {
        _eventLogger.message(BrokerMessages.MANAGEMENT_MODE(SystemConfig.MANAGEMENT_MODE_USER_NAME, _parent.getManagementModePassword()));
    }
    setState(State.ACTIVE);
}
Also used : HousekeepingExecutor(org.apache.qpid.server.util.HousekeepingExecutor) TaskExecutorImpl(org.apache.qpid.server.configuration.updater.TaskExecutorImpl) PreferenceRecord(org.apache.qpid.server.store.preferences.PreferenceRecord) PreferenceStoreUpdaterImpl(org.apache.qpid.server.store.preferences.PreferenceStoreUpdaterImpl) PreferencesRecoverer(org.apache.qpid.server.store.preferences.PreferencesRecoverer)

Example 14 with PreferenceRecord

use of org.apache.qpid.server.store.preferences.PreferenceRecord in project qpid-broker-j by apache.

the class UserPreferencesImpl method doReplaceByType.

private void doReplaceByType(final String type, final Collection<Preference> preferences) {
    Principal currentPrincipal = getMainPrincipalOrThrow();
    Collection<Preference> augmentedPreferences = augmentForReplace(preferences);
    validateNewPreferencesForReplaceByType(type, augmentedPreferences);
    Collection<UUID> preferenceRecordsToRemove = new HashSet<>();
    Collection<PreferenceRecord> preferenceRecordsToAdd = new HashSet<>();
    for (Preference preference : _preferences.values()) {
        if (principalsEqual(preference.getOwner(), currentPrincipal) && (type == null || Objects.equals(preference.getType(), type))) {
            preferenceRecordsToRemove.add(preference.getId());
        }
    }
    for (Preference preference : augmentedPreferences) {
        preferenceRecordsToAdd.add(PreferenceRecordImpl.fromPreference(preference));
    }
    _preferenceStore.replace(preferenceRecordsToRemove, preferenceRecordsToAdd);
    for (UUID id : preferenceRecordsToRemove) {
        Preference preference = _preferences.remove(id);
        _preferencesByName.get(preference.getName()).remove(preference);
    }
    for (Preference preference : augmentedPreferences) {
        addPreference(preference);
    }
}
Also used : PreferenceRecord(org.apache.qpid.server.store.preferences.PreferenceRecord) UUID(java.util.UUID) AuthenticatedPrincipal(org.apache.qpid.server.security.auth.AuthenticatedPrincipal) Principal(java.security.Principal) HashSet(java.util.HashSet)

Example 15 with PreferenceRecord

use of org.apache.qpid.server.store.preferences.PreferenceRecord in project qpid-broker-j by apache.

the class AbstractVirtualHost method onActivate.

@StateTransition(currentState = { State.UNINITIALIZED, State.ERRORED }, desiredState = State.ACTIVE)
private ListenableFuture<Void> onActivate() {
    long threadPoolKeepAliveTimeout = getContextValue(Long.class, CONNECTION_THREAD_POOL_KEEP_ALIVE_TIMEOUT);
    final SuppressingInheritedAccessControlContextThreadFactory connectionThreadFactory = new SuppressingInheritedAccessControlContextThreadFactory("virtualhost-" + getName() + "-iopool", getSystemTaskSubject("IO Pool", getPrincipal()));
    _networkConnectionScheduler = new NetworkConnectionScheduler("virtualhost-" + getName() + "-iopool", getNumberOfSelectors(), getConnectionThreadPoolSize(), threadPoolKeepAliveTimeout, connectionThreadFactory);
    _networkConnectionScheduler.start();
    updateAccessControl();
    initialiseStatisticsReporting();
    MessageStore messageStore = getMessageStore();
    messageStore.openMessageStore(this);
    startFileSystemSpaceChecking();
    if (!(_virtualHostNode.getConfigurationStore() instanceof MessageStoreProvider)) {
        getEventLogger().message(getMessageStoreLogSubject(), MessageStoreMessages.CREATED());
        getEventLogger().message(getMessageStoreLogSubject(), MessageStoreMessages.STORE_LOCATION(messageStore.getStoreLocation()));
    }
    messageStore.upgradeStoreStructure();
    if (_linkRegistry != null) {
        _linkRegistry.open();
    }
    getBroker().assignTargetSizes();
    final PreferenceStoreUpdater updater = new PreferenceStoreUpdaterImpl();
    Collection<PreferenceRecord> records = _preferenceStore.openAndLoad(updater);
    _preferenceTaskExecutor = new TaskExecutorImpl("virtualhost-" + getName() + "-preferences", null);
    _preferenceTaskExecutor.start();
    PreferencesRecoverer preferencesRecoverer = new PreferencesRecoverer(_preferenceTaskExecutor);
    preferencesRecoverer.recoverPreferences(this, records, _preferenceStore);
    if (_createDefaultExchanges) {
        return doAfter(createDefaultExchanges(), new Runnable() {

            @Override
            public void run() {
                _createDefaultExchanges = false;
                postCreateDefaultExchangeTasks();
            }
        });
    } else {
        postCreateDefaultExchangeTasks();
        return Futures.immediateFuture(null);
    }
}
Also used : MessageStore(org.apache.qpid.server.store.MessageStore) PreferenceStoreUpdater(org.apache.qpid.server.store.preferences.PreferenceStoreUpdater) TaskExecutorImpl(org.apache.qpid.server.configuration.updater.TaskExecutorImpl) PreferenceRecord(org.apache.qpid.server.store.preferences.PreferenceRecord) SuppressingInheritedAccessControlContextThreadFactory(org.apache.qpid.server.pool.SuppressingInheritedAccessControlContextThreadFactory) MessageStoreProvider(org.apache.qpid.server.store.MessageStoreProvider) PreferenceStoreUpdaterImpl(org.apache.qpid.server.store.preferences.PreferenceStoreUpdaterImpl) PreferencesRecoverer(org.apache.qpid.server.store.preferences.PreferencesRecoverer) NetworkConnectionScheduler(org.apache.qpid.server.transport.NetworkConnectionScheduler)

Aggregations

PreferenceRecord (org.apache.qpid.server.store.preferences.PreferenceRecord)16 PreferenceRecordImpl (org.apache.qpid.server.store.preferences.PreferenceRecordImpl)6 UUID (java.util.UUID)5 PreparedStatement (java.sql.PreparedStatement)4 ResultSet (java.sql.ResultSet)4 ArrayList (java.util.ArrayList)4 LinkedHashSet (java.util.LinkedHashSet)4 StoreException (org.apache.qpid.server.store.StoreException)4 DatabaseEntry (com.sleepycat.je.DatabaseEntry)3 HashSet (java.util.HashSet)3 ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)3 MapBinding (org.apache.qpid.server.store.berkeleydb.tuple.MapBinding)3 UUIDTupleBinding (org.apache.qpid.server.store.berkeleydb.tuple.UUIDTupleBinding)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Database (com.sleepycat.je.Database)2 TaskExecutorImpl (org.apache.qpid.server.configuration.updater.TaskExecutorImpl)2 ModelVersion (org.apache.qpid.server.model.ModelVersion)2 PreferenceStoreUpdaterImpl (org.apache.qpid.server.store.preferences.PreferenceStoreUpdaterImpl)2 PreferencesRecoverer (org.apache.qpid.server.store.preferences.PreferencesRecoverer)2 Cursor (com.sleepycat.je.Cursor)1