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