use of org.apache.qpid.server.store.handler.ConfiguredObjectRecordHandler in project qpid-broker-j by apache.
the class VirtualHostStoreUpgraderAndRecoverer method upgradeAndRecover.
public boolean upgradeAndRecover(final DurableConfigurationStore durableConfigurationStore, final ConfiguredObjectRecord... initialRecords) {
final List<ConfiguredObjectRecord> records = new ArrayList<>();
boolean isNew = durableConfigurationStore.openConfigurationStore(new ConfiguredObjectRecordHandler() {
@Override
public void handle(final ConfiguredObjectRecord record) {
records.add(record);
}
}, initialRecords);
List<ConfiguredObjectRecord> upgradedRecords = upgrade(durableConfigurationStore, records, VirtualHost.class.getSimpleName(), VirtualHost.MODEL_VERSION);
recover(_virtualHostNode, durableConfigurationStore, upgradedRecords, isNew);
return isNew;
}
use of org.apache.qpid.server.store.handler.ConfiguredObjectRecordHandler in project qpid-broker-j by apache.
the class VirtualHostTest method testRestartingVirtualHostRecoversChildren.
public void testRestartingVirtualHostRecoversChildren() {
String virtualHostName = getName();
VirtualHost<?> virtualHost = createVirtualHost(virtualHostName);
assertEquals("Unexpected state", State.ACTIVE, virtualHost.getState());
final ConfiguredObjectRecord virtualHostCor = virtualHost.asObjectRecord();
// Give virtualhost a queue and an exchange
Queue queue = virtualHost.createChild(Queue.class, Collections.singletonMap(Queue.NAME, "myQueue"));
final ConfiguredObjectRecord queueCor = queue.asObjectRecord();
Map<String, Object> exchangeArgs = new HashMap<>();
exchangeArgs.put(Exchange.NAME, "myExchange");
exchangeArgs.put(Exchange.TYPE, ExchangeDefaults.DIRECT_EXCHANGE_CLASS);
Exchange exchange = virtualHost.createChild(Exchange.class, exchangeArgs);
final ConfiguredObjectRecord exchangeCor = exchange.asObjectRecord();
assertEquals("Unexpected number of queues before stop", 1, virtualHost.getChildren(Queue.class).size());
assertEquals("Unexpected number of exchanges before stop", 5, virtualHost.getChildren(Exchange.class).size());
final List<ConfiguredObjectRecord> allObjects = new ArrayList<>();
allObjects.add(virtualHostCor);
allObjects.add(queueCor);
for (Exchange e : virtualHost.getChildren(Exchange.class)) {
allObjects.add(e.asObjectRecord());
}
((AbstractConfiguredObject<?>) virtualHost).stop();
assertEquals("Unexpected state", State.STOPPED, virtualHost.getState());
assertEquals("Unexpected number of queues after stop", 0, virtualHost.getChildren(Queue.class).size());
assertEquals("Unexpected number of exchanges after stop", 0, virtualHost.getChildren(Exchange.class).size());
// Setup an answer that will return the configured object records
doAnswer(new Answer() {
final Iterator<ConfiguredObjectRecord> corIterator = allObjects.iterator();
@Override
public Object answer(final InvocationOnMock invocation) {
ConfiguredObjectRecordHandler handler = (ConfiguredObjectRecordHandler) invocation.getArguments()[0];
boolean handlerContinue = true;
while (corIterator.hasNext()) {
handler.handle(corIterator.next());
}
return null;
}
}).when(_configStore).reload(any(ConfiguredObjectRecordHandler.class));
((AbstractConfiguredObject<?>) virtualHost).start();
assertEquals("Unexpected state", State.ACTIVE, virtualHost.getState());
assertEquals("Unexpected number of queues after restart", 1, virtualHost.getChildren(Queue.class).size());
assertEquals("Unexpected number of exchanges after restart", 5, virtualHost.getChildren(Exchange.class).size());
}
use of org.apache.qpid.server.store.handler.ConfiguredObjectRecordHandler in project qpid-broker-j by apache.
the class ManagementModeStoreHandlerTest method virtualHostEntryQuiescedStatusTestImpl.
private void virtualHostEntryQuiescedStatusTestImpl(boolean mmQuiesceVhosts) {
UUID virtualHostId = UUID.randomUUID();
Map<String, Object> attributes = new HashMap<String, Object>();
attributes.put(VirtualHost.TYPE, "STANDARD");
final ConfiguredObjectRecord virtualHost = new ConfiguredObjectRecordImpl(virtualHostId, VirtualHost.class.getSimpleName(), attributes, Collections.singletonMap(Broker.class.getSimpleName(), _root.getId()));
final ArgumentCaptor<ConfiguredObjectRecordHandler> recovererArgumentCaptor = ArgumentCaptor.forClass(ConfiguredObjectRecordHandler.class);
doAnswer(new Answer() {
@Override
public Object answer(final InvocationOnMock invocation) throws Throwable {
ConfiguredObjectRecordHandler recoverer = recovererArgumentCaptor.getValue();
recoverer.handle(_root);
recoverer.handle(_portEntry);
recoverer.handle(virtualHost);
return false;
}
}).when(_store).openConfigurationStore(recovererArgumentCaptor.capture());
State expectedState = mmQuiesceVhosts ? State.QUIESCED : null;
if (mmQuiesceVhosts) {
_systemConfigAttributes.put(SystemConfig.MANAGEMENT_MODE_QUIESCE_VIRTUAL_HOSTS, mmQuiesceVhosts);
}
_handler = createManagementModeStoreHandler();
_handler.init(_systemConfig);
Collection<ConfiguredObjectRecord> records = openAndGetRecords();
ConfiguredObjectRecord hostEntry = getEntry(records, virtualHostId);
Map<String, Object> hostAttributes = new HashMap<String, Object>(hostEntry.getAttributes());
assertEquals("Unexpected state", expectedState, hostAttributes.get(VirtualHost.STATE));
hostAttributes.remove(VirtualHost.STATE);
assertEquals("Unexpected attributes", attributes, hostAttributes);
}
use of org.apache.qpid.server.store.handler.ConfiguredObjectRecordHandler in project qpid-broker-j by apache.
the class ManagementModeStoreHandlerTest method openAndGetRecords.
private Collection<ConfiguredObjectRecord> openAndGetRecords() {
final Collection<ConfiguredObjectRecord> records = new ArrayList<>();
_handler.openConfigurationStore(new ConfiguredObjectRecordHandler() {
@Override
public void handle(final ConfiguredObjectRecord record) {
records.add(record);
}
});
return records;
}
use of org.apache.qpid.server.store.handler.ConfiguredObjectRecordHandler in project qpid-broker-j by apache.
the class AbstractSystemConfig method initiateStoreAndRecovery.
private Container<?> initiateStoreAndRecovery() throws IOException {
ConfiguredObjectRecord[] initialRecords = convertToConfigurationRecords(getInitialConfigurationLocation());
final DurableConfigurationStore store = getConfigurationStore();
store.init(AbstractSystemConfig.this);
store.upgradeStoreStructure();
final List<ConfiguredObjectRecord> records = new ArrayList<>();
boolean isNew = store.openConfigurationStore(new ConfiguredObjectRecordHandler() {
@Override
public void handle(final ConfiguredObjectRecord record) {
records.add(record);
}
}, initialRecords);
String containerTypeName = getDefaultContainerType();
for (ConfiguredObjectRecord record : records) {
if (record.getParents() != null && record.getParents().size() == 1 && getId().equals(record.getParents().get(SystemConfig.class.getSimpleName()))) {
containerTypeName = record.getType();
break;
}
}
QpidServiceLoader loader = new QpidServiceLoader();
final ContainerType<?> containerType = loader.getInstancesByType(ContainerType.class).get(containerTypeName);
if (containerType != null) {
if (containerType.getModel() != getModel()) {
updateModel(containerType.getModel());
}
containerType.getRecoverer(this).upgradeAndRecover(records);
} else {
throw new IllegalConfigurationException("Unknown container type '" + containerTypeName + "'");
}
final Class categoryClass = containerType.getCategoryClass();
return (Container<?>) getContainer(categoryClass);
}
Aggregations