Search in sources :

Example 36 with ConfiguredObject

use of org.apache.qpid.server.model.ConfiguredObject in project qpid-broker-j by apache.

the class StoreConfigurationChangeListener method childAdded.

@Override
public void childAdded(ConfiguredObject<?> object, ConfiguredObject<?> child) {
    if (!object.managesChildStorage()) {
        if (object.isDurable() && child.isDurable()) {
            Model model = child.getModel();
            Class<? extends ConfiguredObject> parentType = model.getParentType(child.getCategoryClass());
            if (parentType.equals(object.getCategoryClass())) {
                child.addChangeListener(this);
                _store.update(true, child.asObjectRecord());
                Class<? extends ConfiguredObject> categoryClass = child.getCategoryClass();
                Collection<Class<? extends ConfiguredObject>> childTypes = model.getChildTypes(categoryClass);
                for (Class<? extends ConfiguredObject> childClass : childTypes) {
                    for (ConfiguredObject<?> grandchild : child.getChildren(childClass)) {
                        childAdded(child, grandchild);
                    }
                }
            }
        }
    }
}
Also used : Model(org.apache.qpid.server.model.Model) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject)

Example 37 with ConfiguredObject

use of org.apache.qpid.server.model.ConfiguredObject in project qpid-broker-j by apache.

the class BDBPreferenceStoreFactoryService method createInstance.

@Override
public PreferenceStore createInstance(final ConfiguredObject<?> parent, final Map<String, Object> preferenceStoreAttributes) {
    final Object path = preferenceStoreAttributes.get(PATH);
    if (path == null || !(path instanceof String)) {
        throw new IllegalConfigurationException("BDBPreferenceStore requires path");
    }
    final String storePath = (String) path;
    return new BDBPreferenceStore(parent, storePath);
}
Also used : IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject)

Example 38 with ConfiguredObject

use of org.apache.qpid.server.model.ConfiguredObject in project qpid-broker-j by apache.

the class UpgradeFrom5To6 method createQueueConfiguredObjectRecord.

private UpgradeConfiguredObjectRecord createQueueConfiguredObjectRecord(String queueName, String owner, boolean exclusive, FieldTable arguments) {
    Map<String, Object> attributesMap = buildQueueArgumentMap(queueName, owner, exclusive, arguments);
    String json = serialiseMap(attributesMap);
    UpgradeConfiguredObjectRecord configuredObject = new UpgradeConfiguredObjectRecord(Queue.class.getName(), json);
    return configuredObject;
}
Also used : ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) Queue(org.apache.qpid.server.model.Queue)

Example 39 with ConfiguredObject

use of org.apache.qpid.server.model.ConfiguredObject in project qpid-broker-j by apache.

the class UpgradeFrom7To8 method performUpgrade.

@Override
public void performUpgrade(Environment environment, UpgradeInteractionHandler handler, ConfiguredObject<?> parent) {
    reportStarting(environment, 7);
    DatabaseConfig dbConfig = new DatabaseConfig();
    dbConfig.setTransactional(true);
    dbConfig.setAllowCreate(true);
    Database hierarchyDb = environment.openDatabase(null, "CONFIGURED_OBJECT_HIERARCHY", dbConfig);
    Database configuredObjectsDb = environment.openDatabase(null, "CONFIGURED_OBJECTS", dbConfig);
    Database configVersionDb = environment.openDatabase(null, "CONFIG_VERSION", dbConfig);
    Database messageMetadataDb = environment.openDatabase(null, "MESSAGE_METADATA", dbConfig);
    Database messageMetadataSeqDb = environment.openDatabase(null, "MESSAGE_METADATA.SEQ", dbConfig);
    long maxMessageId = getMaximumMessageId(messageMetadataDb);
    createMessageMetadataSequence(messageMetadataSeqDb, maxMessageId);
    Cursor objectsCursor = null;
    String stringifiedConfigVersion = BrokerModel.MODEL_VERSION;
    int configVersion = getConfigVersion(configVersionDb);
    if (configVersion > -1) {
        stringifiedConfigVersion = "0." + configVersion;
    }
    configVersionDb.close();
    String virtualHostName = parent.getName();
    Map<String, Object> virtualHostAttributes = new HashMap<String, Object>();
    virtualHostAttributes.put("modelVersion", stringifiedConfigVersion);
    virtualHostAttributes.put("name", virtualHostName);
    UUID virtualHostId = UUIDGenerator.generateVhostUUID(virtualHostName);
    ConfiguredObjectRecord virtualHostRecord = new org.apache.qpid.server.store.ConfiguredObjectRecordImpl(virtualHostId, "VirtualHost", virtualHostAttributes);
    Transaction txn = environment.beginTransaction(null, null);
    try {
        objectsCursor = configuredObjectsDb.openCursor(txn, null);
        DatabaseEntry key = new DatabaseEntry();
        DatabaseEntry value = new DatabaseEntry();
        ObjectMapper mapper = new ObjectMapper();
        while (objectsCursor.getNext(key, value, LockMode.RMW) == OperationStatus.SUCCESS) {
            UUID id = UUIDTupleBinding.getInstance().entryToObject(key);
            TupleInput input = TupleBinding.entryToInput(value);
            String type = input.readString();
            String json = input.readString();
            Map<String, Object> attributes = null;
            try {
                attributes = mapper.readValue(json, MAP_TYPE_REFERENCE);
            } catch (Exception e) {
                throw new StoreException(e);
            }
            String name = (String) attributes.get("name");
            if (type.equals("Exchange")) {
                _defaultExchanges.remove(name);
            }
            if (!type.endsWith("Binding")) {
                storeVirtualHostHierarchyRecord(hierarchyDb, txn, id, virtualHostId);
            } else {
                try {
                    DatabaseEntry hierarchyKey = new DatabaseEntry();
                    DatabaseEntry hierarchyValue = new DatabaseEntry();
                    Object queueIdString = attributes.remove("queue");
                    if (queueIdString instanceof String) {
                        UUID queueId = UUID.fromString(queueIdString.toString());
                        UUIDTupleBinding.getInstance().objectToEntry(queueId, hierarchyValue);
                        TupleOutput tupleOutput = new TupleOutput();
                        tupleOutput.writeLong(id.getMostSignificantBits());
                        tupleOutput.writeLong(id.getLeastSignificantBits());
                        tupleOutput.writeString("Queue");
                        TupleBinding.outputToEntry(tupleOutput, hierarchyKey);
                        hierarchyDb.put(txn, hierarchyKey, hierarchyValue);
                    }
                    Object exchangeIdString = attributes.remove("exchange");
                    if (exchangeIdString instanceof String) {
                        UUID exchangeId = UUID.fromString(exchangeIdString.toString());
                        UUIDTupleBinding.getInstance().objectToEntry(exchangeId, hierarchyValue);
                        TupleOutput tupleOutput = new TupleOutput();
                        tupleOutput.writeLong(id.getMostSignificantBits());
                        tupleOutput.writeLong(id.getLeastSignificantBits());
                        tupleOutput.writeString("Exchange");
                        TupleBinding.outputToEntry(tupleOutput, hierarchyKey);
                        hierarchyDb.put(txn, hierarchyKey, hierarchyValue);
                    }
                    TupleOutput tupleOutput = new TupleOutput();
                    tupleOutput.writeString(type);
                    StringWriter writer = new StringWriter();
                    mapper.writeValue(writer, attributes);
                    tupleOutput.writeString(writer.getBuffer().toString());
                    TupleBinding.outputToEntry(tupleOutput, value);
                    objectsCursor.putCurrent(value);
                } catch (IOException e) {
                    throw new StoreException(e);
                }
            }
        }
    } finally {
        if (objectsCursor != null) {
            objectsCursor.close();
        }
    }
    storeConfiguredObjectEntry(configuredObjectsDb, txn, virtualHostRecord);
    for (Map.Entry<String, String> defaultExchangeEntry : _defaultExchanges.entrySet()) {
        UUID id = UUIDGenerator.generateExchangeUUID(defaultExchangeEntry.getKey(), virtualHostName);
        Map<String, Object> exchangeAttributes = new HashMap<String, Object>();
        exchangeAttributes.put("name", defaultExchangeEntry.getKey());
        exchangeAttributes.put("type", defaultExchangeEntry.getValue());
        exchangeAttributes.put("lifetimePolicy", "PERMANENT");
        ConfiguredObjectRecord exchangeRecord = new org.apache.qpid.server.store.ConfiguredObjectRecordImpl(id, "Exchange", exchangeAttributes);
        storeConfiguredObjectEntry(configuredObjectsDb, txn, exchangeRecord);
        storeVirtualHostHierarchyRecord(hierarchyDb, txn, id, virtualHostId);
    }
    txn.commit();
    hierarchyDb.close();
    configuredObjectsDb.close();
    messageMetadataDb.close();
    messageMetadataSeqDb.close();
    reportFinished(environment, 8);
}
Also used : HashMap(java.util.HashMap) DatabaseEntry(com.sleepycat.je.DatabaseEntry) Cursor(com.sleepycat.je.Cursor) TupleInput(com.sleepycat.bind.tuple.TupleInput) StringWriter(java.io.StringWriter) Database(com.sleepycat.je.Database) UUID(java.util.UUID) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DatabaseConfig(com.sleepycat.je.DatabaseConfig) TupleOutput(com.sleepycat.bind.tuple.TupleOutput) IOException(java.io.IOException) StoreException(org.apache.qpid.server.store.StoreException) IOException(java.io.IOException) StoreException(org.apache.qpid.server.store.StoreException) Transaction(com.sleepycat.je.Transaction) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) ConfiguredObjectRecord(org.apache.qpid.server.store.ConfiguredObjectRecord) HashMap(java.util.HashMap) Map(java.util.Map)

Example 40 with ConfiguredObject

use of org.apache.qpid.server.model.ConfiguredObject in project qpid-broker-j by apache.

the class BDBHAVirtualHostNodeTest method testIntruderProtectionInManagementMode.

public void testIntruderProtectionInManagementMode() throws Exception {
    int nodePortNumber = _portHelper.getNextAvailable();
    int intruderPortNumber = _portHelper.getNextAvailable();
    String helperAddress = "localhost:" + nodePortNumber;
    String groupName = "group";
    String nodeName = "node";
    Map<String, Object> nodeAttributes = _helper.createNodeAttributes(nodeName, groupName, helperAddress, helperAddress, nodeName, nodePortNumber);
    BDBHAVirtualHostNode<?> node = _helper.createAndStartHaVHN(nodeAttributes);
    final CountDownLatch stopLatch = new CountDownLatch(1);
    ConfigurationChangeListener listener = new AbstractConfigurationChangeListener() {

        @Override
        public void stateChanged(ConfiguredObject<?> object, State oldState, State newState) {
            if (newState == State.ERRORED) {
                stopLatch.countDown();
            }
        }
    };
    node.addChangeListener(listener);
    File environmentPathFile = new File(_helper.getMessageStorePath() + File.separator + "intruder");
    Durability durability = Durability.parse((String) nodeAttributes.get(BDBHAVirtualHostNode.DURABILITY));
    joinIntruder(intruderPortNumber, "intruder", groupName, helperAddress, durability, environmentPathFile);
    LOGGER.debug("Permitted and intruder nodes are created");
    assertTrue("Intruder protection was not triggered during expected timeout", stopLatch.await(10, TimeUnit.SECONDS));
    LOGGER.debug("Master node transited into ERRORED state due to intruder protection");
    when(_helper.getBroker().isManagementMode()).thenReturn(true);
    LOGGER.debug("Starting node in management mode");
    final CountDownLatch stateChangeLatch = new CountDownLatch(1);
    final CountDownLatch roleChangeLatch = new CountDownLatch(1);
    node.addChangeListener(new AbstractConfigurationChangeListener() {

        @Override
        public void stateChanged(final ConfiguredObject<?> object, final State oldState, final State newState) {
            if (newState == State.ERRORED) {
                stateChangeLatch.countDown();
            }
        }

        @Override
        public void attributeSet(final ConfiguredObject<?> object, final String attributeName, final Object oldAttributeValue, final Object newAttributeValue) {
            if (BDBHAVirtualHostNode.ROLE.equals(attributeName) && NodeRole.DETACHED.equals(NodeRole.DETACHED)) {
                roleChangeLatch.countDown();
            }
        }
    });
    node.start();
    LOGGER.debug("Node is started");
    // verify that intruder detection is triggered after restart and environment is closed
    assertTrue("Node state was not set to ERRORED", stateChangeLatch.await(10, TimeUnit.SECONDS));
    assertTrue("Node role was not set to DETACHED", roleChangeLatch.await(10, TimeUnit.SECONDS));
}
Also used : Durability(com.sleepycat.je.Durability) CountDownLatch(java.util.concurrent.CountDownLatch) AbstractConfigurationChangeListener(org.apache.qpid.server.model.AbstractConfigurationChangeListener) ConfigurationChangeListener(org.apache.qpid.server.model.ConfigurationChangeListener) AbstractConfigurationChangeListener(org.apache.qpid.server.model.AbstractConfigurationChangeListener) State(org.apache.qpid.server.model.State) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) File(java.io.File)

Aggregations

ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)91 ArrayList (java.util.ArrayList)37 HashMap (java.util.HashMap)28 List (java.util.List)23 AbstractConfiguredObject (org.apache.qpid.server.model.AbstractConfiguredObject)22 LinkedHashMap (java.util.LinkedHashMap)20 UUID (java.util.UUID)20 Map (java.util.Map)18 AbstractConfigurationChangeListener (org.apache.qpid.server.model.AbstractConfigurationChangeListener)12 ManagedObject (org.apache.qpid.server.model.ManagedObject)11 Date (java.util.Date)7 TreeMap (java.util.TreeMap)6 CountDownLatch (java.util.concurrent.CountDownLatch)6 InternalMessageHeader (org.apache.qpid.server.message.internal.InternalMessageHeader)6 State (org.apache.qpid.server.model.State)6 Collection (java.util.Collection)5 ConfiguredObjectFinder (org.apache.qpid.server.model.ConfiguredObjectFinder)5 Model (org.apache.qpid.server.model.Model)5 Preference (org.apache.qpid.server.model.preferences.Preference)5 IllegalConfigurationException (org.apache.qpid.server.configuration.IllegalConfigurationException)4