use of org.apache.qpid.server.store.ConfiguredObjectRecord in project qpid-broker-j by apache.
the class ManagementModeStoreHandler method createCLIPortEntry.
private ConfiguredObjectRecord createCLIPortEntry(int port, Protocol protocol) {
ConfiguredObjectRecord parent = findBroker();
Map<String, Object> attributes = new HashMap<String, Object>();
attributes.put(Port.PORT, port);
attributes.put(Port.PROTOCOLS, Collections.singleton(protocol));
attributes.put(Port.NAME, MANAGEMENT_MODE_PORT_PREFIX + protocol.name());
attributes.put(Port.AUTHENTICATION_PROVIDER, BrokerImpl.MANAGEMENT_MODE_AUTHENTICATION);
ConfiguredObjectRecord portEntry = new ConfiguredObjectRecordImpl(UUID.randomUUID(), PORT_TYPE, attributes, Collections.singletonMap(parent.getType(), parent.getId()));
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Add management mode port configuration " + portEntry + " for port " + port + " and protocol " + protocol);
}
return portEntry;
}
use of org.apache.qpid.server.store.ConfiguredObjectRecord in project qpid-broker-j by apache.
the class BDBConfigurationStore method doVisitAllConfiguredObjectRecords.
private Collection<? extends ConfiguredObjectRecord> doVisitAllConfiguredObjectRecords() {
Map<UUID, BDBConfiguredObjectRecord> configuredObjects = new HashMap<>();
try (Cursor objectsCursor = getConfiguredObjectsDb().openCursor(null, null)) {
DatabaseEntry key = new DatabaseEntry();
DatabaseEntry value = new DatabaseEntry();
while (objectsCursor.getNext(key, value, LockMode.READ_UNCOMMITTED) == OperationStatus.SUCCESS) {
UUID id = UUIDTupleBinding.getInstance().entryToObject(key);
BDBConfiguredObjectRecord configuredObject = (BDBConfiguredObjectRecord) new ConfiguredObjectBinding(id).entryToObject(value);
configuredObjects.put(configuredObject.getId(), configuredObject);
}
// set parents
try (Cursor hierarchyCursor = getConfiguredObjectHierarchyDb().openCursor(null, null)) {
while (hierarchyCursor.getNext(key, value, LockMode.READ_UNCOMMITTED) == OperationStatus.SUCCESS) {
HierarchyKey hk = HierarchyKeyBinding.getInstance().entryToObject(key);
UUID parentId = UUIDTupleBinding.getInstance().entryToObject(value);
BDBConfiguredObjectRecord child = configuredObjects.get(hk.getChildId());
if (child != null) {
ConfiguredObjectRecord parent = configuredObjects.get(parentId);
if (parent != null) {
child.addParent(hk.getParentType(), parent);
}
}
}
}
}
return configuredObjects.values();
}
use of org.apache.qpid.server.store.ConfiguredObjectRecord in project qpid-broker-j by apache.
the class BDBConfigurationStore method openConfigurationStore.
@Override
public boolean openConfigurationStore(ConfiguredObjectRecordHandler handler, final ConfiguredObjectRecord... initialRecords) {
changeState(CONFIGURED, OPEN);
try {
Collection<? extends ConfiguredObjectRecord> records = doVisitAllConfiguredObjectRecords();
boolean empty = records.isEmpty();
if (empty) {
records = Arrays.asList(initialRecords);
com.sleepycat.je.Transaction txn = null;
try {
txn = _environmentFacade.beginTransaction(null);
for (ConfiguredObjectRecord record : records) {
update(true, record, txn);
}
txn.commit();
txn = null;
} catch (RuntimeException e) {
throw _environmentFacade.handleDatabaseException("Error updating configuration details within the store: " + e, e);
} finally {
if (txn != null) {
abortTransactionSafely(txn, _environmentFacade);
}
}
}
for (ConfiguredObjectRecord record : records) {
handler.handle(record);
}
return empty;
} catch (RuntimeException e) {
throw _environmentFacade.handleDatabaseException("Cannot visit configured object records", e);
}
}
use of org.apache.qpid.server.store.ConfiguredObjectRecord in project qpid-broker-j by apache.
the class AbstractConfiguredObject method asObjectRecord.
@Override
public final ConfiguredObjectRecord asObjectRecord() {
return new ConfiguredObjectRecord() {
@Override
public UUID getId() {
return AbstractConfiguredObject.this.getId();
}
@Override
public String getType() {
return getCategoryClass().getSimpleName();
}
@Override
public Map<String, Object> getAttributes() {
return Subject.doAs(getSubjectWithAddedSystemRights(), new PrivilegedAction<Map<String, Object>>() {
@Override
public Map<String, Object> run() {
Map<String, Object> attributes = new LinkedHashMap<>();
Map<String, Object> actualAttributes = getActualAttributes();
for (ConfiguredObjectAttribute<?, ?> attr : _attributeTypes.values()) {
if (attr.isPersisted() && !ID.equals(attr.getName())) {
if (attr.isDerived()) {
Object value = getAttribute(attr.getName());
attributes.put(attr.getName(), toRecordedForm(attr, value));
} else if (actualAttributes.containsKey(attr.getName())) {
Object value = actualAttributes.get(attr.getName());
attributes.put(attr.getName(), toRecordedForm(attr, value));
}
}
}
return attributes;
}
});
}
public Object toRecordedForm(final ConfiguredObjectAttribute<?, ?> attr, Object value) {
if (value instanceof ConfiguredObject) {
value = ((ConfiguredObject) value).getId();
}
if (attr.isSecure() && _encrypter != null && value != null) {
if (value instanceof Collection || value instanceof Map) {
ObjectMapper mapper = ConfiguredObjectJacksonModule.newObjectMapper(false);
try (StringWriter stringWriter = new StringWriter()) {
mapper.writeValue(stringWriter, value);
value = _encrypter.encrypt(stringWriter.toString());
} catch (IOException e) {
throw new IllegalConfigurationException("Failure when encrypting a secret value", e);
}
} else {
value = _encrypter.encrypt(value.toString());
}
}
return value;
}
@Override
public Map<String, UUID> getParents() {
Map<String, UUID> parents = new LinkedHashMap<>();
Class<? extends ConfiguredObject> parentClass = getModel().getParentType(getCategoryClass());
ConfiguredObject parent = (ConfiguredObject) getParent();
if (parent != null) {
parents.put(parentClass.getSimpleName(), parent.getId());
}
return parents;
}
@Override
public String toString() {
return AbstractConfiguredObject.this.getClass().getSimpleName() + "[name=" + getName() + ", categoryClass=" + getCategoryClass() + ", type=" + getType() + ", id=" + getId() + ", attributes=" + getAttributes() + "]";
}
};
}
use of org.apache.qpid.server.store.ConfiguredObjectRecord in project qpid-broker-j by apache.
the class AbstractVirtualHost method importMessageStore.
@Override
public void importMessageStore(final String source) {
try {
final URL url = convertStringToURL(source);
try (InputStream input = url.openStream();
BufferedInputStream bufferedInputStream = new BufferedInputStream(input);
DataInputStream data = new DataInputStream(bufferedInputStream)) {
final MessageStoreSerializer serializer = MessageStoreSerializer.FACTORY.newInstance(data);
doSync(doOnConfigThread(new Task<ListenableFuture<Void>, IOException>() {
@Override
public ListenableFuture<Void> execute() throws IOException {
if (getState() != State.STOPPED) {
throw new IllegalArgumentException("The importMessageStore operation can only be called when the virtual host is stopped");
}
try {
_messageStore.openMessageStore(AbstractVirtualHost.this);
checkMessageStoreEmpty();
final Map<String, UUID> queueMap = new HashMap<>();
getDurableConfigurationStore().reload(new ConfiguredObjectRecordHandler() {
@Override
public void handle(final ConfiguredObjectRecord record) {
if (record.getType().equals(Queue.class.getSimpleName())) {
queueMap.put((String) record.getAttributes().get(ConfiguredObject.NAME), record.getId());
}
}
});
serializer.deserialize(queueMap, _messageStore, data);
} finally {
_messageStore.closeMessageStore();
}
return Futures.immediateFuture(null);
}
@Override
public String getObject() {
return AbstractVirtualHost.this.toString();
}
@Override
public String getAction() {
return "importMessageStore";
}
@Override
public String getArguments() {
if (url.getProtocol().equalsIgnoreCase("http") || url.getProtocol().equalsIgnoreCase("https") || url.getProtocol().equalsIgnoreCase("file")) {
return "source=" + source;
} else if (url.getProtocol().equalsIgnoreCase("data")) {
return "source=<data stream>";
} else {
return "source=<unknown source type>";
}
}
}));
}
} catch (IOException e) {
throw new IllegalConfigurationException("Cannot convert '" + source + "' to a readable resource", e);
}
}
Aggregations