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);
}
}
}
}
}
}
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);
}
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;
}
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);
}
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));
}
Aggregations