Search in sources :

Example 1 with VirtualHostStoreUpgraderAndRecoverer

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

the class AbstractStandardVirtualHostNode method activate.

@Override
protected ListenableFuture<Void> activate() {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Activating virtualhost node " + this);
    }
    getConfigurationStore().init(this);
    getConfigurationStore().upgradeStoreStructure();
    getEventLogger().message(getConfigurationStoreLogSubject(), ConfigStoreMessages.CREATED());
    writeLocationEventLog();
    getEventLogger().message(getConfigurationStoreLogSubject(), ConfigStoreMessages.RECOVERY_START());
    VirtualHostStoreUpgraderAndRecoverer upgrader = new VirtualHostStoreUpgraderAndRecoverer(this);
    ConfiguredObjectRecord[] initialRecords = null;
    try {
        initialRecords = getInitialRecords();
    } catch (IOException e) {
        throw new IllegalConfigurationException("Could not process initial configuration", e);
    }
    final boolean isNew = upgrader.upgradeAndRecover(getConfigurationStore(), initialRecords);
    if (initialRecords.length > 0) {
        setAttributes(Collections.<String, Object>singletonMap(VIRTUALHOST_INITIAL_CONFIGURATION, "{}"));
    }
    getEventLogger().message(getConfigurationStoreLogSubject(), ConfigStoreMessages.RECOVERY_COMPLETE());
    QueueManagingVirtualHost<?> host = getVirtualHost();
    if (host != null) {
        final QueueManagingVirtualHost<?> recoveredHost = host;
        final ListenableFuture<Void> openFuture;
        recoveredHost.setFirstOpening(isNew && initialRecords.length == 0);
        openFuture = Subject.doAs(getSubjectWithAddedSystemRights(), new PrivilegedAction<ListenableFuture<Void>>() {

            @Override
            public ListenableFuture<Void> run() {
                return recoveredHost.openAsync();
            }
        });
        return openFuture;
    } else {
        return Futures.immediateFuture(null);
    }
}
Also used : VirtualHostStoreUpgraderAndRecoverer(org.apache.qpid.server.store.VirtualHostStoreUpgraderAndRecoverer) PrivilegedAction(java.security.PrivilegedAction) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) ConfiguredObjectRecord(org.apache.qpid.server.store.ConfiguredObjectRecord) IOException(java.io.IOException)

Example 2 with VirtualHostStoreUpgraderAndRecoverer

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

the class BDBHAVirtualHostNodeImpl method onMaster.

private void onMaster() {
    boolean success = false;
    try {
        boolean firstOpening = false;
        closeVirtualHostIfExist().get();
        getEventLogger().message(getConfigurationStoreLogSubject(), ConfigStoreMessages.RECOVERY_START());
        VirtualHostStoreUpgraderAndRecoverer upgraderAndRecoverer = new VirtualHostStoreUpgraderAndRecoverer(this);
        if (getConfigurationStore().isOpen()) {
            upgraderAndRecoverer.reloadAndRecover(getConfigurationStore());
        } else {
            getConfigurationStore().upgradeStoreStructure();
            ConfiguredObjectRecord[] initialRecords = getInitialRecords();
            if (upgraderAndRecoverer.upgradeAndRecover(getConfigurationStore(), initialRecords)) {
                setAttributes(Collections.<String, Object>singletonMap(VIRTUALHOST_INITIAL_CONFIGURATION, "{}"));
                firstOpening = initialRecords.length == 0;
            }
        }
        getEventLogger().message(getConfigurationStoreLogSubject(), ConfigStoreMessages.RECOVERY_COMPLETE());
        VirtualHost<?> host = getVirtualHost();
        if (host == null) {
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("Creating new virtualhost with name : " + getGroupName());
            }
            Map<String, Object> hostAttributes = new HashMap<>();
            hostAttributes.put(VirtualHost.MODEL_VERSION, BrokerModel.MODEL_VERSION);
            hostAttributes.put(VirtualHost.NAME, getGroupName());
            hostAttributes.put(VirtualHost.TYPE, BDBHAVirtualHostImpl.VIRTUAL_HOST_TYPE);
            createChild(VirtualHost.class, hostAttributes);
        } else {
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("Recovered virtualhost with name : " + getGroupName());
            }
            final VirtualHost<?> recoveredHost = host;
            // so the following test should always return true
            if (recoveredHost instanceof QueueManagingVirtualHost) {
                ((QueueManagingVirtualHost<?>) recoveredHost).setFirstOpening(firstOpening);
            }
            Subject.doAs(getSubjectWithAddedSystemRights(), new PrivilegedAction<Object>() {

                @Override
                public Object run() {
                    recoveredHost.open();
                    return null;
                }
            });
        }
        success = true;
    } catch (Exception e) {
        LOGGER.error("Failed to activate on hearing MASTER change event", e);
    } finally {
        setState(success ? State.ACTIVE : State.ERRORED);
    }
}
Also used : QueueManagingVirtualHost(org.apache.qpid.server.virtualhost.QueueManagingVirtualHost) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) URISyntaxException(java.net.URISyntaxException) TimeoutException(java.util.concurrent.TimeoutException) LogWriteException(com.sleepycat.je.LogWriteException) DatabaseException(com.sleepycat.je.DatabaseException) StoreException(org.apache.qpid.server.store.StoreException) ConnectionScopedRuntimeException(org.apache.qpid.server.util.ConnectionScopedRuntimeException) ServerScopedRuntimeException(org.apache.qpid.server.util.ServerScopedRuntimeException) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) ExecutionException(java.util.concurrent.ExecutionException) VirtualHostStoreUpgraderAndRecoverer(org.apache.qpid.server.store.VirtualHostStoreUpgraderAndRecoverer) ManagedObject(org.apache.qpid.server.model.ManagedObject) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) ConfiguredObjectRecord(org.apache.qpid.server.store.ConfiguredObjectRecord)

Example 3 with VirtualHostStoreUpgraderAndRecoverer

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

the class AbstractVirtualHost method onRestart.

@StateTransition(currentState = { State.STOPPED }, desiredState = State.ACTIVE)
private ListenableFuture<Void> onRestart() {
    createHousekeepingExecutor();
    final VirtualHostStoreUpgraderAndRecoverer virtualHostStoreUpgraderAndRecoverer = new VirtualHostStoreUpgraderAndRecoverer((VirtualHostNode<?>) getParent());
    virtualHostStoreUpgraderAndRecoverer.reloadAndRecoverVirtualHost(getDurableConfigurationStore());
    final Collection<VirtualHostAccessControlProvider> accessControlProviders = getChildren(VirtualHostAccessControlProvider.class);
    if (!accessControlProviders.isEmpty()) {
        accessControlProviders.forEach(child -> child.addChangeListener(_accessControlProviderListener));
    }
    final List<ListenableFuture<Void>> childOpenFutures = new ArrayList<>();
    Subject.doAs(getSubjectWithAddedSystemRights(), (PrivilegedAction<Object>) () -> {
        applyToChildren(child -> {
            final ListenableFuture<Void> childOpenFuture = child.openAsync();
            childOpenFutures.add(childOpenFuture);
            addFutureCallback(childOpenFuture, new FutureCallback<Void>() {

                @Override
                public void onSuccess(final Void result) {
                }

                @Override
                public void onFailure(final Throwable t) {
                    LOGGER.error("Exception occurred while opening {} : {}", child.getClass().getSimpleName(), child.getName(), t);
                }
            }, getTaskExecutor());
        });
        return null;
    });
    ListenableFuture<List<Void>> combinedFuture = Futures.allAsList(childOpenFutures);
    return Futures.transformAsync(combinedFuture, input -> onActivate(), MoreExecutors.directExecutor());
}
Also used : AccessControlContext(java.security.AccessControlContext) Arrays(java.util.Arrays) BufferedInputStream(java.io.BufferedInputStream) MessageStoreSerializer(org.apache.qpid.server.store.serializer.MessageStoreSerializer) Future(java.util.concurrent.Future) NetworkConnectionScheduler(org.apache.qpid.server.transport.NetworkConnectionScheduler) Map(java.util.Map) QueueEntryIterator(org.apache.qpid.server.queue.QueueEntryIterator) UserPreferences(org.apache.qpid.server.model.preferences.UserPreferences) EnumSet(java.util.EnumSet) AutoCommitTransaction(org.apache.qpid.server.txn.AutoCommitTransaction) Set(java.util.Set) AMQPConnection(org.apache.qpid.server.transport.AMQPConnection) InstanceProperties(org.apache.qpid.server.message.InstanceProperties) Iterators.cycle(com.google.common.collect.Iterators.cycle) StandardCharsets(java.nio.charset.StandardCharsets) HousekeepingExecutor(org.apache.qpid.server.util.HousekeepingExecutor) Serializable(java.io.Serializable) MessageStoreMessages(org.apache.qpid.server.logging.messages.MessageStoreMessages) Operation(org.apache.qpid.server.security.access.Operation) PreferenceRecord(org.apache.qpid.server.store.preferences.PreferenceRecord) QpidServiceLoader(org.apache.qpid.server.plugin.QpidServiceLoader) CompoundAccessControl(org.apache.qpid.server.security.CompoundAccessControl) TaskExecutor(org.apache.qpid.server.configuration.updater.TaskExecutor) PreferencesRoot(org.apache.qpid.server.store.preferences.PreferencesRoot) Callable(java.util.concurrent.Callable) ServerMessage(org.apache.qpid.server.message.ServerMessage) ArrayList(java.util.ArrayList) ResultCalculator(org.apache.qpid.server.security.SubjectFixedResultAccessControl.ResultCalculator) PreferenceStoreUpdaterImpl(org.apache.qpid.server.store.preferences.PreferenceStoreUpdaterImpl) UserPreferencesImpl(org.apache.qpid.server.model.preferences.UserPreferencesImpl) QueueEntry(org.apache.qpid.server.queue.QueueEntry) MessageHandler(org.apache.qpid.server.store.handler.MessageHandler) SubjectFixedResultAccessControl(org.apache.qpid.server.security.SubjectFixedResultAccessControl) PreferenceStore(org.apache.qpid.server.store.preferences.PreferenceStore) StoredMessage(org.apache.qpid.server.store.StoredMessage) MessageDeletedException(org.apache.qpid.server.message.MessageDeletedException) DtxRegistry(org.apache.qpid.server.txn.DtxRegistry) MessageInstanceHandler(org.apache.qpid.server.store.handler.MessageInstanceHandler) IOException(java.io.IOException) PreferencesRecoverer(org.apache.qpid.server.store.preferences.PreferencesRecoverer) File(java.io.File) FutureCallback(com.google.common.util.concurrent.FutureCallback) DurableConfigurationStore(org.apache.qpid.server.store.DurableConfigurationStore) Strings(org.apache.qpid.server.util.Strings) AtomicLong(java.util.concurrent.atomic.AtomicLong) Futures(com.google.common.util.concurrent.Futures) Result(org.apache.qpid.server.security.Result) SuppressingInheritedAccessControlContextThreadFactory(org.apache.qpid.server.pool.SuppressingInheritedAccessControlContextThreadFactory) ScheduledFuture(java.util.concurrent.ScheduledFuture) MessageReference(org.apache.qpid.server.message.MessageReference) URL(java.net.URL) Date(java.util.Date) DistributedTransactionHandler(org.apache.qpid.server.store.handler.DistributedTransactionHandler) LoggerFactory(org.slf4j.LoggerFactory) DefaultDestination(org.apache.qpid.server.exchange.DefaultDestination) TaskExecutorImpl(org.apache.qpid.server.configuration.updater.TaskExecutorImpl) SettableFuture(com.google.common.util.concurrent.SettableFuture) MessageStore(org.apache.qpid.server.store.MessageStore) ExchangeDefaults(org.apache.qpid.server.exchange.ExchangeDefaults) AmqpPort(org.apache.qpid.server.model.port.AmqpPort) StoreException(org.apache.qpid.server.store.StoreException) MessageEnqueueRecord(org.apache.qpid.server.store.MessageEnqueueRecord) PatternSyntaxException(java.util.regex.PatternSyntaxException) LocalTransaction(org.apache.qpid.server.txn.LocalTransaction) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) org.apache.qpid.server.model(org.apache.qpid.server.model) LinkModel(org.apache.qpid.server.protocol.LinkModel) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) UUID(java.util.UUID) PrivilegedAction(java.security.PrivilegedAction) RoutingResult(org.apache.qpid.server.message.RoutingResult) ConnectionValidator(org.apache.qpid.server.plugin.ConnectionValidator) MessageStoreLogSubject(org.apache.qpid.server.logging.subjects.MessageStoreLogSubject) List(java.util.List) Principal(java.security.Principal) AMQMessageHeader(org.apache.qpid.server.message.AMQMessageHeader) MessageDestination(org.apache.qpid.server.message.MessageDestination) MessageSource(org.apache.qpid.server.message.MessageSource) Pattern(java.util.regex.Pattern) UnsupportedEncodingException(java.io.UnsupportedEncodingException) DataInputStream(java.io.DataInputStream) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) InternalMessage(org.apache.qpid.server.message.internal.InternalMessage) AccessControl(org.apache.qpid.server.security.AccessControl) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) JdkFutureAdapters(com.google.common.util.concurrent.JdkFutureAdapters) EventLogger(org.apache.qpid.server.logging.EventLogger) HashSet(java.util.HashSet) Collections.newSetFromMap(java.util.Collections.newSetFromMap) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) Preference(org.apache.qpid.server.model.preferences.Preference) AuthenticatedPrincipal(org.apache.qpid.server.security.auth.AuthenticatedPrincipal) SystemNodeCreator(org.apache.qpid.server.plugin.SystemNodeCreator) ConfiguredObjectRecord(org.apache.qpid.server.store.ConfiguredObjectRecord) Task(org.apache.qpid.server.configuration.updater.Task) OutputStream(java.io.OutputStream) PreferenceStoreUpdater(org.apache.qpid.server.store.preferences.PreferenceStoreUpdater) ServerTransaction(org.apache.qpid.server.txn.ServerTransaction) Logger(org.slf4j.Logger) VirtualHostMessages(org.apache.qpid.server.logging.messages.VirtualHostMessages) Iterator(java.util.Iterator) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) SocketConnectionMetaData(org.apache.qpid.server.security.auth.SocketConnectionMetaData) MalformedURLException(java.net.MalformedURLException) Subject(javax.security.auth.Subject) TimeUnit(java.util.concurrent.TimeUnit) ConfiguredObjectRecordHandler(org.apache.qpid.server.store.handler.ConfiguredObjectRecordHandler) VirtualHostStoreUpgraderAndRecoverer(org.apache.qpid.server.store.VirtualHostStoreUpgraderAndRecoverer) URLEncoder(java.net.URLEncoder) Event(org.apache.qpid.server.store.Event) MessageStoreProvider(org.apache.qpid.server.store.MessageStoreProvider) MessageNode(org.apache.qpid.server.message.MessageNode) Collections(java.util.Collections) StatisticsReportingTask(org.apache.qpid.server.stats.StatisticsReportingTask) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) VirtualHostStoreUpgraderAndRecoverer(org.apache.qpid.server.store.VirtualHostStoreUpgraderAndRecoverer) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) ArrayList(java.util.ArrayList) List(java.util.List) FutureCallback(com.google.common.util.concurrent.FutureCallback)

Aggregations

IOException (java.io.IOException)2 PrivilegedAction (java.security.PrivilegedAction)2 HashMap (java.util.HashMap)2 IllegalConfigurationException (org.apache.qpid.server.configuration.IllegalConfigurationException)2 ConfiguredObjectRecord (org.apache.qpid.server.store.ConfiguredObjectRecord)2 VirtualHostStoreUpgraderAndRecoverer (org.apache.qpid.server.store.VirtualHostStoreUpgraderAndRecoverer)2 Iterators.cycle (com.google.common.collect.Iterators.cycle)1 FutureCallback (com.google.common.util.concurrent.FutureCallback)1 Futures (com.google.common.util.concurrent.Futures)1 JdkFutureAdapters (com.google.common.util.concurrent.JdkFutureAdapters)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 MoreExecutors (com.google.common.util.concurrent.MoreExecutors)1 SettableFuture (com.google.common.util.concurrent.SettableFuture)1 DatabaseException (com.sleepycat.je.DatabaseException)1 LogWriteException (com.sleepycat.je.LogWriteException)1 BufferedInputStream (java.io.BufferedInputStream)1 DataInputStream (java.io.DataInputStream)1 File (java.io.File)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1