Search in sources :

Example 1 with ConfiguredObjectRecordHandler

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;
}
Also used : ArrayList(java.util.ArrayList) VirtualHost(org.apache.qpid.server.model.VirtualHost) ConfiguredObjectRecordHandler(org.apache.qpid.server.store.handler.ConfiguredObjectRecordHandler)

Example 2 with ConfiguredObjectRecordHandler

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());
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ConfiguredObjectRecord(org.apache.qpid.server.store.ConfiguredObjectRecord) ConfiguredObjectRecordHandler(org.apache.qpid.server.store.handler.ConfiguredObjectRecordHandler)

Example 3 with ConfiguredObjectRecordHandler

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);
}
Also used : HashMap(java.util.HashMap) Answer(org.mockito.stubbing.Answer) Mockito.doAnswer(org.mockito.Mockito.doAnswer) ConfiguredObjectRecordImpl(org.apache.qpid.server.store.ConfiguredObjectRecordImpl) InvocationOnMock(org.mockito.invocation.InvocationOnMock) State(org.apache.qpid.server.model.State) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) ConfiguredObjectRecord(org.apache.qpid.server.store.ConfiguredObjectRecord) VirtualHost(org.apache.qpid.server.model.VirtualHost) UUID(java.util.UUID) ConfiguredObjectRecordHandler(org.apache.qpid.server.store.handler.ConfiguredObjectRecordHandler)

Example 4 with ConfiguredObjectRecordHandler

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;
}
Also used : ArrayList(java.util.ArrayList) ConfiguredObjectRecord(org.apache.qpid.server.store.ConfiguredObjectRecord) ConfiguredObjectRecordHandler(org.apache.qpid.server.store.handler.ConfiguredObjectRecordHandler)

Example 5 with ConfiguredObjectRecordHandler

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);
}
Also used : DurableConfigurationStore(org.apache.qpid.server.store.DurableConfigurationStore) QpidServiceLoader(org.apache.qpid.server.plugin.QpidServiceLoader) ArrayList(java.util.ArrayList) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) ConfiguredObjectRecord(org.apache.qpid.server.store.ConfiguredObjectRecord) ConfiguredObjectRecordHandler(org.apache.qpid.server.store.handler.ConfiguredObjectRecordHandler)

Aggregations

ConfiguredObjectRecordHandler (org.apache.qpid.server.store.handler.ConfiguredObjectRecordHandler)11 ConfiguredObjectRecord (org.apache.qpid.server.store.ConfiguredObjectRecord)8 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)5 ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)4 Mockito.doAnswer (org.mockito.Mockito.doAnswer)4 InvocationOnMock (org.mockito.invocation.InvocationOnMock)4 Answer (org.mockito.stubbing.Answer)4 UUID (java.util.UUID)2 IllegalConfigurationException (org.apache.qpid.server.configuration.IllegalConfigurationException)2 VirtualHost (org.apache.qpid.server.model.VirtualHost)2 ConfiguredObjectRecordImpl (org.apache.qpid.server.store.ConfiguredObjectRecordImpl)2 DurableConfigurationStore (org.apache.qpid.server.store.DurableConfigurationStore)2 Matchers.anyString (org.mockito.Matchers.anyString)2 BufferedInputStream (java.io.BufferedInputStream)1 DataInputStream (java.io.DataInputStream)1 File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 URL (java.net.URL)1