use of org.apache.qpid.server.store.ConfiguredObjectRecord 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.ConfiguredObjectRecord in project qpid-broker-j by apache.
the class AbstractStandardVirtualHostNode method enrichInitialVirtualHostRootRecord.
@Override
protected ConfiguredObjectRecord enrichInitialVirtualHostRootRecord(final ConfiguredObjectRecord vhostRecord) {
ConfiguredObjectRecord replacementRecord;
if (vhostRecord.getAttributes().get(ConfiguredObject.NAME) == null) {
Map<String, Object> updatedAttributes = new LinkedHashMap<>(vhostRecord.getAttributes());
updatedAttributes.put(ConfiguredObject.NAME, getName());
if (!updatedAttributes.containsKey(VirtualHost.MODEL_VERSION)) {
updatedAttributes.put(VirtualHost.MODEL_VERSION, getBroker().getModelVersion());
}
replacementRecord = new ConfiguredObjectRecordImpl(vhostRecord.getId(), vhostRecord.getType(), updatedAttributes, vhostRecord.getParents());
} else if (vhostRecord.getAttributes().get(VirtualHost.MODEL_VERSION) == null) {
Map<String, Object> updatedAttributes = new LinkedHashMap<>(vhostRecord.getAttributes());
updatedAttributes.put(VirtualHost.MODEL_VERSION, getBroker().getModelVersion());
replacementRecord = new ConfiguredObjectRecordImpl(vhostRecord.getId(), vhostRecord.getType(), updatedAttributes, vhostRecord.getParents());
} else {
replacementRecord = vhostRecord;
}
return replacementRecord;
}
use of org.apache.qpid.server.store.ConfiguredObjectRecord in project qpid-broker-j by apache.
the class AbstractVirtualHostNode method addExchangeIfNecessary.
private void addExchangeIfNecessary(final String exchangeClass, final String exchangeName, final Collection<ConfiguredObjectRecord> records, final ConfiguredObjectRecord vhostRecord) {
boolean found = false;
for (ConfiguredObjectRecord record : records) {
if (Exchange.class.getSimpleName().equals(record.getType()) && exchangeName.equals(record.getAttributes().get(ConfiguredObject.NAME))) {
found = true;
break;
}
}
if (!found) {
final Map<String, Object> exchangeAttributes = new HashMap<>();
exchangeAttributes.put(ConfiguredObject.NAME, exchangeName);
exchangeAttributes.put(ConfiguredObject.TYPE, exchangeClass);
records.add(new ConfiguredObjectRecordImpl(UUID.randomUUID(), Exchange.class.getSimpleName(), exchangeAttributes, Collections.singletonMap(VirtualHost.class.getSimpleName(), vhostRecord.getId())));
}
}
use of org.apache.qpid.server.store.ConfiguredObjectRecord in project qpid-broker-j by apache.
the class AbstractVirtualHostNode method getInitialRecords.
protected final ConfiguredObjectRecord[] getInitialRecords() throws IOException {
ConfiguredObjectRecordConverter converter = new ConfiguredObjectRecordConverter(getModel());
Collection<ConfiguredObjectRecord> records = new ArrayList<>(converter.readFromJson(VirtualHost.class, this, getInitialConfigReader()));
if (!records.isEmpty()) {
ConfiguredObjectRecord vhostRecord = null;
for (ConfiguredObjectRecord record : records) {
if (record.getType().equals(VirtualHost.class.getSimpleName())) {
vhostRecord = record;
break;
}
}
if (vhostRecord != null) {
records.remove(vhostRecord);
vhostRecord = enrichInitialVirtualHostRootRecord(vhostRecord);
records.add(vhostRecord);
} else {
// this should be impossible as the converter should always generate a parent record
throw new IllegalConfigurationException("Somehow the initial configuration has records but " + "not a VirtualHost. This must be a coding error in Qpid");
}
addStandardExchangesIfNecessary(records, vhostRecord);
enrichWithAuditInformation(records);
}
return records.toArray(new ConfiguredObjectRecord[records.size()]);
}
use of org.apache.qpid.server.store.ConfiguredObjectRecord in project qpid-broker-j by apache.
the class ManagementModeStoreHandlerTest method testSaveRoot.
public void testSaveRoot() {
_systemConfigAttributes.put(SystemConfig.MANAGEMENT_MODE_HTTP_PORT_OVERRIDE, 1000);
_handler = createManagementModeStoreHandler();
_handler.init(_systemConfig);
Collection<ConfiguredObjectRecord> records = openAndGetRecords();
ConfiguredObjectRecord root = getRootEntry(records);
Map<String, Object> attributes = new HashMap<String, Object>();
attributes.put(Broker.NAME, "TEST");
ConfiguredObjectRecord configurationEntry = new ConfiguredObjectRecordImpl(_rootId, Broker.class.getSimpleName(), attributes, root.getParents());
_handler.update(false, configurationEntry);
verify(_store).update(anyBoolean(), any(ConfiguredObjectRecord.class));
}
Aggregations