Search in sources :

Example 6 with ConfiguredObjectRecord

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);
    }
}
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 7 with ConfiguredObjectRecord

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;
}
Also used : ConfiguredObjectRecordImpl(org.apache.qpid.server.store.ConfiguredObjectRecordImpl) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) ConfiguredObjectRecord(org.apache.qpid.server.store.ConfiguredObjectRecord) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Example 8 with ConfiguredObjectRecord

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())));
    }
}
Also used : ConfiguredObjectRecordImpl(org.apache.qpid.server.store.ConfiguredObjectRecordImpl) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ManagedObject(org.apache.qpid.server.model.ManagedObject) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) AbstractConfiguredObject(org.apache.qpid.server.model.AbstractConfiguredObject) ConfiguredObjectRecord(org.apache.qpid.server.store.ConfiguredObjectRecord) VirtualHost(org.apache.qpid.server.model.VirtualHost) NonStandardVirtualHost(org.apache.qpid.server.virtualhost.NonStandardVirtualHost)

Example 9 with ConfiguredObjectRecord

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()]);
}
Also used : ConfiguredObjectRecordConverter(org.apache.qpid.server.store.ConfiguredObjectRecordConverter) ArrayList(java.util.ArrayList) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) ConfiguredObjectRecord(org.apache.qpid.server.store.ConfiguredObjectRecord) VirtualHost(org.apache.qpid.server.model.VirtualHost) NonStandardVirtualHost(org.apache.qpid.server.virtualhost.NonStandardVirtualHost)

Example 10 with ConfiguredObjectRecord

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));
}
Also used : ConfiguredObjectRecordImpl(org.apache.qpid.server.store.ConfiguredObjectRecordImpl) Broker(org.apache.qpid.server.model.Broker) HashMap(java.util.HashMap) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) ConfiguredObjectRecord(org.apache.qpid.server.store.ConfiguredObjectRecord)

Aggregations

ConfiguredObjectRecord (org.apache.qpid.server.store.ConfiguredObjectRecord)58 HashMap (java.util.HashMap)27 ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)25 UUID (java.util.UUID)24 ConfiguredObjectRecordImpl (org.apache.qpid.server.store.ConfiguredObjectRecordImpl)14 IllegalConfigurationException (org.apache.qpid.server.configuration.IllegalConfigurationException)13 ArrayList (java.util.ArrayList)12 ConfiguredObjectRecordHandler (org.apache.qpid.server.store.handler.ConfiguredObjectRecordHandler)8 LinkedHashMap (java.util.LinkedHashMap)6 IOException (java.io.IOException)5 Transaction (com.sleepycat.je.Transaction)4 Map (java.util.Map)4 DurableConfigurationStore (org.apache.qpid.server.store.DurableConfigurationStore)4 StoreException (org.apache.qpid.server.store.StoreException)4 Mockito.doAnswer (org.mockito.Mockito.doAnswer)4 InvocationOnMock (org.mockito.invocation.InvocationOnMock)4 Answer (org.mockito.stubbing.Answer)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 Connection (java.sql.Connection)3 SQLException (java.sql.SQLException)3